OLD | NEW |
(Empty) | |
| 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 |
| 19 bool MagnifierKeyScroller::IsEnabled() { |
| 20 return (magnifier_key_scroller_enabled || |
| 21 CommandLine::ForCurrentProcess()->HasSwitch( |
| 22 switches::kAshEnableMagnifierKeyScroller)) && |
| 23 ash::Shell::GetInstance()->magnification_controller()->IsEnabled(); |
| 24 } |
| 25 |
| 26 // static |
| 27 void MagnifierKeyScroller::SetEnabled(bool enabled) { |
| 28 magnifier_key_scroller_enabled = enabled; |
| 29 } |
| 30 |
| 31 // static |
| 32 scoped_ptr<ui::EventHandler> MagnifierKeyScroller::CreateHandler() { |
| 33 scoped_ptr<KeyHoldDetector::Delegate> delegate(new MagnifierKeyScroller()); |
| 34 return scoped_ptr<ui::EventHandler>(new KeyHoldDetector(delegate.Pass())); |
| 35 } |
| 36 |
| 37 bool MagnifierKeyScroller::ShouldProcessEvent(const ui::KeyEvent* event) const { |
| 38 return IsEnabled() && |
| 39 (event->key_code() == ui::VKEY_UP || |
| 40 event->key_code() == ui::VKEY_DOWN || |
| 41 event->key_code() == ui::VKEY_LEFT || |
| 42 event->key_code() == ui::VKEY_RIGHT); |
| 43 } |
| 44 |
| 45 bool MagnifierKeyScroller::IsStartEvent(const ui::KeyEvent* event) const { |
| 46 return event->type() == ui::ET_KEY_PRESSED && |
| 47 event->flags() & ui::EF_SHIFT_DOWN; |
| 48 } |
| 49 |
| 50 void MagnifierKeyScroller::OnKeyHold(const ui::KeyEvent* event) { |
| 51 MagnificationController* controller = |
| 52 Shell::GetInstance()->magnification_controller(); |
| 53 switch (event->key_code()) { |
| 54 case ui::VKEY_UP: |
| 55 controller->SetScrollDirection(MagnificationController::SCROLL_UP); |
| 56 break; |
| 57 case ui::VKEY_DOWN: |
| 58 controller->SetScrollDirection(MagnificationController::SCROLL_DOWN); |
| 59 break; |
| 60 case ui::VKEY_LEFT: |
| 61 controller->SetScrollDirection(MagnificationController::SCROLL_LEFT); |
| 62 break; |
| 63 case ui::VKEY_RIGHT: |
| 64 controller->SetScrollDirection(MagnificationController::SCROLL_RIGHT); |
| 65 break; |
| 66 default: |
| 67 NOTREACHED() << "Unknown keyboard_code:" << event->key_code(); |
| 68 } |
| 69 } |
| 70 |
| 71 void MagnifierKeyScroller::OnKeyUnhold(const ui::KeyEvent* event) { |
| 72 MagnificationController* controller = |
| 73 Shell::GetInstance()->magnification_controller(); |
| 74 controller->SetScrollDirection(MagnificationController::SCROLL_NONE); |
| 75 } |
| 76 |
| 77 MagnifierKeyScroller::MagnifierKeyScroller() {} |
| 78 |
| 79 MagnifierKeyScroller::~MagnifierKeyScroller() {} |
| 80 |
| 81 } // namespace ash |
OLD | NEW |