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

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

Issue 212173002: Media controls should fade out after a while regardless of mouse position (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: "Patchset 3" Created 6 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 unified diff | Download patch
« no previous file with comments | « Source/core/html/shadow/MediaControls.h ('k') | 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) 2011, 2012 Apple Inc. All rights reserved. 2 * Copyright (C) 2011, 2012 Apple Inc. All rights reserved.
3 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. 3 * Copyright (C) 2011, 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 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 18 matching lines...) Expand all
29 29
30 #include "bindings/v8/ExceptionStatePlaceholder.h" 30 #include "bindings/v8/ExceptionStatePlaceholder.h"
31 #include "core/events/MouseEvent.h" 31 #include "core/events/MouseEvent.h"
32 #include "core/html/HTMLMediaElement.h" 32 #include "core/html/HTMLMediaElement.h"
33 #include "core/html/MediaController.h" 33 #include "core/html/MediaController.h"
34 #include "core/rendering/RenderTheme.h" 34 #include "core/rendering/RenderTheme.h"
35 35
36 namespace WebCore { 36 namespace WebCore {
37 37
38 #if OS(ANDROID) 38 #if OS(ANDROID)
39 static const bool alwaysHideFullscreenControls = true;
40 static const bool needOverlayPlayButton = true; 39 static const bool needOverlayPlayButton = true;
41 #else 40 #else
42 static const bool alwaysHideFullscreenControls = false;
43 static const bool needOverlayPlayButton = false; 41 static const bool needOverlayPlayButton = false;
44 #endif 42 #endif
45 43
46 static const double timeWithoutMouseMovementBeforeHidingFullscreenControls = 3; 44 static const double timeWithoutMouseMovementBeforeHidingMediaControls = 3;
47 45
48 MediaControls::MediaControls(HTMLMediaElement& mediaElement) 46 MediaControls::MediaControls(HTMLMediaElement& mediaElement)
49 : HTMLDivElement(mediaElement.document()) 47 : HTMLDivElement(mediaElement.document())
50 , m_mediaElement(mediaElement) 48 , m_mediaElement(mediaElement)
51 , m_panel(0) 49 , m_panel(0)
52 , m_textDisplayContainer(0) 50 , m_textDisplayContainer(0)
53 , m_overlayPlayButton(0) 51 , m_overlayPlayButton(0)
54 , m_overlayEnclosure(0) 52 , m_overlayEnclosure(0)
55 , m_playButton(0) 53 , m_playButton(0)
56 , m_currentTimeDisplay(0) 54 , m_currentTimeDisplay(0)
57 , m_timeline(0) 55 , m_timeline(0)
58 , m_muteButton(0) 56 , m_muteButton(0)
59 , m_volumeSlider(0) 57 , m_volumeSlider(0)
60 , m_toggleClosedCaptionsButton(0) 58 , m_toggleClosedCaptionsButton(0)
61 , m_fullScreenButton(0) 59 , m_fullScreenButton(0)
62 , m_durationDisplay(0) 60 , m_durationDisplay(0)
63 , m_enclosure(0) 61 , m_enclosure(0)
64 , m_hideFullscreenControlsTimer(this, &MediaControls::hideFullscreenControls TimerFired) 62 , m_hideMediaControlsTimer(this, &MediaControls::hideMediaControlsTimerFired )
65 , m_isFullscreen(false)
66 , m_isMouseOverControls(false) 63 , m_isMouseOverControls(false)
67 , m_isPausedForScrubbing(false) 64 , m_isPausedForScrubbing(false)
68 { 65 {
69 } 66 }
70 67
71 PassRefPtr<MediaControls> MediaControls::create(HTMLMediaElement& mediaElement) 68 PassRefPtr<MediaControls> MediaControls::create(HTMLMediaElement& mediaElement)
72 { 69 {
73 RefPtr<MediaControls> controls = adoptRef(new MediaControls(mediaElement)); 70 RefPtr<MediaControls> controls = adoptRef(new MediaControls(mediaElement));
74 71
75 if (controls->initializeControls()) 72 if (controls->initializeControls())
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 void MediaControls::makeOpaque() 205 void MediaControls::makeOpaque()
209 { 206 {
210 m_panel->makeOpaque(); 207 m_panel->makeOpaque();
211 } 208 }
212 209
213 void MediaControls::makeTransparent() 210 void MediaControls::makeTransparent()
214 { 211 {
215 m_panel->makeTransparent(); 212 m_panel->makeTransparent();
216 } 213 }
217 214
218 bool MediaControls::shouldHideFullscreenControls() 215 bool MediaControls::shouldHideMediaControls()
219 { 216 {
220 return alwaysHideFullscreenControls || !m_panel->hovered(); 217 return !m_panel->hovered();
221 } 218 }
222 219
223 void MediaControls::playbackStarted() 220 void MediaControls::playbackStarted()
224 { 221 {
225 m_currentTimeDisplay->show(); 222 m_currentTimeDisplay->show();
226 m_durationDisplay->hide(); 223 m_durationDisplay->hide();
227 224
228 updatePlayState(); 225 updatePlayState();
229 m_timeline->setPosition(mediaElement().currentTime()); 226 m_timeline->setPosition(mediaElement().currentTime());
230 updateCurrentTimeDisplay(); 227 updateCurrentTimeDisplay();
231 228
232 if (m_isFullscreen) 229 startHideMediaControlsTimer();
233 startHideFullscreenControlsTimer();
234 } 230 }
235 231
236 void MediaControls::playbackProgressed() 232 void MediaControls::playbackProgressed()
237 { 233 {
238 m_timeline->setPosition(mediaElement().currentTime()); 234 m_timeline->setPosition(mediaElement().currentTime());
239 updateCurrentTimeDisplay(); 235 updateCurrentTimeDisplay();
240 236
241 if (!m_isMouseOverControls && mediaElement().hasVideo()) 237 if (!m_isMouseOverControls && mediaElement().hasVideo())
242 makeTransparent(); 238 makeTransparent();
243 } 239 }
244 240
245 void MediaControls::playbackStopped() 241 void MediaControls::playbackStopped()
246 { 242 {
247 updatePlayState(); 243 updatePlayState();
248 m_timeline->setPosition(mediaElement().currentTime()); 244 m_timeline->setPosition(mediaElement().currentTime());
249 updateCurrentTimeDisplay(); 245 updateCurrentTimeDisplay();
250 makeOpaque(); 246 makeOpaque();
251 247
252 stopHideFullscreenControlsTimer(); 248 stopHideMediaControlsTimer();
253 } 249 }
254 250
255 void MediaControls::updatePlayState() 251 void MediaControls::updatePlayState()
256 { 252 {
257 if (m_isPausedForScrubbing) 253 if (m_isPausedForScrubbing)
258 return; 254 return;
259 255
260 if (m_overlayPlayButton) 256 if (m_overlayPlayButton)
261 m_overlayPlayButton->updateDisplayType(); 257 m_overlayPlayButton->updateDisplayType();
262 m_playButton->updateDisplayType(); 258 m_playButton->updateDisplayType();
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 m_toggleClosedCaptionsButton->hide(); 316 m_toggleClosedCaptionsButton->hide();
321 } 317 }
322 318
323 void MediaControls::closedCaptionTracksChanged() 319 void MediaControls::closedCaptionTracksChanged()
324 { 320 {
325 refreshClosedCaptionsButtonVisibility(); 321 refreshClosedCaptionsButtonVisibility();
326 } 322 }
327 323
328 void MediaControls::enteredFullscreen() 324 void MediaControls::enteredFullscreen()
329 { 325 {
330 m_isFullscreen = true;
331 m_fullScreenButton->setIsFullscreen(true); 326 m_fullScreenButton->setIsFullscreen(true);
332 startHideFullscreenControlsTimer(); 327 stopHideMediaControlsTimer();
328 startHideMediaControlsTimer();
333 } 329 }
334 330
335 void MediaControls::exitedFullscreen() 331 void MediaControls::exitedFullscreen()
336 { 332 {
337 m_isFullscreen = false;
338 m_fullScreenButton->setIsFullscreen(false); 333 m_fullScreenButton->setIsFullscreen(false);
339 stopHideFullscreenControlsTimer(); 334 stopHideMediaControlsTimer();
335 startHideMediaControlsTimer();
340 } 336 }
341 337
342 void MediaControls::defaultEventHandler(Event* event) 338 void MediaControls::defaultEventHandler(Event* event)
343 { 339 {
344 HTMLDivElement::defaultEventHandler(event); 340 HTMLDivElement::defaultEventHandler(event);
345 341
346 if (event->type() == EventTypeNames::mouseover) { 342 if (event->type() == EventTypeNames::mouseover) {
347 if (!containsRelatedTarget(event)) { 343 if (!containsRelatedTarget(event)) {
348 m_isMouseOverControls = true; 344 m_isMouseOverControls = true;
349 if (!mediaElement().togglePlayStateWillPlay()) { 345 if (!mediaElement().togglePlayStateWillPlay()) {
350 makeOpaque(); 346 makeOpaque();
351 if (shouldHideFullscreenControls()) 347 if (shouldHideMediaControls())
352 startHideFullscreenControlsTimer(); 348 startHideMediaControlsTimer();
353 } 349 }
354 } 350 }
355 return; 351 return;
356 } 352 }
357 353
358 if (event->type() == EventTypeNames::mouseout) { 354 if (event->type() == EventTypeNames::mouseout) {
359 if (!containsRelatedTarget(event)) { 355 if (!containsRelatedTarget(event)) {
360 m_isMouseOverControls = false; 356 m_isMouseOverControls = false;
361 stopHideFullscreenControlsTimer(); 357 stopHideMediaControlsTimer();
362 } 358 }
363 return; 359 return;
364 } 360 }
365 361
366 if (event->type() == EventTypeNames::mousemove) { 362 if (event->type() == EventTypeNames::mousemove) {
367 if (m_isFullscreen) { 363 // When we get a mouse move, show the media controls, and start a timer
368 // When we get a mouse move in fullscreen mode, show the media contr ols, and start a timer 364 // that will hide the media controls after a 3 seconds without a mouse m ove.
369 // that will hide the media controls after a 3 seconds without a mou se move. 365 makeOpaque();
370 makeOpaque(); 366 if (shouldHideMediaControls())
371 if (shouldHideFullscreenControls()) 367 startHideMediaControlsTimer();
372 startHideFullscreenControlsTimer();
373 }
374 return; 368 return;
375 } 369 }
376 } 370 }
377 371
378 void MediaControls::hideFullscreenControlsTimerFired(Timer<MediaControls>*) 372 void MediaControls::hideMediaControlsTimerFired(Timer<MediaControls>*)
379 { 373 {
380 if (mediaElement().togglePlayStateWillPlay()) 374 if (mediaElement().togglePlayStateWillPlay())
381 return; 375 return;
382 376
383 if (!m_isFullscreen) 377 if (!shouldHideMediaControls())
384 return;
385
386 if (!shouldHideFullscreenControls())
387 return; 378 return;
388 379
389 makeTransparent(); 380 makeTransparent();
390 } 381 }
391 382
392 void MediaControls::startHideFullscreenControlsTimer() 383 void MediaControls::startHideMediaControlsTimer()
393 { 384 {
394 if (!m_isFullscreen) 385 m_hideMediaControlsTimer.startOneShot(timeWithoutMouseMovementBeforeHidingMe diaControls, FROM_HERE);
395 return;
396
397 m_hideFullscreenControlsTimer.startOneShot(timeWithoutMouseMovementBeforeHid ingFullscreenControls, FROM_HERE);
398 } 386 }
399 387
400 void MediaControls::stopHideFullscreenControlsTimer() 388 void MediaControls::stopHideMediaControlsTimer()
401 { 389 {
402 m_hideFullscreenControlsTimer.stop(); 390 m_hideMediaControlsTimer.stop();
403 } 391 }
404 392
405 const AtomicString& MediaControls::shadowPseudoId() const 393 const AtomicString& MediaControls::shadowPseudoId() const
406 { 394 {
407 DEFINE_STATIC_LOCAL(AtomicString, id, ("-webkit-media-controls")); 395 DEFINE_STATIC_LOCAL(AtomicString, id, ("-webkit-media-controls"));
408 return id; 396 return id;
409 } 397 }
410 398
411 bool MediaControls::containsRelatedTarget(Event* event) 399 bool MediaControls::containsRelatedTarget(Event* event)
412 { 400 {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 437
450 void MediaControls::updateTextTrackDisplay() 438 void MediaControls::updateTextTrackDisplay()
451 { 439 {
452 if (!m_textDisplayContainer) 440 if (!m_textDisplayContainer)
453 createTextTrackDisplay(); 441 createTextTrackDisplay();
454 442
455 m_textDisplayContainer->updateDisplay(); 443 m_textDisplayContainer->updateDisplay();
456 } 444 }
457 445
458 } 446 }
OLDNEW
« no previous file with comments | « Source/core/html/shadow/MediaControls.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698