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

Side by Side Diff: Source/modules/screen_orientation/ScreenOrientationController.cpp

Issue 319633007: Move WebScreenOrientationClient to WebFrameClient. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: don't send the events multiple times Created 6 years, 6 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 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "config.h" 5 #include "config.h"
6 #include "modules/screen_orientation/ScreenOrientationController.h" 6 #include "modules/screen_orientation/ScreenOrientationController.h"
7 7
8 #include "core/dom/Document.h" 8 #include "core/dom/Document.h"
9 #include "core/frame/DOMWindow.h" 9 #include "core/frame/DOMWindow.h"
10 #include "core/frame/FrameView.h" 10 #include "core/frame/FrameView.h"
11 #include "core/frame/LocalFrame.h" 11 #include "core/frame/LocalFrame.h"
12 #include "core/frame/Screen.h" 12 #include "core/frame/Screen.h"
13 #include "core/page/Page.h" 13 #include "core/page/Page.h"
14 #include "platform/LayoutTestSupport.h" 14 #include "platform/LayoutTestSupport.h"
15 #include "platform/PlatformScreen.h" 15 #include "platform/PlatformScreen.h"
16 #include "public/platform/Platform.h" 16 #include "public/platform/Platform.h"
17 #include "public/platform/WebScreenOrientationClient.h" 17 #include "public/platform/WebScreenOrientationClient.h"
18 18
19 namespace WebCore { 19 namespace WebCore {
20 20
21 ScreenOrientationController::~ScreenOrientationController() 21 ScreenOrientationController::~ScreenOrientationController()
22 { 22 {
23 } 23 }
24 24
25 void ScreenOrientationController::provideTo(Page& page, blink::WebScreenOrientat ionClient* client) 25 void ScreenOrientationController::provideTo(LocalFrame& frame, blink::WebScreenO rientationClient* client)
26 { 26 {
27 ScreenOrientationController* controller = new ScreenOrientationController(pa ge, client); 27 ScreenOrientationController* controller = new ScreenOrientationController(fr ame, client);
28 WillBeHeapSupplement<Page>::provideTo(page, supplementName(), adoptPtrWillBe Noop(controller)); 28 WillBeHeapSupplement<LocalFrame>::provideTo(frame, supplementName(), adoptPt rWillBeNoop(controller));
29 } 29 }
30 30
31 ScreenOrientationController& ScreenOrientationController::from(Page& page) 31 ScreenOrientationController& ScreenOrientationController::from(LocalFrame& frame )
32 { 32 {
33 return *static_cast<ScreenOrientationController*>(WillBeHeapSupplement<Page> ::from(page, supplementName())); 33 return *static_cast<ScreenOrientationController*>(WillBeHeapSupplement<Local Frame>::from(frame, supplementName()));
34 } 34 }
35 35
36 ScreenOrientationController::ScreenOrientationController(Page& page, blink::WebS creenOrientationClient* client) 36 ScreenOrientationController::ScreenOrientationController(LocalFrame& frame, blin k::WebScreenOrientationClient* client)
37 : PageLifecycleObserver(&page) 37 : PageLifecycleObserver(frame.page())
38 , m_overrideOrientation(blink::WebScreenOrientationUndefined) 38 , m_overrideOrientation(blink::WebScreenOrientationUndefined)
39 , m_client(client) 39 , m_client(client)
40 , m_frame(frame)
40 { 41 {
41 } 42 }
42 43
43 const char* ScreenOrientationController::supplementName() 44 const char* ScreenOrientationController::supplementName()
44 { 45 {
45 return "ScreenOrientationController"; 46 return "ScreenOrientationController";
46 } 47 }
47 48
48 // Compute the screen orientation using the orientation angle and the screen wid th / height. 49 // Compute the screen orientation using the orientation angle and the screen wid th / height.
49 blink::WebScreenOrientationType ScreenOrientationController::computeOrientation( FrameView* view) 50 blink::WebScreenOrientationType ScreenOrientationController::computeOrientation( FrameView* view)
(...skipping 20 matching lines...) Expand all
70 ASSERT_NOT_REACHED(); 71 ASSERT_NOT_REACHED();
71 return blink::WebScreenOrientationPortraitPrimary; 72 return blink::WebScreenOrientationPortraitPrimary;
72 } 73 }
73 } 74 }
74 75
75 void ScreenOrientationController::pageVisibilityChanged() 76 void ScreenOrientationController::pageVisibilityChanged()
76 { 77 {
77 if (page() && page()->visibilityState() == PageVisibilityStateVisible) { 78 if (page() && page()->visibilityState() == PageVisibilityStateVisible) {
78 blink::WebScreenOrientationType oldOrientation = m_overrideOrientation; 79 blink::WebScreenOrientationType oldOrientation = m_overrideOrientation;
79 m_overrideOrientation = blink::WebScreenOrientationUndefined; 80 m_overrideOrientation = blink::WebScreenOrientationUndefined;
80 LocalFrame* mainFrame = page()->mainFrame(); 81 // FIXME: sendOrientationChangeEvent() currently send an event all the
81 if (mainFrame && oldOrientation != orientation()) 82 // children of the frame, so it should only be called on the frame on
82 mainFrame->sendOrientationChangeEvent(); 83 // top of the tree. We would need the embedder to call
84 // sendOrientationChangeEvent on every WebFrame part of a WebView to be
85 // able to remove this.
86 if (m_frame.localFrameRoot() == &m_frame && oldOrientation != orientatio n())
Inactive 2014/06/10 14:48:48 nit: this '&' should not be needed due to DEFINE_C
mlamouri (slow - plz ping) 2014/06/10 16:27:23 This is working. The name of that macro can't be m
87 m_frame.sendOrientationChangeEvent();
83 } else if (m_overrideOrientation == blink::WebScreenOrientationUndefined) { 88 } else if (m_overrideOrientation == blink::WebScreenOrientationUndefined) {
84 // The page is no longer visible, store the last know screen orientation 89 // The page is no longer visible, store the last know screen orientation
85 // so that we keep returning this orientation until the page becomes 90 // so that we keep returning this orientation until the page becomes
86 // visible again. 91 // visible again.
87 m_overrideOrientation = orientation(); 92 m_overrideOrientation = orientation();
88 } 93 }
89 } 94 }
90 95
91 blink::WebScreenOrientationType ScreenOrientationController::orientation() const 96 blink::WebScreenOrientationType ScreenOrientationController::orientation() const
92 { 97 {
93 if (m_overrideOrientation != blink::WebScreenOrientationUndefined) { 98 if (m_overrideOrientation != blink::WebScreenOrientationUndefined) {
94 // The page is not visible, keep returning the last known screen orienta tion. 99 // The page is not visible, keep returning the last known screen orienta tion.
95 ASSERT(!page() || page()->visibilityState() != PageVisibilityStateVisibl e); 100 ASSERT(!page() || page()->visibilityState() != PageVisibilityStateVisibl e);
96 return m_overrideOrientation; 101 return m_overrideOrientation;
97 } 102 }
98 103
99 LocalFrame* mainFrame = page() ? page()->mainFrame() : 0; 104 blink::WebScreenOrientationType orientationType = screenOrientationType(m_fr ame.view());
100 if (!mainFrame)
101 return blink::WebScreenOrientationPortraitPrimary;
102 blink::WebScreenOrientationType orientationType = screenOrientationType(main Frame->view());
103 if (orientationType == blink::WebScreenOrientationUndefined) { 105 if (orientationType == blink::WebScreenOrientationUndefined) {
104 // The embedder could not provide us with an orientation, deduce it ours elves. 106 // The embedder could not provide us with an orientation, deduce it ours elves.
105 orientationType = computeOrientation(mainFrame->view()); 107 orientationType = computeOrientation(m_frame.view());
106 } 108 }
107 ASSERT(orientationType != blink::WebScreenOrientationUndefined); 109 ASSERT(orientationType != blink::WebScreenOrientationUndefined);
108 return orientationType; 110 return orientationType;
109 } 111 }
110 112
111 void ScreenOrientationController::lockOrientation(blink::WebScreenOrientationLoc kType orientation, blink::WebLockOrientationCallback* callback) 113 void ScreenOrientationController::lockOrientation(blink::WebScreenOrientationLoc kType orientation, blink::WebLockOrientationCallback* callback)
112 { 114 {
113 if (!m_client) { 115 if (!m_client) {
114 // FIXME: temporary until the content layer gets updated. 116 // FIXME: temporary until the content layer gets updated.
115 blink::Platform::current()->lockOrientation(orientation, callback); 117 blink::Platform::current()->lockOrientation(orientation, callback);
116 return; 118 return;
117 } 119 }
118 120
119 m_client->lockOrientation(orientation, callback); 121 m_client->lockOrientation(orientation, callback);
120 } 122 }
121 123
122 void ScreenOrientationController::unlockOrientation() 124 void ScreenOrientationController::unlockOrientation()
123 { 125 {
124 if (!m_client) { 126 if (!m_client) {
125 // FIXME: temporary until the content layer gets updated. 127 // FIXME: temporary until the content layer gets updated.
126 blink::Platform::current()->unlockOrientation(); 128 blink::Platform::current()->unlockOrientation();
127 return; 129 return;
128 } 130 }
129 131
130 m_client->unlockOrientation(); 132 m_client->unlockOrientation();
131 } 133 }
132 134
133 } // namespace WebCore 135 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/modules/screen_orientation/ScreenOrientationController.h ('k') | Source/web/WebLocalFrameImpl.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698