Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(111)

Unified Diff: ui/app_list/views/search_box_view.cc

Issue 69813002: Adds the speech recognition button to the app-list searchbox. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix win Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/app_list/views/search_box_view.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/app_list/views/search_box_view.cc
diff --git a/ui/app_list/views/search_box_view.cc b/ui/app_list/views/search_box_view.cc
index ad0e2c56be667a3e90d5e4930fc13b141afbaab2..ba40bf3b5f346c5bac1621c84b4ecafd3abdb9f5 100644
--- a/ui/app_list/views/search_box_view.cc
+++ b/ui/app_list/views/search_box_view.cc
@@ -8,11 +8,14 @@
#include "grit/ui_resources.h"
#include "ui/app_list/app_list_model.h"
+#include "ui/app_list/app_list_view_delegate.h"
#include "ui/app_list/search_box_model.h"
#include "ui/app_list/views/app_list_menu_views.h"
#include "ui/app_list/views/search_box_view_delegate.h"
+#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/events/event.h"
+#include "ui/views/controls/button/image_button.h"
#include "ui/views/controls/button/menu_button.h"
#include "ui/views/controls/image_view.h"
#include "ui/views/controls/textfield/textfield.h"
@@ -44,6 +47,7 @@ SearchBoxView::SearchBoxView(SearchBoxViewDelegate* delegate,
view_delegate_(view_delegate),
model_(model),
icon_view_(new views::ImageView),
+ speech_button_(NULL),
search_box_(new views::Textfield),
contents_view_(NULL) {
DCHECK(model_);
@@ -69,6 +73,7 @@ SearchBoxView::SearchBoxView(SearchBoxViewDelegate* delegate,
model_->search_box()->AddObserver(this);
IconChanged();
+ SpeechRecognitionButtonPropChanged();
HintTextChanged();
}
@@ -105,6 +110,18 @@ void SearchBoxView::Layout() {
icon_frame.set_width(kIconDimension + 2 * kPadding);
icon_view_->SetBoundsRect(icon_frame);
+ // Places |speech_button_| if exists. |speech_button_frame| holds its bounds
+ // to calculate the search box bounds.
+ gfx::Rect speech_button_frame;
+ if (speech_button_) {
+ speech_button_frame = icon_frame;
+ speech_button_frame.set_x(rect.right() - icon_frame.width());
+ gfx::Size button_size = speech_button_->GetPreferredSize();
+ gfx::Point button_origin = speech_button_frame.CenterPoint();
+ button_origin.Offset(-button_size.width() / 2, -button_size.height() / 2);
+ speech_button_->SetBoundsRect(gfx::Rect(button_origin, button_size));
+ }
+
gfx::Rect menu_button_frame(rect);
#if !defined(OS_CHROMEOS)
menu_button_frame.set_width(kMenuButtonDimension);
@@ -118,8 +135,11 @@ void SearchBoxView::Layout() {
gfx::Rect edit_frame(rect);
edit_frame.set_x(icon_frame.right());
- edit_frame.set_width(
- rect.width() - icon_frame.width() - kPadding - menu_button_frame.width());
+ int edit_frame_width =
+ rect.width() - icon_frame.width() - kPadding - menu_button_frame.width();
+ if (!speech_button_frame.IsEmpty())
+ edit_frame_width -= speech_button_frame.width() + kPadding;
+ edit_frame.set_width(edit_frame_width);
edit_frame.ClampToCenteredSize(
gfx::Size(edit_frame.width(), search_box_->GetPreferredSize().height()));
search_box_->SetBoundsRect(edit_frame);
@@ -160,6 +180,12 @@ bool SearchBoxView::HandleKeyEvent(views::Textfield* sender,
return handled;
}
+void SearchBoxView::ButtonPressed(views::Button* sender,
+ const ui::Event& event) {
+ DCHECK(!speech_button_ && sender == speech_button_);
+ view_delegate_->ToggleSpeechRecognition();
+}
+
void SearchBoxView::OnMenuButtonClicked(View* source, const gfx::Point& point) {
if (!menu_)
menu_.reset(new AppListMenuViews(view_delegate_));
@@ -174,6 +200,34 @@ void SearchBoxView::IconChanged() {
icon_view_->SetImage(model_->search_box()->icon());
}
+void SearchBoxView::SpeechRecognitionButtonPropChanged() {
+ const SearchBoxModel::ToggleButtonProperty* speech_button_prop =
+ model_->search_box()->speech_button();
+ if (speech_button_prop) {
+ if (!speech_button_) {
+ speech_button_ = new views::ToggleImageButton(this);
+ AddChildView(speech_button_);
+ }
+ speech_button_->SetImage(views::Button::STATE_NORMAL,
+ &speech_button_prop->icon);
+ speech_button_->SetToggledImage(views::Button::STATE_NORMAL,
+ &speech_button_prop->toggled_icon);
+ speech_button_->SetTooltipText(speech_button_prop->tooltip);
+ speech_button_->SetToggledTooltipText(speech_button_prop->toggled_tooltip);
+ } else {
+ if (speech_button_) {
+ // Deleting a view will detach it from its parent.
+ delete speech_button_;
+ speech_button_ = NULL;
+ }
+ }
+}
+
+void SearchBoxView::SetSpeechRecognitionButtonState(bool toggled) {
+ if (speech_button_)
+ speech_button_->SetToggled(toggled);
+}
+
void SearchBoxView::HintTextChanged() {
search_box_->set_placeholder_text(model_->search_box()->hint_text());
}
« no previous file with comments | « ui/app_list/views/search_box_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698