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 41 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 76 const gfx::ImageSkia& icon() const { return icon_; } 77 void SetIcon(const gfx::ImageSkia& icon); 78 79 const base::string16& title() const { return title_; } 80 void set_title(const base::string16& title) { title_ = title;} 81 82 const Tags& title_tags() const { return title_tags_; } 83 void set_title_tags(const Tags& tags) { title_tags_ = tags; } 84 85 const base::string16& details() const { return details_; } 86 void set_details(const base::string16& details) { details_ = details; } 87 88 const Tags& details_tags() const { return details_tags_; } 89 void set_details_tags(const Tags& tags) { details_tags_ = tags; } 90 91 const Actions& actions() const { 92 return actions_; 93 } 94 void SetActions(const Actions& sets); 95 96 bool is_installing() const { return is_installing_; } 97 void SetIsInstalling(bool is_installing); 98 99 int percent_downloaded() const { return percent_downloaded_; } 100 void SetPercentDownloaded(int percent_downloaded); 101 102 void NotifyItemInstalled(); 103 void NotifyItemUninstalled(); 104 105 void AddObserver(SearchResultObserver* observer); 106 void RemoveObserver(SearchResultObserver* observer); 107 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(); 112 113 private: 114 gfx::ImageSkia icon_; 115 116 base::string16 title_; 117 Tags title_tags_; 118 119 base::string16 details_; 120 Tags details_tags_; 121 122 Actions actions_; 123 124 bool is_installing_; 125 int percent_downloaded_; 126 127 ObserverList<SearchResultObserver> observers_; 128 129 DISALLOW_COPY_AND_ASSIGN(SearchResult); 130 }; 131 132 } // namespace app_list 133 134 #endif // UI_APP_LIST_SEARCH_RESULT_H_ 135