Skip to content

Commit

Permalink
Move keyboard brightness controller to ash/system/chromeos.
Browse files Browse the repository at this point in the history
BUG=119298
R=stevenjb@chromium.org,oshima@chromium.org

Review URL: https://chromiumcodereview.appspot.com/11150020

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@163616 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
tfarina@chromium.org committed Oct 23, 2012
1 parent 64d8d39 commit 30f58c9
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 37 deletions.
20 changes: 13 additions & 7 deletions ash/accelerators/accelerator_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@

#if defined(OS_CHROMEOS)
#include "ash/display/output_configurator_animation.h"
#include "ash/system/chromeos/keyboard_brightness_controller.h"
#include "base/chromeos/chromeos_version.h"
#include "base/time.h"
#include "chromeos/display/output_configurator.h"
Expand Down Expand Up @@ -370,6 +371,11 @@ void AcceleratorController::Init() {

if (DebugShortcutsEnabled())
RegisterAccelerators(kDebugAcceleratorData, kDebugAcceleratorDataLength);

#if defined(OS_CHROMEOS)
keyboard_brightness_control_delegate_.reset(
new KeyboardBrightnessController());
#endif
}

void AcceleratorController::Register(const ui::Accelerator& accelerator,
Expand Down Expand Up @@ -827,13 +833,6 @@ void AcceleratorController::SetImeControlDelegate(
ime_control_delegate_.swap(ime_control_delegate);
}

void AcceleratorController::SetKeyboardBrightnessControlDelegate(
scoped_ptr<KeyboardBrightnessControlDelegate>
keyboard_brightness_control_delegate) {
keyboard_brightness_control_delegate_.swap(
keyboard_brightness_control_delegate);
}

void AcceleratorController::SetScreenshotDelegate(
scoped_ptr<ScreenshotDelegate> screenshot_delegate) {
screenshot_delegate_.swap(screenshot_delegate);
Expand Down Expand Up @@ -892,6 +891,13 @@ void AcceleratorController::RegisterAccelerators(
}
}

void AcceleratorController::SetKeyboardBrightnessControlDelegate(
scoped_ptr<KeyboardBrightnessControlDelegate>
keyboard_brightness_control_delegate) {
keyboard_brightness_control_delegate_ =
keyboard_brightness_control_delegate.Pass();
}

bool AcceleratorController::CanHandleAccelerators() const {
return true;
}
Expand Down
12 changes: 8 additions & 4 deletions ash/accelerators/accelerator_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
#include <map>
#include <set>

#include "ash/ash_export.h"
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/gtest_prod_util.h"
#include "base/memory/scoped_ptr.h"
#include "ash/ash_export.h"
#include "ui/base/accelerators/accelerator.h"

namespace ui {
Expand Down Expand Up @@ -76,16 +77,15 @@ class ASH_EXPORT AcceleratorController : public ui::AcceleratorTarget {
scoped_ptr<BrightnessControlDelegate> brightness_control_delegate);
void SetImeControlDelegate(
scoped_ptr<ImeControlDelegate> ime_control_delegate);
void SetKeyboardBrightnessControlDelegate(
scoped_ptr<KeyboardBrightnessControlDelegate>
keyboard_brightness_control_delegate);
void SetScreenshotDelegate(
scoped_ptr<ScreenshotDelegate> screenshot_delegate);
BrightnessControlDelegate* brightness_control_delegate() const {
return brightness_control_delegate_.get();
}

private:
FRIEND_TEST_ALL_PREFIXES(AcceleratorControllerTest, GlobalAccelerators);

// Initializes the accelerators this class handles as a target.
void Init();

Expand All @@ -97,6 +97,10 @@ class ASH_EXPORT AcceleratorController : public ui::AcceleratorTarget {
void RegisterAccelerators(const AcceleratorData accelerators[],
size_t accelerators_length);

void SetKeyboardBrightnessControlDelegate(
scoped_ptr<KeyboardBrightnessControlDelegate>
keyboard_brightness_control_delegate);

scoped_ptr<ui::AcceleratorManager> accelerator_manager_;

// TODO(derat): BrightnessControlDelegate is also used by the system tray;
Expand Down
8 changes: 3 additions & 5 deletions ash/accelerators/accelerator_controller_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#endif

namespace ash {
namespace test {

namespace {

Expand Down Expand Up @@ -308,7 +307,7 @@ bool TestTarget::CanHandleAccelerators() const {

} // namespace

class AcceleratorControllerTest : public AshTestBase {
class AcceleratorControllerTest : public test::AshTestBase {
public:
AcceleratorControllerTest() {};
virtual ~AcceleratorControllerTest() {};
Expand Down Expand Up @@ -824,8 +823,8 @@ TEST_F(AcceleratorControllerTest, GlobalAccelerators) {
const ui::Accelerator alt_f6(ui::VKEY_F6, ui::EF_ALT_DOWN);
const ui::Accelerator alt_f7(ui::VKEY_F7, ui::EF_ALT_DOWN);
{
EXPECT_FALSE(GetController()->Process(alt_f6));
EXPECT_FALSE(GetController()->Process(alt_f7));
EXPECT_TRUE(GetController()->Process(alt_f6));
EXPECT_TRUE(GetController()->Process(alt_f7));
DummyKeyboardBrightnessControlDelegate* delegate =
new DummyKeyboardBrightnessControlDelegate(false);
GetController()->SetKeyboardBrightnessControlDelegate(
Expand Down Expand Up @@ -1177,5 +1176,4 @@ TEST_F(AcceleratorControllerTest, DisallowedAtModalWindow) {
}
#endif

} // namespace test
} // namespace ash
2 changes: 2 additions & 0 deletions ash/ash.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@
'system/brightness/brightness_control_delegate.h',
'system/brightness/tray_brightness.cc',
'system/brightness/tray_brightness.h',
'system/chromeos/keyboard_brightness_controller.cc',
'system/chromeos/keyboard_brightness_controller.h',
'system/chromeos/network/network_observer.h',
'system/chromeos/network/tray_network.cc',
'system/chromeos/network/tray_network.h',
Expand Down
4 changes: 2 additions & 2 deletions ash/display/multi_display_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class Rect;
}

namespace ash {
namespace test {
class AcceleratorControllerTest;
namespace test {
class AshTestBase;
class SystemGestureEventFilterTest;
}
Expand Down Expand Up @@ -106,7 +106,7 @@ class ASH_EXPORT MultiDisplayManager : public aura::DisplayManager,
private:
FRIEND_TEST_ALL_PREFIXES(ExtendedDesktopTest, ConvertPoint);
FRIEND_TEST_ALL_PREFIXES(MultiDisplayManagerTest, TestNativeDisplaysChanged);
friend class test::AcceleratorControllerTest;
friend class ash::AcceleratorControllerTest;
friend class test::AshTestBase;
friend class MultiDisplayManagerTest;
friend class test::SystemGestureEventFilterTest;
Expand Down
2 changes: 2 additions & 0 deletions ash/shell_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class SystemTrayDelegate;
class UserWallpaperDelegate;

enum UserMetricsAction {
UMA_ACCEL_KEYBOARD_BRIGHTNESS_DOWN_F6,
UMA_ACCEL_KEYBOARD_BRIGHTNESS_UP_F7,
UMA_ACCEL_MAXIMIZE_RESTORE_F4,
UMA_ACCEL_NEWTAB_T,
UMA_ACCEL_NEXTWINDOW_F5,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,22 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/ui/ash/keyboard_brightness_controller_chromeos.h"
#include "ash/system/chromeos/keyboard_brightness_controller.h"

#include "ash/shell.h"
#include "ash/shell_delegate.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/power_manager_client.h"
#include "content/public/browser/user_metrics.h"
#include "ui/base/accelerators/accelerator.h"

namespace ash {

bool KeyboardBrightnessController::HandleKeyboardBrightnessDown(
const ui::Accelerator& accelerator) {
if (accelerator.key_code() == ui::VKEY_F6) {
content::RecordAction(
content::UserMetricsAction("Accel_KeyboardBrightnessDown_F6"));
Shell::GetInstance()->delegate()->RecordUserMetricsAction(
UMA_ACCEL_KEYBOARD_BRIGHTNESS_DOWN_F6);
}

chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->
Expand All @@ -24,11 +28,13 @@ bool KeyboardBrightnessController::HandleKeyboardBrightnessDown(
bool KeyboardBrightnessController::HandleKeyboardBrightnessUp(
const ui::Accelerator& accelerator) {
if (accelerator.key_code() == ui::VKEY_F7) {
content::RecordAction(
content::UserMetricsAction("Accel_KeyboardBrightnessUp_F7"));
Shell::GetInstance()->delegate()->RecordUserMetricsAction(
UMA_ACCEL_KEYBOARD_BRIGHTNESS_UP_F7);
}

chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->
IncreaseKeyboardBrightness();
return true;
}

} // namespace ash
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,34 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_UI_ASH_KEYBOARD_BRIGHTNESS_CONTROLLER_CHROMEOS_H_
#define CHROME_BROWSER_UI_ASH_KEYBOARD_BRIGHTNESS_CONTROLLER_CHROMEOS_H_
#ifndef ASH_SYSTEM_CHROMEOS_KEYBOARD_BRIGHTNESS_CONTROLLER_H_
#define ASH_SYSTEM_CHROMEOS_KEYBOARD_BRIGHTNESS_CONTROLLER_H_

#include "ash/ash_export.h"
#include "ash/system/keyboard_brightness/keyboard_brightness_control_delegate.h"
#include "base/basictypes.h"
#include "base/compiler_specific.h"

namespace ash {

// A class which controls keyboard brightness when Alt+F6, Alt+F7 or a
// multimedia key for keyboard brightness is pressed.
class KeyboardBrightnessController
: public ash::KeyboardBrightnessControlDelegate {
class ASH_EXPORT KeyboardBrightnessController
: public KeyboardBrightnessControlDelegate {
public:
KeyboardBrightnessController() {}
virtual ~KeyboardBrightnessController() {}

private:
// Overridden from ash::KeyboardBrightnessControlDelegate:
// Overridden from KeyboardBrightnessControlDelegate:
virtual bool HandleKeyboardBrightnessDown(
const ui::Accelerator& accelerator) OVERRIDE;
virtual bool HandleKeyboardBrightnessUp(
const ui::Accelerator& accelerator) OVERRIDE;

private:
DISALLOW_COPY_AND_ASSIGN(KeyboardBrightnessController);
};

#endif // CHROME_BROWSER_UI_ASH_KEYBOARD_BRIGHTNESS_CONTROLLER_CHROMEOS_H_
} // namespace ash

#endif // ASH_SYSTEM_CHROMEOS_KEYBOARD_BRIGHTNESS_CONTROLLER_H_
5 changes: 0 additions & 5 deletions chrome/browser/ui/ash/ash_init.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,10 @@
#include "chrome/browser/chromeos/login/user_manager.h"
#include "chrome/browser/ui/ash/brightness_controller_chromeos.h"
#include "chrome/browser/ui/ash/ime_controller_chromeos.h"
#include "chrome/browser/ui/ash/keyboard_brightness_controller_chromeos.h"
#include "chrome/browser/ui/ash/volume_controller_chromeos.h"
#include "ui/base/x/x11_util.h"
#endif


namespace chrome {

bool ShouldOpenAshOnStartup() {
Expand Down Expand Up @@ -83,9 +81,6 @@ void OpenAsh() {
new BrightnessController).Pass());
shell->accelerator_controller()->SetImeControlDelegate(
scoped_ptr<ash::ImeControlDelegate>(new ImeController).Pass());
shell->accelerator_controller()->SetKeyboardBrightnessControlDelegate(
scoped_ptr<ash::KeyboardBrightnessControlDelegate>(
new KeyboardBrightnessController).Pass());
ash::Shell::GetInstance()->high_contrast_controller()->SetEnabled(
chromeos::accessibility::IsHighContrastEnabled());

Expand Down
8 changes: 8 additions & 0 deletions chrome/browser/ui/ash/chrome_shell_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,14 @@ void ChromeShellDelegate::RecordUserMetricsAction(
case ash::UMA_LAUNCHER_CLICK_ON_APP:
content::RecordAction(content::UserMetricsAction("Launcher_ClickOnApp"));
break;
case ash::UMA_ACCEL_KEYBOARD_BRIGHTNESS_DOWN_F6:
content::RecordAction(
content::UserMetricsAction("Accel_KeyboardBrightnessDown_F6"));
break;
case ash::UMA_ACCEL_KEYBOARD_BRIGHTNESS_UP_F7:
content::RecordAction(
content::UserMetricsAction("Accel_KeyboardBrightnessUp_F7"));
break;
}
}

Expand Down
2 changes: 0 additions & 2 deletions chrome/chrome_browser_ui.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,6 @@
'browser/ui/ash/extension_utils.h',
'browser/ui/ash/ime_controller_chromeos.cc',
'browser/ui/ash/ime_controller_chromeos.h',
'browser/ui/ash/keyboard_brightness_controller_chromeos.cc',
'browser/ui/ash/keyboard_brightness_controller_chromeos.h',
'browser/ui/ash/launcher/browser_launcher_item_controller.cc',
'browser/ui/ash/launcher/browser_launcher_item_controller.h',
'browser/ui/ash/launcher/chrome_launcher_controller.cc',
Expand Down

0 comments on commit 30f58c9

Please sign in to comment.