15d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved. 25d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// found in the LICENSE file. 45d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 55d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ash/accelerators/magnifier_key_scroller.h" 65d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 75d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ash/accelerators/key_hold_detector.h" 85d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ash/ash_switches.h" 95d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ash/magnifier/magnification_controller.h" 105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ash/shell.h" 115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/command_line.h" 125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)namespace ash { 145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)namespace { 155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool magnifier_key_scroller_enabled = false; 165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// static 195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool MagnifierKeyScroller::IsEnabled() { 20cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) bool has_switch = false; 21cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#if defined(OS_CHROMEOS) 22cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) has_switch = CommandLine::ForCurrentProcess()->HasSwitch( 23cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) switches::kAshEnableMagnifierKeyScroller); 24cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#endif 25cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 26cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) return (magnifier_key_scroller_enabled || has_switch) && 275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ash::Shell::GetInstance()->magnification_controller()->IsEnabled(); 285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// static 315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void MagnifierKeyScroller::SetEnabled(bool enabled) { 325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) magnifier_key_scroller_enabled = enabled; 335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// static 365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)scoped_ptr<ui::EventHandler> MagnifierKeyScroller::CreateHandler() { 375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) scoped_ptr<KeyHoldDetector::Delegate> delegate(new MagnifierKeyScroller()); 385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return scoped_ptr<ui::EventHandler>(new KeyHoldDetector(delegate.Pass())); 395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool MagnifierKeyScroller::ShouldProcessEvent(const ui::KeyEvent* event) const { 425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return IsEnabled() && 435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) (event->key_code() == ui::VKEY_UP || 445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) event->key_code() == ui::VKEY_DOWN || 455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) event->key_code() == ui::VKEY_LEFT || 465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) event->key_code() == ui::VKEY_RIGHT); 475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool MagnifierKeyScroller::IsStartEvent(const ui::KeyEvent* event) const { 505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return event->type() == ui::ET_KEY_PRESSED && 515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) event->flags() & ui::EF_SHIFT_DOWN; 525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void MagnifierKeyScroller::OnKeyHold(const ui::KeyEvent* event) { 555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MagnificationController* controller = 565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Shell::GetInstance()->magnification_controller(); 575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) switch (event->key_code()) { 585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) case ui::VKEY_UP: 595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) controller->SetScrollDirection(MagnificationController::SCROLL_UP); 605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) break; 615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) case ui::VKEY_DOWN: 625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) controller->SetScrollDirection(MagnificationController::SCROLL_DOWN); 635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) break; 645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) case ui::VKEY_LEFT: 655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) controller->SetScrollDirection(MagnificationController::SCROLL_LEFT); 665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) break; 675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) case ui::VKEY_RIGHT: 685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) controller->SetScrollDirection(MagnificationController::SCROLL_RIGHT); 695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) break; 705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) default: 715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) NOTREACHED() << "Unknown keyboard_code:" << event->key_code(); 725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void MagnifierKeyScroller::OnKeyUnhold(const ui::KeyEvent* event) { 765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MagnificationController* controller = 775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Shell::GetInstance()->magnification_controller(); 785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) controller->SetScrollDirection(MagnificationController::SCROLL_NONE); 795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)MagnifierKeyScroller::MagnifierKeyScroller() {} 825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)MagnifierKeyScroller::~MagnifierKeyScroller() {} 845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} // namespace ash 86