Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(375)

Unified Diff: third_party/WebKit/Source/core/html/HTMLElement.cpp

Issue 2179273003: Implement spec-compliant HTMLElement.prototype.isContentEditable (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move isEditingHost and isEditable to HTMLElement.cpp Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/html/HTMLElement.cpp
diff --git a/third_party/WebKit/Source/core/html/HTMLElement.cpp b/third_party/WebKit/Source/core/html/HTMLElement.cpp
index 109e8b45a3b0c2aa45eade29c6a8d508673ddd28..861b41d0e4ee98c2309e53fe679e84493b01b16c 100644
--- a/third_party/WebKit/Source/core/html/HTMLElement.cpp
+++ b/third_party/WebKit/Source/core/html/HTMLElement.cpp
@@ -29,6 +29,7 @@
#include "core/CSSPropertyNames.h"
#include "core/CSSValueKeywords.h"
#include "core/HTMLNames.h"
+#include "core/MathMLNames.h"
#include "core/XMLNames.h"
#include "core/css/CSSColorValue.h"
#include "core/css/CSSMarkup.h"
@@ -58,6 +59,7 @@
#include "core/layout/LayoutBoxModelObject.h"
#include "core/layout/LayoutObject.h"
#include "core/page/SpatialNavigation.h"
+#include "core/svg/SVGSVGElement.h"
#include "platform/Language.h"
#include "platform/text/BidiResolver.h"
#include "platform/text/BidiTextRun.h"
@@ -72,6 +74,41 @@ using namespace WTF;
using namespace std;
+namespace {
+
+// https://w3c.github.io/editing/execCommand.html#editing-host
+bool isEditingHost(const Node& node)
+{
+ if (!node.isHTMLElement())
+ return false;
+ String normalizedValue = toHTMLElement(node).contentEditable();
+ if (normalizedValue == "true" || normalizedValue == "plaintext-only")
+ return true;
+ return node.document().inDesignMode() && node.document().documentElement() == &node;
+}
+
+// https://w3c.github.io/editing/execCommand.html#editable
+bool isEditable(const Node& node)
+{
+ if (isEditingHost(node))
+ return false;
+ if (node.isHTMLElement() && toHTMLElement(node).contentEditable() == "false")
+ return false;
+ if (!node.parentNode())
+ return false;
+ if (!isEditingHost(*node.parentNode()) && !isEditable(*node.parentNode()))
+ return false;
+ if (node.isHTMLElement())
+ return true;
+ if (isSVGSVGElement(node))
+ return true;
+ if (node.isElementNode() && toElement(node).hasTagName(MathMLNames::mathTag))
+ return true;
+ return !node.isElementNode() && node.parentNode()->isHTMLElement();
+}
+
+} // anonymous namespace
+
DEFINE_ELEMENT_FACTORY_WITH_TAGNAME(HTMLElement);
String HTMLElement::debugNodeName() const
@@ -587,9 +624,9 @@ void HTMLElement::setContentEditable(const String& enabled, ExceptionState& exce
exceptionState.throwDOMException(SyntaxError, "The value provided ('" + enabled + "') is not one of 'true', 'false', 'plaintext-only', or 'inherit'.");
}
-bool HTMLElement::isContentEditable() const
+bool HTMLElement::isContentEditableForBinding() const
{
- return blink::isContentEditable(*this);
+ return isEditingHost(*this) || isEditable(*this);
}
bool HTMLElement::draggable() const
« no previous file with comments | « third_party/WebKit/Source/core/html/HTMLElement.h ('k') | third_party/WebKit/Source/core/html/HTMLElement.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698