| OLD | NEW |
| 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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 int center_x = | 104 int center_x = |
| 105 static_cast<int>((client_rect->left() + client_rect->right()) / 2); | 105 static_cast<int>((client_rect->left() + client_rect->right()) / 2); |
| 106 int center_y = | 106 int center_y = |
| 107 static_cast<int>((client_rect->top() + client_rect->bottom()) / 2); | 107 static_cast<int>((client_rect->top() + client_rect->bottom()) / 2); |
| 108 | 108 |
| 109 return element.GetDocument().ElementFromPoint(center_x, center_y); | 109 return element.GetDocument().ElementFromPoint(center_x, center_y); |
| 110 } | 110 } |
| 111 | 111 |
| 112 } // anonymous namespace | 112 } // anonymous namespace |
| 113 | 113 |
| 114 MediaControlPlayButtonElement::MediaControlPlayButtonElement( | |
| 115 MediaControls& media_controls) | |
| 116 : MediaControlInputElement(media_controls, kMediaPlayButton) {} | |
| 117 | |
| 118 MediaControlPlayButtonElement* MediaControlPlayButtonElement::Create( | |
| 119 MediaControls& media_controls) { | |
| 120 MediaControlPlayButtonElement* button = | |
| 121 new MediaControlPlayButtonElement(media_controls); | |
| 122 button->EnsureUserAgentShadowRoot(); | |
| 123 button->setType(InputTypeNames::button); | |
| 124 button->SetShadowPseudoId(AtomicString("-webkit-media-controls-play-button")); | |
| 125 return button; | |
| 126 } | |
| 127 | |
| 128 void MediaControlPlayButtonElement::DefaultEventHandler(Event* event) { | |
| 129 if (event->type() == EventTypeNames::click) { | |
| 130 if (MediaElement().paused()) | |
| 131 Platform::Current()->RecordAction( | |
| 132 UserMetricsAction("Media.Controls.Play")); | |
| 133 else | |
| 134 Platform::Current()->RecordAction( | |
| 135 UserMetricsAction("Media.Controls.Pause")); | |
| 136 | |
| 137 // Allow play attempts for plain src= media to force a reload in the error | |
| 138 // state. This allows potential recovery for transient network and decoder | |
| 139 // resource issues. | |
| 140 const String& url = MediaElement().currentSrc().GetString(); | |
| 141 if (MediaElement().error() && !HTMLMediaElement::IsMediaStreamURL(url) && | |
| 142 !HTMLMediaSource::Lookup(url)) | |
| 143 MediaElement().load(); | |
| 144 | |
| 145 MediaElement().TogglePlayState(); | |
| 146 UpdateDisplayType(); | |
| 147 event->SetDefaultHandled(); | |
| 148 } | |
| 149 MediaControlInputElement::DefaultEventHandler(event); | |
| 150 } | |
| 151 | |
| 152 void MediaControlPlayButtonElement::UpdateDisplayType() { | |
| 153 SetDisplayType(MediaElement().paused() ? kMediaPlayButton | |
| 154 : kMediaPauseButton); | |
| 155 UpdateOverflowString(); | |
| 156 } | |
| 157 | |
| 158 WebLocalizedString::Name | |
| 159 MediaControlPlayButtonElement::GetOverflowStringName() { | |
| 160 if (MediaElement().paused()) | |
| 161 return WebLocalizedString::kOverflowMenuPlay; | |
| 162 return WebLocalizedString::kOverflowMenuPause; | |
| 163 } | |
| 164 | |
| 165 // ---------------------------- | |
| 166 | |
| 167 MediaControlOverlayPlayButtonElement::MediaControlOverlayPlayButtonElement( | |
| 168 MediaControls& media_controls) | |
| 169 : MediaControlInputElement(media_controls, kMediaOverlayPlayButton) {} | |
| 170 | |
| 171 MediaControlOverlayPlayButtonElement* | |
| 172 MediaControlOverlayPlayButtonElement::Create(MediaControls& media_controls) { | |
| 173 MediaControlOverlayPlayButtonElement* button = | |
| 174 new MediaControlOverlayPlayButtonElement(media_controls); | |
| 175 button->EnsureUserAgentShadowRoot(); | |
| 176 button->setType(InputTypeNames::button); | |
| 177 button->SetShadowPseudoId( | |
| 178 AtomicString("-webkit-media-controls-overlay-play-button")); | |
| 179 return button; | |
| 180 } | |
| 181 | |
| 182 void MediaControlOverlayPlayButtonElement::DefaultEventHandler(Event* event) { | |
| 183 if (event->type() == EventTypeNames::click && MediaElement().paused()) { | |
| 184 Platform::Current()->RecordAction( | |
| 185 UserMetricsAction("Media.Controls.PlayOverlay")); | |
| 186 MediaElement().Play(); | |
| 187 UpdateDisplayType(); | |
| 188 event->SetDefaultHandled(); | |
| 189 } | |
| 190 } | |
| 191 | |
| 192 void MediaControlOverlayPlayButtonElement::UpdateDisplayType() { | |
| 193 SetIsWanted(MediaElement().ShouldShowControls() && MediaElement().paused()); | |
| 194 } | |
| 195 | |
| 196 bool MediaControlOverlayPlayButtonElement::KeepEventInNode(Event* event) { | |
| 197 return IsUserInteractionEvent(event); | |
| 198 } | |
| 199 | |
| 200 // ---------------------------- | |
| 201 | |
| 202 MediaControlToggleClosedCaptionsButtonElement:: | |
| 203 MediaControlToggleClosedCaptionsButtonElement(MediaControls& media_controls) | |
| 204 : MediaControlInputElement(media_controls, kMediaShowClosedCaptionsButton) { | |
| 205 } | |
| 206 | |
| 207 MediaControlToggleClosedCaptionsButtonElement* | |
| 208 MediaControlToggleClosedCaptionsButtonElement::Create( | |
| 209 MediaControls& media_controls) { | |
| 210 MediaControlToggleClosedCaptionsButtonElement* button = | |
| 211 new MediaControlToggleClosedCaptionsButtonElement(media_controls); | |
| 212 button->EnsureUserAgentShadowRoot(); | |
| 213 button->setType(InputTypeNames::button); | |
| 214 button->SetShadowPseudoId( | |
| 215 AtomicString("-webkit-media-controls-toggle-closed-captions-button")); | |
| 216 button->SetIsWanted(false); | |
| 217 return button; | |
| 218 } | |
| 219 | |
| 220 void MediaControlToggleClosedCaptionsButtonElement::UpdateDisplayType() { | |
| 221 bool captions_visible = MediaElement().TextTracksVisible(); | |
| 222 SetDisplayType(captions_visible ? kMediaHideClosedCaptionsButton | |
| 223 : kMediaShowClosedCaptionsButton); | |
| 224 } | |
| 225 | |
| 226 void MediaControlToggleClosedCaptionsButtonElement::DefaultEventHandler( | |
| 227 Event* event) { | |
| 228 if (event->type() == EventTypeNames::click) { | |
| 229 if (MediaElement().textTracks()->length() == 1) { | |
| 230 // If only one track exists, toggle it on/off | |
| 231 if (MediaElement().textTracks()->HasShowingTracks()) { | |
| 232 GetMediaControls().DisableShowingTextTracks(); | |
| 233 } else { | |
| 234 GetMediaControls().ShowTextTrackAtIndex(0); | |
| 235 } | |
| 236 } else { | |
| 237 GetMediaControls().ToggleTextTrackList(); | |
| 238 } | |
| 239 | |
| 240 UpdateDisplayType(); | |
| 241 event->SetDefaultHandled(); | |
| 242 } | |
| 243 | |
| 244 MediaControlInputElement::DefaultEventHandler(event); | |
| 245 } | |
| 246 | |
| 247 WebLocalizedString::Name | |
| 248 MediaControlToggleClosedCaptionsButtonElement::GetOverflowStringName() { | |
| 249 return WebLocalizedString::kOverflowMenuCaptions; | |
| 250 } | |
| 251 | |
| 252 // ---------------------------- | |
| 253 | |
| 254 MediaControlOverflowMenuButtonElement::MediaControlOverflowMenuButtonElement( | |
| 255 MediaControls& media_controls) | |
| 256 : MediaControlInputElement(media_controls, kMediaOverflowButton) {} | |
| 257 | |
| 258 MediaControlOverflowMenuButtonElement* | |
| 259 MediaControlOverflowMenuButtonElement::Create(MediaControls& media_controls) { | |
| 260 MediaControlOverflowMenuButtonElement* button = | |
| 261 new MediaControlOverflowMenuButtonElement(media_controls); | |
| 262 button->EnsureUserAgentShadowRoot(); | |
| 263 button->setType(InputTypeNames::button); | |
| 264 button->SetShadowPseudoId( | |
| 265 AtomicString("-internal-media-controls-overflow-button")); | |
| 266 button->SetIsWanted(false); | |
| 267 return button; | |
| 268 } | |
| 269 | |
| 270 void MediaControlOverflowMenuButtonElement::DefaultEventHandler(Event* event) { | |
| 271 if (event->type() == EventTypeNames::click) { | |
| 272 if (GetMediaControls().OverflowMenuVisible()) | |
| 273 Platform::Current()->RecordAction( | |
| 274 UserMetricsAction("Media.Controls.OverflowClose")); | |
| 275 else | |
| 276 Platform::Current()->RecordAction( | |
| 277 UserMetricsAction("Media.Controls.OverflowOpen")); | |
| 278 | |
| 279 GetMediaControls().ToggleOverflowMenu(); | |
| 280 event->SetDefaultHandled(); | |
| 281 } | |
| 282 | |
| 283 MediaControlInputElement::DefaultEventHandler(event); | |
| 284 } | |
| 285 | |
| 286 // ---------------------------- | 114 // ---------------------------- |
| 287 MediaControlDownloadButtonElement::MediaControlDownloadButtonElement( | 115 MediaControlDownloadButtonElement::MediaControlDownloadButtonElement( |
| 288 MediaControls& media_controls) | 116 MediaControls& media_controls) |
| 289 : MediaControlInputElement(media_controls, kMediaDownloadButton) {} | 117 : MediaControlInputElement(media_controls, kMediaDownloadButton) {} |
| 290 | 118 |
| 291 MediaControlDownloadButtonElement* MediaControlDownloadButtonElement::Create( | 119 MediaControlDownloadButtonElement* MediaControlDownloadButtonElement::Create( |
| 292 MediaControls& media_controls) { | 120 MediaControls& media_controls) { |
| 293 MediaControlDownloadButtonElement* button = | 121 MediaControlDownloadButtonElement* button = |
| 294 new MediaControlDownloadButtonElement(media_controls); | 122 new MediaControlDownloadButtonElement(media_controls); |
| 295 button->EnsureUserAgentShadowRoot(); | 123 button->EnsureUserAgentShadowRoot(); |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 588 if (LayoutObject* layout_object = this->GetLayoutObject()) | 416 if (LayoutObject* layout_object = this->GetLayoutObject()) |
| 589 layout_object->SetShouldDoFullPaintInvalidation(); | 417 layout_object->SetShouldDoFullPaintInvalidation(); |
| 590 } | 418 } |
| 591 | 419 |
| 592 bool MediaControlVolumeSliderElement::KeepEventInNode(Event* event) { | 420 bool MediaControlVolumeSliderElement::KeepEventInNode(Event* event) { |
| 593 return IsUserInteractionEventForSlider(event, GetLayoutObject()); | 421 return IsUserInteractionEventForSlider(event, GetLayoutObject()); |
| 594 } | 422 } |
| 595 | 423 |
| 596 // ---------------------------- | 424 // ---------------------------- |
| 597 | 425 |
| 598 MediaControlFullscreenButtonElement::MediaControlFullscreenButtonElement( | |
| 599 MediaControls& media_controls) | |
| 600 : MediaControlInputElement(media_controls, kMediaEnterFullscreenButton) {} | |
| 601 | |
| 602 MediaControlFullscreenButtonElement* | |
| 603 MediaControlFullscreenButtonElement::Create(MediaControls& media_controls) { | |
| 604 MediaControlFullscreenButtonElement* button = | |
| 605 new MediaControlFullscreenButtonElement(media_controls); | |
| 606 button->EnsureUserAgentShadowRoot(); | |
| 607 button->setType(InputTypeNames::button); | |
| 608 button->SetShadowPseudoId( | |
| 609 AtomicString("-webkit-media-controls-fullscreen-button")); | |
| 610 button->SetIsFullscreen(media_controls.MediaElement().IsFullscreen()); | |
| 611 button->SetIsWanted(false); | |
| 612 return button; | |
| 613 } | |
| 614 | |
| 615 void MediaControlFullscreenButtonElement::DefaultEventHandler(Event* event) { | |
| 616 if (event->type() == EventTypeNames::click) { | |
| 617 bool is_embedded_experience_enabled = | |
| 618 GetDocument().GetSettings() && | |
| 619 GetDocument().GetSettings()->GetEmbeddedMediaExperienceEnabled(); | |
| 620 if (MediaElement().IsFullscreen()) { | |
| 621 Platform::Current()->RecordAction( | |
| 622 UserMetricsAction("Media.Controls.ExitFullscreen")); | |
| 623 if (is_embedded_experience_enabled) { | |
| 624 Platform::Current()->RecordAction(UserMetricsAction( | |
| 625 "Media.Controls.ExitFullscreen.EmbeddedExperience")); | |
| 626 } | |
| 627 GetMediaControls().ExitFullscreen(); | |
| 628 } else { | |
| 629 Platform::Current()->RecordAction( | |
| 630 UserMetricsAction("Media.Controls.EnterFullscreen")); | |
| 631 if (is_embedded_experience_enabled) { | |
| 632 Platform::Current()->RecordAction(UserMetricsAction( | |
| 633 "Media.Controls.EnterFullscreen.EmbeddedExperience")); | |
| 634 } | |
| 635 GetMediaControls().EnterFullscreen(); | |
| 636 } | |
| 637 event->SetDefaultHandled(); | |
| 638 } | |
| 639 MediaControlInputElement::DefaultEventHandler(event); | |
| 640 } | |
| 641 | |
| 642 void MediaControlFullscreenButtonElement::SetIsFullscreen(bool is_fullscreen) { | |
| 643 SetDisplayType(is_fullscreen ? kMediaExitFullscreenButton | |
| 644 : kMediaEnterFullscreenButton); | |
| 645 } | |
| 646 | |
| 647 WebLocalizedString::Name | |
| 648 MediaControlFullscreenButtonElement::GetOverflowStringName() { | |
| 649 if (MediaElement().IsFullscreen()) | |
| 650 return WebLocalizedString::kOverflowMenuExitFullscreen; | |
| 651 return WebLocalizedString::kOverflowMenuEnterFullscreen; | |
| 652 } | |
| 653 | |
| 654 // ---------------------------- | |
| 655 | |
| 656 MediaControlCastButtonElement::MediaControlCastButtonElement( | 426 MediaControlCastButtonElement::MediaControlCastButtonElement( |
| 657 MediaControls& media_controls, | 427 MediaControls& media_controls, |
| 658 bool is_overlay_button) | 428 bool is_overlay_button) |
| 659 : MediaControlInputElement(media_controls, kMediaCastOnButton), | 429 : MediaControlInputElement(media_controls, kMediaCastOnButton), |
| 660 is_overlay_button_(is_overlay_button) { | 430 is_overlay_button_(is_overlay_button) { |
| 661 if (is_overlay_button_) | 431 if (is_overlay_button_) |
| 662 RecordMetrics(CastOverlayMetrics::kCreated); | 432 RecordMetrics(CastOverlayMetrics::kCreated); |
| 663 SetIsPlayingRemotely(false); | 433 SetIsPlayingRemotely(false); |
| 664 } | 434 } |
| 665 | 435 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 745 | 515 |
| 746 void MediaControlCastButtonElement::RecordMetrics(CastOverlayMetrics metric) { | 516 void MediaControlCastButtonElement::RecordMetrics(CastOverlayMetrics metric) { |
| 747 DCHECK(is_overlay_button_); | 517 DCHECK(is_overlay_button_); |
| 748 DEFINE_STATIC_LOCAL( | 518 DEFINE_STATIC_LOCAL( |
| 749 EnumerationHistogram, overlay_histogram, | 519 EnumerationHistogram, overlay_histogram, |
| 750 ("Cast.Sender.Overlay", static_cast<int>(CastOverlayMetrics::kCount))); | 520 ("Cast.Sender.Overlay", static_cast<int>(CastOverlayMetrics::kCount))); |
| 751 overlay_histogram.Count(static_cast<int>(metric)); | 521 overlay_histogram.Count(static_cast<int>(metric)); |
| 752 } | 522 } |
| 753 | 523 |
| 754 } // namespace blink | 524 } // namespace blink |
| OLD | NEW |