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"
16 bool magnifier_key_scroller_enabled
= false;
20 bool MagnifierKeyScroller::IsEnabled() {
21 bool has_switch
= false;
22 #if defined(OS_CHROMEOS)
23 has_switch
= base::CommandLine::ForCurrentProcess()->HasSwitch(
24 switches::kAshEnableMagnifierKeyScroller
);
27 return (magnifier_key_scroller_enabled
|| has_switch
) &&
28 ash::Shell::GetInstance()->magnification_controller()->IsEnabled();
32 void MagnifierKeyScroller::SetEnabled(bool enabled
) {
33 magnifier_key_scroller_enabled
= enabled
;
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 {
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()) {
60 controller
->SetScrollDirection(MagnificationController::SCROLL_UP
);
63 controller
->SetScrollDirection(MagnificationController::SCROLL_DOWN
);
66 controller
->SetScrollDirection(MagnificationController::SCROLL_LEFT
);
69 controller
->SetScrollDirection(MagnificationController::SCROLL_RIGHT
);
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() {}