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

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-14T17:10:06 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) {
51 const unsigned bidi_level = start.BidiLevel();
52 InlineBox* result = const_cast<InlineBox*>(&start);
53 for (InlineBox* runner = TraversalStrategy::Forward(start); runner;
54 runner = TraversalStrategy::Forward(*runner)) {
55 if (runner->BidiLevel() <= bidi_level)
56 return result;
57 result = runner;
58 }
59 return result;
60 }
61
62 template <typename TraversalStrategy>
63 InlineBox* FindBoudnaryOfEntireBidiRun(const InlineBox& start) {
64 const unsigned bidi_level = start.BidiLevel();
65 InlineBox* result = const_cast<InlineBox*>(&start);
66 for (InlineBox* runner = TraversalStrategy::Forward(start); runner;
67 runner = TraversalStrategy::Forward(*runner)) {
68 if (runner->BidiLevel() < bidi_level)
69 return result;
70 result = runner;
71 }
72 return result;
73 }
74
75 } // namespace
76
77 InlineBox* InlineBoxTraversal::FindLeftBoundaryOfBidiRunIgnoringLineBreak(
78 const InlineBox& inline_box) {
79 return FindBoudnaryOfBidiRun<TraverseLeftIgnoringLineBreak>(inline_box);
80 }
81
82 InlineBox* InlineBoxTraversal::FindLeftBoundaryOfEntireBidiRun(
83 const InlineBox& inline_box) {
84 return FindBoudnaryOfEntireBidiRun<TraverseLeft>(inline_box);
85 }
86
87 InlineBox* InlineBoxTraversal::FindLeftBoundaryOfEntireBidiRunIgnoringLineBreak(
88 const InlineBox& inline_box) {
89 return FindBoudnaryOfEntireBidiRun<TraverseLeftIgnoringLineBreak>(inline_box);
90 }
91
92 InlineBox* InlineBoxTraversal::FindRightBoundaryOfBidiRunIgnoringLineBreak(
93 const InlineBox& inline_box) {
94 return FindBoudnaryOfBidiRun<TraverseRightIgnoringLineBreak>(inline_box);
95 }
96
97 InlineBox* InlineBoxTraversal::FindRightBoundaryOfEntireBidiRun(
98 const InlineBox& inline_box) {
99 return FindBoudnaryOfEntireBidiRun<TraverseRight>(inline_box);
100 }
101
102 InlineBox*
103 InlineBoxTraversal::FindRightBoundaryOfEntireBidiRunIgnoringLineBreak(
104 const InlineBox& inline_box) {
105 return FindBoudnaryOfEntireBidiRun<TraverseRightIgnoringLineBreak>(
106 inline_box);
107 }
108
109 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698