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.
5 #include "ui/app_list/search_box_model.h"
7 #include "base/metrics/histogram.h"
8 #include "ui/app_list/search_box_model_observer.h"
12 SearchBoxModel::SpeechButtonProperty::SpeechButtonProperty(
13 const gfx::ImageSkia
& on_icon
,
14 const base::string16
& on_tooltip
,
15 const gfx::ImageSkia
& off_icon
,
16 const base::string16
& off_tooltip
)
18 on_tooltip(on_tooltip
),
20 off_tooltip(off_tooltip
) {
23 SearchBoxModel::SpeechButtonProperty::~SpeechButtonProperty() {
26 SearchBoxModel::SearchBoxModel() {
29 SearchBoxModel::~SearchBoxModel() {
32 void SearchBoxModel::SetIcon(const gfx::ImageSkia
& icon
) {
34 FOR_EACH_OBSERVER(SearchBoxModelObserver
, observers_
, IconChanged());
37 void SearchBoxModel::SetSpeechRecognitionButton(
38 scoped_ptr
<SearchBoxModel::SpeechButtonProperty
> speech_button
) {
39 speech_button_
= speech_button
.Pass();
40 FOR_EACH_OBSERVER(SearchBoxModelObserver
,
42 SpeechRecognitionButtonPropChanged());
45 void SearchBoxModel::SetHintText(const base::string16
& hint_text
) {
46 if (hint_text_
== hint_text
)
49 hint_text_
= hint_text
;
50 FOR_EACH_OBSERVER(SearchBoxModelObserver
, observers_
, HintTextChanged());
53 void SearchBoxModel::SetSelectionModel(const gfx::SelectionModel
& sel
) {
54 if (selection_model_
== sel
)
57 selection_model_
= sel
;
58 FOR_EACH_OBSERVER(SearchBoxModelObserver
,
60 SelectionModelChanged());
63 void SearchBoxModel::SetText(const base::string16
& text
) {
67 // Log that a new search has been commenced whenever the text box text
68 // transitions from empty to non-empty.
69 if (text_
.empty() && !text
.empty()) {
70 UMA_HISTOGRAM_ENUMERATION("Apps.AppListSearchCommenced", 1, 2);
73 FOR_EACH_OBSERVER(SearchBoxModelObserver
, observers_
, TextChanged());
76 void SearchBoxModel::AddObserver(SearchBoxModelObserver
* observer
) {
77 observers_
.AddObserver(observer
);
80 void SearchBoxModel::RemoveObserver(SearchBoxModelObserver
* observer
) {
81 observers_
.RemoveObserver(observer
);
84 } // namespace app_list