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