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_box_model.h" 6 7#include "base/metrics/histogram.h" 8#include "ui/app_list/search_box_model_observer.h" 9 10namespace app_list { 11 12SearchBoxModel::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 : on_icon(on_icon), 18 on_tooltip(on_tooltip), 19 off_icon(off_icon), 20 off_tooltip(off_tooltip) { 21} 22 23SearchBoxModel::SpeechButtonProperty::~SpeechButtonProperty() { 24} 25 26SearchBoxModel::SearchBoxModel() { 27} 28 29SearchBoxModel::~SearchBoxModel() { 30} 31 32void SearchBoxModel::SetIcon(const gfx::ImageSkia& icon) { 33 icon_ = icon; 34 FOR_EACH_OBSERVER(SearchBoxModelObserver, observers_, IconChanged()); 35} 36 37void SearchBoxModel::SetSpeechRecognitionButton( 38 scoped_ptr<SearchBoxModel::SpeechButtonProperty> speech_button) { 39 speech_button_ = speech_button.Pass(); 40 FOR_EACH_OBSERVER(SearchBoxModelObserver, 41 observers_, 42 SpeechRecognitionButtonPropChanged()); 43} 44 45void SearchBoxModel::SetHintText(const base::string16& hint_text) { 46 if (hint_text_ == hint_text) 47 return; 48 49 hint_text_ = hint_text; 50 FOR_EACH_OBSERVER(SearchBoxModelObserver, observers_, HintTextChanged()); 51} 52 53void SearchBoxModel::SetSelectionModel(const gfx::SelectionModel& sel) { 54 if (selection_model_ == sel) 55 return; 56 57 selection_model_ = sel; 58 FOR_EACH_OBSERVER(SearchBoxModelObserver, 59 observers_, 60 SelectionModelChanged()); 61} 62 63void SearchBoxModel::SetText(const base::string16& text) { 64 if (text_ == text) 65 return; 66 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); 71 } 72 text_ = text; 73 FOR_EACH_OBSERVER(SearchBoxModelObserver, observers_, TextChanged()); 74} 75 76void SearchBoxModel::AddObserver(SearchBoxModelObserver* observer) { 77 observers_.AddObserver(observer); 78} 79 80void SearchBoxModel::RemoveObserver(SearchBoxModelObserver* observer) { 81 observers_.RemoveObserver(observer); 82} 83 84} // namespace app_list 85