Update V8 to version 4.6.55.
[chromium-blink-merge.git] / ui / app_list / search_box_model.cc
blob87632d5f4b57800246e7e12a86552dc6b7974aff
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"
10 namespace app_list {
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)
18 : on_icon(on_icon),
19 on_tooltip(on_tooltip),
20 off_icon(off_icon),
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) {
35 icon_ = 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,
43 observers_,
44 SpeechRecognitionButtonPropChanged());
47 void SearchBoxModel::SetHintText(const base::string16& hint_text) {
48 if (hint_text_ == hint_text)
49 return;
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)
57 return;
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)
65 return;
67 selection_model_ = sel;
68 FOR_EACH_OBSERVER(SearchBoxModelObserver,
69 observers_,
70 SelectionModelChanged());
73 void SearchBoxModel::SetText(const base::string16& text) {
74 if (text_ == text)
75 return;
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);
82 text_ = text;
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