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

Side by Side 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, 4 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * Copyright (C) 2004-2008, 2013, 2014 Apple Inc. All rights reserved. 4 * Copyright (C) 2004-2008, 2013, 2014 Apple Inc. All rights reserved.
5 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/) 5 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/)
6 * Copyright (C) 2011 Motorola Mobility. All rights reserved. 6 * Copyright (C) 2011 Motorola Mobility. All rights reserved.
7 * 7 *
8 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public 9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
(...skipping 11 matching lines...) Expand all
22 * 22 *
23 */ 23 */
24 24
25 #include "core/html/HTMLElement.h" 25 #include "core/html/HTMLElement.h"
26 26
27 #include "bindings/core/v8/ExceptionState.h" 27 #include "bindings/core/v8/ExceptionState.h"
28 #include "bindings/core/v8/ScriptEventListener.h" 28 #include "bindings/core/v8/ScriptEventListener.h"
29 #include "core/CSSPropertyNames.h" 29 #include "core/CSSPropertyNames.h"
30 #include "core/CSSValueKeywords.h" 30 #include "core/CSSValueKeywords.h"
31 #include "core/HTMLNames.h" 31 #include "core/HTMLNames.h"
32 #include "core/MathMLNames.h"
32 #include "core/XMLNames.h" 33 #include "core/XMLNames.h"
33 #include "core/css/CSSColorValue.h" 34 #include "core/css/CSSColorValue.h"
34 #include "core/css/CSSMarkup.h" 35 #include "core/css/CSSMarkup.h"
35 #include "core/css/StylePropertySet.h" 36 #include "core/css/StylePropertySet.h"
36 #include "core/dom/DocumentFragment.h" 37 #include "core/dom/DocumentFragment.h"
37 #include "core/dom/ElementTraversal.h" 38 #include "core/dom/ElementTraversal.h"
38 #include "core/dom/ExceptionCode.h" 39 #include "core/dom/ExceptionCode.h"
39 #include "core/dom/NodeTraversal.h" 40 #include "core/dom/NodeTraversal.h"
40 #include "core/dom/StyleChangeReason.h" 41 #include "core/dom/StyleChangeReason.h"
41 #include "core/dom/Text.h" 42 #include "core/dom/Text.h"
42 #include "core/dom/shadow/ElementShadow.h" 43 #include "core/dom/shadow/ElementShadow.h"
43 #include "core/dom/shadow/FlatTreeTraversal.h" 44 #include "core/dom/shadow/FlatTreeTraversal.h"
44 #include "core/dom/shadow/ShadowRoot.h" 45 #include "core/dom/shadow/ShadowRoot.h"
45 #include "core/editing/EditingUtilities.h" 46 #include "core/editing/EditingUtilities.h"
46 #include "core/editing/serializers/Serialization.h" 47 #include "core/editing/serializers/Serialization.h"
47 #include "core/events/EventListener.h" 48 #include "core/events/EventListener.h"
48 #include "core/events/KeyboardEvent.h" 49 #include "core/events/KeyboardEvent.h"
49 #include "core/frame/Settings.h" 50 #include "core/frame/Settings.h"
50 #include "core/frame/UseCounter.h" 51 #include "core/frame/UseCounter.h"
51 #include "core/html/HTMLBRElement.h" 52 #include "core/html/HTMLBRElement.h"
52 #include "core/html/HTMLFormElement.h" 53 #include "core/html/HTMLFormElement.h"
53 #include "core/html/HTMLInputElement.h" 54 #include "core/html/HTMLInputElement.h"
54 #include "core/html/HTMLMenuElement.h" 55 #include "core/html/HTMLMenuElement.h"
55 #include "core/html/HTMLTemplateElement.h" 56 #include "core/html/HTMLTemplateElement.h"
56 #include "core/html/HTMLTextFormControlElement.h" 57 #include "core/html/HTMLTextFormControlElement.h"
57 #include "core/html/parser/HTMLParserIdioms.h" 58 #include "core/html/parser/HTMLParserIdioms.h"
58 #include "core/layout/LayoutBoxModelObject.h" 59 #include "core/layout/LayoutBoxModelObject.h"
59 #include "core/layout/LayoutObject.h" 60 #include "core/layout/LayoutObject.h"
60 #include "core/page/SpatialNavigation.h" 61 #include "core/page/SpatialNavigation.h"
62 #include "core/svg/SVGSVGElement.h"
61 #include "platform/Language.h" 63 #include "platform/Language.h"
62 #include "platform/text/BidiResolver.h" 64 #include "platform/text/BidiResolver.h"
63 #include "platform/text/BidiTextRun.h" 65 #include "platform/text/BidiTextRun.h"
64 #include "platform/text/TextRunIterator.h" 66 #include "platform/text/TextRunIterator.h"
65 #include "wtf/StdLibExtras.h" 67 #include "wtf/StdLibExtras.h"
66 #include "wtf/text/CString.h" 68 #include "wtf/text/CString.h"
67 69
68 namespace blink { 70 namespace blink {
69 71
70 using namespace HTMLNames; 72 using namespace HTMLNames;
71 using namespace WTF; 73 using namespace WTF;
72 74
73 using namespace std; 75 using namespace std;
74 76
77 namespace {
78
79 // https://w3c.github.io/editing/execCommand.html#editing-host
80 bool isEditingHost(const Node& node)
81 {
82 if (!node.isHTMLElement())
83 return false;
84 String normalizedValue = toHTMLElement(node).contentEditable();
85 if (normalizedValue == "true" || normalizedValue == "plaintext-only")
86 return true;
87 return node.document().inDesignMode() && node.document().documentElement() = = &node;
88 }
89
90 // https://w3c.github.io/editing/execCommand.html#editable
91 bool isEditable(const Node& node)
92 {
93 if (isEditingHost(node))
94 return false;
95 if (node.isHTMLElement() && toHTMLElement(node).contentEditable() == "false" )
96 return false;
97 if (!node.parentNode())
98 return false;
99 if (!isEditingHost(*node.parentNode()) && !isEditable(*node.parentNode()))
100 return false;
101 if (node.isHTMLElement())
102 return true;
103 if (isSVGSVGElement(node))
104 return true;
105 if (node.isElementNode() && toElement(node).hasTagName(MathMLNames::mathTag) )
106 return true;
107 return !node.isElementNode() && node.parentNode()->isHTMLElement();
108 }
109
110 } // anonymous namespace
111
75 DEFINE_ELEMENT_FACTORY_WITH_TAGNAME(HTMLElement); 112 DEFINE_ELEMENT_FACTORY_WITH_TAGNAME(HTMLElement);
76 113
77 String HTMLElement::debugNodeName() const 114 String HTMLElement::debugNodeName() const
78 { 115 {
79 if (document().isHTMLDocument()) { 116 if (document().isHTMLDocument()) {
80 return tagQName().hasPrefix() 117 return tagQName().hasPrefix()
81 ? Element::nodeName().upper() 118 ? Element::nodeName().upper()
82 : tagQName().localName().upper(); 119 : tagQName().localName().upper();
83 } 120 }
84 return Element::nodeName(); 121 return Element::nodeName();
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 else if (equalIgnoringCase(enabled, "false")) 617 else if (equalIgnoringCase(enabled, "false"))
581 setAttribute(contenteditableAttr, "false"); 618 setAttribute(contenteditableAttr, "false");
582 else if (equalIgnoringCase(enabled, "plaintext-only")) 619 else if (equalIgnoringCase(enabled, "plaintext-only"))
583 setAttribute(contenteditableAttr, "plaintext-only"); 620 setAttribute(contenteditableAttr, "plaintext-only");
584 else if (equalIgnoringCase(enabled, "inherit")) 621 else if (equalIgnoringCase(enabled, "inherit"))
585 removeAttribute(contenteditableAttr); 622 removeAttribute(contenteditableAttr);
586 else 623 else
587 exceptionState.throwDOMException(SyntaxError, "The value provided ('" + enabled + "') is not one of 'true', 'false', 'plaintext-only', or 'inherit'."); 624 exceptionState.throwDOMException(SyntaxError, "The value provided ('" + enabled + "') is not one of 'true', 'false', 'plaintext-only', or 'inherit'.");
588 } 625 }
589 626
590 bool HTMLElement::isContentEditable() const 627 bool HTMLElement::isContentEditableForBinding() const
591 { 628 {
592 return blink::isContentEditable(*this); 629 return isEditingHost(*this) || isEditable(*this);
593 } 630 }
594 631
595 bool HTMLElement::draggable() const 632 bool HTMLElement::draggable() const
596 { 633 {
597 return equalIgnoringCase(getAttribute(draggableAttr), "true"); 634 return equalIgnoringCase(getAttribute(draggableAttr), "true");
598 } 635 }
599 636
600 void HTMLElement::setDraggable(bool value) 637 void HTMLElement::setDraggable(bool value)
601 { 638 {
602 setAttribute(draggableAttr, value ? "true" : "false"); 639 setAttribute(draggableAttr, value ? "true" : "false");
(...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after
1109 #ifndef NDEBUG 1146 #ifndef NDEBUG
1110 1147
1111 // For use in the debugger 1148 // For use in the debugger
1112 void dumpInnerHTML(blink::HTMLElement*); 1149 void dumpInnerHTML(blink::HTMLElement*);
1113 1150
1114 void dumpInnerHTML(blink::HTMLElement* element) 1151 void dumpInnerHTML(blink::HTMLElement* element)
1115 { 1152 {
1116 printf("%s\n", element->innerHTML().ascii().data()); 1153 printf("%s\n", element->innerHTML().ascii().data());
1117 } 1154 }
1118 #endif 1155 #endif
OLDNEW
« 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