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/common/ash_switches.h" | 7 #include "ash/common/ash_switches.h" |
8 #include "ash/common/session/session_state_delegate.h" | 8 #include "ash/common/session/session_state_delegate.h" |
9 #include "ash/common/shell_window_ids.h" | 9 #include "ash/common/shell_window_ids.h" |
10 #include "ash/shell.h" | 10 #include "ash/shell.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/maximize_mode/maximize_mode_controller.h" |
13 #include "ash/wm/session_state_animator.h" | 13 #include "ash/wm/session_state_animator.h" |
14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
15 #include "ui/aura/window_event_dispatcher.h" | 15 #include "ui/aura/window_event_dispatcher.h" |
16 #include "ui/display/types/display_snapshot.h" | 16 #include "ui/display/types/display_snapshot.h" |
17 #include "ui/events/event_handler.h" | 17 #include "ui/events/event_handler.h" |
18 #include "ui/wm/core/compound_event_filter.h" | 18 #include "ui/wm/core/compound_event_filter.h" |
19 | 19 |
20 namespace ash { | 20 namespace ash { |
21 | 21 |
22 PowerButtonController::PowerButtonController(LockStateController* controller) | 22 PowerButtonController::PowerButtonController(LockStateController* controller) |
23 : power_button_down_(false), | 23 : power_button_down_(false), |
24 lock_button_down_(false), | 24 lock_button_down_(false), |
25 volume_down_pressed_(false), | 25 volume_down_pressed_(false), |
26 brightness_is_zero_(false), | 26 brightness_is_zero_(false), |
27 internal_display_off_and_external_display_on_(false), | 27 internal_display_off_and_external_display_on_(false), |
28 has_legacy_power_button_( | 28 has_legacy_power_button_( |
29 base::CommandLine::ForCurrentProcess() | 29 base::CommandLine::ForCurrentProcess()->HasSwitch( |
30 ->HasSwitch(switches::kAuraLegacyPowerButton)), | 30 switches::kAuraLegacyPowerButton)), |
31 #if defined(OS_CHROMEOS) | 31 #if defined(OS_CHROMEOS) |
32 enable_quick_lock_(base::CommandLine::ForCurrentProcess()->HasSwitch( | 32 enable_quick_lock_(base::CommandLine::ForCurrentProcess()->HasSwitch( |
33 switches::kAshEnableTouchView)), | 33 switches::kAshEnableTouchView)), |
34 #else | 34 #else |
35 enable_quick_lock_(false), | 35 enable_quick_lock_(false), |
36 #endif | 36 #endif |
37 controller_(controller) { | 37 controller_(controller) { |
38 #if defined(OS_CHROMEOS) | 38 #if defined(OS_CHROMEOS) |
39 Shell::GetInstance()->display_configurator()->AddObserver(this); | 39 Shell::GetInstance()->display_configurator()->AddObserver(this); |
40 #endif | 40 #endif |
41 Shell::GetInstance()->PrependPreTargetHandler(this); | 41 Shell::GetInstance()->PrependPreTargetHandler(this); |
42 } | 42 } |
43 | 43 |
44 PowerButtonController::~PowerButtonController() { | 44 PowerButtonController::~PowerButtonController() { |
45 #if defined(OS_CHROMEOS) | 45 #if defined(OS_CHROMEOS) |
46 Shell::GetInstance()->display_configurator()->RemoveObserver(this); | 46 Shell::GetInstance()->display_configurator()->RemoveObserver(this); |
47 #endif | 47 #endif |
48 Shell::GetInstance()->RemovePreTargetHandler(this); | 48 Shell::GetInstance()->RemovePreTargetHandler(this); |
49 } | 49 } |
50 | 50 |
51 void PowerButtonController::OnScreenBrightnessChanged(double percent) { | 51 void PowerButtonController::OnScreenBrightnessChanged(double percent) { |
52 brightness_is_zero_ = percent <= 0.001; | 52 brightness_is_zero_ = percent <= 0.001; |
53 } | 53 } |
54 | 54 |
55 void PowerButtonController::OnPowerButtonEvent( | 55 void PowerButtonController::OnPowerButtonEvent( |
56 bool down, const base::TimeTicks& timestamp) { | 56 bool down, |
| 57 const base::TimeTicks& timestamp) { |
57 power_button_down_ = down; | 58 power_button_down_ = down; |
58 | 59 |
59 if (controller_->ShutdownRequested()) | 60 if (controller_->ShutdownRequested()) |
60 return; | 61 return; |
61 | 62 |
62 // Avoid starting the lock/shutdown sequence if the power button is pressed | 63 // Avoid starting the lock/shutdown sequence if the power button is pressed |
63 // while the screen is off (http://crbug.com/128451), unless an external | 64 // while the screen is off (http://crbug.com/128451), unless an external |
64 // display is still on (http://crosbug.com/p/24912). | 65 // display is still on (http://crosbug.com/p/24912). |
65 if (brightness_is_zero_ && !internal_display_off_and_external_display_on_) | 66 if (brightness_is_zero_ && !internal_display_off_and_external_display_on_) |
66 return; | 67 return; |
67 | 68 |
68 if (volume_down_pressed_ && down && | 69 if (volume_down_pressed_ && down && |
69 Shell::GetInstance()->maximize_mode_controller()-> | 70 Shell::GetInstance() |
70 IsMaximizeModeWindowManagerEnabled()) { | 71 ->maximize_mode_controller() |
| 72 ->IsMaximizeModeWindowManagerEnabled()) { |
71 Shell::GetInstance()->accelerator_controller()->PerformActionIfEnabled( | 73 Shell::GetInstance()->accelerator_controller()->PerformActionIfEnabled( |
72 ash::TAKE_SCREENSHOT); | 74 ash::TAKE_SCREENSHOT); |
73 return; | 75 return; |
74 } | 76 } |
75 | 77 |
76 const SessionStateDelegate* session_state_delegate = | 78 const SessionStateDelegate* session_state_delegate = |
77 Shell::GetInstance()->session_state_delegate(); | 79 Shell::GetInstance()->session_state_delegate(); |
78 if (has_legacy_power_button_) { | 80 if (has_legacy_power_button_) { |
79 // If power button releases won't get reported correctly because we're not | 81 // If power button releases won't get reported correctly because we're not |
80 // running on official hardware, just lock the screen or shut down | 82 // running on official hardware, just lock the screen or shut down |
81 // immediately. | 83 // immediately. |
82 if (down) { | 84 if (down) { |
83 if (session_state_delegate->CanLockScreen() && | 85 if (session_state_delegate->CanLockScreen() && |
84 !session_state_delegate->IsUserSessionBlocked() && | 86 !session_state_delegate->IsUserSessionBlocked() && |
85 !controller_->LockRequested()) { | 87 !controller_->LockRequested()) { |
86 controller_->StartLockAnimationAndLockImmediately(false); | 88 controller_->StartLockAnimationAndLockImmediately(false); |
87 } else { | 89 } else { |
88 controller_->RequestShutdown(); | 90 controller_->RequestShutdown(); |
89 } | 91 } |
90 } | 92 } |
91 } else { // !has_legacy_power_button_ | 93 } else { // !has_legacy_power_button_ |
92 if (down) { | 94 if (down) { |
93 // If we already have a pending request to lock the screen, wait. | 95 // If we already have a pending request to lock the screen, wait. |
94 if (controller_->LockRequested()) | 96 if (controller_->LockRequested()) |
95 return; | 97 return; |
96 | 98 |
97 if (session_state_delegate->CanLockScreen() && | 99 if (session_state_delegate->CanLockScreen() && |
98 !session_state_delegate->IsUserSessionBlocked()) { | 100 !session_state_delegate->IsUserSessionBlocked()) { |
99 if (Shell::GetInstance()->maximize_mode_controller()-> | 101 if (Shell::GetInstance() |
100 IsMaximizeModeWindowManagerEnabled() && enable_quick_lock_) | 102 ->maximize_mode_controller() |
| 103 ->IsMaximizeModeWindowManagerEnabled() && |
| 104 enable_quick_lock_) |
101 controller_->StartLockAnimationAndLockImmediately(true); | 105 controller_->StartLockAnimationAndLockImmediately(true); |
102 else | 106 else |
103 controller_->StartLockAnimation(true); | 107 controller_->StartLockAnimation(true); |
104 } else { | 108 } else { |
105 controller_->StartShutdownAnimation(); | 109 controller_->StartShutdownAnimation(); |
106 } | 110 } |
107 } else { // Button is up. | 111 } else { // Button is up. |
108 if (controller_->CanCancelLockAnimation()) | 112 if (controller_->CanCancelLockAnimation()) |
109 controller_->CancelLockAnimation(); | 113 controller_->CancelLockAnimation(); |
110 else if (controller_->CanCancelShutdownAnimation()) | 114 else if (controller_->CanCancelShutdownAnimation()) |
111 controller_->CancelShutdownAnimation(); | 115 controller_->CancelShutdownAnimation(); |
112 } | 116 } |
113 } | 117 } |
114 } | 118 } |
115 | 119 |
116 void PowerButtonController::OnLockButtonEvent( | 120 void PowerButtonController::OnLockButtonEvent( |
117 bool down, const base::TimeTicks& timestamp) { | 121 bool down, |
| 122 const base::TimeTicks& timestamp) { |
118 lock_button_down_ = down; | 123 lock_button_down_ = down; |
119 | 124 |
120 const SessionStateDelegate* session_state_delegate = | 125 const SessionStateDelegate* session_state_delegate = |
121 Shell::GetInstance()->session_state_delegate(); | 126 Shell::GetInstance()->session_state_delegate(); |
122 if (!session_state_delegate->CanLockScreen() || | 127 if (!session_state_delegate->CanLockScreen() || |
123 session_state_delegate->IsScreenLocked() || | 128 session_state_delegate->IsScreenLocked() || |
124 controller_->LockRequested() || | 129 controller_->LockRequested() || controller_->ShutdownRequested()) { |
125 controller_->ShutdownRequested()) { | |
126 return; | 130 return; |
127 } | 131 } |
128 | 132 |
129 // Give the power button precedence over the lock button. | 133 // Give the power button precedence over the lock button. |
130 if (power_button_down_) | 134 if (power_button_down_) |
131 return; | 135 return; |
132 | 136 |
133 if (down) | 137 if (down) |
134 controller_->StartLockAnimation(false); | 138 controller_->StartLockAnimation(false); |
135 else | 139 else |
(...skipping 17 matching lines...) Expand all Loading... |
153 } else if (display->current_mode()) { | 157 } else if (display->current_mode()) { |
154 external_display_on = true; | 158 external_display_on = true; |
155 } | 159 } |
156 } | 160 } |
157 internal_display_off_and_external_display_on_ = | 161 internal_display_off_and_external_display_on_ = |
158 internal_display_off && external_display_on; | 162 internal_display_off && external_display_on; |
159 } | 163 } |
160 #endif | 164 #endif |
161 | 165 |
162 } // namespace ash | 166 } // namespace ash |
OLD | NEW |