| 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 28 matching lines...) Expand all Loading... |
| 39 #include "core/events/Event.h" | 39 #include "core/events/Event.h" |
| 40 #include "core/frame/UseCounter.h" | 40 #include "core/frame/UseCounter.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/html/track/vtt/VTTScanner.h" | 47 #include "core/html/track/vtt/VTTScanner.h" |
| 48 #include "core/rendering/RenderVTTCue.h" | 48 #include "core/rendering/RenderVTTCue.h" |
| 49 #include "platform/FloatConversion.h" |
| 49 #include "platform/RuntimeEnabledFeatures.h" | 50 #include "platform/RuntimeEnabledFeatures.h" |
| 50 #include "platform/text/BidiResolver.h" | 51 #include "platform/text/BidiResolver.h" |
| 51 #include "platform/text/TextRunIterator.h" | 52 #include "platform/text/TextRunIterator.h" |
| 52 #include "wtf/MathExtras.h" | 53 #include "wtf/MathExtras.h" |
| 53 #include "wtf/text/StringBuilder.h" | 54 #include "wtf/text/StringBuilder.h" |
| 54 | 55 |
| 55 namespace blink { | 56 namespace blink { |
| 56 | 57 |
| 57 static const int undefinedPosition = -1; | 58 static const float undefinedPosition = -1; |
| 58 static const int undefinedSize = -1; | 59 static const float undefinedSize = -1; |
| 59 | 60 |
| 60 static const CSSValueID displayWritingModeMap[] = { | 61 static const CSSValueID displayWritingModeMap[] = { |
| 61 CSSValueHorizontalTb, CSSValueVerticalRl, CSSValueVerticalLr | 62 CSSValueHorizontalTb, CSSValueVerticalRl, CSSValueVerticalLr |
| 62 }; | 63 }; |
| 63 static_assert(WTF_ARRAY_LENGTH(displayWritingModeMap) == VTTCue::NumberOfWriting
Directions, | 64 static_assert(WTF_ARRAY_LENGTH(displayWritingModeMap) == VTTCue::NumberOfWriting
Directions, |
| 64 "displayWritingModeMap should have the same number of elements as VTTCue::Nu
mberOfWritingDirections"); | 65 "displayWritingModeMap should have the same number of elements as VTTCue::Nu
mberOfWritingDirections"); |
| 65 | 66 |
| 66 static const CSSValueID displayAlignmentMap[] = { | 67 static const CSSValueID displayAlignmentMap[] = { |
| 67 CSSValueStart, CSSValueCenter, CSSValueEnd, CSSValueLeft, CSSValueRight | 68 CSSValueStart, CSSValueCenter, CSSValueEnd, CSSValueLeft, CSSValueRight |
| 68 }; | 69 }; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 DEFINE_STATIC_LOCAL(const String, verticalrl, ("rl")); | 110 DEFINE_STATIC_LOCAL(const String, verticalrl, ("rl")); |
| 110 return verticalrl; | 111 return verticalrl; |
| 111 } | 112 } |
| 112 | 113 |
| 113 static const String& verticalGrowingRightKeyword() | 114 static const String& verticalGrowingRightKeyword() |
| 114 { | 115 { |
| 115 DEFINE_STATIC_LOCAL(const String, verticallr, ("lr")); | 116 DEFINE_STATIC_LOCAL(const String, verticallr, ("lr")); |
| 116 return verticallr; | 117 return verticallr; |
| 117 } | 118 } |
| 118 | 119 |
| 119 static bool isInvalidPercentage(int value, ExceptionState& exceptionState) | 120 static bool isInvalidPercentage(double value, ExceptionState& exceptionState) |
| 120 { | 121 { |
| 122 ASSERT(std::isfinite(value)); |
| 121 if (value < 0 || value > 100) { | 123 if (value < 0 || value > 100) { |
| 122 exceptionState.throwDOMException(IndexSizeError, ExceptionMessages::inde
xOutsideRange("value", value, 0, ExceptionMessages::InclusiveBound, 100, Excepti
onMessages::InclusiveBound)); | 124 exceptionState.throwDOMException(IndexSizeError, ExceptionMessages::inde
xOutsideRange<double>("value", value, 0, ExceptionMessages::InclusiveBound, 100,
ExceptionMessages::InclusiveBound)); |
| 123 return true; | 125 return true; |
| 124 } | 126 } |
| 125 return false; | 127 return false; |
| 126 } | 128 } |
| 127 | 129 |
| 128 VTTCueBox::VTTCueBox(Document& document, VTTCue* cue) | 130 VTTCueBox::VTTCueBox(Document& document, VTTCue* cue) |
| 129 : HTMLDivElement(document) | 131 : HTMLDivElement(document) |
| 130 , m_cue(cue) | 132 , m_cue(cue) |
| 131 { | 133 { |
| 132 setShadowPseudoId(AtomicString("-webkit-media-text-track-display", AtomicStr
ing::ConstructFromLiteral)); | 134 setShadowPseudoId(AtomicString("-webkit-media-text-track-display", AtomicStr
ing::ConstructFromLiteral)); |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 void VTTCue::setSnapToLines(bool value) | 299 void VTTCue::setSnapToLines(bool value) |
| 298 { | 300 { |
| 299 if (m_snapToLines == value) | 301 if (m_snapToLines == value) |
| 300 return; | 302 return; |
| 301 | 303 |
| 302 cueWillChange(); | 304 cueWillChange(); |
| 303 m_snapToLines = value; | 305 m_snapToLines = value; |
| 304 cueDidChange(); | 306 cueDidChange(); |
| 305 } | 307 } |
| 306 | 308 |
| 307 void VTTCue::setLine(int position, ExceptionState& exceptionState) | 309 void VTTCue::setLine(double position, ExceptionState& exceptionState) |
| 308 { | 310 { |
| 309 // http://www.whatwg.org/specs/web-apps/current-work/multipage/the-video-ele
ment.html#dom-texttrackcue-line | 311 // http://www.whatwg.org/specs/web-apps/current-work/multipage/the-video-ele
ment.html#dom-texttrackcue-line |
| 310 // On setting, if the text track cue snap-to-lines flag is not set, and the
new | 312 // On setting, if the text track cue snap-to-lines flag is not set, and the
new |
| 311 // value is negative or greater than 100, then throw an IndexSizeError excep
tion. | 313 // value is negative or greater than 100, then throw an IndexSizeError excep
tion. |
| 312 if (!m_snapToLines && (position < 0 || position > 100)) { | 314 if (!m_snapToLines && (position < 0 || position > 100)) { |
| 313 exceptionState.throwDOMException(IndexSizeError, "The snap-to-lines flag
is not set, and the value provided (" + String::number(position) + ") is not be
tween 0 and 100."); | 315 exceptionState.throwDOMException(IndexSizeError, "The snap-to-lines flag
is not set, and the value provided (" + String::number(position) + ") is not be
tween 0 and 100."); |
| 314 return; | 316 return; |
| 315 } | 317 } |
| 316 | 318 |
| 317 // Otherwise, set the text track cue line position to the new value. | 319 // Otherwise, set the text track cue line position to the new value. |
| 318 if (m_linePosition == position) | 320 float floatPosition = narrowPrecisionToFloat(position); |
| 321 if (m_linePosition == floatPosition) |
| 319 return; | 322 return; |
| 320 | 323 |
| 321 cueWillChange(); | 324 cueWillChange(); |
| 322 m_linePosition = position; | 325 m_linePosition = floatPosition; |
| 323 m_computedLinePosition = calculateComputedLinePosition(); | 326 m_computedLinePosition = calculateComputedLinePosition(); |
| 324 cueDidChange(); | 327 cueDidChange(); |
| 325 } | 328 } |
| 326 | 329 |
| 327 void VTTCue::setPosition(int position, ExceptionState& exceptionState) | 330 void VTTCue::setPosition(double position, ExceptionState& exceptionState) |
| 328 { | 331 { |
| 329 // http://www.whatwg.org/specs/web-apps/current-work/multipage/the-video-ele
ment.html#dom-texttrackcue-position | 332 // http://www.whatwg.org/specs/web-apps/current-work/multipage/the-video-ele
ment.html#dom-texttrackcue-position |
| 330 // On setting, if the new value is negative or greater than 100, then throw
an IndexSizeError exception. | 333 // On setting, if the new value is negative or greater than 100, then throw
an IndexSizeError exception. |
| 331 // Otherwise, set the text track cue text position to the new value. | 334 // Otherwise, set the text track cue text position to the new value. |
| 332 if (isInvalidPercentage(position, exceptionState)) | 335 if (isInvalidPercentage(position, exceptionState)) |
| 333 return; | 336 return; |
| 334 | 337 |
| 335 // Otherwise, set the text track cue line position to the new value. | 338 // Otherwise, set the text track cue line position to the new value. |
| 336 if (m_textPosition == position) | 339 float floatPosition = narrowPrecisionToFloat(position); |
| 340 if (m_textPosition == floatPosition) |
| 337 return; | 341 return; |
| 338 | 342 |
| 339 cueWillChange(); | 343 cueWillChange(); |
| 340 m_textPosition = position; | 344 m_textPosition = floatPosition; |
| 341 cueDidChange(); | 345 cueDidChange(); |
| 342 } | 346 } |
| 343 | 347 |
| 344 void VTTCue::setSize(int size, ExceptionState& exceptionState) | 348 void VTTCue::setSize(double size, ExceptionState& exceptionState) |
| 345 { | 349 { |
| 346 // http://www.whatwg.org/specs/web-apps/current-work/multipage/the-video-ele
ment.html#dom-texttrackcue-size | 350 // http://www.whatwg.org/specs/web-apps/current-work/multipage/the-video-ele
ment.html#dom-texttrackcue-size |
| 347 // On setting, if the new value is negative or greater than 100, then throw
an IndexSizeError | 351 // On setting, if the new value is negative or greater than 100, then throw
an IndexSizeError |
| 348 // exception. Otherwise, set the text track cue size to the new value. | 352 // exception. Otherwise, set the text track cue size to the new value. |
| 349 if (isInvalidPercentage(size, exceptionState)) | 353 if (isInvalidPercentage(size, exceptionState)) |
| 350 return; | 354 return; |
| 351 | 355 |
| 352 // Otherwise, set the text track cue line position to the new value. | 356 // Otherwise, set the text track cue line position to the new value. |
| 353 if (m_cueSize == size) | 357 float floatSize = narrowPrecisionToFloat(size); |
| 358 if (m_cueSize == floatSize) |
| 354 return; | 359 return; |
| 355 | 360 |
| 356 cueWillChange(); | 361 cueWillChange(); |
| 357 m_cueSize = size; | 362 m_cueSize = floatSize; |
| 358 cueDidChange(); | 363 cueDidChange(); |
| 359 } | 364 } |
| 360 | 365 |
| 361 const String& VTTCue::align() const | 366 const String& VTTCue::align() const |
| 362 { | 367 { |
| 363 switch (m_cueAlignment) { | 368 switch (m_cueAlignment) { |
| 364 case Start: | 369 case Start: |
| 365 return startKeyword(); | 370 return startKeyword(); |
| 366 case Middle: | 371 case Middle: |
| 367 return middleKeyword(); | 372 return middleKeyword(); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 cueWillChange(); | 463 cueWillChange(); |
| 459 m_regionId = regionId; | 464 m_regionId = regionId; |
| 460 cueDidChange(); | 465 cueDidChange(); |
| 461 } | 466 } |
| 462 | 467 |
| 463 void VTTCue::notifyRegionWhenRemovingDisplayTree(bool notifyRegion) | 468 void VTTCue::notifyRegionWhenRemovingDisplayTree(bool notifyRegion) |
| 464 { | 469 { |
| 465 m_notifyRegion = notifyRegion; | 470 m_notifyRegion = notifyRegion; |
| 466 } | 471 } |
| 467 | 472 |
| 468 int VTTCue::calculateComputedLinePosition() | 473 float VTTCue::calculateComputedLinePosition() |
| 469 { | 474 { |
| 470 // http://www.whatwg.org/specs/web-apps/current-work/multipage/the-video-ele
ment.html#text-track-cue-computed-line-position | 475 // http://www.whatwg.org/specs/web-apps/current-work/multipage/the-video-ele
ment.html#text-track-cue-computed-line-position |
| 471 | 476 |
| 472 // If the text track cue line position is numeric, then that is the text | 477 // If the text track cue line position is numeric, then that is the text |
| 473 // track cue computed line position. | 478 // track cue computed line position. |
| 474 if (m_linePosition != undefinedPosition) | 479 if (m_linePosition != undefinedPosition) |
| 475 return m_linePosition; | 480 return m_linePosition; |
| 476 | 481 |
| 477 // If the text track cue snap-to-lines flag of the text track cue is not | 482 // If the text track cue snap-to-lines flag of the text track cue is not |
| 478 // set, the text track cue computed line position is the value 100; | 483 // set, the text track cue computed line position is the value 100; |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 580 // 10.4 If the text track cue writing direction is horizontal, then let | 585 // 10.4 If the text track cue writing direction is horizontal, then let |
| 581 // block-flow be 'tb'. Otherwise, if the text track cue writing direction is | 586 // block-flow be 'tb'. Otherwise, if the text track cue writing direction is |
| 582 // vertical growing left, then let block-flow be 'lr'. Otherwise, the text | 587 // vertical growing left, then let block-flow be 'lr'. Otherwise, the text |
| 583 // track cue writing direction is vertical growing right; let block-flow be | 588 // track cue writing direction is vertical growing right; let block-flow be |
| 584 // 'rl'. | 589 // 'rl'. |
| 585 | 590 |
| 586 // The above step is done through the writing direction static map. | 591 // The above step is done through the writing direction static map. |
| 587 | 592 |
| 588 // 10.5 Determine the value of maximum size for cue as per the appropriate | 593 // 10.5 Determine the value of maximum size for cue as per the appropriate |
| 589 // rules from the following list: | 594 // rules from the following list: |
| 590 int maximumSize = m_textPosition; | 595 float maximumSize = m_textPosition; |
| 591 if ((m_writingDirection == Horizontal && m_cueAlignment == Start && m_displa
yDirection == CSSValueLtr) | 596 if ((m_writingDirection == Horizontal && m_cueAlignment == Start && m_displa
yDirection == CSSValueLtr) |
| 592 || (m_writingDirection == Horizontal && m_cueAlignment == End && m_displ
ayDirection == CSSValueRtl) | 597 || (m_writingDirection == Horizontal && m_cueAlignment == End && m_displ
ayDirection == CSSValueRtl) |
| 593 || (m_writingDirection == Horizontal && m_cueAlignment == Left) | 598 || (m_writingDirection == Horizontal && m_cueAlignment == Left) |
| 594 || (m_writingDirection == VerticalGrowingLeft && (m_cueAlignment == Star
t || m_cueAlignment == Left)) | 599 || (m_writingDirection == VerticalGrowingLeft && (m_cueAlignment == Star
t || m_cueAlignment == Left)) |
| 595 || (m_writingDirection == VerticalGrowingRight && (m_cueAlignment == Sta
rt || m_cueAlignment == Left))) { | 600 || (m_writingDirection == VerticalGrowingRight && (m_cueAlignment == Sta
rt || m_cueAlignment == Left))) { |
| 596 maximumSize = 100 - m_textPosition; | 601 maximumSize = 100 - m_textPosition; |
| 597 } else if ((m_writingDirection == Horizontal && m_cueAlignment == End && m_d
isplayDirection == CSSValueLtr) | 602 } else if ((m_writingDirection == Horizontal && m_cueAlignment == End && m_d
isplayDirection == CSSValueLtr) |
| 598 || (m_writingDirection == Horizontal && m_cueAlignment == Start && m_dis
playDirection == CSSValueRtl) | 603 || (m_writingDirection == Horizontal && m_cueAlignment == Start && m_dis
playDirection == CSSValueRtl) |
| 599 || (m_writingDirection == Horizontal && m_cueAlignment == Right) | 604 || (m_writingDirection == Horizontal && m_cueAlignment == Right) |
| 600 || (m_writingDirection == VerticalGrowingLeft && (m_cueAlignment == End
|| m_cueAlignment == Right)) | 605 || (m_writingDirection == VerticalGrowingLeft && (m_cueAlignment == End
|| m_cueAlignment == Right)) |
| 601 || (m_writingDirection == VerticalGrowingRight && (m_cueAlignment == End
|| m_cueAlignment == Right))) { | 606 || (m_writingDirection == VerticalGrowingRight && (m_cueAlignment == End
|| m_cueAlignment == Right))) { |
| 602 maximumSize = m_textPosition; | 607 maximumSize = m_textPosition; |
| 603 } else if (m_cueAlignment == Middle) { | 608 } else if (m_cueAlignment == Middle) { |
| 604 maximumSize = m_textPosition <= 50 ? m_textPosition : (100 - m_textPosit
ion); | 609 maximumSize = m_textPosition <= 50 ? m_textPosition : (100 - m_textPosit
ion); |
| 605 maximumSize = maximumSize * 2; | 610 maximumSize = maximumSize * 2; |
| 606 } else { | 611 } else { |
| 607 ASSERT_NOT_REACHED(); | 612 ASSERT_NOT_REACHED(); |
| 608 } | 613 } |
| 609 | 614 |
| 610 // 10.6 If the text track cue size is less than maximum size, then let size | 615 // 10.6 If the text track cue size is less than maximum size, then let size |
| 611 // be text track cue size. Otherwise, let size be maximum size. | 616 // be text track cue size. Otherwise, let size be maximum size. |
| 612 m_displaySize = std::min(m_cueSize, maximumSize); | 617 m_displaySize = std::min(m_cueSize, maximumSize); |
| 613 | 618 |
| 614 // FIXME: Understand why step 10.7 is missing (just a copy/paste error?) | 619 // FIXME: Understand why step 10.7 is missing (just a copy/paste error?) |
| 615 // Could be done within a spec implementation check - http://crbug.com/30158
0 | 620 // Could be done within a spec implementation check - http://crbug.com/30158
0 |
| 616 | 621 |
| 617 // 10.8 Determine the value of x-position or y-position for cue as per the | 622 // 10.8 Determine the value of x-position or y-position for cue as per the |
| 618 // appropriate rules from the following list: | 623 // appropriate rules from the following list: |
| 619 if (m_writingDirection == Horizontal) { | 624 if (m_writingDirection == Horizontal) { |
| 620 int visualTextPosition = m_displayDirection == CSSValueLtr ? m_textPosit
ion : 100 - m_textPosition; | 625 float visualTextPosition = m_displayDirection == CSSValueLtr ? m_textPos
ition : 100 - m_textPosition; |
| 621 | 626 |
| 622 switch (resolveCueAlignment(m_cueAlignment, m_displayDirection)) { | 627 switch (resolveCueAlignment(m_cueAlignment, m_displayDirection)) { |
| 623 case Left: | 628 case Left: |
| 624 m_displayPosition.setX(visualTextPosition); | 629 m_displayPosition.setX(visualTextPosition); |
| 625 break; | 630 break; |
| 626 case Right: | 631 case Right: |
| 627 m_displayPosition.setX(visualTextPosition - m_displaySize); | 632 m_displayPosition.setX(visualTextPosition - m_displaySize); |
| 628 break; | 633 break; |
| 629 case Middle: | 634 case Middle: |
| 630 m_displayPosition.setX(visualTextPosition - m_displaySize / 2); | 635 m_displayPosition.setX(visualTextPosition - m_displaySize / 2); |
| (...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1045 CSSValueID VTTCue::getCSSWritingDirection() const | 1050 CSSValueID VTTCue::getCSSWritingDirection() const |
| 1046 { | 1051 { |
| 1047 return m_displayDirection; | 1052 return m_displayDirection; |
| 1048 } | 1053 } |
| 1049 | 1054 |
| 1050 CSSValueID VTTCue::getCSSWritingMode() const | 1055 CSSValueID VTTCue::getCSSWritingMode() const |
| 1051 { | 1056 { |
| 1052 return displayWritingModeMap[m_writingDirection]; | 1057 return displayWritingModeMap[m_writingDirection]; |
| 1053 } | 1058 } |
| 1054 | 1059 |
| 1055 int VTTCue::getCSSSize() const | 1060 float VTTCue::getCSSSize() const |
| 1056 { | 1061 { |
| 1057 ASSERT(m_displaySize != undefinedSize); | 1062 ASSERT(m_displaySize != undefinedSize); |
| 1058 return m_displaySize; | 1063 return m_displaySize; |
| 1059 } | 1064 } |
| 1060 | 1065 |
| 1061 FloatPoint VTTCue::getCSSPosition() const | 1066 FloatPoint VTTCue::getCSSPosition() const |
| 1062 { | 1067 { |
| 1063 if (!m_snapToLines) | 1068 if (!m_snapToLines) |
| 1064 return getPositionCoordinates(); | 1069 return getPositionCoordinates(); |
| 1065 | 1070 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1080 | 1085 |
| 1081 void VTTCue::trace(Visitor* visitor) | 1086 void VTTCue::trace(Visitor* visitor) |
| 1082 { | 1087 { |
| 1083 visitor->trace(m_vttNodeTree); | 1088 visitor->trace(m_vttNodeTree); |
| 1084 visitor->trace(m_cueBackgroundBox); | 1089 visitor->trace(m_cueBackgroundBox); |
| 1085 visitor->trace(m_displayTree); | 1090 visitor->trace(m_displayTree); |
| 1086 TextTrackCue::trace(visitor); | 1091 TextTrackCue::trace(visitor); |
| 1087 } | 1092 } |
| 1088 | 1093 |
| 1089 } // namespace blink | 1094 } // namespace blink |
| OLD | NEW |