Move OSVersion out of platform_backend.
[chromium-blink-merge.git] / ash / accelerators / magnifier_key_scroller.cc
blob2e339501f33e42a015a21b68c31c878c1bed6958
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 void MagnifierKeyScroller::OnKeyHold(const ui::KeyEvent* event) {
56 MagnificationController* controller =
57 Shell::GetInstance()->magnification_controller();
58 switch (event->key_code()) {
59 case ui::VKEY_UP:
60 controller->SetScrollDirection(MagnificationController::SCROLL_UP);
61 break;
62 case ui::VKEY_DOWN:
63 controller->SetScrollDirection(MagnificationController::SCROLL_DOWN);
64 break;
65 case ui::VKEY_LEFT:
66 controller->SetScrollDirection(MagnificationController::SCROLL_LEFT);
67 break;
68 case ui::VKEY_RIGHT:
69 controller->SetScrollDirection(MagnificationController::SCROLL_RIGHT);
70 break;
71 default:
72 NOTREACHED() << "Unknown keyboard_code:" << event->key_code();
76 void MagnifierKeyScroller::OnKeyUnhold(const ui::KeyEvent* event) {
77 MagnificationController* controller =
78 Shell::GetInstance()->magnification_controller();
79 controller->SetScrollDirection(MagnificationController::SCROLL_NONE);
82 MagnifierKeyScroller::MagnifierKeyScroller() {}
84 MagnifierKeyScroller::~MagnifierKeyScroller() {}
86 } // namespace ash