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