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/gfx/image/image_skia.h"
15 #include "ui/gfx/range/range.h"
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
28 class APP_LIST_EXPORT SearchResult
{
30 // How the result should be displayed.
36 // A tagged range in search result text.
37 struct APP_LIST_EXPORT Tag
{
38 // Similar to ACMatchClassification::Style, the style values are not
39 // mutually exclusive.
47 Tag(int styles
, size_t start
, size_t end
)
55 typedef std::vector
<Tag
> Tags
;
57 // Data representing an action that can be performed on this search result.
58 // An action could be represented as an icon set or as a blue button with
59 // a label. Icon set is chosen if label text is empty. Otherwise, a blue
60 // button with the label text will be used.
61 struct APP_LIST_EXPORT Action
{
62 Action(const gfx::ImageSkia
& base_image
,
63 const gfx::ImageSkia
& hover_image
,
64 const gfx::ImageSkia
& pressed_image
,
65 const base::string16
& tooltip_text
);
66 Action(const base::string16
& label_text
,
67 const base::string16
& tooltip_text
);
70 gfx::ImageSkia base_image
;
71 gfx::ImageSkia hover_image
;
72 gfx::ImageSkia pressed_image
;
74 base::string16 tooltip_text
;
75 base::string16 label_text
;
77 typedef std::vector
<Action
> Actions
;
80 virtual ~SearchResult();
82 const gfx::ImageSkia
& icon() const { return icon_
; }
83 void SetIcon(const gfx::ImageSkia
& icon
);
85 const base::string16
& title() const { return title_
; }
86 void set_title(const base::string16
& title
) { title_
= title
;}
88 const Tags
& title_tags() const { return title_tags_
; }
89 void set_title_tags(const Tags
& tags
) { title_tags_
= tags
; }
91 const base::string16
& details() const { return details_
; }
92 void set_details(const base::string16
& details
) { details_
= details
; }
94 const Tags
& details_tags() const { return details_tags_
; }
95 void set_details_tags(const Tags
& tags
) { details_tags_
= tags
; }
97 const std::string
& id() const { return id_
; }
98 double relevance() const { return relevance_
; }
99 DisplayType
display_type() const { return display_type_
; }
101 const Actions
& actions() const {
104 void SetActions(const Actions
& sets
);
106 bool is_installing() const { return is_installing_
; }
107 void SetIsInstalling(bool is_installing
);
109 int percent_downloaded() const { return percent_downloaded_
; }
110 void SetPercentDownloaded(int percent_downloaded
);
112 // Returns the dimension at which this result's icon should be displayed.
113 int GetPreferredIconDimension() const;
115 void NotifyItemInstalled();
116 void NotifyItemUninstalled();
118 void AddObserver(SearchResultObserver
* observer
);
119 void RemoveObserver(SearchResultObserver
* observer
);
122 virtual void Open(int event_flags
);
124 // Invokes a custom action on the result.
125 virtual void InvokeAction(int action_index
, int event_flags
);
127 // Returns the context menu model for this item, or NULL if there is currently
128 // no menu for the item (e.g. during install).
129 // Note the returned menu model is owned by this item.
130 virtual ui::MenuModel
* GetContextMenuModel();
133 void set_id(const std::string
& id
) { id_
= id
; }
134 void set_relevance(double relevance
) { relevance_
= relevance
; }
135 void set_display_type(DisplayType display_type
) {
136 display_type_
= display_type
;
140 gfx::ImageSkia icon_
;
142 base::string16 title_
;
145 base::string16 details_
;
150 DisplayType display_type_
;
155 int percent_downloaded_
;
157 ObserverList
<SearchResultObserver
> observers_
;
159 DISALLOW_COPY_AND_ASSIGN(SearchResult
);
162 } // namespace app_list
164 #endif // UI_APP_LIST_SEARCH_RESULT_H_