| 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 "grit/ui_resources.h" | 9 #include "grit/ui_resources.h" |
| 10 #include "ui/app_list/search_box_model.h" | 10 #include "ui/app_list/search_box_model.h" |
| 11 #include "ui/app_list/search_box_view_delegate.h" | 11 #include "ui/app_list/search_box_view_delegate.h" |
| 12 #include "ui/app_list/views/app_list_menu_views.h" |
| 12 #include "ui/base/events/event.h" | 13 #include "ui/base/events/event.h" |
| 13 #include "ui/base/resource/resource_bundle.h" | 14 #include "ui/base/resource/resource_bundle.h" |
| 14 #include "ui/views/controls/button/menu_button.h" | 15 #include "ui/views/controls/button/menu_button.h" |
| 15 #include "ui/views/controls/image_view.h" | 16 #include "ui/views/controls/image_view.h" |
| 16 #include "ui/views/controls/textfield/textfield.h" | 17 #include "ui/views/controls/textfield/textfield.h" |
| 17 | 18 |
| 18 namespace app_list { | 19 namespace app_list { |
| 19 | 20 |
| 20 namespace { | 21 namespace { |
| 21 | 22 |
| 22 const int kPadding = 14; | 23 const int kPadding = 14; |
| 23 const int kIconDimension = 32; | 24 const int kIconDimension = 32; |
| 24 const int kPreferredWidth = 360; | 25 const int kPreferredWidth = 360; |
| 25 const int kPreferredHeight = 48; | 26 const int kPreferredHeight = 48; |
| 26 const int kMenuButtonDimension = 29; | 27 const int kMenuButtonDimension = 29; |
| 27 | 28 |
| 28 const SkColor kHintTextColor = SkColorSetRGB(0xA0, 0xA0, 0xA0); | 29 const SkColor kHintTextColor = SkColorSetRGB(0xA0, 0xA0, 0xA0); |
| 29 | 30 |
| 30 } // namespace | 31 } // namespace |
| 31 | 32 |
| 32 SearchBoxView::SearchBoxView(SearchBoxViewDelegate* delegate, | 33 SearchBoxView::SearchBoxView(SearchBoxViewDelegate* delegate) |
| 33 AppListViewDelegate* view_delegate) | |
| 34 : delegate_(delegate), | 34 : delegate_(delegate), |
| 35 model_(NULL), | 35 model_(NULL), |
| 36 menu_(view_delegate), | |
| 37 icon_view_(new views::ImageView), | 36 icon_view_(new views::ImageView), |
| 38 search_box_(new views::Textfield), | 37 search_box_(new views::Textfield), |
| 39 contents_view_(NULL) { | 38 contents_view_(NULL) { |
| 40 AddChildView(icon_view_); | 39 AddChildView(icon_view_); |
| 41 | 40 |
| 42 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 41 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 43 | 42 |
| 44 #if !defined(OS_CHROMEOS) | 43 #if !defined(OS_CHROMEOS) |
| 45 menu_button_ = new views::MenuButton(NULL, base::string16(), this, false); | 44 menu_button_ = new views::MenuButton(NULL, base::string16(), this, false); |
| 46 menu_button_->set_border(NULL); | 45 menu_button_->set_border(NULL); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 } | 82 } |
| 84 | 83 |
| 85 void SearchBoxView::ClearSearch() { | 84 void SearchBoxView::ClearSearch() { |
| 86 search_box_->SetText(base::string16()); | 85 search_box_->SetText(base::string16()); |
| 87 // Updates model and fires query changed manually because SetText() above | 86 // Updates model and fires query changed manually because SetText() above |
| 88 // does not generate ContentsChanged() notification. | 87 // does not generate ContentsChanged() notification. |
| 89 UpdateModel(); | 88 UpdateModel(); |
| 90 NotifyQueryChanged(); | 89 NotifyQueryChanged(); |
| 91 } | 90 } |
| 92 | 91 |
| 92 void SearchBoxView::UpdateMenu(AppListViewDelegate* view_delegate) { |
| 93 menu_.reset(new AppListMenuViews(view_delegate)); |
| 94 } |
| 95 |
| 93 gfx::Size SearchBoxView::GetPreferredSize() { | 96 gfx::Size SearchBoxView::GetPreferredSize() { |
| 94 return gfx::Size(kPreferredWidth, kPreferredHeight); | 97 return gfx::Size(kPreferredWidth, kPreferredHeight); |
| 95 } | 98 } |
| 96 | 99 |
| 97 void SearchBoxView::Layout() { | 100 void SearchBoxView::Layout() { |
| 98 gfx::Rect rect(GetContentsBounds()); | 101 gfx::Rect rect(GetContentsBounds()); |
| 99 if (rect.IsEmpty()) | 102 if (rect.IsEmpty()) |
| 100 return; | 103 return; |
| 101 | 104 |
| 102 gfx::Rect icon_frame(rect); | 105 gfx::Rect icon_frame(rect); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 bool SearchBoxView::HandleKeyEvent(views::Textfield* sender, | 155 bool SearchBoxView::HandleKeyEvent(views::Textfield* sender, |
| 153 const ui::KeyEvent& key_event) { | 156 const ui::KeyEvent& key_event) { |
| 154 bool handled = false; | 157 bool handled = false; |
| 155 if (contents_view_ && contents_view_->visible()) | 158 if (contents_view_ && contents_view_->visible()) |
| 156 handled = contents_view_->OnKeyPressed(key_event); | 159 handled = contents_view_->OnKeyPressed(key_event); |
| 157 | 160 |
| 158 return handled; | 161 return handled; |
| 159 } | 162 } |
| 160 | 163 |
| 161 void SearchBoxView::OnMenuButtonClicked(View* source, const gfx::Point& point) { | 164 void SearchBoxView::OnMenuButtonClicked(View* source, const gfx::Point& point) { |
| 162 menu_.RunMenuAt(menu_button_, | 165 menu_->RunMenuAt(menu_button_, |
| 163 menu_button_->GetBoundsInScreen().bottom_right()); | 166 menu_button_->GetBoundsInScreen().bottom_right()); |
| 164 } | 167 } |
| 165 | 168 |
| 166 void SearchBoxView::IconChanged() { | 169 void SearchBoxView::IconChanged() { |
| 167 icon_view_->SetImage(model_->icon()); | 170 icon_view_->SetImage(model_->icon()); |
| 168 } | 171 } |
| 169 | 172 |
| 170 void SearchBoxView::HintTextChanged() { | 173 void SearchBoxView::HintTextChanged() { |
| 171 search_box_->set_placeholder_text(model_->hint_text()); | 174 search_box_->set_placeholder_text(model_->hint_text()); |
| 172 } | 175 } |
| 173 | 176 |
| 174 void SearchBoxView::SelectionModelChanged() { | 177 void SearchBoxView::SelectionModelChanged() { |
| 175 search_box_->SelectSelectionModel(model_->selection_model()); | 178 search_box_->SelectSelectionModel(model_->selection_model()); |
| 176 } | 179 } |
| 177 | 180 |
| 178 void SearchBoxView::TextChanged() { | 181 void SearchBoxView::TextChanged() { |
| 179 search_box_->SetText(model_->text()); | 182 search_box_->SetText(model_->text()); |
| 180 } | 183 } |
| 181 | 184 |
| 182 } // namespace app_list | 185 } // namespace app_list |
| OLD | NEW |