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" | |
| 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; | |
|
jochen (gone - plz use gerrit)
2014/05/26 10:02:11
i thought we use fixed widht/height during layout
Inactive
2014/05/26 16:42:38
I will double check but last I checked (not long a
Inactive
2014/05/27 14:22:15
I have just verified that screen.width returns 192
| |
| 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(); | |
| 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; | |
| 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 |
| OLD | NEW |