diff options
author | mazda@chromium.org <mazda@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-18 03:17:13 +0000 |
---|---|---|
committer | mazda@chromium.org <mazda@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-18 03:17:13 +0000 |
commit | 3b9bb0467aa2b8c7d9f41e5d1b364d3ca84969eb (patch) | |
tree | 6d71596963782f5a4a6f70ac85c7ce9b44db6d7e /ui | |
parent | 24553937f6e10b9f0d64164b74a1355953968b5c (diff) | |
download | chromium_src-3b9bb0467aa2b8c7d9f41e5d1b364d3ca84969eb.zip chromium_src-3b9bb0467aa2b8c7d9f41e5d1b364d3ca84969eb.tar.gz chromium_src-3b9bb0467aa2b8c7d9f41e5d1b364d3ca84969eb.tar.bz2 |
Revert 110637 - Add ShellAcceleratorController that manages global keyboard accelerators.
- Create ShellAcceleratorController that manages global keyboard accelerators and also processes several accelerators as a target.
- Create ShellAcceleratorFilter, which is used by DesktopEventFilter to handle accelerators.
- Add a function to Shell for accessing ShellAcceleratorController.
BUG=97255
TEST=Manual
Review URL: http://codereview.chromium.org/8465021
TBR=mazda@chromium.org
Review URL: http://codereview.chromium.org/8602003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@110643 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r-- | ui/aura/desktop.cc | 61 | ||||
-rw-r--r-- | ui/aura/desktop.h | 5 | ||||
-rw-r--r-- | ui/aura_shell/aura_shell.gyp | 4 | ||||
-rw-r--r-- | ui/aura_shell/desktop_event_filter.cc | 6 | ||||
-rw-r--r-- | ui/aura_shell/desktop_event_filter.h | 6 | ||||
-rw-r--r-- | ui/aura_shell/shell.cc | 2 | ||||
-rw-r--r-- | ui/aura_shell/shell.h | 6 | ||||
-rw-r--r-- | ui/aura_shell/shell_accelerator_controller.cc | 126 | ||||
-rw-r--r-- | ui/aura_shell/shell_accelerator_controller.h | 62 | ||||
-rw-r--r-- | ui/aura_shell/shell_accelerator_filter.cc | 59 | ||||
-rw-r--r-- | ui/aura_shell/shell_accelerator_filter.h | 39 |
11 files changed, 56 insertions, 320 deletions
diff --git a/ui/aura/desktop.cc b/ui/aura/desktop.cc index cb4fbdb..dab97c7 100644 --- a/ui/aura/desktop.cc +++ b/ui/aura/desktop.cc @@ -26,7 +26,10 @@ #include "ui/base/hit_test.h" #include "ui/gfx/compositor/compositor.h" #include "ui/gfx/compositor/layer.h" +#include "ui/gfx/compositor/layer_animation_sequence.h" #include "ui/gfx/compositor/layer_animator.h" +#include "ui/gfx/compositor/screen_rotation.h" +#include "ui/gfx/interpolated_transform.h" using std::string; using std::vector; @@ -92,6 +95,50 @@ void GetEventFiltersToNotify(Window* target, EventFilters* filters) { } } +#if !defined(NDEBUG) +bool MaybeFullScreen(DesktopHost* host, KeyEvent* event) { + if (event->key_code() == ui::VKEY_F11) { + host->ToggleFullScreen(); + return true; + } + return false; +} + +bool MaybeRotate(Desktop* desktop, KeyEvent* event) { + if ((event->flags() & ui::EF_CONTROL_DOWN) && + event->key_code() == ui::VKEY_HOME) { + static int i = 0; + int delta = 0; + switch (i) { + case 0: delta = 90; break; + case 1: delta = 90; break; + case 2: delta = 90; break; + case 3: delta = 90; break; + case 4: delta = -90; break; + case 5: delta = -90; break; + case 6: delta = -90; break; + case 7: delta = -90; break; + case 8: delta = -90; break; + case 9: delta = 180; break; + case 10: delta = 180; break; + case 11: delta = 90; break; + case 12: delta = 180; break; + case 13: delta = 180; break; + } + i = (i + 1) % 14; + desktop->layer()->GetAnimator()->set_preemption_strategy( + ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS); + scoped_ptr<ui::LayerAnimationSequence> screen_rotation( + new ui::LayerAnimationSequence(new ui::ScreenRotation(delta))); + screen_rotation->AddObserver(desktop); + desktop->layer()->GetAnimator()->ScheduleAnimation( + screen_rotation.release()); + return true; + } + return false; +} +#endif + } // namespace Desktop* Desktop::instance_ = NULL; @@ -227,6 +274,14 @@ bool Desktop::DispatchMouseEvent(MouseEvent* event) { } bool Desktop::DispatchKeyEvent(KeyEvent* event) { +#if !defined(NDEBUG) + // TODO(beng): replace this hack with global keyboard event handlers. + if (event->type() == ui::ET_KEY_PRESSED) { + if (MaybeFullScreen(host_.get(), event) || MaybeRotate(this, event)) + return true; + } +#endif + if (focused_window_) { KeyEvent translated_event(*event); return ProcessKeyEvent(focused_window_, &translated_event); @@ -396,12 +451,6 @@ void Desktop::SetTransform(const ui::Transform& transform) { OnHostResized(host_->GetSize()); } -#if !defined(NDEBUG) -void Desktop::ToggleFullScreen() { - host_->ToggleFullScreen(); -} -#endif - void Desktop::HandleMouseMoved(const MouseEvent& event, Window* target) { if (target == mouse_moved_handler_) return; diff --git a/ui/aura/desktop.h b/ui/aura/desktop.h index eab2531..10e7f64 100644 --- a/ui/aura/desktop.h +++ b/ui/aura/desktop.h @@ -136,11 +136,6 @@ class AURA_EXPORT Desktop : public ui::CompositorDelegate, // Overridden from Window: virtual void SetTransform(const ui::Transform& transform) OVERRIDE; -#if !defined(NDEBUG) - // Toggles the host's full screen state. - void ToggleFullScreen(); -#endif - private: // Called whenever the mouse moves, tracks the current |mouse_moved_handler_|, // sending exited and entered events as its value changes. diff --git a/ui/aura_shell/aura_shell.gyp b/ui/aura_shell/aura_shell.gyp index 1d54490..1b8667e 100644 --- a/ui/aura_shell/aura_shell.gyp +++ b/ui/aura_shell/aura_shell.gyp @@ -76,10 +76,6 @@ 'shelf_layout_controller.h', 'shell.cc', 'shell.h', - 'shell_accelerator_controller.cc', - 'shell_accelerator_controller.h', - 'shell_accelerator_filter.cc', - 'shell_accelerator_filter.h', 'shell_delegate.h', 'shell_factory.h', 'shell_window_ids.h', diff --git a/ui/aura_shell/desktop_event_filter.cc b/ui/aura_shell/desktop_event_filter.cc index 67a75ea..dc4b4cf 100644 --- a/ui/aura_shell/desktop_event_filter.cc +++ b/ui/aura_shell/desktop_event_filter.cc @@ -9,7 +9,6 @@ #include "ui/aura/focus_manager.h" #include "ui/aura/window_delegate.h" #include "ui/aura_shell/shell.h" -#include "ui/aura_shell/shell_accelerator_filter.h" #include "ui/aura_shell/stacking_controller.h" #include "ui/base/hit_test.h" @@ -44,16 +43,13 @@ gfx::NativeCursor CursorForWindowComponent(int window_component) { // DesktopEventFilter, public: DesktopEventFilter::DesktopEventFilter() - : EventFilter(aura::Desktop::GetInstance()), - shell_accelerator_filter_(new ShellAcceleratorFilter) { - AddFilter(shell_accelerator_filter_.get()); + : EventFilter(aura::Desktop::GetInstance()) { } DesktopEventFilter::~DesktopEventFilter() { // Additional filters are not owned by DesktopEventFilter and they // should all be removed when running here. |filters_| has // check_empty == true and will DCHECK failure if it is not empty. - RemoveFilter(shell_accelerator_filter_.get()); } void DesktopEventFilter::AddFilter(aura::EventFilter* filter) { diff --git a/ui/aura_shell/desktop_event_filter.h b/ui/aura_shell/desktop_event_filter.h index a9775d8..e4d1c45 100644 --- a/ui/aura_shell/desktop_event_filter.h +++ b/ui/aura_shell/desktop_event_filter.h @@ -7,7 +7,6 @@ #pragma once #include "base/compiler_specific.h" -#include "base/memory/scoped_ptr.h" #include "base/observer_list.h" #include "ui/aura/event_filter.h" #include "ui/aura_shell/aura_shell_export.h" @@ -15,8 +14,6 @@ namespace aura_shell { namespace internal { -class ShellAcceleratorFilter; - // DesktopEventFilter gets all desktop events first and can provide actions to // those events. It implements desktop features such as click to activate a // window and cursor change when moving mouse. @@ -59,9 +56,6 @@ class AURA_SHELL_EXPORT DesktopEventFilter : public aura::EventFilter { // Additional event filters that pre-handles events. ObserverList<aura::EventFilter, true> filters_; - // An event filter that pre-handles global accelerators. - scoped_ptr<ShellAcceleratorFilter> shell_accelerator_filter_; - DISALLOW_COPY_AND_ASSIGN(DesktopEventFilter); }; diff --git a/ui/aura_shell/shell.cc b/ui/aura_shell/shell.cc index 21b04ab..b439de1 100644 --- a/ui/aura_shell/shell.cc +++ b/ui/aura_shell/shell.cc @@ -20,7 +20,6 @@ #include "ui/aura_shell/launcher/launcher.h" #include "ui/aura_shell/modal_container_layout_manager.h" #include "ui/aura_shell/shelf_layout_controller.h" -#include "ui/aura_shell/shell_accelerator_controller.h" #include "ui/aura_shell/shell_delegate.h" #include "ui/aura_shell/shell_factory.h" #include "ui/aura_shell/shell_window_ids.h" @@ -99,7 +98,6 @@ Shell* Shell::instance_ = NULL; Shell::Shell(ShellDelegate* delegate) : ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)), - accelerator_controller_(new ShellAcceleratorController), delegate_(delegate) { aura::Desktop::GetInstance()->SetEventFilter( new internal::DesktopEventFilter); diff --git a/ui/aura_shell/shell.h b/ui/aura_shell/shell.h index 159e96b..fd0d596 100644 --- a/ui/aura_shell/shell.h +++ b/ui/aura_shell/shell.h @@ -27,7 +27,6 @@ class Rect; namespace aura_shell { class Launcher; -class ShellAcceleratorController; class ShellDelegate; namespace internal { @@ -62,9 +61,6 @@ class AURA_SHELL_EXPORT Shell { // Toggles between overview mode and normal mode. void ToggleOverview(); - ShellAcceleratorController* accelerator_controller() { - return accelerator_controller_.get(); - } ShellDelegate* delegate() { return delegate_.get(); } Launcher* launcher() { return launcher_.get(); } @@ -85,8 +81,6 @@ class AURA_SHELL_EXPORT Shell { base::WeakPtrFactory<Shell> method_factory_; - scoped_ptr<ShellAcceleratorController> accelerator_controller_; - scoped_ptr<ShellDelegate> delegate_; scoped_ptr<Launcher> launcher_; diff --git a/ui/aura_shell/shell_accelerator_controller.cc b/ui/aura_shell/shell_accelerator_controller.cc deleted file mode 100644 index 9c67a9d..0000000 --- a/ui/aura_shell/shell_accelerator_controller.cc +++ /dev/null @@ -1,126 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ui/aura_shell/shell_accelerator_controller.h" - -#include "ui/aura/desktop.h" -#include "ui/aura/event.h" -#include "ui/aura_shell/shell.h" -#include "ui/base/accelerator_manager.h" -#include "ui/base/models/accelerator.h" -#include "ui/gfx/compositor/layer_animation_sequence.h" -#include "ui/gfx/compositor/layer_animator.h" -#include "ui/gfx/compositor/screen_rotation.h" - -namespace { - -// Acceleraters handled by ShellAcceleratorController. -struct AcceleratorData { - ui::KeyboardCode keycode; - bool shift; - bool ctrl; - bool alt; -} kAcceleratorData[] = { - { ui::VKEY_F11, false, false, false }, - { ui::VKEY_HOME, false, true, false }, -}; - -// Registers the accelerators with ShellAcceleratorController. -void RegisterAccelerators(aura_shell::ShellAcceleratorController* controller) { - for (size_t i = 0; i < arraysize(kAcceleratorData); ++i) { - controller->Register(ui::Accelerator(kAcceleratorData[i].keycode, - kAcceleratorData[i].shift, - kAcceleratorData[i].ctrl, - kAcceleratorData[i].alt), - controller); - } -} - -#if !defined(NDEBUG) -// Rotates the screen. -void RotateScreen() { - static int i = 0; - int delta = 0; - switch (i) { - case 0: delta = 90; break; - case 1: delta = 90; break; - case 2: delta = 90; break; - case 3: delta = 90; break; - case 4: delta = -90; break; - case 5: delta = -90; break; - case 6: delta = -90; break; - case 7: delta = -90; break; - case 8: delta = -90; break; - case 9: delta = 180; break; - case 10: delta = 180; break; - case 11: delta = 90; break; - case 12: delta = 180; break; - case 13: delta = 180; break; - } - i = (i + 1) % 14; - aura::Desktop::GetInstance()->layer()->GetAnimator()->set_preemption_strategy( - ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS); - scoped_ptr<ui::LayerAnimationSequence> screen_rotation( - new ui::LayerAnimationSequence(new ui::ScreenRotation(delta))); - screen_rotation->AddObserver(aura::Desktop::GetInstance()); - aura::Desktop::GetInstance()->layer()->GetAnimator()->ScheduleAnimation( - screen_rotation.release()); -} -#endif - -} // namespace - -namespace aura_shell { - -//////////////////////////////////////////////////////////////////////////////// -// ShellAcceleratorController, public: - -ShellAcceleratorController::ShellAcceleratorController() - : accelerator_manager_(new ui::AcceleratorManager) { - RegisterAccelerators(this); -} - -ShellAcceleratorController::~ShellAcceleratorController() { -} - -void ShellAcceleratorController::Register( - const ui::Accelerator& accelerator, - ui::AcceleratorTarget* target) { - accelerator_manager_->Register(accelerator, target); -} - -void ShellAcceleratorController::Unregister( - const ui::Accelerator& accelerator, - ui::AcceleratorTarget* target) { - accelerator_manager_->Unregister(accelerator, target); -} - -void ShellAcceleratorController::UnregisterAll( - ui::AcceleratorTarget* target) { - accelerator_manager_->UnregisterAll(target); -} - -bool ShellAcceleratorController::Process(const ui::Accelerator& accelerator) { - return accelerator_manager_->Process(accelerator); -} - -//////////////////////////////////////////////////////////////////////////////// -// ShellAcceleratorController, ui::AcceleratorTarget implementation: - -bool ShellAcceleratorController::AcceleratorPressed( - const ui::Accelerator& accelerator) { -#if !defined(NDEBUG) - if (accelerator.key_code() == ui::VKEY_F11) { - aura::Desktop::GetInstance()->ToggleFullScreen(); - return true; - } else if (accelerator.key_code() == ui::VKEY_HOME && - accelerator.IsCtrlDown()) { - RotateScreen(); - return true; - } -#endif - return false; -} - -} // namespace aura_shell diff --git a/ui/aura_shell/shell_accelerator_controller.h b/ui/aura_shell/shell_accelerator_controller.h deleted file mode 100644 index 14f1f3a..0000000 --- a/ui/aura_shell/shell_accelerator_controller.h +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef UI_AURA_SHELL_SHELL_ACCELERATOR_CONTROLLER_H_ -#define UI_AURA_SHELL_SHELL_ACCELERATOR_CONTROLLER_H_ -#pragma once - -#include "base/basictypes.h" -#include "base/compiler_specific.h" -#include "base/memory/scoped_ptr.h" -#include "ui/aura_shell/aura_shell_export.h" -#include "ui/base/models/accelerator.h" - -namespace ui { -class AcceleratorManager; -} // namespace ui - -namespace aura_shell { - -// ShellAcceleratorController provides functions for registering or -// unregistering global keyboard accelerators, which are handled earlier than -// any windows. It also implements several handlers as an accelerator target. -class AURA_SHELL_EXPORT ShellAcceleratorController - : public ui::AcceleratorTarget { - public: - ShellAcceleratorController(); - virtual ~ShellAcceleratorController(); - - // Register a global keyboard accelerator for the specified target. If - // multiple targets are registered for an accelerator, a target registered - // later has higher priority. - void Register(const ui::Accelerator& accelerator, - ui::AcceleratorTarget* target); - - // Unregister the specified keyboard accelerator for the specified target. - void Unregister(const ui::Accelerator& accelerator, - ui::AcceleratorTarget* target); - - // Unregister all keyboard accelerators for the specified target. - void UnregisterAll(ui::AcceleratorTarget* target); - - // Activate the target associated with the specified accelerator. - // First, AcceleratorPressed handler of the most recently registered target - // is called, and if that handler processes the event (i.e. returns true), - // this method immediately returns. If not, we do the same thing on the next - // target, and so on. - // Returns true if an accelerator was activated. - bool Process(const ui::Accelerator& accelerator); - - // Overridden from ui::AcceleratorTarget: - virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE; - - private: - scoped_ptr<ui::AcceleratorManager> accelerator_manager_; - - DISALLOW_COPY_AND_ASSIGN(ShellAcceleratorController); -}; - -} // namespace aura_shell - -#endif // UI_AURA_SHELL_SHELL_ACCELERATOR_CONTROLLER_H_ diff --git a/ui/aura_shell/shell_accelerator_filter.cc b/ui/aura_shell/shell_accelerator_filter.cc deleted file mode 100644 index 3a9cde5..0000000 --- a/ui/aura_shell/shell_accelerator_filter.cc +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ui/aura_shell/shell_accelerator_filter.h" - -#include "ui/aura/desktop.h" -#include "ui/aura/event.h" -#include "ui/aura_shell/shell.h" -#include "ui/aura_shell/shell_accelerator_controller.h" -#include "ui/base/accelerator_manager.h" -#include "ui/base/models/accelerator.h" - -namespace { -const int kModifierFlagMask = (ui::EF_SHIFT_DOWN | - ui::EF_CONTROL_DOWN | - ui::EF_ALT_DOWN); -} // namespace - -namespace aura_shell { -namespace internal { - -//////////////////////////////////////////////////////////////////////////////// -// ShellAcceleratorFilter, public: - -ShellAcceleratorFilter::ShellAcceleratorFilter() - : EventFilter(aura::Desktop::GetInstance()) { -} - -ShellAcceleratorFilter::~ShellAcceleratorFilter() { -} - -//////////////////////////////////////////////////////////////////////////////// -// ShellAcceleratorFilter, EventFilter implementation: - -bool ShellAcceleratorFilter::PreHandleKeyEvent(aura::Window* target, - aura::KeyEvent* event) { - if (event->type() == ui::ET_KEY_PRESSED && - Shell::GetInstance()->accelerator_controller()->Process( - ui::Accelerator(event->key_code(), - event->flags() & kModifierFlagMask))) { - return true; - } - return false; -} - -bool ShellAcceleratorFilter::PreHandleMouseEvent(aura::Window* target, - aura::MouseEvent* event) { - return false; -} - -ui::TouchStatus ShellAcceleratorFilter::PreHandleTouchEvent( - aura::Window* target, - aura::TouchEvent* event) { - return ui::TOUCH_STATUS_UNKNOWN; -} - -} // namespace internal -} // namespace aura_shell diff --git a/ui/aura_shell/shell_accelerator_filter.h b/ui/aura_shell/shell_accelerator_filter.h deleted file mode 100644 index 3e35ba6..0000000 --- a/ui/aura_shell/shell_accelerator_filter.h +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef UI_AURA_SHELL_SHELL_ACCELERATOR_FILTER_H_ -#define UI_AURA_SHELL_SHELL_ACCELERATOR_FILTER_H_ -#pragma once - -#include "base/basictypes.h" -#include "base/compiler_specific.h" -#include "ui/aura/event_filter.h" -#include "ui/aura_shell/aura_shell_export.h" - -namespace aura_shell { -namespace internal { - -// ShellAcceleratorFilter filters key events for ShellAcceleratorControler -// handling global keyboard accelerators. -class AURA_SHELL_EXPORT ShellAcceleratorFilter : public aura::EventFilter { - public: - ShellAcceleratorFilter(); - virtual ~ShellAcceleratorFilter(); - - // Overridden from aura::EventFilter: - virtual bool PreHandleKeyEvent(aura::Window* target, - aura::KeyEvent* event) OVERRIDE; - virtual bool PreHandleMouseEvent(aura::Window* target, - aura::MouseEvent* event) OVERRIDE; - virtual ui::TouchStatus PreHandleTouchEvent(aura::Window* target, - aura::TouchEvent* event) OVERRIDE; - - private: - DISALLOW_COPY_AND_ASSIGN(ShellAcceleratorFilter); -}; - -} // namespace internal -} // namespace aura_shell - -#endif // UI_AURA_SHELL_SHELL_ACCELERATOR_FILTER_H_ |