search_result.h revision 5e3f23d412006dc4db4e659864679f29341e113f
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/base/range/range.h"
16#include "ui/gfx/image/image_skia.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 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    ui::Range range;
49  };
50  typedef std::vector<Tag> Tags;
51
52  // A collection of images representing an action that can be performed on this
53  // search result.
54  struct ActionIconSet {
55    ActionIconSet(const gfx::ImageSkia& base_image,
56                  const gfx::ImageSkia& hover_image,
57                  const gfx::ImageSkia& pressed_image,
58                  const string16& tooltip_text);
59    ~ActionIconSet();
60
61    gfx::ImageSkia base_image;
62    gfx::ImageSkia hover_image;
63    gfx::ImageSkia pressed_image;
64
65    string16 tooltip_text;
66  };
67  typedef std::vector<ActionIconSet> ActionIconSets;
68
69  SearchResult();
70  virtual ~SearchResult();
71
72  const gfx::ImageSkia& icon() const { return icon_; }
73  void SetIcon(const gfx::ImageSkia& icon);
74
75  const string16& title() const { return title_; }
76  void set_title(const string16& title) { title_ = title;}
77
78  const Tags& title_tags() const { return title_tags_; }
79  void set_title_tags(const Tags& tags) { title_tags_ = tags; }
80
81  const string16& details() const { return details_; }
82  void set_details(const string16& details) { details_ = details; }
83
84  const Tags& details_tags() const { return details_tags_; }
85  void set_details_tags(const Tags& tags) { details_tags_ = tags; }
86
87  const ActionIconSets& action_icons() const {
88    return action_icons_;
89  }
90  void SetActionIcons(const ActionIconSets& sets);
91
92  void AddObserver(SearchResultObserver* observer);
93  void RemoveObserver(SearchResultObserver* observer);
94
95  // Returns the context menu model for this item.
96  // Note the returned menu model is owned by this item.
97  virtual ui::MenuModel* GetContextMenuModel();
98
99 private:
100  gfx::ImageSkia icon_;
101
102  string16 title_;
103  Tags title_tags_;
104
105  string16 details_;
106  Tags details_tags_;
107
108  // Optional list of icons representing additional actions that can be
109  // performed on this result.
110  ActionIconSets action_icons_;
111
112  ObserverList<SearchResultObserver> observers_;
113
114  DISALLOW_COPY_AND_ASSIGN(SearchResult);
115};
116
117}  // namespace app_list
118
119#endif  // UI_APP_LIST_SEARCH_RESULT_H_
120