Blink roll 171798:171837
[chromium-blink-merge.git] / ui / app_list / search_result.h
blob6064ffb797cf23297c835a306787440e52086ded
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 <vector>
10 #include "base/basictypes.h"
11 #include "base/observer_list.h"
12 #include "base/strings/string16.h"
13 #include "ui/app_list/app_list_export.h"
14 #include "ui/gfx/image/image_skia.h"
15 #include "ui/gfx/range/range.h"
17 namespace ui {
18 class MenuModel;
21 namespace app_list {
23 class SearchResultObserver;
25 // SearchResult consists of an icon, title text and details text. Title and
26 // details text can have tagged ranges that are displayed differently from
27 // default style.
28 class APP_LIST_EXPORT SearchResult {
29 public:
30 // A tagged range in search result text.
31 struct APP_LIST_EXPORT Tag {
32 // Similar to ACMatchClassification::Style, the style values are not
33 // mutually exclusive.
34 enum Style {
35 NONE = 0,
36 URL = 1 << 0,
37 MATCH = 1 << 1,
38 DIM = 1 << 2,
41 Tag(int styles, size_t start, size_t end)
42 : styles(styles),
43 range(start, end) {
46 int styles;
47 gfx::Range range;
49 typedef std::vector<Tag> Tags;
51 // Data representing an action that can be performed on this search result.
52 // An action could be represented as an icon set or as a blue button with
53 // a label. Icon set is chosen if label text is empty. Otherwise, a blue
54 // button with the label text will be used.
55 struct APP_LIST_EXPORT Action {
56 Action(const gfx::ImageSkia& base_image,
57 const gfx::ImageSkia& hover_image,
58 const gfx::ImageSkia& pressed_image,
59 const base::string16& tooltip_text);
60 Action(const base::string16& label_text,
61 const base::string16& tooltip_text);
62 ~Action();
64 gfx::ImageSkia base_image;
65 gfx::ImageSkia hover_image;
66 gfx::ImageSkia pressed_image;
68 base::string16 tooltip_text;
69 base::string16 label_text;
71 typedef std::vector<Action> Actions;
73 SearchResult();
74 virtual ~SearchResult();
76 const gfx::ImageSkia& icon() const { return icon_; }
77 void SetIcon(const gfx::ImageSkia& icon);
79 const base::string16& title() const { return title_; }
80 void set_title(const base::string16& title) { title_ = title;}
82 const Tags& title_tags() const { return title_tags_; }
83 void set_title_tags(const Tags& tags) { title_tags_ = tags; }
85 const base::string16& details() const { return details_; }
86 void set_details(const base::string16& details) { details_ = details; }
88 const Tags& details_tags() const { return details_tags_; }
89 void set_details_tags(const Tags& tags) { details_tags_ = tags; }
91 const Actions& actions() const {
92 return actions_;
94 void SetActions(const Actions& sets);
96 bool is_installing() const { return is_installing_; }
97 void SetIsInstalling(bool is_installing);
99 int percent_downloaded() const { return percent_downloaded_; }
100 void SetPercentDownloaded(int percent_downloaded);
102 void NotifyItemInstalled();
103 void NotifyItemUninstalled();
105 void AddObserver(SearchResultObserver* observer);
106 void RemoveObserver(SearchResultObserver* observer);
108 // Returns the context menu model for this item, or NULL if there is currently
109 // no menu for the item (e.g. during install).
110 // Note the returned menu model is owned by this item.
111 virtual ui::MenuModel* GetContextMenuModel();
113 private:
114 gfx::ImageSkia icon_;
116 base::string16 title_;
117 Tags title_tags_;
119 base::string16 details_;
120 Tags details_tags_;
122 Actions actions_;
124 bool is_installing_;
125 int percent_downloaded_;
127 ObserverList<SearchResultObserver> observers_;
129 DISALLOW_COPY_AND_ASSIGN(SearchResult);
132 } // namespace app_list
134 #endif // UI_APP_LIST_SEARCH_RESULT_H_