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 : RenderViewObserver(NULL), |
| 17 current_lock_(blink::WebScreenOrientationLockDefault), |
16 device_orientation_(blink::WebScreenOrientationPortraitPrimary), | 18 device_orientation_(blink::WebScreenOrientationPortraitPrimary), |
17 current_orientation_(blink::WebScreenOrientationPortraitPrimary), | 19 current_orientation_(blink::WebScreenOrientationPortraitPrimary), |
18 listener_(NULL) { | 20 listener_(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) { |
29 listener_ = listener; | 31 listener_ = listener; |
30 } | 32 } |
31 | 33 |
32 void MockScreenOrientationController::ResetData() { | 34 void MockScreenOrientationController::ResetData() { |
| 35 if (render_view_impl()) |
| 36 render_view_impl()->RemoveObserver(this); |
| 37 |
33 current_lock_ = blink::WebScreenOrientationLockDefault; | 38 current_lock_ = blink::WebScreenOrientationLockDefault; |
34 device_orientation_ = blink::WebScreenOrientationPortraitPrimary; | 39 device_orientation_ = blink::WebScreenOrientationPortraitPrimary; |
35 current_orientation_ = blink::WebScreenOrientationPortraitPrimary; | 40 current_orientation_ = blink::WebScreenOrientationPortraitPrimary; |
36 } | 41 } |
37 | 42 |
38 void MockScreenOrientationController::UpdateLock( | 43 void MockScreenOrientationController::UpdateLock( |
39 blink::WebScreenOrientationLockType lock) { | 44 blink::WebScreenOrientationLockType lock) { |
40 base::MessageLoop::current()->PostTask( | 45 base::MessageLoop::current()->PostTask( |
41 FROM_HERE, | 46 FROM_HERE, |
42 base::Bind(&MockScreenOrientationController::UpdateLockSync, this, lock)); | 47 base::Bind(&MockScreenOrientationController::UpdateLockSync, this, lock)); |
(...skipping 14 matching lines...) Expand all Loading... |
57 | 62 |
58 void MockScreenOrientationController::ResetLockSync() { | 63 void MockScreenOrientationController::ResetLockSync() { |
59 bool will_screen_orientation_need_updating = | 64 bool will_screen_orientation_need_updating = |
60 !IsOrientationAllowedByCurrentLock(device_orientation_); | 65 !IsOrientationAllowedByCurrentLock(device_orientation_); |
61 current_lock_ = blink::WebScreenOrientationLockDefault; | 66 current_lock_ = blink::WebScreenOrientationLockDefault; |
62 if (will_screen_orientation_need_updating) | 67 if (will_screen_orientation_need_updating) |
63 UpdateScreenOrientation(device_orientation_); | 68 UpdateScreenOrientation(device_orientation_); |
64 } | 69 } |
65 | 70 |
66 void MockScreenOrientationController::UpdateDeviceOrientation( | 71 void MockScreenOrientationController::UpdateDeviceOrientation( |
| 72 RenderView* render_view, |
67 blink::WebScreenOrientationType orientation) { | 73 blink::WebScreenOrientationType orientation) { |
| 74 if (this->render_view()) { |
| 75 // Make sure that render_view_ did not change during test. |
| 76 DCHECK_EQ(this->render_view(), render_view); |
| 77 } else { |
| 78 Observe(render_view); |
| 79 } |
| 80 |
68 if (device_orientation_ == orientation) | 81 if (device_orientation_ == orientation) |
69 return; | 82 return; |
70 device_orientation_ = orientation; | 83 device_orientation_ = orientation; |
71 if (!IsOrientationAllowedByCurrentLock(orientation)) | 84 if (!IsOrientationAllowedByCurrentLock(orientation)) |
72 return; | 85 return; |
73 UpdateScreenOrientation(orientation); | 86 UpdateScreenOrientation(orientation); |
74 } | 87 } |
75 | 88 |
| 89 RenderViewImpl* MockScreenOrientationController::render_view_impl() const { |
| 90 return static_cast<RenderViewImpl*>(render_view()); |
| 91 } |
| 92 |
76 void MockScreenOrientationController::UpdateScreenOrientation( | 93 void MockScreenOrientationController::UpdateScreenOrientation( |
77 blink::WebScreenOrientationType orientation) { | 94 blink::WebScreenOrientationType orientation) { |
78 if (current_orientation_ == orientation) | 95 if (current_orientation_ == orientation) |
79 return; | 96 return; |
80 current_orientation_ = orientation; | 97 current_orientation_ = orientation; |
| 98 if (render_view_impl()) |
| 99 render_view_impl()->SetScreenOrientationForTesting(orientation); |
| 100 |
81 if (listener_) | 101 if (listener_) |
82 listener_->didChangeScreenOrientation(current_orientation_); | 102 listener_->didChangeScreenOrientation(current_orientation_); |
83 } | 103 } |
84 | 104 |
85 bool MockScreenOrientationController::IsOrientationAllowedByCurrentLock( | 105 bool MockScreenOrientationController::IsOrientationAllowedByCurrentLock( |
86 blink::WebScreenOrientationType orientation) { | 106 blink::WebScreenOrientationType orientation) { |
87 if (current_lock_ == blink::WebScreenOrientationLockDefault || | 107 if (current_lock_ == blink::WebScreenOrientationLockDefault || |
88 current_lock_ == blink::WebScreenOrientationLockAny) { | 108 current_lock_ == blink::WebScreenOrientationLockAny) { |
89 return true; | 109 return true; |
90 } | 110 } |
(...skipping 26 matching lines...) Expand all Loading... |
117 case blink::WebScreenOrientationLockLandscapePrimary: | 137 case blink::WebScreenOrientationLockLandscapePrimary: |
118 case blink::WebScreenOrientationLockLandscape: | 138 case blink::WebScreenOrientationLockLandscape: |
119 return blink::WebScreenOrientationLandscapePrimary; | 139 return blink::WebScreenOrientationLandscapePrimary; |
120 case blink::WebScreenOrientationLockLandscapeSecondary: | 140 case blink::WebScreenOrientationLockLandscapeSecondary: |
121 return blink::WebScreenOrientationLandscapePrimary; | 141 return blink::WebScreenOrientationLandscapePrimary; |
122 default: | 142 default: |
123 return blink::WebScreenOrientationPortraitPrimary; | 143 return blink::WebScreenOrientationPortraitPrimary; |
124 } | 144 } |
125 } | 145 } |
126 | 146 |
| 147 void MockScreenOrientationController::OnDestruct() { |
| 148 } |
| 149 |
127 } // namespace content | 150 } // namespace content |
OLD | NEW |