| 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 AppListViewDelegate* view_delegate) |
| 34 : delegate_(delegate), | 35 : delegate_(delegate), |
| 36 view_delegate_(view_delegate), |
| 35 model_(NULL), | 37 model_(NULL), |
| 36 menu_(view_delegate), | |
| 37 icon_view_(new views::ImageView), | 38 icon_view_(new views::ImageView), |
| 38 search_box_(new views::Textfield), | 39 search_box_(new views::Textfield), |
| 39 contents_view_(NULL) { | 40 contents_view_(NULL) { |
| 40 AddChildView(icon_view_); | 41 AddChildView(icon_view_); |
| 41 | 42 |
| 42 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 43 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 43 | 44 |
| 44 #if !defined(OS_CHROMEOS) | 45 #if !defined(OS_CHROMEOS) |
| 45 menu_button_ = new views::MenuButton(NULL, base::string16(), this, false); | 46 menu_button_ = new views::MenuButton(NULL, base::string16(), this, false); |
| 46 menu_button_->set_border(NULL); | 47 menu_button_->set_border(NULL); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 } | 84 } |
| 84 | 85 |
| 85 void SearchBoxView::ClearSearch() { | 86 void SearchBoxView::ClearSearch() { |
| 86 search_box_->SetText(base::string16()); | 87 search_box_->SetText(base::string16()); |
| 87 // Updates model and fires query changed manually because SetText() above | 88 // Updates model and fires query changed manually because SetText() above |
| 88 // does not generate ContentsChanged() notification. | 89 // does not generate ContentsChanged() notification. |
| 89 UpdateModel(); | 90 UpdateModel(); |
| 90 NotifyQueryChanged(); | 91 NotifyQueryChanged(); |
| 91 } | 92 } |
| 92 | 93 |
| 94 void SearchBoxView::InvalidateMenu() { |
| 95 menu_.reset(); |
| 96 } |
| 97 |
| 93 gfx::Size SearchBoxView::GetPreferredSize() { | 98 gfx::Size SearchBoxView::GetPreferredSize() { |
| 94 return gfx::Size(kPreferredWidth, kPreferredHeight); | 99 return gfx::Size(kPreferredWidth, kPreferredHeight); |
| 95 } | 100 } |
| 96 | 101 |
| 97 void SearchBoxView::Layout() { | 102 void SearchBoxView::Layout() { |
| 98 gfx::Rect rect(GetContentsBounds()); | 103 gfx::Rect rect(GetContentsBounds()); |
| 99 if (rect.IsEmpty()) | 104 if (rect.IsEmpty()) |
| 100 return; | 105 return; |
| 101 | 106 |
| 102 gfx::Rect icon_frame(rect); | 107 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, | 157 bool SearchBoxView::HandleKeyEvent(views::Textfield* sender, |
| 153 const ui::KeyEvent& key_event) { | 158 const ui::KeyEvent& key_event) { |
| 154 bool handled = false; | 159 bool handled = false; |
| 155 if (contents_view_ && contents_view_->visible()) | 160 if (contents_view_ && contents_view_->visible()) |
| 156 handled = contents_view_->OnKeyPressed(key_event); | 161 handled = contents_view_->OnKeyPressed(key_event); |
| 157 | 162 |
| 158 return handled; | 163 return handled; |
| 159 } | 164 } |
| 160 | 165 |
| 161 void SearchBoxView::OnMenuButtonClicked(View* source, const gfx::Point& point) { | 166 void SearchBoxView::OnMenuButtonClicked(View* source, const gfx::Point& point) { |
| 162 menu_.RunMenuAt(menu_button_, | 167 if (!menu_) |
| 163 menu_button_->GetBoundsInScreen().bottom_right()); | 168 menu_.reset(new AppListMenuViews(view_delegate_)); |
| 169 |
| 170 menu_->RunMenuAt(menu_button_, |
| 171 menu_button_->GetBoundsInScreen().bottom_right()); |
| 164 } | 172 } |
| 165 | 173 |
| 166 void SearchBoxView::IconChanged() { | 174 void SearchBoxView::IconChanged() { |
| 167 icon_view_->SetImage(model_->icon()); | 175 icon_view_->SetImage(model_->icon()); |
| 168 } | 176 } |
| 169 | 177 |
| 170 void SearchBoxView::HintTextChanged() { | 178 void SearchBoxView::HintTextChanged() { |
| 171 search_box_->set_placeholder_text(model_->hint_text()); | 179 search_box_->set_placeholder_text(model_->hint_text()); |
| 172 } | 180 } |
| 173 | 181 |
| 174 void SearchBoxView::SelectionModelChanged() { | 182 void SearchBoxView::SelectionModelChanged() { |
| 175 search_box_->SelectSelectionModel(model_->selection_model()); | 183 search_box_->SelectSelectionModel(model_->selection_model()); |
| 176 } | 184 } |
| 177 | 185 |
| 178 void SearchBoxView::TextChanged() { | 186 void SearchBoxView::TextChanged() { |
| 179 search_box_->SetText(model_->text()); | 187 search_box_->SetText(model_->text()); |
| 180 } | 188 } |
| 181 | 189 |
| 182 } // namespace app_list | 190 } // namespace app_list |
| OLD | NEW |