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

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

Issue 280283002: Stop firing orientationchange events at pages that are not visible (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Take feedback into consideration 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 | Annotate | Revision Log
« no previous file with comments | « Source/modules/screen_orientation/ScreenOrientationController.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "platform/LayoutTestSupport.h" 14 #include "platform/LayoutTestSupport.h"
14 #include "platform/PlatformScreen.h" 15 #include "platform/PlatformScreen.h"
15 16
16 namespace WebCore { 17 namespace WebCore {
17 18
18 DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(ScreenOrientationController) 19 DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(ScreenOrientationController)
19 20
20 ScreenOrientationController& ScreenOrientationController::from(Document& documen t) 21 ScreenOrientationController& ScreenOrientationController::from(Document& documen t)
21 { 22 {
22 ScreenOrientationController* controller = static_cast<ScreenOrientationContr oller*>(DocumentSupplement::from(document, supplementName())); 23 ScreenOrientationController* controller = static_cast<ScreenOrientationContr oller*>(DocumentSupplement::from(document, supplementName()));
23 if (!controller) { 24 if (!controller) {
24 controller = new ScreenOrientationController(document); 25 controller = new ScreenOrientationController(document);
25 DocumentSupplement::provideTo(document, supplementName(), adoptPtrWillBe Noop(controller)); 26 DocumentSupplement::provideTo(document, supplementName(), adoptPtrWillBe Noop(controller));
26 } 27 }
27 return *controller; 28 return *controller;
28 } 29 }
29 30
30 ScreenOrientationController::ScreenOrientationController(Document& document) 31 ScreenOrientationController::ScreenOrientationController(Document& document)
31 : m_document(document) 32 : PageLifecycleObserver(document.page())
33 , m_document(document)
34 , m_overrideOrientation(blink::WebScreenOrientationUndefined)
32 { 35 {
33 } 36 }
34 37
35 const char* ScreenOrientationController::supplementName() 38 const char* ScreenOrientationController::supplementName()
36 { 39 {
37 return "ScreenOrientationController"; 40 return "ScreenOrientationController";
38 } 41 }
39 42
40 // Compute the screen orientation using the orientation angle and the screen wid th / height. 43 // Compute the screen orientation using the orientation angle and the screen wid th / height.
41 blink::WebScreenOrientationType ScreenOrientationController::computeOrientation( FrameView* view) 44 blink::WebScreenOrientationType ScreenOrientationController::computeOrientation( FrameView* view)
(...skipping 15 matching lines...) Expand all
57 case 180: 60 case 180:
58 return isTallDisplay ? blink::WebScreenOrientationPortraitSecondary : bl ink::WebScreenOrientationLandscapeSecondary; 61 return isTallDisplay ? blink::WebScreenOrientationPortraitSecondary : bl ink::WebScreenOrientationLandscapeSecondary;
59 case 270: 62 case 270:
60 return isTallDisplay ? blink::WebScreenOrientationLandscapeSecondary : b link::WebScreenOrientationPortraitPrimary; 63 return isTallDisplay ? blink::WebScreenOrientationLandscapeSecondary : b link::WebScreenOrientationPortraitPrimary;
61 default: 64 default:
62 ASSERT_NOT_REACHED(); 65 ASSERT_NOT_REACHED();
63 return blink::WebScreenOrientationPortraitPrimary; 66 return blink::WebScreenOrientationPortraitPrimary;
64 } 67 }
65 } 68 }
66 69
70 void ScreenOrientationController::pageVisibilityChanged()
71 {
72 if (page() && page()->visibilityState() == PageVisibilityStateVisible) {
73 blink::WebScreenOrientationType oldOrientation = m_overrideOrientation;
74 m_overrideOrientation = blink::WebScreenOrientationUndefined;
75 LocalFrame* mainFrame = m_document.frame();
76 if (mainFrame && oldOrientation != orientation())
77 mainFrame->sendOrientationChangeEvent();
78 } else if (m_overrideOrientation == blink::WebScreenOrientationUndefined) {
79 // The page is no longer visible, store the last know screen orientation
80 // so that we keep returning this orientation until the page becomes
81 // visible again.
82 m_overrideOrientation = orientation();
83 }
84 }
85
67 blink::WebScreenOrientationType ScreenOrientationController::orientation() const 86 blink::WebScreenOrientationType ScreenOrientationController::orientation() const
68 { 87 {
88 if (m_overrideOrientation != blink::WebScreenOrientationUndefined) {
89 // The page is not visible, keep returning the last known screen orienta tion.
90 ASSERT(!page() || page()->visibilityState() != PageVisibilityStateVisibl e);
91 return m_overrideOrientation;
92 }
93
69 LocalFrame* mainFrame = m_document.frame(); 94 LocalFrame* mainFrame = m_document.frame();
70 if (!mainFrame) 95 if (!mainFrame)
71 return blink::WebScreenOrientationPortraitPrimary; 96 return blink::WebScreenOrientationPortraitPrimary;
72 blink::WebScreenOrientationType orientationType = screenOrientationType(main Frame->view()); 97 blink::WebScreenOrientationType orientationType = screenOrientationType(main Frame->view());
73 if (orientationType == blink::WebScreenOrientationUndefined) { 98 if (orientationType == blink::WebScreenOrientationUndefined) {
74 // The embedder could not provide us with an orientation, deduce it ours elves. 99 // The embedder could not provide us with an orientation, deduce it ours elves.
75 orientationType = computeOrientation(mainFrame->view()); 100 orientationType = computeOrientation(mainFrame->view());
76 } 101 }
77 ASSERT(orientationType != blink::WebScreenOrientationUndefined); 102 ASSERT(orientationType != blink::WebScreenOrientationUndefined);
78 return orientationType; 103 return orientationType;
79 } 104 }
80 105
81 } // namespace WebCore 106 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/modules/screen_orientation/ScreenOrientationController.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698