Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(98)

Side by Side Diff: third_party/WebKit/Source/core/html/shadow/MediaControlElements.cpp

Issue 2709393004: Media Controls: Fix time updates when dragging from track not scrubber (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/html/shadow/SliderThumbElement.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 27 matching lines...) Expand all
38 #include "core/events/MouseEvent.h" 38 #include "core/events/MouseEvent.h"
39 #include "core/frame/LocalFrame.h" 39 #include "core/frame/LocalFrame.h"
40 #include "core/frame/Settings.h" 40 #include "core/frame/Settings.h"
41 #include "core/html/HTMLAnchorElement.h" 41 #include "core/html/HTMLAnchorElement.h"
42 #include "core/html/HTMLLabelElement.h" 42 #include "core/html/HTMLLabelElement.h"
43 #include "core/html/HTMLMediaSource.h" 43 #include "core/html/HTMLMediaSource.h"
44 #include "core/html/HTMLSpanElement.h" 44 #include "core/html/HTMLSpanElement.h"
45 #include "core/html/HTMLVideoElement.h" 45 #include "core/html/HTMLVideoElement.h"
46 #include "core/html/TimeRanges.h" 46 #include "core/html/TimeRanges.h"
47 #include "core/html/shadow/MediaControls.h" 47 #include "core/html/shadow/MediaControls.h"
48 #include "core/html/shadow/ShadowElementNames.h"
49 #include "core/html/shadow/SliderThumbElement.h"
48 #include "core/html/track/TextTrackList.h" 50 #include "core/html/track/TextTrackList.h"
49 #include "core/input/EventHandler.h" 51 #include "core/input/EventHandler.h"
50 #include "core/layout/api/LayoutSliderItem.h" 52 #include "core/layout/LayoutObject.h"
51 #include "core/page/Page.h" 53 #include "core/page/Page.h"
52 #include "platform/EventDispatchForbiddenScope.h" 54 #include "platform/EventDispatchForbiddenScope.h"
53 #include "platform/Histogram.h" 55 #include "platform/Histogram.h"
54 #include "platform/RuntimeEnabledFeatures.h" 56 #include "platform/RuntimeEnabledFeatures.h"
55 #include "platform/text/PlatformLocale.h" 57 #include "platform/text/PlatformLocale.h"
56 #include "public/platform/Platform.h" 58 #include "public/platform/Platform.h"
57 #include "public/platform/UserMetricsAction.h" 59 #include "public/platform/UserMetricsAction.h"
58 60
59 namespace blink { 61 namespace blink {
60 62
61 using namespace HTMLNames; 63 using namespace HTMLNames;
62 64
63 namespace { 65 namespace {
64 66
65 // This is the duration from mediaControls.css 67 // This is the duration from mediaControls.css
66 const double fadeOutDuration = 0.3; 68 const double fadeOutDuration = 0.3;
67 69
68 const QualifiedName& trackIndexAttrName() { 70 const QualifiedName& trackIndexAttrName() {
69 // Save the track index in an attribute to avoid holding a pointer to the text 71 // Save the track index in an attribute to avoid holding a pointer to the text
70 // track. 72 // track.
71 DEFINE_STATIC_LOCAL(QualifiedName, trackIndexAttr, 73 DEFINE_STATIC_LOCAL(QualifiedName, trackIndexAttr,
72 (nullAtom, "data-track-index", nullAtom)); 74 (nullAtom, "data-track-index", nullAtom));
73 return trackIndexAttr; 75 return trackIndexAttr;
74 } 76 }
75 77
76 // When specified as trackIndex, disable text tracks. 78 // When specified as trackIndex, disable text tracks.
77 const int trackIndexOffValue = -1; 79 const int trackIndexOffValue = -1;
78 80
81 bool inDragMode(MediaControlInputElement* rangeInput) {
82 SliderThumbElement* thumb =
83 toSliderThumbElement(rangeInput->userAgentShadowRoot()->getElementById(
84 ShadowElementNames::sliderThumb()));
85 return thumb && thumb->inDragMode();
86 }
87
79 bool isUserInteractionEvent(Event* event) { 88 bool isUserInteractionEvent(Event* event) {
80 const AtomicString& type = event->type(); 89 const AtomicString& type = event->type();
81 return type == EventTypeNames::mousedown || type == EventTypeNames::mouseup || 90 return type == EventTypeNames::mousedown || type == EventTypeNames::mouseup ||
82 type == EventTypeNames::click || type == EventTypeNames::dblclick || 91 type == EventTypeNames::click || type == EventTypeNames::dblclick ||
83 event->isKeyboardEvent() || event->isTouchEvent(); 92 event->isKeyboardEvent() || event->isTouchEvent();
84 } 93 }
85 94
86 // Sliders (the volume control and timeline) need to capture some additional 95 // Sliders (the volume control and timeline) need to capture some additional
87 // events used when dragging the thumb. 96 // events used when dragging the thumb.
88 bool isUserInteractionEventForSlider(Event* event, LayoutObject* layoutObject) { 97 bool isUserInteractionEventForSlider(Event* event,
98 MediaControlInputElement* rangeInput) {
89 // It is unclear if this can be converted to isUserInteractionEvent(), since 99 // It is unclear if this can be converted to isUserInteractionEvent(), since
90 // mouse* events seem to be eaten during a drag anyway. crbug.com/516416 . 100 // mouse* events seem to be eaten during a drag anyway. crbug.com/516416 .
91 if (isUserInteractionEvent(event)) 101 if (isUserInteractionEvent(event))
92 return true; 102 return true;
93 103
94 // Some events are only captured during a slider drag. 104 // Some events are only captured during a slider drag.
95 LayoutSliderItem slider = LayoutSliderItem(toLayoutSlider(layoutObject)); 105 if (!inDragMode(rangeInput))
96 if (!slider.isNull() && !slider.inDragMode())
97 return false; 106 return false;
98 107
99 const AtomicString& type = event->type(); 108 const AtomicString& type = event->type();
100 return type == EventTypeNames::mouseover || 109 return type == EventTypeNames::mouseover ||
101 type == EventTypeNames::mouseout || 110 type == EventTypeNames::mouseout ||
102 type == EventTypeNames::mousemove || 111 type == EventTypeNames::mousemove ||
103 type == EventTypeNames::pointerover || 112 type == EventTypeNames::pointerover ||
104 type == EventTypeNames::pointerout || 113 type == EventTypeNames::pointerout ||
105 type == EventTypeNames::pointermove; 114 type == EventTypeNames::pointermove;
106 } 115 }
(...skipping 669 matching lines...) Expand 10 before | Expand all | Expand 10 after
776 // attribute to be rounded to a value slightly higher than the duration. If 785 // attribute to be rounded to a value slightly higher than the duration. If
777 // this happens and scrubber is dragged near the max, seek to duration. 786 // this happens and scrubber is dragged near the max, seek to duration.
778 if (duration < time && time <= maxAttribute && maxAttribute <= duration + 0.5) 787 if (duration < time && time <= maxAttribute && maxAttribute <= duration + 0.5)
779 time = duration; 788 time = duration;
780 789
781 // FIXME: This will need to take the timeline offset into consideration 790 // FIXME: This will need to take the timeline offset into consideration
782 // once that concept is supported, see https://crbug.com/312699 791 // once that concept is supported, see https://crbug.com/312699
783 if (mediaElement().seekable()->contain(time)) 792 if (mediaElement().seekable()->contain(time))
784 mediaElement().setCurrentTime(time); 793 mediaElement().setCurrentTime(time);
785 794
786 LayoutSliderItem slider = LayoutSliderItem(toLayoutSlider(layoutObject())); 795 if (inDragMode(this))
787 if (!slider.isNull() && slider.inDragMode())
788 mediaControls().updateCurrentTimeDisplay(); 796 mediaControls().updateCurrentTimeDisplay();
789 } 797 }
790 798
791 bool MediaControlTimelineElement::willRespondToMouseClickEvents() { 799 bool MediaControlTimelineElement::willRespondToMouseClickEvents() {
792 return isConnected() && document().isActive(); 800 return isConnected() && document().isActive();
793 } 801 }
794 802
795 void MediaControlTimelineElement::setPosition(double currentTime) { 803 void MediaControlTimelineElement::setPosition(double currentTime) {
796 setValue(String::number(currentTime)); 804 setValue(String::number(currentTime));
797 805
798 if (LayoutObject* layoutObject = this->layoutObject()) 806 if (LayoutObject* layoutObject = this->layoutObject())
799 layoutObject->setShouldDoFullPaintInvalidation(); 807 layoutObject->setShouldDoFullPaintInvalidation();
800 } 808 }
801 809
802 void MediaControlTimelineElement::setDuration(double duration) { 810 void MediaControlTimelineElement::setDuration(double duration) {
803 setFloatingPointAttribute(maxAttr, std::isfinite(duration) ? duration : 0); 811 setFloatingPointAttribute(maxAttr, std::isfinite(duration) ? duration : 0);
804 812
805 if (LayoutObject* layoutObject = this->layoutObject()) 813 if (LayoutObject* layoutObject = this->layoutObject())
806 layoutObject->setShouldDoFullPaintInvalidation(); 814 layoutObject->setShouldDoFullPaintInvalidation();
807 } 815 }
808 816
809 bool MediaControlTimelineElement::keepEventInNode(Event* event) { 817 bool MediaControlTimelineElement::keepEventInNode(Event* event) {
810 return isUserInteractionEventForSlider(event, layoutObject()); 818 return isUserInteractionEventForSlider(event, this);
811 } 819 }
812 820
813 // ---------------------------- 821 // ----------------------------
814 822
815 MediaControlVolumeSliderElement::MediaControlVolumeSliderElement( 823 MediaControlVolumeSliderElement::MediaControlVolumeSliderElement(
816 MediaControls& mediaControls) 824 MediaControls& mediaControls)
817 : MediaControlInputElement(mediaControls, MediaVolumeSlider) {} 825 : MediaControlInputElement(mediaControls, MediaVolumeSlider) {}
818 826
819 MediaControlVolumeSliderElement* MediaControlVolumeSliderElement::create( 827 MediaControlVolumeSliderElement* MediaControlVolumeSliderElement::create(
820 MediaControls& mediaControls) { 828 MediaControls& mediaControls) {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
867 void MediaControlVolumeSliderElement::setVolume(double volume) { 875 void MediaControlVolumeSliderElement::setVolume(double volume) {
868 if (value().toDouble() == volume) 876 if (value().toDouble() == volume)
869 return; 877 return;
870 878
871 setValue(String::number(volume)); 879 setValue(String::number(volume));
872 if (LayoutObject* layoutObject = this->layoutObject()) 880 if (LayoutObject* layoutObject = this->layoutObject())
873 layoutObject->setShouldDoFullPaintInvalidation(); 881 layoutObject->setShouldDoFullPaintInvalidation();
874 } 882 }
875 883
876 bool MediaControlVolumeSliderElement::keepEventInNode(Event* event) { 884 bool MediaControlVolumeSliderElement::keepEventInNode(Event* event) {
877 return isUserInteractionEventForSlider(event, layoutObject()); 885 return isUserInteractionEventForSlider(event, this);
878 } 886 }
879 887
880 // ---------------------------- 888 // ----------------------------
881 889
882 MediaControlFullscreenButtonElement::MediaControlFullscreenButtonElement( 890 MediaControlFullscreenButtonElement::MediaControlFullscreenButtonElement(
883 MediaControls& mediaControls) 891 MediaControls& mediaControls)
884 : MediaControlInputElement(mediaControls, MediaEnterFullscreenButton) {} 892 : MediaControlInputElement(mediaControls, MediaEnterFullscreenButton) {}
885 893
886 MediaControlFullscreenButtonElement* 894 MediaControlFullscreenButtonElement*
887 MediaControlFullscreenButtonElement::create(MediaControls& mediaControls) { 895 MediaControlFullscreenButtonElement::create(MediaControls& mediaControls) {
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
1054 MediaControlCurrentTimeDisplayElement* 1062 MediaControlCurrentTimeDisplayElement*
1055 MediaControlCurrentTimeDisplayElement::create(MediaControls& mediaControls) { 1063 MediaControlCurrentTimeDisplayElement::create(MediaControls& mediaControls) {
1056 MediaControlCurrentTimeDisplayElement* element = 1064 MediaControlCurrentTimeDisplayElement* element =
1057 new MediaControlCurrentTimeDisplayElement(mediaControls); 1065 new MediaControlCurrentTimeDisplayElement(mediaControls);
1058 element->setShadowPseudoId( 1066 element->setShadowPseudoId(
1059 AtomicString("-webkit-media-controls-current-time-display")); 1067 AtomicString("-webkit-media-controls-current-time-display"));
1060 return element; 1068 return element;
1061 } 1069 }
1062 1070
1063 } // namespace blink 1071 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/html/shadow/SliderThumbElement.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698