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 "ash/wm/maximize_mode/maximize_mode_controller.h" | 5 #include "ash/wm/maximize_mode/maximize_mode_controller.h" |
6 | 6 |
| 7 #include "ash/accelerators/accelerator_controller.h" |
| 8 #include "ash/accelerators/accelerator_table.h" |
7 #include "ash/accelerometer/accelerometer_controller.h" | 9 #include "ash/accelerometer/accelerometer_controller.h" |
8 #include "ash/ash_switches.h" | 10 #include "ash/ash_switches.h" |
9 #include "ash/display/display_manager.h" | 11 #include "ash/display/display_manager.h" |
10 #include "ash/shell.h" | 12 #include "ash/shell.h" |
11 #include "ash/wm/maximize_mode/maximize_mode_event_blocker.h" | 13 #include "ash/wm/maximize_mode/maximize_mode_event_blocker.h" |
12 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 15 #include "ui/base/accelerators/accelerator.h" |
| 16 #include "ui/events/event.h" |
| 17 #include "ui/events/event_handler.h" |
| 18 #include "ui/events/keycodes/keyboard_codes.h" |
13 #include "ui/gfx/vector3d_f.h" | 19 #include "ui/gfx/vector3d_f.h" |
14 | 20 |
15 namespace ash { | 21 namespace ash { |
16 | 22 |
17 namespace { | 23 namespace { |
18 | 24 |
19 // The hinge angle at which to enter maximize mode. | 25 // The hinge angle at which to enter maximize mode. |
20 const float kEnterMaximizeModeAngle = 200.0f; | 26 const float kEnterMaximizeModeAngle = 200.0f; |
21 | 27 |
22 // The angle at which to exit maximize mode, this is specifically less than the | 28 // The angle at which to exit maximize mode, this is specifically less than the |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 gfx::Vector3dF cross(base); | 80 gfx::Vector3dF cross(base); |
75 cross.Cross(other); | 81 cross.Cross(other); |
76 // If the dot product of this cross product is normal, it means that the | 82 // If the dot product of this cross product is normal, it means that the |
77 // shortest angle between |base| and |other| was counterclockwise with respect | 83 // shortest angle between |base| and |other| was counterclockwise with respect |
78 // to the surface represented by |normal| and this angle must be reversed. | 84 // to the surface represented by |normal| and this angle must be reversed. |
79 if (gfx::DotProduct(cross, normal) > 0.0f) | 85 if (gfx::DotProduct(cross, normal) > 0.0f) |
80 angle = 360.0f - angle; | 86 angle = 360.0f - angle; |
81 return angle; | 87 return angle; |
82 } | 88 } |
83 | 89 |
| 90 #if defined(OS_CHROMEOS) |
| 91 |
| 92 // An event handler which listens for a volume down + power keypress and |
| 93 // triggers a screenshot when this is seen. |
| 94 class ScreenshotActionHandler : public ui::EventHandler { |
| 95 public: |
| 96 ScreenshotActionHandler(); |
| 97 virtual ~ScreenshotActionHandler(); |
| 98 |
| 99 // ui::EventHandler: |
| 100 virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE; |
| 101 |
| 102 private: |
| 103 bool volume_down_pressed_; |
| 104 |
| 105 DISALLOW_COPY_AND_ASSIGN(ScreenshotActionHandler); |
| 106 }; |
| 107 |
| 108 ScreenshotActionHandler::ScreenshotActionHandler() |
| 109 : volume_down_pressed_(false) { |
| 110 Shell::GetInstance()->PrependPreTargetHandler(this); |
| 111 } |
| 112 |
| 113 ScreenshotActionHandler::~ScreenshotActionHandler() { |
| 114 Shell::GetInstance()->RemovePreTargetHandler(this); |
| 115 } |
| 116 |
| 117 void ScreenshotActionHandler::OnKeyEvent(ui::KeyEvent* event) { |
| 118 if (event->key_code() == ui::VKEY_VOLUME_DOWN) { |
| 119 volume_down_pressed_ = event->type() == ui::ET_KEY_PRESSED || |
| 120 event->type() == ui::ET_TRANSLATED_KEY_PRESS; |
| 121 } else if (volume_down_pressed_ && |
| 122 event->key_code() == ui::VKEY_POWER && |
| 123 event->type() == ui::ET_KEY_PRESSED) { |
| 124 Shell::GetInstance()->accelerator_controller()->PerformAction( |
| 125 ash::TAKE_SCREENSHOT, ui::Accelerator()); |
| 126 } |
| 127 } |
| 128 |
| 129 #endif // OS_CHROMEOS |
| 130 |
84 } // namespace | 131 } // namespace |
85 | 132 |
86 MaximizeModeController::MaximizeModeController() | 133 MaximizeModeController::MaximizeModeController() |
87 : rotation_locked_(false), | 134 : rotation_locked_(false), |
88 have_seen_accelerometer_data_(false) { | 135 have_seen_accelerometer_data_(false) { |
89 Shell::GetInstance()->accelerometer_controller()->AddObserver(this); | 136 Shell::GetInstance()->accelerometer_controller()->AddObserver(this); |
90 } | 137 } |
91 | 138 |
92 MaximizeModeController::~MaximizeModeController() { | 139 MaximizeModeController::~MaximizeModeController() { |
93 Shell::GetInstance()->accelerometer_controller()->RemoveObserver(this); | 140 Shell::GetInstance()->accelerometer_controller()->RemoveObserver(this); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 | 198 |
152 // Toggle maximize mode on or off when corresponding thresholds are passed. | 199 // Toggle maximize mode on or off when corresponding thresholds are passed. |
153 // TODO(flackr): Make MaximizeModeController own the MaximizeModeWindowManager | 200 // TODO(flackr): Make MaximizeModeController own the MaximizeModeWindowManager |
154 // such that observations of state changes occur after the change and shell | 201 // such that observations of state changes occur after the change and shell |
155 // has fewer states to track. | 202 // has fewer states to track. |
156 if (maximize_mode_engaged && | 203 if (maximize_mode_engaged && |
157 angle > kFullyOpenAngleErrorTolerance && | 204 angle > kFullyOpenAngleErrorTolerance && |
158 angle < kExitMaximizeModeAngle) { | 205 angle < kExitMaximizeModeAngle) { |
159 Shell::GetInstance()->EnableMaximizeModeWindowManager(false); | 206 Shell::GetInstance()->EnableMaximizeModeWindowManager(false); |
160 event_blocker_.reset(); | 207 event_blocker_.reset(); |
| 208 event_handler_.reset(); |
161 } else if (!maximize_mode_engaged && | 209 } else if (!maximize_mode_engaged && |
162 angle > kEnterMaximizeModeAngle) { | 210 angle > kEnterMaximizeModeAngle) { |
163 Shell::GetInstance()->EnableMaximizeModeWindowManager(true); | 211 Shell::GetInstance()->EnableMaximizeModeWindowManager(true); |
164 event_blocker_.reset(new MaximizeModeEventBlocker); | 212 event_blocker_.reset(new MaximizeModeEventBlocker); |
| 213 #if defined(OS_CHROMEOS) |
| 214 event_handler_.reset(new ScreenshotActionHandler); |
| 215 #endif |
165 } | 216 } |
166 } | 217 } |
167 | 218 |
168 void MaximizeModeController::HandleScreenRotation(const gfx::Vector3dF& lid) { | 219 void MaximizeModeController::HandleScreenRotation(const gfx::Vector3dF& lid) { |
169 bool maximize_mode_engaged = | 220 bool maximize_mode_engaged = |
170 Shell::GetInstance()->IsMaximizeModeWindowManagerEnabled(); | 221 Shell::GetInstance()->IsMaximizeModeWindowManagerEnabled(); |
171 | 222 |
172 DisplayManager* display_manager = | 223 DisplayManager* display_manager = |
173 Shell::GetInstance()->display_manager(); | 224 Shell::GetInstance()->display_manager(); |
174 gfx::Display::Rotation current_rotation = display_manager->GetDisplayInfo( | 225 gfx::Display::Rotation current_rotation = display_manager->GetDisplayInfo( |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 // When exiting maximize mode return rotation to 0. When entering, rotate to | 293 // When exiting maximize mode return rotation to 0. When entering, rotate to |
243 // match screen orientation. | 294 // match screen orientation. |
244 if (new_rotation == gfx::Display::ROTATE_0 || | 295 if (new_rotation == gfx::Display::ROTATE_0 || |
245 maximize_mode_engaged) { | 296 maximize_mode_engaged) { |
246 display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(), | 297 display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(), |
247 new_rotation); | 298 new_rotation); |
248 } | 299 } |
249 } | 300 } |
250 | 301 |
251 } // namespace ash | 302 } // namespace ash |
OLD | NEW |