Chromium Code Reviews| 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 { |
| 121 if (value < 0 || value > 100) { | 122 if (value < 0 || value > 100) { |
|
philipj_slow
2015/01/20 10:07:38
Maybe ASSERT(std::isfinite(value)) since we're a f
fs
2015/01/20 10:22:49
Done.
| |
| 122 exceptionState.throwDOMException(IndexSizeError, ExceptionMessages::inde xOutsideRange("value", value, 0, ExceptionMessages::InclusiveBound, 100, Excepti onMessages::InclusiveBound)); | 123 exceptionState.throwDOMException(IndexSizeError, ExceptionMessages::inde xOutsideRange<double>("value", value, 0, ExceptionMessages::InclusiveBound, 100, ExceptionMessages::InclusiveBound)); |
| 123 return true; | 124 return true; |
| 124 } | 125 } |
| 125 return false; | 126 return false; |
| 126 } | 127 } |
| 127 | 128 |
| 128 VTTCueBox::VTTCueBox(Document& document, VTTCue* cue) | 129 VTTCueBox::VTTCueBox(Document& document, VTTCue* cue) |
| 129 : HTMLDivElement(document) | 130 : HTMLDivElement(document) |
| 130 , m_cue(cue) | 131 , m_cue(cue) |
| 131 { | 132 { |
| 132 setShadowPseudoId(AtomicString("-webkit-media-text-track-display", AtomicStr ing::ConstructFromLiteral)); | 133 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) | 298 void VTTCue::setSnapToLines(bool value) |
| 298 { | 299 { |
| 299 if (m_snapToLines == value) | 300 if (m_snapToLines == value) |
| 300 return; | 301 return; |
| 301 | 302 |
| 302 cueWillChange(); | 303 cueWillChange(); |
| 303 m_snapToLines = value; | 304 m_snapToLines = value; |
| 304 cueDidChange(); | 305 cueDidChange(); |
| 305 } | 306 } |
| 306 | 307 |
| 307 void VTTCue::setLine(int position, ExceptionState& exceptionState) | 308 void VTTCue::setLine(double position, ExceptionState& exceptionState) |
| 308 { | 309 { |
| 309 // http://www.whatwg.org/specs/web-apps/current-work/multipage/the-video-ele ment.html#dom-texttrackcue-line | 310 // 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 | 311 // 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. | 312 // value is negative or greater than 100, then throw an IndexSizeError excep tion. |
| 312 if (!m_snapToLines && (position < 0 || position > 100)) { | 313 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."); | 314 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; | 315 return; |
| 315 } | 316 } |
| 316 | 317 |
| 317 // Otherwise, set the text track cue line position to the new value. | 318 // Otherwise, set the text track cue line position to the new value. |
| 318 if (m_linePosition == position) | 319 float floatPosition = narrowPrecisionToFloat(position); |
| 320 if (m_linePosition == floatPosition) | |
| 319 return; | 321 return; |
| 320 | 322 |
| 321 cueWillChange(); | 323 cueWillChange(); |
| 322 m_linePosition = position; | 324 m_linePosition = floatPosition; |
| 323 m_computedLinePosition = calculateComputedLinePosition(); | 325 m_computedLinePosition = calculateComputedLinePosition(); |
| 324 cueDidChange(); | 326 cueDidChange(); |
| 325 } | 327 } |
| 326 | 328 |
| 327 void VTTCue::setPosition(int position, ExceptionState& exceptionState) | 329 void VTTCue::setPosition(double position, ExceptionState& exceptionState) |
| 328 { | 330 { |
| 329 // http://www.whatwg.org/specs/web-apps/current-work/multipage/the-video-ele ment.html#dom-texttrackcue-position | 331 // 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. | 332 // 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. | 333 // Otherwise, set the text track cue text position to the new value. |
| 332 if (isInvalidPercentage(position, exceptionState)) | 334 if (isInvalidPercentage(position, exceptionState)) |
| 333 return; | 335 return; |
| 334 | 336 |
| 335 // Otherwise, set the text track cue line position to the new value. | 337 // Otherwise, set the text track cue line position to the new value. |
| 336 if (m_textPosition == position) | 338 float floatPosition = narrowPrecisionToFloat(position); |
| 339 if (m_textPosition == floatPosition) | |
| 337 return; | 340 return; |
| 338 | 341 |
| 339 cueWillChange(); | 342 cueWillChange(); |
| 340 m_textPosition = position; | 343 m_textPosition = floatPosition; |
| 341 cueDidChange(); | 344 cueDidChange(); |
| 342 } | 345 } |
| 343 | 346 |
| 344 void VTTCue::setSize(int size, ExceptionState& exceptionState) | 347 void VTTCue::setSize(double size, ExceptionState& exceptionState) |
| 345 { | 348 { |
| 346 // http://www.whatwg.org/specs/web-apps/current-work/multipage/the-video-ele ment.html#dom-texttrackcue-size | 349 // 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 | 350 // 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. | 351 // exception. Otherwise, set the text track cue size to the new value. |
| 349 if (isInvalidPercentage(size, exceptionState)) | 352 if (isInvalidPercentage(size, exceptionState)) |
| 350 return; | 353 return; |
| 351 | 354 |
| 352 // Otherwise, set the text track cue line position to the new value. | 355 // Otherwise, set the text track cue line position to the new value. |
| 353 if (m_cueSize == size) | 356 float floatSize = narrowPrecisionToFloat(size); |
| 357 if (m_cueSize == floatSize) | |
| 354 return; | 358 return; |
| 355 | 359 |
| 356 cueWillChange(); | 360 cueWillChange(); |
| 357 m_cueSize = size; | 361 m_cueSize = floatSize; |
| 358 cueDidChange(); | 362 cueDidChange(); |
| 359 } | 363 } |
| 360 | 364 |
| 361 const String& VTTCue::align() const | 365 const String& VTTCue::align() const |
| 362 { | 366 { |
| 363 switch (m_cueAlignment) { | 367 switch (m_cueAlignment) { |
| 364 case Start: | 368 case Start: |
| 365 return startKeyword(); | 369 return startKeyword(); |
| 366 case Middle: | 370 case Middle: |
| 367 return middleKeyword(); | 371 return middleKeyword(); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 458 cueWillChange(); | 462 cueWillChange(); |
| 459 m_regionId = regionId; | 463 m_regionId = regionId; |
| 460 cueDidChange(); | 464 cueDidChange(); |
| 461 } | 465 } |
| 462 | 466 |
| 463 void VTTCue::notifyRegionWhenRemovingDisplayTree(bool notifyRegion) | 467 void VTTCue::notifyRegionWhenRemovingDisplayTree(bool notifyRegion) |
| 464 { | 468 { |
| 465 m_notifyRegion = notifyRegion; | 469 m_notifyRegion = notifyRegion; |
| 466 } | 470 } |
| 467 | 471 |
| 468 int VTTCue::calculateComputedLinePosition() | 472 float VTTCue::calculateComputedLinePosition() |
| 469 { | 473 { |
| 470 // http://www.whatwg.org/specs/web-apps/current-work/multipage/the-video-ele ment.html#text-track-cue-computed-line-position | 474 // http://www.whatwg.org/specs/web-apps/current-work/multipage/the-video-ele ment.html#text-track-cue-computed-line-position |
| 471 | 475 |
| 472 // If the text track cue line position is numeric, then that is the text | 476 // If the text track cue line position is numeric, then that is the text |
| 473 // track cue computed line position. | 477 // track cue computed line position. |
| 474 if (m_linePosition != undefinedPosition) | 478 if (m_linePosition != undefinedPosition) |
| 475 return m_linePosition; | 479 return m_linePosition; |
| 476 | 480 |
| 477 // If the text track cue snap-to-lines flag of the text track cue is not | 481 // 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; | 482 // 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 | 584 // 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 | 585 // 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 | 586 // 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 | 587 // track cue writing direction is vertical growing right; let block-flow be |
| 584 // 'rl'. | 588 // 'rl'. |
| 585 | 589 |
| 586 // The above step is done through the writing direction static map. | 590 // The above step is done through the writing direction static map. |
| 587 | 591 |
| 588 // 10.5 Determine the value of maximum size for cue as per the appropriate | 592 // 10.5 Determine the value of maximum size for cue as per the appropriate |
| 589 // rules from the following list: | 593 // rules from the following list: |
| 590 int maximumSize = m_textPosition; | 594 float maximumSize = m_textPosition; |
| 591 if ((m_writingDirection == Horizontal && m_cueAlignment == Start && m_displa yDirection == CSSValueLtr) | 595 if ((m_writingDirection == Horizontal && m_cueAlignment == Start && m_displa yDirection == CSSValueLtr) |
| 592 || (m_writingDirection == Horizontal && m_cueAlignment == End && m_displ ayDirection == CSSValueRtl) | 596 || (m_writingDirection == Horizontal && m_cueAlignment == End && m_displ ayDirection == CSSValueRtl) |
| 593 || (m_writingDirection == Horizontal && m_cueAlignment == Left) | 597 || (m_writingDirection == Horizontal && m_cueAlignment == Left) |
| 594 || (m_writingDirection == VerticalGrowingLeft && (m_cueAlignment == Star t || m_cueAlignment == Left)) | 598 || (m_writingDirection == VerticalGrowingLeft && (m_cueAlignment == Star t || m_cueAlignment == Left)) |
| 595 || (m_writingDirection == VerticalGrowingRight && (m_cueAlignment == Sta rt || m_cueAlignment == Left))) { | 599 || (m_writingDirection == VerticalGrowingRight && (m_cueAlignment == Sta rt || m_cueAlignment == Left))) { |
| 596 maximumSize = 100 - m_textPosition; | 600 maximumSize = 100 - m_textPosition; |
| 597 } else if ((m_writingDirection == Horizontal && m_cueAlignment == End && m_d isplayDirection == CSSValueLtr) | 601 } else if ((m_writingDirection == Horizontal && m_cueAlignment == End && m_d isplayDirection == CSSValueLtr) |
| 598 || (m_writingDirection == Horizontal && m_cueAlignment == Start && m_dis playDirection == CSSValueRtl) | 602 || (m_writingDirection == Horizontal && m_cueAlignment == Start && m_dis playDirection == CSSValueRtl) |
| 599 || (m_writingDirection == Horizontal && m_cueAlignment == Right) | 603 || (m_writingDirection == Horizontal && m_cueAlignment == Right) |
| 600 || (m_writingDirection == VerticalGrowingLeft && (m_cueAlignment == End || m_cueAlignment == Right)) | 604 || (m_writingDirection == VerticalGrowingLeft && (m_cueAlignment == End || m_cueAlignment == Right)) |
| 601 || (m_writingDirection == VerticalGrowingRight && (m_cueAlignment == End || m_cueAlignment == Right))) { | 605 || (m_writingDirection == VerticalGrowingRight && (m_cueAlignment == End || m_cueAlignment == Right))) { |
| 602 maximumSize = m_textPosition; | 606 maximumSize = m_textPosition; |
| 603 } else if (m_cueAlignment == Middle) { | 607 } else if (m_cueAlignment == Middle) { |
| 604 maximumSize = m_textPosition <= 50 ? m_textPosition : (100 - m_textPosit ion); | 608 maximumSize = m_textPosition <= 50 ? m_textPosition : (100 - m_textPosit ion); |
| 605 maximumSize = maximumSize * 2; | 609 maximumSize = maximumSize * 2; |
| 606 } else { | 610 } else { |
| 607 ASSERT_NOT_REACHED(); | 611 ASSERT_NOT_REACHED(); |
| 608 } | 612 } |
| 609 | 613 |
| 610 // 10.6 If the text track cue size is less than maximum size, then let size | 614 // 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. | 615 // be text track cue size. Otherwise, let size be maximum size. |
| 612 m_displaySize = std::min(m_cueSize, maximumSize); | 616 m_displaySize = std::min(m_cueSize, maximumSize); |
| 613 | 617 |
| 614 // FIXME: Understand why step 10.7 is missing (just a copy/paste error?) | 618 // 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 | 619 // Could be done within a spec implementation check - http://crbug.com/30158 0 |
| 616 | 620 |
| 617 // 10.8 Determine the value of x-position or y-position for cue as per the | 621 // 10.8 Determine the value of x-position or y-position for cue as per the |
| 618 // appropriate rules from the following list: | 622 // appropriate rules from the following list: |
| 619 if (m_writingDirection == Horizontal) { | 623 if (m_writingDirection == Horizontal) { |
| 620 int visualTextPosition = m_displayDirection == CSSValueLtr ? m_textPosit ion : 100 - m_textPosition; | 624 float visualTextPosition = m_displayDirection == CSSValueLtr ? m_textPos ition : 100 - m_textPosition; |
| 621 | 625 |
| 622 switch (resolveCueAlignment(m_cueAlignment, m_displayDirection)) { | 626 switch (resolveCueAlignment(m_cueAlignment, m_displayDirection)) { |
| 623 case Left: | 627 case Left: |
| 624 m_displayPosition.setX(visualTextPosition); | 628 m_displayPosition.setX(visualTextPosition); |
| 625 break; | 629 break; |
| 626 case Right: | 630 case Right: |
| 627 m_displayPosition.setX(visualTextPosition - m_displaySize); | 631 m_displayPosition.setX(visualTextPosition - m_displaySize); |
| 628 break; | 632 break; |
| 629 case Middle: | 633 case Middle: |
| 630 m_displayPosition.setX(visualTextPosition - m_displaySize / 2); | 634 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 | 1049 CSSValueID VTTCue::getCSSWritingDirection() const |
| 1046 { | 1050 { |
| 1047 return m_displayDirection; | 1051 return m_displayDirection; |
| 1048 } | 1052 } |
| 1049 | 1053 |
| 1050 CSSValueID VTTCue::getCSSWritingMode() const | 1054 CSSValueID VTTCue::getCSSWritingMode() const |
| 1051 { | 1055 { |
| 1052 return displayWritingModeMap[m_writingDirection]; | 1056 return displayWritingModeMap[m_writingDirection]; |
| 1053 } | 1057 } |
| 1054 | 1058 |
| 1055 int VTTCue::getCSSSize() const | 1059 float VTTCue::getCSSSize() const |
| 1056 { | 1060 { |
| 1057 ASSERT(m_displaySize != undefinedSize); | 1061 ASSERT(m_displaySize != undefinedSize); |
| 1058 return m_displaySize; | 1062 return m_displaySize; |
| 1059 } | 1063 } |
| 1060 | 1064 |
| 1061 FloatPoint VTTCue::getCSSPosition() const | 1065 FloatPoint VTTCue::getCSSPosition() const |
| 1062 { | 1066 { |
| 1063 if (!m_snapToLines) | 1067 if (!m_snapToLines) |
| 1064 return getPositionCoordinates(); | 1068 return getPositionCoordinates(); |
| 1065 | 1069 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 1080 | 1084 |
| 1081 void VTTCue::trace(Visitor* visitor) | 1085 void VTTCue::trace(Visitor* visitor) |
| 1082 { | 1086 { |
| 1083 visitor->trace(m_vttNodeTree); | 1087 visitor->trace(m_vttNodeTree); |
| 1084 visitor->trace(m_cueBackgroundBox); | 1088 visitor->trace(m_cueBackgroundBox); |
| 1085 visitor->trace(m_displayTree); | 1089 visitor->trace(m_displayTree); |
| 1086 TextTrackCue::trace(visitor); | 1090 TextTrackCue::trace(visitor); |
| 1087 } | 1091 } |
| 1088 | 1092 |
| 1089 } // namespace blink | 1093 } // namespace blink |
| OLD | NEW |