summaryrefslogtreecommitdiffstats
path: root/ui/app_list
diff options
context:
space:
mode:
authormukai@chromium.org <mukai@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-13 21:11:04 +0000
committermukai@chromium.org <mukai@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-13 21:11:04 +0000
commitf016174aae0c998630521484063ea5c8808e1203 (patch)
tree6ef81a89283c38a5bc7e7ee31e236f36e5647792 /ui/app_list
parentba1821ceea9c8c40b15c80d62463b57ed2612cad (diff)
downloadchromium_src-f016174aae0c998630521484063ea5c8808e1203.zip
chromium_src-f016174aae0c998630521484063ea5c8808e1203.tar.gz
chromium_src-f016174aae0c998630521484063ea5c8808e1203.tar.bz2
Adds the speech recognition button to the app-list searchbox.
BUG=313904 R=xiyuan@chromium.org TBR=jamescook@chromium.org TEST=manually Review URL: https://codereview.chromium.org/69813002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@234902 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/app_list')
-rw-r--r--ui/app_list/app_list_view_delegate.h3
-rw-r--r--ui/app_list/cocoa/apps_search_box_controller.mm13
-rw-r--r--ui/app_list/search_box_model.cc28
-rw-r--r--ui/app_list/search_box_model.h27
-rw-r--r--ui/app_list/search_box_model_observer.h7
-rw-r--r--ui/app_list/test/app_list_test_view_delegate.h1
-rw-r--r--ui/app_list/views/search_box_view.cc58
-rw-r--r--ui/app_list/views/search_box_view.h9
8 files changed, 143 insertions, 3 deletions
diff --git a/ui/app_list/app_list_view_delegate.h b/ui/app_list/app_list_view_delegate.h
index 4a217db..563afc4 100644
--- a/ui/app_list/app_list_view_delegate.h
+++ b/ui/app_list/app_list_view_delegate.h
@@ -115,6 +115,9 @@ class APP_LIST_EXPORT AppListViewDelegate {
// Open the feedback UI.
virtual void OpenFeedback() = 0;
+ // Invoked to toggle the status of speech recognition.
+ virtual void ToggleSpeechRecognition() = 0;
+
// Shows the app list for the profile specified by |profile_path|.
virtual void ShowForProfileByPath(const base::FilePath& profile_path) = 0;
diff --git a/ui/app_list/cocoa/apps_search_box_controller.mm b/ui/app_list/cocoa/apps_search_box_controller.mm
index 93a96cb..1ef31e3 100644
--- a/ui/app_list/cocoa/apps_search_box_controller.mm
+++ b/ui/app_list/cocoa/apps_search_box_controller.mm
@@ -53,6 +53,8 @@ class SearchBoxModelObserverBridge : public SearchBoxModelObserver {
void SetSearchText(const base::string16& text);
virtual void IconChanged() OVERRIDE;
+ virtual void SpeechRecognitionButtonPropChanged() OVERRIDE;
+ virtual void SetSpeechRecognitionButtonState(bool toggled) OVERRIDE;
virtual void HintTextChanged() OVERRIDE;
virtual void SelectionModelChanged() OVERRIDE;
virtual void TextChanged() OVERRIDE;
@@ -96,6 +98,17 @@ void SearchBoxModelObserverBridge::IconChanged() {
GetModel()->icon(), base::mac::GetSRGBColorSpace())];
}
+void SearchBoxModelObserverBridge::SpeechRecognitionButtonPropChanged() {
+ // TODO(mukai): implement.
+ NOTIMPLEMENTED();
+}
+
+void SearchBoxModelObserverBridge::SetSpeechRecognitionButtonState(
+ bool toggled) {
+ // TODO(mukai): implement.
+ NOTIMPLEMENTED();
+}
+
void SearchBoxModelObserverBridge::HintTextChanged() {
[[[parent_ searchTextField] cell] setPlaceholderString:
base::SysUTF16ToNSString(GetModel()->hint_text())];
diff --git a/ui/app_list/search_box_model.cc b/ui/app_list/search_box_model.cc
index 5130e50..d84b33c 100644
--- a/ui/app_list/search_box_model.cc
+++ b/ui/app_list/search_box_model.cc
@@ -9,6 +9,20 @@
namespace app_list {
+SearchBoxModel::ToggleButtonProperty::ToggleButtonProperty(
+ const gfx::ImageSkia& icon,
+ const gfx::ImageSkia& toggled_icon,
+ const base::string16& tooltip,
+ const base::string16& toggled_tooltip)
+ : icon(icon),
+ toggled_icon(toggled_icon),
+ tooltip(tooltip),
+ toggled_tooltip(toggled_tooltip) {
+}
+
+SearchBoxModel::ToggleButtonProperty::~ToggleButtonProperty() {
+}
+
SearchBoxModel::SearchBoxModel() {
}
@@ -20,6 +34,20 @@ void SearchBoxModel::SetIcon(const gfx::ImageSkia& icon) {
FOR_EACH_OBSERVER(SearchBoxModelObserver, observers_, IconChanged());
}
+void SearchBoxModel::SetSpeechRecognitionButton(
+ scoped_ptr<SearchBoxModel::ToggleButtonProperty> speech_button) {
+ speech_button_ = speech_button.Pass();
+ FOR_EACH_OBSERVER(SearchBoxModelObserver,
+ observers_,
+ SpeechRecognitionButtonPropChanged());
+}
+
+void SearchBoxModel::SetSpeechRecognitionButtonState(bool toggled) {
+ FOR_EACH_OBSERVER(SearchBoxModelObserver,
+ observers_,
+ SetSpeechRecognitionButtonState(toggled));
+}
+
void SearchBoxModel::SetHintText(const base::string16& hint_text) {
if (hint_text_ == hint_text)
return;
diff --git a/ui/app_list/search_box_model.h b/ui/app_list/search_box_model.h
index 764281f..4cb0b41 100644
--- a/ui/app_list/search_box_model.h
+++ b/ui/app_list/search_box_model.h
@@ -23,13 +23,37 @@ class SearchBoxModelObserver;
// text, cursor position and selected text in edit control.
class APP_LIST_EXPORT SearchBoxModel {
public:
+ // The properties of the button with toggled status.
+ struct APP_LIST_EXPORT ToggleButtonProperty {
+ ToggleButtonProperty(const gfx::ImageSkia& icon,
+ const gfx::ImageSkia& toggled_icon,
+ const base::string16& tooltip,
+ const base::string16& toggled_tooltip);
+ ~ToggleButtonProperty();
+
+ gfx::ImageSkia icon;
+ gfx::ImageSkia toggled_icon;
+ base::string16 tooltip;
+ base::string16 toggled_tooltip;
+ };
+
SearchBoxModel();
~SearchBoxModel();
- // Sets/gets the icon on side of edit box.
+ // Sets/gets the icon on the left side of edit box.
void SetIcon(const gfx::ImageSkia& icon);
const gfx::ImageSkia& icon() const { return icon_; }
+ // Sets/gets the properties for the button of speech recognition.
+ void SetSpeechRecognitionButton(
+ scoped_ptr<ToggleButtonProperty> speech_button);
+ const ToggleButtonProperty* speech_button() const {
+ return speech_button_.get();
+ }
+
+ // Sets the speech recognition button state.
+ void SetSpeechRecognitionButtonState(bool toggled);
+
// Sets/gets the hint text to display when there is in input.
void SetHintText(const base::string16& hint_text);
const base::string16& hint_text() const { return hint_text_; }
@@ -49,6 +73,7 @@ class APP_LIST_EXPORT SearchBoxModel {
private:
gfx::ImageSkia icon_;
+ scoped_ptr<ToggleButtonProperty> speech_button_;
base::string16 hint_text_;
gfx::SelectionModel selection_model_;
base::string16 text_;
diff --git a/ui/app_list/search_box_model_observer.h b/ui/app_list/search_box_model_observer.h
index b4cc40c..189d452 100644
--- a/ui/app_list/search_box_model_observer.h
+++ b/ui/app_list/search_box_model_observer.h
@@ -14,6 +14,13 @@ class APP_LIST_EXPORT SearchBoxModelObserver {
// Invoked when icon is changed.
virtual void IconChanged() = 0;
+ // Invoked when the some properties of the speech recognition button is
+ // changed.
+ virtual void SpeechRecognitionButtonPropChanged() = 0;
+
+ // Invoked when the speech recognition button state is changed.
+ virtual void SetSpeechRecognitionButtonState(bool toggled) = 0;
+
// Invoked when hint text is changed.
virtual void HintTextChanged() = 0;
diff --git a/ui/app_list/test/app_list_test_view_delegate.h b/ui/app_list/test/app_list_test_view_delegate.h
index cffcdacd..9f1bacd 100644
--- a/ui/app_list/test/app_list_test_view_delegate.h
+++ b/ui/app_list/test/app_list_test_view_delegate.h
@@ -48,6 +48,7 @@ class AppListTestViewDelegate : public AppListViewDelegate {
virtual void OpenSettings() OVERRIDE {}
virtual void OpenHelp() OVERRIDE {}
virtual void OpenFeedback() OVERRIDE {}
+ virtual void ToggleSpeechRecognition() OVERRIDE {}
virtual void ShowForProfileByPath(
const base::FilePath& profile_path) OVERRIDE {};
virtual content::WebContents* GetStartPageContents() OVERRIDE;
diff --git a/ui/app_list/views/search_box_view.cc b/ui/app_list/views/search_box_view.cc
index ad0e2c5..ba40bf3 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());
}
diff --git a/ui/app_list/views/search_box_view.h b/ui/app_list/views/search_box_view.h
index c069902..ad12ede 100644
--- a/ui/app_list/views/search_box_view.h
+++ b/ui/app_list/views/search_box_view.h
@@ -8,6 +8,7 @@
#include <string>
#include "ui/app_list/search_box_model_observer.h"
+#include "ui/views/controls/button/image_button.h"
#include "ui/views/controls/button/menu_button_listener.h"
#include "ui/views/controls/textfield/textfield_controller.h"
#include "ui/views/view.h"
@@ -32,6 +33,7 @@ class SearchBoxViewDelegate;
// contents and selection model of the Textfield.
class SearchBoxView : public views::View,
public views::TextfieldController,
+ public views::ButtonListener,
public views::MenuButtonListener,
public SearchBoxModelObserver {
public:
@@ -68,12 +70,18 @@ class SearchBoxView : public views::View,
virtual bool HandleKeyEvent(views::Textfield* sender,
const ui::KeyEvent& key_event) OVERRIDE;
+ // Overridden from views::ButtonListener:
+ virtual void ButtonPressed(views::Button* sender,
+ const ui::Event& event) OVERRIDE;
+
// Overridden from views::MenuButtonListener:
virtual void OnMenuButtonClicked(View* source,
const gfx::Point& point) OVERRIDE;
// Overridden from SearchBoxModelObserver:
virtual void IconChanged() OVERRIDE;
+ virtual void SpeechRecognitionButtonPropChanged() OVERRIDE;
+ virtual void SetSpeechRecognitionButtonState(bool toggled) OVERRIDE;
virtual void HintTextChanged() OVERRIDE;
virtual void SelectionModelChanged() OVERRIDE;
virtual void TextChanged() OVERRIDE;
@@ -85,6 +93,7 @@ class SearchBoxView : public views::View,
scoped_ptr<AppListMenuViews> menu_;
views::ImageView* icon_view_; // Owned by views hierarchy.
+ views::ToggleImageButton* speech_button_; // Owned by views hierarchy.
views::MenuButton* menu_button_; // Owned by views hierarchy.
views::Textfield* search_box_; // Owned by views hierarchy.
views::View* contents_view_; // Owned by views hierarchy.