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
,
17 const base::string16
& accessible_name
)
19 on_tooltip(on_tooltip
),
21 off_tooltip(off_tooltip
),
22 accessible_name(accessible_name
) {
25 SearchBoxModel::SpeechButtonProperty::~SpeechButtonProperty() {
28 SearchBoxModel::SearchBoxModel() {
31 SearchBoxModel::~SearchBoxModel() {
34 void SearchBoxModel::SetIcon(const gfx::ImageSkia
& icon
) {
36 FOR_EACH_OBSERVER(SearchBoxModelObserver
, observers_
, IconChanged());
39 void SearchBoxModel::SetSpeechRecognitionButton(
40 scoped_ptr
<SearchBoxModel::SpeechButtonProperty
> speech_button
) {
41 speech_button_
= speech_button
.Pass();
42 FOR_EACH_OBSERVER(SearchBoxModelObserver
,
44 SpeechRecognitionButtonPropChanged());
47 void SearchBoxModel::SetHintText(const base::string16
& hint_text
) {
48 if (hint_text_
== hint_text
)
51 hint_text_
= hint_text
;
52 FOR_EACH_OBSERVER(SearchBoxModelObserver
, observers_
, HintTextChanged());
55 void SearchBoxModel::SetAccessibleName(const base::string16
& accessible_name
) {
56 if (accessible_name_
== accessible_name
)
59 accessible_name_
= accessible_name
;
60 FOR_EACH_OBSERVER(SearchBoxModelObserver
, observers_
, HintTextChanged());
63 void SearchBoxModel::SetSelectionModel(const gfx::SelectionModel
& sel
) {
64 if (selection_model_
== sel
)
67 selection_model_
= sel
;
68 FOR_EACH_OBSERVER(SearchBoxModelObserver
,
70 SelectionModelChanged());
73 void SearchBoxModel::SetText(const base::string16
& text
) {
77 // Log that a new search has been commenced whenever the text box text
78 // transitions from empty to non-empty.
79 if (text_
.empty() && !text
.empty()) {
80 UMA_HISTOGRAM_ENUMERATION("Apps.AppListSearchCommenced", 1, 2);
83 FOR_EACH_OBSERVER(SearchBoxModelObserver
, observers_
, TextChanged());
86 void SearchBoxModel::AddObserver(SearchBoxModelObserver
* observer
) {
87 observers_
.AddObserver(observer
);
90 void SearchBoxModel::RemoveObserver(SearchBoxModelObserver
* observer
) {
91 observers_
.RemoveObserver(observer
);
94 } // namespace app_list