OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "config.h" | |
6 #include "modules/screen_orientation/ScreenOrientationController.h" | |
7 | |
8 #include "core/dom/Document.h" | |
9 #include "core/events/Event.h" | |
10 #include "core/frame/DOMWindow.h" | |
11 #include "core/frame/Screen.h" | |
12 #include "modules/screen_orientation/ScreenOrientationDispatcher.h" | |
13 | |
14 namespace WebCore { | |
15 | |
16 ScreenOrientationController::~ScreenOrientationController() | |
17 { | |
18 ScreenOrientationDispatcher::instance().removeController(this); | |
19 } | |
20 | |
21 ScreenOrientationController* ScreenOrientationController::from(Document* documen t) | |
22 { | |
23 ScreenOrientationController* controller = static_cast<ScreenOrientationContr oller*>(DocumentSupplement::from(document, supplementName())); | |
24 if (!controller) { | |
25 ASSERT(document); | |
abarth-chromium
2014/02/19 18:51:49
We don't usually have this ASSERT here. The code
Inactive
2014/02/19 19:04:51
Done.
| |
26 controller = new ScreenOrientationController(*document); | |
27 DocumentSupplement::provideTo(document, supplementName(), adoptPtr(contr oller)); | |
28 } | |
29 return controller; | |
30 } | |
31 | |
32 ScreenOrientationController::ScreenOrientationController(Document& document) | |
33 : m_document(document) | |
34 // FIXME: This orientation is not necessary the right one until the first or ientationchange | |
35 // event is fired. | |
abarth-chromium
2014/02/19 18:51:49
I'd skip this FIXME
Inactive
2014/02/19 19:04:51
Done.
| |
36 , m_orientation(blink::WebScreenOrientationPortraitPrimary) | |
37 { | |
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() && m_document.domWindow()->screen() | |
45 && !m_document.activeDOMObjectsAreSuspended() | |
46 && !m_document.activeDOMObjectsAreStopped()) | |
47 m_document.domWindow()->screen()->dispatchEvent(Event::create(EventTypeN ames::orientationchange)); | |
48 } | |
49 | |
50 const char* ScreenOrientationController::supplementName() | |
51 { | |
52 return "ScreenOrientationController"; | |
53 } | |
54 | |
55 void ScreenOrientationController::didChangeScreenOrientation(blink::WebScreenOri entation orientation) | |
56 { | |
57 if (orientation == m_orientation) | |
58 return; | |
59 | |
60 m_orientation = orientation; | |
61 dispatchOrientationChangeEvent(); | |
62 } | |
63 | |
64 } // namespace WebCore | |
OLD | NEW |