search_result.h revision 58537e28ecd584eab876aee8be7156509866d23a
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/base/models/list_model.h" 15#include "ui/gfx/image/image_skia.h" 16#include "ui/gfx/range/range.h" 17 18namespace ui { 19class MenuModel; 20} 21 22namespace app_list { 23 24class SearchResultObserver; 25 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 28// default style. 29class APP_LIST_EXPORT SearchResult { 30 public: 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. 35 enum Style { 36 NONE = 0, 37 URL = 1 << 0, 38 MATCH = 1 << 1, 39 DIM = 1 << 2, 40 }; 41 42 Tag(int styles, size_t start, size_t end) 43 : styles(styles), 44 range(start, end) { 45 } 46 47 int styles; 48 gfx::Range range; 49 }; 50 typedef std::vector<Tag> Tags; 51 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); 63 ~Action(); 64 65 gfx::ImageSkia base_image; 66 gfx::ImageSkia hover_image; 67 gfx::ImageSkia pressed_image; 68 69 base::string16 tooltip_text; 70 base::string16 label_text; 71 }; 72 typedef std::vector<Action> Actions; 73 74 SearchResult(); 75 virtual ~SearchResult(); 76 77 const gfx::ImageSkia& icon() const { return icon_; } 78 void SetIcon(const gfx::ImageSkia& icon); 79 80 const base::string16& title() const { return title_; } 81 void set_title(const base::string16& title) { title_ = title;} 82 83 const Tags& title_tags() const { return title_tags_; } 84 void set_title_tags(const Tags& tags) { title_tags_ = tags; } 85 86 const base::string16& details() const { return details_; } 87 void set_details(const base::string16& details) { details_ = details; } 88 89 const Tags& details_tags() const { return details_tags_; } 90 void set_details_tags(const Tags& tags) { details_tags_ = tags; } 91 92 const Actions& actions() const { 93 return actions_; 94 } 95 void SetActions(const Actions& sets); 96 97 bool is_installing() const { return is_installing_; } 98 void SetIsInstalling(bool is_installing); 99 100 int percent_downloaded() const { return percent_downloaded_; } 101 void SetPercentDownloaded(int percent_downloaded); 102 103 void NotifyItemInstalled(); 104 void NotifyItemUninstalled(); 105 106 void AddObserver(SearchResultObserver* observer); 107 void RemoveObserver(SearchResultObserver* observer); 108 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(); 113 114 private: 115 gfx::ImageSkia icon_; 116 117 base::string16 title_; 118 Tags title_tags_; 119 120 base::string16 details_; 121 Tags details_tags_; 122 123 Actions actions_; 124 125 bool is_installing_; 126 int percent_downloaded_; 127 128 ObserverList<SearchResultObserver> observers_; 129 130 DISALLOW_COPY_AND_ASSIGN(SearchResult); 131}; 132 133} // namespace app_list 134 135#endif // UI_APP_LIST_SEARCH_RESULT_H_ 136