Chromium Code Reviews| 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/events/Event.h" | 9 #include "core/events/Event.h" |
| 10 #include "core/frame/DOMWindow.h" | 10 #include "core/frame/DOMWindow.h" |
| 11 #include "core/frame/FrameView.h" | 11 #include "core/frame/FrameView.h" |
| 12 #include "core/frame/LocalFrame.h" | 12 #include "core/frame/LocalFrame.h" |
| 13 #include "core/frame/Screen.h" | 13 #include "core/frame/Screen.h" |
| 14 #include "core/page/Page.h" | |
| 14 #include "platform/LayoutTestSupport.h" | 15 #include "platform/LayoutTestSupport.h" |
| 15 #include "platform/PlatformScreen.h" | 16 #include "platform/PlatformScreen.h" |
| 16 | 17 |
| 17 namespace WebCore { | 18 namespace WebCore { |
| 18 | 19 |
| 19 ScreenOrientationController::~ScreenOrientationController() | 20 ScreenOrientationController::~ScreenOrientationController() |
| 20 { | 21 { |
| 21 } | 22 } |
| 22 | 23 |
| 23 ScreenOrientationController& ScreenOrientationController::from(Document& documen t) | 24 ScreenOrientationController& ScreenOrientationController::from(Document& documen t) |
| 24 { | 25 { |
| 25 ScreenOrientationController* controller = static_cast<ScreenOrientationContr oller*>(DocumentSupplement::from(document, supplementName())); | 26 ScreenOrientationController* controller = static_cast<ScreenOrientationContr oller*>(DocumentSupplement::from(document, supplementName())); |
| 26 if (!controller) { | 27 if (!controller) { |
| 27 controller = new ScreenOrientationController(document); | 28 controller = new ScreenOrientationController(document); |
| 28 DocumentSupplement::provideTo(document, supplementName(), adoptPtrWillBe Noop(controller)); | 29 DocumentSupplement::provideTo(document, supplementName(), adoptPtrWillBe Noop(controller)); |
| 29 } | 30 } |
| 30 return *controller; | 31 return *controller; |
| 31 } | 32 } |
| 32 | 33 |
| 33 ScreenOrientationController::ScreenOrientationController(Document& document) | 34 ScreenOrientationController::ScreenOrientationController(Document& document) |
| 34 : m_document(document) | 35 : PageLifecycleObserver(document.page()) |
|
mlamouri (slow - plz ping)
2014/05/28 14:05:33
Can a document get detached and attached again?
Inactive
2014/05/28 15:27:28
I do not think so.
| |
| 36 , m_document(document) | |
| 37 , m_lastVisibleOrientation(blink::WebScreenOrientationUndefined) | |
| 35 { | 38 { |
| 36 } | 39 } |
| 37 | 40 |
| 38 const char* ScreenOrientationController::supplementName() | 41 const char* ScreenOrientationController::supplementName() |
| 39 { | 42 { |
| 40 return "ScreenOrientationController"; | 43 return "ScreenOrientationController"; |
| 41 } | 44 } |
| 42 | 45 |
| 43 // Compute the screen orientation using the orientation angle and the screen wid th / height. | 46 // Compute the screen orientation using the orientation angle and the screen wid th / height. |
| 44 blink::WebScreenOrientationType ScreenOrientationController::computeOrientation( FrameView* view) | 47 blink::WebScreenOrientationType ScreenOrientationController::computeOrientation( FrameView* view) |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 60 case 180: | 63 case 180: |
| 61 return isTallDisplay ? blink::WebScreenOrientationPortraitSecondary : bl ink::WebScreenOrientationLandscapeSecondary; | 64 return isTallDisplay ? blink::WebScreenOrientationPortraitSecondary : bl ink::WebScreenOrientationLandscapeSecondary; |
| 62 case 270: | 65 case 270: |
| 63 return isTallDisplay ? blink::WebScreenOrientationLandscapeSecondary : b link::WebScreenOrientationPortraitPrimary; | 66 return isTallDisplay ? blink::WebScreenOrientationLandscapeSecondary : b link::WebScreenOrientationPortraitPrimary; |
| 64 default: | 67 default: |
| 65 ASSERT_NOT_REACHED(); | 68 ASSERT_NOT_REACHED(); |
| 66 return blink::WebScreenOrientationPortraitPrimary; | 69 return blink::WebScreenOrientationPortraitPrimary; |
| 67 } | 70 } |
| 68 } | 71 } |
| 69 | 72 |
| 73 void ScreenOrientationController::pageVisibilityChanged() | |
| 74 { | |
| 75 if (page() && page()->visibilityState() == PageVisibilityStateVisible) { | |
| 76 m_lastVisibleOrientation = blink::WebScreenOrientationUndefined; | |
|
mlamouri (slow - plz ping)
2014/05/28 14:05:33
I think it would be appropriate to also fire an ev
Inactive
2014/05/28 15:27:28
Done.
| |
| 77 } else if (m_lastVisibleOrientation == blink::WebScreenOrientationUndefined) { | |
| 78 // The page is no longer visible, store the last know screen orientation | |
| 79 // so that we keep returning this orientation until the page becomes | |
| 80 // visible again. | |
| 81 m_lastVisibleOrientation = orientation(); | |
| 82 } | |
| 83 } | |
| 84 | |
| 70 blink::WebScreenOrientationType ScreenOrientationController::orientation() const | 85 blink::WebScreenOrientationType ScreenOrientationController::orientation() const |
| 71 { | 86 { |
| 87 if (m_lastVisibleOrientation != blink::WebScreenOrientationUndefined) { | |
|
mlamouri (slow - plz ping)
2014/05/28 14:05:33
I'm not a big fan of side effects like that (ie. m
Inactive
2014/05/28 15:27:28
I renamed the variable to m_overrideOrientation fo
| |
| 88 // The page is not visible, keep returning the last known screen orienta tion. | |
| 89 return m_lastVisibleOrientation; | |
| 90 } | |
| 91 | |
| 72 LocalFrame* mainFrame = m_document.frame(); | 92 LocalFrame* mainFrame = m_document.frame(); |
| 73 if (!mainFrame) | 93 if (!mainFrame) |
| 74 return blink::WebScreenOrientationPortraitPrimary; | 94 return blink::WebScreenOrientationPortraitPrimary; |
| 75 blink::WebScreenOrientationType orientationType = screenOrientationType(main Frame->view()); | 95 blink::WebScreenOrientationType orientationType = screenOrientationType(main Frame->view()); |
| 76 if (orientationType == blink::WebScreenOrientationUndefined) { | 96 if (orientationType == blink::WebScreenOrientationUndefined) { |
| 77 // The embedder could not provide us with an orientation, deduce it ours elves. | 97 // The embedder could not provide us with an orientation, deduce it ours elves. |
| 78 orientationType = computeOrientation(mainFrame->view()); | 98 orientationType = computeOrientation(mainFrame->view()); |
| 79 } | 99 } |
| 80 ASSERT(orientationType != blink::WebScreenOrientationUndefined); | 100 ASSERT(orientationType != blink::WebScreenOrientationUndefined); |
| 81 return orientationType; | 101 return orientationType; |
| 82 } | 102 } |
| 83 | 103 |
| 84 } // namespace WebCore | 104 } // namespace WebCore |
| OLD | NEW |