OLD | NEW |
---|---|
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 Loading... | |
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 ASSERT(page()); |
Inactive
2014/06/03 18:04:53
Why is this safe? This assertion above seems to hi
mlamouri (slow - plz ping)
2014/06/03 19:49:30
Done.
| |
100 LocalFrame* mainFrame = page()->mainFrame(); | |
97 if (!mainFrame) | 101 if (!mainFrame) |
98 return blink::WebScreenOrientationPortraitPrimary; | 102 return blink::WebScreenOrientationPortraitPrimary; |
99 blink::WebScreenOrientationType orientationType = screenOrientationType(main Frame->view()); | 103 blink::WebScreenOrientationType orientationType = screenOrientationType(main Frame->view()); |
100 if (orientationType == blink::WebScreenOrientationUndefined) { | 104 if (orientationType == blink::WebScreenOrientationUndefined) { |
101 // The embedder could not provide us with an orientation, deduce it ours elves. | 105 // The embedder could not provide us with an orientation, deduce it ours elves. |
102 orientationType = computeOrientation(mainFrame->view()); | 106 orientationType = computeOrientation(mainFrame->view()); |
103 } | 107 } |
104 ASSERT(orientationType != blink::WebScreenOrientationUndefined); | 108 ASSERT(orientationType != blink::WebScreenOrientationUndefined); |
105 return orientationType; | 109 return orientationType; |
106 } | 110 } |
107 | 111 |
112 void ScreenOrientationController::lockOrientation(blink::WebScreenOrientationLoc kType orientation, blink::WebLockOrientationCallback* callback) | |
113 { | |
114 if (!m_client) { | |
115 // FIXME: temporary until the content layer gets updated. | |
116 blink::Platform::current()->lockOrientation(orientation, callback); | |
117 return; | |
118 } | |
119 | |
120 m_client->lockOrientation(orientation, callback); | |
121 } | |
122 | |
123 void ScreenOrientationController::unlockOrientation() | |
124 { | |
125 if (!m_client) { | |
126 // FIXME: temporary until the content layer gets updated. | |
127 blink::Platform::current()->unlockOrientation(); | |
128 return; | |
129 } | |
130 | |
131 m_client->unlockOrientation(); | |
132 } | |
133 | |
108 } // namespace WebCore | 134 } // namespace WebCore |
OLD | NEW |