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

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

Issue 169403006: Screen Orientation API: screen.orientation & orientationchange event (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fix nits Created 6 years, 10 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
(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 controller = new ScreenOrientationController(*document);
26 DocumentSupplement::provideTo(document, supplementName(), adoptPtr(contr oller));
27 }
28 return controller;
29 }
30
31 ScreenOrientationController::ScreenOrientationController(Document& document)
32 : m_document(document)
33 , m_orientation(blink::WebScreenOrientationPortraitPrimary)
34 {
35 // FIXME: We should listen for screen orientation change events only when th e page is visible.
36 ScreenOrientationDispatcher::instance().addController(this);
37 }
38
39 void ScreenOrientationController::dispatchOrientationChangeEvent()
40 {
41 if (m_document.domWindow() && m_document.domWindow()->screen()
42 && !m_document.activeDOMObjectsAreSuspended()
43 && !m_document.activeDOMObjectsAreStopped())
44 m_document.domWindow()->screen()->dispatchEvent(Event::create(EventTypeN ames::orientationchange));
45 }
46
47 const char* ScreenOrientationController::supplementName()
48 {
49 return "ScreenOrientationController";
50 }
51
52 void ScreenOrientationController::didChangeScreenOrientation(blink::WebScreenOri entation orientation)
53 {
54 if (orientation == m_orientation)
55 return;
56
57 m_orientation = orientation;
58 dispatchOrientationChangeEvent();
59 }
60
61 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698