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 == TextDirection::Ltr | 133 WTF::Unicode::CharDirection direction = textDirection == TextDirection::kLtr |
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 == TextDirection::Ltr ? 0 : 1, | 137 context = BidiContext::create(textDirection == TextDirection::kLtr ? 0 : 1, |
138 direction, 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 == TextDirection::Rtl) { | 156 if (textDirection == TextDirection::kRtl) { |
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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 = s.context->dir() == WTF::Unicode::LeftToRight | 258 m_paragraphDirectionality = s.context->dir() == WTF::Unicode::LeftToRight |
259 ? TextDirection::Ltr | 259 ? TextDirection::kLtr |
260 : TextDirection::Rtl; | 260 : TextDirection::kRtl; |
261 } | 261 } |
262 | 262 |
263 MidpointState<Iterator>& midpointState() { return m_midpointState; } | 263 MidpointState<Iterator>& midpointState() { return m_midpointState; } |
264 | 264 |
265 // 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 |
266 // 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 |
267 // ignore) all child isolated spans. | 267 // ignore) all child isolated spans. |
268 void enterIsolate() { m_nestedIsolateCount++; } | 268 void enterIsolate() { m_nestedIsolateCount++; } |
269 void exitIsolate() { | 269 void exitIsolate() { |
270 ASSERT(m_nestedIsolateCount >= 1); | 270 ASSERT(m_nestedIsolateCount >= 1); |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
546 if (!needsToApplyL1Rule(runs)) | 546 if (!needsToApplyL1Rule(runs)) |
547 return; | 547 return; |
548 | 548 |
549 Run* trailingSpaceRun = runs.logicallyLastRun(); | 549 Run* trailingSpaceRun = runs.logicallyLastRun(); |
550 | 550 |
551 int firstSpace = findFirstTrailingSpaceAtRun(trailingSpaceRun); | 551 int firstSpace = findFirstTrailingSpaceAtRun(trailingSpaceRun); |
552 if (firstSpace == trailingSpaceRun->stop()) | 552 if (firstSpace == trailingSpaceRun->stop()) |
553 return; | 553 return; |
554 | 554 |
555 bool shouldReorder = | 555 bool shouldReorder = |
556 trailingSpaceRun != (m_paragraphDirectionality == TextDirection::Ltr | 556 trailingSpaceRun != (m_paragraphDirectionality == TextDirection::kLtr |
557 ? runs.lastRun() | 557 ? runs.lastRun() |
558 : runs.firstRun()); | 558 : runs.firstRun()); |
559 if (firstSpace != trailingSpaceRun->start()) { | 559 if (firstSpace != trailingSpaceRun->start()) { |
560 BidiContext* baseContext = context(); | 560 BidiContext* baseContext = context(); |
561 while (BidiContext* parent = baseContext->parent()) | 561 while (BidiContext* parent = baseContext->parent()) |
562 baseContext = parent; | 562 baseContext = parent; |
563 | 563 |
564 m_trailingSpaceRun = addTrailingRun( | 564 m_trailingSpaceRun = addTrailingRun( |
565 runs, firstSpace, trailingSpaceRun->m_stop, trailingSpaceRun, | 565 runs, firstSpace, trailingSpaceRun->m_stop, trailingSpaceRun, |
566 baseContext, m_paragraphDirectionality); | 566 baseContext, m_paragraphDirectionality); |
567 ASSERT(m_trailingSpaceRun); | 567 ASSERT(m_trailingSpaceRun); |
568 trailingSpaceRun->m_stop = firstSpace; | 568 trailingSpaceRun->m_stop = firstSpace; |
569 return; | 569 return; |
570 } | 570 } |
571 if (!shouldReorder) { | 571 if (!shouldReorder) { |
572 m_trailingSpaceRun = trailingSpaceRun; | 572 m_trailingSpaceRun = trailingSpaceRun; |
573 return; | 573 return; |
574 } | 574 } |
575 | 575 |
576 if (m_paragraphDirectionality == TextDirection::Ltr) { | 576 if (m_paragraphDirectionality == TextDirection::kLtr) { |
577 runs.moveRunToEnd(trailingSpaceRun); | 577 runs.moveRunToEnd(trailingSpaceRun); |
578 trailingSpaceRun->m_level = 0; | 578 trailingSpaceRun->m_level = 0; |
579 } else { | 579 } else { |
580 runs.moveRunToBeginning(trailingSpaceRun); | 580 runs.moveRunToBeginning(trailingSpaceRun); |
581 trailingSpaceRun->m_level = 1; | 581 trailingSpaceRun->m_level = 1; |
582 } | 582 } |
583 m_trailingSpaceRun = trailingSpaceRun; | 583 m_trailingSpaceRun = trailingSpaceRun; |
584 } | 584 } |
585 | 585 |
586 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... |
745 // and retry. | 745 // and retry. |
746 if (!U16_IS_TRAIL(low)) | 746 if (!U16_IS_TRAIL(low)) |
747 continue; | 747 continue; |
748 current = U16_GET_SUPPLEMENTARY(high, low); | 748 current = U16_GET_SUPPLEMENTARY(high, low); |
749 } | 749 } |
750 WTF::Unicode::CharDirection charDirection = | 750 WTF::Unicode::CharDirection charDirection = |
751 WTF::Unicode::direction(current); | 751 WTF::Unicode::direction(current); |
752 if (charDirection == WTF::Unicode::LeftToRight) { | 752 if (charDirection == WTF::Unicode::LeftToRight) { |
753 if (hasStrongDirectionality) | 753 if (hasStrongDirectionality) |
754 *hasStrongDirectionality = true; | 754 *hasStrongDirectionality = true; |
755 return TextDirection::Ltr; | 755 return TextDirection::kLtr; |
756 } | 756 } |
757 if (charDirection == WTF::Unicode::RightToLeft || | 757 if (charDirection == WTF::Unicode::RightToLeft || |
758 charDirection == WTF::Unicode::RightToLeftArabic) { | 758 charDirection == WTF::Unicode::RightToLeftArabic) { |
759 if (hasStrongDirectionality) | 759 if (hasStrongDirectionality) |
760 *hasStrongDirectionality = true; | 760 *hasStrongDirectionality = true; |
761 return TextDirection::Rtl; | 761 return TextDirection::kRtl; |
762 } | 762 } |
763 increment(); | 763 increment(); |
764 } | 764 } |
765 if (hasStrongDirectionality) | 765 if (hasStrongDirectionality) |
766 *hasStrongDirectionality = false; | 766 *hasStrongDirectionality = false; |
767 return TextDirection::Ltr; | 767 return TextDirection::kLtr; |
768 } | 768 } |
769 | 769 |
770 inline TextDirection directionForCharacter(UChar32 character) { | 770 inline TextDirection directionForCharacter(UChar32 character) { |
771 WTF::Unicode::CharDirection charDirection = | 771 WTF::Unicode::CharDirection charDirection = |
772 WTF::Unicode::direction(character); | 772 WTF::Unicode::direction(character); |
773 if (charDirection == WTF::Unicode::RightToLeft || | 773 if (charDirection == WTF::Unicode::RightToLeft || |
774 charDirection == WTF::Unicode::RightToLeftArabic) | 774 charDirection == WTF::Unicode::RightToLeftArabic) |
775 return TextDirection::Rtl; | 775 return TextDirection::kRtl; |
776 return TextDirection::Ltr; | 776 return TextDirection::kLtr; |
777 } | 777 } |
778 | 778 |
779 template <class Iterator, class Run, class IsolatedRun> | 779 template <class Iterator, class Run, class IsolatedRun> |
780 void BidiResolver<Iterator, Run, IsolatedRun>::createBidiRunsForLine( | 780 void BidiResolver<Iterator, Run, IsolatedRun>::createBidiRunsForLine( |
781 const Iterator& end, | 781 const Iterator& end, |
782 VisualDirectionOverride override, | 782 VisualDirectionOverride override, |
783 bool hardLineBreak, | 783 bool hardLineBreak, |
784 bool reorderRuns) { | 784 bool reorderRuns) { |
785 using namespace WTF::Unicode; | 785 using namespace WTF::Unicode; |
786 | 786 |
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1216 template <class Iterator, class Run, class IsolatedRun> | 1216 template <class Iterator, class Run, class IsolatedRun> |
1217 MidpointState<Iterator> | 1217 MidpointState<Iterator> |
1218 BidiResolver<Iterator, Run, IsolatedRun>::midpointStateForIsolatedRun( | 1218 BidiResolver<Iterator, Run, IsolatedRun>::midpointStateForIsolatedRun( |
1219 Run& run) { | 1219 Run& run) { |
1220 return m_midpointStateForIsolatedRun.take(&run); | 1220 return m_midpointStateForIsolatedRun.take(&run); |
1221 } | 1221 } |
1222 | 1222 |
1223 } // namespace blink | 1223 } // namespace blink |
1224 | 1224 |
1225 #endif // BidiResolver_h | 1225 #endif // BidiResolver_h |
OLD | NEW |