Roll src/third_party/WebKit 5778f6a:4127337 (svn 193788:193794)
[chromium-blink-merge.git] / ui / app_list / search_result.h
blob4d5300ca486b89bd21861034a07ab16135c3e4df
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.
5 #ifndef UI_APP_LIST_SEARCH_RESULT_H_
6 #define UI_APP_LIST_SEARCH_RESULT_H_
8 #include <string>
9 #include <vector>
11 #include "base/basictypes.h"
12 #include "base/observer_list.h"
13 #include "base/strings/string16.h"
14 #include "ui/app_list/app_list_export.h"
15 #include "ui/gfx/image/image_skia.h"
16 #include "ui/gfx/range/range.h"
18 namespace ui {
19 class MenuModel;
22 namespace app_list {
24 class SearchResultObserver;
26 // SearchResult consists of an icon, title text and details text. Title and
27 // details text can have tagged ranges that are displayed differently from
28 // default style.
29 class APP_LIST_EXPORT SearchResult {
30 public:
31 // How the result should be displayed. Do not change the order of these as
32 // they are used for metrics.
33 enum DisplayType {
34 DISPLAY_NONE = 0,
35 DISPLAY_LIST,
36 DISPLAY_TILE,
37 DISPLAY_RECOMMENDATION,
38 // Add new values here.
40 DISPLAY_TYPE_LAST,
43 // A tagged range in search result text.
44 struct APP_LIST_EXPORT Tag {
45 // Similar to ACMatchClassification::Style, the style values are not
46 // mutually exclusive.
47 enum Style {
48 NONE = 0,
49 URL = 1 << 0,
50 MATCH = 1 << 1,
51 DIM = 1 << 2,
54 Tag(int styles, size_t start, size_t end)
55 : styles(styles),
56 range(start, end) {
59 int styles;
60 gfx::Range range;
62 typedef std::vector<Tag> Tags;
64 // Data representing an action that can be performed on this search result.
65 // An action could be represented as an icon set or as a blue button with
66 // a label. Icon set is chosen if label text is empty. Otherwise, a blue
67 // button with the label text will be used.
68 struct APP_LIST_EXPORT Action {
69 Action(const gfx::ImageSkia& base_image,
70 const gfx::ImageSkia& hover_image,
71 const gfx::ImageSkia& pressed_image,
72 const base::string16& tooltip_text);
73 Action(const base::string16& label_text,
74 const base::string16& tooltip_text);
75 ~Action();
77 gfx::ImageSkia base_image;
78 gfx::ImageSkia hover_image;
79 gfx::ImageSkia pressed_image;
81 base::string16 tooltip_text;
82 base::string16 label_text;
84 typedef std::vector<Action> Actions;
86 SearchResult();
87 virtual ~SearchResult();
89 const gfx::ImageSkia& icon() const { return icon_; }
90 void SetIcon(const gfx::ImageSkia& icon);
92 const base::string16& title() const { return title_; }
93 void set_title(const base::string16& title) { title_ = title;}
95 const Tags& title_tags() const { return title_tags_; }
96 void set_title_tags(const Tags& tags) { title_tags_ = tags; }
98 const base::string16& details() const { return details_; }
99 void set_details(const base::string16& details) { details_ = details; }
101 const Tags& details_tags() const { return details_tags_; }
102 void set_details_tags(const Tags& tags) { details_tags_ = tags; }
104 const std::string& id() const { return id_; }
106 double relevance() const { return relevance_; }
107 void set_relevance(double relevance) { relevance_ = relevance; }
109 DisplayType display_type() const { return display_type_; }
110 void set_display_type(DisplayType display_type) {
111 display_type_ = display_type;
114 const Actions& actions() const {
115 return actions_;
117 void SetActions(const Actions& sets);
119 // Whether the result can be automatically selected by a voice query.
120 // (Non-voice results can still appear in the results list to be manually
121 // selected.)
122 bool voice_result() const { return voice_result_; }
124 bool is_installing() const { return is_installing_; }
125 void SetIsInstalling(bool is_installing);
127 int percent_downloaded() const { return percent_downloaded_; }
128 void SetPercentDownloaded(int percent_downloaded);
130 // Returns the dimension at which this result's icon should be displayed.
131 int GetPreferredIconDimension() const;
133 void NotifyItemInstalled();
135 void AddObserver(SearchResultObserver* observer);
136 void RemoveObserver(SearchResultObserver* observer);
138 // TODO(mukai): Remove this method and really simplify the ownership of
139 // SearchResult. Ideally, SearchResult will be copyable.
140 virtual scoped_ptr<SearchResult> Duplicate() const = 0;
142 // Opens the result.
143 virtual void Open(int event_flags);
145 // Invokes a custom action on the result. It does nothing by default.
146 virtual void InvokeAction(int action_index, int event_flags);
148 // Returns the context menu model for this item, or NULL if there is currently
149 // no menu for the item (e.g. during install).
150 // Note the returned menu model is owned by this item.
151 virtual ui::MenuModel* GetContextMenuModel();
153 protected:
154 void set_id(const std::string& id) { id_ = id; }
155 void set_voice_result(bool voice_result) { voice_result_ = voice_result; }
157 private:
158 gfx::ImageSkia icon_;
160 base::string16 title_;
161 Tags title_tags_;
163 base::string16 details_;
164 Tags details_tags_;
166 std::string id_;
167 double relevance_;
168 DisplayType display_type_;
170 Actions actions_;
171 bool voice_result_;
173 bool is_installing_;
174 int percent_downloaded_;
176 ObserverList<SearchResultObserver> observers_;
178 DISALLOW_COPY_AND_ASSIGN(SearchResult);
181 } // namespace app_list
183 #endif // UI_APP_LIST_SEARCH_RESULT_H_