Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 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 #ifndef CONTENT_RENDERER_SCREEN_ORIENTATION_MOCK_SCREEN_ORIENTATION_CONTROLLER_H _ | |
| 6 #define CONTENT_RENDERER_SCREEN_ORIENTATION_MOCK_SCREEN_ORIENTATION_CONTROLLER_H _ | |
| 7 | |
| 8 #include "third_party/WebKit/public/platform/WebScreenOrientationListener.h" | |
| 9 #include "third_party/WebKit/public/platform/WebScreenOrientationLockType.h" | |
| 10 #include "third_party/WebKit/public/platform/WebScreenOrientationType.h" | |
| 11 | |
| 12 namespace content { | |
| 13 | |
| 14 class MockScreenOrientationController { | |
| 15 public: | |
| 16 MockScreenOrientationController(); | |
| 17 | |
| 18 void SetListener(blink::WebScreenOrientationListener* listener) { | |
| 19 listener_ = listener; | |
| 20 } | |
| 21 | |
| 22 void ResetData(); | |
| 23 void UpdateLock(blink::WebScreenOrientationLockType); | |
| 24 void ResetLock(); | |
| 25 void UpdateDeviceOrientation(blink::WebScreenOrientationType); | |
| 26 | |
| 27 private: | |
| 28 void UpdateScreenOrientation(blink::WebScreenOrientationType); | |
| 29 bool IsOrientationAllowedByCurrentLock(blink::WebScreenOrientationType); | |
| 30 blink::WebScreenOrientationType SuitableOrientationForCurrentLock(); | |
| 31 | |
| 32 blink::WebScreenOrientationLockType current_lock_; | |
| 33 blink::WebScreenOrientationType device_orientation_; | |
| 34 blink::WebScreenOrientationType current_orientation_; | |
| 35 blink::WebScreenOrientationListener* listener_; | |
| 36 }; | |
|
jochen (gone - plz use gerrit)
2014/05/14 09:10:54
disallow copy & assign
Inactive
2014/05/14 13:33:03
Done.
| |
| 37 | |
| 38 MockScreenOrientationController::MockScreenOrientationController() | |
|
jochen (gone - plz use gerrit)
2014/05/14 09:10:54
please put the implementation into a .cc file
Inactive
2014/05/14 13:33:03
Done.
| |
| 39 : current_lock_(blink::WebScreenOrientationLockDefault), | |
| 40 device_orientation_(blink::WebScreenOrientationPortraitPrimary), | |
| 41 current_orientation_(blink::WebScreenOrientationPortraitPrimary), | |
| 42 listener_(NULL) { | |
| 43 } | |
| 44 | |
| 45 void MockScreenOrientationController::ResetData() { | |
| 46 current_lock_ = blink::WebScreenOrientationLockDefault; | |
| 47 device_orientation_ = blink::WebScreenOrientationPortraitPrimary; | |
| 48 current_orientation_ = blink::WebScreenOrientationPortraitPrimary; | |
| 49 } | |
| 50 | |
| 51 void MockScreenOrientationController::UpdateLock( | |
| 52 blink::WebScreenOrientationLockType lock) { | |
| 53 DCHECK(lock != blink::WebScreenOrientationLockDefault); | |
| 54 current_lock_ = lock; | |
| 55 if (IsOrientationAllowedByCurrentLock(current_orientation_)) | |
| 56 UpdateScreenOrientation(SuitableOrientationForCurrentLock()); | |
| 57 } | |
| 58 | |
| 59 void MockScreenOrientationController::ResetLock() { | |
| 60 bool will_screen_orientation_need_updating = | |
| 61 !IsOrientationAllowedByCurrentLock(device_orientation_); | |
| 62 current_lock_ = blink::WebScreenOrientationLockDefault; | |
| 63 if (will_screen_orientation_need_updating) | |
| 64 UpdateScreenOrientation(device_orientation_); | |
| 65 } | |
| 66 | |
| 67 void MockScreenOrientationController::UpdateDeviceOrientation( | |
| 68 blink::WebScreenOrientationType orientation) { | |
| 69 if (device_orientation_ == orientation) | |
| 70 return; | |
| 71 device_orientation_ = orientation; | |
| 72 if (!IsOrientationAllowedByCurrentLock(orientation)) | |
| 73 return; | |
| 74 UpdateScreenOrientation(orientation); | |
| 75 } | |
| 76 | |
| 77 void MockScreenOrientationController::UpdateScreenOrientation( | |
| 78 blink::WebScreenOrientationType orientation) { | |
| 79 if (current_orientation_ == orientation) | |
| 80 return; | |
| 81 current_orientation_ = orientation; | |
| 82 if (listener_) | |
| 83 listener_->didChangeScreenOrientation(current_orientation_); | |
| 84 } | |
| 85 | |
| 86 bool MockScreenOrientationController::IsOrientationAllowedByCurrentLock( | |
| 87 blink::WebScreenOrientationType orientation) { | |
| 88 if (current_lock_ == blink::WebScreenOrientationLockDefault || | |
| 89 current_lock_ == blink::WebScreenOrientationLockAny) { | |
| 90 return true; | |
| 91 } | |
| 92 | |
| 93 switch (orientation) { | |
| 94 case blink::WebScreenOrientationPortraitPrimary: | |
| 95 return current_lock_ == blink::WebScreenOrientationLockPortraitPrimary || | |
| 96 current_lock_ == blink::WebScreenOrientationLockPortrait; | |
| 97 case blink::WebScreenOrientationPortraitSecondary: | |
| 98 return current_lock_ == | |
| 99 blink::WebScreenOrientationLockPortraitSecondary || | |
| 100 current_lock_ == blink::WebScreenOrientationLockPortrait; | |
| 101 case blink::WebScreenOrientationLandscapePrimary: | |
| 102 return current_lock_ == blink::WebScreenOrientationLockLandscapePrimary || | |
| 103 current_lock_ == blink::WebScreenOrientationLockLandscape; | |
| 104 case blink::WebScreenOrientationLandscapeSecondary: | |
| 105 return current_lock_ == | |
| 106 blink::WebScreenOrientationLockLandscapeSecondary || | |
| 107 current_lock_ == blink::WebScreenOrientationLockLandscape; | |
| 108 default: | |
| 109 return false; | |
| 110 } | |
| 111 } | |
| 112 | |
| 113 blink::WebScreenOrientationType | |
| 114 MockScreenOrientationController::SuitableOrientationForCurrentLock() { | |
| 115 switch (current_lock_) { | |
| 116 case blink::WebScreenOrientationLockPortraitSecondary: | |
| 117 return blink::WebScreenOrientationPortraitSecondary; | |
| 118 case blink::WebScreenOrientationLockLandscapePrimary: | |
| 119 case blink::WebScreenOrientationLockLandscape: | |
| 120 return blink::WebScreenOrientationLandscapePrimary; | |
| 121 case blink::WebScreenOrientationLockLandscapeSecondary: | |
| 122 return blink::WebScreenOrientationLandscapePrimary; | |
| 123 default: | |
| 124 return blink::WebScreenOrientationPortraitPrimary; | |
| 125 } | |
| 126 } | |
| 127 | |
| 128 } // namespace content | |
| 129 | |
| 130 #endif // CONTENT_RENDERER_SCREEN_ORIENTATION_MOCK_SCREEN_ORIENTATION_CONTROLLER _H_ | |
| OLD | NEW |