Chromium Code Reviews| Index: athena/input/input_manager_impl.cc |
| diff --git a/athena/input/input_manager_impl.cc b/athena/input/input_manager_impl.cc |
| index 1594b43b16e8d5bf9bd8582a6a990e25ec9bc0e9..4b92e237d778a3717e5c2fb5fab3080ce222d28c 100644 |
| --- a/athena/input/input_manager_impl.cc |
| +++ b/athena/input/input_manager_impl.cc |
| @@ -2,65 +2,43 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -#include "athena/input/public/input_manager.h" |
| +#include "athena/input/input_manager_impl.h" |
| -#include "athena/input/accelerator_manager_impl.h" |
| #include "base/logging.h" |
| -#include "ui/aura/client/event_client.h" |
| +#include "chromeos/dbus/dbus_thread_manager.h" |
| #include "ui/aura/env.h" |
| #include "ui/aura/window.h" |
| -#include "ui/events/event_target.h" |
| namespace athena { |
| namespace { |
| -InputManager* instance = NULL; |
| - |
| -class InputManagerImpl : public InputManager, |
| - public ui::EventTarget, |
| - public aura::client::EventClient { |
| - public: |
| - InputManagerImpl(); |
| - virtual ~InputManagerImpl(); |
| - |
| - void Init(); |
| - void Shutdown(); |
| - |
| - private: |
| - // InputManager: |
| - virtual void OnRootWindowCreated(aura::Window* root_window) override; |
| - virtual ui::EventTarget* GetTopmostEventTarget() override { return this; } |
| - virtual AcceleratorManager* GetAcceleratorManager() override { |
| - return accelerator_manager_.get(); |
| - } |
| - |
| - // Overridden from aura::client::EventClient: |
| - virtual bool CanProcessEventsWithinSubtree( |
| - const aura::Window* window) const override { |
| - return window && !window->ignore_events(); |
| - } |
| - virtual ui::EventTarget* GetToplevelEventTarget() override { return this; } |
| +// The amount of time that the power button must be held to be |
| +// treated as long press. |
| +const int kLongPressTimeoutMs = 1000; |
| - // ui::EventTarget: |
| - virtual bool CanAcceptEvent(const ui::Event& event) override; |
| - virtual ui::EventTarget* GetParentTarget() override; |
| - virtual scoped_ptr<ui::EventTargetIterator> GetChildIterator() const override; |
| - virtual ui::EventTargeter* GetEventTargeter() override; |
| - virtual void OnEvent(ui::Event* event) override; |
| - |
| - scoped_ptr<AcceleratorManagerImpl> accelerator_manager_; |
| +InputManager* instance = NULL; |
| - DISALLOW_COPY_AND_ASSIGN(InputManagerImpl); |
| +enum { |
| + CMD_DEBUG_POWER_BUTTON_PRESSED, |
| + CMD_DEBUG_POWER_BUTTON_RELEASED, |
| }; |
| +} // namespace |
| + |
| InputManagerImpl::InputManagerImpl() |
| : accelerator_manager_( |
| - AcceleratorManagerImpl::CreateGlobalAcceleratorManager()) { |
| + AcceleratorManagerImpl::CreateGlobalAcceleratorManager()), |
| + power_button_timeout_ms_(kLongPressTimeoutMs), |
| + brightness_is_zero_(false) { |
| DCHECK(!instance); |
| instance = this; |
| + chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver( |
| + this); |
| } |
| InputManagerImpl::~InputManagerImpl() { |
| + chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver( |
| + this); |
| DCHECK_EQ(instance, this); |
| Shutdown(); |
| instance = NULL; |
| @@ -68,6 +46,7 @@ InputManagerImpl::~InputManagerImpl() { |
| void InputManagerImpl::Init() { |
| accelerator_manager_->Init(); |
| + InstallAccelerators(); |
| } |
| void InputManagerImpl::Shutdown() { |
| @@ -79,6 +58,31 @@ void InputManagerImpl::OnRootWindowCreated(aura::Window* root_window) { |
| accelerator_manager_->OnRootWindowCreated(root_window); |
| } |
| +ui::EventTarget* InputManagerImpl::GetTopmostEventTarget() { |
| + return this; |
| +} |
| + |
| +AcceleratorManager* InputManagerImpl::GetAcceleratorManager() { |
| + return accelerator_manager_.get(); |
| +} |
| + |
| +void InputManagerImpl::AddPowerButtonObserver(PowerButtonObserver* observer) { |
| + power_button_observers_.AddObserver(observer); |
| +} |
| +void InputManagerImpl::RemovePowerButtonObserver( |
| + PowerButtonObserver* observer) { |
| + power_button_observers_.RemoveObserver(observer); |
| +} |
| + |
| +bool InputManagerImpl::CanProcessEventsWithinSubtree( |
| + const aura::Window* window) const { |
| + return window && !window->ignore_events(); |
| +} |
| + |
| +ui::EventTarget* InputManagerImpl::GetToplevelEventTarget() { |
| + return this; |
| +} |
| + |
| bool InputManagerImpl::CanAcceptEvent(const ui::Event& event) { |
| return true; |
| } |
| @@ -99,7 +103,87 @@ ui::EventTargeter* InputManagerImpl::GetEventTargeter() { |
| void InputManagerImpl::OnEvent(ui::Event* event) { |
| } |
| -} // namespace |
| +void InputManagerImpl::BrightnessChanged(int level, bool user_initiated) { |
| + if (brightness_is_zero_) |
| + zero_brightness_end_time_ = base::TimeTicks::Now(); |
| + brightness_is_zero_ = (level == 0); |
|
Jun Mukai
2014/10/15 23:38:45
I personally feel that these power-button related
|
| +} |
| + |
| +void InputManagerImpl::PowerButtonEventReceived( |
| + bool down, |
| + const base::TimeTicks& timestamp) { |
| + // Ignore power button pressed while the screen is off (http://crbug.com/128451). |
|
Jun Mukai
2014/10/15 23:38:45
exceeds 80 chars?
|
| + // TODO(oshima): This needs to be revisited for athena. |
| + base::TimeDelta time_since_zero_brightness = |
| + brightness_is_zero_ |
| + ? base::TimeDelta() |
| + : (base::TimeTicks::Now() - zero_brightness_end_time_); |
| + const int kShortTimeMs = 10; |
| + if (time_since_zero_brightness.InMilliseconds() <= kShortTimeMs) |
| + return; |
| + |
| + if (down) { |
| + FOR_EACH_OBSERVER(PowerButtonObserver, |
| + power_button_observers_, |
| + OnPowerButtonStateChanged(PowerButtonObserver::PRESSED)); |
| + timer_.Start(FROM_HERE, |
| + base::TimeDelta::FromMilliseconds(kLongPressTimeoutMs), |
| + this, |
| + &InputManagerImpl::NotifyLongPress); |
| + } else { |
| + FOR_EACH_OBSERVER(PowerButtonObserver, |
| + power_button_observers_, |
| + OnPowerButtonStateChanged(PowerButtonObserver::RELEASED)); |
| + timer_.Stop(); |
| + } |
| +} |
| + |
| +bool InputManagerImpl::IsCommandEnabled(int command_id) const { |
| + return true; |
| +} |
| + |
| +bool InputManagerImpl::OnAcceleratorFired(int command_id, |
| + const ui::Accelerator& accelerator) { |
| + switch (command_id) { |
| + case CMD_DEBUG_POWER_BUTTON_PRESSED: |
| + PowerButtonEventReceived(true, base::TimeTicks()); |
| + break; |
| + case CMD_DEBUG_POWER_BUTTON_RELEASED: |
| + PowerButtonEventReceived(false, base::TimeTicks()); |
| + break; |
| + } |
| + return true; |
| +} |
| + |
| +void InputManagerImpl::NotifyLongPress() { |
| + FOR_EACH_OBSERVER( |
| + PowerButtonObserver, |
| + power_button_observers_, |
| + OnPowerButtonStateChanged(PowerButtonObserver::LONG_PRESSED)); |
| +} |
| + |
| +void InputManagerImpl::InstallAccelerators() { |
| + const AcceleratorData accelerator_data[] = { |
| + {TRIGGER_ON_PRESS, |
| + ui::VKEY_P, |
| + ui::EF_ALT_DOWN, |
| + CMD_DEBUG_POWER_BUTTON_PRESSED, |
| + AF_DEBUG | AF_NON_AUTO_REPEATABLE}, |
| + {TRIGGER_ON_RELEASE, |
| + ui::VKEY_P, |
| + ui::EF_ALT_DOWN, |
| + CMD_DEBUG_POWER_BUTTON_RELEASED, |
| + AF_DEBUG}, |
| + }; |
| + AcceleratorManager::Get()->RegisterAccelerators( |
| + accelerator_data, arraysize(accelerator_data), this); |
| +} |
| + |
| +int InputManagerImpl::SetPowerButtonTimeoutMsForTest(int timeout) { |
| + int old_timeout = power_button_timeout_ms_; |
| + power_button_timeout_ms_ = timeout; |
| + return old_timeout; |
| +} |
| // static |
| InputManager* InputManager::Create() { |