| 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..cdffbe809f4862544e377a0e266350287c700634 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),
|
| + right_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();
|
| + RightButtonPropChanged();
|
| HintTextChanged();
|
| }
|
|
|
| @@ -105,6 +110,17 @@ void SearchBoxView::Layout() {
|
| icon_frame.set_width(kIconDimension + 2 * kPadding);
|
| icon_view_->SetBoundsRect(icon_frame);
|
|
|
| + // Empty if right icon doesn't exist.
|
| + gfx::Rect right_button_frame;
|
| + if (right_button_) {
|
| + right_button_frame = icon_frame;
|
| + right_button_frame.set_x(rect.right() - icon_frame.width());
|
| + gfx::Size button_size = right_button_->GetPreferredSize();
|
| + gfx::Point button_origin = right_button_frame.CenterPoint();
|
| + button_origin.Offset(-button_size.width() / 2, -button_size.height() / 2);
|
| + right_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 +134,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 (!right_button_frame.IsEmpty())
|
| + edit_frame_width -= right_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 +179,12 @@ bool SearchBoxView::HandleKeyEvent(views::Textfield* sender,
|
| return handled;
|
| }
|
|
|
| +void SearchBoxView::ButtonPressed(views::Button* sender,
|
| + const ui::Event& event) {
|
| + DCHECK(!right_button_ && sender == right_button_);
|
| + view_delegate_->OnRightButtonClicked();
|
| +}
|
| +
|
| void SearchBoxView::OnMenuButtonClicked(View* source, const gfx::Point& point) {
|
| if (!menu_)
|
| menu_.reset(new AppListMenuViews(view_delegate_));
|
| @@ -174,6 +199,34 @@ void SearchBoxView::IconChanged() {
|
| icon_view_->SetImage(model_->search_box()->icon());
|
| }
|
|
|
| +void SearchBoxView::RightButtonPropChanged() {
|
| + const SearchBoxModel::RightButtonProperty* right_button_prop =
|
| + model_->search_box()->right_button();
|
| + if (right_button_prop) {
|
| + if (!right_button_) {
|
| + right_button_ = new views::ToggleImageButton(this);
|
| + AddChildView(right_button_);
|
| + }
|
| + right_button_->SetImage(views::Button::STATE_NORMAL,
|
| + &right_button_prop->icon);
|
| + right_button_->SetToggledImage(views::Button::STATE_NORMAL,
|
| + &right_button_prop->toggled_icon);
|
| + right_button_->SetTooltipText(right_button_prop->tooltip);
|
| + right_button_->SetToggledTooltipText(right_button_prop->toggled_tooltip);
|
| + } else {
|
| + if (right_button_) {
|
| + // Deleting a view will detach it from its parent.
|
| + delete right_button_;
|
| + right_button_ = NULL;
|
| + }
|
| + }
|
| +}
|
| +
|
| +void SearchBoxView::RightButtonStateChanged(bool toggled) {
|
| + if (right_button_)
|
| + right_button_->SetToggled(toggled);
|
| +}
|
| +
|
| void SearchBoxView::HintTextChanged() {
|
| search_box_->set_placeholder_text(model_->search_box()->hint_text());
|
| }
|
|
|