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

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: 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 if (oldOrientation != orientation())
Inactive 2014/06/09 17:29:29 Why don't we keep doing this? Why do we keep the L
mlamouri (slow - plz ping) 2014/06/09 17:31:51 Because page->mainFrame() might not be the same as
81 if (mainFrame && oldOrientation != orientation()) 82 m_frame.sendOrientationChangeEvent();
82 mainFrame->sendOrientationChangeEvent();
83 } else if (m_overrideOrientation == blink::WebScreenOrientationUndefined) { 83 } else if (m_overrideOrientation == blink::WebScreenOrientationUndefined) {
84 // The page is no longer visible, store the last know screen orientation 84 // The page is no longer visible, store the last know screen orientation
85 // so that we keep returning this orientation until the page becomes 85 // so that we keep returning this orientation until the page becomes
86 // visible again. 86 // visible again.
87 m_overrideOrientation = orientation(); 87 m_overrideOrientation = orientation();
88 } 88 }
89 } 89 }
90 90
91 blink::WebScreenOrientationType ScreenOrientationController::orientation() const 91 blink::WebScreenOrientationType ScreenOrientationController::orientation() const
92 { 92 {
93 if (m_overrideOrientation != blink::WebScreenOrientationUndefined) { 93 if (m_overrideOrientation != blink::WebScreenOrientationUndefined) {
94 // The page is not visible, keep returning the last known screen orienta tion. 94 // The page is not visible, keep returning the last known screen orienta tion.
95 ASSERT(!page() || page()->visibilityState() != PageVisibilityStateVisibl e); 95 ASSERT(!page() || page()->visibilityState() != PageVisibilityStateVisibl e);
96 return m_overrideOrientation; 96 return m_overrideOrientation;
97 } 97 }
98 98
99 LocalFrame* mainFrame = page() ? page()->mainFrame() : 0; 99 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) { 100 if (orientationType == blink::WebScreenOrientationUndefined) {
104 // The embedder could not provide us with an orientation, deduce it ours elves. 101 // The embedder could not provide us with an orientation, deduce it ours elves.
105 orientationType = computeOrientation(mainFrame->view()); 102 orientationType = computeOrientation(m_frame.view());
106 } 103 }
107 ASSERT(orientationType != blink::WebScreenOrientationUndefined); 104 ASSERT(orientationType != blink::WebScreenOrientationUndefined);
108 return orientationType; 105 return orientationType;
109 } 106 }
110 107
111 void ScreenOrientationController::lockOrientation(blink::WebScreenOrientationLoc kType orientation, blink::WebLockOrientationCallback* callback) 108 void ScreenOrientationController::lockOrientation(blink::WebScreenOrientationLoc kType orientation, blink::WebLockOrientationCallback* callback)
112 { 109 {
113 if (!m_client) { 110 if (!m_client) {
114 // FIXME: temporary until the content layer gets updated. 111 // FIXME: temporary until the content layer gets updated.
115 blink::Platform::current()->lockOrientation(orientation, callback); 112 blink::Platform::current()->lockOrientation(orientation, callback);
116 return; 113 return;
117 } 114 }
118 115
119 m_client->lockOrientation(orientation, callback); 116 m_client->lockOrientation(orientation, callback);
120 } 117 }
121 118
122 void ScreenOrientationController::unlockOrientation() 119 void ScreenOrientationController::unlockOrientation()
123 { 120 {
124 if (!m_client) { 121 if (!m_client) {
125 // FIXME: temporary until the content layer gets updated. 122 // FIXME: temporary until the content layer gets updated.
126 blink::Platform::current()->unlockOrientation(); 123 blink::Platform::current()->unlockOrientation();
127 return; 124 return;
128 } 125 }
129 126
130 m_client->unlockOrientation(); 127 m_client->unlockOrientation();
131 } 128 }
132 129
133 } // namespace WebCore 130 } // 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