| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef MOJO_SERIVCES_WINDOW_MANAGER_FOCUS_CONTROLLER_H_ | |
| 6 #define MOJO_SERIVCES_WINDOW_MANAGER_FOCUS_CONTROLLER_H_ | |
| 7 | |
| 8 #include "base/compiler_specific.h" | |
| 9 #include "base/memory/scoped_ptr.h" | |
| 10 #include "base/observer_list.h" | |
| 11 #include "base/scoped_observer.h" | |
| 12 #include "mojo/services/public/cpp/view_manager/view_observer.h" | |
| 13 #include "ui/events/event_handler.h" | |
| 14 | |
| 15 namespace mojo { | |
| 16 | |
| 17 class FocusControllerObserver; | |
| 18 class FocusRules; | |
| 19 | |
| 20 // FocusController handles focus and activation changes in a mojo window | |
| 21 // manager. Within the window manager, there can only be one focused and one | |
| 22 // active window at a time. When focus or activation changes, notifications are | |
| 23 // sent using the FocusControllerObserver interface. | |
| 24 class FocusController : public ui::EventHandler, | |
| 25 public ViewObserver { | |
| 26 public: | |
| 27 // |rules| cannot be null. | |
| 28 explicit FocusController(scoped_ptr<FocusRules> rules); | |
| 29 virtual ~FocusController(); | |
| 30 | |
| 31 void AddObserver(FocusControllerObserver* observer); | |
| 32 void RemoveObserver(FocusControllerObserver* observer); | |
| 33 | |
| 34 void ActivateView(View* view); | |
| 35 void DeactivateView(View* view); | |
| 36 View* GetActiveView(); | |
| 37 View* GetActivatableView(View* view); | |
| 38 View* GetToplevelView(View* view); | |
| 39 bool CanActivateView(View* view) const; | |
| 40 | |
| 41 void FocusView(View* view); | |
| 42 | |
| 43 void ResetFocusWithinActiveView(View* view); | |
| 44 View* GetFocusedView(); | |
| 45 | |
| 46 // Overridden from ui::EventHandler: | |
| 47 void OnKeyEvent(ui::KeyEvent* event) override; | |
| 48 void OnMouseEvent(ui::MouseEvent* event) override; | |
| 49 void OnScrollEvent(ui::ScrollEvent* event) override; | |
| 50 void OnTouchEvent(ui::TouchEvent* event) override; | |
| 51 void OnGestureEvent(ui::GestureEvent* event) override; | |
| 52 | |
| 53 // Overridden from ViewObserver: | |
| 54 void OnTreeChanging(const TreeChangeParams& params) override; | |
| 55 void OnTreeChanged(const TreeChangeParams& params) override; | |
| 56 void OnViewVisibilityChanged(View* view) override; | |
| 57 void OnViewDestroying(View* view) override; | |
| 58 | |
| 59 private: | |
| 60 // Internal implementation that sets the focused view, fires events etc. | |
| 61 // This function must be called with a valid focusable view. | |
| 62 void SetFocusedView(View* view); | |
| 63 | |
| 64 // Internal implementation that sets the active window, fires events etc. | |
| 65 // This function must be called with a valid |activatable_window|. | |
| 66 // |requested window| refers to the window that was passed in to an external | |
| 67 // request (e.g. FocusWindow or ActivateWindow). It may be null, e.g. if | |
| 68 // SetActiveWindow was not called by an external request. |activatable_window| | |
| 69 // refers to the actual window to be activated, which may be different. | |
| 70 void SetActiveView(View* requested_view, | |
| 71 View* activatable_view); | |
| 72 | |
| 73 // Called when a window's disposition changed such that it and its hierarchy | |
| 74 // are no longer focusable/activatable. |next| is a valid window that is used | |
| 75 // as a starting point for finding a window to focus next based on rules. | |
| 76 void ViewLostFocusFromDispositionChange(View* view, View* next); | |
| 77 | |
| 78 // Called when an attempt is made to focus or activate a window via an input | |
| 79 // event targeted at that window. Rules determine the best focusable window | |
| 80 // for the input window. | |
| 81 void ViewFocusedFromInputEvent(View* view); | |
| 82 | |
| 83 View* active_view_; | |
| 84 View* focused_view_; | |
| 85 | |
| 86 bool updating_focus_; | |
| 87 bool updating_activation_; | |
| 88 | |
| 89 scoped_ptr<FocusRules> rules_; | |
| 90 | |
| 91 ObserverList<FocusControllerObserver> focus_controller_observers_; | |
| 92 | |
| 93 ScopedObserver<View, ViewObserver> observer_manager_; | |
| 94 | |
| 95 DISALLOW_COPY_AND_ASSIGN(FocusController); | |
| 96 }; | |
| 97 | |
| 98 // Sets/Gets the focus controller for a root view. | |
| 99 void SetFocusController(View* view, FocusController* focus_controller); | |
| 100 FocusController* GetFocusController(View* view); | |
| 101 | |
| 102 } // namespace mojo | |
| 103 | |
| 104 #endif // MOJO_SERIVCES_WINDOW_MANAGER_FOCUS_CONTROLLER_H_ | |
| OLD | NEW |