Index: content/renderer/screen_orientation/mock_screen_orientation_controller.h |
diff --git a/content/renderer/screen_orientation/mock_screen_orientation_controller.h b/content/renderer/screen_orientation/mock_screen_orientation_controller.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..0673db96f96b4ce4110e69729ea1887039be7a2f |
--- /dev/null |
+++ b/content/renderer/screen_orientation/mock_screen_orientation_controller.h |
@@ -0,0 +1,130 @@ |
+// Copyright (c) 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef CONTENT_RENDERER_SCREEN_ORIENTATION_MOCK_SCREEN_ORIENTATION_CONTROLLER_H_ |
+#define CONTENT_RENDERER_SCREEN_ORIENTATION_MOCK_SCREEN_ORIENTATION_CONTROLLER_H_ |
+ |
+#include "third_party/WebKit/public/platform/WebScreenOrientationListener.h" |
+#include "third_party/WebKit/public/platform/WebScreenOrientationLockType.h" |
+#include "third_party/WebKit/public/platform/WebScreenOrientationType.h" |
+ |
+namespace content { |
+ |
+class MockScreenOrientationController { |
+ public: |
+ MockScreenOrientationController(); |
+ |
+ void SetListener(blink::WebScreenOrientationListener* listener) { |
+ listener_ = listener; |
+ } |
+ |
+ void ResetData(); |
+ void UpdateLock(blink::WebScreenOrientationLockType); |
+ void ResetLock(); |
+ void UpdateDeviceOrientation(blink::WebScreenOrientationType); |
+ |
+ private: |
+ void UpdateScreenOrientation(blink::WebScreenOrientationType); |
+ bool IsOrientationAllowedByCurrentLock(blink::WebScreenOrientationType); |
+ blink::WebScreenOrientationType SuitableOrientationForCurrentLock(); |
+ |
+ blink::WebScreenOrientationLockType current_lock_; |
+ blink::WebScreenOrientationType device_orientation_; |
+ blink::WebScreenOrientationType current_orientation_; |
+ blink::WebScreenOrientationListener* listener_; |
+}; |
jochen (gone - plz use gerrit)
2014/05/14 09:10:54
disallow copy & assign
Inactive
2014/05/14 13:33:03
Done.
|
+ |
+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.
|
+ : current_lock_(blink::WebScreenOrientationLockDefault), |
+ device_orientation_(blink::WebScreenOrientationPortraitPrimary), |
+ current_orientation_(blink::WebScreenOrientationPortraitPrimary), |
+ listener_(NULL) { |
+} |
+ |
+void MockScreenOrientationController::ResetData() { |
+ current_lock_ = blink::WebScreenOrientationLockDefault; |
+ device_orientation_ = blink::WebScreenOrientationPortraitPrimary; |
+ current_orientation_ = blink::WebScreenOrientationPortraitPrimary; |
+} |
+ |
+void MockScreenOrientationController::UpdateLock( |
+ blink::WebScreenOrientationLockType lock) { |
+ DCHECK(lock != blink::WebScreenOrientationLockDefault); |
+ current_lock_ = lock; |
+ if (IsOrientationAllowedByCurrentLock(current_orientation_)) |
+ UpdateScreenOrientation(SuitableOrientationForCurrentLock()); |
+} |
+ |
+void MockScreenOrientationController::ResetLock() { |
+ bool will_screen_orientation_need_updating = |
+ !IsOrientationAllowedByCurrentLock(device_orientation_); |
+ current_lock_ = blink::WebScreenOrientationLockDefault; |
+ if (will_screen_orientation_need_updating) |
+ UpdateScreenOrientation(device_orientation_); |
+} |
+ |
+void MockScreenOrientationController::UpdateDeviceOrientation( |
+ blink::WebScreenOrientationType orientation) { |
+ if (device_orientation_ == orientation) |
+ return; |
+ device_orientation_ = orientation; |
+ if (!IsOrientationAllowedByCurrentLock(orientation)) |
+ return; |
+ UpdateScreenOrientation(orientation); |
+} |
+ |
+void MockScreenOrientationController::UpdateScreenOrientation( |
+ blink::WebScreenOrientationType orientation) { |
+ if (current_orientation_ == orientation) |
+ return; |
+ current_orientation_ = orientation; |
+ if (listener_) |
+ listener_->didChangeScreenOrientation(current_orientation_); |
+} |
+ |
+bool MockScreenOrientationController::IsOrientationAllowedByCurrentLock( |
+ blink::WebScreenOrientationType orientation) { |
+ if (current_lock_ == blink::WebScreenOrientationLockDefault || |
+ current_lock_ == blink::WebScreenOrientationLockAny) { |
+ return true; |
+ } |
+ |
+ switch (orientation) { |
+ case blink::WebScreenOrientationPortraitPrimary: |
+ return current_lock_ == blink::WebScreenOrientationLockPortraitPrimary || |
+ current_lock_ == blink::WebScreenOrientationLockPortrait; |
+ case blink::WebScreenOrientationPortraitSecondary: |
+ return current_lock_ == |
+ blink::WebScreenOrientationLockPortraitSecondary || |
+ current_lock_ == blink::WebScreenOrientationLockPortrait; |
+ case blink::WebScreenOrientationLandscapePrimary: |
+ return current_lock_ == blink::WebScreenOrientationLockLandscapePrimary || |
+ current_lock_ == blink::WebScreenOrientationLockLandscape; |
+ case blink::WebScreenOrientationLandscapeSecondary: |
+ return current_lock_ == |
+ blink::WebScreenOrientationLockLandscapeSecondary || |
+ current_lock_ == blink::WebScreenOrientationLockLandscape; |
+ default: |
+ return false; |
+ } |
+} |
+ |
+blink::WebScreenOrientationType |
+MockScreenOrientationController::SuitableOrientationForCurrentLock() { |
+ switch (current_lock_) { |
+ case blink::WebScreenOrientationLockPortraitSecondary: |
+ return blink::WebScreenOrientationPortraitSecondary; |
+ case blink::WebScreenOrientationLockLandscapePrimary: |
+ case blink::WebScreenOrientationLockLandscape: |
+ return blink::WebScreenOrientationLandscapePrimary; |
+ case blink::WebScreenOrientationLockLandscapeSecondary: |
+ return blink::WebScreenOrientationLandscapePrimary; |
+ default: |
+ return blink::WebScreenOrientationPortraitPrimary; |
+ } |
+} |
+ |
+} // namespace content |
+ |
+#endif // CONTENT_RENDERER_SCREEN_ORIENTATION_MOCK_SCREEN_ORIENTATION_CONTROLLER_H_ |