2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2003-06-25 12:50:48 +04:00
|
|
|
|
2016-07-09 05:42:33 +03:00
|
|
|
#include "mozilla/HTMLEditor.h"
|
|
|
|
|
2016-07-07 08:01:12 +03:00
|
|
|
#include "HTMLEditUtils.h"
|
2019-03-15 08:01:10 +03:00
|
|
|
#include "mozilla/PresShell.h"
|
2012-07-13 10:33:42 +04:00
|
|
|
#include "mozilla/dom/Element.h"
|
|
|
|
#include "nsAString.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsDebug.h"
|
|
|
|
#include "nsError.h"
|
2018-01-30 07:40:11 +03:00
|
|
|
#include "nsGenericHTMLElement.h"
|
2012-07-13 10:33:42 +04:00
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsIHTMLObjectResizer.h"
|
|
|
|
#include "nsLiteralString.h"
|
2003-07-14 11:37:39 +04:00
|
|
|
#include "nsReadableUtils.h"
|
2012-07-13 10:33:42 +04:00
|
|
|
#include "nsString.h"
|
|
|
|
#include "nscore.h"
|
2003-06-25 12:50:48 +04:00
|
|
|
|
2016-07-09 05:42:33 +03:00
|
|
|
namespace mozilla {
|
2016-07-07 08:01:12 +03:00
|
|
|
|
2003-06-25 12:50:48 +04:00
|
|
|
NS_IMETHODIMP
|
2016-07-09 05:42:33 +03:00
|
|
|
HTMLEditor::SetInlineTableEditingEnabled(bool aIsEnabled) {
|
Bug 1449564 - part 1: Disable object resizer and inline table editor in default r=m_kato
Gecko supports resizers of <img> elements and <table>, <td>, <th> elements and
has UI to remove existing table row or column in default. However, the other
browsers don't have such UI and web apps need to disable this feature with
calling both:
document.execCommand("enableObjectResizing", false, false);
document.execCommand("enableInlineTableEditing", false, false);
for avoiding conflicting with their own features to edit such elements.
Therefore, it doesn't make sense to keep enabling them in default only on
Gecko. If web apps want to keep using these features, they should call:
document.execCommand("enableObjectResizing", false, true);
document.execCommand("enableInlineTableEditing", false, true);
at initializing the editor.
And also this patch fixes bugs of
document.queryCommandState("enableObjectResizing") and
document.queryCommandState("enableInlineTableEditing"). They always return
false even after calling document.execCommand(..., false, true) since
nsSetDocumentStateCommand::GetCommandStateParams() sets bool value as
STATE_ATTRIBUTE. However, nsHTMLDocument::QueryCommandValue() which is the
caller referring STATE_ATTRIBUTE doesn't treat it as bool value. And also
those commands are related to state of document. Therefore, they should be
return as bool value of STATE_ALL instead. Then,
nsHTMLDocument::QueryCommandState() returns the state as expected. Note that
those commands are supported only by Gecko. So, we don't need to worry about
the compatibility.
Finally, this patch rewrites 2 existing tests to check basic behavior of
resizers and appearance of resizers.
Note that this patch does not add new tests to test inline table editor
since it's difficult to test the behavior with current API. Perhaps, we
should add an API to nsIHTMLEditor to retrieve each anonymous elements in
another bug since it requires to add wrapping API of SpecialPowers.
MozReview-Commit-ID: 1FhYo5vcV60
--HG--
rename : editor/libeditor/tests/test_objectResizing.html => editor/libeditor/tests/test_resizers_appearance.html
rename : editor/libeditor/tests/test_bug640321.html => editor/libeditor/tests/test_resizers_resizing_elements.html
extra : rebase_source : a707de5a64ef1f8ce974cdf1be093d1b4f61c7bc
2018-04-02 11:26:46 +03:00
|
|
|
EnableInlineTableEditor(aIsEnabled);
|
2003-06-25 12:50:48 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2016-07-09 05:42:33 +03:00
|
|
|
HTMLEditor::GetInlineTableEditingEnabled(bool* aIsEnabled) {
|
Bug 1449564 - part 1: Disable object resizer and inline table editor in default r=m_kato
Gecko supports resizers of <img> elements and <table>, <td>, <th> elements and
has UI to remove existing table row or column in default. However, the other
browsers don't have such UI and web apps need to disable this feature with
calling both:
document.execCommand("enableObjectResizing", false, false);
document.execCommand("enableInlineTableEditing", false, false);
for avoiding conflicting with their own features to edit such elements.
Therefore, it doesn't make sense to keep enabling them in default only on
Gecko. If web apps want to keep using these features, they should call:
document.execCommand("enableObjectResizing", false, true);
document.execCommand("enableInlineTableEditing", false, true);
at initializing the editor.
And also this patch fixes bugs of
document.queryCommandState("enableObjectResizing") and
document.queryCommandState("enableInlineTableEditing"). They always return
false even after calling document.execCommand(..., false, true) since
nsSetDocumentStateCommand::GetCommandStateParams() sets bool value as
STATE_ATTRIBUTE. However, nsHTMLDocument::QueryCommandValue() which is the
caller referring STATE_ATTRIBUTE doesn't treat it as bool value. And also
those commands are related to state of document. Therefore, they should be
return as bool value of STATE_ALL instead. Then,
nsHTMLDocument::QueryCommandState() returns the state as expected. Note that
those commands are supported only by Gecko. So, we don't need to worry about
the compatibility.
Finally, this patch rewrites 2 existing tests to check basic behavior of
resizers and appearance of resizers.
Note that this patch does not add new tests to test inline table editor
since it's difficult to test the behavior with current API. Perhaps, we
should add an API to nsIHTMLEditor to retrieve each anonymous elements in
another bug since it requires to add wrapping API of SpecialPowers.
MozReview-Commit-ID: 1FhYo5vcV60
--HG--
rename : editor/libeditor/tests/test_objectResizing.html => editor/libeditor/tests/test_resizers_appearance.html
rename : editor/libeditor/tests/test_bug640321.html => editor/libeditor/tests/test_resizers_resizing_elements.html
extra : rebase_source : a707de5a64ef1f8ce974cdf1be093d1b4f61c7bc
2018-04-02 11:26:46 +03:00
|
|
|
*aIsEnabled = IsInlineTableEditorEnabled();
|
2003-06-25 12:50:48 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2018-09-11 15:10:54 +03:00
|
|
|
nsresult HTMLEditor::ShowInlineTableEditingUIInternal(Element& aCellElement) {
|
|
|
|
if (NS_WARN_IF(!HTMLEditUtils::IsTableCell(&aCellElement))) {
|
2003-06-25 12:50:48 +04:00
|
|
|
return NS_OK;
|
2016-07-07 08:01:12 +03:00
|
|
|
}
|
2003-06-25 12:50:48 +04:00
|
|
|
|
2018-09-11 15:10:54 +03:00
|
|
|
if (NS_WARN_IF(!IsDescendantOfEditorRoot(&aCellElement))) {
|
|
|
|
return NS_ERROR_FAILURE;
|
2017-09-09 17:49:02 +03:00
|
|
|
}
|
|
|
|
|
2018-09-11 15:10:54 +03:00
|
|
|
if (NS_WARN_IF(mInlineEditedCell)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
2008-04-14 00:22:31 +04:00
|
|
|
}
|
|
|
|
|
2018-09-11 15:10:54 +03:00
|
|
|
mInlineEditedCell = &aCellElement;
|
|
|
|
|
2003-06-25 12:50:48 +04:00
|
|
|
// the resizers and the shadow will be anonymous children of the body
|
2017-08-07 08:09:51 +03:00
|
|
|
RefPtr<Element> bodyElement = GetRoot();
|
2018-09-11 15:10:54 +03:00
|
|
|
if (NS_WARN_IF(!bodyElement)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
do {
|
|
|
|
// The buttons of inline table editor will be children of the <body>
|
|
|
|
// element. Creating the anonymous elements may cause calling
|
|
|
|
// HideInlineTableEditingUIInternal() via a mutation event listener.
|
|
|
|
// So, we should store new button to a local variable, then, check:
|
|
|
|
// - whether creating a button is already set to the member or not
|
|
|
|
// - whether already created buttons are changed to another set
|
|
|
|
// If creating the buttons are canceled, we hit the latter check.
|
|
|
|
// If buttons for another table are created during this, we hit the latter
|
|
|
|
// check too.
|
|
|
|
// If buttons are just created again for same element, we hit the former
|
|
|
|
// check.
|
|
|
|
ManualNACPtr addColumnBeforeButton = CreateAnonymousElement(
|
|
|
|
nsGkAtoms::a, *bodyElement,
|
|
|
|
NS_LITERAL_STRING("mozTableAddColumnBefore"), false);
|
|
|
|
if (NS_WARN_IF(!addColumnBeforeButton)) {
|
|
|
|
break; // Hide unnecessary buttons created above.
|
|
|
|
}
|
|
|
|
if (NS_WARN_IF(mAddColumnBeforeButton) ||
|
|
|
|
NS_WARN_IF(mInlineEditedCell != &aCellElement)) {
|
|
|
|
return NS_ERROR_FAILURE; // Don't hide another set of buttons.
|
|
|
|
}
|
|
|
|
mAddColumnBeforeButton = std::move(addColumnBeforeButton);
|
|
|
|
|
|
|
|
ManualNACPtr removeColumnButton = CreateAnonymousElement(
|
|
|
|
nsGkAtoms::a, *bodyElement, NS_LITERAL_STRING("mozTableRemoveColumn"),
|
|
|
|
false);
|
|
|
|
if (NS_WARN_IF(!removeColumnButton)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (NS_WARN_IF(mRemoveColumnButton) ||
|
|
|
|
NS_WARN_IF(mInlineEditedCell != &aCellElement)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
mRemoveColumnButton = std::move(removeColumnButton);
|
|
|
|
|
|
|
|
ManualNACPtr addColumnAfterButton = CreateAnonymousElement(
|
|
|
|
nsGkAtoms::a, *bodyElement, NS_LITERAL_STRING("mozTableAddColumnAfter"),
|
|
|
|
false);
|
|
|
|
if (NS_WARN_IF(!addColumnAfterButton)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (NS_WARN_IF(mAddColumnAfterButton) ||
|
|
|
|
NS_WARN_IF(mInlineEditedCell != &aCellElement)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
mAddColumnAfterButton = std::move(addColumnAfterButton);
|
|
|
|
|
|
|
|
ManualNACPtr addRowBeforeButton = CreateAnonymousElement(
|
|
|
|
nsGkAtoms::a, *bodyElement, NS_LITERAL_STRING("mozTableAddRowBefore"),
|
|
|
|
false);
|
|
|
|
if (NS_WARN_IF(!addRowBeforeButton)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (NS_WARN_IF(mAddRowBeforeButton) ||
|
|
|
|
NS_WARN_IF(mInlineEditedCell != &aCellElement)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
mAddRowBeforeButton = std::move(addRowBeforeButton);
|
|
|
|
|
|
|
|
ManualNACPtr removeRowButton =
|
|
|
|
CreateAnonymousElement(nsGkAtoms::a, *bodyElement,
|
|
|
|
NS_LITERAL_STRING("mozTableRemoveRow"), false);
|
|
|
|
if (NS_WARN_IF(!removeRowButton)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (NS_WARN_IF(mRemoveRowButton) ||
|
|
|
|
NS_WARN_IF(mInlineEditedCell != &aCellElement)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
mRemoveRowButton = std::move(removeRowButton);
|
|
|
|
|
|
|
|
ManualNACPtr addRowAfterButton =
|
|
|
|
CreateAnonymousElement(nsGkAtoms::a, *bodyElement,
|
|
|
|
NS_LITERAL_STRING("mozTableAddRowAfter"), false);
|
|
|
|
if (NS_WARN_IF(!addRowAfterButton)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (NS_WARN_IF(mAddRowAfterButton) ||
|
|
|
|
NS_WARN_IF(mInlineEditedCell != &aCellElement)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
mAddRowAfterButton = std::move(addRowAfterButton);
|
|
|
|
|
|
|
|
AddMouseClickListener(mAddColumnBeforeButton);
|
|
|
|
AddMouseClickListener(mRemoveColumnButton);
|
|
|
|
AddMouseClickListener(mAddColumnAfterButton);
|
|
|
|
AddMouseClickListener(mAddRowBeforeButton);
|
|
|
|
AddMouseClickListener(mRemoveRowButton);
|
|
|
|
AddMouseClickListener(mAddRowAfterButton);
|
|
|
|
|
|
|
|
nsresult rv = RefreshInlineTableEditingUIInternal();
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
} while (true);
|
|
|
|
|
|
|
|
HideInlineTableEditingUIInternal();
|
|
|
|
return NS_ERROR_FAILURE;
|
2003-06-25 12:50:48 +04:00
|
|
|
}
|
|
|
|
|
2018-09-11 15:10:54 +03:00
|
|
|
void HTMLEditor::HideInlineTableEditingUIInternal() {
|
2012-07-30 18:20:58 +04:00
|
|
|
mInlineEditedCell = nullptr;
|
2003-06-25 12:50:48 +04:00
|
|
|
|
|
|
|
RemoveMouseClickListener(mAddColumnBeforeButton);
|
|
|
|
RemoveMouseClickListener(mRemoveColumnButton);
|
|
|
|
RemoveMouseClickListener(mAddColumnAfterButton);
|
|
|
|
RemoveMouseClickListener(mAddRowBeforeButton);
|
|
|
|
RemoveMouseClickListener(mRemoveRowButton);
|
|
|
|
RemoveMouseClickListener(mAddRowAfterButton);
|
|
|
|
|
|
|
|
// get the presshell's document observer interface.
|
2019-03-15 08:01:10 +03:00
|
|
|
RefPtr<PresShell> presShell = GetPresShell();
|
2010-05-06 05:20:43 +04:00
|
|
|
// We allow the pres shell to be null; when it is, we presume there
|
|
|
|
// are no document observers to notify, but we still want to
|
|
|
|
// UnbindFromTree.
|
2003-06-25 12:50:48 +04:00
|
|
|
|
2018-08-17 12:23:13 +03:00
|
|
|
// Calling DeleteRefToAnonymousNode() may cause showing the UI again.
|
|
|
|
// Therefore, we should forget all anonymous contents first.
|
|
|
|
// Otherwise, we could leak the old content because of overwritten by
|
2018-09-11 15:10:54 +03:00
|
|
|
// ShowInlineTableEditingUIInternal().
|
2018-08-17 12:23:13 +03:00
|
|
|
ManualNACPtr addColumnBeforeButton(std::move(mAddColumnBeforeButton));
|
|
|
|
ManualNACPtr removeColumnButton(std::move(mRemoveColumnButton));
|
|
|
|
ManualNACPtr addColumnAfterButton(std::move(mAddColumnAfterButton));
|
|
|
|
ManualNACPtr addRowBeforeButton(std::move(mAddRowBeforeButton));
|
|
|
|
ManualNACPtr removeRowButton(std::move(mRemoveRowButton));
|
|
|
|
ManualNACPtr addRowAfterButton(std::move(mAddRowAfterButton));
|
|
|
|
|
2019-03-15 08:01:10 +03:00
|
|
|
DeleteRefToAnonymousNode(std::move(addColumnBeforeButton), presShell);
|
|
|
|
DeleteRefToAnonymousNode(std::move(removeColumnButton), presShell);
|
|
|
|
DeleteRefToAnonymousNode(std::move(addColumnAfterButton), presShell);
|
|
|
|
DeleteRefToAnonymousNode(std::move(addRowBeforeButton), presShell);
|
|
|
|
DeleteRefToAnonymousNode(std::move(removeRowButton), presShell);
|
|
|
|
DeleteRefToAnonymousNode(std::move(addRowAfterButton), presShell);
|
2003-06-25 12:50:48 +04:00
|
|
|
}
|
|
|
|
|
2018-01-25 16:16:32 +03:00
|
|
|
nsresult HTMLEditor::DoInlineTableEditingAction(const Element& aElement) {
|
2018-01-19 10:41:41 +03:00
|
|
|
nsAutoString anonclass;
|
|
|
|
aElement.GetAttr(kNameSpaceID_None, nsGkAtoms::_moz_anonclass, anonclass);
|
|
|
|
|
|
|
|
if (!StringBeginsWith(anonclass, NS_LITERAL_STRING("mozTable"))) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2018-10-30 13:00:17 +03:00
|
|
|
AutoEditActionDataSetter editActionData(*this, EditAction::eNotEditing);
|
|
|
|
if (NS_WARN_IF(!editActionData.CanHandle())) {
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
}
|
|
|
|
|
2018-01-19 10:41:41 +03:00
|
|
|
RefPtr<Element> tableElement = GetEnclosingTable(mInlineEditedCell);
|
|
|
|
int32_t rowCount, colCount;
|
|
|
|
nsresult rv = GetTableSize(tableElement, &rowCount, &colCount);
|
2019-02-25 12:07:54 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return EditorBase::ToGenericNSResult(rv);
|
|
|
|
}
|
2018-01-19 10:41:41 +03:00
|
|
|
|
|
|
|
bool hideUI = false;
|
|
|
|
bool hideResizersWithInlineTableUI = (mResizedObject == tableElement);
|
|
|
|
|
|
|
|
if (anonclass.EqualsLiteral("mozTableAddColumnBefore")) {
|
2018-10-30 13:00:17 +03:00
|
|
|
AutoEditActionDataSetter editActionData(*this,
|
|
|
|
EditAction::eInsertTableColumn);
|
|
|
|
if (NS_WARN_IF(!editActionData.CanHandle())) {
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
}
|
2018-09-20 12:15:08 +03:00
|
|
|
DebugOnly<nsresult> rv = InsertTableColumnsWithTransaction(
|
|
|
|
1, InsertPosition::eBeforeSelectedCell);
|
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
|
|
|
|
"Failed to insert a column before the selected cell");
|
2018-01-19 10:41:41 +03:00
|
|
|
} else if (anonclass.EqualsLiteral("mozTableAddColumnAfter")) {
|
2018-10-30 13:00:17 +03:00
|
|
|
AutoEditActionDataSetter editActionData(*this,
|
|
|
|
EditAction::eInsertTableColumn);
|
|
|
|
if (NS_WARN_IF(!editActionData.CanHandle())) {
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
}
|
2018-09-20 12:15:08 +03:00
|
|
|
DebugOnly<nsresult> rv = InsertTableColumnsWithTransaction(
|
|
|
|
1, InsertPosition::eAfterSelectedCell);
|
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
|
|
|
|
"Failed to insert a column after the selected cell");
|
2018-01-19 10:41:41 +03:00
|
|
|
} else if (anonclass.EqualsLiteral("mozTableAddRowBefore")) {
|
2018-10-30 13:00:17 +03:00
|
|
|
AutoEditActionDataSetter editActionData(*this,
|
|
|
|
EditAction::eInsertTableRowElement);
|
|
|
|
if (NS_WARN_IF(!editActionData.CanHandle())) {
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
}
|
2018-09-20 09:55:17 +03:00
|
|
|
DebugOnly<nsresult> rv =
|
|
|
|
InsertTableRowsWithTransaction(1, InsertPosition::eBeforeSelectedCell);
|
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
|
|
|
|
"Failed to insert a row before the selected cell");
|
2018-01-19 10:41:41 +03:00
|
|
|
} else if (anonclass.EqualsLiteral("mozTableAddRowAfter")) {
|
2018-10-30 13:00:17 +03:00
|
|
|
AutoEditActionDataSetter editActionData(*this,
|
|
|
|
EditAction::eInsertTableRowElement);
|
|
|
|
if (NS_WARN_IF(!editActionData.CanHandle())) {
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
}
|
2018-09-20 09:55:17 +03:00
|
|
|
DebugOnly<nsresult> rv =
|
|
|
|
InsertTableRowsWithTransaction(1, InsertPosition::eAfterSelectedCell);
|
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
|
|
|
|
"Failed to insert a row after the selected cell");
|
2018-01-19 10:41:41 +03:00
|
|
|
} else if (anonclass.EqualsLiteral("mozTableRemoveColumn")) {
|
2018-10-30 13:00:17 +03:00
|
|
|
AutoEditActionDataSetter editActionData(*this,
|
|
|
|
EditAction::eRemoveTableColumn);
|
|
|
|
if (NS_WARN_IF(!editActionData.CanHandle())) {
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
}
|
2018-09-19 09:34:33 +03:00
|
|
|
DebugOnly<nsresult> rv = DeleteSelectedTableColumnsWithTransaction(1);
|
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
|
|
|
|
"Failed to delete the selected table column");
|
2018-01-19 10:41:41 +03:00
|
|
|
hideUI = (colCount == 1);
|
|
|
|
} else if (anonclass.EqualsLiteral("mozTableRemoveRow")) {
|
2018-10-30 13:00:17 +03:00
|
|
|
AutoEditActionDataSetter editActionData(*this,
|
|
|
|
EditAction::eRemoveTableRowElement);
|
|
|
|
if (NS_WARN_IF(!editActionData.CanHandle())) {
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
}
|
2018-09-18 10:56:45 +03:00
|
|
|
DebugOnly<nsresult> rv = DeleteSelectedTableRowsWithTransaction(1);
|
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
|
|
|
|
"Failed to delete the selected table row");
|
2018-01-19 10:41:41 +03:00
|
|
|
hideUI = (rowCount == 1);
|
|
|
|
} else {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2003-06-25 12:50:48 +04:00
|
|
|
|
2018-09-20 09:55:17 +03:00
|
|
|
// InsertTableRowsWithTransaction() might causes reframe.
|
2018-01-19 10:41:41 +03:00
|
|
|
if (Destroyed()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2017-07-14 09:48:40 +03:00
|
|
|
|
2018-01-19 10:41:41 +03:00
|
|
|
if (hideUI) {
|
2018-09-11 15:10:54 +03:00
|
|
|
HideInlineTableEditingUIInternal();
|
2018-01-19 10:41:41 +03:00
|
|
|
if (hideResizersWithInlineTableUI) {
|
2018-09-06 08:02:46 +03:00
|
|
|
DebugOnly<nsresult> rv = HideResizersInternal();
|
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "Failed to hide resizers");
|
2003-06-25 12:50:48 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-11-24 09:58:01 +03:00
|
|
|
void HTMLEditor::AddMouseClickListener(Element* aElement) {
|
2018-04-05 20:42:42 +03:00
|
|
|
if (aElement) {
|
|
|
|
aElement->AddEventListener(NS_LITERAL_STRING("click"), mEventListener,
|
|
|
|
true);
|
2010-03-06 07:01:28 +03:00
|
|
|
}
|
2003-06-25 12:50:48 +04:00
|
|
|
}
|
|
|
|
|
2016-11-24 09:58:01 +03:00
|
|
|
void HTMLEditor::RemoveMouseClickListener(Element* aElement) {
|
2018-04-05 20:42:40 +03:00
|
|
|
if (aElement) {
|
|
|
|
aElement->RemoveEventListener(NS_LITERAL_STRING("click"), mEventListener,
|
|
|
|
true);
|
2010-03-06 07:01:28 +03:00
|
|
|
}
|
2003-06-25 12:50:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2016-07-09 05:42:33 +03:00
|
|
|
HTMLEditor::RefreshInlineTableEditingUI() {
|
2018-10-30 13:00:17 +03:00
|
|
|
AutoEditActionDataSetter editActionData(*this, EditAction::eNotEditing);
|
|
|
|
if (NS_WARN_IF(!editActionData.CanHandle())) {
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
}
|
|
|
|
|
2018-09-11 15:10:54 +03:00
|
|
|
nsresult rv = RefreshInlineTableEditingUIInternal();
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
2019-02-25 12:07:54 +03:00
|
|
|
return EditorBase::ToGenericNSResult(rv);
|
2018-09-11 15:10:54 +03:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult HTMLEditor::RefreshInlineTableEditingUIInternal() {
|
2017-12-15 19:14:54 +03:00
|
|
|
if (!mInlineEditedCell) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2018-09-11 15:10:54 +03:00
|
|
|
RefPtr<nsGenericHTMLElement> inlineEditingCellElement =
|
2018-03-22 00:39:04 +03:00
|
|
|
nsGenericHTMLElement::FromNode(mInlineEditedCell);
|
2018-09-11 15:10:54 +03:00
|
|
|
if (NS_WARN_IF(!inlineEditingCellElement)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
2011-10-30 00:03:55 +04:00
|
|
|
}
|
2003-06-25 12:50:48 +04:00
|
|
|
|
2018-09-11 15:10:54 +03:00
|
|
|
int32_t cellX = 0, cellY = 0;
|
|
|
|
GetElementOrigin(*mInlineEditedCell, cellX, cellY);
|
2003-06-25 12:50:48 +04:00
|
|
|
|
2018-09-11 15:10:54 +03:00
|
|
|
int32_t cellWidth = inlineEditingCellElement->OffsetWidth();
|
|
|
|
int32_t cellHeight = inlineEditingCellElement->OffsetHeight();
|
2003-06-25 12:50:48 +04:00
|
|
|
|
2018-09-11 15:10:54 +03:00
|
|
|
int32_t centerOfCellX = cellX + cellWidth / 2;
|
|
|
|
int32_t centerOfCellY = cellY + cellHeight / 2;
|
2003-06-25 12:50:48 +04:00
|
|
|
|
2017-12-15 19:14:54 +03:00
|
|
|
RefPtr<Element> tableElement = GetEnclosingTable(mInlineEditedCell);
|
2018-09-11 15:10:54 +03:00
|
|
|
int32_t rowCount = 0, colCount = 0;
|
2018-01-30 07:40:11 +03:00
|
|
|
nsresult rv = GetTableSize(tableElement, &rowCount, &colCount);
|
2018-09-11 15:10:54 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
2003-06-25 12:50:48 +04:00
|
|
|
|
2018-09-11 15:10:54 +03:00
|
|
|
RefPtr<Element> addColumunBeforeButton = mAddColumnBeforeButton.get();
|
|
|
|
SetAnonymousElementPosition(centerOfCellX - 10, cellY - 7,
|
|
|
|
addColumunBeforeButton);
|
|
|
|
if (NS_WARN_IF(addColumunBeforeButton != mAddColumnBeforeButton.get())) {
|
|
|
|
return NS_ERROR_FAILURE;
|
2003-06-25 12:50:48 +04:00
|
|
|
}
|
2018-09-11 15:10:54 +03:00
|
|
|
|
|
|
|
RefPtr<Element> removeColumnButton = mRemoveColumnButton.get();
|
|
|
|
SetAnonymousElementPosition(centerOfCellX - 4, cellY - 7, removeColumnButton);
|
|
|
|
if (NS_WARN_IF(removeColumnButton != mRemoveColumnButton.get())) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<Element> addColumnAfterButton = mAddColumnAfterButton.get();
|
|
|
|
SetAnonymousElementPosition(centerOfCellX + 6, cellY - 7,
|
|
|
|
addColumnAfterButton);
|
|
|
|
if (NS_WARN_IF(addColumnAfterButton != mAddColumnAfterButton.get())) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<Element> addRowBeforeButton = mAddRowBeforeButton.get();
|
|
|
|
SetAnonymousElementPosition(cellX - 7, centerOfCellY - 10,
|
|
|
|
addRowBeforeButton);
|
|
|
|
if (NS_WARN_IF(addRowBeforeButton != mAddRowBeforeButton.get())) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<Element> removeRowButton = mRemoveRowButton.get();
|
|
|
|
SetAnonymousElementPosition(cellX - 7, centerOfCellY - 4, removeRowButton);
|
|
|
|
if (NS_WARN_IF(removeRowButton != mRemoveRowButton.get())) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<Element> addRowAfterButton = mAddRowAfterButton.get();
|
|
|
|
SetAnonymousElementPosition(cellX - 7, centerOfCellY + 6, addRowAfterButton);
|
|
|
|
if (NS_WARN_IF(addRowAfterButton != mAddRowAfterButton.get())) {
|
|
|
|
return NS_ERROR_FAILURE;
|
2003-06-25 12:50:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-07-09 05:42:33 +03:00
|
|
|
} // namespace mozilla
|