| 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 "ash/app_list/app_list_view.h" | 5 #include "ash/app_list/app_list_view.h" |
| 6 | 6 |
| 7 #include "ash/app_list/app_list_groups_view.h" | |
| 8 #include "ash/app_list/app_list_item_view.h" | 7 #include "ash/app_list/app_list_item_view.h" |
| 9 #include "ash/app_list/app_list_model.h" | 8 #include "ash/app_list/app_list_model.h" |
| 9 #include "ash/app_list/app_list_model_view.h" |
| 10 #include "ash/app_list/app_list_view_delegate.h" | 10 #include "ash/app_list/app_list_view_delegate.h" |
| 11 #include "ash/app_list/search_box_view.h" |
| 11 #include "ash/shell.h" | 12 #include "ash/shell.h" |
| 12 #include "ui/views/layout/fill_layout.h" | 13 #include "ui/views/controls/textfield/textfield.h" |
| 13 #include "ui/views/widget/widget.h" | 14 #include "ui/views/widget/widget.h" |
| 14 | 15 |
| 15 namespace ash { | 16 namespace ash { |
| 16 | 17 |
| 17 AppListView::AppListView( | 18 AppListView::AppListView( |
| 18 AppListModel* model, | |
| 19 AppListViewDelegate* delegate, | 19 AppListViewDelegate* delegate, |
| 20 const gfx::Rect& bounds) | 20 const gfx::Rect& bounds) |
| 21 : model_(model), | 21 : model_(new AppListModel), |
| 22 delegate_(delegate) { | 22 delegate_(delegate), |
| 23 search_box_view_(NULL), |
| 24 model_view_(NULL) { |
| 23 Init(bounds); | 25 Init(bounds); |
| 24 } | 26 } |
| 25 | 27 |
| 26 AppListView::~AppListView() { | 28 AppListView::~AppListView() { |
| 27 } | 29 } |
| 28 | 30 |
| 29 void AppListView::Close() { | 31 void AppListView::Close() { |
| 30 if (GetWidget()->IsVisible()) | 32 if (GetWidget()->IsVisible()) |
| 31 Shell::GetInstance()->ToggleAppList(); | 33 Shell::GetInstance()->ToggleAppList(); |
| 32 } | 34 } |
| 33 | 35 |
| 34 void AppListView::Init(const gfx::Rect& bounds) { | 36 void AppListView::Init(const gfx::Rect& bounds) { |
| 35 SetLayoutManager(new views::FillLayout); | 37 search_box_view_ = new SearchBoxView; |
| 36 AppListGroupsView* groups_view = new AppListGroupsView(model_.get(), this); | 38 AddChildView(search_box_view_); |
| 37 AddChildView(groups_view); | 39 model_view_ = new AppListModelView(model_.get(), this); |
| 40 AddChildView(model_view_); |
| 38 | 41 |
| 39 views::Widget::InitParams widget_params( | 42 views::Widget::InitParams widget_params( |
| 40 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 43 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
| 41 widget_params.bounds = bounds; | 44 widget_params.bounds = bounds; |
| 42 widget_params.delegate = this; | 45 widget_params.delegate = this; |
| 43 widget_params.keep_on_top = true; | 46 widget_params.keep_on_top = true; |
| 44 widget_params.transparent = true; | 47 widget_params.transparent = true; |
| 45 | 48 |
| 46 views::Widget* widget = new views::Widget; | 49 views::Widget* widget = new views::Widget; |
| 47 widget->Init(widget_params); | 50 widget->Init(widget_params); |
| 48 widget->SetContentsView(this); | 51 widget->SetContentsView(this); |
| 49 | 52 |
| 50 if (groups_view->GetFocusedTile()) | 53 UpdateModel(); |
| 51 groups_view->GetFocusedTile()->RequestFocus(); | 54 } |
| 55 |
| 56 void AppListView::UpdateModel() { |
| 57 if (delegate_.get()) |
| 58 delegate_->BuildAppListModel(search_box_view_->search_text(), model_.get()); |
| 59 } |
| 60 |
| 61 views::View* AppListView::GetInitiallyFocusedView() { |
| 62 return search_box_view_->search_box(); |
| 63 } |
| 64 |
| 65 void AppListView::Layout() { |
| 66 gfx::Rect rect(GetContentsBounds()); |
| 67 |
| 68 const int kSectionPadding = 20; |
| 69 |
| 70 const int kSearchBoxContainerHeight = 60; |
| 71 const int kSearchBoxHeight = 48; |
| 72 const int kSearchBoxWidth = 640; |
| 73 |
| 74 gfx::Rect search_box_frame(rect); |
| 75 search_box_frame.set_height(kSearchBoxContainerHeight); |
| 76 search_box_view_->SetBounds( |
| 77 search_box_frame.x(), |
| 78 search_box_frame.y() + (search_box_frame.height() - kSearchBoxHeight) / 2, |
| 79 kSearchBoxWidth, |
| 80 kSearchBoxHeight); |
| 81 |
| 82 gfx::Rect app_list_frame(rect); |
| 83 app_list_frame.set_y(search_box_frame.bottom() + kSectionPadding); |
| 84 model_view_->SetBoundsRect(app_list_frame); |
| 52 } | 85 } |
| 53 | 86 |
| 54 bool AppListView::OnKeyPressed(const views::KeyEvent& event) { | 87 bool AppListView::OnKeyPressed(const views::KeyEvent& event) { |
| 55 if (event.key_code() == ui::VKEY_ESCAPE) { | 88 if (event.key_code() == ui::VKEY_ESCAPE) { |
| 56 Close(); | 89 Close(); |
| 57 return true; | 90 return true; |
| 58 } | 91 } |
| 59 | 92 |
| 60 return false; | 93 return false; |
| 61 } | 94 } |
| 62 | 95 |
| 63 bool AppListView::OnMousePressed(const views::MouseEvent& event) { | 96 bool AppListView::OnMousePressed(const views::MouseEvent& event) { |
| 64 // If mouse click reaches us, this means user clicks on blank area. So close. | 97 // If mouse click reaches us, this means user clicks on blank area. So close. |
| 65 Close(); | 98 Close(); |
| 66 | 99 |
| 67 return true; | 100 return true; |
| 68 } | 101 } |
| 69 | 102 |
| 70 void AppListView::AppListItemActivated(AppListItemView* sender, | 103 void AppListView::ButtonPressed(views::Button* sender, |
| 71 int event_flags) { | 104 const views::Event& event) { |
| 72 if (delegate_.get()) | 105 if (delegate_.get()) { |
| 73 delegate_->OnAppListItemActivated(sender->model(), event_flags); | 106 delegate_->OnAppListItemActivated( |
| 107 static_cast<AppListItemView*>(sender)->model(), |
| 108 event.flags()); |
| 109 } |
| 74 Close(); | 110 Close(); |
| 75 } | 111 } |
| 76 | 112 |
| 77 } // namespace ash | 113 } // namespace ash |
| OLD | NEW |