Cleanup setting of 'sysroot' in common.gypi
[chromium-blink-merge.git] / ash / accelerators / magnifier_key_scroller.cc
blobf5198dc702a2d82997a341d0a60783d51f2b2c87
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ash/accelerators/magnifier_key_scroller.h"
7 #include "ash/accelerators/key_hold_detector.h"
8 #include "ash/ash_switches.h"
9 #include "ash/magnifier/magnification_controller.h"
10 #include "ash/shell.h"
11 #include "base/command_line.h"
12 #include "ui/events/event.h"
14 namespace ash {
15 namespace {
16 bool magnifier_key_scroller_enabled = false;
19 // static
20 bool MagnifierKeyScroller::IsEnabled() {
21 bool has_switch = false;
22 #if defined(OS_CHROMEOS)
23 has_switch = base::CommandLine::ForCurrentProcess()->HasSwitch(
24 switches::kAshEnableMagnifierKeyScroller);
25 #endif
27 return (magnifier_key_scroller_enabled || has_switch) &&
28 ash::Shell::GetInstance()->magnification_controller()->IsEnabled();
31 // static
32 void MagnifierKeyScroller::SetEnabled(bool enabled) {
33 magnifier_key_scroller_enabled = enabled;
36 // static
37 scoped_ptr<ui::EventHandler> MagnifierKeyScroller::CreateHandler() {
38 scoped_ptr<KeyHoldDetector::Delegate> delegate(new MagnifierKeyScroller());
39 return scoped_ptr<ui::EventHandler>(new KeyHoldDetector(delegate.Pass()));
42 bool MagnifierKeyScroller::ShouldProcessEvent(const ui::KeyEvent* event) const {
43 return IsEnabled() &&
44 (event->key_code() == ui::VKEY_UP ||
45 event->key_code() == ui::VKEY_DOWN ||
46 event->key_code() == ui::VKEY_LEFT ||
47 event->key_code() == ui::VKEY_RIGHT);
50 bool MagnifierKeyScroller::IsStartEvent(const ui::KeyEvent* event) const {
51 return event->type() == ui::ET_KEY_PRESSED &&
52 event->flags() & ui::EF_SHIFT_DOWN;
55 bool MagnifierKeyScroller::ShouldStopEventPropagation() const {
56 return true;
59 void MagnifierKeyScroller::OnKeyHold(const ui::KeyEvent* event) {
60 MagnificationController* controller =
61 Shell::GetInstance()->magnification_controller();
62 switch (event->key_code()) {
63 case ui::VKEY_UP:
64 controller->SetScrollDirection(MagnificationController::SCROLL_UP);
65 break;
66 case ui::VKEY_DOWN:
67 controller->SetScrollDirection(MagnificationController::SCROLL_DOWN);
68 break;
69 case ui::VKEY_LEFT:
70 controller->SetScrollDirection(MagnificationController::SCROLL_LEFT);
71 break;
72 case ui::VKEY_RIGHT:
73 controller->SetScrollDirection(MagnificationController::SCROLL_RIGHT);
74 break;
75 default:
76 NOTREACHED() << "Unknown keyboard_code:" << event->key_code();
80 void MagnifierKeyScroller::OnKeyUnhold(const ui::KeyEvent* event) {
81 MagnificationController* controller =
82 Shell::GetInstance()->magnification_controller();
83 controller->SetScrollDirection(MagnificationController::SCROLL_NONE);
86 MagnifierKeyScroller::MagnifierKeyScroller() {}
88 MagnifierKeyScroller::~MagnifierKeyScroller() {}
90 } // namespace ash