Move VISUAL_STATE promise to activation
[chromium-blink-merge.git] / ash / accelerators / magnifier_key_scroller.cc
blobeeeda2dfa81b01a95995a5b06cb2842ec559e65c
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"
13 namespace ash {
14 namespace {
15 bool magnifier_key_scroller_enabled = false;
18 // static
19 bool MagnifierKeyScroller::IsEnabled() {
20 bool has_switch = false;
21 #if defined(OS_CHROMEOS)
22 has_switch = base::CommandLine::ForCurrentProcess()->HasSwitch(
23 switches::kAshEnableMagnifierKeyScroller);
24 #endif
26 return (magnifier_key_scroller_enabled || has_switch) &&
27 ash::Shell::GetInstance()->magnification_controller()->IsEnabled();
30 // static
31 void MagnifierKeyScroller::SetEnabled(bool enabled) {
32 magnifier_key_scroller_enabled = enabled;
35 // static
36 scoped_ptr<ui::EventHandler> MagnifierKeyScroller::CreateHandler() {
37 scoped_ptr<KeyHoldDetector::Delegate> delegate(new MagnifierKeyScroller());
38 return scoped_ptr<ui::EventHandler>(new KeyHoldDetector(delegate.Pass()));
41 bool MagnifierKeyScroller::ShouldProcessEvent(const ui::KeyEvent* event) const {
42 return IsEnabled() &&
43 (event->key_code() == ui::VKEY_UP ||
44 event->key_code() == ui::VKEY_DOWN ||
45 event->key_code() == ui::VKEY_LEFT ||
46 event->key_code() == ui::VKEY_RIGHT);
49 bool MagnifierKeyScroller::IsStartEvent(const ui::KeyEvent* event) const {
50 return event->type() == ui::ET_KEY_PRESSED &&
51 event->flags() & ui::EF_SHIFT_DOWN;
54 void MagnifierKeyScroller::OnKeyHold(const ui::KeyEvent* event) {
55 MagnificationController* controller =
56 Shell::GetInstance()->magnification_controller();
57 switch (event->key_code()) {
58 case ui::VKEY_UP:
59 controller->SetScrollDirection(MagnificationController::SCROLL_UP);
60 break;
61 case ui::VKEY_DOWN:
62 controller->SetScrollDirection(MagnificationController::SCROLL_DOWN);
63 break;
64 case ui::VKEY_LEFT:
65 controller->SetScrollDirection(MagnificationController::SCROLL_LEFT);
66 break;
67 case ui::VKEY_RIGHT:
68 controller->SetScrollDirection(MagnificationController::SCROLL_RIGHT);
69 break;
70 default:
71 NOTREACHED() << "Unknown keyboard_code:" << event->key_code();
75 void MagnifierKeyScroller::OnKeyUnhold(const ui::KeyEvent* event) {
76 MagnificationController* controller =
77 Shell::GetInstance()->magnification_controller();
78 controller->SetScrollDirection(MagnificationController::SCROLL_NONE);
81 MagnifierKeyScroller::MagnifierKeyScroller() {}
83 MagnifierKeyScroller::~MagnifierKeyScroller() {}
85 } // namespace ash