search_result_actions_view.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // Copyright 2013 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_APP_LIST_VIEWS_SEARCH_RESULT_ACTIONS_VIEW_H_
  5. #define ASH_APP_LIST_VIEWS_SEARCH_RESULT_ACTIONS_VIEW_H_
  6. #include <list>
  7. #include "ash/app_list/model/search/search_result.h"
  8. #include "ash/ash_export.h"
  9. #include "ui/views/view.h"
  10. namespace ash {
  11. class SearchResultActionsViewDelegate;
  12. class SearchResultView;
  13. // SearchResultActionsView displays a SearchResult::Actions in a button
  14. // strip. Each action is presented as a button and horizontally laid out.
  15. class ASH_EXPORT SearchResultActionsView : public views::View {
  16. public:
  17. explicit SearchResultActionsView(SearchResultActionsViewDelegate* delegate);
  18. SearchResultActionsView(const SearchResultActionsView&) = delete;
  19. SearchResultActionsView& operator=(const SearchResultActionsView&) = delete;
  20. ~SearchResultActionsView() override;
  21. void SetActions(const SearchResult::Actions& actions);
  22. bool IsValidActionIndex(size_t action_index) const;
  23. bool IsSearchResultHoveredOrSelected() const;
  24. // Hides search result actions until they are next updated.
  25. void HideActions();
  26. // Updates the button UI upon the SearchResultView's UI state change.
  27. void UpdateButtonsOnStateChanged();
  28. // views::View:
  29. const char* GetClassName() const override;
  30. // Selects the result action expected to be initially selected when the parent
  31. // result view gets selected.
  32. // |reverse_tab_order| - Whether the parent result view was selected in
  33. // reverse tab order.
  34. // Returns whether an action was selected (returns false if selected_action_
  35. // is not set).
  36. bool SelectInitialAction(bool reverse_tab_order);
  37. // Select the next result action that should be selected during tab traversal.
  38. // It will not change selection if the next selection would be invalid.
  39. // Note that "no selected action" is treated as a valid (zero) state.
  40. //
  41. // |reverse_tab_order| - Whether the selection should be changed assuming
  42. // reverse tab order.
  43. // Returns whether the selection was changed (which includes selected action
  44. // getting cleared).
  45. bool SelectNextAction(bool reverse_tab_order);
  46. // Returns the selected action button.
  47. views::View* GetSelectedView();
  48. // Clears selected action state.
  49. void ClearSelectedAction();
  50. // Returns the selected action index, or -1 if an action is not selected.
  51. int GetSelectedAction() const;
  52. // Whether an action is currently selected.
  53. bool HasSelectedAction() const;
  54. private:
  55. void CreateImageButton(const SearchResult::Action& action, int action_index);
  56. // Returns the number of available actions.
  57. size_t GetActionCount() const;
  58. // views::View overrides:
  59. void ChildVisibilityChanged(views::View* child) override;
  60. // If an action is currently selected, the selected action index.
  61. absl::optional<int> selected_action_;
  62. SearchResultActionsViewDelegate* const delegate_; // Not owned.
  63. std::list<base::CallbackListSubscription> subscriptions_;
  64. };
  65. } // namespace ash
  66. #endif // ASH_APP_LIST_VIEWS_SEARCH_RESULT_ACTIONS_VIEW_H_