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

Side by Side Diff: ash/wm/maximize_mode/maximize_mode_controller.cc

Issue 197883011: Enable maximize mode when keyboard is open past 180 degrees. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add tests, constants, and stickiness to entering / exiting. Created 6 years, 8 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 "ash/wm/maximize_mode/maximize_mode_controller.h"
6
7 #include "ash/accelerometer/accelerometer_controller.h"
8 #include "ash/shell.h"
9 #include "ui/gfx/vector3d_f.h"
10
11 namespace ash {
12 namespace internal {
13
14 namespace {
15
16 // The hinge angle at which to enter maximize mode.
17 const float kEnterMaximizeModeAngle = 200.0f;
18
19 // The angle at which to exit maximize mode, this is specifically less than the
20 // angle to enter maximize mode to prevent rapid toggling when near the angle.
21 const float kExitMaximizeModeAngle = 160.0f;
22
23 // When the lid is fully open 360 degrees, the accelerometer readings can
24 // occasionally appear as though the lid is almost closed. If the lid appears
25 // near closed but the device is on we assume it is an erroneous reading from
26 // it being open 360 degrees.
27 const float kFullyOpenAngleErrorTolerance = 10.0f;
28
29 // When the device approaches vertical orientation (i.e. portrait orientation)
30 // the accelerometers for the base and lid approach the same values (i.e.
31 // gravity pointing in the direction of the hinge). When this happens we cannot
32 // compute the hinge angle reliably and must turn ignore accelerometer readings.
33 // This is the angle from vertical under which we will not compute a hinge
34 // angle.
35 const float kHingeAxisAlignedThreshold = 15.0f;
36
37 const gfx::Vector3dF kHingeVector(0.0f, 1.0f, 0.0f);
oshima 2014/04/01 22:29:08 won't this create static initializer?
38 const float kRadiansToDegrees = 180.0f / 3.14159265f;
39
40 } // namespace
41
42 MaximizeModeController::MaximizeModeController() {
43 Shell::GetInstance()->accelerometer_controller()->AddObserver(this);
Mr4D (OOO till 08-26) 2014/04/01 22:05:50 This was fired periodically and not on state chang
flackr 2014/04/02 21:24:30 Yes, this is always fired periodically.
44 }
45
46 MaximizeModeController::~MaximizeModeController() {
47 Shell::GetInstance()->accelerometer_controller()->RemoveObserver(this);
48 }
49
50 void MaximizeModeController::OnAccelerometerUpdated(
51 const gfx::Vector3dF& base,
52 const gfx::Vector3dF& lid) {
53 // As the hinge approaches a vertical angle, the base and lid accelerometers
54 // approach the same values making any angle calculations highly inaccurate.
55 // Bail out early when it is too close.
56 float hinge_angle = acos(
57 gfx::DotProduct(base, kHingeVector) / base.Length()) * kRadiansToDegrees;
Mr4D (OOO till 08-26) 2014/04/01 22:05:50 Just checking - What was the frequency for the eve
oshima 2014/04/01 22:29:08 I agree with Stefan's concern. I guess it's alread
flackr 2014/04/02 21:24:30 Even before I added a separate enter and exit thre
oshima 2014/04/02 22:11:30 I think the mode flag should eventually move here
flackr 2014/04/03 02:52:14 I agree, that is what the TODO on line 73 is for.
58 if (hinge_angle < kHingeAxisAlignedThreshold ||
59 hinge_angle > 180.0f - kHingeAxisAlignedThreshold)
60 return;
61
62 // Compute the angle between the base and the lid.
Mr4D (OOO till 08-26) 2014/04/01 22:05:50 You might want to pull this out into a separate fu
flackr 2014/04/02 21:24:30 Good call, made two helpers for shortest angle and
63 float dot_product = gfx::DotProduct(base, lid);
64 float angle = acos(dot_product / base.Length() / lid.Length()) *
65 kRadiansToDegrees;
66 gfx::Vector3dF cross(base);
67 cross.Cross(lid);
68 float sign = gfx::DotProduct(cross, kHingeVector);
69 if (sign > 0.0f)
70 angle = 360.0f - angle;
71
72 // Toggle maximize mode on or off when corresponding thresholds are passed.
73 // TODO(flackr): Make MaximizeModeController own the MaximizeModeWindowManager
74 // such that observations of state changes occur after the change and shell
75 // has fewer states to track.
76 bool maximize_mode_engaged =
77 Shell::GetInstance()->IsMaximizeModeWindowManagerEnabled();
78 if (maximize_mode_engaged &&
79 angle > kFullyOpenAngleErrorTolerance &&
80 angle < kExitMaximizeModeAngle) {
81 Shell::GetInstance()->EnableMaximizeModeWindowManager(false);
82 } else if (!maximize_mode_engaged &&
83 angle > kEnterMaximizeModeAngle) {
84 Shell::GetInstance()->EnableMaximizeModeWindowManager(true);
85 }
86 }
87
88 } // namespace internal
89 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698