Added llvm into exceptions as we can't add README.chromium into 3rd party repository
[chromium-blink-merge.git] / ui / app_list / search_result.h
blobaa3a6b11c9d387877110094a2ce595a3271c84e8
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.
32 enum DisplayType {
33 DISPLAY_LIST,
34 DISPLAY_TILE,
35 DISPLAY_RECOMMENDATION,
36 DISPLAY_NONE,
39 // A tagged range in search result text.
40 struct APP_LIST_EXPORT Tag {
41 // Similar to ACMatchClassification::Style, the style values are not
42 // mutually exclusive.
43 enum Style {
44 NONE = 0,
45 URL = 1 << 0,
46 MATCH = 1 << 1,
47 DIM = 1 << 2,
50 Tag(int styles, size_t start, size_t end)
51 : styles(styles),
52 range(start, end) {
55 int styles;
56 gfx::Range range;
58 typedef std::vector<Tag> Tags;
60 // Data representing an action that can be performed on this search result.
61 // An action could be represented as an icon set or as a blue button with
62 // a label. Icon set is chosen if label text is empty. Otherwise, a blue
63 // button with the label text will be used.
64 struct APP_LIST_EXPORT Action {
65 Action(const gfx::ImageSkia& base_image,
66 const gfx::ImageSkia& hover_image,
67 const gfx::ImageSkia& pressed_image,
68 const base::string16& tooltip_text);
69 Action(const base::string16& label_text,
70 const base::string16& tooltip_text);
71 ~Action();
73 gfx::ImageSkia base_image;
74 gfx::ImageSkia hover_image;
75 gfx::ImageSkia pressed_image;
77 base::string16 tooltip_text;
78 base::string16 label_text;
80 typedef std::vector<Action> Actions;
82 SearchResult();
83 virtual ~SearchResult();
85 const gfx::ImageSkia& icon() const { return icon_; }
86 void SetIcon(const gfx::ImageSkia& icon);
88 const base::string16& title() const { return title_; }
89 void set_title(const base::string16& title) { title_ = title;}
91 const Tags& title_tags() const { return title_tags_; }
92 void set_title_tags(const Tags& tags) { title_tags_ = tags; }
94 const base::string16& details() const { return details_; }
95 void set_details(const base::string16& details) { details_ = details; }
97 const Tags& details_tags() const { return details_tags_; }
98 void set_details_tags(const Tags& tags) { details_tags_ = tags; }
100 const std::string& id() const { return id_; }
102 double relevance() const { return relevance_; }
103 void set_relevance(double relevance) { relevance_ = relevance; }
105 DisplayType display_type() const { return display_type_; }
106 void set_display_type(DisplayType display_type) {
107 display_type_ = display_type;
110 const Actions& actions() const {
111 return actions_;
113 void SetActions(const Actions& sets);
115 // Whether the result can be automatically selected by a voice query.
116 // (Non-voice results can still appear in the results list to be manually
117 // selected.)
118 bool voice_result() const { return voice_result_; }
120 bool is_installing() const { return is_installing_; }
121 void SetIsInstalling(bool is_installing);
123 int percent_downloaded() const { return percent_downloaded_; }
124 void SetPercentDownloaded(int percent_downloaded);
126 // Returns the dimension at which this result's icon should be displayed.
127 int GetPreferredIconDimension() const;
129 void NotifyItemInstalled();
131 void AddObserver(SearchResultObserver* observer);
132 void RemoveObserver(SearchResultObserver* observer);
134 // TODO(mukai): Remove this method and really simplify the ownership of
135 // SearchResult. Ideally, SearchResult will be copyable.
136 virtual scoped_ptr<SearchResult> Duplicate() const = 0;
138 // Opens the result.
139 virtual void Open(int event_flags);
141 // Invokes a custom action on the result. It does nothing by default.
142 virtual void InvokeAction(int action_index, int event_flags);
144 // Returns the context menu model for this item, or NULL if there is currently
145 // no menu for the item (e.g. during install).
146 // Note the returned menu model is owned by this item.
147 virtual ui::MenuModel* GetContextMenuModel();
149 protected:
150 void set_id(const std::string& id) { id_ = id; }
151 void set_voice_result(bool voice_result) { voice_result_ = voice_result; }
153 private:
154 gfx::ImageSkia icon_;
156 base::string16 title_;
157 Tags title_tags_;
159 base::string16 details_;
160 Tags details_tags_;
162 std::string id_;
163 double relevance_;
164 DisplayType display_type_;
166 Actions actions_;
167 bool voice_result_;
169 bool is_installing_;
170 int percent_downloaded_;
172 ObserverList<SearchResultObserver> observers_;
174 DISALLOW_COPY_AND_ASSIGN(SearchResult);
177 } // namespace app_list
179 #endif // UI_APP_LIST_SEARCH_RESULT_H_