| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2013, Opera Software ASA. All rights reserved. | 2 * Copyright (c) 2013, Opera Software ASA. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 #include "core/dom/DocumentFragment.h" | 38 #include "core/dom/DocumentFragment.h" |
| 39 #include "core/dom/NodeTraversal.h" | 39 #include "core/dom/NodeTraversal.h" |
| 40 #include "core/events/Event.h" | 40 #include "core/events/Event.h" |
| 41 #include "core/html/HTMLDivElement.h" | 41 #include "core/html/HTMLDivElement.h" |
| 42 #include "core/html/track/TextTrack.h" | 42 #include "core/html/track/TextTrack.h" |
| 43 #include "core/html/track/TextTrackCueList.h" | 43 #include "core/html/track/TextTrackCueList.h" |
| 44 #include "core/html/track/vtt/VTTElement.h" | 44 #include "core/html/track/vtt/VTTElement.h" |
| 45 #include "core/html/track/vtt/VTTParser.h" | 45 #include "core/html/track/vtt/VTTParser.h" |
| 46 #include "core/html/track/vtt/VTTRegionList.h" | 46 #include "core/html/track/vtt/VTTRegionList.h" |
| 47 #include "core/rendering/RenderVTTCue.h" | 47 #include "core/rendering/RenderVTTCue.h" |
| 48 #include "platform/graphics/TextRunIterator.h" |
| 49 #include "platform/text/BidiResolver.h" |
| 48 #include "wtf/MathExtras.h" | 50 #include "wtf/MathExtras.h" |
| 49 #include "wtf/text/StringBuilder.h" | 51 #include "wtf/text/StringBuilder.h" |
| 50 | 52 |
| 51 namespace WebCore { | 53 namespace WebCore { |
| 52 | 54 |
| 53 static const int undefinedPosition = -1; | 55 static const int undefinedPosition = -1; |
| 54 | 56 |
| 55 static const CSSValueID displayWritingModeMap[] = { | 57 static const CSSValueID displayWritingModeMap[] = { |
| 56 CSSValueHorizontalTb, CSSValueVerticalRl, CSSValueVerticalLr | 58 CSSValueHorizontalTb, CSSValueVerticalRl, CSSValueVerticalLr |
| 57 }; | 59 }; |
| (...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 490 | 492 |
| 491 // Increment n by one. | 493 // Increment n by one. |
| 492 n++; | 494 n++; |
| 493 | 495 |
| 494 // Negate n. | 496 // Negate n. |
| 495 n = -n; | 497 n = -n; |
| 496 | 498 |
| 497 return n; | 499 return n; |
| 498 } | 500 } |
| 499 | 501 |
| 500 static bool isCueParagraphSeparator(UChar character) | 502 class VTTTextRunIterator : public TextRunIterator { |
| 503 public: |
| 504 VTTTextRunIterator() { } |
| 505 VTTTextRunIterator(const TextRun* textRun, unsigned offset) : TextRunIterato
r(textRun, offset) { } |
| 506 |
| 507 bool atParagraphSeparator() const |
| 508 { |
| 509 // Within a cue, paragraph boundaries are only denoted by Type B charact
ers, |
| 510 // such as U+000A LINE FEED (LF), U+0085 NEXT LINE (NEL), and U+2029 PAR
AGRAPH SEPARATOR. |
| 511 return WTF::Unicode::category(current()) & WTF::Unicode::Separator_Parag
raph; |
| 512 } |
| 513 }; |
| 514 |
| 515 // Almost the same as determineDirectionality in core/html/HTMLElement.cpp, but |
| 516 // that one uses a "plain" TextRunIterator (which only checks for '\n'). |
| 517 static TextDirection determineDirectionality(const String& value, bool& hasStron
gDirectionality) |
| 501 { | 518 { |
| 502 // Within a cue, paragraph boundaries are only denoted by Type B characters, | 519 TextRun run(value); |
| 503 // such as U+000A LINE FEED (LF), U+0085 NEXT LINE (NEL), and U+2029 PARAGRA
PH SEPARATOR. | 520 BidiResolver<VTTTextRunIterator, BidiCharacterRun> bidiResolver; |
| 504 return WTF::Unicode::category(character) & WTF::Unicode::Separator_Paragraph
; | 521 bidiResolver.setStatus(BidiStatus(LTR, false)); |
| 522 bidiResolver.setPositionIgnoringNestedIsolates(VTTTextRunIterator(&run, 0)); |
| 523 return bidiResolver.determineParagraphDirectionality(&hasStrongDirectionalit
y); |
| 505 } | 524 } |
| 506 | 525 |
| 507 void VTTCue::determineTextDirection() | 526 static CSSValueID determineTextDirection(DocumentFragment* vttRoot) |
| 508 { | 527 { |
| 509 DEFINE_STATIC_LOCAL(const String, rtTag, ("rt")); | 528 DEFINE_STATIC_LOCAL(const String, rtTag, ("rt")); |
| 510 createVTTNodeTree(); | 529 ASSERT(vttRoot); |
| 511 | 530 |
| 512 // Apply the Unicode Bidirectional Algorithm's Paragraph Level steps to the | 531 // Apply the Unicode Bidirectional Algorithm's Paragraph Level steps to the |
| 513 // concatenation of the values of each WebVTT Text Object in nodes, in a | 532 // concatenation of the values of each WebVTT Text Object in nodes, in a |
| 514 // pre-order, depth-first traversal, excluding WebVTT Ruby Text Objects and | 533 // pre-order, depth-first traversal, excluding WebVTT Ruby Text Objects and |
| 515 // their descendants. | 534 // their descendants. |
| 516 StringBuilder paragraphBuilder; | 535 TextDirection textDirection = LTR; |
| 517 for (Node* node = m_vttNodeTree->firstChild(); node; node = NodeTraversal::n
ext(*node, m_vttNodeTree.get())) { | 536 for (Node* node = vttRoot->firstChild(); node; node = NodeTraversal::next(*n
ode, vttRoot)) { |
| 518 if (!node->isTextNode() || node->localName() == rtTag) | 537 if (!node->isTextNode() || node->localName() == rtTag) |
| 519 continue; | 538 continue; |
| 520 | 539 |
| 521 paragraphBuilder.append(node->nodeValue()); | 540 bool hasStrongDirectionality; |
| 541 textDirection = determineDirectionality(node->nodeValue(), hasStrongDire
ctionality); |
| 542 if (hasStrongDirectionality) |
| 543 break; |
| 522 } | 544 } |
| 523 | 545 return isLeftToRightDirection(textDirection) ? CSSValueLtr : CSSValueRtl; |
| 524 String paragraph = paragraphBuilder.toString(); | |
| 525 if (!paragraph.length()) | |
| 526 return; | |
| 527 | |
| 528 for (size_t i = 0; i < paragraph.length(); ++i) { | |
| 529 UChar current = paragraph[i]; | |
| 530 if (!current || isCueParagraphSeparator(current)) | |
| 531 return; | |
| 532 | |
| 533 if (UChar current = paragraph[i]) { | |
| 534 WTF::Unicode::Direction charDirection = WTF::Unicode::direction(curr
ent); | |
| 535 if (charDirection == WTF::Unicode::LeftToRight) { | |
| 536 m_displayDirection = CSSValueLtr; | |
| 537 return; | |
| 538 } | |
| 539 if (charDirection == WTF::Unicode::RightToLeft | |
| 540 || charDirection == WTF::Unicode::RightToLeftArabic) { | |
| 541 m_displayDirection = CSSValueRtl; | |
| 542 return; | |
| 543 } | |
| 544 } | |
| 545 } | |
| 546 } | 546 } |
| 547 | 547 |
| 548 void VTTCue::calculateDisplayParameters() | 548 void VTTCue::calculateDisplayParameters() |
| 549 { | 549 { |
| 550 createVTTNodeTree(); |
| 551 |
| 550 // Steps 10.2, 10.3 | 552 // Steps 10.2, 10.3 |
| 551 determineTextDirection(); | 553 m_displayDirection = determineTextDirection(m_vttNodeTree.get()); |
| 552 | 554 |
| 553 // 10.4 If the text track cue writing direction is horizontal, then let | 555 // 10.4 If the text track cue writing direction is horizontal, then let |
| 554 // block-flow be 'tb'. Otherwise, if the text track cue writing direction is | 556 // block-flow be 'tb'. Otherwise, if the text track cue writing direction is |
| 555 // vertical growing left, then let block-flow be 'lr'. Otherwise, the text | 557 // vertical growing left, then let block-flow be 'lr'. Otherwise, the text |
| 556 // track cue writing direction is vertical growing right; let block-flow be | 558 // track cue writing direction is vertical growing right; let block-flow be |
| 557 // 'rl'. | 559 // 'rl'. |
| 558 | 560 |
| 559 // The above step is done through the writing direction static map. | 561 // The above step is done through the writing direction static map. |
| 560 | 562 |
| 561 // 10.5 Determine the value of maximum size for cue as per the appropriate | 563 // 10.5 Determine the value of maximum size for cue as per the appropriate |
| (...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1108 return m_cueBackgroundBox->executionContext(); | 1110 return m_cueBackgroundBox->executionContext(); |
| 1109 } | 1111 } |
| 1110 | 1112 |
| 1111 Document& VTTCue::document() const | 1113 Document& VTTCue::document() const |
| 1112 { | 1114 { |
| 1113 ASSERT(m_cueBackgroundBox); | 1115 ASSERT(m_cueBackgroundBox); |
| 1114 return m_cueBackgroundBox->document(); | 1116 return m_cueBackgroundBox->document(); |
| 1115 } | 1117 } |
| 1116 | 1118 |
| 1117 } // namespace WebCore | 1119 } // namespace WebCore |
| OLD | NEW |