| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef UI_VIEWS_COREWM_FOCUS_CONTROLLER_H_ | 5 #ifndef UI_VIEWS_COREWM_FOCUS_CONTROLLER_H_ |
| 6 #define UI_VIEWS_COREWM_FOCUS_CONTROLLER_H_ | 6 #define UI_VIEWS_COREWM_FOCUS_CONTROLLER_H_ |
| 7 | 7 |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "ui/aura/client/activation_client.h" | 9 #include "ui/aura/client/activation_client.h" |
| 10 #include "ui/aura/client/focus_client.h" |
| 10 #include "ui/aura/env_observer.h" | 11 #include "ui/aura/env_observer.h" |
| 11 #include "ui/aura/window_observer.h" | 12 #include "ui/aura/window_observer.h" |
| 12 #include "ui/base/events/event_dispatcher.h" | 13 #include "ui/base/events/event_dispatcher.h" |
| 13 #include "ui/views/views_export.h" | 14 #include "ui/views/views_export.h" |
| 14 | 15 |
| 15 namespace views { | 16 namespace views { |
| 16 namespace corewm { | 17 namespace corewm { |
| 17 | 18 |
| 18 class FocusRules; | 19 class FocusRules; |
| 19 | 20 |
| 20 // FocusController handles focus and activation changes for an environment | 21 // FocusController handles focus and activation changes for an environment |
| 21 // encompassing one or more RootWindows. Within an environment there can be | 22 // encompassing one or more RootWindows. Within an environment there can be |
| 22 // only one focused and one active window at a time. When focus or activation | 23 // only one focused and one active window at a time. When focus or activation |
| 23 // changes a FocusChangeEvent is dispatched. | 24 // changes a FocusChangeEvent is dispatched. |
| 24 // Changes to focus and activation can be from three sources: | 25 // Changes to focus and activation can be from three sources: |
| 25 // . the Aura Client API (implemented here in aura::client::ActivationClient). | 26 // . the Aura Client API (implemented here in aura::client::ActivationClient). |
| 26 // (The FocusController must be set as the ActivationClient implementation | 27 // (The FocusController must be set as the ActivationClient implementation |
| 27 // for all RootWindows). | 28 // for all RootWindows). |
| 28 // . input events (implemented here in ui::EventHandler). | 29 // . input events (implemented here in ui::EventHandler). |
| 29 // (The FocusController must be registered as a pre-target handler for | 30 // (The FocusController must be registered as a pre-target handler for |
| 30 // the applicable environment owner, either a RootWindow or another type). | 31 // the applicable environment owner, either a RootWindow or another type). |
| 31 // . Window disposition changes (implemented here in aura::WindowObserver). | 32 // . Window disposition changes (implemented here in aura::WindowObserver). |
| 32 // (The FocusController registers itself as an observer of the active and | 33 // (The FocusController registers itself as an observer of the active and |
| 33 // focused windows). | 34 // focused windows). |
| 34 class VIEWS_EXPORT FocusController : public aura::client::ActivationClient, | 35 class VIEWS_EXPORT FocusController : public aura::client::ActivationClient, |
| 36 public aura::client::FocusClient, |
| 35 public ui::EventHandler, | 37 public ui::EventHandler, |
| 36 public aura::WindowObserver, | 38 public aura::WindowObserver, |
| 37 public aura::EnvObserver, | 39 public aura::EnvObserver, |
| 38 public ui::EventDispatcher { | 40 public ui::EventDispatcher { |
| 39 public: | 41 public: |
| 40 // |rules| cannot be NULL. | 42 // |rules| cannot be NULL. |
| 41 explicit FocusController(FocusRules* rules); | 43 explicit FocusController(FocusRules* rules); |
| 42 virtual ~FocusController(); | 44 virtual ~FocusController(); |
| 43 | 45 |
| 44 // TODO(beng): FocusClient | |
| 45 // Sets the focused window, resulting in focus change events being sent. | |
| 46 // Must only be called with valid focusable windows per FocusRules. | |
| 47 void FocusWindow(aura::Window* window); | |
| 48 aura::Window* focused_window() { return focused_window_; } | |
| 49 | |
| 50 private: | 46 private: |
| 51 // Overridden from aura::ActivationClient: | 47 // Overridden from aura::client::ActivationClient: |
| 52 virtual void AddObserver( | 48 virtual void AddObserver( |
| 53 aura::client::ActivationChangeObserver* observer) OVERRIDE; | 49 aura::client::ActivationChangeObserver* observer) OVERRIDE; |
| 54 virtual void RemoveObserver( | 50 virtual void RemoveObserver( |
| 55 aura::client::ActivationChangeObserver* observer) OVERRIDE; | 51 aura::client::ActivationChangeObserver* observer) OVERRIDE; |
| 56 virtual void ActivateWindow(aura::Window* window) OVERRIDE; | 52 virtual void ActivateWindow(aura::Window* window) OVERRIDE; |
| 57 virtual void DeactivateWindow(aura::Window* window) OVERRIDE; | 53 virtual void DeactivateWindow(aura::Window* window) OVERRIDE; |
| 58 virtual aura::Window* GetActiveWindow() OVERRIDE; | 54 virtual aura::Window* GetActiveWindow() OVERRIDE; |
| 59 virtual aura::Window* GetActivatableWindow(aura::Window* window) OVERRIDE; | 55 virtual aura::Window* GetActivatableWindow(aura::Window* window) OVERRIDE; |
| 60 virtual bool OnWillFocusWindow(aura::Window* window, | 56 virtual bool OnWillFocusWindow(aura::Window* window, |
| 61 const ui::Event* event) OVERRIDE; | 57 const ui::Event* event) OVERRIDE; |
| 62 virtual bool CanActivateWindow(aura::Window* window) const OVERRIDE; | 58 virtual bool CanActivateWindow(aura::Window* window) const OVERRIDE; |
| 63 | 59 |
| 60 // Overridden from aura::client::FocusClient: |
| 61 virtual void AddObserver( |
| 62 aura::client::FocusChangeObserver* observer) OVERRIDE; |
| 63 virtual void RemoveObserver( |
| 64 aura::client::FocusChangeObserver* observer) OVERRIDE; |
| 65 virtual void FocusWindow(aura::Window* window, |
| 66 const ui::Event* event) OVERRIDE; |
| 67 virtual aura::Window* GetFocusedWindow() OVERRIDE; |
| 68 |
| 64 // Overridden from ui::EventHandler: | 69 // Overridden from ui::EventHandler: |
| 65 virtual ui::EventResult OnKeyEvent(ui::KeyEvent* event) OVERRIDE; | 70 virtual ui::EventResult OnKeyEvent(ui::KeyEvent* event) OVERRIDE; |
| 66 virtual ui::EventResult OnMouseEvent(ui::MouseEvent* event) OVERRIDE; | 71 virtual ui::EventResult OnMouseEvent(ui::MouseEvent* event) OVERRIDE; |
| 67 virtual ui::EventResult OnScrollEvent(ui::ScrollEvent* event) OVERRIDE; | 72 virtual ui::EventResult OnScrollEvent(ui::ScrollEvent* event) OVERRIDE; |
| 68 virtual ui::EventResult OnTouchEvent(ui::TouchEvent* event) OVERRIDE; | 73 virtual ui::EventResult OnTouchEvent(ui::TouchEvent* event) OVERRIDE; |
| 69 virtual ui::EventResult OnGestureEvent(ui::GestureEvent* event) OVERRIDE; | 74 virtual ui::EventResult OnGestureEvent(ui::GestureEvent* event) OVERRIDE; |
| 70 | 75 |
| 71 // Overridden from aura::WindowObserver: | 76 // Overridden from aura::WindowObserver: |
| 72 virtual void OnWindowVisibilityChanging(aura::Window* window, | 77 virtual void OnWindowVisibilityChanging(aura::Window* window, |
| 73 bool visible) OVERRIDE; | 78 bool visible) OVERRIDE; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 104 | 109 |
| 105 scoped_ptr<FocusRules> rules_; | 110 scoped_ptr<FocusRules> rules_; |
| 106 | 111 |
| 107 DISALLOW_COPY_AND_ASSIGN(FocusController); | 112 DISALLOW_COPY_AND_ASSIGN(FocusController); |
| 108 }; | 113 }; |
| 109 | 114 |
| 110 } // namespace corewm | 115 } // namespace corewm |
| 111 } // namespace views | 116 } // namespace views |
| 112 | 117 |
| 113 #endif // UI_VIEWS_COREWM_FOCUS_CONTROLLER_H_ | 118 #endif // UI_VIEWS_COREWM_FOCUS_CONTROLLER_H_ |
| OLD | NEW |