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

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: same size as media controls Created 5 years, 10 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
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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 #include "core/html/MediaController.h" 48 #include "core/html/MediaController.h"
49 #include "core/html/MediaError.h" 49 #include "core/html/MediaError.h"
50 #include "core/html/MediaFragmentURIParser.h" 50 #include "core/html/MediaFragmentURIParser.h"
51 #include "core/html/TimeRanges.h" 51 #include "core/html/TimeRanges.h"
52 #include "core/html/shadow/MediaControls.h" 52 #include "core/html/shadow/MediaControls.h"
53 #include "core/html/track/AudioTrack.h" 53 #include "core/html/track/AudioTrack.h"
54 #include "core/html/track/AudioTrackList.h" 54 #include "core/html/track/AudioTrackList.h"
55 #include "core/html/track/AutomaticTrackSelection.h" 55 #include "core/html/track/AutomaticTrackSelection.h"
56 #include "core/html/track/CueTimeline.h" 56 #include "core/html/track/CueTimeline.h"
57 #include "core/html/track/InbandTextTrack.h" 57 #include "core/html/track/InbandTextTrack.h"
58 #include "core/html/track/TextTrackContainer.h"
58 #include "core/html/track/TextTrackList.h" 59 #include "core/html/track/TextTrackList.h"
59 #include "core/html/track/VideoTrack.h" 60 #include "core/html/track/VideoTrack.h"
60 #include "core/html/track/VideoTrackList.h" 61 #include "core/html/track/VideoTrackList.h"
61 #include "core/layout/LayoutVideo.h" 62 #include "core/layout/LayoutVideo.h"
62 #include "core/layout/LayoutView.h" 63 #include "core/layout/LayoutView.h"
63 #include "core/layout/compositing/LayerCompositor.h" 64 #include "core/layout/compositing/LayerCompositor.h"
64 #include "core/loader/FrameLoader.h" 65 #include "core/loader/FrameLoader.h"
65 #include "platform/ContentType.h" 66 #include "platform/ContentType.h"
66 #include "platform/Logging.h" 67 #include "platform/Logging.h"
67 #include "platform/MIMETypeFromURL.h" 68 #include "platform/MIMETypeFromURL.h"
(...skipping 3109 matching lines...) Expand 10 before | Expand all | Expand 10 after
3177 } 3178 }
3178 } 3179 }
3179 return false; 3180 return false;
3180 } 3181 }
3181 3182
3182 bool HTMLMediaElement::closedCaptionsVisible() const 3183 bool HTMLMediaElement::closedCaptionsVisible() const
3183 { 3184 {
3184 return m_closedCaptionsVisible; 3185 return m_closedCaptionsVisible;
3185 } 3186 }
3186 3187
3188 static void assertShadowRootChildren(ShadowRoot& shadowRoot)
philipj_slow 2015/02/26 09:51:52 I don't know if this seems pedantic. I failed to g
3189 {
3190 #if ENABLE(ASSERT)
3191 // There can be up to two children, either or both of the text
3192 // track container and media controls. If both are present, the
3193 // text track container must be the first child.
3194 unsigned numberOfChildren = shadowRoot.countChildren();
3195 ASSERT(numberOfChildren <= 2);
3196 Node* firstChild = shadowRoot.firstChild();
3197 Node* lastChild = shadowRoot.lastChild();
3198 if (numberOfChildren == 1) {
3199 ASSERT(firstChild->isTextTrackContainer() || firstChild->isMediaControls ());
3200 } else if (numberOfChildren == 2) {
3201 ASSERT(firstChild->isTextTrackContainer());
3202 ASSERT(lastChild->isMediaControls());
3203 }
3204 #endif
3205 }
3206
3207 TextTrackContainer& HTMLMediaElement::ensureTextTrackContainer()
3208 {
3209 ShadowRoot& shadowRoot = ensureClosedShadowRoot();
3210 assertShadowRootChildren(shadowRoot);
3211
3212 Node* firstChild = shadowRoot.firstChild();
3213 if (firstChild && firstChild->isTextTrackContainer())
3214 return toTextTrackContainer(*firstChild);
3215
3216 RefPtrWillBeRawPtr<TextTrackContainer> textTrackContainer = TextTrackContain er::create(document());
3217
3218 // The text track container should be inserted before the media controls,
3219 // so that they are rendered behind them.
3220 shadowRoot.insertBefore(textTrackContainer, firstChild);
3221
3222 assertShadowRootChildren(shadowRoot);
3223
3224 return *textTrackContainer;
3225 }
3226
3187 void HTMLMediaElement::updateTextTrackDisplay() 3227 void HTMLMediaElement::updateTextTrackDisplay()
3188 { 3228 {
3189 WTF_LOG(Media, "HTMLMediaElement::updateTextTrackDisplay(%p)", this); 3229 WTF_LOG(Media, "HTMLMediaElement::updateTextTrackDisplay(%p)", this);
3190 3230
3191 ensureMediaControls(); 3231 // FIXME: this probably doesn't hold
philipj_slow 2015/02/26 09:51:52 Um, right. fs, I think we can get here for audio e
fs 2015/02/26 12:30:51 My (loose) plan so far wrt this has been to not ev
philipj_slow 2015/02/27 07:13:51 Not creating the container for audio sounds like a
fs 2015/02/27 09:50:31 Acknowledged.
3192 mediaControls()->updateTextTrackDisplay(); 3232 ASSERT(isHTMLVideoElement());
3233 ensureTextTrackContainer().updateDisplay(*this);
3193 } 3234 }
3194 3235
3195 void HTMLMediaElement::setClosedCaptionsVisible(bool closedCaptionVisible) 3236 void HTMLMediaElement::setClosedCaptionsVisible(bool closedCaptionVisible)
3196 { 3237 {
3197 WTF_LOG(Media, "HTMLMediaElement::setClosedCaptionsVisible(%p, %s)", this, b oolString(closedCaptionVisible)); 3238 WTF_LOG(Media, "HTMLMediaElement::setClosedCaptionsVisible(%p, %s)", this, b oolString(closedCaptionVisible));
3198 3239
3199 if (!m_player || !hasClosedCaptions()) 3240 if (!m_player || !hasClosedCaptions())
3200 return; 3241 return;
3201 3242
3202 m_closedCaptionsVisible = closedCaptionVisible; 3243 m_closedCaptionsVisible = closedCaptionVisible;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
3255 3296
3256 WTF_LOG(Media, "HTMLMediaElement::setShouldDelayLoadEvent(%p, %s)", this, bo olString(shouldDelay)); 3297 WTF_LOG(Media, "HTMLMediaElement::setShouldDelayLoadEvent(%p, %s)", this, bo olString(shouldDelay));
3257 3298
3258 m_shouldDelayLoadEvent = shouldDelay; 3299 m_shouldDelayLoadEvent = shouldDelay;
3259 if (shouldDelay) 3300 if (shouldDelay)
3260 document().incrementLoadEventDelayCount(); 3301 document().incrementLoadEventDelayCount();
3261 else 3302 else
3262 document().decrementLoadEventDelayCount(); 3303 document().decrementLoadEventDelayCount();
3263 } 3304 }
3264 3305
3265
3266 MediaControls* HTMLMediaElement::mediaControls() const 3306 MediaControls* HTMLMediaElement::mediaControls() const
3267 { 3307 {
3268 if (ShadowRoot* shadowRoot = closedShadowRoot()) { 3308 if (ShadowRoot* shadowRoot = closedShadowRoot()) {
3269 // Note that |shadowRoot->firstChild()| may be null. 3309 Node* lastChild = shadowRoot->lastChild();
3270 return toMediaControls(shadowRoot->firstChild()); 3310 if (lastChild && lastChild->isMediaControls())
3311 return toMediaControls(lastChild);
3271 } 3312 }
3272 3313
3273 return nullptr; 3314 return nullptr;
3274 } 3315 }
3275 3316
3276 void HTMLMediaElement::ensureMediaControls() 3317 void HTMLMediaElement::ensureMediaControls()
3277 { 3318 {
3278 if (mediaControls()) 3319 if (mediaControls())
3279 return; 3320 return;
3280 3321
3281 RefPtrWillBeRawPtr<MediaControls> mediaControls = MediaControls::create(*thi s); 3322 RefPtrWillBeRawPtr<MediaControls> mediaControls = MediaControls::create(*thi s);
3282 3323
3283 mediaControls->reset(); 3324 mediaControls->reset();
3284 if (isFullscreen()) 3325 if (isFullscreen())
3285 mediaControls->enteredFullscreen(); 3326 mediaControls->enteredFullscreen();
3286 3327
3287 ensureClosedShadowRoot().appendChild(mediaControls); 3328 ShadowRoot& shadowRoot = ensureClosedShadowRoot();
3329 assertShadowRootChildren(shadowRoot);
3330
3331 // The media controls should be inserted after the text track container,
3332 // so that they are rendered in front of captions and subtitles.
3333 shadowRoot.appendChild(mediaControls);
3334
3335 assertShadowRootChildren(shadowRoot);
3288 3336
3289 if (!shouldShowControls() || !inDocument()) 3337 if (!shouldShowControls() || !inDocument())
3290 mediaControls->hide(); 3338 mediaControls->hide();
3291 } 3339 }
3292 3340
3293 void HTMLMediaElement::configureMediaControls() 3341 void HTMLMediaElement::configureMediaControls()
3294 { 3342 {
3295 if (!inDocument()) { 3343 if (!inDocument()) {
3296 if (mediaControls()) 3344 if (mediaControls())
3297 mediaControls()->hide(); 3345 mediaControls()->hide();
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
3333 && m_haveVisibleTextTrack == haveVisibleTextTrack) { 3381 && m_haveVisibleTextTrack == haveVisibleTextTrack) {
3334 cueTimeline().updateActiveCues(currentTime()); 3382 cueTimeline().updateActiveCues(currentTime());
3335 return; 3383 return;
3336 } 3384 }
3337 m_haveVisibleTextTrack = haveVisibleTextTrack; 3385 m_haveVisibleTextTrack = haveVisibleTextTrack;
3338 m_closedCaptionsVisible = m_haveVisibleTextTrack; 3386 m_closedCaptionsVisible = m_haveVisibleTextTrack;
3339 3387
3340 if (!m_haveVisibleTextTrack && !mediaControls()) 3388 if (!m_haveVisibleTextTrack && !mediaControls())
3341 return; 3389 return;
3342 3390
3343 ensureMediaControls(); 3391 if (mediaControls())
3344 mediaControls()->changedClosedCaptionsVisibility(); 3392 mediaControls()->changedClosedCaptionsVisibility();
3345 3393
3346 cueTimeline().updateActiveCues(currentTime()); 3394 cueTimeline().updateActiveCues(currentTime());
3347 updateTextTrackDisplay(); 3395 updateTextTrackDisplay();
3348 } 3396 }
3349 3397
3350 void* HTMLMediaElement::preDispatchEventHandler(Event* event) 3398 void* HTMLMediaElement::preDispatchEventHandler(Event* event)
3351 { 3399 {
3352 if (event && event->type() == EventTypeNames::webkitfullscreenchange) 3400 if (event && event->type() == EventTypeNames::webkitfullscreenchange)
3353 configureMediaControls(); 3401 configureMediaControls();
3354 3402
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
3596 3644
3597 #if ENABLE(WEB_AUDIO) 3645 #if ENABLE(WEB_AUDIO)
3598 void HTMLMediaElement::clearWeakMembers(Visitor* visitor) 3646 void HTMLMediaElement::clearWeakMembers(Visitor* visitor)
3599 { 3647 {
3600 if (!visitor->isAlive(m_audioSourceNode) && audioSourceProvider()) 3648 if (!visitor->isAlive(m_audioSourceNode) && audioSourceProvider())
3601 audioSourceProvider()->setClient(nullptr); 3649 audioSourceProvider()->setClient(nullptr);
3602 } 3650 }
3603 #endif 3651 #endif
3604 3652
3605 } 3653 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698