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 #ifndef UI_APP_LIST_SEARCH_BOX_MODEL_H_ | 5 #ifndef UI_APP_LIST_SEARCH_BOX_MODEL_H_ |
6 #define UI_APP_LIST_SEARCH_BOX_MODEL_H_ | 6 #define UI_APP_LIST_SEARCH_BOX_MODEL_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/observer_list.h" | 9 #include "base/observer_list.h" |
10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
11 #include "ui/app_list/app_list_export.h" | 11 #include "ui/app_list/app_list_export.h" |
12 #include "ui/gfx/image/image_skia.h" | 12 #include "ui/gfx/image/image_skia.h" |
13 #include "ui/gfx/selection_model.h" | 13 #include "ui/gfx/selection_model.h" |
14 | 14 |
15 namespace app_list { | 15 namespace app_list { |
16 | 16 |
17 class SearchBoxModelObserver; | 17 class SearchBoxModelObserver; |
18 | 18 |
19 // SearchBoxModel consisits of an icon, a hint text, a user text and a selection | 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 | 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 | 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 | 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. | 23 // text, cursor position and selected text in edit control. |
24 class APP_LIST_EXPORT SearchBoxModel { | 24 class APP_LIST_EXPORT SearchBoxModel { |
25 public: | 25 public: |
26 // The properties of the button with toggled status. | 26 // The properties of the button. |
27 struct APP_LIST_EXPORT ToggleButtonProperty { | 27 struct APP_LIST_EXPORT ButtonProperty { |
28 ToggleButtonProperty(const gfx::ImageSkia& icon, | 28 ButtonProperty(const gfx::ImageSkia& icon, const base::string16& tooltip); |
29 const gfx::ImageSkia& toggled_icon, | 29 ~ButtonProperty(); |
30 const base::string16& tooltip, | |
31 const base::string16& toggled_tooltip); | |
32 ~ToggleButtonProperty(); | |
33 | 30 |
34 gfx::ImageSkia icon; | 31 gfx::ImageSkia icon; |
35 gfx::ImageSkia toggled_icon; | |
36 base::string16 tooltip; | 32 base::string16 tooltip; |
37 base::string16 toggled_tooltip; | |
38 }; | 33 }; |
39 | 34 |
40 SearchBoxModel(); | 35 SearchBoxModel(); |
41 ~SearchBoxModel(); | 36 ~SearchBoxModel(); |
42 | 37 |
43 // Sets/gets the icon on the left side of edit box. | 38 // Sets/gets the icon on the left side of edit box. |
44 void SetIcon(const gfx::ImageSkia& icon); | 39 void SetIcon(const gfx::ImageSkia& icon); |
45 const gfx::ImageSkia& icon() const { return icon_; } | 40 const gfx::ImageSkia& icon() const { return icon_; } |
46 | 41 |
47 // Sets/gets the properties for the button of speech recognition. | 42 // Sets/gets the properties for the button of speech recognition. |
48 void SetSpeechRecognitionButton( | 43 void SetSpeechRecognitionButton(scoped_ptr<ButtonProperty> speech_button); |
49 scoped_ptr<ToggleButtonProperty> speech_button); | 44 const ButtonProperty* speech_button() const { return speech_button_.get(); } |
50 const ToggleButtonProperty* speech_button() const { | |
51 return speech_button_.get(); | |
52 } | |
53 | |
54 // Sets the speech recognition button state. | |
55 void SetSpeechRecognitionButtonState(bool toggled); | |
56 | 45 |
57 // Sets/gets the hint text to display when there is in input. | 46 // Sets/gets the hint text to display when there is in input. |
58 void SetHintText(const base::string16& hint_text); | 47 void SetHintText(const base::string16& hint_text); |
59 const base::string16& hint_text() const { return hint_text_; } | 48 const base::string16& hint_text() const { return hint_text_; } |
60 | 49 |
61 // Sets/gets the selection model for the search box's Textfield. | 50 // Sets/gets the selection model for the search box's Textfield. |
62 void SetSelectionModel(const gfx::SelectionModel& sel); | 51 void SetSelectionModel(const gfx::SelectionModel& sel); |
63 const gfx::SelectionModel& selection_model() const { | 52 const gfx::SelectionModel& selection_model() const { |
64 return selection_model_; | 53 return selection_model_; |
65 } | 54 } |
66 | 55 |
67 // Sets/gets the text for the search box's Textfield. | 56 // Sets/gets the text for the search box's Textfield. |
68 void SetText(const base::string16& text); | 57 void SetText(const base::string16& text); |
69 const base::string16& text() const { return text_; } | 58 const base::string16& text() const { return text_; } |
70 | 59 |
71 void AddObserver(SearchBoxModelObserver* observer); | 60 void AddObserver(SearchBoxModelObserver* observer); |
72 void RemoveObserver(SearchBoxModelObserver* observer); | 61 void RemoveObserver(SearchBoxModelObserver* observer); |
73 | 62 |
74 private: | 63 private: |
75 gfx::ImageSkia icon_; | 64 gfx::ImageSkia icon_; |
76 scoped_ptr<ToggleButtonProperty> speech_button_; | 65 scoped_ptr<ButtonProperty> speech_button_; |
77 base::string16 hint_text_; | 66 base::string16 hint_text_; |
78 gfx::SelectionModel selection_model_; | 67 gfx::SelectionModel selection_model_; |
79 base::string16 text_; | 68 base::string16 text_; |
80 | 69 |
81 ObserverList<SearchBoxModelObserver> observers_; | 70 ObserverList<SearchBoxModelObserver> observers_; |
82 | 71 |
83 DISALLOW_COPY_AND_ASSIGN(SearchBoxModel); | 72 DISALLOW_COPY_AND_ASSIGN(SearchBoxModel); |
84 }; | 73 }; |
85 | 74 |
86 } // namespace app_list | 75 } // namespace app_list |
87 | 76 |
88 #endif // UI_APP_LIST_SEARCH_BOX_MODEL_H_ | 77 #endif // UI_APP_LIST_SEARCH_BOX_MODEL_H_ |
OLD | NEW |