Avi Drissman | 3a215d1e | 2022-09-07 19:43:09 | [diff] [blame] | 1 | // Copyright 2012 The Chromium Authors |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 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 ASH_FOCUS_CYCLER_H_ |
| 6 | #define ASH_FOCUS_CYCLER_H_ |
| 7 | |
| 8 | #include <vector> |
| 9 | |
| 10 | #include "ash/ash_export.h" |
Avi Drissman | 4de6dab | 2023-01-06 23:17:35 | [diff] [blame] | 11 | #include "base/functional/callback.h" |
Arthur Sonzogni | 834e018f | 2023-04-22 10:20:02 | [diff] [blame] | 12 | #include "base/memory/raw_ptr.h" |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 13 | |
| 14 | namespace views { |
| 15 | class Widget; |
| 16 | } // namespace views |
| 17 | |
| 18 | namespace ash { |
| 19 | |
| 20 | // This class handles moving focus between a set of widgets and the main browser |
| 21 | // window. |
| 22 | class ASH_EXPORT FocusCycler { |
| 23 | public: |
| 24 | enum Direction { FORWARD, BACKWARD }; |
| 25 | |
| 26 | FocusCycler(); |
Peter Boström | ec31a04 | 2021-09-16 23:37:34 | [diff] [blame] | 27 | |
| 28 | FocusCycler(const FocusCycler&) = delete; |
| 29 | FocusCycler& operator=(const FocusCycler&) = delete; |
| 30 | |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 31 | ~FocusCycler(); |
| 32 | |
| 33 | // Returns the widget the FocusCycler is attempting to activate or NULL if |
| 34 | // FocusCycler is not activating any widgets. |
| 35 | const views::Widget* widget_activating() const { return widget_activating_; } |
| 36 | |
| 37 | // Add a widget to the focus cycle. The widget needs to have an |
| 38 | // AccessiblePaneView as the content view. |
| 39 | void AddWidget(views::Widget* widget); |
| 40 | |
| 41 | // Remove a widget from the focus cycle. |
| 42 | void RemoveWidget(views::Widget* widget); |
| 43 | |
| 44 | // Move focus to the next widget. |
Fred Shih | cc77ef1e | 2023-06-16 16:44:45 | [diff] [blame] | 45 | void RotateFocus(Direction direction, bool move_onto_next_widget = false); |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 46 | |
| 47 | // Moves focus the specified widget. Returns true if the widget was activated. |
| 48 | bool FocusWidget(views::Widget* widget); |
| 49 | |
Mitsuru Oshima | 7353b9b | 2018-12-01 02:12:02 | [diff] [blame] | 50 | // Find a widget that matches the criteria given by |callback| |
| 51 | // in the cycle list. |
| 52 | views::Widget* FindWidget( |
| 53 | base::RepeatingCallback<bool(views::Widget*)> callback); |
| 54 | |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 55 | private: |
Ali Hijazi | e63cbaf6 | 2023-12-20 19:29:35 | [diff] [blame^] | 56 | std::vector<raw_ptr<views::Widget, VectorExperimental>> widgets_; |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 57 | |
| 58 | // See description above getter. |
Arthur Sonzogni | 834e018f | 2023-04-22 10:20:02 | [diff] [blame] | 59 | raw_ptr<views::Widget, ExperimentalAsh> widget_activating_; |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 60 | }; |
| 61 | |
| 62 | } // namespace ash |
| 63 | |
| 64 | #endif // ASH_FOCUS_CYCLER_H_ |