• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #ifndef UI_APP_LIST_SEARCH_RESULT_H_
6 #define UI_APP_LIST_SEARCH_RESULT_H_
7 
8 #include <vector>
9 
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"
16 
17 namespace ui {
18 class MenuModel;
19 }
20 
21 namespace app_list {
22 
23 class SearchResultObserver;
24 
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,
39     };
40 
TagTag41     Tag(int styles, size_t start, size_t end)
42         : styles(styles),
43           range(start, end) {
44     }
45 
46     int styles;
47     gfx::Range range;
48   };
49   typedef std::vector<Tag> Tags;
50 
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();
63 
64     gfx::ImageSkia base_image;
65     gfx::ImageSkia hover_image;
66     gfx::ImageSkia pressed_image;
67 
68     base::string16 tooltip_text;
69     base::string16 label_text;
70   };
71   typedef std::vector<Action> Actions;
72 
73   SearchResult();
74   virtual ~SearchResult();
75 
icon()76   const gfx::ImageSkia& icon() const { return icon_; }
77   void SetIcon(const gfx::ImageSkia& icon);
78 
title()79   const base::string16& title() const { return title_; }
set_title(const base::string16 & title)80   void set_title(const base::string16& title) { title_ = title;}
81 
title_tags()82   const Tags& title_tags() const { return title_tags_; }
set_title_tags(const Tags & tags)83   void set_title_tags(const Tags& tags) { title_tags_ = tags; }
84 
details()85   const base::string16& details() const { return details_; }
set_details(const base::string16 & details)86   void set_details(const base::string16& details) { details_ = details; }
87 
details_tags()88   const Tags& details_tags() const { return details_tags_; }
set_details_tags(const Tags & tags)89   void set_details_tags(const Tags& tags) { details_tags_ = tags; }
90 
id()91   const std::string& id() const { return id_; }
relevance()92   double relevance() { return relevance_; }
93 
actions()94   const Actions& actions() const {
95     return actions_;
96   }
97   void SetActions(const Actions& sets);
98 
is_installing()99   bool is_installing() const { return is_installing_; }
100   void SetIsInstalling(bool is_installing);
101 
percent_downloaded()102   int percent_downloaded() const { return percent_downloaded_; }
103   void SetPercentDownloaded(int percent_downloaded);
104 
105   void NotifyItemInstalled();
106   void NotifyItemUninstalled();
107 
108   void AddObserver(SearchResultObserver* observer);
109   void RemoveObserver(SearchResultObserver* observer);
110 
111   // Opens the result.
112   virtual void Open(int event_flags);
113 
114   // Invokes a custom action on the result.
115   virtual void InvokeAction(int action_index, int event_flags);
116 
117   // Returns the context menu model for this item, or NULL if there is currently
118   // no menu for the item (e.g. during install).
119   // Note the returned menu model is owned by this item.
120   virtual ui::MenuModel* GetContextMenuModel();
121 
122  protected:
set_id(const std::string & id)123   void set_id(const std::string& id) { id_ = id; }
set_relevance(double relevance)124   void set_relevance(double relevance) { relevance_ = relevance; }
125 
126  private:
127   gfx::ImageSkia icon_;
128 
129   base::string16 title_;
130   Tags title_tags_;
131 
132   base::string16 details_;
133   Tags details_tags_;
134 
135   std::string id_;
136   double relevance_;
137 
138   Actions actions_;
139 
140   bool is_installing_;
141   int percent_downloaded_;
142 
143   ObserverList<SearchResultObserver> observers_;
144 
145   DISALLOW_COPY_AND_ASSIGN(SearchResult);
146 };
147 
148 }  // namespace app_list
149 
150 #endif  // UI_APP_LIST_SEARCH_RESULT_H_
151