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

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

Issue 1894993003: Merge "Add user actions to record media controls interaction." (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2704
Patch Set: Created 4 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 | « no previous file | tools/metrics/actions/actions.xml » ('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/html/HTMLMediaSource.h" 38 #include "core/html/HTMLMediaSource.h"
39 #include "core/html/HTMLVideoElement.h" 39 #include "core/html/HTMLVideoElement.h"
40 #include "core/html/TimeRanges.h" 40 #include "core/html/TimeRanges.h"
41 #include "core/html/shadow/MediaControls.h" 41 #include "core/html/shadow/MediaControls.h"
42 #include "core/input/EventHandler.h" 42 #include "core/input/EventHandler.h"
43 #include "core/layout/LayoutTheme.h" 43 #include "core/layout/LayoutTheme.h"
44 #include "core/layout/LayoutVideo.h" 44 #include "core/layout/LayoutVideo.h"
45 #include "core/layout/api/LayoutSliderItem.h" 45 #include "core/layout/api/LayoutSliderItem.h"
46 #include "platform/Histogram.h" 46 #include "platform/Histogram.h"
47 #include "platform/RuntimeEnabledFeatures.h" 47 #include "platform/RuntimeEnabledFeatures.h"
48 #include "public/platform/Platform.h"
49 #include "public/platform/UserMetricsAction.h"
48 50
49 namespace blink { 51 namespace blink {
50 52
51 using namespace HTMLNames; 53 using namespace HTMLNames;
52 54
53 namespace { 55 namespace {
54 56
55 // This is the duration from mediaControls.css 57 // This is the duration from mediaControls.css
56 const double fadeOutDuration = 0.3; 58 const double fadeOutDuration = 0.3;
57 59
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 RawPtr<MediaControlMuteButtonElement> button = new MediaControlMuteButtonEle ment(mediaControls); 249 RawPtr<MediaControlMuteButtonElement> button = new MediaControlMuteButtonEle ment(mediaControls);
248 button->ensureUserAgentShadowRoot(); 250 button->ensureUserAgentShadowRoot();
249 button->setType(InputTypeNames::button); 251 button->setType(InputTypeNames::button);
250 button->setShadowPseudoId(AtomicString("-webkit-media-controls-mute-button") ); 252 button->setShadowPseudoId(AtomicString("-webkit-media-controls-mute-button") );
251 return button.release(); 253 return button.release();
252 } 254 }
253 255
254 void MediaControlMuteButtonElement::defaultEventHandler(Event* event) 256 void MediaControlMuteButtonElement::defaultEventHandler(Event* event)
255 { 257 {
256 if (event->type() == EventTypeNames::click) { 258 if (event->type() == EventTypeNames::click) {
259 if (mediaElement().muted())
260 Platform::current()->recordAction(UserMetricsAction("Media.Controls. Unmute"));
261 else
262 Platform::current()->recordAction(UserMetricsAction("Media.Controls. Mute"));
263
257 mediaElement().setMuted(!mediaElement().muted()); 264 mediaElement().setMuted(!mediaElement().muted());
258 event->setDefaultHandled(); 265 event->setDefaultHandled();
259 } 266 }
260 267
261 HTMLInputElement::defaultEventHandler(event); 268 HTMLInputElement::defaultEventHandler(event);
262 } 269 }
263 270
264 void MediaControlMuteButtonElement::updateDisplayType() 271 void MediaControlMuteButtonElement::updateDisplayType()
265 { 272 {
266 setDisplayType(mediaElement().muted() ? MediaUnMuteButton : MediaMuteButton) ; 273 setDisplayType(mediaElement().muted() ? MediaUnMuteButton : MediaMuteButton) ;
(...skipping 11 matching lines...) Expand all
278 RawPtr<MediaControlPlayButtonElement> button = new MediaControlPlayButtonEle ment(mediaControls); 285 RawPtr<MediaControlPlayButtonElement> button = new MediaControlPlayButtonEle ment(mediaControls);
279 button->ensureUserAgentShadowRoot(); 286 button->ensureUserAgentShadowRoot();
280 button->setType(InputTypeNames::button); 287 button->setType(InputTypeNames::button);
281 button->setShadowPseudoId(AtomicString("-webkit-media-controls-play-button") ); 288 button->setShadowPseudoId(AtomicString("-webkit-media-controls-play-button") );
282 return button.release(); 289 return button.release();
283 } 290 }
284 291
285 void MediaControlPlayButtonElement::defaultEventHandler(Event* event) 292 void MediaControlPlayButtonElement::defaultEventHandler(Event* event)
286 { 293 {
287 if (event->type() == EventTypeNames::click) { 294 if (event->type() == EventTypeNames::click) {
295 if (mediaElement().paused())
296 Platform::current()->recordAction(UserMetricsAction("Media.Controls. Play"));
297 else
298 Platform::current()->recordAction(UserMetricsAction("Media.Controls. Pause"));
299
288 // Allow play attempts for plain src= media to force a reload in the err or state. This allows potential 300 // Allow play attempts for plain src= media to force a reload in the err or state. This allows potential
289 // recovery for transient network and decoder resource issues. 301 // recovery for transient network and decoder resource issues.
290 const String& url = mediaElement().currentSrc().getString(); 302 const String& url = mediaElement().currentSrc().getString();
291 if (mediaElement().error() && !HTMLMediaElement::isMediaStreamURL(url) & & !HTMLMediaSource::lookup(url)) 303 if (mediaElement().error() && !HTMLMediaElement::isMediaStreamURL(url) & & !HTMLMediaSource::lookup(url))
292 mediaElement().load(); 304 mediaElement().load();
293 305
294 mediaElement().togglePlayState(); 306 mediaElement().togglePlayState();
295 updateDisplayType(); 307 updateDisplayType();
296 event->setDefaultHandled(); 308 event->setDefaultHandled();
297 } 309 }
(...skipping 17 matching lines...) Expand all
315 RawPtr<MediaControlOverlayPlayButtonElement> button = new MediaControlOverla yPlayButtonElement(mediaControls); 327 RawPtr<MediaControlOverlayPlayButtonElement> button = new MediaControlOverla yPlayButtonElement(mediaControls);
316 button->ensureUserAgentShadowRoot(); 328 button->ensureUserAgentShadowRoot();
317 button->setType(InputTypeNames::button); 329 button->setType(InputTypeNames::button);
318 button->setShadowPseudoId(AtomicString("-webkit-media-controls-overlay-play- button")); 330 button->setShadowPseudoId(AtomicString("-webkit-media-controls-overlay-play- button"));
319 return button.release(); 331 return button.release();
320 } 332 }
321 333
322 void MediaControlOverlayPlayButtonElement::defaultEventHandler(Event* event) 334 void MediaControlOverlayPlayButtonElement::defaultEventHandler(Event* event)
323 { 335 {
324 if (event->type() == EventTypeNames::click && mediaElement().paused()) { 336 if (event->type() == EventTypeNames::click && mediaElement().paused()) {
337 Platform::current()->recordAction(UserMetricsAction("Media.Controls.Play Overlay"));
325 mediaElement().play(); 338 mediaElement().play();
326 updateDisplayType(); 339 updateDisplayType();
327 event->setDefaultHandled(); 340 event->setDefaultHandled();
328 } 341 }
329 } 342 }
330 343
331 void MediaControlOverlayPlayButtonElement::updateDisplayType() 344 void MediaControlOverlayPlayButtonElement::updateDisplayType()
332 { 345 {
333 setIsWanted(mediaElement().shouldShowControls() && mediaElement().paused()); 346 setIsWanted(mediaElement().shouldShowControls() && mediaElement().paused());
334 } 347 }
(...skipping 24 matching lines...) Expand all
359 void MediaControlToggleClosedCaptionsButtonElement::updateDisplayType() 372 void MediaControlToggleClosedCaptionsButtonElement::updateDisplayType()
360 { 373 {
361 bool captionsVisible = mediaElement().closedCaptionsVisible(); 374 bool captionsVisible = mediaElement().closedCaptionsVisible();
362 setDisplayType(captionsVisible ? MediaHideClosedCaptionsButton : MediaShowCl osedCaptionsButton); 375 setDisplayType(captionsVisible ? MediaHideClosedCaptionsButton : MediaShowCl osedCaptionsButton);
363 setChecked(captionsVisible); 376 setChecked(captionsVisible);
364 } 377 }
365 378
366 void MediaControlToggleClosedCaptionsButtonElement::defaultEventHandler(Event* e vent) 379 void MediaControlToggleClosedCaptionsButtonElement::defaultEventHandler(Event* e vent)
367 { 380 {
368 if (event->type() == EventTypeNames::click) { 381 if (event->type() == EventTypeNames::click) {
382 if (mediaElement().closedCaptionsVisible())
383 Platform::current()->recordAction(UserMetricsAction("Media.Controls. ClosedCaptionHide"));
384 else
385 Platform::current()->recordAction(UserMetricsAction("Media.Controls. ClosedCaptionShow"));
369 mediaElement().setClosedCaptionsVisible(!mediaElement().closedCaptionsVi sible()); 386 mediaElement().setClosedCaptionsVisible(!mediaElement().closedCaptionsVi sible());
370 setChecked(mediaElement().closedCaptionsVisible()); 387 setChecked(mediaElement().closedCaptionsVisible());
371 updateDisplayType(); 388 updateDisplayType();
372 event->setDefaultHandled(); 389 event->setDefaultHandled();
373 } 390 }
374 391
375 HTMLInputElement::defaultEventHandler(event); 392 HTMLInputElement::defaultEventHandler(event);
376 } 393 }
377 394
378 // ---------------------------- 395 // ----------------------------
(...skipping 14 matching lines...) Expand all
393 } 410 }
394 411
395 void MediaControlTimelineElement::defaultEventHandler(Event* event) 412 void MediaControlTimelineElement::defaultEventHandler(Event* event)
396 { 413 {
397 if (event->isMouseEvent() && toMouseEvent(event)->button() != LeftButton) 414 if (event->isMouseEvent() && toMouseEvent(event)->button() != LeftButton)
398 return; 415 return;
399 416
400 if (!inShadowIncludingDocument() || !document().isActive()) 417 if (!inShadowIncludingDocument() || !document().isActive())
401 return; 418 return;
402 419
403 if (event->type() == EventTypeNames::mousedown) 420 if (event->type() == EventTypeNames::mousedown) {
421 Platform::current()->recordAction(UserMetricsAction("Media.Controls.Scru bbingBegin"));
404 mediaControls().beginScrubbing(); 422 mediaControls().beginScrubbing();
423 }
405 424
406 if (event->type() == EventTypeNames::mouseup) 425 if (event->type() == EventTypeNames::mouseup) {
426 Platform::current()->recordAction(UserMetricsAction("Media.Controls.Scru bbingEnd"));
407 mediaControls().endScrubbing(); 427 mediaControls().endScrubbing();
428 }
408 429
409 MediaControlInputElement::defaultEventHandler(event); 430 MediaControlInputElement::defaultEventHandler(event);
410 431
411 if (event->type() == EventTypeNames::mouseover || event->type() == EventType Names::mouseout || event->type() == EventTypeNames::mousemove) 432 if (event->type() == EventTypeNames::mouseover || event->type() == EventType Names::mouseout || event->type() == EventTypeNames::mousemove)
412 return; 433 return;
413 434
414 double time = value().toDouble(); 435 double time = value().toDouble();
415 if (event->type() == EventTypeNames::input) { 436 if (event->type() == EventTypeNames::input) {
416 // FIXME: This will need to take the timeline offset into consideration 437 // FIXME: This will need to take the timeline offset into consideration
417 // once that concept is supported, see https://crbug.com/312699 438 // once that concept is supported, see https://crbug.com/312699
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 return; 495 return;
475 496
476 if (!inShadowIncludingDocument() || !document().isActive()) 497 if (!inShadowIncludingDocument() || !document().isActive())
477 return; 498 return;
478 499
479 MediaControlInputElement::defaultEventHandler(event); 500 MediaControlInputElement::defaultEventHandler(event);
480 501
481 if (event->type() == EventTypeNames::mouseover || event->type() == EventType Names::mouseout || event->type() == EventTypeNames::mousemove) 502 if (event->type() == EventTypeNames::mouseover || event->type() == EventType Names::mouseout || event->type() == EventTypeNames::mousemove)
482 return; 503 return;
483 504
505 if (event->type() == EventTypeNames::mousedown)
506 Platform::current()->recordAction(UserMetricsAction("Media.Controls.Volu meChangeBegin"));
507
508 if (event->type() == EventTypeNames::mouseup)
509 Platform::current()->recordAction(UserMetricsAction("Media.Controls.Volu meChangeEnd"));
510
484 double volume = value().toDouble(); 511 double volume = value().toDouble();
485 mediaElement().setVolume(volume, ASSERT_NO_EXCEPTION); 512 mediaElement().setVolume(volume, ASSERT_NO_EXCEPTION);
486 mediaElement().setMuted(false); 513 mediaElement().setMuted(false);
487 } 514 }
488 515
489 bool MediaControlVolumeSliderElement::willRespondToMouseMoveEvents() 516 bool MediaControlVolumeSliderElement::willRespondToMouseMoveEvents()
490 { 517 {
491 if (!inShadowIncludingDocument() || !document().isActive()) 518 if (!inShadowIncludingDocument() || !document().isActive())
492 return false; 519 return false;
493 520
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 button->ensureUserAgentShadowRoot(); 553 button->ensureUserAgentShadowRoot();
527 button->setType(InputTypeNames::button); 554 button->setType(InputTypeNames::button);
528 button->setShadowPseudoId(AtomicString("-webkit-media-controls-fullscreen-bu tton")); 555 button->setShadowPseudoId(AtomicString("-webkit-media-controls-fullscreen-bu tton"));
529 button->setIsWanted(false); 556 button->setIsWanted(false);
530 return button.release(); 557 return button.release();
531 } 558 }
532 559
533 void MediaControlFullscreenButtonElement::defaultEventHandler(Event* event) 560 void MediaControlFullscreenButtonElement::defaultEventHandler(Event* event)
534 { 561 {
535 if (event->type() == EventTypeNames::click) { 562 if (event->type() == EventTypeNames::click) {
536 if (mediaElement().isFullscreen()) 563 if (mediaElement().isFullscreen()) {
564 Platform::current()->recordAction(UserMetricsAction("Media.Controls. ExitFullscreen"));
537 mediaElement().exitFullscreen(); 565 mediaElement().exitFullscreen();
538 else 566 } else {
567 Platform::current()->recordAction(UserMetricsAction("Media.Controls. EnterFullscreen"));
539 mediaElement().enterFullscreen(); 568 mediaElement().enterFullscreen();
569 }
540 event->setDefaultHandled(); 570 event->setDefaultHandled();
541 } 571 }
542 HTMLInputElement::defaultEventHandler(event); 572 HTMLInputElement::defaultEventHandler(event);
543 } 573 }
544 574
545 void MediaControlFullscreenButtonElement::setIsFullscreen(bool isFullscreen) 575 void MediaControlFullscreenButtonElement::setIsFullscreen(bool isFullscreen)
546 { 576 {
547 setDisplayType(isFullscreen ? MediaExitFullscreenButton : MediaEnterFullscre enButton); 577 setDisplayType(isFullscreen ? MediaExitFullscreenButton : MediaEnterFullscre enButton);
548 } 578 }
549 579
(...skipping 11 matching lines...) Expand all
561 { 591 {
562 RawPtr<MediaControlCastButtonElement> button = new MediaControlCastButtonEle ment(mediaControls, isOverlayButton); 592 RawPtr<MediaControlCastButtonElement> button = new MediaControlCastButtonEle ment(mediaControls, isOverlayButton);
563 button->ensureUserAgentShadowRoot(); 593 button->ensureUserAgentShadowRoot();
564 button->setType(InputTypeNames::button); 594 button->setType(InputTypeNames::button);
565 return button.release(); 595 return button.release();
566 } 596 }
567 597
568 void MediaControlCastButtonElement::defaultEventHandler(Event* event) 598 void MediaControlCastButtonElement::defaultEventHandler(Event* event)
569 { 599 {
570 if (event->type() == EventTypeNames::click) { 600 if (event->type() == EventTypeNames::click) {
601 if (m_isOverlayButton)
602 Platform::current()->recordAction(UserMetricsAction("Media.Controls. CastOverlay"));
603 else
604 Platform::current()->recordAction(UserMetricsAction("Media.Controls. Cast"));
605
571 if (m_isOverlayButton && !m_clickUseCounted) { 606 if (m_isOverlayButton && !m_clickUseCounted) {
572 m_clickUseCounted = true; 607 m_clickUseCounted = true;
573 recordMetrics(CastOverlayMetrics::Clicked); 608 recordMetrics(CastOverlayMetrics::Clicked);
574 } 609 }
575 if (mediaElement().isPlayingRemotely()) { 610 if (mediaElement().isPlayingRemotely()) {
576 mediaElement().requestRemotePlaybackControl(); 611 mediaElement().requestRemotePlaybackControl();
577 } else { 612 } else {
578 mediaElement().requestRemotePlayback(); 613 mediaElement().requestRemotePlayback();
579 } 614 }
580 } 615 }
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 } 691 }
657 692
658 RawPtr<MediaControlCurrentTimeDisplayElement> MediaControlCurrentTimeDisplayElem ent::create(MediaControls& mediaControls) 693 RawPtr<MediaControlCurrentTimeDisplayElement> MediaControlCurrentTimeDisplayElem ent::create(MediaControls& mediaControls)
659 { 694 {
660 RawPtr<MediaControlCurrentTimeDisplayElement> element = new MediaControlCurr entTimeDisplayElement(mediaControls); 695 RawPtr<MediaControlCurrentTimeDisplayElement> element = new MediaControlCurr entTimeDisplayElement(mediaControls);
661 element->setShadowPseudoId(AtomicString("-webkit-media-controls-current-time -display")); 696 element->setShadowPseudoId(AtomicString("-webkit-media-controls-current-time -display"));
662 return element.release(); 697 return element.release();
663 } 698 }
664 699
665 } // namespace blink 700 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | tools/metrics/actions/actions.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698