| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 COMPONENTS_MUS_WS_FOCUS_CONTROLLER_H_ | 5 #ifndef COMPONENTS_MUS_WS_FOCUS_CONTROLLER_H_ |
| 6 #define COMPONENTS_MUS_WS_FOCUS_CONTROLLER_H_ | 6 #define COMPONENTS_MUS_WS_FOCUS_CONTROLLER_H_ |
| 7 | 7 |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/observer_list.h" |
| 9 #include "components/mus/ws/server_window_drawn_tracker_observer.h" | 10 #include "components/mus/ws/server_window_drawn_tracker_observer.h" |
| 10 | 11 |
| 11 namespace mus { | 12 namespace mus { |
| 12 | 13 |
| 13 namespace ws { | 14 namespace ws { |
| 14 | 15 |
| 15 class FocusControllerDelegate; | 16 class FocusControllerObserver; |
| 16 class ServerWindow; | 17 class ServerWindow; |
| 17 class ServerWindowDrawnTracker; | 18 class ServerWindowDrawnTracker; |
| 18 | 19 |
| 19 // Tracks a focused window. Focus is moved to another window when the drawn | 20 // Describes the source of the change. |
| 20 // state of the focused window changes and the delegate is notified. | 21 enum class FocusControllerChangeSource { |
| 22 EXPLICIT, |
| 23 DRAWN_STATE_CHANGED, |
| 24 }; |
| 25 |
| 26 // Tracks the focused window. Focus is moved to another window when the drawn |
| 27 // state of the focused window changes. |
| 21 class FocusController : public ServerWindowDrawnTrackerObserver { | 28 class FocusController : public ServerWindowDrawnTrackerObserver { |
| 22 public: | 29 public: |
| 23 explicit FocusController(FocusControllerDelegate* delegate); | 30 FocusController(); |
| 24 ~FocusController() override; | 31 ~FocusController() override; |
| 25 | 32 |
| 26 // Sets the focused window. Does nothing if |window| is currently focused. | 33 // Sets the focused window. Does nothing if |window| is currently focused. |
| 27 // This does not notify the delegate. | 34 // This does not notify the delegate. |
| 28 void SetFocusedWindow(ServerWindow* window); | 35 void SetFocusedWindow(ServerWindow* window); |
| 29 ServerWindow* GetFocusedWindow(); | 36 ServerWindow* GetFocusedWindow(); |
| 30 | 37 |
| 31 // Moves activation to the next activatable window. | 38 // Moves activation to the next activatable window. |
| 32 void CycleActivationForward(); | 39 void CycleActivationForward(); |
| 33 | 40 |
| 41 void AddObserver(FocusControllerObserver* observer); |
| 42 void RemoveObserver(FocusControllerObserver* observer); |
| 43 |
| 34 private: | 44 private: |
| 35 // Describes the source of the change. | |
| 36 enum ChangeSource { | |
| 37 CHANGE_SOURCE_EXPLICIT, | |
| 38 CHANGE_SOURCE_DRAWN_STATE_CHANGED, | |
| 39 }; | |
| 40 | |
| 41 // Returns whether |window| can be focused or activated. | 45 // Returns whether |window| can be focused or activated. |
| 42 bool CanBeFocused(ServerWindow* window) const; | 46 bool CanBeFocused(ServerWindow* window) const; |
| 43 bool CanBeActivated(ServerWindow* window) const; | 47 bool CanBeActivated(ServerWindow* window) const; |
| 44 | 48 |
| 45 // Implementation of SetFocusedWindow(). | 49 // Implementation of SetFocusedWindow(). |
| 46 void SetFocusedWindowImpl(ServerWindow* window, ChangeSource change_source); | 50 void SetFocusedWindowImpl(FocusControllerChangeSource change_source, |
| 51 ServerWindow* window); |
| 47 | 52 |
| 48 // ServerWindowDrawnTrackerObserver: | 53 // ServerWindowDrawnTrackerObserver: |
| 49 void OnDrawnStateChanged(ServerWindow* ancestor, | 54 void OnDrawnStateChanged(ServerWindow* ancestor, |
| 50 ServerWindow* window, | 55 ServerWindow* window, |
| 51 bool is_drawn) override; | 56 bool is_drawn) override; |
| 52 | 57 |
| 53 FocusControllerDelegate* delegate_; | 58 base::ObserverList<FocusControllerObserver> observers_; |
| 54 scoped_ptr<ServerWindowDrawnTracker> drawn_tracker_; | 59 scoped_ptr<ServerWindowDrawnTracker> drawn_tracker_; |
| 55 | 60 |
| 56 DISALLOW_COPY_AND_ASSIGN(FocusController); | 61 DISALLOW_COPY_AND_ASSIGN(FocusController); |
| 57 }; | 62 }; |
| 58 | 63 |
| 59 } // namespace ws | 64 } // namespace ws |
| 60 | 65 |
| 61 } // namespace mus | 66 } // namespace mus |
| 62 | 67 |
| 63 #endif // COMPONENTS_MUS_WS_FOCUS_CONTROLLER_H_ | 68 #endif // COMPONENTS_MUS_WS_FOCUS_CONTROLLER_H_ |
| OLD | NEW |