Ejemplo n.º 1
0
nsresult
HTMLEditor::ShowInlineTableEditingUI(Element* aCell)
{
  // do nothing if aCell is not a table cell...
  if (!aCell || !HTMLEditUtils::IsTableCell(aCell)) {
    return NS_OK;
  }

  if (NS_WARN_IF(!IsDescendantOfEditorRoot(aCell))) {
    return NS_ERROR_UNEXPECTED;
  }

  if (mInlineEditedCell) {
    NS_ERROR("call HideInlineTableEditingUI first");
    return NS_ERROR_UNEXPECTED;
  }

  // the resizers and the shadow will be anonymous children of the body
  RefPtr<Element> bodyElement = GetRoot();
  NS_ENSURE_TRUE(bodyElement, NS_ERROR_NULL_POINTER);

  mAddColumnBeforeButton =
    CreateAnonymousElement(nsGkAtoms::a, *bodyElement,
                           NS_LITERAL_STRING("mozTableAddColumnBefore"), false);
  mRemoveColumnButton =
    CreateAnonymousElement(nsGkAtoms::a, *bodyElement,
                           NS_LITERAL_STRING("mozTableRemoveColumn"), false);
  mAddColumnAfterButton =
    CreateAnonymousElement(nsGkAtoms::a, *bodyElement,
                           NS_LITERAL_STRING("mozTableAddColumnAfter"), false);

  mAddRowBeforeButton =
    CreateAnonymousElement(nsGkAtoms::a, *bodyElement,
                           NS_LITERAL_STRING("mozTableAddRowBefore"), false);
  mRemoveRowButton =
    CreateAnonymousElement(nsGkAtoms::a, *bodyElement,
                           NS_LITERAL_STRING("mozTableRemoveRow"), false);
  mAddRowAfterButton =
    CreateAnonymousElement(nsGkAtoms::a, *bodyElement,
                           NS_LITERAL_STRING("mozTableAddRowAfter"), false);

  AddMouseClickListener(mAddColumnBeforeButton);
  AddMouseClickListener(mRemoveColumnButton);
  AddMouseClickListener(mAddColumnAfterButton);
  AddMouseClickListener(mAddRowBeforeButton);
  AddMouseClickListener(mRemoveRowButton);
  AddMouseClickListener(mAddRowAfterButton);

  mInlineEditedCell = aCell;
  return RefreshInlineTableEditingUI();
}
NS_IMETHODIMP
HTMLEditor::ShowInlineTableEditingUI(nsIDOMElement* aCell)
{
  NS_ENSURE_ARG_POINTER(aCell);

  // do nothing if aCell is not a table cell...
  if (!HTMLEditUtils::IsTableCell(aCell)) {
    return NS_OK;
  }

  if (mInlineEditedCell) {
    NS_ERROR("call HideInlineTableEditingUI first");
    return NS_ERROR_UNEXPECTED;
  }

  // the resizers and the shadow will be anonymous children of the body
  nsCOMPtr<nsIDOMElement> bodyElement = do_QueryInterface(GetRoot());
  NS_ENSURE_TRUE(bodyElement, NS_ERROR_NULL_POINTER);

  mAddColumnBeforeButton =
    CreateAnonymousElement(nsGkAtoms::a, bodyElement,
                           NS_LITERAL_STRING("mozTableAddColumnBefore"), false);
  mRemoveColumnButton =
    CreateAnonymousElement(nsGkAtoms::a, bodyElement,
                           NS_LITERAL_STRING("mozTableRemoveColumn"), false);
  mAddColumnAfterButton =
    CreateAnonymousElement(nsGkAtoms::a, bodyElement,
                           NS_LITERAL_STRING("mozTableAddColumnAfter"), false);

  mAddRowBeforeButton =
    CreateAnonymousElement(nsGkAtoms::a, bodyElement,
                           NS_LITERAL_STRING("mozTableAddRowBefore"), false);
  mRemoveRowButton =
    CreateAnonymousElement(nsGkAtoms::a, bodyElement,
                           NS_LITERAL_STRING("mozTableRemoveRow"), false);
  mAddRowAfterButton =
    CreateAnonymousElement(nsGkAtoms::a, bodyElement,
                           NS_LITERAL_STRING("mozTableAddRowAfter"), false);

  AddMouseClickListener(mAddColumnBeforeButton);
  AddMouseClickListener(mRemoveColumnButton);
  AddMouseClickListener(mAddColumnAfterButton);
  AddMouseClickListener(mAddRowBeforeButton);
  AddMouseClickListener(mRemoveRowButton);
  AddMouseClickListener(mAddRowAfterButton);

  mInlineEditedCell = aCell;
  return RefreshInlineTableEditingUI();
}
NS_IMETHODIMP
nsHTMLEditor::ShowInlineTableEditingUI(nsIDOMElement * aCell)
{
  NS_ENSURE_ARG_POINTER(aCell);

  // do nothing if aCell is not a table cell...
  if (!nsHTMLEditUtils::IsTableCell(aCell))
    return NS_OK;

  if (mInlineEditedCell) {
    NS_ERROR("call HideInlineTableEditingUI first");
    return NS_ERROR_UNEXPECTED;
  }

  // the resizers and the shadow will be anonymous children of the body
  nsIDOMElement *bodyElement = GetRoot();
  NS_ENSURE_TRUE(bodyElement, NS_ERROR_NULL_POINTER);

  CreateAnonymousElement(NS_LITERAL_STRING("a"), bodyElement,
                         NS_LITERAL_STRING("mozTableAddColumnBefore"),
                         PR_FALSE, getter_AddRefs(mAddColumnBeforeButton));
  CreateAnonymousElement(NS_LITERAL_STRING("a"), bodyElement,
                         NS_LITERAL_STRING("mozTableRemoveColumn"),
                         PR_FALSE, getter_AddRefs(mRemoveColumnButton));
  CreateAnonymousElement(NS_LITERAL_STRING("a"), bodyElement,
                         NS_LITERAL_STRING("mozTableAddColumnAfter"),
                         PR_FALSE, getter_AddRefs(mAddColumnAfterButton));

  CreateAnonymousElement(NS_LITERAL_STRING("a"), bodyElement,
                         NS_LITERAL_STRING("mozTableAddRowBefore"),
                         PR_FALSE, getter_AddRefs(mAddRowBeforeButton));
  CreateAnonymousElement(NS_LITERAL_STRING("a"), bodyElement,
                         NS_LITERAL_STRING("mozTableRemoveRow"),
                         PR_FALSE, getter_AddRefs(mRemoveRowButton));
  CreateAnonymousElement(NS_LITERAL_STRING("a"), bodyElement,
                         NS_LITERAL_STRING("mozTableAddRowAfter"),
                         PR_FALSE, getter_AddRefs(mAddRowAfterButton));

  AddMouseClickListener(mAddColumnBeforeButton);
  AddMouseClickListener(mRemoveColumnButton);
  AddMouseClickListener(mAddColumnAfterButton);
  AddMouseClickListener(mAddRowBeforeButton);
  AddMouseClickListener(mRemoveRowButton);
  AddMouseClickListener(mAddRowAfterButton);

  mInlineEditedCell = aCell;
  return RefreshInlineTableEditingUI();
}