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

Side by Side Diff: Source/core/html/HTMLMediaElement.cpp

Issue 949203002: Separate the text track container from the media controls (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: address nits Created 5 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/css/mediaControls.css ('k') | Source/core/html/shadow/MediaControls.h » ('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) 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights reserved. 2 * Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 3165 matching lines...) Expand 10 before | Expand all | Expand 10 after
3176 } 3176 }
3177 } 3177 }
3178 return false; 3178 return false;
3179 } 3179 }
3180 3180
3181 bool HTMLMediaElement::closedCaptionsVisible() const 3181 bool HTMLMediaElement::closedCaptionsVisible() const
3182 { 3182 {
3183 return m_closedCaptionsVisible; 3183 return m_closedCaptionsVisible;
3184 } 3184 }
3185 3185
3186 static void assertShadowRootChildren(ShadowRoot& shadowRoot)
3187 {
3188 #if ENABLE(ASSERT)
3189 // There can be up to two children, either or both of the text
3190 // track container and media controls. If both are present, the
3191 // text track container must be the first child.
3192 unsigned numberOfChildren = shadowRoot.countChildren();
3193 ASSERT(numberOfChildren <= 2);
3194 Node* firstChild = shadowRoot.firstChild();
3195 Node* lastChild = shadowRoot.lastChild();
3196 if (numberOfChildren == 1) {
3197 ASSERT(firstChild->isTextTrackContainer() || firstChild->isMediaControls ());
3198 } else if (numberOfChildren == 2) {
3199 ASSERT(firstChild->isTextTrackContainer());
3200 ASSERT(lastChild->isMediaControls());
3201 }
3202 #endif
3203 }
3204
3186 TextTrackContainer& HTMLMediaElement::ensureTextTrackContainer() 3205 TextTrackContainer& HTMLMediaElement::ensureTextTrackContainer()
3187 { 3206 {
3188 ensureMediaControls(); 3207 ShadowRoot& shadowRoot = ensureClosedShadowRoot();
3189 return *mediaControls()->textTrackContainer(); 3208 assertShadowRootChildren(shadowRoot);
3209
3210 Node* firstChild = shadowRoot.firstChild();
3211 if (firstChild && firstChild->isTextTrackContainer())
3212 return toTextTrackContainer(*firstChild);
3213
3214 RefPtrWillBeRawPtr<TextTrackContainer> textTrackContainer = TextTrackContain er::create(document());
3215
3216 // The text track container should be inserted before the media controls,
3217 // so that they are rendered behind them.
3218 shadowRoot.insertBefore(textTrackContainer, firstChild);
3219
3220 assertShadowRootChildren(shadowRoot);
3221
3222 return *textTrackContainer;
3190 } 3223 }
3191 3224
3192 void HTMLMediaElement::updateTextTrackDisplay() 3225 void HTMLMediaElement::updateTextTrackDisplay()
3193 { 3226 {
3194 WTF_LOG(Media, "HTMLMediaElement::updateTextTrackDisplay(%p)", this); 3227 WTF_LOG(Media, "HTMLMediaElement::updateTextTrackDisplay(%p)", this);
3195 3228
3196 ensureTextTrackContainer().updateDisplay(*this); 3229 ensureTextTrackContainer().updateDisplay(*this);
3197 } 3230 }
3198 3231
3199 void HTMLMediaElement::setClosedCaptionsVisible(bool closedCaptionVisible) 3232 void HTMLMediaElement::setClosedCaptionsVisible(bool closedCaptionVisible)
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
3262 3295
3263 WTF_LOG(Media, "HTMLMediaElement::setShouldDelayLoadEvent(%p, %s)", this, bo olString(shouldDelay)); 3296 WTF_LOG(Media, "HTMLMediaElement::setShouldDelayLoadEvent(%p, %s)", this, bo olString(shouldDelay));
3264 3297
3265 m_shouldDelayLoadEvent = shouldDelay; 3298 m_shouldDelayLoadEvent = shouldDelay;
3266 if (shouldDelay) 3299 if (shouldDelay)
3267 document().incrementLoadEventDelayCount(); 3300 document().incrementLoadEventDelayCount();
3268 else 3301 else
3269 document().decrementLoadEventDelayCount(); 3302 document().decrementLoadEventDelayCount();
3270 } 3303 }
3271 3304
3272
3273 MediaControls* HTMLMediaElement::mediaControls() const 3305 MediaControls* HTMLMediaElement::mediaControls() const
3274 { 3306 {
3275 if (ShadowRoot* shadowRoot = closedShadowRoot()) { 3307 if (ShadowRoot* shadowRoot = closedShadowRoot()) {
3276 // Note that |shadowRoot->firstChild()| may be null. 3308 Node* lastChild = shadowRoot->lastChild();
3277 return toMediaControls(shadowRoot->firstChild()); 3309 if (lastChild && lastChild->isMediaControls())
3310 return toMediaControls(lastChild);
3278 } 3311 }
3279 3312
3280 return nullptr; 3313 return nullptr;
3281 } 3314 }
3282 3315
3283 void HTMLMediaElement::ensureMediaControls() 3316 void HTMLMediaElement::ensureMediaControls()
3284 { 3317 {
3285 if (mediaControls()) 3318 if (mediaControls())
3286 return; 3319 return;
3287 3320
3288 RefPtrWillBeRawPtr<MediaControls> mediaControls = MediaControls::create(*thi s); 3321 RefPtrWillBeRawPtr<MediaControls> mediaControls = MediaControls::create(*thi s);
3289 3322
3290 mediaControls->reset(); 3323 mediaControls->reset();
3291 if (isFullscreen()) 3324 if (isFullscreen())
3292 mediaControls->enteredFullscreen(); 3325 mediaControls->enteredFullscreen();
3293 3326
3294 ensureClosedShadowRoot().appendChild(mediaControls); 3327 ShadowRoot& shadowRoot = ensureClosedShadowRoot();
3328 assertShadowRootChildren(shadowRoot);
3329
3330 // The media controls should be inserted after the text track container,
3331 // so that they are rendered in front of captions and subtitles.
3332 shadowRoot.appendChild(mediaControls);
3333
3334 assertShadowRootChildren(shadowRoot);
3295 3335
3296 if (!shouldShowControls() || !inDocument()) 3336 if (!shouldShowControls() || !inDocument())
3297 mediaControls->hide(); 3337 mediaControls->hide();
3298 } 3338 }
3299 3339
3300 void HTMLMediaElement::configureMediaControls() 3340 void HTMLMediaElement::configureMediaControls()
3301 { 3341 {
3302 if (!inDocument()) { 3342 if (!inDocument()) {
3303 if (mediaControls()) 3343 if (mediaControls())
3304 mediaControls()->hide(); 3344 mediaControls()->hide();
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
3340 && m_haveVisibleTextTrack == haveVisibleTextTrack) { 3380 && m_haveVisibleTextTrack == haveVisibleTextTrack) {
3341 cueTimeline().updateActiveCues(currentTime()); 3381 cueTimeline().updateActiveCues(currentTime());
3342 return; 3382 return;
3343 } 3383 }
3344 m_haveVisibleTextTrack = haveVisibleTextTrack; 3384 m_haveVisibleTextTrack = haveVisibleTextTrack;
3345 m_closedCaptionsVisible = m_haveVisibleTextTrack; 3385 m_closedCaptionsVisible = m_haveVisibleTextTrack;
3346 3386
3347 if (!m_haveVisibleTextTrack && !mediaControls()) 3387 if (!m_haveVisibleTextTrack && !mediaControls())
3348 return; 3388 return;
3349 3389
3350 ensureMediaControls(); 3390 if (mediaControls())
3351 mediaControls()->changedClosedCaptionsVisibility(); 3391 mediaControls()->changedClosedCaptionsVisibility();
3352 3392
3353 cueTimeline().updateActiveCues(currentTime()); 3393 cueTimeline().updateActiveCues(currentTime());
3354 3394
3355 // Note: The "time marches on" algorithm (updateActiveCues) runs the "rules 3395 // Note: The "time marches on" algorithm (updateActiveCues) runs the "rules
3356 // for updating the text track rendering" (updateTextTrackDisplay) only for 3396 // for updating the text track rendering" (updateTextTrackDisplay) only for
3357 // "affected tracks", i.e. tracks where the the active cues have changed. 3397 // "affected tracks", i.e. tracks where the the active cues have changed.
3358 // This misses cues in tracks that changed mode between hidden and showing. 3398 // This misses cues in tracks that changed mode between hidden and showing.
3359 // This appears to be a spec bug, which we work around here: 3399 // This appears to be a spec bug, which we work around here:
3360 // https://www.w3.org/Bugs/Public/show_bug.cgi?id=28236 3400 // https://www.w3.org/Bugs/Public/show_bug.cgi?id=28236
3361 updateTextTrackDisplay(); 3401 updateTextTrackDisplay();
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
3610 3650
3611 #if ENABLE(WEB_AUDIO) 3651 #if ENABLE(WEB_AUDIO)
3612 void HTMLMediaElement::clearWeakMembers(Visitor* visitor) 3652 void HTMLMediaElement::clearWeakMembers(Visitor* visitor)
3613 { 3653 {
3614 if (!visitor->isAlive(m_audioSourceNode) && audioSourceProvider()) 3654 if (!visitor->isAlive(m_audioSourceNode) && audioSourceProvider())
3615 audioSourceProvider()->setClient(nullptr); 3655 audioSourceProvider()->setClient(nullptr);
3616 } 3656 }
3617 #endif 3657 #endif
3618 3658
3619 } 3659 }
OLDNEW
« no previous file with comments | « Source/core/css/mediaControls.css ('k') | Source/core/html/shadow/MediaControls.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698