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

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

Issue 230613004: Block keyboard and mouse input when maximize mode is activated by accelerometer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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
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 "ash/wm/maximize_mode/maximize_mode_controller.h" 5 #include "ash/wm/maximize_mode/maximize_mode_controller.h"
6 6
7 #include "ash/accelerometer/accelerometer_controller.h" 7 #include "ash/accelerometer/accelerometer_controller.h"
8 #include "ash/display/display_manager.h" 8 #include "ash/display/display_manager.h"
9 #include "ash/shell.h" 9 #include "ash/shell.h"
10 #include "ui/aura/client/cursor_client.h"
11 #include "ui/events/event_handler.h"
10 #include "ui/gfx/vector3d_f.h" 12 #include "ui/gfx/vector3d_f.h"
11 13
12 namespace ash { 14 namespace ash {
13 15
14 namespace { 16 namespace {
15 17
16 // The hinge angle at which to enter maximize mode. 18 // The hinge angle at which to enter maximize mode.
17 const float kEnterMaximizeModeAngle = 200.0f; 19 const float kEnterMaximizeModeAngle = 200.0f;
18 20
19 // The angle at which to exit maximize mode, this is specifically less than the 21 // The angle at which to exit maximize mode, this is specifically less than the
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 gfx::Vector3dF cross(base); 63 gfx::Vector3dF cross(base);
62 cross.Cross(other); 64 cross.Cross(other);
63 // If the dot product of this cross product is normal, it means that the 65 // If the dot product of this cross product is normal, it means that the
64 // shortest angle between |base| and |other| was counterclockwise with respect 66 // shortest angle between |base| and |other| was counterclockwise with respect
65 // to the surface represented by |normal| and this angle must be reversed. 67 // to the surface represented by |normal| and this angle must be reversed.
66 if (gfx::DotProduct(cross, normal) > 0.0f) 68 if (gfx::DotProduct(cross, normal) > 0.0f)
67 angle = 360.0f - angle; 69 angle = 360.0f - angle;
68 return angle; 70 return angle;
69 } 71 }
70 72
73 // Filter to prevent delivery of mouse and touch events while maximize mode is
74 // active.
75 // TODO(flackr): This should only stop events from the internal keyboard and
76 // touchpad.
77 class BlockKeyboardAndTouchpadFilter : public ui::EventHandler {
78 public:
79 BlockKeyboardAndTouchpadFilter();
80 virtual ~BlockKeyboardAndTouchpadFilter();
81
82 // Overridden from ui::EventHandler:
83 virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE;
84 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE;
85
86 private:
87 DISALLOW_COPY_AND_ASSIGN(BlockKeyboardAndTouchpadFilter);
88 };
89
90 BlockKeyboardAndTouchpadFilter::BlockKeyboardAndTouchpadFilter() {
91 // This needs to be the first handler to block events.
92 Shell::GetInstance()->PrependPreTargetHandler(this);
sadrul 2014/04/09 16:54:18 Can you install a WindowTargeter on the root-windo
flackr 2014/04/09 17:11:49 It looks like event targeters are per window / roo
sadrul 2014/04/09 17:33:30 There isn't a global event targeter. If a new root
flackr 2014/04/10 02:30:02 Just wanted to be sure I wasn't just missing somet
93 aura::client::CursorClient* cursor_client_ =
94 aura::client::GetCursorClient(Shell::GetTargetRootWindow());
95 if (cursor_client_)
96 cursor_client_->HideCursor();
97 }
98
99 BlockKeyboardAndTouchpadFilter::~BlockKeyboardAndTouchpadFilter() {
100 Shell::GetInstance()->RemovePreTargetHandler(this);
101 }
102
103 void BlockKeyboardAndTouchpadFilter::OnKeyEvent(ui::KeyEvent* event) {
104 if (event->HasNativeEvent())
105 event->StopPropagation();
106 }
107
108 void BlockKeyboardAndTouchpadFilter::OnMouseEvent(ui::MouseEvent* event) {
109 if (event->HasNativeEvent())
110 event->StopPropagation();
111 }
112
71 } // namespace 113 } // namespace
72 114
73 MaximizeModeController::MaximizeModeController() { 115 MaximizeModeController::MaximizeModeController() {
74 Shell::GetInstance()->accelerometer_controller()->AddObserver(this); 116 Shell::GetInstance()->accelerometer_controller()->AddObserver(this);
75 } 117 }
76 118
77 MaximizeModeController::~MaximizeModeController() { 119 MaximizeModeController::~MaximizeModeController() {
78 Shell::GetInstance()->accelerometer_controller()->RemoveObserver(this); 120 Shell::GetInstance()->accelerometer_controller()->RemoveObserver(this);
79 } 121 }
80 122
(...skipping 25 matching lines...) Expand all
106 float angle = ClockwiseAngleBetweenVectorsInDegrees(base, lid, hinge_vector); 148 float angle = ClockwiseAngleBetweenVectorsInDegrees(base, lid, hinge_vector);
107 149
108 // Toggle maximize mode on or off when corresponding thresholds are passed. 150 // Toggle maximize mode on or off when corresponding thresholds are passed.
109 // TODO(flackr): Make MaximizeModeController own the MaximizeModeWindowManager 151 // TODO(flackr): Make MaximizeModeController own the MaximizeModeWindowManager
110 // such that observations of state changes occur after the change and shell 152 // such that observations of state changes occur after the change and shell
111 // has fewer states to track. 153 // has fewer states to track.
112 if (maximize_mode_engaged && 154 if (maximize_mode_engaged &&
113 angle > kFullyOpenAngleErrorTolerance && 155 angle > kFullyOpenAngleErrorTolerance &&
114 angle < kExitMaximizeModeAngle) { 156 angle < kExitMaximizeModeAngle) {
115 Shell::GetInstance()->EnableMaximizeModeWindowManager(false); 157 Shell::GetInstance()->EnableMaximizeModeWindowManager(false);
158 event_handler_.reset();
116 } else if (!maximize_mode_engaged && 159 } else if (!maximize_mode_engaged &&
117 angle > kEnterMaximizeModeAngle) { 160 angle > kEnterMaximizeModeAngle) {
118 Shell::GetInstance()->EnableMaximizeModeWindowManager(true); 161 Shell::GetInstance()->EnableMaximizeModeWindowManager(true);
162 event_handler_.reset(new BlockKeyboardAndTouchpadFilter);
119 } 163 }
120 } 164 }
121 165
122 void MaximizeModeController::HandleScreenRotation(const gfx::Vector3dF& lid) { 166 void MaximizeModeController::HandleScreenRotation(const gfx::Vector3dF& lid) {
123 bool maximize_mode_engaged = 167 bool maximize_mode_engaged =
124 Shell::GetInstance()->IsMaximizeModeWindowManagerEnabled(); 168 Shell::GetInstance()->IsMaximizeModeWindowManagerEnabled();
125 169
126 DisplayManager* display_manager = 170 DisplayManager* display_manager =
127 Shell::GetInstance()->display_manager(); 171 Shell::GetInstance()->display_manager();
128 gfx::Display::Rotation current_rotation = display_manager->GetDisplayInfo( 172 gfx::Display::Rotation current_rotation = display_manager->GetDisplayInfo(
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 // When exiting maximize mode return rotation to 0. When entering, rotate to 236 // When exiting maximize mode return rotation to 0. When entering, rotate to
193 // match screen orientation. 237 // match screen orientation.
194 if (new_rotation == gfx::Display::ROTATE_0 || 238 if (new_rotation == gfx::Display::ROTATE_0 ||
195 maximize_mode_engaged) { 239 maximize_mode_engaged) {
196 display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(), 240 display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(),
197 new_rotation); 241 new_rotation);
198 } 242 }
199 } 243 }
200 244
201 } // namespace ash 245 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/maximize_mode/maximize_mode_controller.h ('k') | ash/wm/maximize_mode/maximize_mode_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698