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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/editing/EditingStrategy.h ('k') | Source/core/editing/htmlediting.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/editing/EditingStrategy.cpp
diff --git a/Source/core/editing/EditingStrategy.cpp b/Source/core/editing/EditingStrategy.cpp
index e54d37ad14786f5565c73486288cc37d4a69ef20..8901830ee0a65dbad4b0fc3bc6c71e1a2113afd9 100644
--- a/Source/core/editing/EditingStrategy.cpp
+++ b/Source/core/editing/EditingStrategy.cpp
@@ -10,7 +10,48 @@
namespace blink {
template <typename Traversal>
-short comparePositionsAlgorithm(Node* containerA, int offsetA, Node* containerB, int offsetB, bool* disconnected)
+bool EditingAlgorithm<Traversal>::isEmptyNonEditableNodeInEditable(const Node* node)
+{
+ // Editability is defined the DOM tree rather than the composed tree. For example:
+ // DOM:
+ // <host><span>unedittable</span><shadowroot><div ce><content /></div></shadowroot></host>
+ // Composed Tree:
+ // <host><div ce><span1>unedittable</span></div></host>
+ // e.g. editing/shadow/breaking-editing-boundaries.html
+ return !Traversal::hasChildren(*node) && !node->hasEditableStyle() && node->parentNode() && node->parentNode()->hasEditableStyle();
+}
+
+template <typename Traversal>
+bool EditingAlgorithm<Traversal>::editingIgnoresContent(const Node* node)
+{
+ return !node->canContainRangeEndPoint() || isEmptyNonEditableNodeInEditable(node);
+}
+
+template <typename Traversal>
+int EditingAlgorithm<Traversal>::lastOffsetForEditing(const Node* node)
+{
+ ASSERT(node);
+ if (!node)
+ return 0;
+ if (node->offsetInCharacters())
+ return node->maxCharacterOffset();
+
+ if (Traversal::hasChildren(*node))
+ return Traversal::countChildren(*node);
+
+ // FIXME: Try return 0 here.
+
+ if (!editingIgnoresContent(node))
+ return 0;
+
+ // editingIgnoresContent uses the same logic in
+ // isEmptyNonEditableNodeInEditable (htmlediting.cpp). We don't understand
+ // why this function returns 1 even when the node doesn't have children.
+ return 1;
+}
+
+template <typename Traversal>
+short EditingAlgorithm<Traversal>::comparePositions(Node* containerA, int offsetA, Node* containerB, int offsetB, bool* disconnected)
{
ASSERT(containerA);
ASSERT(containerB);
@@ -104,19 +145,6 @@ short comparePositionsAlgorithm(Node* containerA, int offsetA, Node* containerB,
return 0;
}
-short EditingStrategy:: comparePositions(Node* containerA, int offsetA, Node* containerB, int offsetB, bool* disconnected)
-{
- return comparePositionsAlgorithm<NodeTraversal>(containerA, offsetA, containerB, offsetB, disconnected);
-}
-
-bool EditingStrategy::editingIgnoresContent(const Node* node)
-{
- return ::blink::editingIgnoresContent(node);
-}
-
-int EditingStrategy::lastOffsetForEditing(const Node* node)
-{
- return ::blink::lastOffsetForEditing(node);
-}
+template class EditingAlgorithm<NodeTraversal>;
} // namespace blink
« 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