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 bool MagnifierKeyScroller::ShouldStopEventPropagation() const {
59 void MagnifierKeyScroller::OnKeyHold(const ui::KeyEvent
* event
) {
60 MagnificationController
* controller
=
61 Shell::GetInstance()->magnification_controller();
62 switch (event
->key_code()) {
64 controller
->SetScrollDirection(MagnificationController::SCROLL_UP
);
67 controller
->SetScrollDirection(MagnificationController::SCROLL_DOWN
);
70 controller
->SetScrollDirection(MagnificationController::SCROLL_LEFT
);
73 controller
->SetScrollDirection(MagnificationController::SCROLL_RIGHT
);
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() {}