OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2000 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 2000 Lars Knoll (knoll@kde.org) |
3 * Copyright (C) 2003, 2004, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. | 3 * Copyright (C) 2003, 2004, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. |
4 * All right reserved. | 4 * All right reserved. |
5 * Copyright (C) 2010 Google Inc. All rights reserved. | 5 * Copyright (C) 2010 Google Inc. All rights reserved. |
6 * | 6 * |
7 * This library is free software; you can redistribute it and/or | 7 * This library is free software; you can redistribute it and/or |
8 * modify it under the terms of the GNU Library General Public | 8 * modify it under the terms of the GNU Library General Public |
9 * License as published by the Free Software Foundation; either | 9 * License as published by the Free Software Foundation; either |
10 * version 2 of the License, or (at your option) any later version. | 10 * version 2 of the License, or (at your option) any later version. |
(...skipping 15 matching lines...) Expand all Loading... |
26 | 26 |
27 #include "config.h" | 27 #include "config.h" |
28 #include "core/layout/BidiRunForLine.h" | 28 #include "core/layout/BidiRunForLine.h" |
29 | 29 |
30 #include "core/layout/line/InlineIterator.h" | 30 #include "core/layout/line/InlineIterator.h" |
31 | 31 |
32 namespace blink { | 32 namespace blink { |
33 | 33 |
34 using namespace WTF::Unicode; | 34 using namespace WTF::Unicode; |
35 | 35 |
36 static RenderObject* firstRenderObjectForDirectionalityDetermination( | 36 static LayoutObject* firstLayoutObjectForDirectionalityDetermination( |
37 RenderObject* root, RenderObject* current = 0) | 37 LayoutObject* root, LayoutObject* current = 0) |
38 { | 38 { |
39 RenderObject* next = current; | 39 LayoutObject* next = current; |
40 while (current) { | 40 while (current) { |
41 if (isIsolated(current->style()->unicodeBidi()) | 41 if (isIsolated(current->style()->unicodeBidi()) |
42 && (current->isRenderInline() || current->isRenderBlock())) { | 42 && (current->isRenderInline() || current->isRenderBlock())) { |
43 if (current != root) | 43 if (current != root) |
44 current = 0; | 44 current = 0; |
45 else | 45 else |
46 current = next; | 46 current = next; |
47 break; | 47 break; |
48 } | 48 } |
49 current = current->parent(); | 49 current = current->parent(); |
(...skipping 23 matching lines...) Expand all Loading... |
73 | 73 |
74 if (!next) | 74 if (!next) |
75 break; | 75 break; |
76 | 76 |
77 current = next; | 77 current = next; |
78 } | 78 } |
79 | 79 |
80 return current; | 80 return current; |
81 } | 81 } |
82 | 82 |
83 TextDirection determinePlaintextDirectionality(RenderObject* root, | 83 TextDirection determinePlaintextDirectionality(LayoutObject* root, |
84 RenderObject* current = 0, unsigned pos = 0) | 84 LayoutObject* current = 0, unsigned pos = 0) |
85 { | 85 { |
86 RenderObject* firstRenderObject = firstRenderObjectForDirectionalityDetermin
ation(root, current); | 86 LayoutObject* firstLayoutObject = firstLayoutObjectForDirectionalityDetermin
ation(root, current); |
87 InlineIterator iter(root, firstRenderObject, firstRenderObject == current ?
pos : 0); | 87 InlineIterator iter(root, firstLayoutObject, firstLayoutObject == current ?
pos : 0); |
88 InlineBidiResolver observer; | 88 InlineBidiResolver observer; |
89 observer.setStatus(BidiStatus(root->style()->direction(), | 89 observer.setStatus(BidiStatus(root->style()->direction(), |
90 isOverride(root->style()->unicodeBidi()))); | 90 isOverride(root->style()->unicodeBidi()))); |
91 observer.setPositionIgnoringNestedIsolates(iter); | 91 observer.setPositionIgnoringNestedIsolates(iter); |
92 return observer.determineParagraphDirectionality(); | 92 return observer.determineParagraphDirectionality(); |
93 } | 93 } |
94 | 94 |
95 // FIXME: This should be a BidiStatus constructor or create method. | 95 // FIXME: This should be a BidiStatus constructor or create method. |
96 static inline BidiStatus statusWithDirection(TextDirection textDirection, | 96 static inline BidiStatus statusWithDirection(TextDirection textDirection, |
97 bool isOverride) | 97 bool isOverride) |
98 { | 98 { |
99 WTF::Unicode::Direction direction = textDirection == LTR | 99 WTF::Unicode::Direction direction = textDirection == LTR |
100 ? LeftToRight | 100 ? LeftToRight |
101 : RightToLeft; | 101 : RightToLeft; |
102 RefPtr<BidiContext> context = BidiContext::create( | 102 RefPtr<BidiContext> context = BidiContext::create( |
103 textDirection == LTR ? 0 : 1, direction, isOverride, FromStyleOrDOM); | 103 textDirection == LTR ? 0 : 1, direction, isOverride, FromStyleOrDOM); |
104 | 104 |
105 // This copies BidiStatus and may churn the ref on BidiContext. | 105 // This copies BidiStatus and may churn the ref on BidiContext. |
106 // I doubt it matters. | 106 // I doubt it matters. |
107 return BidiStatus(direction, direction, direction, context.release()); | 107 return BidiStatus(direction, direction, direction, context.release()); |
108 } | 108 } |
109 | 109 |
110 static inline void setupResolverToResumeInIsolate(InlineBidiResolver& resolver, | 110 static inline void setupResolverToResumeInIsolate(InlineBidiResolver& resolver, |
111 RenderObject* root, RenderObject* startObject) | 111 LayoutObject* root, LayoutObject* startObject) |
112 { | 112 { |
113 if (root != startObject) { | 113 if (root != startObject) { |
114 RenderObject* parent = startObject->parent(); | 114 LayoutObject* parent = startObject->parent(); |
115 setupResolverToResumeInIsolate(resolver, root, parent); | 115 setupResolverToResumeInIsolate(resolver, root, parent); |
116 notifyObserverEnteredObject(&resolver, startObject); | 116 notifyObserverEnteredObject(&resolver, startObject); |
117 } | 117 } |
118 } | 118 } |
119 | 119 |
120 static void restoreIsolatedMidpointStates(InlineBidiResolver& topResolver, | 120 static void restoreIsolatedMidpointStates(InlineBidiResolver& topResolver, |
121 InlineBidiResolver& isolatedResolver) | 121 InlineBidiResolver& isolatedResolver) |
122 { | 122 { |
123 while (!isolatedResolver.isolatedRuns().isEmpty()) { | 123 while (!isolatedResolver.isolatedRuns().isEmpty()) { |
124 BidiRun* run = isolatedResolver.isolatedRuns().last(); | 124 BidiRun* run = isolatedResolver.isolatedRuns().last(); |
125 isolatedResolver.isolatedRuns().removeLast(); | 125 isolatedResolver.isolatedRuns().removeLast(); |
126 topResolver.setMidpointStateForIsolatedRun(run, | 126 topResolver.setMidpointStateForIsolatedRun(run, |
127 isolatedResolver.midpointStateForIsolatedRun(run)); | 127 isolatedResolver.midpointStateForIsolatedRun(run)); |
128 } | 128 } |
129 } | 129 } |
130 | 130 |
131 void constructBidiRunsForLine(InlineBidiResolver& topResolver, | 131 void constructBidiRunsForLine(InlineBidiResolver& topResolver, |
132 BidiRunList<BidiRun>& bidiRuns, const InlineIterator& endOfLine, | 132 BidiRunList<BidiRun>& bidiRuns, const InlineIterator& endOfLine, |
133 VisualDirectionOverride override, bool previousLineBrokeCleanly, | 133 VisualDirectionOverride override, bool previousLineBrokeCleanly, |
134 bool isNewUBAParagraph) | 134 bool isNewUBAParagraph) |
135 { | 135 { |
136 // FIXME: We should pass a BidiRunList into createBidiRunsForLine instead | 136 // FIXME: We should pass a BidiRunList into createBidiRunsForLine instead |
137 // of the resolver owning the runs. | 137 // of the resolver owning the runs. |
138 ASSERT(&topResolver.runs() == &bidiRuns); | 138 ASSERT(&topResolver.runs() == &bidiRuns); |
139 ASSERT(topResolver.position() != endOfLine); | 139 ASSERT(topResolver.position() != endOfLine); |
140 RenderObject* currentRoot = topResolver.position().root(); | 140 LayoutObject* currentRoot = topResolver.position().root(); |
141 topResolver.createBidiRunsForLine(endOfLine, override, | 141 topResolver.createBidiRunsForLine(endOfLine, override, |
142 previousLineBrokeCleanly); | 142 previousLineBrokeCleanly); |
143 | 143 |
144 while (!topResolver.isolatedRuns().isEmpty()) { | 144 while (!topResolver.isolatedRuns().isEmpty()) { |
145 // It does not matter which order we resolve the runs as long as we | 145 // It does not matter which order we resolve the runs as long as we |
146 // resolve them all. | 146 // resolve them all. |
147 BidiRun* isolatedRun = topResolver.isolatedRuns().last(); | 147 BidiRun* isolatedRun = topResolver.isolatedRuns().last(); |
148 topResolver.isolatedRuns().removeLast(); | 148 topResolver.isolatedRuns().removeLast(); |
149 | 149 |
150 RenderObject* startObj = isolatedRun->object(); | 150 LayoutObject* startObj = isolatedRun->object(); |
151 | 151 |
152 // Only inlines make sense with unicode-bidi: isolate (blocks are | 152 // Only inlines make sense with unicode-bidi: isolate (blocks are |
153 // already isolated). | 153 // already isolated). |
154 // FIXME: Because enterIsolate is not passed a RenderObject, we have to | 154 // FIXME: Because enterIsolate is not passed a LayoutObject, we have to |
155 // crawl up the tree to see which parent inline is the isolate. We could | 155 // crawl up the tree to see which parent inline is the isolate. We could |
156 // change enterIsolate to take a RenderObject and do this logic there, | 156 // change enterIsolate to take a LayoutObject and do this logic there, |
157 // but that would be a layering violation for BidiResolver (which knows | 157 // but that would be a layering violation for BidiResolver (which knows |
158 // nothing about RenderObject). | 158 // nothing about LayoutObject). |
159 RenderInline* isolatedInline = toRenderInline( | 159 RenderInline* isolatedInline = toRenderInline( |
160 highestContainingIsolateWithinRoot(startObj, currentRoot)); | 160 highestContainingIsolateWithinRoot(startObj, currentRoot)); |
161 ASSERT(isolatedInline); | 161 ASSERT(isolatedInline); |
162 | 162 |
163 InlineBidiResolver isolatedResolver; | 163 InlineBidiResolver isolatedResolver; |
164 LineMidpointState& isolatedLineMidpointState = | 164 LineMidpointState& isolatedLineMidpointState = |
165 isolatedResolver.midpointState(); | 165 isolatedResolver.midpointState(); |
166 isolatedLineMidpointState = topResolver.midpointStateForIsolatedRun( | 166 isolatedLineMidpointState = topResolver.midpointStateForIsolatedRun( |
167 isolatedRun); | 167 isolatedRun); |
168 EUnicodeBidi unicodeBidi = isolatedInline->style()->unicodeBidi(); | 168 EUnicodeBidi unicodeBidi = isolatedInline->style()->unicodeBidi(); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 isolatedResolver.isolatedRuns()); | 206 isolatedResolver.isolatedRuns()); |
207 currentRoot = isolatedInline; | 207 currentRoot = isolatedInline; |
208 restoreIsolatedMidpointStates(topResolver, isolatedResolver); | 208 restoreIsolatedMidpointStates(topResolver, isolatedResolver); |
209 } | 209 } |
210 } | 210 } |
211 } | 211 } |
212 | 212 |
213 } // namespace blink | 213 } // namespace blink |
214 | 214 |
215 #endif // BidiRunForLine_h | 215 #endif // BidiRunForLine_h |
OLD | NEW |