| 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" | 7 #include "ash/accelerators/accelerator_controller.h" |
| 8 #include "ash/accelerators/accelerator_table.h" | 8 #include "ash/accelerators/accelerator_table.h" |
| 9 #include "ash/accelerometer/accelerometer_controller.h" | 9 #include "ash/accelerometer/accelerometer_controller.h" |
| 10 #include "ash/ash_switches.h" | 10 #include "ash/ash_switches.h" |
| 11 #include "ash/display/display_manager.h" | 11 #include "ash/display/display_manager.h" |
| 12 #include "ash/shell.h" | 12 #include "ash/shell.h" |
| 13 #include "ash/wm/maximize_mode/maximize_mode_event_blocker.h" | 13 #include "ash/wm/maximize_mode/maximize_mode_event_blocker.h" |
| 14 #include "base/auto_reset.h" | 14 #include "base/auto_reset.h" |
| 15 #include "base/command_line.h" | 15 #include "base/command_line.h" |
| 16 #include "ui/base/accelerators/accelerator.h" | 16 #include "ui/base/accelerators/accelerator.h" |
| 17 #include "ui/events/event.h" | 17 #include "ui/events/event.h" |
| 18 #include "ui/events/event_handler.h" | |
| 19 #include "ui/events/keycodes/keyboard_codes.h" | 18 #include "ui/events/keycodes/keyboard_codes.h" |
| 20 #include "ui/gfx/vector3d_f.h" | 19 #include "ui/gfx/vector3d_f.h" |
| 21 | 20 |
| 22 namespace ash { | 21 namespace ash { |
| 23 | 22 |
| 24 namespace { | 23 namespace { |
| 25 | 24 |
| 26 // The hinge angle at which to enter maximize mode. | 25 // The hinge angle at which to enter maximize mode. |
| 27 const float kEnterMaximizeModeAngle = 200.0f; | 26 const float kEnterMaximizeModeAngle = 200.0f; |
| 28 | 27 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 gfx::Vector3dF cross(base); | 82 gfx::Vector3dF cross(base); |
| 84 cross.Cross(other); | 83 cross.Cross(other); |
| 85 // If the dot product of this cross product is normal, it means that the | 84 // If the dot product of this cross product is normal, it means that the |
| 86 // shortest angle between |base| and |other| was counterclockwise with respect | 85 // shortest angle between |base| and |other| was counterclockwise with respect |
| 87 // to the surface represented by |normal| and this angle must be reversed. | 86 // to the surface represented by |normal| and this angle must be reversed. |
| 88 if (gfx::DotProduct(cross, normal) > 0.0f) | 87 if (gfx::DotProduct(cross, normal) > 0.0f) |
| 89 angle = 360.0f - angle; | 88 angle = 360.0f - angle; |
| 90 return angle; | 89 return angle; |
| 91 } | 90 } |
| 92 | 91 |
| 93 #if defined(OS_CHROMEOS) | |
| 94 | |
| 95 // An event handler which listens for a volume down + power keypress and | |
| 96 // triggers a screenshot when this is seen. | |
| 97 class ScreenshotActionHandler : public ui::EventHandler { | |
| 98 public: | |
| 99 ScreenshotActionHandler(); | |
| 100 virtual ~ScreenshotActionHandler(); | |
| 101 | |
| 102 // ui::EventHandler: | |
| 103 virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE; | |
| 104 | |
| 105 private: | |
| 106 bool volume_down_pressed_; | |
| 107 | |
| 108 DISALLOW_COPY_AND_ASSIGN(ScreenshotActionHandler); | |
| 109 }; | |
| 110 | |
| 111 ScreenshotActionHandler::ScreenshotActionHandler() | |
| 112 : volume_down_pressed_(false) { | |
| 113 Shell::GetInstance()->PrependPreTargetHandler(this); | |
| 114 } | |
| 115 | |
| 116 ScreenshotActionHandler::~ScreenshotActionHandler() { | |
| 117 Shell::GetInstance()->RemovePreTargetHandler(this); | |
| 118 } | |
| 119 | |
| 120 void ScreenshotActionHandler::OnKeyEvent(ui::KeyEvent* event) { | |
| 121 if (event->key_code() == ui::VKEY_VOLUME_DOWN) { | |
| 122 volume_down_pressed_ = event->type() == ui::ET_KEY_PRESSED || | |
| 123 event->type() == ui::ET_TRANSLATED_KEY_PRESS; | |
| 124 } else if (volume_down_pressed_ && | |
| 125 event->key_code() == ui::VKEY_POWER && | |
| 126 event->type() == ui::ET_KEY_PRESSED) { | |
| 127 Shell::GetInstance()->accelerator_controller()->PerformAction( | |
| 128 ash::TAKE_SCREENSHOT, ui::Accelerator()); | |
| 129 } | |
| 130 } | |
| 131 | |
| 132 #endif // OS_CHROMEOS | |
| 133 | |
| 134 } // namespace | 92 } // namespace |
| 135 | 93 |
| 136 MaximizeModeController::MaximizeModeController() | 94 MaximizeModeController::MaximizeModeController() |
| 137 : rotation_locked_(false), | 95 : rotation_locked_(false), |
| 138 have_seen_accelerometer_data_(false), | 96 have_seen_accelerometer_data_(false), |
| 139 in_set_screen_rotation_(false), | 97 in_set_screen_rotation_(false), |
| 140 user_rotation_(gfx::Display::ROTATE_0) { | 98 user_rotation_(gfx::Display::ROTATE_0) { |
| 141 Shell::GetInstance()->accelerometer_controller()->AddObserver(this); | 99 Shell::GetInstance()->accelerometer_controller()->AddObserver(this); |
| 142 } | 100 } |
| 143 | 101 |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 | 245 |
| 288 void MaximizeModeController::EnterMaximizeMode() { | 246 void MaximizeModeController::EnterMaximizeMode() { |
| 289 // TODO(jonross): Listen for display configuration changes. If the user | 247 // TODO(jonross): Listen for display configuration changes. If the user |
| 290 // causes a rotation change a rotation lock should be applied. | 248 // causes a rotation change a rotation lock should be applied. |
| 291 // https://crbug.com/369505 | 249 // https://crbug.com/369505 |
| 292 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 250 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
| 293 user_rotation_ = display_manager-> | 251 user_rotation_ = display_manager-> |
| 294 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); | 252 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); |
| 295 Shell::GetInstance()->EnableMaximizeModeWindowManager(true); | 253 Shell::GetInstance()->EnableMaximizeModeWindowManager(true); |
| 296 event_blocker_.reset(new MaximizeModeEventBlocker); | 254 event_blocker_.reset(new MaximizeModeEventBlocker); |
| 297 #if defined(OS_CHROMEOS) | |
| 298 event_handler_.reset(new ScreenshotActionHandler); | |
| 299 #endif | |
| 300 } | 255 } |
| 301 | 256 |
| 302 void MaximizeModeController::LeaveMaximizeMode() { | 257 void MaximizeModeController::LeaveMaximizeMode() { |
| 303 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 258 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
| 304 DisplayInfo info = display_manager-> | 259 DisplayInfo info = display_manager-> |
| 305 GetDisplayInfo(gfx::Display::InternalDisplayId()); | 260 GetDisplayInfo(gfx::Display::InternalDisplayId()); |
| 306 gfx::Display::Rotation current_rotation = info.rotation(); | 261 gfx::Display::Rotation current_rotation = info.rotation(); |
| 307 if (current_rotation != user_rotation_) | 262 if (current_rotation != user_rotation_) |
| 308 SetDisplayRotation(display_manager, user_rotation_); | 263 SetDisplayRotation(display_manager, user_rotation_); |
| 309 rotation_locked_ = false; | 264 rotation_locked_ = false; |
| 310 Shell::GetInstance()->EnableMaximizeModeWindowManager(false); | 265 Shell::GetInstance()->EnableMaximizeModeWindowManager(false); |
| 311 event_blocker_.reset(); | 266 event_blocker_.reset(); |
| 312 event_handler_.reset(); | |
| 313 } | 267 } |
| 314 | 268 |
| 315 } // namespace ash | 269 } // namespace ash |
| OLD | NEW |