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

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

Issue 2944563002: Utilize InlineBoxTraversal in {Left,Right}PositionOf() left/right traversal (Closed)
Patch Set: 2017-06-16T12:38:41 Created 3 years, 6 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 13 matching lines...) Expand all
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */ 25 */
26 26
27 // Copyright 2017 The Chromium Authors. All rights reserved. 27 // Copyright 2017 The Chromium Authors. All rights reserved.
28 // Use of this source code is governed by a BSD-style license that can be 28 // Use of this source code is governed by a BSD-style license that can be
29 // found in the LICENSE file. 29 // found in the LICENSE file.
30 30
31 #include "core/editing/SelectionModifier.h" 31 #include "core/editing/SelectionModifier.h"
32 32
33 #include "core/editing/EditingUtilities.h" 33 #include "core/editing/EditingUtilities.h"
34 #include "core/editing/InlineBoxTraversal.h"
34 #include "core/editing/VisibleUnits.h" 35 #include "core/editing/VisibleUnits.h"
35 #include "core/layout/api/LineLayoutAPIShim.h" 36 #include "core/layout/api/LineLayoutAPIShim.h"
36 #include "core/layout/api/LineLayoutItem.h" 37 #include "core/layout/api/LineLayoutItem.h"
37 #include "core/layout/line/InlineTextBox.h" 38 #include "core/layout/line/InlineTextBox.h"
38 #include "core/layout/line/RootInlineBox.h" 39 #include "core/layout/line/RootInlineBox.h"
39 40
40 namespace blink { 41 namespace blink {
41 42
42 namespace { 43 namespace {
43 44
(...skipping 13 matching lines...) Expand all
57 static int CaretMinOffsetOf(TextDirection direction, const InlineBox& box) { 58 static int CaretMinOffsetOf(TextDirection direction, const InlineBox& box) {
58 if (direction == TextDirection::kLtr) 59 if (direction == TextDirection::kLtr)
59 return box.CaretMinOffset(); 60 return box.CaretMinOffset();
60 return box.CaretMaxOffset(); 61 return box.CaretMaxOffset();
61 } 62 }
62 63
63 static int CaretStartOffsetOf(const InlineBox& box) { 64 static int CaretStartOffsetOf(const InlineBox& box) {
64 return box.CaretLeftmostOffset(); 65 return box.CaretLeftmostOffset();
65 } 66 }
66 67
68 static InlineBox* FindBackwardBoundaryOfEntireBidiRun(const InlineBox& box,
69 unsigned bidi_level) {
70 return InlineBoxTraversal::FindRightBoundaryOfEntireBidiRun(box,
71 bidi_level);
72 }
73
74 static InlineBox* FindForwardBoundaryOfEntireBidiRun(const InlineBox& box,
75 unsigned bidi_level) {
76 return InlineBoxTraversal::FindLeftBoundaryOfEntireBidiRun(box, bidi_level);
77 }
78
67 static int ForwardGraphemeBoundaryOf(TextDirection direction, 79 static int ForwardGraphemeBoundaryOf(TextDirection direction,
68 Node* node, 80 Node* node,
69 int offset) { 81 int offset) {
70 if (direction == TextDirection::kLtr) 82 if (direction == TextDirection::kLtr)
71 return PreviousGraphemeBoundaryOf(node, offset); 83 return PreviousGraphemeBoundaryOf(node, offset);
72 return NextGraphemeBoundaryOf(node, offset); 84 return NextGraphemeBoundaryOf(node, offset);
73 } 85 }
74 86
75 static InlineBox* ForwardLeafChildOf(const InlineBox& box) { 87 static InlineBox* ForwardLeafChildOf(const InlineBox& box) {
76 return box.PrevLeafChild(); 88 return box.PrevLeafChild();
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 static int CaretMinOffsetOf(TextDirection direction, const InlineBox& box) { 140 static int CaretMinOffsetOf(TextDirection direction, const InlineBox& box) {
129 if (direction == TextDirection::kLtr) 141 if (direction == TextDirection::kLtr)
130 return box.CaretMaxOffset(); 142 return box.CaretMaxOffset();
131 return box.CaretMinOffset(); 143 return box.CaretMinOffset();
132 } 144 }
133 145
134 static int CaretStartOffsetOf(const InlineBox& box) { 146 static int CaretStartOffsetOf(const InlineBox& box) {
135 return box.CaretRightmostOffset(); 147 return box.CaretRightmostOffset();
136 } 148 }
137 149
150 static InlineBox* FindBackwardBoundaryOfEntireBidiRun(const InlineBox& box,
151 unsigned bidi_level) {
152 return InlineBoxTraversal::FindLeftBoundaryOfEntireBidiRun(box, bidi_level);
153 }
154
155 static InlineBox* FindForwardBoundaryOfEntireBidiRun(const InlineBox& box,
156 unsigned bidi_level) {
157 return InlineBoxTraversal::FindRightBoundaryOfEntireBidiRun(box,
158 bidi_level);
159 }
160
138 static int ForwardGraphemeBoundaryOf(TextDirection direction, 161 static int ForwardGraphemeBoundaryOf(TextDirection direction,
139 Node* node, 162 Node* node,
140 int offset) { 163 int offset) {
141 if (direction == TextDirection::kLtr) 164 if (direction == TextDirection::kLtr)
142 return NextGraphemeBoundaryOf(node, offset); 165 return NextGraphemeBoundaryOf(node, offset);
143 return PreviousGraphemeBoundaryOf(node, offset); 166 return PreviousGraphemeBoundaryOf(node, offset);
144 } 167 }
145 168
146 static InlineBox* ForwardLeafChildOf(const InlineBox& box) { 169 static InlineBox* ForwardLeafChildOf(const InlineBox& box) {
147 return box.NextLeafChild(); 170 return box.NextLeafChild();
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 prev_box = Traversal::ForwardLeafChildOf(*prev_box); 339 prev_box = Traversal::ForwardLeafChildOf(*prev_box);
317 } while (prev_box && prev_box->BidiLevel() > level); 340 } while (prev_box && prev_box->BidiLevel() > level);
318 341
319 if (!prev_box || prev_box->BidiLevel() < level) 342 if (!prev_box || prev_box->BidiLevel() < level)
320 continue; 343 continue;
321 } 344 }
322 } else { 345 } else {
323 // Trailing edge of a secondary run. Set to the leading edge of 346 // Trailing edge of a secondary run. Set to the leading edge of
324 // the entire run. 347 // the entire run.
325 while (true) { 348 while (true) {
326 while (InlineBox* next_box = Traversal::BackwardLeafChildOf(*box)) { 349 box = Traversal::FindBackwardBoundaryOfEntireBidiRun(*box, level);
327 if (next_box->BidiLevel() < level)
328 break;
329 box = next_box;
330 }
331 if (box->BidiLevel() == level) 350 if (box->BidiLevel() == level)
332 break; 351 break;
333 level = box->BidiLevel(); 352 level = box->BidiLevel();
334 while (InlineBox* prev_box = Traversal::ForwardLeafChildOf(*box)) { 353 box = Traversal::FindForwardBoundaryOfEntireBidiRun(*box, level);
335 if (prev_box->BidiLevel() < level)
336 break;
337 box = prev_box;
338 }
339 if (box->BidiLevel() == level) 354 if (box->BidiLevel() == level)
340 break; 355 break;
341 level = box->BidiLevel(); 356 level = box->BidiLevel();
342 } 357 }
343 line_layout_item = box->GetLineLayoutItem(); 358 line_layout_item = box->GetLineLayoutItem();
344 offset = Traversal::CaretMinOffsetOf(primary_direction, *box); 359 offset = Traversal::CaretMinOffsetOf(primary_direction, *box);
345 } 360 }
346 break; 361 break;
347 } 362 }
348 363
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 } 411 }
397 412
398 VisiblePositionInFlatTree RightPositionOf( 413 VisiblePositionInFlatTree RightPositionOf(
399 const VisiblePositionInFlatTree& visible_position) { 414 const VisiblePositionInFlatTree& visible_position) {
400 return TraverseAlgorithm<EditingInFlatTreeStrategy, 415 return TraverseAlgorithm<EditingInFlatTreeStrategy,
401 TraversalRight<EditingInFlatTreeStrategy>>( 416 TraversalRight<EditingInFlatTreeStrategy>>(
402 visible_position); 417 visible_position);
403 } 418 }
404 419
405 } // namespace blink 420 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698