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 #ifndef UI_APP_LIST_SEARCH_BOX_MODEL_H_
6 #define UI_APP_LIST_SEARCH_BOX_MODEL_H_
8 #include "base/basictypes.h"
9 #include "base/observer_list.h"
10 #include "base/strings/string16.h"
11 #include "ui/app_list/app_list_export.h"
12 #include "ui/gfx/image/image_skia.h"
13 #include "ui/gfx/selection_model.h"
17 class SearchBoxModelObserver
;
19 // SearchBoxModel consisits of an icon, a hint text, a user text and a selection
20 // model. The icon is rendered to the side of the query editor. The hint text
21 // is used as query edit control's placeholder text and displayed when there is
22 // no user text in the control. The selection model and the text represents the
23 // text, cursor position and selected text in edit control.
24 class APP_LIST_EXPORT SearchBoxModel
{
26 // The properties of the speech button.
27 struct APP_LIST_EXPORT SpeechButtonProperty
{
28 SpeechButtonProperty(const gfx::ImageSkia
& on_icon
,
29 const base::string16
& on_tooltip
,
30 const gfx::ImageSkia
& off_icon
,
31 const base::string16
& off_tooltip
,
32 const base::string16
& accessible_name
);
33 ~SpeechButtonProperty();
35 // The icon/tooltip when the hotword is on.
36 gfx::ImageSkia on_icon
;
37 base::string16 on_tooltip
;
39 // The icon/tooltip when the hotword is off.
40 gfx::ImageSkia off_icon
;
41 base::string16 off_tooltip
;
43 // The accessibility name of the button.
44 base::string16 accessible_name
;
50 // Sets/gets the icon on the left side of edit box.
51 void SetIcon(const gfx::ImageSkia
& icon
);
52 const gfx::ImageSkia
& icon() const { return icon_
; }
54 // Sets/gets the properties for the button of speech recognition.
55 void SetSpeechRecognitionButton(
56 scoped_ptr
<SpeechButtonProperty
> speech_button
);
57 const SpeechButtonProperty
* speech_button() const {
58 return speech_button_
.get();
61 // Sets/gets the hint text to display when there is in input.
62 void SetHintText(const base::string16
& hint_text
);
63 const base::string16
& hint_text() const { return hint_text_
; }
65 // Sets/gets the text for screen readers on the search box.
66 void SetAccessibleName(const base::string16
& accessible_name
);
67 const base::string16
& accessible_name() const { return accessible_name_
; }
69 // Sets/gets the selection model for the search box's Textfield.
70 void SetSelectionModel(const gfx::SelectionModel
& sel
);
71 const gfx::SelectionModel
& selection_model() const {
72 return selection_model_
;
75 // Sets/gets the text for the search box's Textfield.
76 void SetText(const base::string16
& text
);
77 const base::string16
& text() const { return text_
; }
79 void AddObserver(SearchBoxModelObserver
* observer
);
80 void RemoveObserver(SearchBoxModelObserver
* observer
);
84 scoped_ptr
<SpeechButtonProperty
> speech_button_
;
85 base::string16 hint_text_
;
86 base::string16 accessible_name_
;
87 gfx::SelectionModel selection_model_
;
90 ObserverList
<SearchBoxModelObserver
> observers_
;
92 DISALLOW_COPY_AND_ASSIGN(SearchBoxModel
);
95 } // namespace app_list
97 #endif // UI_APP_LIST_SEARCH_BOX_MODEL_H_