blob: 2938a47a55a3dc289ece373f788d2370e2dd749a [file] [log] [blame]
Avi Drissman3a215d1e2022-09-07 19:43:091// Copyright 2012 The Chromium Authors
James Cookb0bf8e82017-04-09 17:01:442// 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 Drissman4de6dab2023-01-06 23:17:3511#include "base/functional/callback.h"
Arthur Sonzogni834e018f2023-04-22 10:20:0212#include "base/memory/raw_ptr.h"
James Cookb0bf8e82017-04-09 17:01:4413
14namespace views {
15class Widget;
16} // namespace views
17
18namespace ash {
19
20// This class handles moving focus between a set of widgets and the main browser
21// window.
22class ASH_EXPORT FocusCycler {
23 public:
24 enum Direction { FORWARD, BACKWARD };
25
26 FocusCycler();
Peter Boströmec31a042021-09-16 23:37:3427
28 FocusCycler(const FocusCycler&) = delete;
29 FocusCycler& operator=(const FocusCycler&) = delete;
30
James Cookb0bf8e82017-04-09 17:01:4431 ~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 Shihcc77ef1e2023-06-16 16:44:4545 void RotateFocus(Direction direction, bool move_onto_next_widget = false);
James Cookb0bf8e82017-04-09 17:01:4446
47 // Moves focus the specified widget. Returns true if the widget was activated.
48 bool FocusWidget(views::Widget* widget);
49
Mitsuru Oshima7353b9b2018-12-01 02:12:0250 // 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 Cookb0bf8e82017-04-09 17:01:4455 private:
Ali Hijazie63cbaf62023-12-20 19:29:3556 std::vector<raw_ptr<views::Widget, VectorExperimental>> widgets_;
James Cookb0bf8e82017-04-09 17:01:4457
58 // See description above getter.
Bartek Nowierskideb75842023-12-27 02:32:4259 raw_ptr<views::Widget> widget_activating_;
James Cookb0bf8e82017-04-09 17:01:4460};
61
62} // namespace ash
63
64#endif // ASH_FOCUS_CYCLER_H_