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 "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 |
OLD | NEW |