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 Apple Inc. All right reserved. | 3 * Copyright (C) 2003, 2004, 2006, 2007, 2008 Apple Inc. All right reserved. |
4 * | 4 * |
5 * This library is free software; you can redistribute it and/or | 5 * This library is free software; you can redistribute it and/or |
6 * modify it under the terms of the GNU Library General Public | 6 * modify it under the terms of the GNU Library General Public |
7 * License as published by the Free Software Foundation; either | 7 * License as published by the Free Software Foundation; either |
8 * version 2 of the License, or (at your option) any later version. | 8 * version 2 of the License, or (at your option) any later version. |
9 * | 9 * |
10 * This library is distributed in the hope that it will be useful, | 10 * This library is distributed in the hope that it will be useful, |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 DISALLOW_NEW(); | 123 DISALLOW_NEW(); |
124 BidiStatus() | 124 BidiStatus() |
125 : eor(WTF::Unicode::OtherNeutral), | 125 : eor(WTF::Unicode::OtherNeutral), |
126 lastStrong(WTF::Unicode::OtherNeutral), | 126 lastStrong(WTF::Unicode::OtherNeutral), |
127 last(WTF::Unicode::OtherNeutral) {} | 127 last(WTF::Unicode::OtherNeutral) {} |
128 | 128 |
129 // Creates a BidiStatus representing a new paragraph root with a default | 129 // Creates a BidiStatus representing a new paragraph root with a default |
130 // direction. Uses TextDirection as it only has two possibilities instead of | 130 // direction. Uses TextDirection as it only has two possibilities instead of |
131 // WTF::Unicode::Direction which has 19. | 131 // WTF::Unicode::Direction which has 19. |
132 BidiStatus(TextDirection textDirection, bool isOverride) { | 132 BidiStatus(TextDirection textDirection, bool isOverride) { |
133 WTF::Unicode::CharDirection direction = textDirection == LTR | 133 WTF::Unicode::CharDirection direction = textDirection == TextDirection::Ltr |
134 ? WTF::Unicode::LeftToRight | 134 ? WTF::Unicode::LeftToRight |
135 : WTF::Unicode::RightToLeft; | 135 : WTF::Unicode::RightToLeft; |
136 eor = lastStrong = last = direction; | 136 eor = lastStrong = last = direction; |
137 context = BidiContext::create(textDirection == LTR ? 0 : 1, direction, | 137 context = BidiContext::create(textDirection == TextDirection::Ltr ? 0 : 1, |
138 isOverride); | 138 direction, isOverride); |
139 } | 139 } |
140 | 140 |
141 BidiStatus(WTF::Unicode::CharDirection eorDir, | 141 BidiStatus(WTF::Unicode::CharDirection eorDir, |
142 WTF::Unicode::CharDirection lastStrongDir, | 142 WTF::Unicode::CharDirection lastStrongDir, |
143 WTF::Unicode::CharDirection lastDir, | 143 WTF::Unicode::CharDirection lastDir, |
144 PassRefPtr<BidiContext> bidiContext) | 144 PassRefPtr<BidiContext> bidiContext) |
145 : eor(eorDir), | 145 : eor(eorDir), |
146 lastStrong(lastStrongDir), | 146 lastStrong(lastStrongDir), |
147 last(lastDir), | 147 last(lastDir), |
148 context(bidiContext) {} | 148 context(bidiContext) {} |
149 | 149 |
150 // Creates a BidiStatus for Isolates (RLI/LRI). | 150 // Creates a BidiStatus for Isolates (RLI/LRI). |
151 // The rule X5a ans X5b of UAX#9: http://unicode.org/reports/tr9/#X5a | 151 // The rule X5a ans X5b of UAX#9: http://unicode.org/reports/tr9/#X5a |
152 static BidiStatus createForIsolate(TextDirection textDirection, | 152 static BidiStatus createForIsolate(TextDirection textDirection, |
153 bool isOverride, | 153 bool isOverride, |
154 unsigned char level) { | 154 unsigned char level) { |
155 WTF::Unicode::CharDirection direction; | 155 WTF::Unicode::CharDirection direction; |
156 if (textDirection == RTL) { | 156 if (textDirection == TextDirection::Rtl) { |
157 level = nextGreaterOddLevel(level); | 157 level = nextGreaterOddLevel(level); |
158 direction = WTF::Unicode::RightToLeft; | 158 direction = WTF::Unicode::RightToLeft; |
159 } else { | 159 } else { |
160 level = nextGreaterEvenLevel(level); | 160 level = nextGreaterEvenLevel(level); |
161 direction = WTF::Unicode::LeftToRight; | 161 direction = WTF::Unicode::LeftToRight; |
162 } | 162 } |
163 RefPtr<BidiContext> context = | 163 RefPtr<BidiContext> context = |
164 BidiContext::create(level, direction, isOverride, FromStyleOrDOM); | 164 BidiContext::create(level, direction, isOverride, FromStyleOrDOM); |
165 | 165 |
166 // This copies BidiStatus and may churn the ref on BidiContext. | 166 // This copies BidiStatus and may churn the ref on BidiContext. |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 } | 248 } |
249 void setEorDir(WTF::Unicode::CharDirection eorDir) { m_status.eor = eorDir; } | 249 void setEorDir(WTF::Unicode::CharDirection eorDir) { m_status.eor = eorDir; } |
250 | 250 |
251 WTF::Unicode::CharDirection dir() const { return m_direction; } | 251 WTF::Unicode::CharDirection dir() const { return m_direction; } |
252 void setDir(WTF::Unicode::CharDirection d) { m_direction = d; } | 252 void setDir(WTF::Unicode::CharDirection d) { m_direction = d; } |
253 | 253 |
254 const BidiStatus& status() const { return m_status; } | 254 const BidiStatus& status() const { return m_status; } |
255 void setStatus(const BidiStatus s) { | 255 void setStatus(const BidiStatus s) { |
256 ASSERT(s.context); | 256 ASSERT(s.context); |
257 m_status = s; | 257 m_status = s; |
258 m_paragraphDirectionality = | 258 m_paragraphDirectionality = s.context->dir() == WTF::Unicode::LeftToRight |
259 s.context->dir() == WTF::Unicode::LeftToRight ? LTR : RTL; | 259 ? TextDirection::Ltr |
| 260 : TextDirection::Rtl; |
260 } | 261 } |
261 | 262 |
262 MidpointState<Iterator>& midpointState() { return m_midpointState; } | 263 MidpointState<Iterator>& midpointState() { return m_midpointState; } |
263 | 264 |
264 // The current algorithm handles nested isolates one layer of nesting at a | 265 // The current algorithm handles nested isolates one layer of nesting at a |
265 // time. But when we layout each isolated span, we will walk into (and | 266 // time. But when we layout each isolated span, we will walk into (and |
266 // ignore) all child isolated spans. | 267 // ignore) all child isolated spans. |
267 void enterIsolate() { m_nestedIsolateCount++; } | 268 void enterIsolate() { m_nestedIsolateCount++; } |
268 void exitIsolate() { | 269 void exitIsolate() { |
269 ASSERT(m_nestedIsolateCount >= 1); | 270 ASSERT(m_nestedIsolateCount >= 1); |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
545 if (!needsToApplyL1Rule(runs)) | 546 if (!needsToApplyL1Rule(runs)) |
546 return; | 547 return; |
547 | 548 |
548 Run* trailingSpaceRun = runs.logicallyLastRun(); | 549 Run* trailingSpaceRun = runs.logicallyLastRun(); |
549 | 550 |
550 int firstSpace = findFirstTrailingSpaceAtRun(trailingSpaceRun); | 551 int firstSpace = findFirstTrailingSpaceAtRun(trailingSpaceRun); |
551 if (firstSpace == trailingSpaceRun->stop()) | 552 if (firstSpace == trailingSpaceRun->stop()) |
552 return; | 553 return; |
553 | 554 |
554 bool shouldReorder = | 555 bool shouldReorder = |
555 trailingSpaceRun != | 556 trailingSpaceRun != (m_paragraphDirectionality == TextDirection::Ltr |
556 (m_paragraphDirectionality == LTR ? runs.lastRun() : runs.firstRun()); | 557 ? runs.lastRun() |
| 558 : runs.firstRun()); |
557 if (firstSpace != trailingSpaceRun->start()) { | 559 if (firstSpace != trailingSpaceRun->start()) { |
558 BidiContext* baseContext = context(); | 560 BidiContext* baseContext = context(); |
559 while (BidiContext* parent = baseContext->parent()) | 561 while (BidiContext* parent = baseContext->parent()) |
560 baseContext = parent; | 562 baseContext = parent; |
561 | 563 |
562 m_trailingSpaceRun = addTrailingRun( | 564 m_trailingSpaceRun = addTrailingRun( |
563 runs, firstSpace, trailingSpaceRun->m_stop, trailingSpaceRun, | 565 runs, firstSpace, trailingSpaceRun->m_stop, trailingSpaceRun, |
564 baseContext, m_paragraphDirectionality); | 566 baseContext, m_paragraphDirectionality); |
565 ASSERT(m_trailingSpaceRun); | 567 ASSERT(m_trailingSpaceRun); |
566 trailingSpaceRun->m_stop = firstSpace; | 568 trailingSpaceRun->m_stop = firstSpace; |
567 return; | 569 return; |
568 } | 570 } |
569 if (!shouldReorder) { | 571 if (!shouldReorder) { |
570 m_trailingSpaceRun = trailingSpaceRun; | 572 m_trailingSpaceRun = trailingSpaceRun; |
571 return; | 573 return; |
572 } | 574 } |
573 | 575 |
574 if (m_paragraphDirectionality == LTR) { | 576 if (m_paragraphDirectionality == TextDirection::Ltr) { |
575 runs.moveRunToEnd(trailingSpaceRun); | 577 runs.moveRunToEnd(trailingSpaceRun); |
576 trailingSpaceRun->m_level = 0; | 578 trailingSpaceRun->m_level = 0; |
577 } else { | 579 } else { |
578 runs.moveRunToBeginning(trailingSpaceRun); | 580 runs.moveRunToBeginning(trailingSpaceRun); |
579 trailingSpaceRun->m_level = 1; | 581 trailingSpaceRun->m_level = 1; |
580 } | 582 } |
581 m_trailingSpaceRun = trailingSpaceRun; | 583 m_trailingSpaceRun = trailingSpaceRun; |
582 } | 584 } |
583 | 585 |
584 template <class Iterator, class Run, class IsolatedRun> | 586 template <class Iterator, class Run, class IsolatedRun> |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
743 // and retry. | 745 // and retry. |
744 if (!U16_IS_TRAIL(low)) | 746 if (!U16_IS_TRAIL(low)) |
745 continue; | 747 continue; |
746 current = U16_GET_SUPPLEMENTARY(high, low); | 748 current = U16_GET_SUPPLEMENTARY(high, low); |
747 } | 749 } |
748 WTF::Unicode::CharDirection charDirection = | 750 WTF::Unicode::CharDirection charDirection = |
749 WTF::Unicode::direction(current); | 751 WTF::Unicode::direction(current); |
750 if (charDirection == WTF::Unicode::LeftToRight) { | 752 if (charDirection == WTF::Unicode::LeftToRight) { |
751 if (hasStrongDirectionality) | 753 if (hasStrongDirectionality) |
752 *hasStrongDirectionality = true; | 754 *hasStrongDirectionality = true; |
753 return LTR; | 755 return TextDirection::Ltr; |
754 } | 756 } |
755 if (charDirection == WTF::Unicode::RightToLeft || | 757 if (charDirection == WTF::Unicode::RightToLeft || |
756 charDirection == WTF::Unicode::RightToLeftArabic) { | 758 charDirection == WTF::Unicode::RightToLeftArabic) { |
757 if (hasStrongDirectionality) | 759 if (hasStrongDirectionality) |
758 *hasStrongDirectionality = true; | 760 *hasStrongDirectionality = true; |
759 return RTL; | 761 return TextDirection::Rtl; |
760 } | 762 } |
761 increment(); | 763 increment(); |
762 } | 764 } |
763 if (hasStrongDirectionality) | 765 if (hasStrongDirectionality) |
764 *hasStrongDirectionality = false; | 766 *hasStrongDirectionality = false; |
765 return LTR; | 767 return TextDirection::Ltr; |
766 } | 768 } |
767 | 769 |
768 inline TextDirection directionForCharacter(UChar32 character) { | 770 inline TextDirection directionForCharacter(UChar32 character) { |
769 WTF::Unicode::CharDirection charDirection = | 771 WTF::Unicode::CharDirection charDirection = |
770 WTF::Unicode::direction(character); | 772 WTF::Unicode::direction(character); |
771 if (charDirection == WTF::Unicode::RightToLeft || | 773 if (charDirection == WTF::Unicode::RightToLeft || |
772 charDirection == WTF::Unicode::RightToLeftArabic) | 774 charDirection == WTF::Unicode::RightToLeftArabic) |
773 return RTL; | 775 return TextDirection::Rtl; |
774 return LTR; | 776 return TextDirection::Ltr; |
775 } | 777 } |
776 | 778 |
777 template <class Iterator, class Run, class IsolatedRun> | 779 template <class Iterator, class Run, class IsolatedRun> |
778 void BidiResolver<Iterator, Run, IsolatedRun>::createBidiRunsForLine( | 780 void BidiResolver<Iterator, Run, IsolatedRun>::createBidiRunsForLine( |
779 const Iterator& end, | 781 const Iterator& end, |
780 VisualDirectionOverride override, | 782 VisualDirectionOverride override, |
781 bool hardLineBreak, | 783 bool hardLineBreak, |
782 bool reorderRuns) { | 784 bool reorderRuns) { |
783 using namespace WTF::Unicode; | 785 using namespace WTF::Unicode; |
784 | 786 |
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1214 template <class Iterator, class Run, class IsolatedRun> | 1216 template <class Iterator, class Run, class IsolatedRun> |
1215 MidpointState<Iterator> | 1217 MidpointState<Iterator> |
1216 BidiResolver<Iterator, Run, IsolatedRun>::midpointStateForIsolatedRun( | 1218 BidiResolver<Iterator, Run, IsolatedRun>::midpointStateForIsolatedRun( |
1217 Run& run) { | 1219 Run& run) { |
1218 return m_midpointStateForIsolatedRun.take(&run); | 1220 return m_midpointStateForIsolatedRun.take(&run); |
1219 } | 1221 } |
1220 | 1222 |
1221 } // namespace blink | 1223 } // namespace blink |
1222 | 1224 |
1223 #endif // BidiResolver_h | 1225 #endif // BidiResolver_h |
OLD | NEW |