Skip to content

Commit

Permalink
Remove return value for VolumeControlDelegate::HandleVolumeMute() and…
Browse files Browse the repository at this point in the history
… co.

In order to split AcceleratorController::PerformAction() into
AcceleratorController::CanPerformAction() and
AcceleratorController::PerformAction(), it is necessary to either:
- Know whether the VolumeControlDelegate should process VKEY_VOLUME_MUTE  prior
  to calling VolumeControlDelegate::HandleVolumeMute(). This would require
  introducing VolumeControlDelegate::CanHandleVolumeMute().
OR
- Have VolumeControlDelegate always process VKEY_VOLUME_MUTE.

In the case of VolumeControlDelegate, KeyboardBrightnessControlDelegate and
BrightnessControlDelegate the non-test implementations always handle the key
events.

This CL:
- Removes the return values of the implementations of VolumeControlDelegate,
  KeyboardBrightnessControlDelegate and BrightnessControlDelegate given that
  the non-test implementations always return true.
- Makes the volume and brightness accelerators CrOS only. This allows the
  volume and brightness keys to be always handled. (VolumeControlDelegate is
  the only consume of VKEY_VOLUME_MUTE so it is ok for it to always handle the
  event)

BUG=404473
TEST=None

Review URL: https://codereview.chromium.org/734893002

Cr-Commit-Position: refs/heads/master@{#305229}
  • Loading branch information
pkotwicz authored and Commit bot committed Nov 21, 2014
1 parent 34497e9 commit ccfd8f4
Show file tree
Hide file tree
Showing 16 changed files with 151 additions and 235 deletions.
104 changes: 70 additions & 34 deletions ash/accelerators/accelerator_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ bool HandleToggleFullscreen(ui::KeyboardCode key_code) {
return true;
}

bool HandleToggleOverview(const ui::Accelerator& accelerator) {
bool HandleToggleOverview() {
base::RecordAction(base::UserMetricsAction("Accel_Overview_F5"));
Shell::GetInstance()->window_selector_controller()->ToggleOverview();
return true;
Expand Down Expand Up @@ -501,6 +501,20 @@ bool HandlePositionCenter() {
}

#if defined(OS_CHROMEOS)
bool HandleBrightnessDown(BrightnessControlDelegate* delegate,
const ui::Accelerator& accelerator) {
if (delegate)
delegate->HandleBrightnessDown(accelerator);
return true;
}

bool HandleBrightnessUp(BrightnessControlDelegate* delegate,
const ui::Accelerator& accelerator) {
if (delegate)
delegate->HandleBrightnessUp(accelerator);
return true;
}

bool HandleDisableCapsLock(ui::KeyboardCode key_code,
ui::EventType previous_event_type,
ui::KeyboardCode previous_key_code) {
Expand All @@ -524,6 +538,20 @@ bool HandleDisableCapsLock(ui::KeyboardCode key_code,
return false;
}

bool HandleKeyboardBrightnessDown(KeyboardBrightnessControlDelegate* delegate,
const ui::Accelerator& accelerator) {
if (delegate)
delegate->HandleKeyboardBrightnessDown(accelerator);
return true;
}

bool HandleKeyboardBrightnessUp(KeyboardBrightnessControlDelegate* delegate,
const ui::Accelerator& accelerator) {
if (delegate)
delegate->HandleKeyboardBrightnessUp(accelerator);
return true;
}

bool HandleLock(ui::KeyboardCode key_code) {
base::RecordAction(UserMetricsAction("Accel_LockScreen_L"));
Shell::GetInstance()->session_state_delegate()->LockScreen();
Expand Down Expand Up @@ -650,6 +678,30 @@ bool HandleTouchHudModeChange() {
return false;
}

bool HandleVolumeDown(const ui::Accelerator& accelerator) {
VolumeControlDelegate* volume_delegate =
Shell::GetInstance()->system_tray_delegate()->GetVolumeControlDelegate();
if (volume_delegate)
volume_delegate->HandleVolumeDown(accelerator);
return true;
}

bool HandleVolumeMute(const ui::Accelerator& accelerator) {
VolumeControlDelegate* volume_delegate =
Shell::GetInstance()->system_tray_delegate()->GetVolumeControlDelegate();
if (volume_delegate)
volume_delegate->HandleVolumeMute(accelerator);
return true;
}

bool HandleVolumeUp(const ui::Accelerator& accelerator) {
VolumeControlDelegate* volume_delegate =
Shell::GetInstance()->system_tray_delegate()->GetVolumeControlDelegate();
if (volume_delegate)
volume_delegate->HandleVolumeUp(accelerator);
return true;
}

#endif // defined(OS_CHROMEOS)

class AutoSet {
Expand Down Expand Up @@ -831,7 +883,6 @@ void AcceleratorController::RegisterAccelerators(

bool AcceleratorController::PerformAction(AcceleratorAction action,
const ui::Accelerator& accelerator) {
ash::Shell* shell = ash::Shell::GetInstance();
AcceleratorProcessingRestriction restriction =
GetAcceleratorProcessingRestriction(action);
if (restriction != RESTRICTION_NONE)
Expand Down Expand Up @@ -860,14 +911,6 @@ bool AcceleratorController::PerformAction(AcceleratorAction action,
return HandleAccessibleFocusCycle(false);
case ACCESSIBLE_FOCUS_PREVIOUS:
return HandleAccessibleFocusCycle(true);
case BRIGHTNESS_DOWN:
if (brightness_control_delegate_)
return brightness_control_delegate_->HandleBrightnessDown(accelerator);
return false;
case BRIGHTNESS_UP:
if (brightness_control_delegate_)
return brightness_control_delegate_->HandleBrightnessUp(accelerator);
return false;
case CYCLE_BACKWARD_MRU:
return HandleCycleBackwardMRU(accelerator);
case CYCLE_FORWARD_MRU:
Expand Down Expand Up @@ -974,22 +1017,7 @@ bool AcceleratorController::PerformAction(AcceleratorAction action,
accelerators::ToggleMaximized();
return true;
case TOGGLE_OVERVIEW:
return HandleToggleOverview(accelerator);
case VOLUME_DOWN: {
ash::VolumeControlDelegate* volume_delegate =
shell->system_tray_delegate()->GetVolumeControlDelegate();
return volume_delegate && volume_delegate->HandleVolumeDown(accelerator);
}
case VOLUME_MUTE: {
ash::VolumeControlDelegate* volume_delegate =
shell->system_tray_delegate()->GetVolumeControlDelegate();
return volume_delegate && volume_delegate->HandleVolumeMute(accelerator);
}
case VOLUME_UP: {
ash::VolumeControlDelegate* volume_delegate =
shell->system_tray_delegate()->GetVolumeControlDelegate();
return volume_delegate && volume_delegate->HandleVolumeUp(accelerator);
}
return HandleToggleOverview();
case WINDOW_CYCLE_SNAP_DOCK_LEFT:
case WINDOW_CYCLE_SNAP_DOCK_RIGHT:
return HandleWindowSnapOrDock(action);
Expand All @@ -998,6 +1026,12 @@ bool AcceleratorController::PerformAction(AcceleratorAction action,
case WINDOW_POSITION_CENTER:
return HandlePositionCenter();
#if defined(OS_CHROMEOS)
case BRIGHTNESS_DOWN:
return HandleBrightnessDown(brightness_control_delegate_.get(),
accelerator);
case BRIGHTNESS_UP:
return HandleBrightnessUp(brightness_control_delegate_.get(),
accelerator);
case DEBUG_ADD_REMOVE_DISPLAY:
return debug::PerformDebugAction(action);
case DISABLE_CAPS_LOCK:
Expand All @@ -1007,15 +1041,11 @@ bool AcceleratorController::PerformAction(AcceleratorAction action,
Shell::GetInstance()->gpu_support()->DisableGpuWatchdog();
return true;
case KEYBOARD_BRIGHTNESS_DOWN:
if (keyboard_brightness_control_delegate_)
return keyboard_brightness_control_delegate_->
HandleKeyboardBrightnessDown(accelerator);
return false;
return HandleKeyboardBrightnessDown(
keyboard_brightness_control_delegate_.get(), accelerator);
case KEYBOARD_BRIGHTNESS_UP:
if (keyboard_brightness_control_delegate_)
return keyboard_brightness_control_delegate_->
HandleKeyboardBrightnessUp(accelerator);
return false;
return HandleKeyboardBrightnessUp(
keyboard_brightness_control_delegate_.get(), accelerator);
case LOCK_PRESSED:
case LOCK_RELEASED:
Shell::GetInstance()->power_button_controller()->
Expand Down Expand Up @@ -1068,6 +1098,12 @@ bool AcceleratorController::PerformAction(AcceleratorAction action,
case TOUCH_HUD_PROJECTION_TOGGLE:
accelerators::ToggleTouchHudProjection();
return true;
case VOLUME_DOWN:
return HandleVolumeDown(accelerator);
case VOLUME_MUTE:
return HandleVolumeMute(accelerator);
case VOLUME_UP:
return HandleVolumeUp(accelerator);
#else
case DUMMY_FOR_RESERVED:
NOTREACHED();
Expand Down
Loading

0 comments on commit ccfd8f4

Please sign in to comment.