| 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 break; | 47 break; |
| 48 } | 48 } |
| 49 current = current->parent(); | 49 current = current->parent(); |
| 50 } | 50 } |
| 51 | 51 |
| 52 if (!current) | 52 if (!current) |
| 53 current = root->slowFirstChild(); | 53 current = root->slowFirstChild(); |
| 54 | 54 |
| 55 while (current) { | 55 while (current) { |
| 56 next = nullptr; | 56 next = nullptr; |
| 57 if (isIteratorTarget(current) && !(current->isText() | 57 if (isIteratorTarget(LineLayoutItem(current)) && !(current->isText() |
| 58 && toLayoutText(current)->isAllCollapsibleWhitespace())) | 58 && toLayoutText(current)->isAllCollapsibleWhitespace())) |
| 59 break; | 59 break; |
| 60 | 60 |
| 61 if (!isIteratorTarget(current) | 61 if (!isIteratorTarget(LineLayoutItem(current)) |
| 62 && !isIsolated(current->style()->unicodeBidi())) | 62 && !isIsolated(current->style()->unicodeBidi())) |
| 63 next = current->slowFirstChild(); | 63 next = current->slowFirstChild(); |
| 64 | 64 |
| 65 if (!next) { | 65 if (!next) { |
| 66 while (current && current != root) { | 66 while (current && current != root) { |
| 67 next = current->nextSibling(); | 67 next = current->nextSibling(); |
| 68 if (next) | 68 if (next) |
| 69 break; | 69 break; |
| 70 current = current->parent(); | 70 current = current->parent(); |
| 71 } | 71 } |
| 72 } | 72 } |
| 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(LayoutObject* root, | 83 TextDirection determinePlaintextDirectionality(LayoutObject* root, |
| 84 LayoutObject* current = 0, unsigned pos = 0) | 84 LayoutObject* current = 0, unsigned pos = 0) |
| 85 { | 85 { |
| 86 LayoutObject* firstLayoutObject = firstLayoutObjectForDirectionalityDetermin
ation(root, current); | 86 LayoutObject* firstLayoutObject = firstLayoutObjectForDirectionalityDetermin
ation(root, current); |
| 87 InlineIterator iter(root, firstLayoutObject, firstLayoutObject == current ?
pos : 0); | 87 InlineIterator iter(LineLayoutItem(root), LineLayoutItem(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 LayoutObject* root, LayoutObject* startObject) | 111 LayoutObject* root, LayoutObject* startObject) |
| 112 { | 112 { |
| 113 if (root != startObject) { | 113 if (root != startObject) { |
| 114 LayoutObject* 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, LineLayoutItem(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, |
| (...skipping 23 matching lines...) Expand all Loading... |
| 150 LayoutObject* 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 LayoutObject, 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 LayoutObject 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 LayoutObject). | 158 // nothing about LayoutObject). |
| 159 LayoutInline* isolatedInline = toLayoutInline( | 159 LayoutInline* isolatedInline = toLayoutInline( |
| 160 highestContainingIsolateWithinRoot(startObj, currentRoot)); | 160 highestContainingIsolateWithinRoot(LineLayoutItem(startObj), LineLay
outItem(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(); |
| 169 TextDirection direction; | 169 TextDirection direction; |
| 170 if (unicodeBidi == Plaintext) { | 170 if (unicodeBidi == Plaintext) { |
| 171 direction = determinePlaintextDirectionality(isolatedInline, | 171 direction = determinePlaintextDirectionality(isolatedInline, |
| 172 isNewUBAParagraph ? startObj : 0); | 172 isNewUBAParagraph ? startObj : 0); |
| 173 } else { | 173 } else { |
| 174 ASSERT(unicodeBidi == Isolate || unicodeBidi == IsolateOverride); | 174 ASSERT(unicodeBidi == Isolate || unicodeBidi == IsolateOverride); |
| 175 direction = isolatedInline->style()->direction(); | 175 direction = isolatedInline->style()->direction(); |
| 176 } | 176 } |
| 177 isolatedResolver.setStatus(statusWithDirection(direction, | 177 isolatedResolver.setStatus(statusWithDirection(direction, |
| 178 isOverride(unicodeBidi))); | 178 isOverride(unicodeBidi))); |
| 179 | 179 |
| 180 setupResolverToResumeInIsolate(isolatedResolver, isolatedInline, | 180 setupResolverToResumeInIsolate(isolatedResolver, isolatedInline, |
| 181 startObj); | 181 startObj); |
| 182 | 182 |
| 183 // The starting position is the beginning of the first run within the | 183 // The starting position is the beginning of the first run within the |
| 184 // isolate that was identified during the earlier call to | 184 // isolate that was identified during the earlier call to |
| 185 // createBidiRunsForLine. This can be but is not necessarily the first | 185 // createBidiRunsForLine. This can be but is not necessarily the first |
| 186 // run within the isolate. | 186 // run within the isolate. |
| 187 InlineIterator iter = InlineIterator(isolatedInline, startObj, | 187 InlineIterator iter = InlineIterator(LineLayoutItem(isolatedInline), Lin
eLayoutItem(startObj), |
| 188 isolatedRun->m_start); | 188 isolatedRun->m_start); |
| 189 isolatedResolver.setPositionIgnoringNestedIsolates(iter); | 189 isolatedResolver.setPositionIgnoringNestedIsolates(iter); |
| 190 // We stop at the next end of line; we may re-enter this isolate in the | 190 // We stop at the next end of line; we may re-enter this isolate in the |
| 191 // next call to constructBidiRuns(). | 191 // next call to constructBidiRuns(). |
| 192 // FIXME: What should end and previousLineBrokeCleanly be? | 192 // FIXME: What should end and previousLineBrokeCleanly be? |
| 193 // rniwa says previousLineBrokeCleanly is just a WinIE hack and could | 193 // rniwa says previousLineBrokeCleanly is just a WinIE hack and could |
| 194 // always be false here? | 194 // always be false here? |
| 195 isolatedResolver.createBidiRunsForLine(endOfLine, NoVisualOverride, | 195 isolatedResolver.createBidiRunsForLine(endOfLine, NoVisualOverride, |
| 196 previousLineBrokeCleanly); | 196 previousLineBrokeCleanly); |
| 197 | 197 |
| 198 ASSERT(isolatedResolver.runs().runCount()); | 198 ASSERT(isolatedResolver.runs().runCount()); |
| 199 if (isolatedResolver.runs().runCount()) | 199 if (isolatedResolver.runs().runCount()) |
| 200 bidiRuns.replaceRunWithRuns(isolatedRun, isolatedResolver.runs()); | 200 bidiRuns.replaceRunWithRuns(isolatedRun, isolatedResolver.runs()); |
| 201 | 201 |
| 202 // If we encountered any nested isolate runs, just move them | 202 // If we encountered any nested isolate runs, just move them |
| 203 // to the top resolver's list for later processing. | 203 // to the top resolver's list for later processing. |
| 204 if (!isolatedResolver.isolatedRuns().isEmpty()) { | 204 if (!isolatedResolver.isolatedRuns().isEmpty()) { |
| 205 topResolver.isolatedRuns().appendVector( | 205 topResolver.isolatedRuns().appendVector( |
| 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 |