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_constants.h" | 9 #include "ui/app_list/app_list_constants.h" |
10 #include "ui/app_list/app_list_model.h" | 10 #include "ui/app_list/app_list_model.h" |
(...skipping 25 matching lines...) Expand all Loading... | |
36 const int kPreferredHeight = 48; | 36 const int kPreferredHeight = 48; |
37 | 37 |
38 const SkColor kHintTextColor = SkColorSetRGB(0xA0, 0xA0, 0xA0); | 38 const SkColor kHintTextColor = SkColorSetRGB(0xA0, 0xA0, 0xA0); |
39 | 39 |
40 // Menu offset relative to the bottom-right corner of the menu button. | 40 // Menu offset relative to the bottom-right corner of the menu button. |
41 const int kMenuYOffsetFromButton = -4; | 41 const int kMenuYOffsetFromButton = -4; |
42 const int kMenuXOffsetFromButton = -7; | 42 const int kMenuXOffsetFromButton = -7; |
43 | 43 |
44 const int kBackgroundBorderCornerRadius = 2; | 44 const int kBackgroundBorderCornerRadius = 2; |
45 | 45 |
46 const int kShadowBlur = 4; | |
47 const int kShadowYOffset = 2; | |
48 const SkColor kShadowColor = SkColorSetARGB(0x33, 0, 0, 0); | |
49 | |
50 // A background that paints a solid white rounded rect with a thin grey border. | 46 // A background that paints a solid white rounded rect with a thin grey border. |
51 class ExperimentalSearchBoxBackground : public views::Background { | 47 class ExperimentalSearchBoxBackground : public views::Background { |
52 public: | 48 public: |
53 ExperimentalSearchBoxBackground() {} | 49 ExperimentalSearchBoxBackground() {} |
54 ~ExperimentalSearchBoxBackground() override {} | 50 ~ExperimentalSearchBoxBackground() override {} |
55 | 51 |
56 private: | 52 private: |
57 // views::Background overrides: | 53 // views::Background overrides: |
58 void Paint(gfx::Canvas* canvas, views::View* view) const override { | 54 void Paint(gfx::Canvas* canvas, views::View* view) const override { |
59 gfx::Rect bounds = view->GetContentsBounds(); | 55 gfx::Rect bounds = view->GetContentsBounds(); |
(...skipping 18 matching lines...) Expand all Loading... | |
78 icon_view_(NULL), | 74 icon_view_(NULL), |
79 back_button_(NULL), | 75 back_button_(NULL), |
80 speech_button_(NULL), | 76 speech_button_(NULL), |
81 menu_button_(NULL), | 77 menu_button_(NULL), |
82 search_box_(new views::Textfield), | 78 search_box_(new views::Textfield), |
83 contents_view_(NULL) { | 79 contents_view_(NULL) { |
84 SetLayoutManager(new views::FillLayout); | 80 SetLayoutManager(new views::FillLayout); |
85 AddChildView(content_container_); | 81 AddChildView(content_container_); |
86 | 82 |
87 if (switches::IsExperimentalAppListEnabled()) { | 83 if (switches::IsExperimentalAppListEnabled()) { |
88 SetBorder(make_scoped_ptr( | 84 SetShadow(GetShadowForZHeight(1)); |
89 new views::ShadowBorder(kShadowBlur, kShadowColor, kShadowYOffset, 0))); | |
90 back_button_ = new views::ImageButton(this); | 85 back_button_ = new views::ImageButton(this); |
91 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 86 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
92 back_button_->SetImage( | 87 back_button_->SetImage( |
93 views::ImageButton::STATE_NORMAL, | 88 views::ImageButton::STATE_NORMAL, |
94 rb.GetImageSkiaNamed(IDR_APP_LIST_FOLDER_BACK_NORMAL)); | 89 rb.GetImageSkiaNamed(IDR_APP_LIST_FOLDER_BACK_NORMAL)); |
95 back_button_->SetImageAlignment(views::ImageButton::ALIGN_CENTER, | 90 back_button_->SetImageAlignment(views::ImageButton::ALIGN_CENTER, |
96 views::ImageButton::ALIGN_MIDDLE); | 91 views::ImageButton::ALIGN_MIDDLE); |
97 content_container_->AddChildView(back_button_); | 92 content_container_->AddChildView(back_button_); |
98 | 93 |
99 content_container_->set_background(new ExperimentalSearchBoxBackground()); | 94 content_container_->set_background(new ExperimentalSearchBoxBackground()); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
168 // Updates model and fires query changed manually because SetText() above | 163 // Updates model and fires query changed manually because SetText() above |
169 // does not generate ContentsChanged() notification. | 164 // does not generate ContentsChanged() notification. |
170 UpdateModel(); | 165 UpdateModel(); |
171 NotifyQueryChanged(); | 166 NotifyQueryChanged(); |
172 } | 167 } |
173 | 168 |
174 void SearchBoxView::InvalidateMenu() { | 169 void SearchBoxView::InvalidateMenu() { |
175 menu_.reset(); | 170 menu_.reset(); |
176 } | 171 } |
177 | 172 |
173 void SearchBoxView::SetShadow(const gfx::ShadowValue& shadow) { | |
174 SetBorder(make_scoped_ptr(new views::ShadowBorder(shadow))); | |
175 Layout(); | |
176 } | |
177 | |
178 gfx::Rect SearchBoxView::GetViewBoundsForSearchBoxContentsBounds( | 178 gfx::Rect SearchBoxView::GetViewBoundsForSearchBoxContentsBounds( |
179 const gfx::Rect& rect) const { | 179 const gfx::Rect& rect) const { |
180 gfx::Rect view_bounds = rect; | 180 gfx::Rect view_bounds = rect; |
181 view_bounds.Inset(GetInsets().Scale(-1)); | 181 view_bounds.Inset(-GetInsets()); |
182 return view_bounds; | 182 return view_bounds; |
183 } | 183 } |
184 | 184 |
185 gfx::Size SearchBoxView::GetPreferredSize() const { | 185 gfx::Size SearchBoxView::GetPreferredSize() const { |
186 return gfx::Size(kPreferredWidth, kPreferredHeight); | 186 return gfx::Size(kPreferredWidth, kPreferredHeight); |
187 } | 187 } |
188 | 188 |
189 bool SearchBoxView::OnMouseWheel(const ui::MouseWheelEvent& event) { | 189 bool SearchBoxView::OnMouseWheel(const ui::MouseWheelEvent& event) { |
190 if (contents_view_) | 190 if (contents_view_) |
191 return contents_view_->OnMouseWheel(event); | 191 return contents_view_->OnMouseWheel(event); |
192 | 192 |
193 return false; | 193 return false; |
194 } | 194 } |
195 | 195 |
196 void SearchBoxView::OnEnabledChanged() { | 196 void SearchBoxView::OnEnabledChanged() { |
197 search_box_->SetEnabled(enabled()); | 197 search_box_->SetEnabled(enabled()); |
198 if (menu_button_) | 198 if (menu_button_) |
199 menu_button_->SetEnabled(enabled()); | 199 menu_button_->SetEnabled(enabled()); |
200 if (speech_button_) | 200 if (speech_button_) |
201 speech_button_->SetEnabled(enabled()); | 201 speech_button_->SetEnabled(enabled()); |
202 } | 202 } |
203 | 203 |
204 // static | |
205 gfx::ShadowValue SearchBoxView::GetShadowForZHeight(int z_height) { | |
206 if (z_height <= 0) | |
207 return gfx::ShadowValue(); | |
208 | |
209 if (z_height == 1) { | |
Matt Giuca
2015/02/06 04:32:27
How about
switch (z_height) {
case 1:
case 2:
calamity
2015/02/06 05:17:51
Kay.
| |
210 return gfx::ShadowValue(gfx::Point(0, kCardShadowYOffset), kCardShadowBlur, | |
211 kCardShadowColor); | |
212 } | |
213 | |
214 if (z_height == 2) | |
215 return gfx::ShadowValue(gfx::Point(0, 2), 4, SkColorSetARGB(0x33, 0, 0, 0)); | |
Matt Giuca
2015/02/06 04:32:27
Without going all the way of defining new constant
calamity
2015/02/06 05:17:51
I don't think this necessarily a good idea. How ab
Matt Giuca
2015/02/06 05:42:18
OK move it to app_list_constants and then it's jus
| |
216 | |
217 return gfx::ShadowValue(gfx::Point(0, 8), 12, SkColorSetARGB(0x3F, 0, 0, 0)); | |
Matt Giuca
2015/02/06 04:32:27
Is this ever used?
calamity
2015/02/06 05:17:51
Nope. It's the 'touch' one in the mocks. I guess w
Matt Giuca
2015/02/06 05:42:18
If it's moved to ALC, then just leave this here.
| |
218 } | |
219 | |
204 void SearchBoxView::UpdateModel() { | 220 void SearchBoxView::UpdateModel() { |
205 // Temporarily remove from observer to ignore notifications caused by us. | 221 // Temporarily remove from observer to ignore notifications caused by us. |
206 model_->search_box()->RemoveObserver(this); | 222 model_->search_box()->RemoveObserver(this); |
207 model_->search_box()->SetText(search_box_->text()); | 223 model_->search_box()->SetText(search_box_->text()); |
208 model_->search_box()->SetSelectionModel(search_box_->GetSelectionModel()); | 224 model_->search_box()->SetSelectionModel(search_box_->GetSelectionModel()); |
209 model_->search_box()->AddObserver(this); | 225 model_->search_box()->AddObserver(this); |
210 } | 226 } |
211 | 227 |
212 void SearchBoxView::NotifyQueryChanged() { | 228 void SearchBoxView::NotifyQueryChanged() { |
213 DCHECK(delegate_); | 229 DCHECK(delegate_); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
304 NotifyQueryChanged(); | 320 NotifyQueryChanged(); |
305 } | 321 } |
306 | 322 |
307 void SearchBoxView::OnSpeechRecognitionStateChanged( | 323 void SearchBoxView::OnSpeechRecognitionStateChanged( |
308 SpeechRecognitionState new_state) { | 324 SpeechRecognitionState new_state) { |
309 SpeechRecognitionButtonPropChanged(); | 325 SpeechRecognitionButtonPropChanged(); |
310 SchedulePaint(); | 326 SchedulePaint(); |
311 } | 327 } |
312 | 328 |
313 } // namespace app_list | 329 } // namespace app_list |
OLD | NEW |