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

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

Issue 277413002: Make screen.orientation implementation use WebScreenInfo::orientationType (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Disable screen orientation detection in layout tests Created 6 years, 7 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
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/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"
12 #include "core/frame/LocalFrame.h"
11 #include "core/frame/Screen.h" 13 #include "core/frame/Screen.h"
12 #include "modules/screen_orientation/ScreenOrientationDispatcher.h" 14 #include "platform/LayoutTestSupport.h"
15 #include "platform/PlatformScreen.h"
13 16
14 namespace WebCore { 17 namespace WebCore {
15 18
16 #if !ENABLE(OILPAN)
17 ScreenOrientationController::~ScreenOrientationController() 19 ScreenOrientationController::~ScreenOrientationController()
18 { 20 {
19 // With oilpan, weak processing removes the controller once it is dead.
20 ScreenOrientationDispatcher::instance().removeController(this);
21 } 21 }
22 #endif
23 22
24 ScreenOrientationController& ScreenOrientationController::from(Document& documen t) 23 ScreenOrientationController& ScreenOrientationController::from(Document& documen t)
25 { 24 {
26 ScreenOrientationController* controller = static_cast<ScreenOrientationContr oller*>(DocumentSupplement::from(document, supplementName())); 25 ScreenOrientationController* controller = static_cast<ScreenOrientationContr oller*>(DocumentSupplement::from(document, supplementName()));
27 if (!controller) { 26 if (!controller) {
28 controller = new ScreenOrientationController(document); 27 controller = new ScreenOrientationController(document);
29 DocumentSupplement::provideTo(document, supplementName(), adoptPtrWillBe Noop(controller)); 28 DocumentSupplement::provideTo(document, supplementName(), adoptPtrWillBe Noop(controller));
30 } 29 }
31 return *controller; 30 return *controller;
32 } 31 }
33 32
34 ScreenOrientationController::ScreenOrientationController(Document& document) 33 ScreenOrientationController::ScreenOrientationController(Document& document)
35 : m_document(document) 34 : m_document(document)
36 , m_orientation(blink::WebScreenOrientationPortraitPrimary)
37 { 35 {
38 // FIXME: We should listen for screen orientation change events only when th e page is visible.
39 ScreenOrientationDispatcher::instance().addController(this);
40 }
41
42 void ScreenOrientationController::dispatchOrientationChangeEvent()
43 {
44 if (m_document.domWindow()
45 && !m_document.activeDOMObjectsAreSuspended()
46 && !m_document.activeDOMObjectsAreStopped())
47 m_document.domWindow()->dispatchEvent(Event::create(EventTypeNames::orie ntationchange));
48 } 36 }
49 37
50 const char* ScreenOrientationController::supplementName() 38 const char* ScreenOrientationController::supplementName()
51 { 39 {
52 return "ScreenOrientationController"; 40 return "ScreenOrientationController";
53 } 41 }
54 42
55 void ScreenOrientationController::didChangeScreenOrientation(blink::WebScreenOri entationType orientation) 43 // Compute the screen orientation using the orientation angle and the screen wid th / height.
44 blink::WebScreenOrientationType ScreenOrientationController::computeOrientation( FrameView* view)
56 { 45 {
57 if (orientation == m_orientation) 46 // Bypass orientation detection in layout tests to get consistent results.
58 return; 47 if (isRunningLayoutTest())
48 return blink::WebScreenOrientationPortraitPrimary;
mlamouri (slow - plz ping) 2014/05/19 14:06:15 That means we will not get test coverage for this
Inactive 2014/05/19 15:14:30 The issue is that depending on the machine where t
mlamouri (slow - plz ping) 2014/05/20 20:09:25 Sure, this could be done in a follow-up. We could
59 49
60 m_orientation = orientation; 50 FloatRect rect = screenRect(view);
61 dispatchOrientationChangeEvent(); 51 uint16_t rotation = screenOrientationAngle(view);
52 bool isTallDisplay = rotation % 180 ? rect.height() < rect.width() : rect.he ight() > rect.width();
mlamouri (slow - plz ping) 2014/05/19 14:06:15 Hmm, I feel like I'm missing something here. Shoul
Inactive 2014/05/19 15:14:30 Well, I tested on an Android phone and it worked s
mlamouri (slow - plz ping) 2014/05/20 20:09:25 Sorry, my bad. I got confused with (rotation % 180
53 switch (rotation) {
54 case 0:
55 return isTallDisplay ? blink::WebScreenOrientationPortraitPrimary : blin k::WebScreenOrientationLandscapePrimary;
56 case 90:
57 return isTallDisplay ? blink::WebScreenOrientationLandscapePrimary : bli nk::WebScreenOrientationPortraitSecondary;
mlamouri (slow - plz ping) 2014/05/19 14:06:15 Why did you pick those values here?
Inactive 2014/05/19 15:14:30 Not sure I understand the question. Those are the
mlamouri (slow - plz ping) 2014/05/20 20:09:25 Nothing was wrong, I was wondering what you used t
58 case 180:
59 return isTallDisplay ? blink::WebScreenOrientationPortraitSecondary : bl ink::WebScreenOrientationLandscapeSecondary;
60 case 270:
61 return isTallDisplay ? blink::WebScreenOrientationLandscapeSecondary : b link::WebScreenOrientationPortraitPrimary;
62 default:
63 ASSERT_NOT_REACHED();
64 return blink::WebScreenOrientationPortraitPrimary;
65 }
66 }
67
68 blink::WebScreenOrientationType ScreenOrientationController::orientation() const
69 {
70 LocalFrame* mainFrame = m_document.frame();
71 if (!mainFrame)
72 return blink::WebScreenOrientationPortraitPrimary;
73 blink::WebScreenOrientationType orientationType = screenOrientationType(main Frame->view());
74 if (orientationType == blink::WebScreenOrientationUndefined) {
75 // The embedder could not provide us with an orientation, deduce it ours elves.
76 orientationType = computeOrientation(mainFrame->view());
77 }
78 ASSERT(orientationType != blink::WebScreenOrientationUndefined);
79 return orientationType;
62 } 80 }
63 81
64 } // namespace WebCore 82 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698