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

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

Issue 2764673002: Embedded media: Rotate to fullscreen
Patch Set: Created 3 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2007, 2008, 2009, 2010 Apple Inc. All rights reserved. 2 * Copyright (C) 2007, 2008, 2009, 2010 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 12 matching lines...) Expand all
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */ 24 */
25 25
26 #include "core/html/HTMLVideoElement.h" 26 #include "core/html/HTMLVideoElement.h"
27 27
28 #include <memory> 28 #include <memory>
29 #include "bindings/core/v8/ExceptionState.h" 29 #include "bindings/core/v8/ExceptionState.h"
30 #include "core/CSSPropertyNames.h" 30 #include "core/CSSPropertyNames.h"
31 #include "core/HTMLNames.h" 31 #include "core/HTMLNames.h"
32 #include "core/dom/Attribute.h" 32 #include "core/dom/Attribute.h"
33 #include "core/dom/ClientRect.h"
33 #include "core/dom/Document.h" 34 #include "core/dom/Document.h"
35 #include "core/dom/DocumentUserGestureToken.h"
34 #include "core/dom/ExceptionCode.h" 36 #include "core/dom/ExceptionCode.h"
35 #include "core/dom/Fullscreen.h" 37 #include "core/dom/Fullscreen.h"
38 #include "core/dom/ResizeObserver.h"
39 #include "core/dom/ResizeObserverCallback.h"
40 #include "core/dom/ResizeObserverEntry.h"
36 #include "core/dom/shadow/ShadowRoot.h" 41 #include "core/dom/shadow/ShadowRoot.h"
37 #include "core/frame/ImageBitmap.h" 42 #include "core/frame/ImageBitmap.h"
38 #include "core/frame/LocalDOMWindow.h" 43 #include "core/frame/LocalDOMWindow.h"
39 #include "core/frame/Settings.h" 44 #include "core/frame/Settings.h"
40 #include "core/html/MediaCustomControlsFullscreenDetector.h" 45 #include "core/html/MediaCustomControlsFullscreenDetector.h"
41 #include "core/html/parser/HTMLParserIdioms.h" 46 #include "core/html/parser/HTMLParserIdioms.h"
42 #include "core/imagebitmap/ImageBitmapOptions.h" 47 #include "core/imagebitmap/ImageBitmapOptions.h"
43 #include "core/layout/LayoutImage.h" 48 #include "core/layout/LayoutImage.h"
44 #include "core/layout/LayoutVideo.h" 49 #include "core/layout/LayoutVideo.h"
45 #include "platform/RuntimeEnabledFeatures.h" 50 #include "platform/RuntimeEnabledFeatures.h"
46 #include "platform/UserGestureIndicator.h" 51 #include "platform/UserGestureIndicator.h"
47 #include "platform/graphics/GraphicsContext.h" 52 #include "platform/graphics/GraphicsContext.h"
48 #include "platform/graphics/ImageBuffer.h" 53 #include "platform/graphics/ImageBuffer.h"
49 #include "platform/graphics/gpu/Extensions3DUtil.h" 54 #include "platform/graphics/gpu/Extensions3DUtil.h"
50 #include "public/platform/WebCanvas.h" 55 #include "public/platform/WebCanvas.h"
51 56
52 namespace blink { 57 namespace blink {
53 58
54 using namespace HTMLNames; 59 using namespace HTMLNames;
55 60
61 class HTMLVideoElementResizeObserverCallback final
62 : public ResizeObserverCallback {
63 public:
64 explicit HTMLVideoElementResizeObserverCallback(HTMLVideoElement* video)
65 : m_video(video), m_prevOrientationLandscape(false) {
66 DCHECK(video);
67 }
68
69 ~HTMLVideoElementResizeObserverCallback() override = default;
70
71 void handleEvent(const HeapVector<Member<ResizeObserverEntry>>& entries,
72 ResizeObserver* observer) override {
73 if (!m_video->document().settings() ||
74 !m_video->document().settings()->getEmbeddedMediaExperienceEnabled())
75 return;
76
77 DCHECK_EQ(1u, entries.size());
78 float documentWidth = entries[0]->contentRect()->width();
79 float documentHeight = entries[0]->contentRect()->height();
80
81 if (!m_prevOrientationLandscape && documentWidth > documentHeight) {
82 UserGestureIndicator gesture(
83 DocumentUserGestureToken::create(&m_video->document()));
84 m_video->webkitEnterFullscreen();
85 }
86
87 m_prevOrientationLandscape = documentWidth > documentHeight;
88 }
89
90 DEFINE_INLINE_TRACE() {
91 visitor->trace(m_video);
92 ResizeObserverCallback::trace(visitor);
93 }
94
95 private:
96 Member<HTMLVideoElement> m_video;
97 bool m_prevOrientationLandscape;
98 };
99
56 inline HTMLVideoElement::HTMLVideoElement(Document& document) 100 inline HTMLVideoElement::HTMLVideoElement(Document& document)
57 : HTMLMediaElement(videoTag, document) { 101 : HTMLMediaElement(videoTag, document),
102 m_customControlsFullscreenDetector(
103 new MediaCustomControlsFullscreenDetector(*this)),
104 m_resizeObserver(ResizeObserver::create(
105 document,
106 new HTMLVideoElementResizeObserverCallback(this))) {
107 m_resizeObserver->observe(document.documentElement());
58 if (document.settings()) { 108 if (document.settings()) {
59 m_defaultPosterURL = 109 m_defaultPosterURL =
60 AtomicString(document.settings()->getDefaultVideoPosterURL()); 110 AtomicString(document.settings()->getDefaultVideoPosterURL());
61 } 111 }
62 112
63 if (RuntimeEnabledFeatures::videoFullscreenDetectionEnabled()) { 113 if (RuntimeEnabledFeatures::videoFullscreenDetectionEnabled()) {
64 m_customControlsFullscreenDetector = 114 m_customControlsFullscreenDetector =
65 new MediaCustomControlsFullscreenDetector(*this); 115 new MediaCustomControlsFullscreenDetector(*this);
66 } 116 }
67 } 117 }
68 118
69 HTMLVideoElement* HTMLVideoElement::create(Document& document) { 119 HTMLVideoElement* HTMLVideoElement::create(Document& document) {
70 HTMLVideoElement* video = new HTMLVideoElement(document); 120 HTMLVideoElement* video = new HTMLVideoElement(document);
71 video->ensureUserAgentShadowRoot(); 121 video->ensureUserAgentShadowRoot();
72 video->suspendIfNeeded(); 122 video->suspendIfNeeded();
73 return video; 123 return video;
74 } 124 }
75 125
76 DEFINE_TRACE(HTMLVideoElement) { 126 DEFINE_TRACE(HTMLVideoElement) {
77 visitor->trace(m_imageLoader); 127 visitor->trace(m_imageLoader);
78 visitor->trace(m_customControlsFullscreenDetector); 128 visitor->trace(m_customControlsFullscreenDetector);
129 visitor->trace(m_resizeObserver);
79 HTMLMediaElement::trace(visitor); 130 HTMLMediaElement::trace(visitor);
80 } 131 }
81 132
82 void HTMLVideoElement::contextDestroyed(ExecutionContext* context) { 133 void HTMLVideoElement::contextDestroyed(ExecutionContext* context) {
134 m_resizeObserver.clear();
83 if (m_customControlsFullscreenDetector) 135 if (m_customControlsFullscreenDetector)
84 m_customControlsFullscreenDetector->contextDestroyed(); 136 m_customControlsFullscreenDetector->contextDestroyed();
85 137
86 HTMLMediaElement::contextDestroyed(context); 138 HTMLMediaElement::contextDestroyed(context);
87 } 139 }
88 140
89 bool HTMLVideoElement::layoutObjectIsNeeded(const ComputedStyle& style) { 141 bool HTMLVideoElement::layoutObjectIsNeeded(const ComputedStyle& style) {
90 return HTMLElement::layoutObjectIsNeeded(style); 142 return HTMLElement::layoutObjectIsNeeded(style);
91 } 143 }
92 144
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 return ScriptPromise(); 439 return ScriptPromise();
388 if (!ImageBitmap::isResizeOptionValid(options, exceptionState)) 440 if (!ImageBitmap::isResizeOptionValid(options, exceptionState))
389 return ScriptPromise(); 441 return ScriptPromise();
390 return ImageBitmapSource::fulfillImageBitmap( 442 return ImageBitmapSource::fulfillImageBitmap(
391 scriptState, 443 scriptState,
392 ImageBitmap::create(this, cropRect, 444 ImageBitmap::create(this, cropRect,
393 eventTarget.toLocalDOMWindow()->document(), options)); 445 eventTarget.toLocalDOMWindow()->document(), options));
394 } 446 }
395 447
396 } // namespace blink 448 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/html/HTMLVideoElement.h ('k') | third_party/WebKit/Source/core/html/MediaDocument.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698