OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/app_list/search_box_model.h" | 5 #include "ui/app_list/search_box_model.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
10 #include "ui/app_list/search_box_model_observer.h" | 10 #include "ui/app_list/search_box_model_observer.h" |
11 | 11 |
12 namespace app_list { | 12 namespace app_list { |
13 | 13 |
14 SearchBoxModel::SpeechButtonProperty::SpeechButtonProperty( | 14 SearchBoxModel::SpeechButtonProperty::SpeechButtonProperty( |
15 const gfx::ImageSkia& on_icon, | 15 const gfx::ImageSkia& on_icon, |
16 const base::string16& on_tooltip, | 16 const base::string16& on_tooltip, |
17 const gfx::ImageSkia& off_icon, | 17 const gfx::ImageSkia& off_icon, |
18 const base::string16& off_tooltip, | 18 const base::string16& off_tooltip, |
19 const base::string16& accessible_name) | 19 const base::string16& accessible_name) |
20 : on_icon(on_icon), | 20 : on_icon(on_icon), |
21 on_tooltip(on_tooltip), | 21 on_tooltip(on_tooltip), |
22 off_icon(off_icon), | 22 off_icon(off_icon), |
23 off_tooltip(off_tooltip), | 23 off_tooltip(off_tooltip), |
24 accessible_name(accessible_name) { | 24 accessible_name(accessible_name) { |
25 } | 25 } |
26 | 26 |
27 SearchBoxModel::SpeechButtonProperty::~SpeechButtonProperty() { | 27 SearchBoxModel::SpeechButtonProperty::~SpeechButtonProperty() { |
28 } | 28 } |
29 | 29 |
30 SearchBoxModel::SearchBoxModel() { | 30 SearchBoxModel::SearchBoxModel() {} |
31 } | |
32 | 31 |
33 SearchBoxModel::~SearchBoxModel() { | 32 SearchBoxModel::~SearchBoxModel() { |
34 } | 33 } |
35 | 34 |
36 void SearchBoxModel::SetSpeechRecognitionButton( | 35 void SearchBoxModel::SetSpeechRecognitionButton( |
37 std::unique_ptr<SearchBoxModel::SpeechButtonProperty> speech_button) { | 36 std::unique_ptr<SearchBoxModel::SpeechButtonProperty> speech_button) { |
38 speech_button_ = std::move(speech_button); | 37 speech_button_ = std::move(speech_button); |
39 for (auto& observer : observers_) | 38 for (auto& observer : observers_) |
40 observer.SpeechRecognitionButtonPropChanged(); | 39 observer.SpeechRecognitionButtonPropChanged(); |
41 } | 40 } |
(...skipping 18 matching lines...) Expand all Loading... |
60 | 59 |
61 void SearchBoxModel::SetSelectionModel(const gfx::SelectionModel& sel) { | 60 void SearchBoxModel::SetSelectionModel(const gfx::SelectionModel& sel) { |
62 if (selection_model_ == sel) | 61 if (selection_model_ == sel) |
63 return; | 62 return; |
64 | 63 |
65 selection_model_ = sel; | 64 selection_model_ = sel; |
66 for (auto& observer : observers_) | 65 for (auto& observer : observers_) |
67 observer.SelectionModelChanged(); | 66 observer.SelectionModelChanged(); |
68 } | 67 } |
69 | 68 |
70 void SearchBoxModel::SetText(const base::string16& text) { | 69 void SearchBoxModel::Update(const base::string16& text, bool is_voice_query) { |
71 if (text_ == text) | 70 if (text_ == text && is_voice_query_ == is_voice_query) |
72 return; | 71 return; |
73 | 72 |
74 // Log that a new search has been commenced whenever the text box text | 73 // Log that a new search has been commenced whenever the text box text |
75 // transitions from empty to non-empty. | 74 // transitions from empty to non-empty. |
76 if (text_.empty() && !text.empty()) { | 75 if (text_.empty() && !text.empty()) { |
77 UMA_HISTOGRAM_ENUMERATION("Apps.AppListSearchCommenced", 1, 2); | 76 UMA_HISTOGRAM_ENUMERATION("Apps.AppListSearchCommenced", 1, 2); |
78 } | 77 } |
79 text_ = text; | 78 text_ = text; |
| 79 is_voice_query_ = is_voice_query; |
80 for (auto& observer : observers_) | 80 for (auto& observer : observers_) |
81 observer.TextChanged(); | 81 observer.Update(); |
82 } | 82 } |
83 | 83 |
84 void SearchBoxModel::AddObserver(SearchBoxModelObserver* observer) { | 84 void SearchBoxModel::AddObserver(SearchBoxModelObserver* observer) { |
85 observers_.AddObserver(observer); | 85 observers_.AddObserver(observer); |
86 } | 86 } |
87 | 87 |
88 void SearchBoxModel::RemoveObserver(SearchBoxModelObserver* observer) { | 88 void SearchBoxModel::RemoveObserver(SearchBoxModelObserver* observer) { |
89 observers_.RemoveObserver(observer); | 89 observers_.RemoveObserver(observer); |
90 } | 90 } |
91 | 91 |
92 } // namespace app_list | 92 } // namespace app_list |
OLD | NEW |