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_window_manager.h" | 13 #include "ash/wm/maximize_mode/maximize_mode_window_manager.h" |
14 #include "ash/wm/maximize_mode/scoped_disable_internal_mouse_and_keyboard.h" | 14 #include "ash/wm/maximize_mode/scoped_disable_internal_mouse_and_keyboard.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 "base/time/default_tick_clock.h" | 18 #include "base/time/default_tick_clock.h" |
19 #include "base/time/tick_clock.h" | 19 #include "base/time/tick_clock.h" |
20 #include "ui/base/accelerators/accelerator.h" | 20 #include "ui/base/accelerators/accelerator.h" |
21 #include "ui/events/event.h" | 21 #include "ui/events/event.h" |
22 #include "ui/events/event_handler.h" | |
23 #include "ui/events/keycodes/keyboard_codes.h" | 22 #include "ui/events/keycodes/keyboard_codes.h" |
24 #include "ui/gfx/vector3d_f.h" | 23 #include "ui/gfx/vector3d_f.h" |
25 | 24 |
26 #if defined(USE_X11) | 25 #if defined(USE_X11) |
27 #include "ash/wm/maximize_mode/scoped_disable_internal_mouse_and_keyboard_x11.h" | 26 #include "ash/wm/maximize_mode/scoped_disable_internal_mouse_and_keyboard_x11.h" |
28 #endif | 27 #endif |
29 | 28 |
30 #if defined(OS_CHROMEOS) | 29 #if defined(OS_CHROMEOS) |
31 #include "chromeos/dbus/dbus_thread_manager.h" | 30 #include "chromeos/dbus/dbus_thread_manager.h" |
32 #endif // OS_CHROMEOS | 31 #endif // OS_CHROMEOS |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 gfx::Vector3dF cross(base); | 102 gfx::Vector3dF cross(base); |
104 cross.Cross(other); | 103 cross.Cross(other); |
105 // If the dot product of this cross product is normal, it means that the | 104 // If the dot product of this cross product is normal, it means that the |
106 // shortest angle between |base| and |other| was counterclockwise with respect | 105 // shortest angle between |base| and |other| was counterclockwise with respect |
107 // to the surface represented by |normal| and this angle must be reversed. | 106 // to the surface represented by |normal| and this angle must be reversed. |
108 if (gfx::DotProduct(cross, normal) > 0.0f) | 107 if (gfx::DotProduct(cross, normal) > 0.0f) |
109 angle = 360.0f - angle; | 108 angle = 360.0f - angle; |
110 return angle; | 109 return angle; |
111 } | 110 } |
112 | 111 |
113 #if defined(OS_CHROMEOS) | |
114 | |
115 // An event handler which listens for a volume down + power keypress and | |
116 // triggers a screenshot when this is seen. | |
117 class ScreenshotActionHandler : public ui::EventHandler { | |
118 public: | |
119 ScreenshotActionHandler(); | |
120 virtual ~ScreenshotActionHandler(); | |
121 | |
122 // ui::EventHandler: | |
123 virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE; | |
124 | |
125 private: | |
126 bool volume_down_pressed_; | |
127 | |
128 DISALLOW_COPY_AND_ASSIGN(ScreenshotActionHandler); | |
129 }; | |
130 | |
131 ScreenshotActionHandler::ScreenshotActionHandler() | |
132 : volume_down_pressed_(false) { | |
133 Shell::GetInstance()->PrependPreTargetHandler(this); | |
134 } | |
135 | |
136 ScreenshotActionHandler::~ScreenshotActionHandler() { | |
137 Shell::GetInstance()->RemovePreTargetHandler(this); | |
138 } | |
139 | |
140 void ScreenshotActionHandler::OnKeyEvent(ui::KeyEvent* event) { | |
141 if (event->key_code() == ui::VKEY_VOLUME_DOWN) { | |
142 volume_down_pressed_ = event->type() == ui::ET_KEY_PRESSED || | |
143 event->type() == ui::ET_TRANSLATED_KEY_PRESS; | |
144 } else if (volume_down_pressed_ && | |
145 event->key_code() == ui::VKEY_POWER && | |
146 event->type() == ui::ET_KEY_PRESSED) { | |
147 Shell::GetInstance()->accelerator_controller()->PerformAction( | |
148 ash::TAKE_SCREENSHOT, ui::Accelerator()); | |
149 } | |
150 } | |
151 | |
152 #endif // OS_CHROMEOS | |
153 | |
154 } // namespace | 112 } // namespace |
155 | 113 |
156 MaximizeModeController::MaximizeModeController() | 114 MaximizeModeController::MaximizeModeController() |
157 : rotation_locked_(false), | 115 : rotation_locked_(false), |
158 have_seen_accelerometer_data_(false), | 116 have_seen_accelerometer_data_(false), |
159 ignore_display_configuration_updates_(false), | 117 ignore_display_configuration_updates_(false), |
160 shutting_down_(false), | 118 shutting_down_(false), |
161 user_rotation_(gfx::Display::ROTATE_0), | 119 user_rotation_(gfx::Display::ROTATE_0), |
162 last_touchview_transition_time_(base::Time::Now()), | 120 last_touchview_transition_time_(base::Time::Now()), |
163 tick_clock_(new base::DefaultTickClock()), | 121 tick_clock_(new base::DefaultTickClock()), |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
425 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 383 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
426 if (display_manager->HasInternalDisplay()) { | 384 if (display_manager->HasInternalDisplay()) { |
427 current_rotation_ = user_rotation_ = display_manager-> | 385 current_rotation_ = user_rotation_ = display_manager-> |
428 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); | 386 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); |
429 LoadDisplayRotationProperties(); | 387 LoadDisplayRotationProperties(); |
430 } | 388 } |
431 EnableMaximizeModeWindowManager(true); | 389 EnableMaximizeModeWindowManager(true); |
432 #if defined(USE_X11) | 390 #if defined(USE_X11) |
433 event_blocker_.reset(new ScopedDisableInternalMouseAndKeyboardX11); | 391 event_blocker_.reset(new ScopedDisableInternalMouseAndKeyboardX11); |
434 #endif | 392 #endif |
435 #if defined(OS_CHROMEOS) | |
436 event_handler_.reset(new ScreenshotActionHandler); | |
437 #endif | |
438 Shell::GetInstance()->display_controller()->AddObserver(this); | 393 Shell::GetInstance()->display_controller()->AddObserver(this); |
439 } | 394 } |
440 | 395 |
441 void MaximizeModeController::LeaveMaximizeMode() { | 396 void MaximizeModeController::LeaveMaximizeMode() { |
442 if (!IsMaximizeModeWindowManagerEnabled()) | 397 if (!IsMaximizeModeWindowManagerEnabled()) |
443 return; | 398 return; |
444 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 399 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
445 if (display_manager->HasInternalDisplay()) { | 400 if (display_manager->HasInternalDisplay()) { |
446 gfx::Display::Rotation current_rotation = display_manager-> | 401 gfx::Display::Rotation current_rotation = display_manager-> |
447 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); | 402 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); |
448 if (current_rotation != user_rotation_) | 403 if (current_rotation != user_rotation_) |
449 SetDisplayRotation(display_manager, user_rotation_); | 404 SetDisplayRotation(display_manager, user_rotation_); |
450 } | 405 } |
451 if (!shutting_down_) | 406 if (!shutting_down_) |
452 SetRotationLocked(false); | 407 SetRotationLocked(false); |
453 EnableMaximizeModeWindowManager(false); | 408 EnableMaximizeModeWindowManager(false); |
454 event_blocker_.reset(); | 409 event_blocker_.reset(); |
455 event_handler_.reset(); | |
456 Shell::GetInstance()->display_controller()->RemoveObserver(this); | 410 Shell::GetInstance()->display_controller()->RemoveObserver(this); |
457 } | 411 } |
458 | 412 |
459 // Called after maximize mode has started, windows might still animate though. | 413 // Called after maximize mode has started, windows might still animate though. |
460 void MaximizeModeController::OnMaximizeModeStarted() { | 414 void MaximizeModeController::OnMaximizeModeStarted() { |
461 RecordTouchViewStateTransition(); | 415 RecordTouchViewStateTransition(); |
462 } | 416 } |
463 | 417 |
464 // Called after maximize mode has ended, windows might still be returning to | 418 // Called after maximize mode has ended, windows might still be returning to |
465 // their original position. | 419 // their original position. |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
521 return elapsed_time <= kLidRecentlyOpenedDuration; | 475 return elapsed_time <= kLidRecentlyOpenedDuration; |
522 } | 476 } |
523 | 477 |
524 void MaximizeModeController::SetTickClockForTest( | 478 void MaximizeModeController::SetTickClockForTest( |
525 scoped_ptr<base::TickClock> tick_clock) { | 479 scoped_ptr<base::TickClock> tick_clock) { |
526 DCHECK(tick_clock_); | 480 DCHECK(tick_clock_); |
527 tick_clock_ = tick_clock.Pass(); | 481 tick_clock_ = tick_clock.Pass(); |
528 } | 482 } |
529 | 483 |
530 } // namespace ash | 484 } // namespace ash |
OLD | NEW |