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

Side by Side Diff: Source/modules/screen_orientation/testing/ScreenOrientationClientMock.cpp

Issue 132113006: Add initial Blink-side support for the Screen Orientation API (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Update compile-time assertion for matching enum 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 "ScreenOrientationClientMock.h"
7
8 #include "modules/screen_orientation/ScreenOrientationController.h"
9
10 namespace WebCore {
11
12 ScreenOrientationClientMock::ScreenOrientationClientMock()
13 : m_controllerTimer(this, &ScreenOrientationClientMock::controllerTimerFired )
14 , m_controller(0)
15 , m_orientation(OrientationPortraitPrimary)
16 , m_lockedOrientations(OrientationAny)
17 {
18 }
19
20 ScreenOrientationClientMock::~ScreenOrientationClientMock()
21 {
22 }
23
24 void ScreenOrientationClientMock::setController(ScreenOrientationController* con troller)
25 {
26 ASSERT(controller && !m_controller);
27 m_controller = controller;
28 }
29
30 void ScreenOrientationClientMock::setScreenOrientation(ScreenOrientationValue or ientation)
31 {
32 if (orientation == m_orientation)
33 return;
34
35 m_orientation = orientation;
36 if (m_lockedOrientations & orientation)
37 asyncUpdateController();
38 }
39
40 void ScreenOrientationClientMock::asyncUpdateController()
41 {
42 ASSERT(m_controller);
43 if (!m_controllerTimer.isActive())
44 m_controllerTimer.startOneShot(0);
45 }
46
47 void ScreenOrientationClientMock::controllerTimerFired(Timer<ScreenOrientationCl ientMock>* timer)
48 {
49 ASSERT_UNUSED(timer, timer == &m_controllerTimer);
50 ASSERT(m_controller);
51
52 m_controller->orientationChanged(m_orientation);
53 }
54
55 void ScreenOrientationClientMock::maybeUpdateOrientationAfterLocking()
56 {
57 if (m_orientation & m_lockedOrientations)
58 return;
59
60 // We need to change our current screen orientation to meet the locking requ irements.
61 ScreenOrientationValue supportedOrientationValues[] = {
62 OrientationPortraitPrimary,
63 OrientationLandscapePrimary,
64 OrientationPortraitSecondary,
65 OrientationLandscapeSecondary
66 };
67
68 for (unsigned i = 0; i < WTF_ARRAY_LENGTH(supportedOrientationValues); ++i) {
69 if (m_lockedOrientations & supportedOrientationValues[i]) {
70 m_orientation = supportedOrientationValues[i];
71 asyncUpdateController();
72 return;
73 }
74 }
75 ASSERT_NOT_REACHED();
76 }
77
78 void ScreenOrientationClientMock::lockOrientation(ScreenOrientationValues orient ations)
79 {
80 m_lockedOrientations = orientations;
81 maybeUpdateOrientationAfterLocking();
82 }
83
84 void ScreenOrientationClientMock::unlockOrientation()
85 {
86 m_lockedOrientations = OrientationAny;
87 if (m_orientation != m_controller->orientation())
88 asyncUpdateController();
89 }
90
91 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698