| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights | 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights |
| 3 * reserved. | 3 * reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 bool editable = HasEditableStyle(*node, editable_type); | 105 bool editable = HasEditableStyle(*node, editable_type); |
| 106 node = NextAtomicLeafNode(*node); | 106 node = NextAtomicLeafNode(*node); |
| 107 while (node) { | 107 while (node) { |
| 108 if (editable == HasEditableStyle(*node, editable_type)) | 108 if (editable == HasEditableStyle(*node, editable_type)) |
| 109 return node; | 109 return node; |
| 110 node = NextAtomicLeafNode(*node); | 110 node = NextAtomicLeafNode(*node); |
| 111 } | 111 } |
| 112 return nullptr; | 112 return nullptr; |
| 113 } | 113 } |
| 114 | 114 |
| 115 InlineBox* FindRightNonPseudoNodeInlineBox(const RootInlineBox& root_box) { |
| 116 for (InlineBox* runner = root_box.FirstLeafChild(); runner; |
| 117 runner = runner->NextLeafChild()) { |
| 118 if (runner->GetLineLayoutItem().NonPseudoNode()) |
| 119 return runner; |
| 120 } |
| 121 return nullptr; |
| 122 } |
| 123 |
| 115 enum LineEndpointComputationMode { kUseLogicalOrdering, kUseInlineBoxOrdering }; | 124 enum LineEndpointComputationMode { kUseLogicalOrdering, kUseInlineBoxOrdering }; |
| 116 template <typename Strategy> | 125 template <typename Strategy> |
| 117 PositionWithAffinityTemplate<Strategy> StartPositionForLine( | 126 PositionWithAffinityTemplate<Strategy> StartPositionForLine( |
| 118 const PositionWithAffinityTemplate<Strategy>& c, | 127 const PositionWithAffinityTemplate<Strategy>& c, |
| 119 LineEndpointComputationMode mode) { | 128 LineEndpointComputationMode mode) { |
| 120 if (c.IsNull()) | 129 if (c.IsNull()) |
| 121 return PositionWithAffinityTemplate<Strategy>(); | 130 return PositionWithAffinityTemplate<Strategy>(); |
| 122 | 131 |
| 123 RootInlineBox* root_box = | 132 RootInlineBox* root_box = |
| 124 RenderedPosition(c.GetPosition(), c.Affinity()).RootBox(); | 133 RenderedPosition(c.GetPosition(), c.Affinity()).RootBox(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 137 Node* start_node; | 146 Node* start_node; |
| 138 InlineBox* start_box; | 147 InlineBox* start_box; |
| 139 if (mode == kUseLogicalOrdering) { | 148 if (mode == kUseLogicalOrdering) { |
| 140 start_node = root_box->GetLogicalStartBoxWithNode(start_box); | 149 start_node = root_box->GetLogicalStartBoxWithNode(start_box); |
| 141 if (!start_node) | 150 if (!start_node) |
| 142 return PositionWithAffinityTemplate<Strategy>(); | 151 return PositionWithAffinityTemplate<Strategy>(); |
| 143 } else { | 152 } else { |
| 144 // Generated content (e.g. list markers and CSS :before and :after | 153 // Generated content (e.g. list markers and CSS :before and :after |
| 145 // pseudoelements) have no corresponding DOM element, and so cannot be | 154 // pseudoelements) have no corresponding DOM element, and so cannot be |
| 146 // represented by a VisiblePosition. Use whatever follows instead. | 155 // represented by a VisiblePosition. Use whatever follows instead. |
| 147 start_box = root_box->FirstLeafChild(); | 156 // TODO(editing-dev): We should consider text-direction of line to |
| 148 while (true) { | 157 // find non-pseudo node. |
| 149 if (!start_box) | 158 start_box = FindRightNonPseudoNodeInlineBox(*root_box); |
| 150 return PositionWithAffinityTemplate<Strategy>(); | 159 if (!start_box) |
| 151 | 160 return PositionWithAffinityTemplate<Strategy>(); |
| 152 start_node = start_box->GetLineLayoutItem().NonPseudoNode(); | 161 start_node = start_box->GetLineLayoutItem().NonPseudoNode(); |
| 153 if (start_node) | |
| 154 break; | |
| 155 | |
| 156 start_box = start_box->NextLeafChild(); | |
| 157 } | |
| 158 } | 162 } |
| 159 | 163 |
| 160 return PositionWithAffinityTemplate<Strategy>( | 164 return PositionWithAffinityTemplate<Strategy>( |
| 161 start_node->IsTextNode() | 165 start_node->IsTextNode() |
| 162 ? PositionTemplate<Strategy>(ToText(start_node), | 166 ? PositionTemplate<Strategy>(ToText(start_node), |
| 163 ToInlineTextBox(start_box)->Start()) | 167 ToInlineTextBox(start_box)->Start()) |
| 164 : PositionTemplate<Strategy>::BeforeNode(start_node)); | 168 : PositionTemplate<Strategy>::BeforeNode(start_node)); |
| 165 } | 169 } |
| 166 | 170 |
| 167 template <typename Strategy> | 171 template <typename Strategy> |
| (...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 680 // to the end of the line we're on. | 684 // to the end of the line we're on. |
| 681 Element* root_element = HasEditableStyle(*node, editable_type) | 685 Element* root_element = HasEditableStyle(*node, editable_type) |
| 682 ? RootEditableElement(*node, editable_type) | 686 ? RootEditableElement(*node, editable_type) |
| 683 : node->GetDocument().documentElement(); | 687 : node->GetDocument().documentElement(); |
| 684 if (!root_element) | 688 if (!root_element) |
| 685 return VisiblePosition(); | 689 return VisiblePosition(); |
| 686 return VisiblePosition::LastPositionInNode(root_element); | 690 return VisiblePosition::LastPositionInNode(root_element); |
| 687 } | 691 } |
| 688 | 692 |
| 689 } // namespace blink | 693 } // namespace blink |
| OLD | NEW |