Chromium Code Reviews| 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) { |
| 29 listener_ = listener; | 31 listener_ = listener; |
| 30 } | 32 } |
| 31 | 33 |
| 32 void MockScreenOrientationController::ResetData() { | 34 void MockScreenOrientationController::ResetData() { |
| 35 render_view_ = 0; | |
| 33 current_lock_ = blink::WebScreenOrientationLockDefault; | 36 current_lock_ = blink::WebScreenOrientationLockDefault; |
| 34 device_orientation_ = blink::WebScreenOrientationPortraitPrimary; | 37 device_orientation_ = blink::WebScreenOrientationPortraitPrimary; |
| 35 current_orientation_ = blink::WebScreenOrientationPortraitPrimary; | 38 current_orientation_ = blink::WebScreenOrientationPortraitPrimary; |
| 36 } | 39 } |
| 37 | 40 |
| 38 void MockScreenOrientationController::UpdateLock( | 41 void MockScreenOrientationController::UpdateLock( |
| 39 blink::WebScreenOrientationLockType lock) { | 42 blink::WebScreenOrientationLockType lock) { |
| 40 base::MessageLoop::current()->PostTask( | 43 base::MessageLoop::current()->PostTask( |
| 41 FROM_HERE, | 44 FROM_HERE, |
| 42 base::Bind(&MockScreenOrientationController::UpdateLockSync, this, lock)); | 45 base::Bind(&MockScreenOrientationController::UpdateLockSync, this, lock)); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 57 | 60 |
| 58 void MockScreenOrientationController::ResetLockSync() { | 61 void MockScreenOrientationController::ResetLockSync() { |
| 59 bool will_screen_orientation_need_updating = | 62 bool will_screen_orientation_need_updating = |
| 60 !IsOrientationAllowedByCurrentLock(device_orientation_); | 63 !IsOrientationAllowedByCurrentLock(device_orientation_); |
| 61 current_lock_ = blink::WebScreenOrientationLockDefault; | 64 current_lock_ = blink::WebScreenOrientationLockDefault; |
| 62 if (will_screen_orientation_need_updating) | 65 if (will_screen_orientation_need_updating) |
| 63 UpdateScreenOrientation(device_orientation_); | 66 UpdateScreenOrientation(device_orientation_); |
| 64 } | 67 } |
| 65 | 68 |
| 66 void MockScreenOrientationController::UpdateDeviceOrientation( | 69 void MockScreenOrientationController::UpdateDeviceOrientation( |
| 70 RenderView* render_view, | |
| 67 blink::WebScreenOrientationType orientation) { | 71 blink::WebScreenOrientationType orientation) { |
| 72 // Make sure that render_view_ did not change during test. | |
| 73 assert(!render_view_ || render_view_ == render_view); | |
|
jochen (gone - plz use gerrit)
2014/06/02 07:21:25
DCHECK
ostap
2014/06/03 00:11:54
Done.
| |
| 74 render_view_ = render_view; | |
| 75 | |
| 68 if (device_orientation_ == orientation) | 76 if (device_orientation_ == orientation) |
| 69 return; | 77 return; |
| 70 device_orientation_ = orientation; | 78 device_orientation_ = orientation; |
| 71 if (!IsOrientationAllowedByCurrentLock(orientation)) | 79 if (!IsOrientationAllowedByCurrentLock(orientation)) |
| 72 return; | 80 return; |
| 73 UpdateScreenOrientation(orientation); | 81 UpdateScreenOrientation(orientation); |
| 74 } | 82 } |
| 75 | 83 |
| 76 void MockScreenOrientationController::UpdateScreenOrientation( | 84 void MockScreenOrientationController::UpdateScreenOrientation( |
| 77 blink::WebScreenOrientationType orientation) { | 85 blink::WebScreenOrientationType orientation) { |
| 78 if (current_orientation_ == orientation) | 86 if (current_orientation_ == orientation) |
| 79 return; | 87 return; |
| 80 current_orientation_ = orientation; | 88 current_orientation_ = orientation; |
| 89 if (render_view_) | |
|
jochen (gone - plz use gerrit)
2014/06/02 07:21:25
nit. add { } because of > 1line body
ostap
2014/06/03 00:11:54
Done.
| |
| 90 static_cast<RenderViewImpl*>(render_view_) | |
|
jochen (gone - plz use gerrit)
2014/06/02 07:21:25
how can you guarantee that e.g. the render view di
ostap
2014/06/03 00:11:54
At previous patches I did call from ~RenderViewImp
| |
| 91 ->SetScreenOrientationForTesting(orientation); | |
| 81 if (listener_) | 92 if (listener_) |
| 82 listener_->didChangeScreenOrientation(current_orientation_); | 93 listener_->didChangeScreenOrientation(current_orientation_); |
| 83 } | 94 } |
| 84 | 95 |
| 85 bool MockScreenOrientationController::IsOrientationAllowedByCurrentLock( | 96 bool MockScreenOrientationController::IsOrientationAllowedByCurrentLock( |
| 86 blink::WebScreenOrientationType orientation) { | 97 blink::WebScreenOrientationType orientation) { |
| 87 if (current_lock_ == blink::WebScreenOrientationLockDefault || | 98 if (current_lock_ == blink::WebScreenOrientationLockDefault || |
| 88 current_lock_ == blink::WebScreenOrientationLockAny) { | 99 current_lock_ == blink::WebScreenOrientationLockAny) { |
| 89 return true; | 100 return true; |
| 90 } | 101 } |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 118 case blink::WebScreenOrientationLockLandscape: | 129 case blink::WebScreenOrientationLockLandscape: |
| 119 return blink::WebScreenOrientationLandscapePrimary; | 130 return blink::WebScreenOrientationLandscapePrimary; |
| 120 case blink::WebScreenOrientationLockLandscapeSecondary: | 131 case blink::WebScreenOrientationLockLandscapeSecondary: |
| 121 return blink::WebScreenOrientationLandscapePrimary; | 132 return blink::WebScreenOrientationLandscapePrimary; |
| 122 default: | 133 default: |
| 123 return blink::WebScreenOrientationPortraitPrimary; | 134 return blink::WebScreenOrientationPortraitPrimary; |
| 124 } | 135 } |
| 125 } | 136 } |
| 126 | 137 |
| 127 } // namespace content | 138 } // namespace content |
| OLD | NEW |