Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(46)

Side by Side Diff: content/shell/renderer/test_runner/mock_screen_orientation_controller.cc

Issue 339913002: Move MockScreenOrientationController to content/shell/renderer/test_runner/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "content/shell/renderer/test_runner/mock_screen_orientation_controller. h"
6
7 #include "base/bind.h"
8 #include "base/logging.h"
9 #include "base/message_loop/message_loop.h"
10 #include "content/renderer/render_view_impl.h"
11
12 namespace content {
13
14 MockScreenOrientationController::MockScreenOrientationController()
15 : render_view_(NULL),
16 current_lock_(blink::WebScreenOrientationLockDefault),
17 device_orientation_(blink::WebScreenOrientationPortraitPrimary),
18 current_orientation_(blink::WebScreenOrientationPortraitPrimary) {
19 }
20
21 MockScreenOrientationController::~MockScreenOrientationController() {
22 }
23
24 void MockScreenOrientationController::ResetData() {
25 current_lock_ = blink::WebScreenOrientationLockDefault;
26 device_orientation_ = blink::WebScreenOrientationPortraitPrimary;
27 current_orientation_ = blink::WebScreenOrientationPortraitPrimary;
28 }
29
30 void MockScreenOrientationController::UpdateDeviceOrientation(
31 RenderView* render_view,
32 blink::WebScreenOrientationType orientation) {
33 render_view_ = render_view;
34 if (device_orientation_ == orientation)
35 return;
36 device_orientation_ = orientation;
37 if (!IsOrientationAllowedByCurrentLock(orientation))
38 return;
39 UpdateScreenOrientation(orientation);
40 }
41
42 void MockScreenOrientationController::UpdateScreenOrientation(
43 blink::WebScreenOrientationType orientation) {
44 if (current_orientation_ == orientation)
45 return;
46 current_orientation_ = orientation;
47 if (render_view_)
48 static_cast<RenderViewImpl*>(render_view_)
Inactive 2014/06/17 17:29:04 This is a layering violation. I don't know how to
mlamouri (slow - plz ping) 2014/06/18 13:47:42 We could from the test_runner.cc notify the WebVie
49 ->SetScreenOrientationForTesting(orientation);
50 }
51
52 bool MockScreenOrientationController::IsOrientationAllowedByCurrentLock(
53 blink::WebScreenOrientationType orientation) {
54 if (current_lock_ == blink::WebScreenOrientationLockDefault ||
55 current_lock_ == blink::WebScreenOrientationLockAny) {
56 return true;
57 }
58
59 switch (orientation) {
60 case blink::WebScreenOrientationPortraitPrimary:
61 return current_lock_ == blink::WebScreenOrientationLockPortraitPrimary ||
62 current_lock_ == blink::WebScreenOrientationLockPortrait;
63 case blink::WebScreenOrientationPortraitSecondary:
64 return current_lock_ ==
65 blink::WebScreenOrientationLockPortraitSecondary ||
66 current_lock_ == blink::WebScreenOrientationLockPortrait;
67 case blink::WebScreenOrientationLandscapePrimary:
68 return current_lock_ == blink::WebScreenOrientationLockLandscapePrimary ||
69 current_lock_ == blink::WebScreenOrientationLockLandscape;
70 case blink::WebScreenOrientationLandscapeSecondary:
71 return current_lock_ ==
72 blink::WebScreenOrientationLockLandscapeSecondary ||
73 current_lock_ == blink::WebScreenOrientationLockLandscape;
74 default:
75 return false;
76 }
77 }
78
79 void MockScreenOrientationController::lockOrientation(
80 blink::WebScreenOrientationLockType orientation,
81 blink::WebLockOrientationCallback* callback) {
82 base::MessageLoop::current()->PostTask(
83 FROM_HERE,
84 base::Bind(&MockScreenOrientationController::UpdateLockSync,
85 base::Unretained(this),
86 orientation,
87 callback));
88 }
89
90 void MockScreenOrientationController::unlockOrientation() {
91 base::MessageLoop::current()->PostTask(
92 FROM_HERE,
93 base::Bind(&MockScreenOrientationController::ResetLockSync,
94 base::Unretained(this)));
95 }
96
97 void MockScreenOrientationController::UpdateLockSync(
98 blink::WebScreenOrientationLockType lock,
99 blink::WebLockOrientationCallback* callback) {
100 DCHECK(lock != blink::WebScreenOrientationLockDefault);
101 current_lock_ = lock;
102 if (!IsOrientationAllowedByCurrentLock(current_orientation_))
103 UpdateScreenOrientation(SuitableOrientationForCurrentLock());
104 // FIXME(ostap): This relationship between orientationType and
105 // orientationAngle is temporary. The test should be able to specify
106 // the angle in addition to the orientation type.
107 unsigned angle;
108 switch (current_orientation_) {
109 case blink::WebScreenOrientationLandscapePrimary:
110 angle = 90;
111 break;
112 case blink::WebScreenOrientationLandscapeSecondary:
113 angle = -90;
mlamouri (slow - plz ping) 2014/06/18 13:47:42 Do not return negative values, please. This should
114 break;
115 case blink::WebScreenOrientationPortraitSecondary:
116 angle = 180;
117 break;
118 default:
119 angle = 0;
120 }
121 callback->onSuccess(angle, current_orientation_);
122 }
123
124 void MockScreenOrientationController::ResetLockSync() {
125 bool will_screen_orientation_need_updating =
126 !IsOrientationAllowedByCurrentLock(device_orientation_);
127 current_lock_ = blink::WebScreenOrientationLockDefault;
128 if (will_screen_orientation_need_updating)
129 UpdateScreenOrientation(device_orientation_);
130 }
131
132 blink::WebScreenOrientationType
133 MockScreenOrientationController::SuitableOrientationForCurrentLock() {
134 switch (current_lock_) {
135 case blink::WebScreenOrientationLockPortraitSecondary:
136 return blink::WebScreenOrientationPortraitSecondary;
137 case blink::WebScreenOrientationLockLandscapePrimary:
138 case blink::WebScreenOrientationLockLandscape:
139 return blink::WebScreenOrientationLandscapePrimary;
140 case blink::WebScreenOrientationLockLandscapeSecondary:
141 return blink::WebScreenOrientationLandscapePrimary;
142 default:
143 return blink::WebScreenOrientationPortraitPrimary;
144 }
145 }
146
147 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698