Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(711)

Side by Side Diff: ash/wm/power_button_controller.cc

Issue 326813004: Added quick lock mechanism while in Touchview (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changed kAshEnablePowerQuickLock to kAshEnablePowerButtonQuickLock. Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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);
37 Shell::GetInstance()->PrependPreTargetHandler(this);
32 #endif 38 #endif
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);
44 Shell::GetInstance()->RemovePreTargetHandler(this);
38 #endif 45 #endif
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()->accelerator_controller()->PerformAction(
flackr 2014/09/03 12:48:29 Can you limit this to be only when in maximize mod
bruthig 2014/09/08 15:33:20 Done.
67 ash::TAKE_SCREENSHOT, ui::Accelerator());
68 return;
69 }
70
58 const SessionStateDelegate* session_state_delegate = 71 const SessionStateDelegate* session_state_delegate =
59 Shell::GetInstance()->session_state_delegate(); 72 Shell::GetInstance()->session_state_delegate();
60 if (has_legacy_power_button_) { 73 if (has_legacy_power_button_) {
61 // If power button releases won't get reported correctly because we're not 74 // 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 75 // running on official hardware, just lock the screen or shut down
63 // immediately. 76 // immediately.
64 if (down) { 77 if (down) {
65 if (session_state_delegate->CanLockScreen() && 78 if (session_state_delegate->CanLockScreen() &&
66 !session_state_delegate->IsScreenLocked() && 79 !session_state_delegate->IsScreenLocked() &&
67 !controller_->LockRequested()) { 80 !controller_->LockRequested()) {
68 controller_->StartLockAnimationAndLockImmediately(); 81 controller_->StartLockAnimationAndLockImmediately(false);
69 } else { 82 } else {
70 controller_->RequestShutdown(); 83 controller_->RequestShutdown();
71 } 84 }
72 } 85 }
73 } else { // !has_legacy_power_button_ 86 } else { // !has_legacy_power_button_
74 if (down) { 87 if (down) {
75 // If we already have a pending request to lock the screen, wait. 88 // If we already have a pending request to lock the screen, wait.
76 if (controller_->LockRequested()) 89 if (controller_->LockRequested())
77 return; 90 return;
78 91
79 if (session_state_delegate->CanLockScreen() && 92 if (session_state_delegate->CanLockScreen() &&
80 !session_state_delegate->IsScreenLocked()) { 93 !session_state_delegate->IsScreenLocked()) {
81 controller_->StartLockAnimation(true); 94 if (Shell::GetInstance()->maximize_mode_controller()->
95 IsMaximizeModeWindowManagerEnabled() && enable_quick_lock_)
96 controller_->StartLockAnimationAndLockImmediately(true);
97 else
98 controller_->StartLockAnimation(true);
82 } else { 99 } else {
83 controller_->StartShutdownAnimation(); 100 controller_->StartShutdownAnimation();
84 } 101 }
85 } else { // Button is up. 102 } else { // Button is up.
86 if (controller_->CanCancelLockAnimation()) 103 if (controller_->CanCancelLockAnimation())
87 controller_->CancelLockAnimation(); 104 controller_->CancelLockAnimation();
88 else if (controller_->CanCancelShutdownAnimation()) 105 else if (controller_->CanCancelShutdownAnimation())
89 controller_->CancelShutdownAnimation(); 106 controller_->CancelShutdownAnimation();
90 } 107 }
91 } 108 }
(...skipping 17 matching lines...) Expand all
109 // something completely stupid if that assumption changes later). 126 // 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
OLDNEW
« ash/wm/power_button_controller.h ('K') | « ash/wm/power_button_controller.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698