focus_cycler.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Copyright (c) 2012 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. #ifndef ASH_FOCUS_CYCLER_H_
  5. #define ASH_FOCUS_CYCLER_H_
  6. #include <vector>
  7. #include "ash/ash_export.h"
  8. #include "base/callback.h"
  9. namespace views {
  10. class Widget;
  11. } // namespace views
  12. namespace ash {
  13. // This class handles moving focus between a set of widgets and the main browser
  14. // window.
  15. class ASH_EXPORT FocusCycler {
  16. public:
  17. enum Direction { FORWARD, BACKWARD };
  18. FocusCycler();
  19. FocusCycler(const FocusCycler&) = delete;
  20. FocusCycler& operator=(const FocusCycler&) = delete;
  21. ~FocusCycler();
  22. // Returns the widget the FocusCycler is attempting to activate or NULL if
  23. // FocusCycler is not activating any widgets.
  24. const views::Widget* widget_activating() const { return widget_activating_; }
  25. // Add a widget to the focus cycle. The widget needs to have an
  26. // AccessiblePaneView as the content view.
  27. void AddWidget(views::Widget* widget);
  28. // Remove a widget from the focus cycle.
  29. void RemoveWidget(views::Widget* widget);
  30. // Move focus to the next widget.
  31. void RotateFocus(Direction direction);
  32. // Moves focus the specified widget. Returns true if the widget was activated.
  33. bool FocusWidget(views::Widget* widget);
  34. // Find a widget that matches the criteria given by |callback|
  35. // in the cycle list.
  36. views::Widget* FindWidget(
  37. base::RepeatingCallback<bool(views::Widget*)> callback);
  38. private:
  39. std::vector<views::Widget*> widgets_;
  40. // See description above getter.
  41. views::Widget* widget_activating_;
  42. };
  43. } // namespace ash
  44. #endif // ASH_FOCUS_CYCLER_H_