Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008, 2009, 2010, 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2008, 2009, 2010, 2011 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2012 Google Inc. All rights reserved. | 3 * Copyright (C) 2012 Google Inc. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * | 8 * |
| 9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 */ | 28 */ |
| 29 | 29 |
| 30 #include "core/html/shadow/MediaControlElements.h" | 30 #include "core/html/shadow/MediaControlElements.h" |
| 31 | 31 |
| 32 #include "bindings/core/v8/ExceptionStatePlaceholder.h" | 32 #include "bindings/core/v8/ExceptionStatePlaceholder.h" |
| 33 #include "core/InputTypeNames.h" | 33 #include "core/InputTypeNames.h" |
| 34 #include "core/dom/ClientRect.h" | 34 #include "core/dom/ClientRect.h" |
| 35 #include "core/dom/Document.h" | |
| 36 #include "core/dom/Text.h" | |
| 35 #include "core/dom/shadow/ShadowRoot.h" | 37 #include "core/dom/shadow/ShadowRoot.h" |
| 36 #include "core/events/MouseEvent.h" | 38 #include "core/events/MouseEvent.h" |
| 37 #include "core/frame/LocalFrame.h" | 39 #include "core/frame/LocalFrame.h" |
| 40 #include "core/html/HTMLLabelElement.h" | |
| 41 #include "core/html/HTMLSpanElement.h" | |
| 38 #include "core/html/HTMLVideoElement.h" | 42 #include "core/html/HTMLVideoElement.h" |
| 39 #include "core/html/TimeRanges.h" | 43 #include "core/html/TimeRanges.h" |
| 40 #include "core/html/shadow/MediaControls.h" | 44 #include "core/html/shadow/MediaControls.h" |
| 45 #include "core/html/track/TextTrackList.h" | |
| 41 #include "core/input/EventHandler.h" | 46 #include "core/input/EventHandler.h" |
| 42 #include "core/layout/LayoutSlider.h" | 47 #include "core/layout/LayoutSlider.h" |
| 43 #include "core/layout/LayoutTheme.h" | 48 #include "core/layout/LayoutTheme.h" |
| 44 #include "core/layout/LayoutVideo.h" | 49 #include "core/layout/LayoutVideo.h" |
| 50 #include "platform/EventDispatchForbiddenScope.h" | |
| 45 #include "platform/Histogram.h" | 51 #include "platform/Histogram.h" |
| 46 #include "platform/RuntimeEnabledFeatures.h" | 52 #include "platform/RuntimeEnabledFeatures.h" |
| 53 #include "platform/text/PlatformLocale.h" | |
| 54 #include "public/platform/Platform.h" | |
| 47 | 55 |
| 48 namespace blink { | 56 namespace blink { |
| 49 | 57 |
| 50 using namespace HTMLNames; | 58 using namespace HTMLNames; |
| 51 | 59 |
| 52 namespace { | 60 namespace { |
| 53 | 61 |
| 54 // This is the duration from mediaControls.css | 62 // This is the duration from mediaControls.css |
| 55 const double fadeOutDuration = 0.3; | 63 const double fadeOutDuration = 0.3; |
| 56 | 64 |
| 65 static const QualifiedName& trackIndexAttrName() | |
| 66 { | |
| 67 // Save the track index in an attribute to avoid holding a pointer to the te xt track element. | |
| 68 DEFINE_STATIC_LOCAL(QualifiedName, trackIndexAttr, (nullAtom, "data-track-in dex", nullAtom)); | |
| 69 return trackIndexAttr; | |
| 70 } | |
| 71 | |
| 72 // When specified as trackIndex, disable text tracks. | |
| 73 static const int trackIndexOffValue = -1; | |
| 74 | |
| 57 bool isUserInteractionEvent(Event* event) | 75 bool isUserInteractionEvent(Event* event) |
| 58 { | 76 { |
| 59 const AtomicString& type = event->type(); | 77 const AtomicString& type = event->type(); |
| 60 return type == EventTypeNames::mousedown | 78 return type == EventTypeNames::mousedown |
| 61 || type == EventTypeNames::mouseup | 79 || type == EventTypeNames::mouseup |
| 62 || type == EventTypeNames::click | 80 || type == EventTypeNames::click |
| 63 || type == EventTypeNames::dblclick | 81 || type == EventTypeNames::dblclick |
| 64 || event->isKeyboardEvent() | 82 || event->isKeyboardEvent() |
| 65 || event->isTouchEvent(); | 83 || event->isTouchEvent(); |
| 66 } | 84 } |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 346 button->setType(InputTypeNames::button); | 364 button->setType(InputTypeNames::button); |
| 347 button->setShadowPseudoId(AtomicString("-webkit-media-controls-toggle-closed -captions-button", AtomicString::ConstructFromLiteral)); | 365 button->setShadowPseudoId(AtomicString("-webkit-media-controls-toggle-closed -captions-button", AtomicString::ConstructFromLiteral)); |
| 348 button->setIsWanted(false); | 366 button->setIsWanted(false); |
| 349 return button.release(); | 367 return button.release(); |
| 350 } | 368 } |
| 351 | 369 |
| 352 void MediaControlToggleClosedCaptionsButtonElement::updateDisplayType() | 370 void MediaControlToggleClosedCaptionsButtonElement::updateDisplayType() |
| 353 { | 371 { |
| 354 bool captionsVisible = mediaElement().closedCaptionsVisible(); | 372 bool captionsVisible = mediaElement().closedCaptionsVisible(); |
| 355 setDisplayType(captionsVisible ? MediaHideClosedCaptionsButton : MediaShowCl osedCaptionsButton); | 373 setDisplayType(captionsVisible ? MediaHideClosedCaptionsButton : MediaShowCl osedCaptionsButton); |
| 356 setChecked(captionsVisible); | |
| 357 } | 374 } |
| 358 | 375 |
| 359 void MediaControlToggleClosedCaptionsButtonElement::defaultEventHandler(Event* e vent) | 376 void MediaControlToggleClosedCaptionsButtonElement::defaultEventHandler(Event* e vent) |
| 360 { | 377 { |
| 361 if (event->type() == EventTypeNames::click) { | 378 if (event->type() == EventTypeNames::click) { |
| 362 mediaElement().setClosedCaptionsVisible(!mediaElement().closedCaptionsVi sible()); | 379 mediaControls().toggleTextTrackList(); |
| 363 setChecked(mediaElement().closedCaptionsVisible()); | |
| 364 updateDisplayType(); | 380 updateDisplayType(); |
| 365 event->setDefaultHandled(); | 381 event->setDefaultHandled(); |
| 366 } | 382 } |
| 367 | 383 |
| 368 HTMLInputElement::defaultEventHandler(event); | 384 HTMLInputElement::defaultEventHandler(event); |
| 369 } | 385 } |
| 370 | 386 |
| 371 // ---------------------------- | 387 // ---------------------------- |
| 372 | 388 |
| 389 MediaControlTextTrackListElement::MediaControlTextTrackListElement(MediaControls & mediaControls) | |
| 390 : MediaControlDivElement(mediaControls, MediaTextTrackList) | |
| 391 { | |
| 392 } | |
| 393 | |
| 394 PassRefPtrWillBeRawPtr<MediaControlTextTrackListElement> MediaControlTextTrackLi stElement::create(MediaControls& mediaControls) | |
| 395 { | |
| 396 RefPtrWillBeRawPtr<MediaControlTextTrackListElement> element = | |
| 397 adoptRefWillBeNoop(new MediaControlTextTrackListElement(mediaControls)); | |
| 398 element->setShadowPseudoId(AtomicString("-internal-media-controls-text-track -list", | |
| 399 AtomicString::ConstructFromLiteral)); | |
| 400 element->setIsWanted(false); | |
| 401 return element.release(); | |
| 402 } | |
| 403 | |
| 404 void MediaControlTextTrackListElement::defaultEventHandler(Event* event) | |
| 405 { | |
| 406 if (event->type() == EventTypeNames::change) { | |
| 407 // Identify which input element was selected and set track to showing | |
| 408 Node* target = event->target()->toNode(); | |
| 409 if (!target || !target->isElementNode()) | |
| 410 return; | |
| 411 | |
| 412 int trackIndex = toElement(target)->getIntegralAttribute(trackIndexAttrN ame()); | |
| 413 disableShowingTextTracks(); | |
| 414 if (trackIndex != trackIndexOffValue) { | |
| 415 showTextTrackAtIndex(trackIndex); | |
| 416 mediaElement().disableAutomaticTextTrackSelection(); | |
| 417 } | |
| 418 | |
| 419 mediaControls().toggleTextTrackList(); | |
| 420 event->setDefaultHandled(); | |
| 421 } | |
| 422 MediaControlDivElement::defaultEventHandler(event); | |
| 423 } | |
| 424 | |
| 425 void MediaControlTextTrackListElement::displayTextTrackList(bool display) | |
| 426 { | |
| 427 setIsWanted(display); | |
| 428 } | |
| 429 | |
| 430 void MediaControlTextTrackListElement::showTextTrackAtIndex(unsigned indexToEnab le) | |
| 431 { | |
| 432 TextTrackList* trackList = mediaElement().textTracks(); | |
| 433 if (trackList->length() == 0) | |
| 434 return; | |
| 435 if (indexToEnable >= trackList->length()) | |
| 436 return; | |
| 437 TextTrack* track = trackList->anonymousIndexedGetter(indexToEnable); | |
| 438 if (track->canBeRendered()) | |
| 439 track->setMode(TextTrack::showingKeyword()); | |
| 440 } | |
| 441 | |
| 442 void MediaControlTextTrackListElement::disableShowingTextTracks() | |
| 443 { | |
| 444 TextTrackList* trackList = mediaElement().textTracks(); | |
| 445 for (unsigned i = 0; i < trackList->length(); ++i) { | |
| 446 TextTrack* track = trackList->anonymousIndexedGetter(i); | |
| 447 if (track->mode() == TextTrack::showingKeyword()) | |
| 448 track->setMode(TextTrack::disabledKeyword()); | |
| 449 } | |
| 450 } | |
| 451 | |
| 452 String MediaControlTextTrackListElement::getTextTrackLabel(TextTrack* track) | |
| 453 { | |
| 454 if (!track) | |
| 455 return mediaElement().locale().queryString(WebLocalizedString::TextTrack sOff); | |
| 456 | |
| 457 String trackLabel = track->label(); | |
| 458 | |
| 459 if (trackLabel.isEmpty()) | |
| 460 trackLabel = track->language(); | |
| 461 | |
| 462 if (trackLabel.isEmpty()) | |
| 463 trackLabel = String(mediaElement().locale().queryString(WebLocalizedStri ng::TextTracksNoLabel)); | |
| 464 | |
| 465 return trackLabel; | |
| 466 } | |
| 467 | |
| 468 // TextTrack parameter when passed in as a nullptr, creates the "Off" list item in the track list. | |
| 469 PassRefPtrWillBeRawPtr<Element> MediaControlTextTrackListElement::createTextTrac kListItem(TextTrack* track) | |
| 470 { | |
| 471 Document& document = this->document(); | |
| 472 int trackIndex = track ? track->trackIndex() : trackIndexOffValue; | |
| 473 RefPtrWillBeRawPtr<HTMLLabelElement> trackItem = HTMLLabelElement::create(do cument, 0); | |
| 474 trackItem->setShadowPseudoId(AtomicString("-internal-media-controls-text-tra ck-list-item", | |
| 475 AtomicString::ConstructFromLiteral)); | |
| 476 RefPtrWillBeRawPtr<HTMLInputElement> trackItemInput = HTMLInputElement::crea te(document, 0, false); | |
| 477 trackItemInput->setShadowPseudoId(AtomicString("-internal-media-controls-tex t-track-list-item-input", | |
| 478 AtomicString::ConstructFromLiteral)); | |
| 479 trackItemInput->setType(InputTypeNames::radio); | |
| 480 trackItemInput->setIntegralAttribute(trackIndexAttrName(), trackIndex); | |
| 481 if (!mediaElement().closedCaptionsVisible()) { | |
| 482 if (!track) | |
| 483 trackItemInput->setChecked(true); | |
| 484 } else { | |
| 485 // If there are multiple text tracks set to showing, they must all have | |
| 486 // checkmarks displayed. | |
| 487 if (track && track->mode() == TextTrack::showingKeyword()) | |
| 488 trackItemInput->setChecked(true); | |
| 489 } | |
| 490 RefPtrWillBeRawPtr<HTMLSpanElement> trackKindMarker = HTMLSpanElement::creat e(document); | |
| 491 if (track && track->kind() == track->captionsKeyword()) { | |
| 492 trackKindMarker->setShadowPseudoId(AtomicString("-internal-media-control s-text-track-list-kind-captions", | |
| 493 AtomicString::ConstructFromLiteral)); | |
| 494 } else if (track && track->kind() == track->subtitlesKeyword()) { | |
| 495 trackKindMarker->setShadowPseudoId(AtomicString("-internal-media-control s-text-track-list-kind-subtitles", | |
| 496 AtomicString::ConstructFromLiteral)); | |
| 497 } | |
| 498 trackItem->appendChild(trackItemInput); | |
| 499 trackItem->appendChild(Text::create(document, getTextTrackLabel(track))); | |
| 500 trackItem->appendChild(trackKindMarker); | |
| 501 return trackItem; | |
| 502 } | |
| 503 | |
| 504 void MediaControlTextTrackListElement::refreshTextTrackListMenu() | |
| 505 { | |
| 506 if (!mediaElement().hasClosedCaptions() || !mediaElement().textTracksAreRead y()) | |
| 507 return; | |
| 508 | |
| 509 removeChildren(OmitSubtreeModifiedEvent); | |
| 510 | |
| 511 // Construct a menu for subtitles and captions | |
| 512 EventDispatchForbiddenScope::AllowUserAgentEvents allowEvents; | |
|
fs
2016/02/24 10:14:57
What events are you seeing here? It'd really be pr
srivats
2016/02/25 21:47:56
Can't remember why this was needed in the first pl
fs
2016/02/25 22:06:48
Ok, I'd suggest adding a "EventDispatchForbiddenSc
srivats
2016/02/25 22:28:36
Adding that causes an assertion failure in Node::d
fs
2016/02/26 09:09:12
No, it will do nothing more than assert. It genera
| |
| 513 RefPtrWillBeRawPtr<HTMLDivElement> tracksSection = HTMLDivElement::create(th is->document()); | |
| 514 tracksSection->setAttribute(roleAttr, radiogroupAttr.localName()); | |
| 515 // Pass in a nullptr to createTextTrackListItem to create the "Off" track it em. | |
| 516 tracksSection->appendChild(createTextTrackListItem(nullptr)); | |
| 517 | |
| 518 TextTrackList* trackList = mediaElement().textTracks(); | |
| 519 for (unsigned i = 0; i < trackList->length(); i++) { | |
| 520 TextTrack* track = trackList->anonymousIndexedGetter(i); | |
| 521 if (!track->canBeRendered()) | |
| 522 continue; | |
| 523 tracksSection->appendChild(createTextTrackListItem(track)); | |
| 524 } | |
| 525 appendChild(tracksSection); | |
| 526 } | |
| 527 | |
| 528 // ---------------------------- | |
| 529 | |
| 373 MediaControlTimelineElement::MediaControlTimelineElement(MediaControls& mediaCon trols) | 530 MediaControlTimelineElement::MediaControlTimelineElement(MediaControls& mediaCon trols) |
| 374 : MediaControlInputElement(mediaControls, MediaSlider) | 531 : MediaControlInputElement(mediaControls, MediaSlider) |
| 375 { | 532 { |
| 376 } | 533 } |
| 377 | 534 |
| 378 PassRefPtrWillBeRawPtr<MediaControlTimelineElement> MediaControlTimelineElement: :create(MediaControls& mediaControls) | 535 PassRefPtrWillBeRawPtr<MediaControlTimelineElement> MediaControlTimelineElement: :create(MediaControls& mediaControls) |
| 379 { | 536 { |
| 380 RefPtrWillBeRawPtr<MediaControlTimelineElement> timeline = adoptRefWillBeNoo p(new MediaControlTimelineElement(mediaControls)); | 537 RefPtrWillBeRawPtr<MediaControlTimelineElement> timeline = adoptRefWillBeNoo p(new MediaControlTimelineElement(mediaControls)); |
| 381 timeline->ensureUserAgentShadowRoot(); | 538 timeline->ensureUserAgentShadowRoot(); |
| 382 timeline->setType(InputTypeNames::range); | 539 timeline->setType(InputTypeNames::range); |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 649 } | 806 } |
| 650 | 807 |
| 651 PassRefPtrWillBeRawPtr<MediaControlCurrentTimeDisplayElement> MediaControlCurren tTimeDisplayElement::create(MediaControls& mediaControls) | 808 PassRefPtrWillBeRawPtr<MediaControlCurrentTimeDisplayElement> MediaControlCurren tTimeDisplayElement::create(MediaControls& mediaControls) |
| 652 { | 809 { |
| 653 RefPtrWillBeRawPtr<MediaControlCurrentTimeDisplayElement> element = adoptRef WillBeNoop(new MediaControlCurrentTimeDisplayElement(mediaControls)); | 810 RefPtrWillBeRawPtr<MediaControlCurrentTimeDisplayElement> element = adoptRef WillBeNoop(new MediaControlCurrentTimeDisplayElement(mediaControls)); |
| 654 element->setShadowPseudoId(AtomicString("-webkit-media-controls-current-time -display", AtomicString::ConstructFromLiteral)); | 811 element->setShadowPseudoId(AtomicString("-webkit-media-controls-current-time -display", AtomicString::ConstructFromLiteral)); |
| 655 return element.release(); | 812 return element.release(); |
| 656 } | 813 } |
| 657 | 814 |
| 658 } // namespace blink | 815 } // namespace blink |
| OLD | NEW |