| OLD | NEW |
| 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 "core/editing/EditingStrategy.h" | 5 #include "core/editing/EditingStrategy.h" |
| 6 | 6 |
| 7 #include "core/editing/EditingUtilities.h" | 7 #include "core/editing/EditingUtilities.h" |
| 8 #include "core/layout/LayoutObject.h" | 8 #include "core/layout/LayoutObject.h" |
| 9 | 9 |
| 10 namespace blink { | 10 namespace blink { |
| 11 | 11 |
| 12 // If a node can contain candidates for VisiblePositions, return the offset of | 12 // If a node can contain candidates for VisiblePositions, return the offset of |
| 13 // the last candidate, otherwise return the number of children for container | 13 // the last candidate, otherwise return the number of children for container |
| 14 // nodes and the length for unrendered text nodes. | 14 // nodes and the length for unrendered text nodes. |
| 15 template <typename Traversal> | 15 template <typename Traversal> |
| 16 int EditingAlgorithm<Traversal>::caretMaxOffset(const Node& node) { | 16 int EditingAlgorithm<Traversal>::caretMaxOffset(const Node& node) { |
| 17 // For rendered text nodes, return the last position that a caret could | 17 // For rendered text nodes, return the last position that a caret could |
| 18 // occupy. | 18 // occupy. |
| 19 if (node.isTextNode() && node.layoutObject()) | 19 if (node.isTextNode() && node.layoutObject()) |
| 20 return node.layoutObject()->caretMaxOffset(); | 20 return node.layoutObject()->caretMaxOffset(); |
| 21 // For containers return the number of children. For others do the same as | 21 // For containers return the number of children. For others do the same as |
| 22 // above. | 22 // above. |
| 23 return lastOffsetForEditing(&node); | 23 return lastOffsetForEditing(&node); |
| 24 } | 24 } |
| 25 | 25 |
| 26 template <typename Traversal> | 26 // TODO(yosin): We should move "isEmptyNonEditableNodeInEditable()" to |
| 27 bool EditingAlgorithm<Traversal>::isEmptyNonEditableNodeInEditable( | 27 // "EditingUtilities.cpp" |
| 28 const Node* node) { | 28 // |isEmptyNonEditableNodeInEditable()| is introduced for fixing |
| 29 // http://crbug.com/428986. |
| 30 static bool isEmptyNonEditableNodeInEditable(const Node* node) { |
| 29 // Editability is defined the DOM tree rather than the flat tree. For example: | 31 // Editability is defined the DOM tree rather than the flat tree. For example: |
| 30 // DOM: | 32 // DOM: |
| 31 // <host> | 33 // <host> |
| 32 // <span>unedittable</span> | 34 // <span>unedittable</span> |
| 33 // <shadowroot><div ce><content /></div></shadowroot> | 35 // <shadowroot><div ce><content /></div></shadowroot> |
| 34 // </host> | 36 // </host> |
| 35 // | 37 // |
| 36 // Flat Tree: | 38 // Flat Tree: |
| 37 // <host><div ce><span1>unedittable</span></div></host> | 39 // <host><div ce><span1>unedittable</span></div></host> |
| 38 // e.g. editing/shadow/breaking-editing-boundaries.html | 40 // e.g. editing/shadow/breaking-editing-boundaries.html |
| 39 return !Traversal::hasChildren(*node) && !hasEditableStyle(*node) && | 41 return !NodeTraversal::hasChildren(*node) && !hasEditableStyle(*node) && |
| 40 node->parentNode() && hasEditableStyle(*node->parentNode()); | 42 node->parentNode() && hasEditableStyle(*node->parentNode()); |
| 41 } | 43 } |
| 42 | 44 |
| 43 template <typename Traversal> | 45 // TODO(yosin): We should move "editingIgnoresContent()" to |
| 44 bool EditingAlgorithm<Traversal>::editingIgnoresContent(const Node* node) { | 46 // "EditingUtilities.cpp" |
| 47 // TODO(yosin) We should make |editingIgnoresContent()| to take |Node&| instead |
| 48 // |Node*|. |
| 49 // TODO(yosin): We should not use |isEmptyNonEditableNodeInEditable()| in |
| 50 // |editingIgnoresContent()| since |isEmptyNonEditableNodeInEditable()| |
| 51 // requires clean layout tree. |
| 52 bool editingIgnoresContent(const Node* node) { |
| 45 return !node->canContainRangeEndPoint() || | 53 return !node->canContainRangeEndPoint() || |
| 46 isEmptyNonEditableNodeInEditable(node); | 54 isEmptyNonEditableNodeInEditable(node); |
| 47 } | 55 } |
| 48 | 56 |
| 49 template <typename Traversal> | 57 template <typename Traversal> |
| 50 int EditingAlgorithm<Traversal>::lastOffsetForEditing(const Node* node) { | 58 int EditingAlgorithm<Traversal>::lastOffsetForEditing(const Node* node) { |
| 51 DCHECK(node); | 59 DCHECK(node); |
| 52 if (!node) | 60 if (!node) |
| 53 return 0; | 61 return 0; |
| 54 if (node->isCharacterDataNode()) | 62 if (node->isCharacterDataNode()) |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 candidateRoot = parent; | 96 candidateRoot = parent; |
| 89 parent = Strategy::parent(*candidateRoot); | 97 parent = Strategy::parent(*candidateRoot); |
| 90 } | 98 } |
| 91 return candidateRoot; | 99 return candidateRoot; |
| 92 } | 100 } |
| 93 | 101 |
| 94 template class CORE_TEMPLATE_EXPORT EditingAlgorithm<NodeTraversal>; | 102 template class CORE_TEMPLATE_EXPORT EditingAlgorithm<NodeTraversal>; |
| 95 template class CORE_TEMPLATE_EXPORT EditingAlgorithm<FlatTreeTraversal>; | 103 template class CORE_TEMPLATE_EXPORT EditingAlgorithm<FlatTreeTraversal>; |
| 96 | 104 |
| 97 } // namespace blink | 105 } // namespace blink |
| OLD | NEW |