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" |
11 #include "ui/app_list/app_list_switches.h" | 11 #include "ui/app_list/app_list_switches.h" |
12 #include "ui/app_list/app_list_view_delegate.h" | 12 #include "ui/app_list/app_list_view_delegate.h" |
13 #include "ui/app_list/search_box_model.h" | 13 #include "ui/app_list/search_box_model.h" |
14 #include "ui/app_list/speech_ui_model.h" | 14 #include "ui/app_list/speech_ui_model.h" |
15 #include "ui/app_list/views/app_list_menu_views.h" | 15 #include "ui/app_list/views/app_list_menu_views.h" |
| 16 #include "ui/app_list/views/contents_view.h" |
16 #include "ui/app_list/views/search_box_view_delegate.h" | 17 #include "ui/app_list/views/search_box_view_delegate.h" |
| 18 #include "ui/base/l10n/l10n_util.h" |
17 #include "ui/base/resource/resource_bundle.h" | 19 #include "ui/base/resource/resource_bundle.h" |
18 #include "ui/events/event.h" | 20 #include "ui/events/event.h" |
19 #include "ui/gfx/canvas.h" | 21 #include "ui/gfx/canvas.h" |
20 #include "ui/gfx/shadow_value.h" | 22 #include "ui/gfx/shadow_value.h" |
21 #include "ui/resources/grit/ui_resources.h" | 23 #include "ui/resources/grit/ui_resources.h" |
| 24 #include "ui/strings/grit/ui_strings.h" |
22 #include "ui/views/border.h" | 25 #include "ui/views/border.h" |
23 #include "ui/views/controls/button/image_button.h" | 26 #include "ui/views/controls/button/image_button.h" |
24 #include "ui/views/controls/button/menu_button.h" | 27 #include "ui/views/controls/button/menu_button.h" |
25 #include "ui/views/controls/image_view.h" | 28 #include "ui/views/controls/image_view.h" |
26 #include "ui/views/controls/textfield/textfield.h" | 29 #include "ui/views/controls/textfield/textfield.h" |
27 #include "ui/views/layout/box_layout.h" | 30 #include "ui/views/layout/box_layout.h" |
28 #include "ui/views/layout/fill_layout.h" | 31 #include "ui/views/layout/fill_layout.h" |
29 #include "ui/views/shadow_border.h" | 32 #include "ui/views/shadow_border.h" |
30 | 33 |
31 namespace app_list { | 34 namespace app_list { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 : ImageButton(listener), selected_(false) {} | 77 : ImageButton(listener), selected_(false) {} |
75 ~SearchBoxImageButton() override {} | 78 ~SearchBoxImageButton() override {} |
76 | 79 |
77 bool selected() { return selected_; } | 80 bool selected() { return selected_; } |
78 void SetSelected(bool selected) { | 81 void SetSelected(bool selected) { |
79 if (selected_ == selected) | 82 if (selected_ == selected) |
80 return; | 83 return; |
81 | 84 |
82 selected_ = selected; | 85 selected_ = selected; |
83 SchedulePaint(); | 86 SchedulePaint(); |
| 87 if (selected) |
| 88 NotifyAccessibilityEvent(ui::AX_EVENT_FOCUS, true); |
84 } | 89 } |
85 | 90 |
86 bool OnKeyPressed(const ui::KeyEvent& event) override { | 91 bool OnKeyPressed(const ui::KeyEvent& event) override { |
87 // Disable space key to press the button. The keyboard events received | 92 // Disable space key to press the button. The keyboard events received |
88 // by this view are forwarded from a Textfield (SearchBoxView) and key | 93 // by this view are forwarded from a Textfield (SearchBoxView) and key |
89 // released events are not forwarded. This leaves the button in pressed | 94 // released events are not forwarded. This leaves the button in pressed |
90 // state. | 95 // state. |
91 if (event.key_code() == ui::VKEY_SPACE) | 96 if (event.key_code() == ui::VKEY_SPACE) |
92 return false; | 97 return false; |
93 | 98 |
(...skipping 30 matching lines...) Expand all Loading... |
124 | 129 |
125 if (switches::IsExperimentalAppListEnabled()) { | 130 if (switches::IsExperimentalAppListEnabled()) { |
126 SetShadow(GetShadowForZHeight(2)); | 131 SetShadow(GetShadowForZHeight(2)); |
127 back_button_ = new SearchBoxImageButton(this); | 132 back_button_ = new SearchBoxImageButton(this); |
128 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 133 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
129 back_button_->SetImage( | 134 back_button_->SetImage( |
130 views::ImageButton::STATE_NORMAL, | 135 views::ImageButton::STATE_NORMAL, |
131 rb.GetImageSkiaNamed(IDR_APP_LIST_FOLDER_BACK_NORMAL)); | 136 rb.GetImageSkiaNamed(IDR_APP_LIST_FOLDER_BACK_NORMAL)); |
132 back_button_->SetImageAlignment(views::ImageButton::ALIGN_CENTER, | 137 back_button_->SetImageAlignment(views::ImageButton::ALIGN_CENTER, |
133 views::ImageButton::ALIGN_MIDDLE); | 138 views::ImageButton::ALIGN_MIDDLE); |
| 139 base::string16 back_title(l10n_util::GetStringUTF16(IDS_APP_LIST_BACK)); |
| 140 back_button_->SetAccessibleName(back_title); |
| 141 back_button_->SetTooltipText(back_title); |
134 content_container_->AddChildView(back_button_); | 142 content_container_->AddChildView(back_button_); |
135 | 143 |
136 content_container_->set_background(new ExperimentalSearchBoxBackground()); | 144 content_container_->set_background(new ExperimentalSearchBoxBackground()); |
137 } else { | 145 } else { |
138 set_background( | 146 set_background( |
139 views::Background::CreateSolidBackground(kSearchBoxBackground)); | 147 views::Background::CreateSolidBackground(kSearchBoxBackground)); |
140 SetBorder( | 148 SetBorder( |
141 views::Border::CreateSolidSidedBorder(0, 0, 1, 0, kTopSeparatorColor)); | 149 views::Border::CreateSolidSidedBorder(0, 0, 1, 0, kTopSeparatorColor)); |
142 icon_view_ = new views::ImageView; | 150 icon_view_ = new views::ImageView; |
143 content_container_->AddChildView(icon_view_); | 151 content_container_->AddChildView(icon_view_); |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 case FOCUS_CONTENTS_VIEW: | 260 case FOCUS_CONTENTS_VIEW: |
253 focused_view_ = move_backwards | 261 focused_view_ = move_backwards |
254 ? (speech_button_ && speech_button_->visible() ? | 262 ? (speech_button_ && speech_button_->visible() ? |
255 FOCUS_MIC_BUTTON : FOCUS_SEARCH_BOX) | 263 FOCUS_MIC_BUTTON : FOCUS_SEARCH_BOX) |
256 : FOCUS_CONTENTS_VIEW; | 264 : FOCUS_CONTENTS_VIEW; |
257 break; | 265 break; |
258 default: | 266 default: |
259 DCHECK(false); | 267 DCHECK(false); |
260 } | 268 } |
261 | 269 |
262 if (back_button_ && focused_view_ == FOCUS_BACK_BUTTON) | 270 switch (focused_view_) { |
263 back_button_->SetSelected(true); | 271 case FOCUS_BACK_BUTTON: |
264 if (speech_button_ && focused_view_ == FOCUS_MIC_BUTTON) | 272 if (back_button_) |
265 speech_button_->SetSelected(true); | 273 back_button_->SetSelected(true); |
| 274 break; |
| 275 case FOCUS_SEARCH_BOX: |
| 276 // Set the ChromeVox focus to the search box. However, DO NOT do this if |
| 277 // we are in the search results state (i.e., if the search box has text in |
| 278 // it), because the focus is about to be shifted to the first search |
| 279 // result and we do not want to read out the name of the search box as |
| 280 // well. |
| 281 if (search_box_->text().empty()) |
| 282 search_box_->NotifyAccessibilityEvent(ui::AX_EVENT_FOCUS, true); |
| 283 break; |
| 284 case FOCUS_MIC_BUTTON: |
| 285 if (speech_button_) |
| 286 speech_button_->SetSelected(true); |
| 287 break; |
| 288 default: |
| 289 break; |
| 290 } |
266 | 291 |
267 if (focused_view_ < FOCUS_CONTENTS_VIEW) | 292 if (focused_view_ < FOCUS_CONTENTS_VIEW) |
268 delegate_->SetSearchResultSelection(focused_view_ == FOCUS_SEARCH_BOX); | 293 delegate_->SetSearchResultSelection(focused_view_ == FOCUS_SEARCH_BOX); |
269 | 294 |
270 return (focused_view_ < FOCUS_CONTENTS_VIEW); | 295 return (focused_view_ < FOCUS_CONTENTS_VIEW); |
271 } | 296 } |
272 | 297 |
273 void SearchBoxView::ResetTabFocus(bool on_contents) { | 298 void SearchBoxView::ResetTabFocus(bool on_contents) { |
274 if (back_button_) | 299 if (back_button_) |
275 back_button_->SetSelected(false); | 300 back_button_->SetSelected(false); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 | 405 |
381 void SearchBoxView::SpeechRecognitionButtonPropChanged() { | 406 void SearchBoxView::SpeechRecognitionButtonPropChanged() { |
382 const SearchBoxModel::SpeechButtonProperty* speech_button_prop = | 407 const SearchBoxModel::SpeechButtonProperty* speech_button_prop = |
383 model_->search_box()->speech_button(); | 408 model_->search_box()->speech_button(); |
384 if (speech_button_prop) { | 409 if (speech_button_prop) { |
385 if (!speech_button_) { | 410 if (!speech_button_) { |
386 speech_button_ = new SearchBoxImageButton(this); | 411 speech_button_ = new SearchBoxImageButton(this); |
387 content_container_->AddChildView(speech_button_); | 412 content_container_->AddChildView(speech_button_); |
388 } | 413 } |
389 | 414 |
| 415 speech_button_->SetAccessibleName(speech_button_prop->accessible_name); |
390 if (view_delegate_->GetSpeechUI()->state() == | 416 if (view_delegate_->GetSpeechUI()->state() == |
391 SPEECH_RECOGNITION_HOTWORD_LISTENING) { | 417 SPEECH_RECOGNITION_HOTWORD_LISTENING) { |
392 speech_button_->SetImage( | 418 speech_button_->SetImage( |
393 views::Button::STATE_NORMAL, &speech_button_prop->on_icon); | 419 views::Button::STATE_NORMAL, &speech_button_prop->on_icon); |
394 speech_button_->SetTooltipText(speech_button_prop->on_tooltip); | 420 speech_button_->SetTooltipText(speech_button_prop->on_tooltip); |
395 } else { | 421 } else { |
396 speech_button_->SetImage( | 422 speech_button_->SetImage( |
397 views::Button::STATE_NORMAL, &speech_button_prop->off_icon); | 423 views::Button::STATE_NORMAL, &speech_button_prop->off_icon); |
398 speech_button_->SetTooltipText(speech_button_prop->off_tooltip); | 424 speech_button_->SetTooltipText(speech_button_prop->off_tooltip); |
399 } | 425 } |
(...skipping 22 matching lines...) Expand all Loading... |
422 NotifyQueryChanged(); | 448 NotifyQueryChanged(); |
423 } | 449 } |
424 | 450 |
425 void SearchBoxView::OnSpeechRecognitionStateChanged( | 451 void SearchBoxView::OnSpeechRecognitionStateChanged( |
426 SpeechRecognitionState new_state) { | 452 SpeechRecognitionState new_state) { |
427 SpeechRecognitionButtonPropChanged(); | 453 SpeechRecognitionButtonPropChanged(); |
428 SchedulePaint(); | 454 SchedulePaint(); |
429 } | 455 } |
430 | 456 |
431 } // namespace app_list | 457 } // namespace app_list |
OLD | NEW |