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

Side by Side Diff: Source/core/editing/EditingStrategy.cpp

Issue 1085163002: Introduce EditingAlgorithm<Traversal> class (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: 2015-04-15T16:50:42 Rebase for Position.h updates Created 5 years, 8 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
« no previous file with comments | « Source/core/editing/EditingStrategy.h ('k') | Source/core/editing/htmlediting.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "config.h" 5 #include "config.h"
6 #include "core/editing/EditingStrategy.h" 6 #include "core/editing/EditingStrategy.h"
7 7
8 #include "core/editing/htmlediting.h" 8 #include "core/editing/htmlediting.h"
9 9
10 namespace blink { 10 namespace blink {
11 11
12 template <typename Traversal> 12 template <typename Traversal>
13 short comparePositionsAlgorithm(Node* containerA, int offsetA, Node* containerB, int offsetB, bool* disconnected) 13 bool EditingAlgorithm<Traversal>::isEmptyNonEditableNodeInEditable(const Node* n ode)
14 {
15 // Editability is defined the DOM tree rather than the composed tree. For ex ample:
16 // DOM:
17 // <host><span>unedittable</span><shadowroot><div ce><content /></div></sh adowroot></host>
18 // Composed Tree:
19 // <host><div ce><span1>unedittable</span></div></host>
20 // e.g. editing/shadow/breaking-editing-boundaries.html
21 return !Traversal::hasChildren(*node) && !node->hasEditableStyle() && node-> parentNode() && node->parentNode()->hasEditableStyle();
22 }
23
24 template <typename Traversal>
25 bool EditingAlgorithm<Traversal>::editingIgnoresContent(const Node* node)
26 {
27 return !node->canContainRangeEndPoint() || isEmptyNonEditableNodeInEditable( node);
28 }
29
30 template <typename Traversal>
31 int EditingAlgorithm<Traversal>::lastOffsetForEditing(const Node* node)
32 {
33 ASSERT(node);
34 if (!node)
35 return 0;
36 if (node->offsetInCharacters())
37 return node->maxCharacterOffset();
38
39 if (Traversal::hasChildren(*node))
40 return Traversal::countChildren(*node);
41
42 // FIXME: Try return 0 here.
43
44 if (!editingIgnoresContent(node))
45 return 0;
46
47 // editingIgnoresContent uses the same logic in
48 // isEmptyNonEditableNodeInEditable (htmlediting.cpp). We don't understand
49 // why this function returns 1 even when the node doesn't have children.
50 return 1;
51 }
52
53 template <typename Traversal>
54 short EditingAlgorithm<Traversal>::comparePositions(Node* containerA, int offset A, Node* containerB, int offsetB, bool* disconnected)
14 { 55 {
15 ASSERT(containerA); 56 ASSERT(containerA);
16 ASSERT(containerB); 57 ASSERT(containerB);
17 58
18 if (disconnected) 59 if (disconnected)
19 *disconnected = false; 60 *disconnected = false;
20 61
21 if (!containerA) 62 if (!containerA)
22 return -1; 63 return -1;
23 if (!containerB) 64 if (!containerB)
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 if (n == childB) 138 if (n == childB)
98 return 1; // A is after B 139 return 1; // A is after B
99 n = Traversal::nextSibling(*n); 140 n = Traversal::nextSibling(*n);
100 } 141 }
101 142
102 // Should never reach this point. 143 // Should never reach this point.
103 ASSERT_NOT_REACHED(); 144 ASSERT_NOT_REACHED();
104 return 0; 145 return 0;
105 } 146 }
106 147
107 short EditingStrategy:: comparePositions(Node* containerA, int offsetA, Node* co ntainerB, int offsetB, bool* disconnected) 148 template class EditingAlgorithm<NodeTraversal>;
108 {
109 return comparePositionsAlgorithm<NodeTraversal>(containerA, offsetA, contain erB, offsetB, disconnected);
110 }
111
112 bool EditingStrategy::editingIgnoresContent(const Node* node)
113 {
114 return ::blink::editingIgnoresContent(node);
115 }
116
117 int EditingStrategy::lastOffsetForEditing(const Node* node)
118 {
119 return ::blink::lastOffsetForEditing(node);
120 }
121 149
122 } // namespace blink 150 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/editing/EditingStrategy.h ('k') | Source/core/editing/htmlediting.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698