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

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

Issue 2820343002: Media Controls: move timeline related code to modules. (Closed)
Patch Set: Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/html/shadow/MediaControlElements.cpp
diff --git a/third_party/WebKit/Source/core/html/shadow/MediaControlElements.cpp b/third_party/WebKit/Source/core/html/shadow/MediaControlElements.cpp
index d5e8d49e9dfebb186b5b4c89706047fb28e1b6f7..32fe370c58a63a71397cdeee1b712b421d6acabe 100644
--- a/third_party/WebKit/Source/core/html/shadow/MediaControlElements.cpp
+++ b/third_party/WebKit/Source/core/html/shadow/MediaControlElements.cpp
@@ -36,23 +36,19 @@
#include "core/dom/Text.h"
#include "core/dom/shadow/ShadowRoot.h"
#include "core/events/KeyboardEvent.h"
-#include "core/events/MouseEvent.h"
#include "core/frame/LocalFrame.h"
#include "core/frame/UseCounter.h"
#include "core/html/HTMLVideoElement.h"
-#include "core/html/TimeRanges.h"
#include "core/html/media/MediaControls.h"
#include "core/html/shadow/ShadowElementNames.h"
#include "core/html/track/TextTrackList.h"
#include "core/input/EventHandler.h"
#include "core/layout/LayoutBoxModelObject.h"
#include "core/layout/api/LayoutSliderItem.h"
-#include "core/page/ChromeClient.h"
#include "platform/Histogram.h"
#include "platform/RuntimeEnabledFeatures.h"
#include "public/platform/Platform.h"
#include "public/platform/UserMetricsAction.h"
-#include "public/platform/WebScreenInfo.h"
namespace blink {
@@ -96,131 +92,6 @@ bool IsUserInteractionEventForSlider(Event* event,
} // anonymous namespace
-// ----------------------------
-
-MediaControlTimelineElement::MediaControlTimelineElement(
- MediaControls& media_controls)
- : MediaControlInputElement(media_controls, kMediaSlider) {}
-
-MediaControlTimelineElement* MediaControlTimelineElement::Create(
- MediaControls& media_controls) {
- MediaControlTimelineElement* timeline =
- new MediaControlTimelineElement(media_controls);
- timeline->EnsureUserAgentShadowRoot();
- timeline->setType(InputTypeNames::range);
- timeline->setAttribute(stepAttr, "any");
- timeline->SetShadowPseudoId(AtomicString("-webkit-media-controls-timeline"));
- return timeline;
-}
-
-void MediaControlTimelineElement::DefaultEventHandler(Event* event) {
- if (event->IsMouseEvent() &&
- ToMouseEvent(event)->button() !=
- static_cast<short>(WebPointerProperties::Button::kLeft))
- return;
-
- if (!isConnected() || !GetDocument().IsActive())
- return;
-
- // TODO(crbug.com/706504): These should listen for pointerdown/up.
- if (event->type() == EventTypeNames::mousedown)
- GetMediaControls().BeginScrubbing();
- if (event->type() == EventTypeNames::mouseup)
- GetMediaControls().EndScrubbing();
-
- // Only respond to main button of primary pointer(s).
- if (event->IsPointerEvent() && ToPointerEvent(event)->isPrimary() &&
- ToPointerEvent(event)->button() ==
- static_cast<short>(WebPointerProperties::Button::kLeft)) {
- if (event->type() == EventTypeNames::pointerdown) {
- Platform::Current()->RecordAction(
- UserMetricsAction("Media.Controls.ScrubbingBegin"));
- GetMediaControls().BeginScrubbing();
- Element* thumb = UserAgentShadowRoot()->GetElementById(
- ShadowElementNames::SliderThumb());
- bool started_from_thumb = thumb && thumb == event->target()->ToNode();
- metrics_.StartGesture(started_from_thumb);
- }
- if (event->type() == EventTypeNames::pointerup) {
- Platform::Current()->RecordAction(
- UserMetricsAction("Media.Controls.ScrubbingEnd"));
- GetMediaControls().EndScrubbing();
- metrics_.RecordEndGesture(TimelineWidth(), MediaElement().duration());
- }
- }
-
- if (event->type() == EventTypeNames::keydown) {
- metrics_.StartKey();
- }
- if (event->type() == EventTypeNames::keyup && event->IsKeyboardEvent()) {
- metrics_.RecordEndKey(TimelineWidth(), ToKeyboardEvent(event)->keyCode());
- }
-
- MediaControlInputElement::DefaultEventHandler(event);
-
- if (event->type() != EventTypeNames::input)
- return;
-
- double time = value().ToDouble();
-
- double duration = MediaElement().duration();
- // Workaround for floating point error - it's possible for this element's max
- // attribute to be rounded to a value slightly higher than the duration. If
- // this happens and scrubber is dragged near the max, seek to duration.
- if (time > duration)
- time = duration;
-
- metrics_.OnInput(MediaElement().currentTime(), time);
-
- // FIXME: This will need to take the timeline offset into consideration
- // once that concept is supported, see https://crbug.com/312699
- if (MediaElement().seekable()->Contain(time))
- MediaElement().setCurrentTime(time);
-
- // Provide immediate feedback (without waiting for media to seek) to make it
- // easier for user to seek to a precise time.
- GetMediaControls().UpdateCurrentTimeDisplay();
-}
-
-bool MediaControlTimelineElement::WillRespondToMouseClickEvents() {
- return isConnected() && GetDocument().IsActive();
-}
-
-void MediaControlTimelineElement::SetPosition(double current_time) {
- setValue(String::Number(current_time));
-
- if (LayoutObject* layout_object = this->GetLayoutObject())
- layout_object->SetShouldDoFullPaintInvalidation();
-}
-
-void MediaControlTimelineElement::SetDuration(double duration) {
- SetFloatingPointAttribute(maxAttr, std::isfinite(duration) ? duration : 0);
-
- if (LayoutObject* layout_object = this->GetLayoutObject())
- layout_object->SetShouldDoFullPaintInvalidation();
-}
-
-void MediaControlTimelineElement::OnPlaying() {
- Frame* frame = GetDocument().GetFrame();
- if (!frame)
- return;
- metrics_.RecordPlaying(
- frame->GetChromeClient().GetScreenInfo().orientation_type,
- MediaElement().IsFullscreen(), TimelineWidth());
-}
-
-bool MediaControlTimelineElement::KeepEventInNode(Event* event) {
- return IsUserInteractionEventForSlider(event, GetLayoutObject());
-}
-
-int MediaControlTimelineElement::TimelineWidth() {
- if (LayoutBoxModelObject* box = GetLayoutBoxModelObject())
- return box->OffsetWidth().Round();
- return 0;
-}
-
-// ----------------------------
-
MediaControlVolumeSliderElement::MediaControlVolumeSliderElement(
MediaControls& media_controls)
: MediaControlInputElement(media_controls, kMediaVolumeSlider) {}

Powered by Google App Engine
This is Rietveld 408576698