This source file includes following definitions.
- controller_
- OnScreenBrightnessChanged
- OnPowerButtonEvent
- OnLockButtonEvent
- OnDisplayModeChanged
#include "ash/wm/power_button_controller.h"
#include "ash/ash_switches.h"
#include "ash/session_state_delegate.h"
#include "ash/shell.h"
#include "ash/shell_window_ids.h"
#include "ash/wm/lock_state_controller.h"
#include "ash/wm/session_state_animator.h"
#include "base/command_line.h"
#include "ui/aura/window_event_dispatcher.h"
#include "ui/display/chromeos/display_snapshot.h"
#include "ui/wm/core/compound_event_filter.h"
namespace ash {
PowerButtonController::PowerButtonController(
LockStateController* controller)
: power_button_down_(false),
lock_button_down_(false),
brightness_is_zero_(false),
internal_display_off_and_external_display_on_(false),
has_legacy_power_button_(
CommandLine::ForCurrentProcess()->HasSwitch(
switches::kAuraLegacyPowerButton)),
controller_(controller) {
#if defined(OS_CHROMEOS)
Shell::GetInstance()->output_configurator()->AddObserver(this);
#endif
}
PowerButtonController::~PowerButtonController() {
#if defined(OS_CHROMEOS)
Shell::GetInstance()->output_configurator()->RemoveObserver(this);
#endif
}
void PowerButtonController::OnScreenBrightnessChanged(double percent) {
brightness_is_zero_ = percent <= 0.001;
}
void PowerButtonController::OnPowerButtonEvent(
bool down, const base::TimeTicks& timestamp) {
power_button_down_ = down;
if (controller_->ShutdownRequested())
return;
if (brightness_is_zero_ && !internal_display_off_and_external_display_on_)
return;
const SessionStateDelegate* session_state_delegate =
Shell::GetInstance()->session_state_delegate();
if (has_legacy_power_button_) {
if (down) {
if (session_state_delegate->CanLockScreen() &&
!session_state_delegate->IsScreenLocked() &&
!controller_->LockRequested()) {
controller_->StartLockAnimationAndLockImmediately();
} else {
controller_->RequestShutdown();
}
}
} else {
if (down) {
if (controller_->LockRequested())
return;
if (session_state_delegate->CanLockScreen() &&
!session_state_delegate->IsScreenLocked()) {
controller_->StartLockAnimation(true);
} else {
controller_->StartShutdownAnimation();
}
} else {
if (controller_->CanCancelLockAnimation())
controller_->CancelLockAnimation();
else if (controller_->CanCancelShutdownAnimation())
controller_->CancelShutdownAnimation();
}
}
}
void PowerButtonController::OnLockButtonEvent(
bool down, const base::TimeTicks& timestamp) {
lock_button_down_ = down;
const SessionStateDelegate* session_state_delegate =
Shell::GetInstance()->session_state_delegate();
if (!session_state_delegate->CanLockScreen() ||
session_state_delegate->IsScreenLocked() ||
controller_->LockRequested() ||
controller_->ShutdownRequested()) {
return;
}
if (power_button_down_)
return;
if (down)
controller_->StartLockAnimation(false);
else
controller_->CancelLockAnimation();
}
#if defined(OS_CHROMEOS)
void PowerButtonController::OnDisplayModeChanged(
const ui::OutputConfigurator::DisplayStateList& outputs) {
bool internal_display_off = false;
bool external_display_on = false;
for (size_t i = 0; i < outputs.size(); ++i) {
const ui::OutputConfigurator::DisplayState& output = outputs[i];
if (output.display->type() == ui::OUTPUT_TYPE_INTERNAL) {
if (!output.display->current_mode())
internal_display_off = true;
} else if (output.display->current_mode()) {
external_display_on = true;
}
}
internal_display_off_and_external_display_on_ =
internal_display_off && external_display_on;
}
#endif
}