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

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

Issue 614263002: Drop all timeline seeks outside of the seekable range. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@seek
Patch Set: Created 6 years, 2 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 | no next file » | 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 19 matching lines...) Expand all
30 #include "config.h" 30 #include "config.h"
31 #include "core/html/shadow/MediaControlElements.h" 31 #include "core/html/shadow/MediaControlElements.h"
32 32
33 #include "bindings/core/v8/ExceptionStatePlaceholder.h" 33 #include "bindings/core/v8/ExceptionStatePlaceholder.h"
34 #include "core/dom/DOMTokenList.h" 34 #include "core/dom/DOMTokenList.h"
35 #include "core/dom/shadow/ShadowRoot.h" 35 #include "core/dom/shadow/ShadowRoot.h"
36 #include "core/events/MouseEvent.h" 36 #include "core/events/MouseEvent.h"
37 #include "core/frame/LocalFrame.h" 37 #include "core/frame/LocalFrame.h"
38 #include "core/html/HTMLVideoElement.h" 38 #include "core/html/HTMLVideoElement.h"
39 #include "core/html/MediaController.h" 39 #include "core/html/MediaController.h"
40 #include "core/html/TimeRanges.h"
40 #include "core/html/shadow/MediaControls.h" 41 #include "core/html/shadow/MediaControls.h"
41 #include "core/html/track/TextTrack.h" 42 #include "core/html/track/TextTrack.h"
42 #include "core/html/track/vtt/VTTRegionList.h" 43 #include "core/html/track/vtt/VTTRegionList.h"
43 #include "core/page/EventHandler.h" 44 #include "core/page/EventHandler.h"
44 #include "core/rendering/RenderMediaControlElements.h" 45 #include "core/rendering/RenderMediaControlElements.h"
45 #include "core/rendering/RenderSlider.h" 46 #include "core/rendering/RenderSlider.h"
46 #include "core/rendering/RenderTheme.h" 47 #include "core/rendering/RenderTheme.h"
47 #include "core/rendering/RenderVideo.h" 48 #include "core/rendering/RenderVideo.h"
48 #include "platform/RuntimeEnabledFeatures.h" 49 #include "platform/RuntimeEnabledFeatures.h"
49 50
50 namespace blink { 51 namespace blink {
51 52
52 using namespace HTMLNames; 53 using namespace HTMLNames;
53 54
54 static const AtomicString& getMediaControlCurrentTimeDisplayElementShadowPseudoI d(); 55 static const AtomicString& getMediaControlCurrentTimeDisplayElementShadowPseudoI d();
55 static const AtomicString& getMediaControlTimeRemainingDisplayElementShadowPseud oId(); 56 static const AtomicString& getMediaControlTimeRemainingDisplayElementShadowPseud oId();
56 57
57 // This is the duration from mediaControls.css 58 // This is the duration from mediaControls.css
58 static const double fadeOutDuration = 0.3; 59 static const double fadeOutDuration = 0.3;
59 60
61 // Snap seeks to the nearest seekable() range if they're <= this percentage of t he duration apart.
62 // I.e., if the seekable() range is [4s, 5s] and the duration 10s, clicks on the timeline >= 3s or <= 6s
63 // would snap to 4 and 5 respectively. Clicks outside of those ranges would be dropped.
64 //
65 // This ensures accidental clicks don't cause annoying timeline jumps, or worse, restart the entire
66 // playback process when only a seek to zero is available.
67 static const double snapPercentageForSeeks = 10 / 100.0;
philipj_slow 2014/10/01 11:14:22 This is 0.1 and not a percentage :)
68
60 static bool isUserInteractionEvent(Event* event) 69 static bool isUserInteractionEvent(Event* event)
61 { 70 {
62 const AtomicString& type = event->type(); 71 const AtomicString& type = event->type();
63 return type == EventTypeNames::mousedown 72 return type == EventTypeNames::mousedown
64 || type == EventTypeNames::mouseup 73 || type == EventTypeNames::mouseup
65 || type == EventTypeNames::click 74 || type == EventTypeNames::click
66 || type == EventTypeNames::dblclick 75 || type == EventTypeNames::dblclick
67 || event->isKeyboardEvent() 76 || event->isKeyboardEvent()
68 || event->isTouchEvent(); 77 || event->isTouchEvent();
69 } 78 }
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 420
412 MediaControlInputElement::defaultEventHandler(event); 421 MediaControlInputElement::defaultEventHandler(event);
413 422
414 if (event->type() == EventTypeNames::mouseover || event->type() == EventType Names::mouseout || event->type() == EventTypeNames::mousemove) 423 if (event->type() == EventTypeNames::mouseover || event->type() == EventType Names::mouseout || event->type() == EventTypeNames::mousemove)
415 return; 424 return;
416 425
417 double time = value().toDouble(); 426 double time = value().toDouble();
418 if (event->type() == EventTypeNames::input) { 427 if (event->type() == EventTypeNames::input) {
419 // FIXME: This will need to take the timeline offset into consideration 428 // FIXME: This will need to take the timeline offset into consideration
420 // once that concept is supported, see https://crbug.com/312699 429 // once that concept is supported, see https://crbug.com/312699
421 if (mediaElement().controller()) 430 if (mediaElement().controller()) {
422 mediaElement().controller()->setCurrentTime(time); 431 mediaElement().controller()->setCurrentTime(time);
philipj_slow 2014/10/01 11:14:22 Should the same rule not apply to a media element
DaleCurtis 2014/10/14 18:06:26 Done.
philipj_slow 2014/10/16 18:52:51 We appear to have miscommunicated :) I mean that t
DaleCurtis 2014/10/16 19:51:50 Sorry I still don't understand. :| Are you saying
philipj_slow 2014/10/16 20:03:18 Oops, sloppy reading on my part! You've already do
423 else 432 } else {
424 mediaElement().setCurrentTime(time, IGNORE_EXCEPTION); 433 // Only pass through seeks that are within the seekable range or clo se enough that we're sure
434 // the user didn't make an accidental click.
435 RefPtrWillBeRawPtr<TimeRanges> seekableRanges = mediaElement().seeka ble();
436 if (seekableRanges->contain(time)) {
437 mediaElement().setCurrentTime(time, IGNORE_EXCEPTION);
438 } else {
439 const double duration = getFloatingPointAttribute(maxAttr);
philipj_slow 2014/10/01 11:14:22 It took me a while to realize that the duration is
440 const double nearestTime = seekableRanges->nearest(time, mediaEl ement().currentTime());
441 if (duration && std::abs(time - nearestTime) / duration <= snapP ercentageForSeeks)
442 mediaElement().setCurrentTime(time, IGNORE_EXCEPTION);
443 }
444 }
425 } 445 }
426 446
427 RenderSlider* slider = toRenderSlider(renderer()); 447 RenderSlider* slider = toRenderSlider(renderer());
428 if (slider && slider->inDragMode()) 448 if (slider && slider->inDragMode())
429 mediaControls().updateCurrentTimeDisplay(); 449 mediaControls().updateCurrentTimeDisplay();
430 } 450 }
431 451
432 bool MediaControlTimelineElement::willRespondToMouseClickEvents() 452 bool MediaControlTimelineElement::willRespondToMouseClickEvents()
433 { 453 {
434 return inDocument() && document().isActive(); 454 return inDocument() && document().isActive();
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
770 float fontSize = smallestDimension * 0.05f; 790 float fontSize = smallestDimension * 0.05f;
771 if (fontSize != m_fontSize) { 791 if (fontSize != m_fontSize) {
772 m_fontSize = fontSize; 792 m_fontSize = fontSize;
773 setInlineStyleProperty(CSSPropertyFontSize, fontSize, CSSPrimitiveValue: :CSS_PX); 793 setInlineStyleProperty(CSSPropertyFontSize, fontSize, CSSPrimitiveValue: :CSS_PX);
774 } 794 }
775 } 795 }
776 796
777 // ---------------------------- 797 // ----------------------------
778 798
779 } // namespace blink 799 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698