Bug 1732845 - Add nsINode::IsInDesignMode() to check whether the node is directly in design mode r=smaug

There are a lot of check of `Document`'s editable state **with** comments. This
means that it's unclear for developers that only `Document` node is editable in
design mode.

Additionally, there are some points which use composed document rather than
uncomposed document even though the raw API uses uncomposed document. Comparing
with the other browsers, checking uncomposed document is compatible behavior,
i.e., nodes in shadow trees are not editable unless `contenteditable`.

Therefore, `nsINode` should have a method to check whether it's in design mode
or not.

Note that it may be called with a node in UA widget.  Therefore, this patch
adds new checks if it's in UA widget subtree or native anonymous subtree,
checking whether it's in design mode with its host.

Differential Revision: https://phabricator.services.mozilla.com/D126764
This commit is contained in:
Masayuki Nakano
2021-10-12 03:14:43 +00:00
parent f61d17c203
commit ffa5244e07
25 changed files with 524 additions and 93 deletions

View File

@@ -6,6 +6,7 @@
#include "mozilla/EventStates.h"
#include "mozilla/dom/BindContext.h"
#include "mozilla/dom/Document.h"
#include "mozilla/dom/HTMLObjectElement.h"
#include "mozilla/dom/HTMLObjectElementBinding.h"
#include "mozilla/dom/ElementInlines.h"
@@ -13,7 +14,7 @@
#include "nsAttrValueInlines.h"
#include "nsGkAtoms.h"
#include "nsError.h"
#include "mozilla/dom/Document.h"
#include "nsIContentInlines.h"
#include "nsIWidget.h"
#include "nsContentUtils.h"
#ifdef XP_MACOSX
@@ -164,7 +165,7 @@ bool HTMLObjectElement::IsHTMLFocusable(bool aWithMouse, bool* aIsFocusable,
// TODO: this should probably be managed directly by IsHTMLFocusable.
// See bug 597242.
Document* doc = GetComposedDoc();
if (!doc || doc->HasFlag(NODE_IS_EDITABLE)) {
if (!doc || IsInDesignMode()) {
if (aTabIndex) {
*aTabIndex = -1;
}