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#include "ui/app_list/search_result.h"
6
7#include "ui/app_list/app_list_constants.h"
8#include "ui/app_list/search_result_observer.h"
9
10namespace app_list {
11
12SearchResult::Action::Action(const gfx::ImageSkia& base_image,
13                             const gfx::ImageSkia& hover_image,
14                             const gfx::ImageSkia& pressed_image,
15                             const base::string16& tooltip_text)
16    : base_image(base_image),
17      hover_image(hover_image),
18      pressed_image(pressed_image),
19      tooltip_text(tooltip_text) {}
20
21SearchResult::Action::Action(const base::string16& label_text,
22                             const base::string16& tooltip_text)
23    : tooltip_text(tooltip_text),
24      label_text(label_text) {}
25
26SearchResult::Action::~Action() {}
27
28SearchResult::SearchResult()
29    : relevance_(0),
30      display_type_(DISPLAY_LIST),
31      is_installing_(false),
32      percent_downloaded_(0) {
33}
34
35SearchResult::~SearchResult() {
36  FOR_EACH_OBSERVER(SearchResultObserver, observers_, OnResultDestroying());
37}
38
39void SearchResult::SetIcon(const gfx::ImageSkia& icon) {
40  icon_ = icon;
41  FOR_EACH_OBSERVER(SearchResultObserver,
42                    observers_,
43                    OnIconChanged());
44}
45
46void SearchResult::SetActions(const Actions& sets) {
47  actions_ = sets;
48  FOR_EACH_OBSERVER(SearchResultObserver,
49                    observers_,
50                    OnActionsChanged());
51}
52
53void SearchResult::SetIsInstalling(bool is_installing) {
54  if (is_installing_ == is_installing)
55    return;
56
57  is_installing_ = is_installing;
58  FOR_EACH_OBSERVER(SearchResultObserver,
59                    observers_,
60                    OnIsInstallingChanged());
61}
62
63void SearchResult::SetPercentDownloaded(int percent_downloaded) {
64  if (percent_downloaded_ == percent_downloaded)
65    return;
66
67  percent_downloaded_ = percent_downloaded;
68  FOR_EACH_OBSERVER(SearchResultObserver,
69                    observers_,
70                    OnPercentDownloadedChanged());
71}
72
73int SearchResult::GetPreferredIconDimension() const {
74  switch (display_type_) {
75    case DISPLAY_TILE:
76      return kTileIconSize;
77    case DISPLAY_LIST:
78      return kListIconSize;
79  }
80  NOTREACHED();
81  return 0;
82}
83
84void SearchResult::NotifyItemInstalled() {
85  FOR_EACH_OBSERVER(SearchResultObserver, observers_, OnItemInstalled());
86}
87
88void SearchResult::NotifyItemUninstalled() {
89  FOR_EACH_OBSERVER(SearchResultObserver, observers_, OnItemUninstalled());
90}
91
92void SearchResult::AddObserver(SearchResultObserver* observer) {
93  observers_.AddObserver(observer);
94}
95
96void SearchResult::RemoveObserver(SearchResultObserver* observer) {
97  observers_.RemoveObserver(observer);
98}
99
100void SearchResult::Open(int event_flags) {
101}
102
103void SearchResult::InvokeAction(int action_index, int event_flags) {
104}
105
106ui::MenuModel* SearchResult::GetContextMenuModel() {
107  return NULL;
108}
109
110}  // namespace app_list
111