| 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 "ash/wm/maximize_mode/maximize_mode_window_manager.h" | 14 #include "ash/wm/maximize_mode/maximize_mode_window_manager.h" |
| 15 #include "base/auto_reset.h" | 15 #include "base/auto_reset.h" |
| 16 #include "base/command_line.h" | 16 #include "base/command_line.h" |
| 17 #include "base/metrics/histogram.h" | 17 #include "base/metrics/histogram.h" |
| 18 #include "ui/base/accelerators/accelerator.h" | 18 #include "ui/base/accelerators/accelerator.h" |
| 19 #include "ui/events/event.h" | 19 #include "ui/events/event.h" |
| 20 #include "ui/events/event_handler.h" | |
| 21 #include "ui/events/keycodes/keyboard_codes.h" | 20 #include "ui/events/keycodes/keyboard_codes.h" |
| 22 #include "ui/gfx/vector3d_f.h" | 21 #include "ui/gfx/vector3d_f.h" |
| 23 | 22 |
| 24 namespace ash { | 23 namespace ash { |
| 25 | 24 |
| 26 namespace { | 25 namespace { |
| 27 | 26 |
| 28 // The hinge angle at which to enter maximize mode. | 27 // The hinge angle at which to enter maximize mode. |
| 29 const float kEnterMaximizeModeAngle = 200.0f; | 28 const float kEnterMaximizeModeAngle = 200.0f; |
| 30 | 29 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 gfx::Vector3dF cross(base); | 84 gfx::Vector3dF cross(base); |
| 86 cross.Cross(other); | 85 cross.Cross(other); |
| 87 // If the dot product of this cross product is normal, it means that the | 86 // If the dot product of this cross product is normal, it means that the |
| 88 // shortest angle between |base| and |other| was counterclockwise with respect | 87 // shortest angle between |base| and |other| was counterclockwise with respect |
| 89 // to the surface represented by |normal| and this angle must be reversed. | 88 // to the surface represented by |normal| and this angle must be reversed. |
| 90 if (gfx::DotProduct(cross, normal) > 0.0f) | 89 if (gfx::DotProduct(cross, normal) > 0.0f) |
| 91 angle = 360.0f - angle; | 90 angle = 360.0f - angle; |
| 92 return angle; | 91 return angle; |
| 93 } | 92 } |
| 94 | 93 |
| 95 #if defined(OS_CHROMEOS) | |
| 96 | |
| 97 // An event handler which listens for a volume down + power keypress and | |
| 98 // triggers a screenshot when this is seen. | |
| 99 class ScreenshotActionHandler : public ui::EventHandler { | |
| 100 public: | |
| 101 ScreenshotActionHandler(); | |
| 102 virtual ~ScreenshotActionHandler(); | |
| 103 | |
| 104 // ui::EventHandler: | |
| 105 virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE; | |
| 106 | |
| 107 private: | |
| 108 bool volume_down_pressed_; | |
| 109 | |
| 110 DISALLOW_COPY_AND_ASSIGN(ScreenshotActionHandler); | |
| 111 }; | |
| 112 | |
| 113 ScreenshotActionHandler::ScreenshotActionHandler() | |
| 114 : volume_down_pressed_(false) { | |
| 115 Shell::GetInstance()->PrependPreTargetHandler(this); | |
| 116 } | |
| 117 | |
| 118 ScreenshotActionHandler::~ScreenshotActionHandler() { | |
| 119 Shell::GetInstance()->RemovePreTargetHandler(this); | |
| 120 } | |
| 121 | |
| 122 void ScreenshotActionHandler::OnKeyEvent(ui::KeyEvent* event) { | |
| 123 if (event->key_code() == ui::VKEY_VOLUME_DOWN) { | |
| 124 volume_down_pressed_ = event->type() == ui::ET_KEY_PRESSED || | |
| 125 event->type() == ui::ET_TRANSLATED_KEY_PRESS; | |
| 126 } else if (volume_down_pressed_ && | |
| 127 event->key_code() == ui::VKEY_POWER && | |
| 128 event->type() == ui::ET_KEY_PRESSED) { | |
| 129 Shell::GetInstance()->accelerator_controller()->PerformAction( | |
| 130 ash::TAKE_SCREENSHOT, ui::Accelerator()); | |
| 131 } | |
| 132 } | |
| 133 | |
| 134 #endif // OS_CHROMEOS | |
| 135 | |
| 136 } // namespace | 94 } // namespace |
| 137 | 95 |
| 138 MaximizeModeController::MaximizeModeController() | 96 MaximizeModeController::MaximizeModeController() |
| 139 : rotation_locked_(false), | 97 : rotation_locked_(false), |
| 140 have_seen_accelerometer_data_(false), | 98 have_seen_accelerometer_data_(false), |
| 141 in_set_screen_rotation_(false), | 99 in_set_screen_rotation_(false), |
| 142 user_rotation_(gfx::Display::ROTATE_0), | 100 user_rotation_(gfx::Display::ROTATE_0), |
| 143 last_touchview_transition_time_(base::Time::Now()) { | 101 last_touchview_transition_time_(base::Time::Now()) { |
| 144 Shell::GetInstance()->accelerometer_controller()->AddObserver(this); | 102 Shell::GetInstance()->accelerometer_controller()->AddObserver(this); |
| 145 Shell::GetInstance()->AddShellObserver(this); | 103 Shell::GetInstance()->AddShellObserver(this); |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(), | 302 display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(), |
| 345 rotation); | 303 rotation); |
| 346 } | 304 } |
| 347 | 305 |
| 348 void MaximizeModeController::EnterMaximizeMode() { | 306 void MaximizeModeController::EnterMaximizeMode() { |
| 349 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 307 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
| 350 current_rotation_ = user_rotation_ = display_manager-> | 308 current_rotation_ = user_rotation_ = display_manager-> |
| 351 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); | 309 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); |
| 352 EnableMaximizeModeWindowManager(true); | 310 EnableMaximizeModeWindowManager(true); |
| 353 event_blocker_.reset(new MaximizeModeEventBlocker); | 311 event_blocker_.reset(new MaximizeModeEventBlocker); |
| 354 #if defined(OS_CHROMEOS) | |
| 355 event_handler_.reset(new ScreenshotActionHandler); | |
| 356 #endif | |
| 357 Shell::GetInstance()->display_controller()->AddObserver(this); | 312 Shell::GetInstance()->display_controller()->AddObserver(this); |
| 358 } | 313 } |
| 359 | 314 |
| 360 void MaximizeModeController::LeaveMaximizeMode() { | 315 void MaximizeModeController::LeaveMaximizeMode() { |
| 361 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 316 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
| 362 gfx::Display::Rotation current_rotation = display_manager-> | 317 gfx::Display::Rotation current_rotation = display_manager-> |
| 363 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); | 318 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); |
| 364 if (current_rotation != user_rotation_) | 319 if (current_rotation != user_rotation_) |
| 365 SetDisplayRotation(display_manager, user_rotation_); | 320 SetDisplayRotation(display_manager, user_rotation_); |
| 366 rotation_locked_ = false; | 321 rotation_locked_ = false; |
| 367 EnableMaximizeModeWindowManager(false); | 322 EnableMaximizeModeWindowManager(false); |
| 368 event_blocker_.reset(); | 323 event_blocker_.reset(); |
| 369 event_handler_.reset(); | |
| 370 } | 324 } |
| 371 | 325 |
| 372 void MaximizeModeController::OnSuspend() { | 326 void MaximizeModeController::OnSuspend() { |
| 373 RecordTouchViewStateTransition(); | 327 RecordTouchViewStateTransition(); |
| 374 } | 328 } |
| 375 | 329 |
| 376 void MaximizeModeController::OnResume() { | 330 void MaximizeModeController::OnResume() { |
| 377 last_touchview_transition_time_ = base::Time::Now(); | 331 last_touchview_transition_time_ = base::Time::Now(); |
| 378 } | 332 } |
| 379 | 333 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 total_non_touchview_time_; | 370 total_non_touchview_time_; |
| 417 if (total_runtime.InSeconds() > 0) { | 371 if (total_runtime.InSeconds() > 0) { |
| 418 UMA_HISTOGRAM_PERCENTAGE("Ash.TouchView.TouchViewActivePercentage", | 372 UMA_HISTOGRAM_PERCENTAGE("Ash.TouchView.TouchViewActivePercentage", |
| 419 100 * total_touchview_time_.InSeconds() / total_runtime.InSeconds()); | 373 100 * total_touchview_time_.InSeconds() / total_runtime.InSeconds()); |
| 420 } | 374 } |
| 421 } | 375 } |
| 422 Shell::GetInstance()->display_controller()->RemoveObserver(this); | 376 Shell::GetInstance()->display_controller()->RemoveObserver(this); |
| 423 } | 377 } |
| 424 | 378 |
| 425 } // namespace ash | 379 } // namespace ash |
| OLD | NEW |