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

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

Issue 1156993013: New media playback UI. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: fixed some tests from previous CL. Created 5 years, 5 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
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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 , m_durationDisplay(nullptr) 61 , m_durationDisplay(nullptr)
62 , m_muteButton(nullptr) 62 , m_muteButton(nullptr)
63 , m_volumeSlider(nullptr) 63 , m_volumeSlider(nullptr)
64 , m_toggleClosedCaptionsButton(nullptr) 64 , m_toggleClosedCaptionsButton(nullptr)
65 , m_castButton(nullptr) 65 , m_castButton(nullptr)
66 , m_fullScreenButton(nullptr) 66 , m_fullScreenButton(nullptr)
67 , m_hideMediaControlsTimer(this, &MediaControls::hideMediaControlsTimerFired ) 67 , m_hideMediaControlsTimer(this, &MediaControls::hideMediaControlsTimerFired )
68 , m_hideTimerBehaviorFlags(IgnoreNone) 68 , m_hideTimerBehaviorFlags(IgnoreNone)
69 , m_isMouseOverControls(false) 69 , m_isMouseOverControls(false)
70 , m_isPausedForScrubbing(false) 70 , m_isPausedForScrubbing(false)
71 , m_panelWidthChangedTimer(this, &MediaControls::panelWidthChangedTimerFired )
72 , m_panelWidth(0)
71 { 73 {
72 } 74 }
73 75
74 PassRefPtrWillBeRawPtr<MediaControls> MediaControls::create(HTMLMediaElement& me diaElement) 76 PassRefPtrWillBeRawPtr<MediaControls> MediaControls::create(HTMLMediaElement& me diaElement)
75 { 77 {
76 RefPtrWillBeRawPtr<MediaControls> controls = adoptRefWillBeNoop(new MediaCon trols(mediaElement)); 78 RefPtrWillBeRawPtr<MediaControls> controls = adoptRefWillBeNoop(new MediaCon trols(mediaElement));
77 controls->setShadowPseudoId(AtomicString("-webkit-media-controls", AtomicStr ing::ConstructFromLiteral)); 79 controls->setShadowPseudoId(AtomicString("-webkit-media-controls", AtomicStr ing::ConstructFromLiteral));
78 controls->initializeControls(); 80 controls->initializeControls();
79 return controls.release(); 81 return controls.release();
80 } 82 }
81 83
82 // The media controls DOM structure looks like: 84 // The media controls DOM structure looks like:
83 // 85 //
84 // MediaControls (-webkit-media-controls) 86 // MediaControls (-webkit-media-controls)
85 // +-MediaControlOverlayEnclosureElement (-webkit-media-controls-o verlay-enclosure) 87 // +-MediaControlOverlayEnclosureElement (-webkit-media-controls-o verlay-enclosure)
86 // | +-MediaControlOverlayPlayButtonElement (-webkit-media-controls-o verlay-play-button) 88 // | +-MediaControlOverlayPlayButtonElement (-webkit-media-controls-o verlay-play-button)
87 // | | {if mediaControlsOverlayPlayButtonEnabled} 89 // | | {if mediaControlsOverlayPlayButtonEnabled}
88 // | \-MediaControlCastButtonElement (-internal-media-controls -overlay-cast-button) 90 // | \-MediaControlCastButtonElement (-internal-media-controls -overlay-cast-button)
89 // \-MediaControlPanelEnclosureElement (-webkit-media-controls-e nclosure) 91 // \-MediaControlPanelEnclosureElement (-webkit-media-controls-e nclosure)
90 // \-MediaControlPanelElement (-webkit-media-controls-p anel) 92 // \-MediaControlPanelElement (-webkit-media-controls-p anel)
91 // +-MediaControlPlayButtonElement (-webkit-media-controls-p lay-button) 93 // +-MediaControlPlayButtonElement (-webkit-media-controls-p lay-button)
92 // +-MediaControlTimelineElement (-webkit-media-controls-t imeline) 94 // +-MediaControlTimelineElement (-webkit-media-controls-t imeline) (if !RTE::newMediaPlaybackUi())
philipj_slow 2015/07/09 08:56:10 Can you use the same style as the above {if mediaC
liberato (no reviews please) 2015/07/09 22:35:34 done. didn't realize that's what it meant.
philipj_slow 2015/07/09 23:18:37 fs pulled the syntax out of a hat, and I just like
93 // +-MediaControlCurrentTimeDisplayElement (-webkit-media-controls-c urrent-time-display) 95 // +-MediaControlCurrentTimeDisplayElement (-webkit-media-controls-c urrent-time-display)
94 // +-MediaControlTimeRemainingDisplayElement (-webkit-media-controls-t ime-remaining-display) 96 // +-MediaControlTimeRemainingDisplayElement (-webkit-media-controls-t ime-remaining-display)
97 // +-MediaControlTimelineElement (-webkit-media-controls-t imeline) (if RTE::newMediaPlaybackUi())
95 // +-MediaControlMuteButtonElement (-webkit-media-controls-m ute-button) 98 // +-MediaControlMuteButtonElement (-webkit-media-controls-m ute-button)
96 // +-MediaControlVolumeSliderElement (-webkit-media-controls-v olume-slider) 99 // +-MediaControlVolumeSliderElement (-webkit-media-controls-v olume-slider)
97 // +-MediaControlToggleClosedCaptionsButtonElement (-webkit-media-controls-t oggle-closed-captions-button) 100 // +-MediaControlToggleClosedCaptionsButtonElement (-webkit-media-controls-t oggle-closed-captions-button)
98 // +-MediaControlCastButtonElement (-internal-media-controls -cast-button) 101 // +-MediaControlCastButtonElement (-internal-media-controls -cast-button)
99 // \-MediaControlFullscreenButtonElement (-webkit-media-controls-f ullscreen-button) 102 // \-MediaControlFullscreenButtonElement (-webkit-media-controls-f ullscreen-button)
100 void MediaControls::initializeControls() 103 void MediaControls::initializeControls()
101 { 104 {
102 RefPtrWillBeRawPtr<MediaControlOverlayEnclosureElement> overlayEnclosure = M ediaControlOverlayEnclosureElement::create(*this); 105 RefPtrWillBeRawPtr<MediaControlOverlayEnclosureElement> overlayEnclosure = M ediaControlOverlayEnclosureElement::create(*this);
103 106
104 if (document().settings() && document().settings()->mediaControlsOverlayPlay ButtonEnabled()) { 107 if (document().settings() && document().settings()->mediaControlsOverlayPlay ButtonEnabled()) {
(...skipping 13 matching lines...) Expand all
118 RefPtrWillBeRawPtr<MediaControlPanelEnclosureElement> enclosure = MediaContr olPanelEnclosureElement::create(*this); 121 RefPtrWillBeRawPtr<MediaControlPanelEnclosureElement> enclosure = MediaContr olPanelEnclosureElement::create(*this);
119 122
120 RefPtrWillBeRawPtr<MediaControlPanelElement> panel = MediaControlPanelElemen t::create(*this); 123 RefPtrWillBeRawPtr<MediaControlPanelElement> panel = MediaControlPanelElemen t::create(*this);
121 124
122 RefPtrWillBeRawPtr<MediaControlPlayButtonElement> playButton = MediaControlP layButtonElement::create(*this); 125 RefPtrWillBeRawPtr<MediaControlPlayButtonElement> playButton = MediaControlP layButtonElement::create(*this);
123 m_playButton = playButton.get(); 126 m_playButton = playButton.get();
124 panel->appendChild(playButton.release()); 127 panel->appendChild(playButton.release());
125 128
126 RefPtrWillBeRawPtr<MediaControlTimelineElement> timeline = MediaControlTimel ineElement::create(*this); 129 RefPtrWillBeRawPtr<MediaControlTimelineElement> timeline = MediaControlTimel ineElement::create(*this);
127 m_timeline = timeline.get(); 130 m_timeline = timeline.get();
128 panel->appendChild(timeline.release()); 131 // In old UX, timeline is before the time / duration text.
132 if (!RuntimeEnabledFeatures::newMediaPlaybackUiEnabled())
philipj_slow 2015/07/09 08:56:10 Break out this into a local variable like in ::res
liberato (no reviews please) 2015/07/09 22:35:34 Done.
133 panel->appendChild(timeline.release());
134 // else we will attach it later.
129 135
130 RefPtrWillBeRawPtr<MediaControlCurrentTimeDisplayElement> currentTimeDisplay = MediaControlCurrentTimeDisplayElement::create(*this); 136 RefPtrWillBeRawPtr<MediaControlCurrentTimeDisplayElement> currentTimeDisplay = MediaControlCurrentTimeDisplayElement::create(*this);
131 m_currentTimeDisplay = currentTimeDisplay.get(); 137 m_currentTimeDisplay = currentTimeDisplay.get();
132 m_currentTimeDisplay->hide(); 138 if (!RuntimeEnabledFeatures::newMediaPlaybackUiEnabled())
philipj_slow 2015/07/09 08:56:10 Transform this into a single setIsWanted() call.
liberato (no reviews please) 2015/07/09 22:35:34 Done.
139 m_currentTimeDisplay->setIsWanted(false);
140 else
141 m_currentTimeDisplay->setIsWanted(true);
142
133 panel->appendChild(currentTimeDisplay.release()); 143 panel->appendChild(currentTimeDisplay.release());
134 144
135 RefPtrWillBeRawPtr<MediaControlTimeRemainingDisplayElement> durationDisplay = MediaControlTimeRemainingDisplayElement::create(*this); 145 RefPtrWillBeRawPtr<MediaControlTimeRemainingDisplayElement> durationDisplay = MediaControlTimeRemainingDisplayElement::create(*this);
136 m_durationDisplay = durationDisplay.get(); 146 m_durationDisplay = durationDisplay.get();
137 panel->appendChild(durationDisplay.release()); 147 panel->appendChild(durationDisplay.release());
138 148
149 // In new UX, timeline is after the time / duration text.
150 if (RuntimeEnabledFeatures::newMediaPlaybackUiEnabled())
151 panel->appendChild(timeline.release());
152
139 RefPtrWillBeRawPtr<MediaControlMuteButtonElement> muteButton = MediaControlM uteButtonElement::create(*this); 153 RefPtrWillBeRawPtr<MediaControlMuteButtonElement> muteButton = MediaControlM uteButtonElement::create(*this);
140 m_muteButton = muteButton.get(); 154 m_muteButton = muteButton.get();
141 panel->appendChild(muteButton.release()); 155 panel->appendChild(muteButton.release());
156 #if OS(ANDROID)
philipj_slow 2015/07/09 08:56:10 Is this actually needed? Should work the same if d
liberato (no reviews please) 2015/07/09 12:10:57 since we unhide mute to handle the 'media starts m
157 if (RuntimeEnabledFeatures::newMediaPlaybackUiEnabled())
158 m_muteButton->setIsWanted(false);
159 #endif
142 160
143 RefPtrWillBeRawPtr<MediaControlVolumeSliderElement> slider = MediaControlVol umeSliderElement::create(*this); 161 RefPtrWillBeRawPtr<MediaControlVolumeSliderElement> slider = MediaControlVol umeSliderElement::create(*this);
144 m_volumeSlider = slider.get(); 162 m_volumeSlider = slider.get();
145 panel->appendChild(slider.release()); 163 panel->appendChild(slider.release());
164 #if OS(ANDROID)
165 if (RuntimeEnabledFeatures::newMediaPlaybackUiEnabled())
166 m_volumeSlider->setIsWanted(false);
167 #endif
146 168
147 RefPtrWillBeRawPtr<MediaControlToggleClosedCaptionsButtonElement> toggleClos edCaptionsButton = MediaControlToggleClosedCaptionsButtonElement::create(*this); 169 RefPtrWillBeRawPtr<MediaControlToggleClosedCaptionsButtonElement> toggleClos edCaptionsButton = MediaControlToggleClosedCaptionsButtonElement::create(*this);
148 m_toggleClosedCaptionsButton = toggleClosedCaptionsButton.get(); 170 m_toggleClosedCaptionsButton = toggleClosedCaptionsButton.get();
149 panel->appendChild(toggleClosedCaptionsButton.release()); 171 panel->appendChild(toggleClosedCaptionsButton.release());
150 172
151 RefPtrWillBeRawPtr<MediaControlCastButtonElement> castButton = MediaControlC astButtonElement::create(*this, false); 173 RefPtrWillBeRawPtr<MediaControlCastButtonElement> castButton = MediaControlC astButtonElement::create(*this, false);
152 m_castButton = castButton.get(); 174 m_castButton = castButton.get();
153 panel->appendChild(castButton.release()); 175 panel->appendChild(castButton.release());
154 176
155 RefPtrWillBeRawPtr<MediaControlFullscreenButtonElement> fullscreenButton = M ediaControlFullscreenButtonElement::create(*this); 177 RefPtrWillBeRawPtr<MediaControlFullscreenButtonElement> fullscreenButton = M ediaControlFullscreenButtonElement::create(*this);
156 m_fullScreenButton = fullscreenButton.get(); 178 m_fullScreenButton = fullscreenButton.get();
157 panel->appendChild(fullscreenButton.release()); 179 panel->appendChild(fullscreenButton.release());
158 180
159 m_panel = panel.get(); 181 m_panel = panel.get();
160 enclosure->appendChild(panel.release()); 182 enclosure->appendChild(panel.release());
161 183
162 m_enclosure = enclosure.get(); 184 m_enclosure = enclosure.get();
163 appendChild(enclosure.release()); 185 appendChild(enclosure.release());
164 } 186 }
165 187
166 void MediaControls::reset() 188 void MediaControls::reset()
167 { 189 {
190 const bool useNewUi = RuntimeEnabledFeatures::newMediaPlaybackUiEnabled();
philipj_slow 2015/07/09 08:56:10 Also make duration const if you prefer that. (If y
liberato (no reviews please) 2015/07/09 12:10:57 i've always assumed that it's a note to myself mor
168 double duration = mediaElement().duration(); 191 double duration = mediaElement().duration();
169 m_durationDisplay->setInnerText(LayoutTheme::theme().formatMediaControlsTime (duration), ASSERT_NO_EXCEPTION); 192 m_durationDisplay->setInnerText(LayoutTheme::theme().formatMediaControlsTime (duration), ASSERT_NO_EXCEPTION);
170 m_durationDisplay->setCurrentValue(duration); 193 m_durationDisplay->setCurrentValue(duration);
171 194
195 if (useNewUi) {
196 // Show everything that we might hide.
197 // If we don't have a duration, then mark it to be hidden. For the
198 // old UI case, want / don't want is the same as show / hide since
199 // it is never marked as not fitting.
200 if (std::isfinite(duration))
201 m_durationDisplay->setIsWanted(true);
202 else
203 m_durationDisplay->setIsWanted(false);
204 m_currentTimeDisplay->setIsWanted(true);
205 m_timeline->setIsWanted(true);
206 }
207
172 updatePlayState(); 208 updatePlayState();
173 209
174 updateCurrentTimeDisplay(); 210 updateCurrentTimeDisplay();
175 211
176 m_timeline->setDuration(duration); 212 m_timeline->setDuration(duration);
177 m_timeline->setPosition(mediaElement().currentTime()); 213 m_timeline->setPosition(mediaElement().currentTime());
178 214
179 if (!mediaElement().hasAudio()) 215 if (!mediaElement().hasAudio()) {
180 m_volumeSlider->hide(); 216 m_volumeSlider->setIsWanted(false);
philipj_slow 2015/07/09 08:56:10 Ditto.
liberato (no reviews please) 2015/07/09 22:35:34 this one always ends up worse with the #ifdef.
philipj_slow 2015/07/09 23:18:37 Oh, here it wasn't actually m_volumeSlider and m_m
181 else 217 if (useNewUi)
182 m_volumeSlider->show(); 218 m_muteButton->setIsWanted(false);
219 } else {
220 #if OS(ANDROID)
philipj_slow 2015/07/09 08:56:10 Should also be possible to do with just CSS.
liberato (no reviews please) 2015/07/09 22:35:34 true, but this way it's all in one spot. otherwis
philipj_slow 2015/07/09 23:18:37 Oh, so before it was always an option to hide usin
liberato (no reviews please) 2015/07/10 07:20:30 i've added settings()->preferHidden{VolumeSlider,
221 // New UI always hides the volume slider on Android.
222 if (useNewUi)
223 m_volumeSlider->setIsWanted(false);
philipj_slow 2015/07/09 08:56:10 Ditto.
liberato (no reviews please) 2015/07/09 22:35:33 Done.
224 else
225 m_volumeSlider->setIsWanted(true);
226 #else
227 m_volumeSlider->setIsWanted(true);
228 m_muteButton->setIsWanted(true);
229 #endif
230 }
231
183 updateVolume(); 232 updateVolume();
184 233
185 refreshClosedCaptionsButtonVisibility(); 234 refreshClosedCaptionsButtonVisibility();
186 235
187 // Unconditionally allow the user to exit fullscreen if we are in it 236 // Unconditionally allow the user to exit fullscreen if we are in it
188 // now. Especially on android, when we might not yet know if 237 // now. Especially on android, when we might not yet know if
189 // fullscreen is supported, we sometimes guess incorrectly and show 238 // fullscreen is supported, we sometimes guess incorrectly and show
190 // the button earlier, and we don't want to remove it here if the 239 // the button earlier, and we don't want to remove it here if the
191 // user chose to enter fullscreen. crbug.com/500732 . 240 // user chose to enter fullscreen. crbug.com/500732 .
192 if ((mediaElement().hasVideo() && fullscreenIsSupported(document())) 241 if ((mediaElement().hasVideo() && fullscreenIsSupported(document()))
193 || mediaElement().isFullscreen()) 242 || mediaElement().isFullscreen()) {
194 m_fullScreenButton->show(); 243 m_fullScreenButton->setIsWanted(true);
philipj_slow 2015/07/09 08:56:10 Ditto.
liberato (no reviews please) 2015/07/09 22:35:34 done.
195 else 244 } else {
196 m_fullScreenButton->hide(); 245 m_fullScreenButton->setIsWanted(false);
246 }
197 247
198 refreshCastButtonVisibility(); 248 refreshCastButtonVisibilityWithoutUpdate();
199 makeOpaque(); 249 makeOpaque();
250 changedControlSelections();
200 } 251 }
201 252
202 LayoutObject* MediaControls::layoutObjectForTextTrackLayout() 253 LayoutObject* MediaControls::layoutObjectForTextTrackLayout()
203 { 254 {
204 return m_panel->layoutObject(); 255 return m_panel->layoutObject();
205 } 256 }
206 257
207 void MediaControls::show() 258 void MediaControls::show()
208 { 259 {
209 makeOpaque(); 260 makeOpaque();
210 m_panel->show(); 261 m_panel->setIsWanted(true);
211 m_panel->setIsDisplayed(true); 262 m_panel->setIsDisplayed(true);
212 if (m_overlayPlayButton) 263 if (m_overlayPlayButton)
213 m_overlayPlayButton->updateDisplayType(); 264 m_overlayPlayButton->updateDisplayType();
214 } 265 }
215 266
216 void MediaControls::mediaElementFocused() 267 void MediaControls::mediaElementFocused()
217 { 268 {
218 if (mediaElement().shouldShowControls()) { 269 if (mediaElement().shouldShowControls()) {
219 show(); 270 show();
220 resetHideMediaControlsTimer(); 271 resetHideMediaControlsTimer();
221 } 272 }
222 } 273 }
223 274
224 void MediaControls::hide() 275 void MediaControls::hide()
225 { 276 {
226 m_panel->hide(); 277 m_panel->setIsWanted(false);
227 m_panel->setIsDisplayed(false); 278 m_panel->setIsDisplayed(false);
228 if (m_overlayPlayButton) 279 if (m_overlayPlayButton)
229 m_overlayPlayButton->hide(); 280 m_overlayPlayButton->setIsWanted(false);
230 } 281 }
231 282
232 void MediaControls::makeOpaque() 283 void MediaControls::makeOpaque()
233 { 284 {
234 m_panel->makeOpaque(); 285 m_panel->makeOpaque();
235 } 286 }
236 287
237 void MediaControls::makeTransparent() 288 void MediaControls::makeTransparent()
238 { 289 {
239 m_panel->makeTransparent(); 290 m_panel->makeTransparent();
(...skipping 16 matching lines...) Expand all
256 // controls/shadow tree. (Perform the checks separately to avoid going 307 // controls/shadow tree. (Perform the checks separately to avoid going
257 // through all the potential ancestor hosts for the focused element.) 308 // through all the potential ancestor hosts for the focused element.)
258 const bool ignoreFocus = behaviorFlags & IgnoreFocus; 309 const bool ignoreFocus = behaviorFlags & IgnoreFocus;
259 if (!ignoreFocus && (mediaElement().focused() || contains(document().focused Element()))) 310 if (!ignoreFocus && (mediaElement().focused() || contains(document().focused Element())))
260 return false; 311 return false;
261 return true; 312 return true;
262 } 313 }
263 314
264 void MediaControls::playbackStarted() 315 void MediaControls::playbackStarted()
265 { 316 {
266 m_currentTimeDisplay->show(); 317 if (!RuntimeEnabledFeatures::newMediaPlaybackUiEnabled()) {
267 m_durationDisplay->hide(); 318 m_currentTimeDisplay->setIsWanted(true);
319 m_durationDisplay->setIsWanted(false);
320 }
268 321
269 updatePlayState(); 322 updatePlayState();
270 m_timeline->setPosition(mediaElement().currentTime()); 323 m_timeline->setPosition(mediaElement().currentTime());
271 updateCurrentTimeDisplay(); 324 updateCurrentTimeDisplay();
272 325
273 startHideMediaControlsTimer(); 326 startHideMediaControlsTimer();
274 } 327 }
275 328
276 void MediaControls::playbackProgressed() 329 void MediaControls::playbackProgressed()
277 { 330 {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 mediaElement().togglePlayState(); 371 mediaElement().togglePlayState();
319 } 372 }
320 } 373 }
321 374
322 void MediaControls::updateCurrentTimeDisplay() 375 void MediaControls::updateCurrentTimeDisplay()
323 { 376 {
324 double now = mediaElement().currentTime(); 377 double now = mediaElement().currentTime();
325 double duration = mediaElement().duration(); 378 double duration = mediaElement().duration();
326 379
327 // After seek, hide duration display and show current time. 380 // After seek, hide duration display and show current time.
328 if (now > 0) { 381 if (!RuntimeEnabledFeatures::newMediaPlaybackUiEnabled() && now > 0) {
329 m_currentTimeDisplay->show(); 382 m_currentTimeDisplay->setIsWanted(true);
330 m_durationDisplay->hide(); 383 m_durationDisplay->setIsWanted(false);
331 } 384 }
332 385
333 // Allow the theme to format the time. 386 // Allow the theme to format the time.
334 m_currentTimeDisplay->setInnerText(LayoutTheme::theme().formatMediaControlsC urrentTime(now, duration), IGNORE_EXCEPTION); 387 m_currentTimeDisplay->setInnerText(LayoutTheme::theme().formatMediaControlsC urrentTime(now, duration), IGNORE_EXCEPTION);
335 m_currentTimeDisplay->setCurrentValue(now); 388 m_currentTimeDisplay->setCurrentValue(now);
336 } 389 }
337 390
338 void MediaControls::updateVolume() 391 void MediaControls::updateVolume()
339 { 392 {
340 m_muteButton->updateDisplayType(); 393 m_muteButton->updateDisplayType();
341 // Invalidate the mute button because it paints differently according to vol ume. 394 // Invalidate the mute button because it paints differently according to vol ume.
342 if (LayoutObject* layoutObject = m_muteButton->layoutObject()) 395 if (LayoutObject* layoutObject = m_muteButton->layoutObject())
343 layoutObject->setShouldDoFullPaintInvalidation(); 396 layoutObject->setShouldDoFullPaintInvalidation();
344 397
345 if (mediaElement().muted()) 398 if (mediaElement().muted()) {
346 m_volumeSlider->setVolume(0); 399 m_volumeSlider->setVolume(0);
347 else 400 // If the element is muted, then we want the unmute button. Otherwise,
philipj_slow 2015/07/09 08:56:11 I think that if we're going to change anything abo
liberato (no reviews please) 2015/07/09 22:35:34 the latter one seems almost exactly what the code
philipj_slow 2015/07/09 23:18:36 FWIW, we unmute when pressing the overlay fullscre
liberato (no reviews please) 2015/07/14 22:10:36 added LayoutTests/media/video-controls-hidden-audi
401 // one can't unmute it. This makes a difference on android, where we
402 // hide the mute button by default. crbug.com/467252 .
403 if (mediaElement().hasAudio()) {
404 m_muteButton->setIsWanted(true);
405 }
406 } else {
348 m_volumeSlider->setVolume(mediaElement().volume()); 407 m_volumeSlider->setVolume(mediaElement().volume());
408 }
409
349 // Invalidate the volume slider because it paints differently according to v olume. 410 // Invalidate the volume slider because it paints differently according to v olume.
350 if (LayoutObject* layoutObject = m_volumeSlider->layoutObject()) 411 if (LayoutObject* layoutObject = m_volumeSlider->layoutObject())
351 layoutObject->setShouldDoFullPaintInvalidation(); 412 layoutObject->setShouldDoFullPaintInvalidation();
352 } 413 }
353 414
354 void MediaControls::changedClosedCaptionsVisibility() 415 void MediaControls::changedClosedCaptionsVisibility()
355 { 416 {
356 m_toggleClosedCaptionsButton->updateDisplayType(); 417 m_toggleClosedCaptionsButton->updateDisplayType();
357 } 418 }
358 419
359 void MediaControls::refreshClosedCaptionsButtonVisibility() 420 void MediaControls::refreshClosedCaptionsButtonVisibility()
360 { 421 {
361 if (mediaElement().hasClosedCaptions()) 422 if (mediaElement().hasClosedCaptions())
362 m_toggleClosedCaptionsButton->show(); 423 m_toggleClosedCaptionsButton->setIsWanted(true);
philipj_slow 2015/07/09 08:56:11 Ditto.
liberato (no reviews please) 2015/07/09 22:35:34 Done.
363 else 424 else
364 m_toggleClosedCaptionsButton->hide(); 425 m_toggleClosedCaptionsButton->setIsWanted(false);
365 } 426 }
366 427
367 static Element* elementFromCenter(Element& element) 428 static Element* elementFromCenter(Element& element)
368 { 429 {
369 ClientRect* clientRect = element.getBoundingClientRect(); 430 ClientRect* clientRect = element.getBoundingClientRect();
370 int centerX = static_cast<int>((clientRect->left() + clientRect->right()) / 2); 431 int centerX = static_cast<int>((clientRect->left() + clientRect->right()) / 2);
371 int centerY = static_cast<int>((clientRect->top() + clientRect->bottom()) / 2); 432 int centerY = static_cast<int>((clientRect->top() + clientRect->bottom()) / 2);
372 433
373 return element.document().elementFromPoint(centerX , centerY); 434 return element.document().elementFromPoint(centerX , centerY);
374 } 435 }
375 436
376 void MediaControls::tryShowOverlayCastButton() 437 void MediaControls::tryShowOverlayCastButton()
377 { 438 {
378 // The element needs to be shown to have its dimensions and position. 439 // The element needs to be shown to have its dimensions and position.
379 m_overlayCastButton->show(); 440 m_overlayCastButton->setIsWanted(true);
380 441
381 if (elementFromCenter(*m_overlayCastButton) != &mediaElement()) 442 if (elementFromCenter(*m_overlayCastButton) != &mediaElement())
382 m_overlayCastButton->hide(); 443 m_overlayCastButton->setIsWanted(false);
383 } 444 }
384 445
385 void MediaControls::refreshCastButtonVisibility() 446 void MediaControls::refreshCastButtonVisibility()
386 { 447 {
448 refreshCastButtonVisibilityWithoutUpdate();
449 changedControlSelections();
450 }
451
452 void MediaControls::hideCastButtons()
453 {
454 m_castButton->setIsWanted(false);
455 m_overlayCastButton->setIsWanted(false);
456 }
457
458 void MediaControls::refreshCastButtonVisibilityWithoutUpdate()
459 {
387 if (mediaElement().hasRemoteRoutes()) { 460 if (mediaElement().hasRemoteRoutes()) {
388 // The reason for the autoplay test is that some pages (e.g. vimeo.com) have an autoplay background video, which 461 // The reason for the autoplay test is that some pages (e.g. vimeo.com) have an autoplay background video, which
389 // doesn't autoplay on Chrome for Android (we prevent it) so starts paus ed. In such cases we don't want to automatically 462 // doesn't autoplay on Chrome for Android (we prevent it) so starts paus ed. In such cases we don't want to automatically
390 // show the cast button, since it looks strange and is unlikely to corre spond with anything the user wants to do. 463 // show the cast button, since it looks strange and is unlikely to corre spond with anything the user wants to do.
391 // If a user does want to cast a paused autoplay video then they can sti ll do so by touching or clicking on the 464 // If a user does want to cast a paused autoplay video then they can sti ll do so by touching or clicking on the
392 // video, which will cause the cast button to appear. 465 // video, which will cause the cast button to appear.
393 if (!mediaElement().shouldShowControls() && !mediaElement().autoplay() & & mediaElement().paused()) { 466 if (!mediaElement().shouldShowControls() && !mediaElement().autoplay() & & mediaElement().paused()) {
467 // Note that this is a case where we add the overlay cast button
468 // without wanting the bar cast button. We depend on the fact
philipj_slow 2015/07/09 08:56:10 s/bar/panel/ or "the button in the controls panel"
liberato (no reviews please) 2015/07/09 22:35:33 expanded comment.
469 // that updateControls...() won't change overlay cast button
470 // visibility in the case where the cast button isn't wanted.
394 showOverlayCastButton(); 471 showOverlayCastButton();
472 m_castButton->setIsWanted(false);
philipj_slow 2015/07/09 08:56:10 The mismatch between showOverlayCastButton() and m
liberato (no reviews please) 2015/07/09 22:35:34 yeah, i agree. changed.
liberato (no reviews please) 2015/07/14 22:10:36 it turns out that the right answer is tryShowOverl
395 } else if (mediaElement().shouldShowControls()) { 473 } else if (mediaElement().shouldShowControls()) {
396 m_overlayCastButton->hide(); 474 m_overlayCastButton->setIsWanted(false);
397 m_castButton->show(); 475 m_castButton->setIsWanted(true);
398 // Check that the cast button actually fits on the bar. 476 // Check that the cast button actually fits on the bar. For the
399 if (m_fullScreenButton->getBoundingClientRect()->right() > m_panel-> getBoundingClientRect()->right()) { 477 // new ui, we let changedControlSelections() handle this.
400 m_castButton->hide(); 478 if ( !RuntimeEnabledFeatures::newMediaPlaybackUiEnabled()
479 && m_fullScreenButton->getBoundingClientRect()->right() > m_pane l->getBoundingClientRect()->right()) {
480 m_castButton->setIsWanted(false);
401 tryShowOverlayCastButton(); 481 tryShowOverlayCastButton();
402 } 482 }
403 } 483 }
404 } else { 484 } else {
405 m_castButton->hide(); 485 m_castButton->setIsWanted(false);
406 m_overlayCastButton->hide(); 486 m_overlayCastButton->setIsWanted(false);
407 } 487 }
488
489 // do NOT updateControls...() here.
philipj_slow 2015/07/09 08:56:11 This comment isn't needed IMHO.
liberato (no reviews please) 2015/07/09 22:35:34 Done.
408 } 490 }
409 491
410 void MediaControls::showOverlayCastButton() 492 void MediaControls::showOverlayCastButton()
411 { 493 {
412 tryShowOverlayCastButton(); 494 tryShowOverlayCastButton();
413 resetHideMediaControlsTimer(); 495 resetHideMediaControlsTimer();
414 } 496 }
415 497
416 void MediaControls::enteredFullscreen() 498 void MediaControls::enteredFullscreen()
417 { 499 {
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
487 unsigned behaviorFlags = m_hideTimerBehaviorFlags | IgnoreFocus | IgnoreVide oHover; 569 unsigned behaviorFlags = m_hideTimerBehaviorFlags | IgnoreFocus | IgnoreVide oHover;
488 m_hideTimerBehaviorFlags = IgnoreNone; 570 m_hideTimerBehaviorFlags = IgnoreNone;
489 571
490 if (mediaElement().togglePlayStateWillPlay()) 572 if (mediaElement().togglePlayStateWillPlay())
491 return; 573 return;
492 574
493 if (!shouldHideMediaControls(behaviorFlags)) 575 if (!shouldHideMediaControls(behaviorFlags))
494 return; 576 return;
495 577
496 makeTransparent(); 578 makeTransparent();
497 m_overlayCastButton->hide(); 579 m_overlayCastButton->setIsWanted(false);
498 } 580 }
499 581
500 void MediaControls::startHideMediaControlsTimer() 582 void MediaControls::startHideMediaControlsTimer()
501 { 583 {
502 m_hideMediaControlsTimer.startOneShot(timeWithoutMouseMovementBeforeHidingMe diaControls, FROM_HERE); 584 m_hideMediaControlsTimer.startOneShot(timeWithoutMouseMovementBeforeHidingMe diaControls, FROM_HERE);
503 } 585 }
504 586
505 void MediaControls::stopHideMediaControlsTimer() 587 void MediaControls::stopHideMediaControlsTimer()
506 { 588 {
507 m_hideMediaControlsTimer.stop(); 589 m_hideMediaControlsTimer.stop();
(...skipping 10 matching lines...) Expand all
518 bool MediaControls::containsRelatedTarget(Event* event) 600 bool MediaControls::containsRelatedTarget(Event* event)
519 { 601 {
520 if (!event->isMouseEvent()) 602 if (!event->isMouseEvent())
521 return false; 603 return false;
522 EventTarget* relatedTarget = toMouseEvent(event)->relatedTarget(); 604 EventTarget* relatedTarget = toMouseEvent(event)->relatedTarget();
523 if (!relatedTarget) 605 if (!relatedTarget)
524 return false; 606 return false;
525 return contains(relatedTarget->toNode()); 607 return contains(relatedTarget->toNode());
526 } 608 }
527 609
610 void MediaControls::notifyPanelWidthChanged(int panelWidth)
611 {
612 // Don't bother to do any work if this matches the most recent panel
613 // width, since we're called after layout.
614 if (panelWidth == 0 || panelWidth == m_panelWidth)
philipj_slow 2015/07/09 08:56:10 Shouldn't m_panelWidth still be updated? Seems sim
fs 2015/07/09 09:31:17 Yeah, if checking this at all, it's probably bette
liberato (no reviews please) 2015/07/09 12:10:56 i can remove the check here safely, but i can't ad
615 return;
616
617 m_panelWidth = panelWidth;
618 m_panelWidthChangedTimer.startOneShot(0, FROM_HERE);
philipj_slow 2015/07/09 08:56:10 Given that this is called from LayoutMedia::layout
fs 2015/07/09 09:31:17 Correct on both accounts AFAIK.
liberato (no reviews please) 2015/07/09 12:10:57 to be clear: i'm about to go spelunking into layou
fs 2015/07/09 12:25:39 Well, it's essentially a QoI issue - there could (
philipj_slow 2015/07/10 14:51:58 So let's add a TODO that acknowledges that there's
liberato (no reviews please) 2015/07/14 22:10:36 Done.
619 }
620
621 void MediaControls::changedControlSelections()
622 {
623 int panelWidth = m_panel->clientWidth();
philipj_slow 2015/07/09 08:56:11 This may trigger a layout, is that intentional? It
liberato (no reviews please) 2015/07/09 22:35:34 i expected that it would avoid a bad frame, but tr
624 // Don't short-circuit update if the panel hasn't changed. The fit state
625 // is a function of the controls we want, so recompute if we can.
626 if (panelWidth == 0)
627 return;
628
629 m_panelWidth = panelWidth;
630 computeWhichControlsFit(panelWidth);
631 }
632
633 void MediaControls::panelWidthChangedTimerFired(Timer<MediaControls>*)
634 {
635 if (!m_panelWidth)
636 return;
637
638 computeWhichControlsFit(m_panelWidth);
639 }
640
641 void MediaControls::computeWhichControlsFit(int panelWidth)
philipj_slow 2015/07/09 08:56:10 Seems like this doesn't need an argument, use m_pa
liberato (no reviews please) 2015/07/09 22:35:33 yeah, i had the same thought. i did it this way s
liberato (no reviews please) 2015/07/14 22:10:36 this does cause an extra bad frame, so i've left i
642 {
643 // Hide all controls that don't fit, and show the ones that do.
644 // This might be better suited for a layout, but since JS media controls
645 // won't benefit from that anwyay, we just do it here like JS will.
646 // The order, in order of decreasing droppiness:
647 // Volume, time, seek bar, cast.
648
649 // Controls that we'll hide / show, in order of decreasing priority.
650 MediaControlElement* elements[] = {
651 m_playButton.get(),
652 m_toggleClosedCaptionsButton.get(),
653 m_fullScreenButton.get(),
654 m_timeline.get(),
655 m_currentTimeDisplay.get(),
656 m_volumeSlider.get(),
657 m_castButton.get(),
658 m_muteButton.get(),
659 m_durationDisplay.get(),
660 0
661 };
662
663 int usedWidth = 0;
664 for (int i = 0; elements[i]; i++) {
philipj_slow 2015/07/09 08:56:10 for (MediaControlElement* element : elements) at l
liberato (no reviews please) 2015/07/09 22:35:34 done, cool.
665 if (elements[i]->isWanted()) {
666 if (usedWidth + elements[i]->minimumWidth() <= panelWidth) {
667 elements[i]->setDoesFit(true);
668 usedWidth += elements[i]->minimumWidth();
669 } else {
670 elements[i]->setDoesFit(false);
671 }
672 }
673 }
674
675 // Special case for cast: if we want a cast button but dropped it, then
676 // show the overlay cast button instead.
677 if (m_castButton->isWanted()) {
678 if (!m_castButton->isShown())
philipj_slow 2015/07/09 08:56:10 I think this and above are the only places where i
liberato (no reviews please) 2015/07/09 22:35:33 i've removed isShown(), but i don't see how to rem
philipj_slow 2015/07/09 23:18:37 Uh right, the loop above is also using isWanted(),
679 m_overlayCastButton->setIsWanted(true);
680 else
681 m_overlayCastButton->setIsWanted(false);
682 } // else do not change overlay cast button state.
philipj_slow 2015/07/09 08:56:11 Don't need this comment.
liberato (no reviews please) 2015/07/09 22:35:34 Done.
683 }
684
528 DEFINE_TRACE(MediaControls) 685 DEFINE_TRACE(MediaControls)
529 { 686 {
530 visitor->trace(m_mediaElement); 687 visitor->trace(m_mediaElement);
531 visitor->trace(m_panel); 688 visitor->trace(m_panel);
532 visitor->trace(m_overlayPlayButton); 689 visitor->trace(m_overlayPlayButton);
533 visitor->trace(m_overlayEnclosure); 690 visitor->trace(m_overlayEnclosure);
534 visitor->trace(m_playButton); 691 visitor->trace(m_playButton);
535 visitor->trace(m_currentTimeDisplay); 692 visitor->trace(m_currentTimeDisplay);
536 visitor->trace(m_timeline); 693 visitor->trace(m_timeline);
537 visitor->trace(m_muteButton); 694 visitor->trace(m_muteButton);
538 visitor->trace(m_volumeSlider); 695 visitor->trace(m_volumeSlider);
539 visitor->trace(m_toggleClosedCaptionsButton); 696 visitor->trace(m_toggleClosedCaptionsButton);
540 visitor->trace(m_fullScreenButton); 697 visitor->trace(m_fullScreenButton);
541 visitor->trace(m_durationDisplay); 698 visitor->trace(m_durationDisplay);
542 visitor->trace(m_enclosure); 699 visitor->trace(m_enclosure);
543 visitor->trace(m_castButton); 700 visitor->trace(m_castButton);
544 visitor->trace(m_overlayCastButton); 701 visitor->trace(m_overlayCastButton);
545 HTMLDivElement::trace(visitor); 702 HTMLDivElement::trace(visitor);
546 } 703 }
547 704
548 } 705 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698