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/views/search_box_view.h" | 5 #include "ui/app_list/views/search_box_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "ui/app_list/app_list_model.h" | 9 #include "ui/app_list/app_list_model.h" |
10 #include "ui/app_list/app_list_switches.h" | 10 #include "ui/app_list/app_list_switches.h" |
11 #include "ui/app_list/app_list_view_delegate.h" | 11 #include "ui/app_list/app_list_view_delegate.h" |
12 #include "ui/app_list/search_box_model.h" | 12 #include "ui/app_list/search_box_model.h" |
13 #include "ui/app_list/speech_ui_model.h" | 13 #include "ui/app_list/speech_ui_model.h" |
14 #include "ui/app_list/views/app_list_menu_views.h" | 14 #include "ui/app_list/views/app_list_menu_views.h" |
15 #include "ui/app_list/views/search_box_view_delegate.h" | 15 #include "ui/app_list/views/search_box_view_delegate.h" |
16 #include "ui/base/resource/resource_bundle.h" | 16 #include "ui/base/resource/resource_bundle.h" |
17 #include "ui/events/event.h" | 17 #include "ui/events/event.h" |
18 #include "ui/gfx/canvas.h" | 18 #include "ui/gfx/canvas.h" |
19 #include "ui/resources/grit/ui_resources.h" | 19 #include "ui/resources/grit/ui_resources.h" |
20 #include "ui/views/border.h" | 20 #include "ui/views/border.h" |
21 #include "ui/views/controls/button/image_button.h" | 21 #include "ui/views/controls/button/image_button.h" |
22 #include "ui/views/controls/button/menu_button.h" | 22 #include "ui/views/controls/button/menu_button.h" |
23 #include "ui/views/controls/image_view.h" | 23 #include "ui/views/controls/image_view.h" |
24 #include "ui/views/controls/textfield/textfield.h" | 24 #include "ui/views/controls/textfield/textfield.h" |
25 #include "ui/views/layout/box_layout.h" | |
25 | 26 |
26 namespace app_list { | 27 namespace app_list { |
27 | 28 |
28 namespace { | 29 namespace { |
29 | 30 |
30 const int kPadding = 14; | 31 const int kPadding = 14; |
31 const int kIconDimension = 32; | |
32 const int kPreferredWidth = 360; | 32 const int kPreferredWidth = 360; |
33 const int kPreferredHeight = 48; | 33 const int kPreferredHeight = 48; |
34 #if !defined(OS_CHROMEOS) | |
35 const int kMenuButtonDimension = 29; | |
36 #endif | |
37 | 34 |
38 const SkColor kHintTextColor = SkColorSetRGB(0xA0, 0xA0, 0xA0); | 35 const SkColor kHintTextColor = SkColorSetRGB(0xA0, 0xA0, 0xA0); |
39 | 36 |
40 // Menu offset relative to the bottom-right corner of the menu button. | 37 // Menu offset relative to the bottom-right corner of the menu button. |
41 const int kMenuYOffsetFromButton = -4; | 38 const int kMenuYOffsetFromButton = -4; |
42 const int kMenuXOffsetFromButton = -7; | 39 const int kMenuXOffsetFromButton = -7; |
43 | 40 |
44 // Experimental app list constants. | 41 // Experimental app list constants. |
45 const int kExperimentalSearchBoxHeight = 37; | 42 const int kExperimentalSearchBoxHeight = 37; |
46 | 43 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
87 view_delegate_(view_delegate), | 84 view_delegate_(view_delegate), |
88 model_(NULL), | 85 model_(NULL), |
89 icon_view_(new views::ImageView), | 86 icon_view_(new views::ImageView), |
90 speech_button_(NULL), | 87 speech_button_(NULL), |
91 search_box_(new views::Textfield), | 88 search_box_(new views::Textfield), |
92 contents_view_(NULL) { | 89 contents_view_(NULL) { |
93 AddChildView(icon_view_); | 90 AddChildView(icon_view_); |
94 if (switches::IsExperimentalAppListEnabled()) | 91 if (switches::IsExperimentalAppListEnabled()) |
95 set_background(new ExperimentalBackground()); | 92 set_background(new ExperimentalBackground()); |
96 | 93 |
94 views::BoxLayout* layout = new views::BoxLayout( | |
95 views::BoxLayout::kHorizontal, kPadding, 0, kPadding); | |
96 SetLayoutManager(layout); | |
97 layout->set_cross_axis_alignment( | |
98 views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER); | |
99 layout->set_minimum_cross_axis_size(switches::IsExperimentalAppListEnabled() | |
100 ? kExperimentalSearchBoxHeight | |
101 : kPreferredHeight); | |
102 | |
97 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 103 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
98 | 104 |
105 search_box_->SetBorder(views::Border::NullBorder()); | |
Matt Giuca
2014/08/26 02:44:14
optional nit: Did this need to move?
(I suppose i
calamity
2014/08/26 04:06:31
Yeah, it does. Child order matters for BoxLayout.
| |
106 search_box_->SetFontList(rb.GetFontList(ui::ResourceBundle::MediumFont)); | |
107 search_box_->set_placeholder_text_color(kHintTextColor); | |
108 search_box_->set_controller(this); | |
109 AddChildView(search_box_); | |
110 layout->SetFlexForView(search_box_, 1); | |
111 | |
99 #if !defined(OS_CHROMEOS) | 112 #if !defined(OS_CHROMEOS) |
100 menu_button_ = new views::MenuButton(NULL, base::string16(), this, false); | 113 menu_button_ = new views::MenuButton(NULL, base::string16(), this, false); |
101 menu_button_->SetBorder(views::Border::NullBorder()); | 114 menu_button_->SetBorder(views::Border::NullBorder()); |
102 menu_button_->SetImage(views::Button::STATE_NORMAL, | 115 menu_button_->SetImage(views::Button::STATE_NORMAL, |
103 *rb.GetImageSkiaNamed(IDR_APP_LIST_TOOLS_NORMAL)); | 116 *rb.GetImageSkiaNamed(IDR_APP_LIST_TOOLS_NORMAL)); |
104 menu_button_->SetImage(views::Button::STATE_HOVERED, | 117 menu_button_->SetImage(views::Button::STATE_HOVERED, |
105 *rb.GetImageSkiaNamed(IDR_APP_LIST_TOOLS_HOVER)); | 118 *rb.GetImageSkiaNamed(IDR_APP_LIST_TOOLS_HOVER)); |
106 menu_button_->SetImage(views::Button::STATE_PRESSED, | 119 menu_button_->SetImage(views::Button::STATE_PRESSED, |
107 *rb.GetImageSkiaNamed(IDR_APP_LIST_TOOLS_PRESSED)); | 120 *rb.GetImageSkiaNamed(IDR_APP_LIST_TOOLS_PRESSED)); |
108 AddChildView(menu_button_); | 121 AddChildView(menu_button_); |
109 #endif | 122 #endif |
110 | 123 |
111 search_box_->SetBorder(views::Border::NullBorder()); | |
112 search_box_->SetFontList(rb.GetFontList(ui::ResourceBundle::MediumFont)); | |
113 search_box_->set_placeholder_text_color(kHintTextColor); | |
114 search_box_->set_controller(this); | |
115 AddChildView(search_box_); | |
116 | |
117 view_delegate_->GetSpeechUI()->AddObserver(this); | 124 view_delegate_->GetSpeechUI()->AddObserver(this); |
118 ModelChanged(); | 125 ModelChanged(); |
119 } | 126 } |
120 | 127 |
121 SearchBoxView::~SearchBoxView() { | 128 SearchBoxView::~SearchBoxView() { |
122 view_delegate_->GetSpeechUI()->RemoveObserver(this); | 129 view_delegate_->GetSpeechUI()->RemoveObserver(this); |
123 model_->search_box()->RemoveObserver(this); | 130 model_->search_box()->RemoveObserver(this); |
124 } | 131 } |
125 | 132 |
126 void SearchBoxView::ModelChanged() { | 133 void SearchBoxView::ModelChanged() { |
(...skipping 25 matching lines...) Expand all Loading... | |
152 menu_.reset(); | 159 menu_.reset(); |
153 } | 160 } |
154 | 161 |
155 gfx::Size SearchBoxView::GetPreferredSize() const { | 162 gfx::Size SearchBoxView::GetPreferredSize() const { |
156 return gfx::Size(kPreferredWidth, | 163 return gfx::Size(kPreferredWidth, |
157 switches::IsExperimentalAppListEnabled() | 164 switches::IsExperimentalAppListEnabled() |
158 ? kExperimentalSearchBoxHeight | 165 ? kExperimentalSearchBoxHeight |
159 : kPreferredHeight); | 166 : kPreferredHeight); |
160 } | 167 } |
161 | 168 |
162 void SearchBoxView::Layout() { | |
163 gfx::Rect rect(GetContentsBounds()); | |
164 if (rect.IsEmpty()) | |
165 return; | |
166 | |
167 gfx::Rect icon_frame(rect); | |
168 icon_frame.set_width(kIconDimension + 2 * kPadding); | |
169 icon_view_->SetBoundsRect(icon_frame); | |
170 | |
171 // Places |speech_button_| if exists. |speech_button_frame| holds its bounds | |
172 // to calculate the search box bounds. | |
173 gfx::Rect speech_button_frame; | |
174 if (speech_button_) { | |
175 speech_button_frame = icon_frame; | |
176 speech_button_frame.set_x(rect.right() - icon_frame.width()); | |
177 gfx::Size button_size = speech_button_->GetPreferredSize(); | |
178 gfx::Point button_origin = speech_button_frame.CenterPoint(); | |
179 button_origin.Offset(-button_size.width() / 2, -button_size.height() / 2); | |
180 speech_button_->SetBoundsRect(gfx::Rect(button_origin, button_size)); | |
181 } | |
182 | |
183 gfx::Rect menu_button_frame(rect); | |
184 #if !defined(OS_CHROMEOS) | |
185 menu_button_frame.set_width(kMenuButtonDimension); | |
186 menu_button_frame.set_x(rect.right() - menu_button_frame.width() - kPadding); | |
187 menu_button_frame.ClampToCenteredSize(gfx::Size(menu_button_frame.width(), | |
188 kMenuButtonDimension)); | |
189 menu_button_->SetBoundsRect(menu_button_frame); | |
190 #else | |
191 menu_button_frame.set_width(0); | |
192 #endif | |
193 | |
194 gfx::Rect edit_frame(rect); | |
195 edit_frame.set_x(icon_frame.right()); | |
196 int edit_frame_width = | |
197 rect.width() - icon_frame.width() - kPadding - menu_button_frame.width(); | |
198 if (!speech_button_frame.IsEmpty()) | |
199 edit_frame_width -= speech_button_frame.width() + kPadding; | |
200 edit_frame.set_width(edit_frame_width); | |
201 edit_frame.ClampToCenteredSize( | |
202 gfx::Size(edit_frame.width(), search_box_->GetPreferredSize().height())); | |
203 search_box_->SetBoundsRect(edit_frame); | |
204 } | |
205 | |
206 bool SearchBoxView::OnMouseWheel(const ui::MouseWheelEvent& event) { | 169 bool SearchBoxView::OnMouseWheel(const ui::MouseWheelEvent& event) { |
207 if (contents_view_) | 170 if (contents_view_) |
208 return contents_view_->OnMouseWheel(event); | 171 return contents_view_->OnMouseWheel(event); |
209 | 172 |
210 return false; | 173 return false; |
211 } | 174 } |
212 | 175 |
213 void SearchBoxView::UpdateModel() { | 176 void SearchBoxView::UpdateModel() { |
214 // Temporarily remove from observer to ignore notifications caused by us. | 177 // Temporarily remove from observer to ignore notifications caused by us. |
215 model_->search_box()->RemoveObserver(this); | 178 model_->search_box()->RemoveObserver(this); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
300 NotifyQueryChanged(); | 263 NotifyQueryChanged(); |
301 } | 264 } |
302 | 265 |
303 void SearchBoxView::OnSpeechRecognitionStateChanged( | 266 void SearchBoxView::OnSpeechRecognitionStateChanged( |
304 SpeechRecognitionState new_state) { | 267 SpeechRecognitionState new_state) { |
305 SpeechRecognitionButtonPropChanged(); | 268 SpeechRecognitionButtonPropChanged(); |
306 SchedulePaint(); | 269 SchedulePaint(); |
307 } | 270 } |
308 | 271 |
309 } // namespace app_list | 272 } // namespace app_list |
OLD | NEW |