OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/power_button_controller.h" | 5 #include "ash/wm/power_button_controller.h" |
6 | 6 |
7 #include "ash/ash_switches.h" | 7 #include "ash/ash_switches.h" |
8 #include "ash/session/session_state_delegate.h" | 8 #include "ash/session/session_state_delegate.h" |
9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
10 #include "ash/shell_window_ids.h" | 10 #include "ash/shell_window_ids.h" |
11 #include "ash/wm/lock_state_controller.h" | 11 #include "ash/wm/lock_state_controller.h" |
| 12 #include "ash/wm/maximize_mode/maximize_mode_controller.h" |
12 #include "ash/wm/session_state_animator.h" | 13 #include "ash/wm/session_state_animator.h" |
13 #include "base/command_line.h" | 14 #include "base/command_line.h" |
14 #include "ui/aura/window_event_dispatcher.h" | 15 #include "ui/aura/window_event_dispatcher.h" |
15 #include "ui/display/types/chromeos/display_snapshot.h" | 16 #include "ui/display/types/chromeos/display_snapshot.h" |
| 17 #include "ui/events/event_handler.h" |
16 #include "ui/wm/core/compound_event_filter.h" | 18 #include "ui/wm/core/compound_event_filter.h" |
17 | 19 |
18 namespace ash { | 20 namespace ash { |
19 | 21 |
20 PowerButtonController::PowerButtonController( | 22 PowerButtonController::PowerButtonController( |
21 LockStateController* controller) | 23 LockStateController* controller) |
22 : power_button_down_(false), | 24 : power_button_down_(false), |
23 lock_button_down_(false), | 25 lock_button_down_(false), |
| 26 volume_down_pressed_(false), |
24 brightness_is_zero_(false), | 27 brightness_is_zero_(false), |
25 internal_display_off_and_external_display_on_(false), | 28 internal_display_off_and_external_display_on_(false), |
26 has_legacy_power_button_( | 29 has_legacy_power_button_( |
27 CommandLine::ForCurrentProcess()->HasSwitch( | 30 CommandLine::ForCurrentProcess()->HasSwitch( |
28 switches::kAuraLegacyPowerButton)), | 31 switches::kAuraLegacyPowerButton)), |
| 32 enable_quick_lock_(CommandLine::ForCurrentProcess()->HasSwitch( |
| 33 switches::kAshEnablePowerButtonQuickLock)), |
29 controller_(controller) { | 34 controller_(controller) { |
30 #if defined(OS_CHROMEOS) | 35 #if defined(OS_CHROMEOS) |
31 Shell::GetInstance()->display_configurator()->AddObserver(this); | 36 Shell::GetInstance()->display_configurator()->AddObserver(this); |
32 #endif | 37 #endif |
| 38 Shell::GetInstance()->PrependPreTargetHandler(this); |
33 } | 39 } |
34 | 40 |
35 PowerButtonController::~PowerButtonController() { | 41 PowerButtonController::~PowerButtonController() { |
36 #if defined(OS_CHROMEOS) | 42 #if defined(OS_CHROMEOS) |
37 Shell::GetInstance()->display_configurator()->RemoveObserver(this); | 43 Shell::GetInstance()->display_configurator()->RemoveObserver(this); |
38 #endif | 44 #endif |
| 45 Shell::GetInstance()->RemovePreTargetHandler(this); |
39 } | 46 } |
40 | 47 |
41 void PowerButtonController::OnScreenBrightnessChanged(double percent) { | 48 void PowerButtonController::OnScreenBrightnessChanged(double percent) { |
42 brightness_is_zero_ = percent <= 0.001; | 49 brightness_is_zero_ = percent <= 0.001; |
43 } | 50 } |
44 | 51 |
45 void PowerButtonController::OnPowerButtonEvent( | 52 void PowerButtonController::OnPowerButtonEvent( |
46 bool down, const base::TimeTicks& timestamp) { | 53 bool down, const base::TimeTicks& timestamp) { |
47 power_button_down_ = down; | 54 power_button_down_ = down; |
48 | 55 |
49 if (controller_->ShutdownRequested()) | 56 if (controller_->ShutdownRequested()) |
50 return; | 57 return; |
51 | 58 |
52 // Avoid starting the lock/shutdown sequence if the power button is pressed | 59 // Avoid starting the lock/shutdown sequence if the power button is pressed |
53 // while the screen is off (http://crbug.com/128451), unless an external | 60 // while the screen is off (http://crbug.com/128451), unless an external |
54 // display is still on (http://crosbug.com/p/24912). | 61 // display is still on (http://crosbug.com/p/24912). |
55 if (brightness_is_zero_ && !internal_display_off_and_external_display_on_) | 62 if (brightness_is_zero_ && !internal_display_off_and_external_display_on_) |
56 return; | 63 return; |
57 | 64 |
| 65 if (volume_down_pressed_ && down && |
| 66 Shell::GetInstance()->maximize_mode_controller()-> |
| 67 IsMaximizeModeWindowManagerEnabled()) { |
| 68 Shell::GetInstance()->accelerator_controller()->PerformAction( |
| 69 ash::TAKE_SCREENSHOT, ui::Accelerator()); |
| 70 return; |
| 71 } |
| 72 |
58 const SessionStateDelegate* session_state_delegate = | 73 const SessionStateDelegate* session_state_delegate = |
59 Shell::GetInstance()->session_state_delegate(); | 74 Shell::GetInstance()->session_state_delegate(); |
60 if (has_legacy_power_button_) { | 75 if (has_legacy_power_button_) { |
61 // If power button releases won't get reported correctly because we're not | 76 // If power button releases won't get reported correctly because we're not |
62 // running on official hardware, just lock the screen or shut down | 77 // running on official hardware, just lock the screen or shut down |
63 // immediately. | 78 // immediately. |
64 if (down) { | 79 if (down) { |
65 if (session_state_delegate->CanLockScreen() && | 80 if (session_state_delegate->CanLockScreen() && |
66 !session_state_delegate->IsScreenLocked() && | 81 !session_state_delegate->IsScreenLocked() && |
67 !controller_->LockRequested()) { | 82 !controller_->LockRequested()) { |
68 controller_->StartLockAnimationAndLockImmediately(); | 83 controller_->StartLockAnimationAndLockImmediately(false); |
69 } else { | 84 } else { |
70 controller_->RequestShutdown(); | 85 controller_->RequestShutdown(); |
71 } | 86 } |
72 } | 87 } |
73 } else { // !has_legacy_power_button_ | 88 } else { // !has_legacy_power_button_ |
74 if (down) { | 89 if (down) { |
75 // If we already have a pending request to lock the screen, wait. | 90 // If we already have a pending request to lock the screen, wait. |
76 if (controller_->LockRequested()) | 91 if (controller_->LockRequested()) |
77 return; | 92 return; |
78 | 93 |
79 if (session_state_delegate->CanLockScreen() && | 94 if (session_state_delegate->CanLockScreen() && |
80 !session_state_delegate->IsScreenLocked()) { | 95 !session_state_delegate->IsScreenLocked()) { |
81 controller_->StartLockAnimation(true); | 96 if (Shell::GetInstance()->maximize_mode_controller()-> |
| 97 IsMaximizeModeWindowManagerEnabled() && enable_quick_lock_) |
| 98 controller_->StartLockAnimationAndLockImmediately(true); |
| 99 else |
| 100 controller_->StartLockAnimation(true); |
82 } else { | 101 } else { |
83 controller_->StartShutdownAnimation(); | 102 controller_->StartShutdownAnimation(); |
84 } | 103 } |
85 } else { // Button is up. | 104 } else { // Button is up. |
86 if (controller_->CanCancelLockAnimation()) | 105 if (controller_->CanCancelLockAnimation()) |
87 controller_->CancelLockAnimation(); | 106 controller_->CancelLockAnimation(); |
88 else if (controller_->CanCancelShutdownAnimation()) | 107 else if (controller_->CanCancelShutdownAnimation()) |
89 controller_->CancelShutdownAnimation(); | 108 controller_->CancelShutdownAnimation(); |
90 } | 109 } |
91 } | 110 } |
92 } | 111 } |
93 | 112 |
94 void PowerButtonController::OnLockButtonEvent( | 113 void PowerButtonController::OnLockButtonEvent( |
95 bool down, const base::TimeTicks& timestamp) { | 114 bool down, const base::TimeTicks& timestamp) { |
96 lock_button_down_ = down; | 115 lock_button_down_ = down; |
97 | 116 |
98 const SessionStateDelegate* session_state_delegate = | 117 const SessionStateDelegate* session_state_delegate = |
99 Shell::GetInstance()->session_state_delegate(); | 118 Shell::GetInstance()->session_state_delegate(); |
100 if (!session_state_delegate->CanLockScreen() || | 119 if (!session_state_delegate->CanLockScreen() || |
101 session_state_delegate->IsScreenLocked() || | 120 session_state_delegate->IsScreenLocked() || |
102 controller_->LockRequested() || | 121 controller_->LockRequested() || |
103 controller_->ShutdownRequested()) { | 122 controller_->ShutdownRequested()) { |
104 return; | 123 return; |
105 } | 124 } |
106 | 125 |
107 // Give the power button precedence over the lock button (we don't expect both | 126 // Give the power button precedence over the lock button. |
108 // buttons to be present, so this is just making sure that we don't do | |
109 // something completely stupid if that assumption changes later). | |
110 if (power_button_down_) | 127 if (power_button_down_) |
111 return; | 128 return; |
112 | 129 |
113 if (down) | 130 if (down) |
114 controller_->StartLockAnimation(false); | 131 controller_->StartLockAnimation(false); |
115 else | 132 else |
116 controller_->CancelLockAnimation(); | 133 controller_->CancelLockAnimation(); |
117 } | 134 } |
118 | 135 |
| 136 void PowerButtonController::OnKeyEvent(ui::KeyEvent* event) { |
| 137 if (event->key_code() == ui::VKEY_VOLUME_DOWN) { |
| 138 volume_down_pressed_ = event->type() == ui::ET_KEY_PRESSED || |
| 139 event->type() == ui::ET_TRANSLATED_KEY_PRESS; |
| 140 } |
| 141 } |
| 142 |
119 #if defined(OS_CHROMEOS) | 143 #if defined(OS_CHROMEOS) |
120 void PowerButtonController::OnDisplayModeChanged( | 144 void PowerButtonController::OnDisplayModeChanged( |
121 const ui::DisplayConfigurator::DisplayStateList& display_states) { | 145 const ui::DisplayConfigurator::DisplayStateList& display_states) { |
122 bool internal_display_off = false; | 146 bool internal_display_off = false; |
123 bool external_display_on = false; | 147 bool external_display_on = false; |
124 for (size_t i = 0; i < display_states.size(); ++i) { | 148 for (size_t i = 0; i < display_states.size(); ++i) { |
125 const ui::DisplayConfigurator::DisplayState& state = display_states[i]; | 149 const ui::DisplayConfigurator::DisplayState& state = display_states[i]; |
126 if (state.display->type() == ui::DISPLAY_CONNECTION_TYPE_INTERNAL) { | 150 if (state.display->type() == ui::DISPLAY_CONNECTION_TYPE_INTERNAL) { |
127 if (!state.display->current_mode()) | 151 if (!state.display->current_mode()) |
128 internal_display_off = true; | 152 internal_display_off = true; |
129 } else if (state.display->current_mode()) { | 153 } else if (state.display->current_mode()) { |
130 external_display_on = true; | 154 external_display_on = true; |
131 } | 155 } |
132 } | 156 } |
133 internal_display_off_and_external_display_on_ = | 157 internal_display_off_and_external_display_on_ = |
134 internal_display_off && external_display_on; | 158 internal_display_off && external_display_on; |
135 } | 159 } |
136 #endif | 160 #endif |
137 | 161 |
138 } // namespace ash | 162 } // namespace ash |
OLD | NEW |