| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ash/accelerators/magnifier_key_scroller.h" | 5 #include "ash/accelerators/magnifier_key_scroller.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "ash/accelerators/key_hold_detector.h" | 9 #include "ash/accelerators/key_hold_detector.h" |
| 10 #include "ash/common/ash_switches.h" | 10 #include "ash/common/ash_switches.h" |
| 11 #include "ash/magnifier/magnification_controller.h" | 11 #include "ash/magnifier/magnification_controller.h" |
| 12 #include "ash/shell.h" | 12 #include "ash/shell.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "ui/events/event.h" | 14 #include "ui/events/event.h" |
| 15 | 15 |
| 16 namespace ash { | 16 namespace ash { |
| 17 namespace { | 17 namespace { |
| 18 bool magnifier_key_scroller_enabled = false; | 18 bool magnifier_key_scroller_enabled = false; |
| 19 } | 19 } |
| 20 | 20 |
| 21 // static | 21 // static |
| 22 bool MagnifierKeyScroller::IsEnabled() { | 22 bool MagnifierKeyScroller::IsEnabled() { |
| 23 bool has_switch = false; | 23 bool has_switch = false; |
| 24 #if defined(OS_CHROMEOS) | 24 #if defined(OS_CHROMEOS) |
| 25 has_switch = base::CommandLine::ForCurrentProcess()->HasSwitch( | 25 has_switch = base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 26 switches::kAshEnableMagnifierKeyScroller); | 26 switches::kAshEnableMagnifierKeyScroller); |
| 27 #endif | 27 #endif |
| 28 | 28 |
| 29 return (magnifier_key_scroller_enabled || has_switch) && | 29 return (magnifier_key_scroller_enabled || has_switch) && |
| 30 ash::Shell::GetInstance()->magnification_controller()->IsEnabled(); | 30 ash::Shell::GetInstance()->magnification_controller()->IsEnabled(); |
| 31 } | 31 } |
| 32 | 32 |
| 33 // static | 33 // static |
| 34 void MagnifierKeyScroller::SetEnabled(bool enabled) { | 34 void MagnifierKeyScroller::SetEnabled(bool enabled) { |
| 35 magnifier_key_scroller_enabled = enabled; | 35 magnifier_key_scroller_enabled = enabled; |
| 36 } | 36 } |
| 37 | 37 |
| 38 // static | 38 // static |
| 39 std::unique_ptr<ui::EventHandler> MagnifierKeyScroller::CreateHandler() { | 39 std::unique_ptr<ui::EventHandler> MagnifierKeyScroller::CreateHandler() { |
| 40 std::unique_ptr<KeyHoldDetector::Delegate> delegate( | 40 std::unique_ptr<KeyHoldDetector::Delegate> delegate( |
| 41 new MagnifierKeyScroller()); | 41 new MagnifierKeyScroller()); |
| 42 return std::unique_ptr<ui::EventHandler>( | 42 return std::unique_ptr<ui::EventHandler>( |
| 43 new KeyHoldDetector(std::move(delegate))); | 43 new KeyHoldDetector(std::move(delegate))); |
| 44 } | 44 } |
| 45 | 45 |
| 46 bool MagnifierKeyScroller::ShouldProcessEvent(const ui::KeyEvent* event) const { | 46 bool MagnifierKeyScroller::ShouldProcessEvent(const ui::KeyEvent* event) const { |
| 47 return IsEnabled() && | 47 return IsEnabled() && (event->key_code() == ui::VKEY_UP || |
| 48 (event->key_code() == ui::VKEY_UP || | 48 event->key_code() == ui::VKEY_DOWN || |
| 49 event->key_code() == ui::VKEY_DOWN || | 49 event->key_code() == ui::VKEY_LEFT || |
| 50 event->key_code() == ui::VKEY_LEFT || | 50 event->key_code() == ui::VKEY_RIGHT); |
| 51 event->key_code() == ui::VKEY_RIGHT); | |
| 52 } | 51 } |
| 53 | 52 |
| 54 bool MagnifierKeyScroller::IsStartEvent(const ui::KeyEvent* event) const { | 53 bool MagnifierKeyScroller::IsStartEvent(const ui::KeyEvent* event) const { |
| 55 return event->type() == ui::ET_KEY_PRESSED && | 54 return event->type() == ui::ET_KEY_PRESSED && |
| 56 event->flags() & ui::EF_SHIFT_DOWN; | 55 event->flags() & ui::EF_SHIFT_DOWN; |
| 57 } | 56 } |
| 58 | 57 |
| 59 bool MagnifierKeyScroller::ShouldStopEventPropagation() const { | 58 bool MagnifierKeyScroller::ShouldStopEventPropagation() const { |
| 60 return true; | 59 return true; |
| 61 } | 60 } |
| 62 | 61 |
| 63 void MagnifierKeyScroller::OnKeyHold(const ui::KeyEvent* event) { | 62 void MagnifierKeyScroller::OnKeyHold(const ui::KeyEvent* event) { |
| 64 MagnificationController* controller = | 63 MagnificationController* controller = |
| 65 Shell::GetInstance()->magnification_controller(); | 64 Shell::GetInstance()->magnification_controller(); |
| 66 switch (event->key_code()) { | 65 switch (event->key_code()) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 85 MagnificationController* controller = | 84 MagnificationController* controller = |
| 86 Shell::GetInstance()->magnification_controller(); | 85 Shell::GetInstance()->magnification_controller(); |
| 87 controller->SetScrollDirection(MagnificationController::SCROLL_NONE); | 86 controller->SetScrollDirection(MagnificationController::SCROLL_NONE); |
| 88 } | 87 } |
| 89 | 88 |
| 90 MagnifierKeyScroller::MagnifierKeyScroller() {} | 89 MagnifierKeyScroller::MagnifierKeyScroller() {} |
| 91 | 90 |
| 92 MagnifierKeyScroller::~MagnifierKeyScroller() {} | 91 MagnifierKeyScroller::~MagnifierKeyScroller() {} |
| 93 | 92 |
| 94 } // namespace ash | 93 } // namespace ash |
| OLD | NEW |