| 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 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 class BidiResolver final { | 214 class BidiResolver final { |
| 215 DISALLOW_NEW(); | 215 DISALLOW_NEW(); |
| 216 WTF_MAKE_NONCOPYABLE(BidiResolver); | 216 WTF_MAKE_NONCOPYABLE(BidiResolver); |
| 217 | 217 |
| 218 public: | 218 public: |
| 219 BidiResolver() | 219 BidiResolver() |
| 220 : m_direction(WTF::Unicode::OtherNeutral), | 220 : m_direction(WTF::Unicode::OtherNeutral), |
| 221 m_reachedEndOfLine(false), | 221 m_reachedEndOfLine(false), |
| 222 m_emptyRun(true), | 222 m_emptyRun(true), |
| 223 m_nestedIsolateCount(0), | 223 m_nestedIsolateCount(0), |
| 224 m_trailingSpaceRun(0) {} | 224 m_trailingSpaceRun(0), |
| 225 m_needsTrailingSpace(false) {} |
| 225 | 226 |
| 226 #if DCHECK_IS_ON() | 227 #if DCHECK_IS_ON() |
| 227 ~BidiResolver(); | 228 ~BidiResolver(); |
| 228 #endif | 229 #endif |
| 229 | 230 |
| 230 const Iterator& position() const { return m_current; } | 231 const Iterator& position() const { return m_current; } |
| 231 Iterator& position() { return m_current; } | 232 Iterator& position() { return m_current; } |
| 232 void setPositionIgnoringNestedIsolates(const Iterator& position) { | 233 void setPositionIgnoringNestedIsolates(const Iterator& position) { |
| 233 m_current = position; | 234 m_current = position; |
| 234 } | 235 } |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 bool breakOnParagraph = false; | 305 bool breakOnParagraph = false; |
| 305 return determineDirectionalityInternal(breakOnParagraph, | 306 return determineDirectionalityInternal(breakOnParagraph, |
| 306 hasStrongDirectionality); | 307 hasStrongDirectionality); |
| 307 } | 308 } |
| 308 | 309 |
| 309 void setMidpointStateForIsolatedRun(Run&, const MidpointState<Iterator>&); | 310 void setMidpointStateForIsolatedRun(Run&, const MidpointState<Iterator>&); |
| 310 MidpointState<Iterator> midpointStateForIsolatedRun(Run&); | 311 MidpointState<Iterator> midpointStateForIsolatedRun(Run&); |
| 311 | 312 |
| 312 Iterator endOfLine() const { return m_endOfLine; } | 313 Iterator endOfLine() const { return m_endOfLine; } |
| 313 | 314 |
| 315 void setNeedsTrailingSpace(bool value) { m_needsTrailingSpace = value; } |
| 314 Run* trailingSpaceRun() const { return m_trailingSpaceRun; } | 316 Run* trailingSpaceRun() const { return m_trailingSpaceRun; } |
| 315 | 317 |
| 316 protected: | 318 protected: |
| 317 void increment() { m_current.increment(); } | 319 void increment() { m_current.increment(); } |
| 318 // FIXME: Instead of InlineBidiResolvers subclassing this method, we should | 320 // FIXME: Instead of InlineBidiResolvers subclassing this method, we should |
| 319 // pass in some sort of Traits object which knows how to create runs for | 321 // pass in some sort of Traits object which knows how to create runs for |
| 320 // appending. | 322 // appending. |
| 321 void appendRun(BidiRunList<Run>&); | 323 void appendRun(BidiRunList<Run>&); |
| 322 | 324 |
| 323 Run* addTrailingRun(BidiRunList<Run>&, | 325 Run* addTrailingRun(BidiRunList<Run>&, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 345 | 347 |
| 346 // FIXME: This should not belong to the resolver, but rather be passed | 348 // FIXME: This should not belong to the resolver, but rather be passed |
| 347 // into createBidiRunsForLine by the caller. | 349 // into createBidiRunsForLine by the caller. |
| 348 BidiRunList<Run> m_runs; | 350 BidiRunList<Run> m_runs; |
| 349 | 351 |
| 350 MidpointState<Iterator> m_midpointState; | 352 MidpointState<Iterator> m_midpointState; |
| 351 | 353 |
| 352 unsigned m_nestedIsolateCount; | 354 unsigned m_nestedIsolateCount; |
| 353 Vector<IsolatedRun> m_isolatedRuns; | 355 Vector<IsolatedRun> m_isolatedRuns; |
| 354 Run* m_trailingSpaceRun; | 356 Run* m_trailingSpaceRun; |
| 357 bool m_needsTrailingSpace; |
| 355 TextDirection m_paragraphDirectionality; | 358 TextDirection m_paragraphDirectionality; |
| 356 | 359 |
| 357 private: | 360 private: |
| 358 void raiseExplicitEmbeddingLevel(BidiRunList<Run>&, | 361 void raiseExplicitEmbeddingLevel(BidiRunList<Run>&, |
| 359 WTF::Unicode::CharDirection from, | 362 WTF::Unicode::CharDirection from, |
| 360 WTF::Unicode::CharDirection to); | 363 WTF::Unicode::CharDirection to); |
| 361 void lowerExplicitEmbeddingLevel(BidiRunList<Run>&, | 364 void lowerExplicitEmbeddingLevel(BidiRunList<Run>&, |
| 362 WTF::Unicode::CharDirection from); | 365 WTF::Unicode::CharDirection from); |
| 363 void checkDirectionInLowerRaiseEmbeddingLevel(); | 366 void checkDirectionInLowerRaiseEmbeddingLevel(); |
| 364 | 367 |
| 365 void updateStatusLastFromCurrentDirection(WTF::Unicode::CharDirection); | 368 void updateStatusLastFromCurrentDirection(WTF::Unicode::CharDirection); |
| 366 void reorderRunsFromLevels(BidiRunList<Run>&) const; | 369 void reorderRunsFromLevels(BidiRunList<Run>&) const; |
| 367 | 370 |
| 368 bool needsToApplyL1Rule(BidiRunList<Run>&) { return false; } | 371 bool needsTrailingSpace(BidiRunList<Run>&) { return m_needsTrailingSpace; } |
| 369 int findFirstTrailingSpaceAtRun(Run*) { return 0; } | 372 int findFirstTrailingSpaceAtRun(Run*) { return 0; } |
| 370 // http://www.unicode.org/reports/tr9/#L1 | 373 // http://www.unicode.org/reports/tr9/#L1 |
| 371 void applyL1Rule(BidiRunList<Run>&); | 374 void computeTrailingSpace(BidiRunList<Run>&); |
| 372 | 375 |
| 373 TextDirection determineDirectionalityInternal(bool breakOnParagraph, | 376 TextDirection determineDirectionalityInternal(bool breakOnParagraph, |
| 374 bool* hasStrongDirectionality); | 377 bool* hasStrongDirectionality); |
| 375 | 378 |
| 376 Vector<BidiEmbedding, 8> m_currentExplicitEmbeddingSequence; | 379 Vector<BidiEmbedding, 8> m_currentExplicitEmbeddingSequence; |
| 377 HashMap<Run*, MidpointState<Iterator>> m_midpointStateForIsolatedRun; | 380 HashMap<Run*, MidpointState<Iterator>> m_midpointStateForIsolatedRun; |
| 378 }; | 381 }; |
| 379 | 382 |
| 380 #if DCHECK_IS_ON() | 383 #if DCHECK_IS_ON() |
| 381 template <class Iterator, class Run, class IsolatedRun> | 384 template <class Iterator, class Run, class IsolatedRun> |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 535 | 538 |
| 536 appendRun(runs); | 539 appendRun(runs); |
| 537 m_emptyRun = true; | 540 m_emptyRun = true; |
| 538 | 541 |
| 539 setLastDir(to); | 542 setLastDir(to); |
| 540 setLastStrongDir(to); | 543 setLastStrongDir(to); |
| 541 m_eor = Iterator(); | 544 m_eor = Iterator(); |
| 542 } | 545 } |
| 543 | 546 |
| 544 template <class Iterator, class Run, class IsolatedRun> | 547 template <class Iterator, class Run, class IsolatedRun> |
| 545 void BidiResolver<Iterator, Run, IsolatedRun>::applyL1Rule( | 548 void BidiResolver<Iterator, Run, IsolatedRun>::computeTrailingSpace( |
| 546 BidiRunList<Run>& runs) { | 549 BidiRunList<Run>& runs) { |
| 547 ASSERT(runs.runCount()); | 550 ASSERT(runs.runCount()); |
| 548 if (!needsToApplyL1Rule(runs)) | |
| 549 return; | |
| 550 | 551 |
| 551 Run* trailingSpaceRun = runs.logicallyLastRun(); | 552 Run* trailingSpaceRun = runs.logicallyLastRun(); |
| 552 | 553 |
| 553 int firstSpace = findFirstTrailingSpaceAtRun(trailingSpaceRun); | 554 int firstSpace = findFirstTrailingSpaceAtRun(trailingSpaceRun); |
| 554 if (firstSpace == trailingSpaceRun->stop()) | 555 if (firstSpace == trailingSpaceRun->stop()) |
| 555 return; | 556 return; |
| 556 | 557 |
| 557 bool shouldReorder = | 558 bool shouldReorder = |
| 558 trailingSpaceRun != (m_paragraphDirectionality == TextDirection::kLtr | 559 trailingSpaceRun != (m_paragraphDirectionality == TextDirection::kLtr |
| 559 ? runs.lastRun() | 560 ? runs.lastRun() |
| 560 : runs.firstRun()); | 561 : runs.firstRun()); |
| 561 if (firstSpace != trailingSpaceRun->start()) { | 562 if (firstSpace != trailingSpaceRun->start()) { |
| 562 BidiContext* baseContext = context(); | 563 BidiContext* baseContext = context(); |
| 563 while (BidiContext* parent = baseContext->parent()) | 564 while (BidiContext* parent = baseContext->parent()) |
| 564 baseContext = parent; | 565 baseContext = parent; |
| 565 | 566 |
| 566 m_trailingSpaceRun = addTrailingRun( | 567 m_trailingSpaceRun = addTrailingRun( |
| 567 runs, firstSpace, trailingSpaceRun->m_stop, trailingSpaceRun, | 568 runs, firstSpace, trailingSpaceRun->m_stop, trailingSpaceRun, |
| 568 baseContext, m_paragraphDirectionality); | 569 baseContext, m_paragraphDirectionality); |
| 569 ASSERT(m_trailingSpaceRun); | 570 ASSERT(m_trailingSpaceRun); |
| 570 trailingSpaceRun->m_stop = firstSpace; | 571 trailingSpaceRun->m_stop = firstSpace; |
| 571 return; | 572 return; |
| 572 } | 573 } |
| 573 if (!shouldReorder) { | 574 if (!shouldReorder) { |
| 574 m_trailingSpaceRun = trailingSpaceRun; | 575 m_trailingSpaceRun = trailingSpaceRun; |
| 575 return; | 576 return; |
| 576 } | 577 } |
| 577 | 578 |
| 579 // Apply L1 rule. |
| 578 if (m_paragraphDirectionality == TextDirection::kLtr) { | 580 if (m_paragraphDirectionality == TextDirection::kLtr) { |
| 579 runs.moveRunToEnd(trailingSpaceRun); | 581 runs.moveRunToEnd(trailingSpaceRun); |
| 580 trailingSpaceRun->m_level = 0; | 582 trailingSpaceRun->m_level = 0; |
| 581 } else { | 583 } else { |
| 582 runs.moveRunToBeginning(trailingSpaceRun); | 584 runs.moveRunToBeginning(trailingSpaceRun); |
| 583 trailingSpaceRun->m_level = 1; | 585 trailingSpaceRun->m_level = 1; |
| 584 } | 586 } |
| 585 m_trailingSpaceRun = trailingSpaceRun; | 587 m_trailingSpaceRun = trailingSpaceRun; |
| 586 } | 588 } |
| 587 | 589 |
| (...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1196 } | 1198 } |
| 1197 } | 1199 } |
| 1198 } | 1200 } |
| 1199 | 1201 |
| 1200 m_runs.setLogicallyLastRun(m_runs.lastRun()); | 1202 m_runs.setLogicallyLastRun(m_runs.lastRun()); |
| 1201 if (reorderRuns) | 1203 if (reorderRuns) |
| 1202 reorderRunsFromLevels(m_runs); | 1204 reorderRunsFromLevels(m_runs); |
| 1203 m_endOfRunAtEndOfLine = Iterator(); | 1205 m_endOfRunAtEndOfLine = Iterator(); |
| 1204 m_endOfLine = Iterator(); | 1206 m_endOfLine = Iterator(); |
| 1205 | 1207 |
| 1206 if (!hardLineBreak && m_runs.runCount()) | 1208 if (!hardLineBreak && m_runs.runCount() && needsTrailingSpace(m_runs)) { |
| 1207 applyL1Rule(m_runs); | 1209 computeTrailingSpace(m_runs); |
| 1210 } |
| 1208 } | 1211 } |
| 1209 | 1212 |
| 1210 template <class Iterator, class Run, class IsolatedRun> | 1213 template <class Iterator, class Run, class IsolatedRun> |
| 1211 void BidiResolver<Iterator, Run, IsolatedRun>::setMidpointStateForIsolatedRun( | 1214 void BidiResolver<Iterator, Run, IsolatedRun>::setMidpointStateForIsolatedRun( |
| 1212 Run& run, | 1215 Run& run, |
| 1213 const MidpointState<Iterator>& midpoint) { | 1216 const MidpointState<Iterator>& midpoint) { |
| 1214 ASSERT(!m_midpointStateForIsolatedRun.contains(&run)); | 1217 ASSERT(!m_midpointStateForIsolatedRun.contains(&run)); |
| 1215 m_midpointStateForIsolatedRun.insert(&run, midpoint); | 1218 m_midpointStateForIsolatedRun.insert(&run, midpoint); |
| 1216 } | 1219 } |
| 1217 | 1220 |
| 1218 template <class Iterator, class Run, class IsolatedRun> | 1221 template <class Iterator, class Run, class IsolatedRun> |
| 1219 MidpointState<Iterator> | 1222 MidpointState<Iterator> |
| 1220 BidiResolver<Iterator, Run, IsolatedRun>::midpointStateForIsolatedRun( | 1223 BidiResolver<Iterator, Run, IsolatedRun>::midpointStateForIsolatedRun( |
| 1221 Run& run) { | 1224 Run& run) { |
| 1222 return m_midpointStateForIsolatedRun.take(&run); | 1225 return m_midpointStateForIsolatedRun.take(&run); |
| 1223 } | 1226 } |
| 1224 | 1227 |
| 1225 } // namespace blink | 1228 } // namespace blink |
| 1226 | 1229 |
| 1227 #endif // BidiResolver_h | 1230 #endif // BidiResolver_h |
| OLD | NEW |