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_
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/base/models/list_model.h"
15 #include "ui/gfx/image/image_skia.h"
16 #include "ui/gfx/range/range.h"
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
29 class APP_LIST_EXPORT SearchResult {
31 // A tagged range in search result text.
32 struct APP_LIST_EXPORT Tag {
33 // Similar to ACMatchClassification::Style, the style values are not
34 // mutually exclusive.
42 Tag(int styles, size_t start, size_t end)
50 typedef std::vector<Tag> Tags;
52 // Data representing an action that can be performed on this search result.
53 // An action could be represented as an icon set or as a blue button with
54 // a label. Icon set is chosen if label text is empty. Otherwise, a blue
55 // button with the label text will be used.
56 struct APP_LIST_EXPORT Action {
57 Action(const gfx::ImageSkia& base_image,
58 const gfx::ImageSkia& hover_image,
59 const gfx::ImageSkia& pressed_image,
60 const base::string16& tooltip_text);
61 Action(const base::string16& label_text,
62 const base::string16& tooltip_text);
65 gfx::ImageSkia base_image;
66 gfx::ImageSkia hover_image;
67 gfx::ImageSkia pressed_image;
69 base::string16 tooltip_text;
70 base::string16 label_text;
72 typedef std::vector<Action> Actions;
75 virtual ~SearchResult();
77 const gfx::ImageSkia& icon() const { return icon_; }
78 void SetIcon(const gfx::ImageSkia& icon);
80 const base::string16& title() const { return title_; }
81 void set_title(const base::string16& title) { title_ = title;}
83 const Tags& title_tags() const { return title_tags_; }
84 void set_title_tags(const Tags& tags) { title_tags_ = tags; }
86 const base::string16& details() const { return details_; }
87 void set_details(const base::string16& details) { details_ = details; }
89 const Tags& details_tags() const { return details_tags_; }
90 void set_details_tags(const Tags& tags) { details_tags_ = tags; }
92 const Actions& actions() const {
95 void SetActions(const Actions& sets);
97 bool is_installing() const { return is_installing_; }
98 void SetIsInstalling(bool is_installing);
100 int percent_downloaded() const { return percent_downloaded_; }
101 void SetPercentDownloaded(int percent_downloaded);
103 void NotifyItemInstalled();
104 void NotifyItemUninstalled();
106 void AddObserver(SearchResultObserver* observer);
107 void RemoveObserver(SearchResultObserver* observer);
109 // Returns the context menu model for this item, or NULL if there is currently
110 // no menu for the item (e.g. during install).
111 // Note the returned menu model is owned by this item.
112 virtual ui::MenuModel* GetContextMenuModel();
115 gfx::ImageSkia icon_;
117 base::string16 title_;
120 base::string16 details_;
126 int percent_downloaded_;
128 ObserverList<SearchResultObserver> observers_;
130 DISALLOW_COPY_AND_ASSIGN(SearchResult);
133 } // namespace app_list
135 #endif // UI_APP_LIST_SEARCH_RESULT_H_