1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
|
// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_APP_LIST_VIEWS_SEARCH_RESULT_BASE_VIEW_H_
#define ASH_APP_LIST_VIEWS_SEARCH_RESULT_BASE_VIEW_H_
#include "ash/app_list/model/search/search_result_observer.h"
#include "ash/ash_export.h"
#include "base/memory/raw_ptr.h"
#include "base/time/time.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "ui/base/metadata/metadata_header_macros.h"
#include "ui/views/controls/button/button.h"
namespace ash {
class SearchResult;
class SearchResultActionsView;
// Base class for views that observe and display a search result
class ASH_EXPORT SearchResultBaseView : public views::Button,
public SearchResultObserver {
public:
METADATA_HEADER(SearchResultBaseView);
SearchResultBaseView();
SearchResultBaseView(const SearchResultBaseView&) = delete;
SearchResultBaseView& operator=(const SearchResultBaseView&) = delete;
// Set whether the result is selected. It updates the background highlight,
// and selects the result action associated with the result if
// SearchBoxSelection feature is enabled.
//
// |reverse_tab_order| - Indicates whether the selection was set as part of
// reverse tab traversal. Should be set when selection was changed while
// handling TAB keyboard key. Ignored if |selected| is false.
void SetSelected(bool selected, absl::optional<bool> reverse_tab_order);
// Selects the initial action that should be associated with the result view,
// notifying a11y hierarchy of the selection. If the result view does not
// support result actions (i.e. does not have actions_view_), this will just
// announce the current result view selection.
// |reverse_tab_order| - whether the action was selected in reverse tab order.
virtual void SelectInitialResultAction(bool reverse_tab_order);
// Selects the next result action for the view, if the result supports
// non-default actions (see actions_view_).
// |reverse_tab_order| - whether the action was selected while handling TAB
// key in reverse tab order.
//
// Returns whether the selected result action was changed.
virtual bool SelectNextResultAction(bool reverse_tab_order);
// Returns the view that is currently selected - for example, if the result
// supports action views and an action view is currently selected, this
// should return the action view, otherwise it should return `this`.
virtual views::View* GetSelectedView();
SearchResult* result() const { return result_; }
void SetResult(SearchResult* result);
// Invoked after |result_| is updated.
virtual void OnResultChanged() {}
// Overridden from SearchResultObserver:
void OnResultDestroying() override;
// Computes the button's spoken feedback name.
std::u16string ComputeAccessibleName() const;
// Clears the result without calling |OnResultChanged| or |OnResultChanging|
void ClearResult();
bool selected() const { return selected_; }
int index_in_container() const { return index_in_container_.value(); }
void set_index_in_container(size_t index) { index_in_container_ = index; }
void set_result_display_start_time(base::TimeTicks start_time) {
result_display_start_time_ = start_time;
}
base::TimeTicks result_display_start_time() const {
return result_display_start_time_;
}
void set_is_default_result(bool is_default) {
is_default_result_ = is_default;
}
bool is_default_result() const { return is_default_result_; }
// views::Button:
bool SkipDefaultKeyEventProcessing(const ui::KeyEvent& event) override;
// views::View:
void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
SearchResultActionsView* actions_view() { return actions_view_; }
protected:
~SearchResultBaseView() override;
void UpdateAccessibleName();
void set_actions_view(SearchResultActionsView* actions_view) {
actions_view_ = actions_view;
}
private:
// If non-default result action was selected, clears the actions_view_'s
// selection state.
void ClearSelectedResultAction();
// Whether the result is currently selected.
bool selected_ = false;
// Expected to be set by result view implementations that supports
// extra result actions. It points to the view containing result actions
// buttons. Owned by the views hierarchy.
raw_ptr<SearchResultActionsView, DanglingUntriaged | ExperimentalAsh>
actions_view_ = nullptr;
// The index of this view within a |SearchResultContainerView| that holds it.
absl::optional<int> index_in_container_;
// The starting time when |result_| is being displayed.
base::TimeTicks result_display_start_time_;
// True if |result_| is selected as the default result which can be
// activated by user by pressing ENTER key.
bool is_default_result_ = false;
raw_ptr<SearchResult, ExperimentalAsh> result_ =
nullptr; // Owned by SearchModel::SearchResults.
};
} // namespace ash
#endif // ASH_APP_LIST_VIEWS_SEARCH_RESULT_BASE_VIEW_H_
|