OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/renderer/screen_orientation/mock_screen_orientation_controller
.h" | 5 #include "content/renderer/screen_orientation/mock_screen_orientation_controller
.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "content/renderer/render_view_impl.h" |
10 #include "third_party/WebKit/public/platform/WebScreenOrientationListener.h" | 11 #include "third_party/WebKit/public/platform/WebScreenOrientationListener.h" |
11 | 12 |
12 namespace content { | 13 namespace content { |
13 | 14 |
14 MockScreenOrientationController::MockScreenOrientationController() | 15 MockScreenOrientationController::MockScreenOrientationController() |
15 : current_lock_(blink::WebScreenOrientationLockDefault), | 16 : current_lock_(blink::WebScreenOrientationLockDefault), |
16 device_orientation_(blink::WebScreenOrientationPortraitPrimary), | 17 device_orientation_(blink::WebScreenOrientationPortraitPrimary), |
17 current_orientation_(blink::WebScreenOrientationPortraitPrimary), | 18 current_orientation_(blink::WebScreenOrientationPortraitPrimary), |
18 listener_(NULL) { | 19 listener_(NULL), |
| 20 render_view_(NULL) { |
19 // Since MockScreenOrientationController is held by LazyInstance reference, | 21 // Since MockScreenOrientationController is held by LazyInstance reference, |
20 // add this ref for it. | 22 // add this ref for it. |
21 AddRef(); | 23 AddRef(); |
22 } | 24 } |
23 | 25 |
24 MockScreenOrientationController::~MockScreenOrientationController() { | 26 MockScreenOrientationController::~MockScreenOrientationController() { |
25 } | 27 } |
26 | 28 |
27 void MockScreenOrientationController::SetListener( | 29 void MockScreenOrientationController::SetListener( |
28 blink::WebScreenOrientationListener* listener) { | 30 blink::WebScreenOrientationListener* listener) { |
(...skipping 28 matching lines...) Expand all Loading... |
57 | 59 |
58 void MockScreenOrientationController::ResetLockSync() { | 60 void MockScreenOrientationController::ResetLockSync() { |
59 bool will_screen_orientation_need_updating = | 61 bool will_screen_orientation_need_updating = |
60 !IsOrientationAllowedByCurrentLock(device_orientation_); | 62 !IsOrientationAllowedByCurrentLock(device_orientation_); |
61 current_lock_ = blink::WebScreenOrientationLockDefault; | 63 current_lock_ = blink::WebScreenOrientationLockDefault; |
62 if (will_screen_orientation_need_updating) | 64 if (will_screen_orientation_need_updating) |
63 UpdateScreenOrientation(device_orientation_); | 65 UpdateScreenOrientation(device_orientation_); |
64 } | 66 } |
65 | 67 |
66 void MockScreenOrientationController::UpdateDeviceOrientation( | 68 void MockScreenOrientationController::UpdateDeviceOrientation( |
| 69 RenderView* render_view, |
67 blink::WebScreenOrientationType orientation) { | 70 blink::WebScreenOrientationType orientation) { |
| 71 // Make sure that render_view_ did not change during test. |
| 72 assert(!render_view_ || render_view_ == render_view); |
| 73 render_view_ = render_view; |
| 74 |
68 if (device_orientation_ == orientation) | 75 if (device_orientation_ == orientation) |
69 return; | 76 return; |
70 device_orientation_ = orientation; | 77 device_orientation_ = orientation; |
71 if (!IsOrientationAllowedByCurrentLock(orientation)) | 78 if (!IsOrientationAllowedByCurrentLock(orientation)) |
72 return; | 79 return; |
73 UpdateScreenOrientation(orientation); | 80 UpdateScreenOrientation(orientation); |
74 } | 81 } |
75 | 82 |
76 void MockScreenOrientationController::UpdateScreenOrientation( | 83 void MockScreenOrientationController::UpdateScreenOrientation( |
77 blink::WebScreenOrientationType orientation) { | 84 blink::WebScreenOrientationType orientation) { |
78 if (current_orientation_ == orientation) | 85 if (current_orientation_ == orientation) |
79 return; | 86 return; |
80 current_orientation_ = orientation; | 87 current_orientation_ = orientation; |
| 88 if (render_view_) |
| 89 static_cast<RenderViewImpl*>(render_view_) |
| 90 ->SetScreenOrientationForTesting(orientation); |
81 if (listener_) | 91 if (listener_) |
82 listener_->didChangeScreenOrientation(current_orientation_); | 92 listener_->didChangeScreenOrientation(current_orientation_); |
83 } | 93 } |
84 | 94 |
85 bool MockScreenOrientationController::IsOrientationAllowedByCurrentLock( | 95 bool MockScreenOrientationController::IsOrientationAllowedByCurrentLock( |
86 blink::WebScreenOrientationType orientation) { | 96 blink::WebScreenOrientationType orientation) { |
87 if (current_lock_ == blink::WebScreenOrientationLockDefault || | 97 if (current_lock_ == blink::WebScreenOrientationLockDefault || |
88 current_lock_ == blink::WebScreenOrientationLockAny) { | 98 current_lock_ == blink::WebScreenOrientationLockAny) { |
89 return true; | 99 return true; |
90 } | 100 } |
(...skipping 26 matching lines...) Expand all Loading... |
117 case blink::WebScreenOrientationLockLandscapePrimary: | 127 case blink::WebScreenOrientationLockLandscapePrimary: |
118 case blink::WebScreenOrientationLockLandscape: | 128 case blink::WebScreenOrientationLockLandscape: |
119 return blink::WebScreenOrientationLandscapePrimary; | 129 return blink::WebScreenOrientationLandscapePrimary; |
120 case blink::WebScreenOrientationLockLandscapeSecondary: | 130 case blink::WebScreenOrientationLockLandscapeSecondary: |
121 return blink::WebScreenOrientationLandscapePrimary; | 131 return blink::WebScreenOrientationLandscapePrimary; |
122 default: | 132 default: |
123 return blink::WebScreenOrientationPortraitPrimary; | 133 return blink::WebScreenOrientationPortraitPrimary; |
124 } | 134 } |
125 } | 135 } |
126 | 136 |
| 137 void MockScreenOrientationController::ResetRenderView() { |
| 138 render_view_ = 0; |
| 139 } |
| 140 |
127 } // namespace content | 141 } // namespace content |
OLD | NEW |