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"
15 bool magnifier_key_scroller_enabled
= false;
19 bool MagnifierKeyScroller::IsEnabled() {
20 bool has_switch
= false;
21 #if defined(OS_CHROMEOS)
22 has_switch
= base::CommandLine::ForCurrentProcess()->HasSwitch(
23 switches::kAshEnableMagnifierKeyScroller
);
26 return (magnifier_key_scroller_enabled
|| has_switch
) &&
27 ash::Shell::GetInstance()->magnification_controller()->IsEnabled();
31 void MagnifierKeyScroller::SetEnabled(bool enabled
) {
32 magnifier_key_scroller_enabled
= enabled
;
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 {
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()) {
59 controller
->SetScrollDirection(MagnificationController::SCROLL_UP
);
62 controller
->SetScrollDirection(MagnificationController::SCROLL_DOWN
);
65 controller
->SetScrollDirection(MagnificationController::SCROLL_LEFT
);
68 controller
->SetScrollDirection(MagnificationController::SCROLL_RIGHT
);
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() {}