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. 4 5 #include "ash/accelerators/magnifier_key_scroller.h" 6 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 13 namespace ash { 14 namespace { 15 bool magnifier_key_scroller_enabled = false; 16 } 17 18 // static IsEnabled()19bool MagnifierKeyScroller::IsEnabled() { 20 bool has_switch = false; 21 #if defined(OS_CHROMEOS) 22 has_switch = CommandLine::ForCurrentProcess()->HasSwitch( 23 switches::kAshEnableMagnifierKeyScroller); 24 #endif 25 26 return (magnifier_key_scroller_enabled || has_switch) && 27 ash::Shell::GetInstance()->magnification_controller()->IsEnabled(); 28 } 29 30 // static SetEnabled(bool enabled)31void MagnifierKeyScroller::SetEnabled(bool enabled) { 32 magnifier_key_scroller_enabled = enabled; 33 } 34 35 // static CreateHandler()36scoped_ptr<ui::EventHandler> MagnifierKeyScroller::CreateHandler() { 37 scoped_ptr<KeyHoldDetector::Delegate> delegate(new MagnifierKeyScroller()); 38 return scoped_ptr<ui::EventHandler>(new KeyHoldDetector(delegate.Pass())); 39 } 40 ShouldProcessEvent(const ui::KeyEvent * event) const41bool 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); 47 } 48 IsStartEvent(const ui::KeyEvent * event) const49bool MagnifierKeyScroller::IsStartEvent(const ui::KeyEvent* event) const { 50 return event->type() == ui::ET_KEY_PRESSED && 51 event->flags() & ui::EF_SHIFT_DOWN; 52 } 53 OnKeyHold(const ui::KeyEvent * event)54void 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(); 72 } 73 } 74 OnKeyUnhold(const ui::KeyEvent * event)75void MagnifierKeyScroller::OnKeyUnhold(const ui::KeyEvent* event) { 76 MagnificationController* controller = 77 Shell::GetInstance()->magnification_controller(); 78 controller->SetScrollDirection(MagnificationController::SCROLL_NONE); 79 } 80 MagnifierKeyScroller()81MagnifierKeyScroller::MagnifierKeyScroller() {} 82 ~MagnifierKeyScroller()83MagnifierKeyScroller::~MagnifierKeyScroller() {} 84 85 } // namespace ash 86