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

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

Issue 315693002: Use WebViewClient instead of BlinkPlatform for screen lock. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: review comments 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"
17 #include "public/platform/WebScreenOrientationClient.h"
16 18
17 namespace WebCore { 19 namespace WebCore {
18 20
19 ScreenOrientationController::~ScreenOrientationController() 21 ScreenOrientationController::~ScreenOrientationController()
20 { 22 {
21 } 23 }
22 24
23 ScreenOrientationController& ScreenOrientationController::from(Document& documen t) 25 void ScreenOrientationController::provideTo(Page& page, blink::WebScreenOrientat ionClient* client)
24 { 26 {
25 ScreenOrientationController* controller = static_cast<ScreenOrientationContr oller*>(DocumentSupplement::from(document, supplementName())); 27 ScreenOrientationController* controller = new ScreenOrientationController(pa ge, client);
26 if (!controller) { 28 WillBeHeapSupplement<Page>::provideTo(page, supplementName(), adoptPtrWillBe Noop(controller));
27 controller = new ScreenOrientationController(document);
28 DocumentSupplement::provideTo(document, supplementName(), adoptPtrWillBe Noop(controller));
29 }
30 return *controller;
31 } 29 }
32 30
33 ScreenOrientationController::ScreenOrientationController(Document& document) 31 ScreenOrientationController& ScreenOrientationController::from(Page& page)
34 : PageLifecycleObserver(document.page()) 32 {
35 , m_document(document) 33 return *static_cast<ScreenOrientationController*>(WillBeHeapSupplement<Page> ::from(page, supplementName()));
34 }
35
36 ScreenOrientationController::ScreenOrientationController(Page& page, blink::WebS creenOrientationClient* client)
37 : PageLifecycleObserver(&page)
36 , m_overrideOrientation(blink::WebScreenOrientationUndefined) 38 , m_overrideOrientation(blink::WebScreenOrientationUndefined)
39 , m_client(client)
37 { 40 {
38 } 41 }
39 42
40 const char* ScreenOrientationController::supplementName() 43 const char* ScreenOrientationController::supplementName()
41 { 44 {
42 return "ScreenOrientationController"; 45 return "ScreenOrientationController";
43 } 46 }
44 47
45 // Compute the screen orientation using the orientation angle and the screen wid th / height. 48 // Compute the screen orientation using the orientation angle and the screen wid th / height.
46 blink::WebScreenOrientationType ScreenOrientationController::computeOrientation( FrameView* view) 49 blink::WebScreenOrientationType ScreenOrientationController::computeOrientation( FrameView* view)
(...skipping 20 matching lines...) Expand all
67 ASSERT_NOT_REACHED(); 70 ASSERT_NOT_REACHED();
68 return blink::WebScreenOrientationPortraitPrimary; 71 return blink::WebScreenOrientationPortraitPrimary;
69 } 72 }
70 } 73 }
71 74
72 void ScreenOrientationController::pageVisibilityChanged() 75 void ScreenOrientationController::pageVisibilityChanged()
73 { 76 {
74 if (page() && page()->visibilityState() == PageVisibilityStateVisible) { 77 if (page() && page()->visibilityState() == PageVisibilityStateVisible) {
75 blink::WebScreenOrientationType oldOrientation = m_overrideOrientation; 78 blink::WebScreenOrientationType oldOrientation = m_overrideOrientation;
76 m_overrideOrientation = blink::WebScreenOrientationUndefined; 79 m_overrideOrientation = blink::WebScreenOrientationUndefined;
77 LocalFrame* mainFrame = m_document.frame(); 80 LocalFrame* mainFrame = page()->mainFrame();
78 if (mainFrame && oldOrientation != orientation()) 81 if (mainFrame && oldOrientation != orientation())
79 mainFrame->sendOrientationChangeEvent(); 82 mainFrame->sendOrientationChangeEvent();
80 } else if (m_overrideOrientation == blink::WebScreenOrientationUndefined) { 83 } else if (m_overrideOrientation == blink::WebScreenOrientationUndefined) {
81 // 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
82 // so that we keep returning this orientation until the page becomes 85 // so that we keep returning this orientation until the page becomes
83 // visible again. 86 // visible again.
84 m_overrideOrientation = orientation(); 87 m_overrideOrientation = orientation();
85 } 88 }
86 } 89 }
87 90
88 blink::WebScreenOrientationType ScreenOrientationController::orientation() const 91 blink::WebScreenOrientationType ScreenOrientationController::orientation() const
89 { 92 {
90 if (m_overrideOrientation != blink::WebScreenOrientationUndefined) { 93 if (m_overrideOrientation != blink::WebScreenOrientationUndefined) {
91 // 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.
92 ASSERT(!page() || page()->visibilityState() != PageVisibilityStateVisibl e); 95 ASSERT(!page() || page()->visibilityState() != PageVisibilityStateVisibl e);
93 return m_overrideOrientation; 96 return m_overrideOrientation;
94 } 97 }
95 98
96 LocalFrame* mainFrame = m_document.frame(); 99 LocalFrame* mainFrame = page() ? page()->mainFrame() : 0;
97 if (!mainFrame) 100 if (!mainFrame)
98 return blink::WebScreenOrientationPortraitPrimary; 101 return blink::WebScreenOrientationPortraitPrimary;
99 blink::WebScreenOrientationType orientationType = screenOrientationType(main Frame->view()); 102 blink::WebScreenOrientationType orientationType = screenOrientationType(main Frame->view());
100 if (orientationType == blink::WebScreenOrientationUndefined) { 103 if (orientationType == blink::WebScreenOrientationUndefined) {
101 // The embedder could not provide us with an orientation, deduce it ours elves. 104 // The embedder could not provide us with an orientation, deduce it ours elves.
102 orientationType = computeOrientation(mainFrame->view()); 105 orientationType = computeOrientation(mainFrame->view());
103 } 106 }
104 ASSERT(orientationType != blink::WebScreenOrientationUndefined); 107 ASSERT(orientationType != blink::WebScreenOrientationUndefined);
105 return orientationType; 108 return orientationType;
106 } 109 }
107 110
111 void ScreenOrientationController::lockOrientation(blink::WebScreenOrientationLoc kType orientation, blink::WebLockOrientationCallback* callback)
112 {
113 if (!m_client) {
114 // FIXME: temporary until the content layer gets updated.
115 blink::Platform::current()->lockOrientation(orientation, callback);
116 return;
117 }
118
119 m_client->lockOrientation(orientation, callback);
120 }
121
122 void ScreenOrientationController::unlockOrientation()
123 {
124 if (!m_client) {
125 // FIXME: temporary until the content layer gets updated.
126 blink::Platform::current()->unlockOrientation();
127 return;
128 }
129
130 m_client->unlockOrientation();
131 }
132
108 } // namespace WebCore 133 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698