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

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

Issue 2942523003: Introduce Find{Left,Right}BoundaryOfBidiRun() and variations (Closed)
Patch Set: 2017-06-15T12:30:33 Pass Bidi level to FindBoundary 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
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "core/editing/InlineBoxTraversal.h"
6
7 #include "core/layout/line/InlineBox.h"
8
9 namespace blink {
10
11 namespace {
12
13 // "Left" Traversal strategy
14 struct TraverseLeft {
15 STATIC_ONLY(TraverseLeft);
16
17 static InlineBox* Forward(const InlineBox& inline_box) {
18 return inline_box.PrevLeafChild();
19 }
20 };
21
22 // "Left" Traversal strategy ignoring line break
23 struct TraverseLeftIgnoringLineBreak {
24 STATIC_ONLY(TraverseLeftIgnoringLineBreak);
25
26 static InlineBox* Forward(const InlineBox& inline_box) {
27 return inline_box.PrevLeafChildIgnoringLineBreak();
28 }
29 };
30
31 // "Right" Traversal strategy
32 struct TraverseRight {
33 STATIC_ONLY(TraverseRight);
34
35 static InlineBox* Forward(const InlineBox& inline_box) {
36 return inline_box.NextLeafChild();
37 }
38 };
39
40 // "Right" Traversal strategy ignoring line break
41 struct TraverseRightIgnoringLineBreak {
42 STATIC_ONLY(TraverseRightIgnoringLineBreak);
43
44 static InlineBox* Forward(const InlineBox& inline_box) {
45 return inline_box.NextLeafChildIgnoringLineBreak();
46 }
47 };
48
49 template <typename TraversalStrategy>
50 InlineBox* FindBoudnaryOfBidiRun(const InlineBox& start, unsigned bidi_level) {
51 InlineBox* result = const_cast<InlineBox*>(&start);
52 for (InlineBox* runner = TraversalStrategy::Forward(start); runner;
53 runner = TraversalStrategy::Forward(*runner)) {
54 if (runner->BidiLevel() <= bidi_level)
55 return result;
56 result = runner;
57 }
58 return result;
59 }
60
61 template <typename TraversalStrategy>
62 InlineBox* FindBoudnaryOfEntireBidiRun(const InlineBox& start,
63 unsigned bidi_level) {
64 InlineBox* result = const_cast<InlineBox*>(&start);
65 for (InlineBox* runner = TraversalStrategy::Forward(start); runner;
66 runner = TraversalStrategy::Forward(*runner)) {
67 if (runner->BidiLevel() < bidi_level)
68 return result;
69 result = runner;
70 }
71 return result;
72 }
73
74 } // namespace
75
76 InlineBox* InlineBoxTraversal::FindLeftBoundaryOfBidiRunIgnoringLineBreak(
77 const InlineBox& inline_box,
78 unsigned bidi_level) {
79 return FindBoudnaryOfBidiRun<TraverseLeftIgnoringLineBreak>(inline_box,
80 bidi_level);
81 }
82
83 InlineBox* InlineBoxTraversal::FindLeftBoundaryOfEntireBidiRun(
84 const InlineBox& inline_box,
85 unsigned bidi_level) {
86 return FindBoudnaryOfEntireBidiRun<TraverseLeft>(inline_box, bidi_level);
87 }
88
89 InlineBox* InlineBoxTraversal::FindLeftBoundaryOfEntireBidiRunIgnoringLineBreak(
90 const InlineBox& inline_box,
91 unsigned bidi_level) {
92 return FindBoudnaryOfEntireBidiRun<TraverseLeftIgnoringLineBreak>(inline_box,
93 bidi_level);
94 }
95
96 InlineBox* InlineBoxTraversal::FindRightBoundaryOfBidiRunIgnoringLineBreak(
97 const InlineBox& inline_box,
98 unsigned bidi_level) {
99 return FindBoudnaryOfBidiRun<TraverseRightIgnoringLineBreak>(inline_box,
100 bidi_level);
101 }
102
103 InlineBox* InlineBoxTraversal::FindRightBoundaryOfEntireBidiRun(
104 const InlineBox& inline_box,
105 unsigned bidi_level) {
106 return FindBoudnaryOfEntireBidiRun<TraverseRight>(inline_box, bidi_level);
107 }
108
109 InlineBox*
110 InlineBoxTraversal::FindRightBoundaryOfEntireBidiRunIgnoringLineBreak(
111 const InlineBox& inline_box,
112 unsigned bidi_level) {
113 return FindBoudnaryOfEntireBidiRun<TraverseRightIgnoringLineBreak>(
114 inline_box, bidi_level);
115 }
116
117 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/editing/InlineBoxTraversal.h ('k') | third_party/WebKit/Source/core/editing/VisibleUnits.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698