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

Side by Side Diff: third_party/WebKit/Source/core/editing/EditingUtilities.cpp

Issue 2179273003: Implement spec-compliant HTMLElement.prototype.isContentEditable (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. 2 * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution. 11 * documentation and/or other materials provided with the distribution.
12 * 12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */ 24 */
25 25
26 #include "core/editing/EditingUtilities.h" 26 #include "core/editing/EditingUtilities.h"
27 27
28 #include "core/HTMLElementFactory.h" 28 #include "core/HTMLElementFactory.h"
29 #include "core/HTMLNames.h" 29 #include "core/HTMLNames.h"
30 #include "core/MathMLNames.h"
30 #include "core/dom/Document.h" 31 #include "core/dom/Document.h"
31 #include "core/dom/ElementTraversal.h" 32 #include "core/dom/ElementTraversal.h"
32 #include "core/dom/NodeComputedStyle.h" 33 #include "core/dom/NodeComputedStyle.h"
33 #include "core/dom/Range.h" 34 #include "core/dom/Range.h"
34 #include "core/dom/Text.h" 35 #include "core/dom/Text.h"
35 #include "core/dom/shadow/ShadowRoot.h" 36 #include "core/dom/shadow/ShadowRoot.h"
36 #include "core/editing/EditingStrategy.h" 37 #include "core/editing/EditingStrategy.h"
37 #include "core/editing/Editor.h" 38 #include "core/editing/Editor.h"
38 #include "core/editing/PlainTextRange.h" 39 #include "core/editing/PlainTextRange.h"
39 #include "core/editing/PositionIterator.h" 40 #include "core/editing/PositionIterator.h"
(...skipping 10 matching lines...) Expand all
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/HTMLDivElement.h" 53 #include "core/html/HTMLDivElement.h"
53 #include "core/html/HTMLLIElement.h" 54 #include "core/html/HTMLLIElement.h"
54 #include "core/html/HTMLParagraphElement.h" 55 #include "core/html/HTMLParagraphElement.h"
55 #include "core/html/HTMLSpanElement.h" 56 #include "core/html/HTMLSpanElement.h"
56 #include "core/html/HTMLTableCellElement.h" 57 #include "core/html/HTMLTableCellElement.h"
57 #include "core/html/HTMLUListElement.h" 58 #include "core/html/HTMLUListElement.h"
58 #include "core/layout/LayoutObject.h" 59 #include "core/layout/LayoutObject.h"
59 #include "core/layout/LayoutTableCell.h" 60 #include "core/layout/LayoutTableCell.h"
61 #include "core/svg/SVGSVGElement.h"
60 #include "wtf/Assertions.h" 62 #include "wtf/Assertions.h"
61 #include "wtf/StdLibExtras.h" 63 #include "wtf/StdLibExtras.h"
62 #include "wtf/text/StringBuilder.h" 64 #include "wtf/text/StringBuilder.h"
63 #include "wtf/text/Unicode.h" 65 #include "wtf/text/Unicode.h"
64 66
65 namespace blink { 67 namespace blink {
66 68
67 using namespace HTMLNames; 69 using namespace HTMLNames;
68 70
69 namespace { 71 namespace {
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 if (editableLevel == RichlyEditable) 294 if (editableLevel == RichlyEditable)
293 return false; 295 return false;
294 296
295 // FIXME(dmazzoni): support ScopedAXObjectCache (crbug/489851). 297 // FIXME(dmazzoni): support ScopedAXObjectCache (crbug/489851).
296 if (AXObjectCache* cache = node.document().existingAXObjectCache()) 298 if (AXObjectCache* cache = node.document().existingAXObjectCache())
297 return cache->rootAXEditableElement(&node); 299 return cache->rootAXEditableElement(&node);
298 300
299 return false; 301 return false;
300 } 302 }
301 303
304 bool isEditingHost(const Node& node)
305 {
306 if (!node.isHTMLElement())
307 return false;
308 String ceValue = toHTMLElement(node).contentEditable();
309 if (ceValue == "true" || ceValue == "plaintext-only")
310 return true;
311 if (node.document().inDesignMode() && node.document().documentElement() == & node)
312 return true;
313 return false;
314 }
yoichio 2016/07/27 01:29:35 If these functions are just for HTMLEelement::isCo
315
316 bool isEditable(const Node& node)
317 {
318 if (isEditingHost(node))
319 return false;
320 if (node.isHTMLElement() && toHTMLElement(node).contentEditable() == "false" )
321 return false;
322 if (!node.parentNode())
323 return false;
324 if (!isEditingHost(*node.parentNode()) && !isEditable(*node.parentNode()))
325 return false;
326 if (node.isHTMLElement())
327 return true;
328 if (isSVGSVGElement(node))
329 return true;
330 if (node.isElementNode() && toElement(node).hasTagName(MathMLNames::mathTag) )
331 return true;
332 if (!node.isElementNode() && node.parentNode()->isHTMLElement())
333 return true;
334 return false;
335 }
336
302 bool isContentEditable(const Node& node) 337 bool isContentEditable(const Node& node)
303 { 338 {
304 node.document().updateStyleAndLayoutTree(); 339 node.document().updateStyleAndLayoutTree();
305 return blink::hasEditableStyle(node, Editable); 340 return blink::hasEditableStyle(node, Editable);
306 } 341 }
307 342
308 bool isContentRichlyEditable(const Node& node) 343 bool isContentRichlyEditable(const Node& node)
309 { 344 {
310 node.document().updateStyleAndLayoutTree(); 345 node.document().updateStyleAndLayoutTree();
311 return blink::hasEditableStyle(node, RichlyEditable); 346 return blink::hasEditableStyle(node, RichlyEditable);
(...skipping 1612 matching lines...) Expand 10 before | Expand all | Expand 10 after
1924 { 1959 {
1925 if (!RuntimeEnabledFeatures::inputEventEnabled()) 1960 if (!RuntimeEnabledFeatures::inputEventEnabled())
1926 return DispatchEventResult::NotCanceled; 1961 return DispatchEventResult::NotCanceled;
1927 if (!target) 1962 if (!target)
1928 return DispatchEventResult::NotCanceled; 1963 return DispatchEventResult::NotCanceled;
1929 InputEvent* beforeInputEvent = InputEvent::createBeforeInput(inputType, data , InputEvent::EventCancelable::IsCancelable, InputEvent::EventIsComposing::NotCo mposing, ranges); 1964 InputEvent* beforeInputEvent = InputEvent::createBeforeInput(inputType, data , InputEvent::EventCancelable::IsCancelable, InputEvent::EventIsComposing::NotCo mposing, ranges);
1930 return target->dispatchEvent(beforeInputEvent); 1965 return target->dispatchEvent(beforeInputEvent);
1931 } 1966 }
1932 1967
1933 } // namespace blink 1968 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698