2003-01-16 17:59:09 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
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-01-16 17:59:09 +03:00
|
|
|
|
2016-08-24 15:53:52 +03:00
|
|
|
#include "mozilla/HTMLEditor.h" // for HTMLEditor
|
2019-02-21 14:16:27 +03:00
|
|
|
#include "mozilla/HTMLEditorCommands.h" // for SetDocumentStateCommand, etc
|
2017-08-07 12:27:16 +03:00
|
|
|
#include "mozilla/TextEditor.h" // for TextEditor
|
2018-07-17 18:30:05 +03:00
|
|
|
#include "nsCommandParams.h" // for nsCommandParams
|
2012-07-13 10:33:42 +04:00
|
|
|
#include "nsCOMPtr.h" // for nsCOMPtr, do_QueryInterface, etc
|
|
|
|
#include "nsCRT.h" // for nsCRT
|
|
|
|
#include "nsDebug.h" // for NS_ENSURE_ARG_POINTER, etc
|
|
|
|
#include "nsError.h" // for NS_ERROR_INVALID_ARG, etc
|
|
|
|
#include "nsIDocShell.h" // for nsIDocShell
|
2019-01-02 16:05:23 +03:00
|
|
|
#include "mozilla/dom/Document.h" // for Document
|
2012-07-13 10:33:42 +04:00
|
|
|
#include "nsIEditingSession.h" // for nsIEditingSession, etc
|
|
|
|
#include "nsIEditor.h" // for nsIEditor
|
|
|
|
#include "nsIPlaintextEditor.h" // for nsIPlaintextEditor, etc
|
|
|
|
#include "nsISelectionController.h" // for nsISelectionController
|
|
|
|
#include "nsISupportsImpl.h" // for nsPresContext::Release
|
|
|
|
#include "nsISupportsUtils.h" // for NS_IF_ADDREF
|
|
|
|
#include "nsIURI.h" // for nsIURI
|
|
|
|
#include "nsPresContext.h" // for nsPresContext
|
|
|
|
#include "nscore.h" // for NS_IMETHODIMP, nsresult, etc
|
2003-01-16 17:59:09 +03:00
|
|
|
|
2012-07-13 10:33:42 +04:00
|
|
|
class nsISupports;
|
2003-01-16 17:59:09 +03:00
|
|
|
|
|
|
|
// defines
|
|
|
|
#define STATE_ENABLED "state_enabled"
|
2012-03-23 23:03:42 +04:00
|
|
|
#define STATE_ALL "state_all"
|
2003-01-16 17:59:09 +03:00
|
|
|
#define STATE_ATTRIBUTE "state_attribute"
|
|
|
|
#define STATE_DATA "state_data"
|
|
|
|
|
2018-06-15 19:13:31 +03:00
|
|
|
namespace mozilla {
|
2003-04-15 17:53:51 +04:00
|
|
|
|
2003-01-16 17:59:09 +03:00
|
|
|
/**
|
|
|
|
* Commands for document state that may be changed via doCommandParams
|
|
|
|
* As of 11/11/02, this is just "cmd_setDocumentModified"
|
|
|
|
* Note that you can use the same command class, nsSetDocumentStateCommand,
|
|
|
|
* for more than one of this type of command
|
|
|
|
* We check the input command param for different behavior
|
|
|
|
*/
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2018-06-15 19:13:31 +03:00
|
|
|
SetDocumentStateCommand::IsCommandEnabled(const char* aCommandName,
|
|
|
|
nsISupports* refCon,
|
|
|
|
bool* outCmdEnabled) {
|
2018-07-17 18:30:05 +03:00
|
|
|
if (NS_WARN_IF(!outCmdEnabled)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
2012-06-21 16:05:24 +04:00
|
|
|
// These commands are always enabled
|
|
|
|
*outCmdEnabled = true;
|
2003-01-16 17:59:09 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2018-06-15 19:13:31 +03:00
|
|
|
SetDocumentStateCommand::DoCommand(const char* aCommandName,
|
|
|
|
nsISupports* refCon) {
|
2003-01-16 17:59:09 +03:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2018-06-15 19:13:31 +03:00
|
|
|
SetDocumentStateCommand::DoCommandParams(const char* aCommandName,
|
|
|
|
nsICommandParams* aParams,
|
|
|
|
nsISupports* refCon) {
|
2018-07-17 18:30:05 +03:00
|
|
|
if (NS_WARN_IF(!aParams)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
2003-01-16 17:59:09 +03:00
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
|
2017-08-07 12:27:16 +03:00
|
|
|
if (NS_WARN_IF(!editor)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
TextEditor* textEditor = editor->AsTextEditor();
|
|
|
|
MOZ_ASSERT(textEditor);
|
2003-01-16 17:59:09 +03:00
|
|
|
|
2018-07-17 18:30:05 +03:00
|
|
|
nsCommandParams* params = aParams->AsCommandParams();
|
2003-01-16 17:59:09 +03:00
|
|
|
|
2018-07-17 18:30:05 +03:00
|
|
|
if (!nsCRT::strcmp(aCommandName, "cmd_setDocumentModified")) {
|
|
|
|
ErrorResult error;
|
|
|
|
bool modified = params->GetBool(STATE_ATTRIBUTE, error);
|
2003-01-16 17:59:09 +03:00
|
|
|
// Should we fail if this param wasn't set?
|
|
|
|
// I'm not sure we should be that strict
|
2018-07-17 18:30:05 +03:00
|
|
|
if (NS_WARN_IF(error.Failed())) {
|
|
|
|
return error.StealNSResult();
|
|
|
|
}
|
2016-10-24 05:27:45 +03:00
|
|
|
if (modified) {
|
2018-07-17 18:30:05 +03:00
|
|
|
nsresult rv = textEditor->IncrementModificationCount(1);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
2016-10-24 05:27:45 +03:00
|
|
|
}
|
2018-07-17 18:30:05 +03:00
|
|
|
nsresult rv = textEditor->ResetModificationCount();
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
2003-01-16 17:59:09 +03:00
|
|
|
}
|
2005-06-02 07:11:35 +04:00
|
|
|
|
2016-10-24 05:27:45 +03:00
|
|
|
if (!nsCRT::strcmp(aCommandName, "cmd_setDocumentReadOnly")) {
|
2018-07-17 18:30:05 +03:00
|
|
|
ErrorResult error;
|
|
|
|
bool isReadOnly = params->GetBool(STATE_ATTRIBUTE, error);
|
|
|
|
if (NS_WARN_IF(error.Failed())) {
|
|
|
|
return error.StealNSResult();
|
|
|
|
}
|
|
|
|
if (isReadOnly) {
|
|
|
|
nsresult rv =
|
|
|
|
textEditor->AddFlags(nsIPlaintextEditor::eEditorReadonlyMask);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
nsresult rv =
|
2017-08-08 06:36:29 +03:00
|
|
|
textEditor->RemoveFlags(nsIPlaintextEditor::eEditorReadonlyMask);
|
2018-07-17 18:30:05 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
2003-01-16 17:59:09 +03:00
|
|
|
}
|
2005-06-02 07:11:35 +04:00
|
|
|
|
2016-10-24 05:27:45 +03:00
|
|
|
if (!nsCRT::strcmp(aCommandName, "cmd_setDocumentUseCSS")) {
|
2017-08-07 12:27:16 +03:00
|
|
|
HTMLEditor* htmlEditor = textEditor->AsHTMLEditor();
|
|
|
|
if (NS_WARN_IF(!htmlEditor)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
2018-07-17 18:30:05 +03:00
|
|
|
ErrorResult error;
|
|
|
|
bool desireCSS = params->GetBool(STATE_ATTRIBUTE, error);
|
|
|
|
if (NS_WARN_IF(error.Failed())) {
|
|
|
|
return error.StealNSResult();
|
|
|
|
}
|
|
|
|
nsresult rv = htmlEditor->SetIsCSSEnabled(desireCSS);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
2003-01-16 17:59:09 +03:00
|
|
|
}
|
|
|
|
|
2016-10-24 05:27:45 +03:00
|
|
|
if (!nsCRT::strcmp(aCommandName, "cmd_insertBrOnReturn")) {
|
2017-08-07 12:27:16 +03:00
|
|
|
HTMLEditor* htmlEditor = textEditor->AsHTMLEditor();
|
|
|
|
if (NS_WARN_IF(!htmlEditor)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
2018-07-17 18:30:05 +03:00
|
|
|
ErrorResult error;
|
|
|
|
bool insertBrOnReturn = params->GetBool(STATE_ATTRIBUTE, error);
|
|
|
|
if (NS_WARN_IF(error.Failed())) {
|
|
|
|
return error.StealNSResult();
|
|
|
|
}
|
|
|
|
nsresult rv =
|
|
|
|
htmlEditor->SetReturnInParagraphCreatesNewParagraph(!insertBrOnReturn);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
2005-06-02 07:11:35 +04:00
|
|
|
}
|
|
|
|
|
2016-08-24 15:53:52 +03:00
|
|
|
if (!nsCRT::strcmp(aCommandName, "cmd_defaultParagraphSeparator")) {
|
2017-08-07 12:27:16 +03:00
|
|
|
HTMLEditor* htmlEditor = textEditor->AsHTMLEditor();
|
|
|
|
if (NS_WARN_IF(!htmlEditor)) {
|
2016-08-24 15:53:52 +03:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
2018-07-10 12:04:46 +03:00
|
|
|
nsAutoCString newValue;
|
2018-07-17 18:30:05 +03:00
|
|
|
nsresult rv = params->GetCString(STATE_ATTRIBUTE, newValue);
|
2016-08-24 15:53:52 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (newValue.LowerCaseEqualsLiteral("div")) {
|
|
|
|
htmlEditor->SetDefaultParagraphSeparator(ParagraphSeparator::div);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
if (newValue.LowerCaseEqualsLiteral("p")) {
|
|
|
|
htmlEditor->SetDefaultParagraphSeparator(ParagraphSeparator::p);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
if (newValue.LowerCaseEqualsLiteral("br")) {
|
|
|
|
// Mozilla extension for backwards compatibility
|
|
|
|
htmlEditor->SetDefaultParagraphSeparator(ParagraphSeparator::br);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This should not be reachable from nsHTMLDocument::ExecCommand
|
|
|
|
NS_WARNING("Invalid default paragraph separator");
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
2016-10-24 05:27:45 +03:00
|
|
|
if (!nsCRT::strcmp(aCommandName, "cmd_enableObjectResizing")) {
|
2017-08-07 12:27:16 +03:00
|
|
|
HTMLEditor* htmlEditor = textEditor->AsHTMLEditor();
|
|
|
|
if (NS_WARN_IF(!htmlEditor)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
2018-07-17 18:30:05 +03:00
|
|
|
ErrorResult error;
|
|
|
|
bool enabled = params->GetBool(STATE_ATTRIBUTE, error);
|
|
|
|
if (NS_WARN_IF(error.Failed())) {
|
|
|
|
return error.StealNSResult();
|
|
|
|
}
|
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
|
|
|
htmlEditor->EnableObjectResizer(enabled);
|
2018-07-17 18:30:05 +03:00
|
|
|
return NS_OK;
|
2005-06-24 21:18:27 +04:00
|
|
|
}
|
|
|
|
|
2016-10-24 05:27:45 +03:00
|
|
|
if (!nsCRT::strcmp(aCommandName, "cmd_enableInlineTableEditing")) {
|
2017-08-07 12:27:16 +03:00
|
|
|
HTMLEditor* htmlEditor = textEditor->AsHTMLEditor();
|
|
|
|
if (NS_WARN_IF(!htmlEditor)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
2018-07-17 18:30:05 +03:00
|
|
|
ErrorResult error;
|
|
|
|
bool enabled = params->GetBool(STATE_ATTRIBUTE, error);
|
|
|
|
if (NS_WARN_IF(error.Failed())) {
|
|
|
|
return error.StealNSResult();
|
|
|
|
}
|
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
|
|
|
htmlEditor->EnableInlineTableEditor(enabled);
|
2018-07-17 18:30:05 +03:00
|
|
|
return NS_OK;
|
2005-06-24 21:18:27 +04:00
|
|
|
}
|
|
|
|
|
2018-04-04 16:27:49 +03:00
|
|
|
if (!nsCRT::strcmp(aCommandName, "cmd_enableAbsolutePositionEditing")) {
|
|
|
|
NS_ENSURE_ARG_POINTER(aParams);
|
|
|
|
HTMLEditor* htmlEditor = textEditor->AsHTMLEditor();
|
|
|
|
if (NS_WARN_IF(!htmlEditor)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
ErrorResult error;
|
|
|
|
bool enabled = params->GetBool(STATE_ATTRIBUTE, error);
|
|
|
|
if (NS_WARN_IF(error.Failed())) {
|
|
|
|
return error.StealNSResult();
|
|
|
|
}
|
|
|
|
htmlEditor->EnableAbsolutePositionEditor(enabled);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-01-16 17:59:09 +03:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2018-06-15 19:13:31 +03:00
|
|
|
SetDocumentStateCommand::GetCommandStateParams(const char* aCommandName,
|
|
|
|
nsICommandParams* aParams,
|
|
|
|
nsISupports* refCon) {
|
2018-07-17 18:30:05 +03:00
|
|
|
if (NS_WARN_IF(!aParams) || NS_WARN_IF(!refCon)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
2003-01-16 17:59:09 +03:00
|
|
|
|
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
|
|
|
// If the result is set to STATE_ALL as bool value, queryCommandState()
|
|
|
|
// returns the bool value.
|
|
|
|
// If the result is set to STATE_ATTRIBUTE as CString value,
|
|
|
|
// queryCommandValue() returns the string value.
|
|
|
|
// Otherwise, ignored.
|
|
|
|
|
2003-01-16 17:59:09 +03:00
|
|
|
// The base editor owns most state info
|
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
|
2017-08-07 12:27:16 +03:00
|
|
|
if (NS_WARN_IF(!editor)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
TextEditor* textEditor = editor->AsTextEditor();
|
|
|
|
MOZ_ASSERT(textEditor);
|
2003-01-16 17:59:09 +03:00
|
|
|
|
2018-07-17 18:30:05 +03:00
|
|
|
nsCommandParams* params = aParams->AsCommandParams();
|
|
|
|
|
2003-01-16 17:59:09 +03:00
|
|
|
// Always get the enabled state
|
2011-09-29 10:19:26 +04:00
|
|
|
bool outCmdEnabled = false;
|
2003-01-16 17:59:09 +03:00
|
|
|
IsCommandEnabled(aCommandName, refCon, &outCmdEnabled);
|
2018-07-17 18:30:05 +03:00
|
|
|
nsresult rv = params->SetBool(STATE_ENABLED, outCmdEnabled);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
2003-01-16 17:59:09 +03:00
|
|
|
|
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
|
|
|
// cmd_setDocumentModified is an internal command.
|
2016-10-24 05:27:45 +03:00
|
|
|
if (!nsCRT::strcmp(aCommandName, "cmd_setDocumentModified")) {
|
2011-09-29 10:19:26 +04:00
|
|
|
bool modified;
|
2017-08-07 12:27:16 +03:00
|
|
|
rv = textEditor->GetDocumentModified(&modified);
|
2018-07-17 18:30:05 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
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
|
|
|
// XXX Nobody refers this result due to wrong type.
|
2018-07-17 18:30:05 +03:00
|
|
|
rv = params->SetBool(STATE_ATTRIBUTE, modified);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
2003-01-16 17:59:09 +03:00
|
|
|
}
|
2005-06-02 07:11:35 +04:00
|
|
|
|
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
|
|
|
// cmd_setDocumentReadOnly is a Gecko specific command, "contentReadOnly".
|
2016-10-24 05:27:45 +03:00
|
|
|
if (!nsCRT::strcmp(aCommandName, "cmd_setDocumentReadOnly")) {
|
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
|
|
|
// XXX Nobody refers this result due to wrong type.
|
2018-07-17 18:30:05 +03:00
|
|
|
rv = params->SetBool(STATE_ATTRIBUTE, textEditor->IsReadonly());
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
2003-06-06 23:28:25 +04:00
|
|
|
}
|
2005-06-02 07:11:35 +04:00
|
|
|
|
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
|
|
|
// cmd_setDocumentUseCSS is a common command, "styleWithCSS".
|
2016-10-24 05:27:45 +03:00
|
|
|
if (!nsCRT::strcmp(aCommandName, "cmd_setDocumentUseCSS")) {
|
2017-08-07 12:27:16 +03:00
|
|
|
HTMLEditor* htmlEditor = textEditor->AsHTMLEditor();
|
|
|
|
if (NS_WARN_IF(!htmlEditor)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
2018-08-28 12:46:53 +03:00
|
|
|
rv = params->SetBool(STATE_ALL, htmlEditor->IsCSSEnabled());
|
2018-07-17 18:30:05 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
2003-06-06 23:28:25 +04:00
|
|
|
}
|
|
|
|
|
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
|
|
|
// cmd_insertBrOnReturn is a Gecko specific command, "insertBrOrReturn".
|
2016-10-24 05:27:45 +03:00
|
|
|
if (!nsCRT::strcmp(aCommandName, "cmd_insertBrOnReturn")) {
|
2017-08-07 12:27:16 +03:00
|
|
|
HTMLEditor* htmlEditor = textEditor->AsHTMLEditor();
|
|
|
|
if (NS_WARN_IF(!htmlEditor)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
2011-09-29 10:19:26 +04:00
|
|
|
bool createPOnReturn;
|
2017-08-07 12:27:16 +03:00
|
|
|
htmlEditor->GetReturnInParagraphCreatesNewParagraph(&createPOnReturn);
|
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
|
|
|
// XXX Nobody refers this result due to wrong type.
|
2018-07-17 18:30:05 +03:00
|
|
|
rv = params->SetBool(STATE_ATTRIBUTE, !createPOnReturn);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
2005-06-02 07:11:35 +04:00
|
|
|
}
|
|
|
|
|
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
|
|
|
// cmd_defaultParagraphSeparator is a common command,
|
|
|
|
// "defaultParagraphSeparator".
|
2016-08-24 15:53:52 +03:00
|
|
|
if (!nsCRT::strcmp(aCommandName, "cmd_defaultParagraphSeparator")) {
|
2017-08-07 12:27:16 +03:00
|
|
|
HTMLEditor* htmlEditor = textEditor->AsHTMLEditor();
|
|
|
|
if (NS_WARN_IF(!htmlEditor)) {
|
2016-08-24 15:53:52 +03:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (htmlEditor->GetDefaultParagraphSeparator()) {
|
2018-07-17 18:30:05 +03:00
|
|
|
case ParagraphSeparator::div: {
|
|
|
|
DebugOnly<nsresult> rv =
|
|
|
|
params->SetCString(STATE_ATTRIBUTE, NS_LITERAL_CSTRING("div"));
|
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
|
|
|
|
"Failed to set command params to return \"div\"");
|
2016-08-24 15:53:52 +03:00
|
|
|
return NS_OK;
|
2018-07-17 18:30:05 +03:00
|
|
|
}
|
|
|
|
case ParagraphSeparator::p: {
|
|
|
|
DebugOnly<nsresult> rv =
|
|
|
|
params->SetCString(STATE_ATTRIBUTE, NS_LITERAL_CSTRING("p"));
|
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
|
|
|
|
"Failed to set command params to return \"p\"");
|
2016-08-24 15:53:52 +03:00
|
|
|
return NS_OK;
|
2018-07-17 18:30:05 +03:00
|
|
|
}
|
|
|
|
case ParagraphSeparator::br: {
|
|
|
|
DebugOnly<nsresult> rv =
|
|
|
|
params->SetCString(STATE_ATTRIBUTE, NS_LITERAL_CSTRING("br"));
|
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
|
|
|
|
"Failed to set command params to return \"br\"");
|
2016-08-24 15:53:52 +03:00
|
|
|
return NS_OK;
|
2018-07-17 18:30:05 +03:00
|
|
|
}
|
2016-08-24 15:53:52 +03:00
|
|
|
default:
|
|
|
|
MOZ_ASSERT_UNREACHABLE("Invalid paragraph separator value");
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
// cmd_enableObjectResizing is a Gecko specific command,
|
|
|
|
// "enableObjectResizing".
|
2016-10-24 05:27:45 +03:00
|
|
|
if (!nsCRT::strcmp(aCommandName, "cmd_enableObjectResizing")) {
|
2017-08-07 12:27:16 +03:00
|
|
|
HTMLEditor* htmlEditor = textEditor->AsHTMLEditor();
|
|
|
|
if (NS_WARN_IF(!htmlEditor)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
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
|
|
|
// We returned the result as STATE_ATTRIBUTE with bool value 60 or earlier.
|
|
|
|
// So, the result was ignored by both nsHTMLDocument::QueryCommandValue()
|
|
|
|
// and nsHTMLDocument::QueryCommandState().
|
|
|
|
rv = params->SetBool(STATE_ALL, htmlEditor->IsObjectResizerEnabled());
|
2018-07-17 18:30:05 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
2005-06-24 21:18:27 +04:00
|
|
|
}
|
|
|
|
|
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
|
|
|
// cmd_enableInlineTableEditing is a Gecko specific command,
|
|
|
|
// "enableInlineTableEditing".
|
2016-10-24 05:27:45 +03:00
|
|
|
if (!nsCRT::strcmp(aCommandName, "cmd_enableInlineTableEditing")) {
|
2017-08-07 12:27:16 +03:00
|
|
|
HTMLEditor* htmlEditor = textEditor->AsHTMLEditor();
|
|
|
|
if (NS_WARN_IF(!htmlEditor)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
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
|
|
|
// We returned the result as STATE_ATTRIBUTE with bool value 60 or earlier.
|
|
|
|
// So, the result was ignored by both nsHTMLDocument::QueryCommandValue()
|
|
|
|
// and nsHTMLDocument::QueryCommandState().
|
|
|
|
rv = params->SetBool(STATE_ALL, htmlEditor->IsInlineTableEditorEnabled());
|
2018-07-17 18:30:05 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
2005-06-24 21:18:27 +04:00
|
|
|
}
|
|
|
|
|
2018-04-04 16:27:49 +03:00
|
|
|
// cmd_enableAbsolutePositionEditing is a Gecko specific command,
|
|
|
|
// "cenableAbsolutePositionEditing".
|
|
|
|
if (!nsCRT::strcmp(aCommandName, "cmd_enableAbsolutePositionEditing")) {
|
|
|
|
NS_ENSURE_ARG_POINTER(aParams);
|
|
|
|
HTMLEditor* htmlEditor = textEditor->AsHTMLEditor();
|
|
|
|
if (NS_WARN_IF(!htmlEditor)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
return params->SetBool(STATE_ALL,
|
|
|
|
htmlEditor->IsAbsolutePositionEditorEnabled());
|
|
|
|
}
|
|
|
|
|
2003-01-16 17:59:09 +03:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-05-28 18:58:42 +03:00
|
|
|
* Commands just for state notification
|
2003-01-16 17:59:09 +03:00
|
|
|
* As of 11/21/02, possible commands are:
|
|
|
|
* "obs_documentCreated"
|
|
|
|
* "obs_documentWillBeDestroyed"
|
|
|
|
* "obs_documentLocationChanged"
|
|
|
|
* Note that you can use the same command class, nsDocumentStateCommand
|
|
|
|
* for these or future observer commands.
|
|
|
|
* We check the input command param for different behavior
|
|
|
|
*
|
|
|
|
* How to use:
|
2019-04-03 15:51:38 +03:00
|
|
|
* 1. Get the nsCommandManager for the current editor
|
2003-01-16 17:59:09 +03:00
|
|
|
* 2. Implement an nsIObserve object, e.g:
|
|
|
|
*
|
2015-05-28 18:58:42 +03:00
|
|
|
* void Observe(
|
2019-04-03 15:51:38 +03:00
|
|
|
* in nsISupports aSubject, // The nsCommandManager calling this
|
2018-11-28 03:54:56 +03:00
|
|
|
* // Observer
|
2003-01-16 17:59:09 +03:00
|
|
|
* in string aTopic, // command name, e.g.:"obs_documentCreated"
|
|
|
|
* // or "obs_documentWillBeDestroyed"
|
|
|
|
in wstring aData ); // ignored (set to "command_status_changed")
|
|
|
|
*
|
|
|
|
* 3. Add the observer by:
|
|
|
|
* commandManager.addObserver(observeobject, obs_documentCreated);
|
2015-05-28 18:58:42 +03:00
|
|
|
* 4. In the appropriate location in editorSession, editor, or commands code,
|
2003-01-16 17:59:09 +03:00
|
|
|
* trigger the notification of this observer by something like:
|
|
|
|
*
|
2019-04-03 15:51:38 +03:00
|
|
|
* RefPtr<nsCommandManager> commandManager = mDocShell->GetCommandManager();
|
|
|
|
* commandManager->CommandStatusChanged(obs_documentCreated);
|
2003-01-16 17:59:09 +03:00
|
|
|
*
|
|
|
|
* 5. Use GetCommandStateParams() to obtain state information
|
2015-05-28 18:58:42 +03:00
|
|
|
* e.g., any creation state codes when creating an editor are
|
|
|
|
* supplied for "obs_documentCreated" command in the
|
2003-01-16 17:59:09 +03:00
|
|
|
* "state_data" param's value
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2018-06-15 19:13:31 +03:00
|
|
|
DocumentStateCommand::IsCommandEnabled(const char* aCommandName,
|
|
|
|
nsISupports* refCon,
|
|
|
|
bool* outCmdEnabled) {
|
2018-07-17 18:30:05 +03:00
|
|
|
if (NS_WARN_IF(!outCmdEnabled)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
2003-01-16 17:59:09 +03:00
|
|
|
// Always return false to discourage callers from using DoCommand()
|
2011-10-17 18:59:28 +04:00
|
|
|
*outCmdEnabled = false;
|
2003-01-16 17:59:09 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2018-06-15 19:13:31 +03:00
|
|
|
DocumentStateCommand::DoCommand(const char* aCommandName, nsISupports* refCon) {
|
2003-01-16 17:59:09 +03:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2018-06-15 19:13:31 +03:00
|
|
|
DocumentStateCommand::DoCommandParams(const char* aCommandName,
|
|
|
|
nsICommandParams* aParams,
|
|
|
|
nsISupports* refCon) {
|
2003-01-16 17:59:09 +03:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2018-06-15 19:13:31 +03:00
|
|
|
DocumentStateCommand::GetCommandStateParams(const char* aCommandName,
|
|
|
|
nsICommandParams* aParams,
|
|
|
|
nsISupports* refCon) {
|
2018-07-17 18:30:05 +03:00
|
|
|
if (NS_WARN_IF(!aParams) || NS_WARN_IF(!aCommandName)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCommandParams* params = aParams->AsCommandParams();
|
2003-01-16 17:59:09 +03:00
|
|
|
|
2016-10-24 05:27:45 +03:00
|
|
|
if (!nsCRT::strcmp(aCommandName, "obs_documentCreated")) {
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t editorStatus = nsIEditingSession::eEditorErrorUnknown;
|
2003-01-16 17:59:09 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIEditingSession> editingSession = do_QueryInterface(refCon);
|
2016-10-24 05:27:45 +03:00
|
|
|
if (editingSession) {
|
2003-01-16 17:59:09 +03:00
|
|
|
// refCon is initially set to nsIEditingSession until editor
|
|
|
|
// is successfully created and source doc is loaded
|
|
|
|
// Embedder gets error status if this fails
|
2015-05-28 18:58:42 +03:00
|
|
|
// If called before startup is finished,
|
2003-01-16 17:59:09 +03:00
|
|
|
// status = eEditorCreationInProgress
|
2018-07-17 18:30:05 +03:00
|
|
|
nsresult rv = editingSession->GetEditorStatus(&editorStatus);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
2016-10-24 05:27:45 +03:00
|
|
|
} else {
|
2003-01-16 17:59:09 +03:00
|
|
|
// If refCon is an editor, then everything started up OK!
|
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
|
2016-10-24 05:27:45 +03:00
|
|
|
if (editor) {
|
2003-01-16 17:59:09 +03:00
|
|
|
editorStatus = nsIEditingSession::eEditorOK;
|
2016-10-24 05:27:45 +03:00
|
|
|
}
|
2003-01-16 17:59:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Note that if refCon is not-null, but is neither
|
|
|
|
// an nsIEditingSession or nsIEditor, we return "eEditorErrorUnknown"
|
2018-07-17 18:30:05 +03:00
|
|
|
DebugOnly<nsresult> rv = params->SetInt(STATE_DATA, editorStatus);
|
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "Failed to set editor status");
|
2003-01-16 17:59:09 +03:00
|
|
|
return NS_OK;
|
2015-05-28 18:58:42 +03:00
|
|
|
}
|
2016-10-24 05:27:45 +03:00
|
|
|
|
|
|
|
if (!nsCRT::strcmp(aCommandName, "obs_documentLocationChanged")) {
|
2003-01-16 17:59:09 +03:00
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
|
2016-10-24 05:27:45 +03:00
|
|
|
if (!editor) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2017-08-07 12:27:16 +03:00
|
|
|
TextEditor* textEditor = editor->AsTextEditor();
|
|
|
|
MOZ_ASSERT(textEditor);
|
2003-01-16 17:59:09 +03:00
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
RefPtr<Document> doc = textEditor->GetDocument();
|
2018-07-17 18:30:05 +03:00
|
|
|
if (NS_WARN_IF(!doc)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
nsIURI* uri = doc->GetDocumentURI();
|
|
|
|
if (NS_WARN_IF(!uri)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
nsresult rv = params->SetISupports(STATE_DATA, uri);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
2015-05-28 18:58:42 +03:00
|
|
|
}
|
2003-01-16 17:59:09 +03:00
|
|
|
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
2018-06-15 19:13:31 +03:00
|
|
|
|
|
|
|
} // namespace mozilla
|