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/shell.h" | 11 #include "ash/shell.h" |
12 #include "ui/views/layout/fill_layout.h" | 12 #include "ui/gfx/screen.h" |
| 13 #include "ui/views/background.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 |
| 18 namespace { |
| 19 |
| 20 // Margins in pixels from work area edges. |
| 21 const int kMargin = 50; |
| 22 |
| 23 // 0.4 black |
| 24 const SkColor kBackgroundColor = SkColorSetARGB(0x66, 0, 0, 0); |
| 25 |
| 26 } // namespace |
| 27 |
17 AppListView::AppListView( | 28 AppListView::AppListView( |
18 AppListModel* model, | |
19 AppListViewDelegate* delegate, | 29 AppListViewDelegate* delegate, |
20 const gfx::Rect& bounds) | 30 const gfx::Rect& bounds) |
21 : model_(model), | 31 : delegate_(delegate), |
22 delegate_(delegate) { | 32 model_view_(NULL) { |
| 33 set_background(views::Background::CreateSolidBackground(kBackgroundColor)); |
23 Init(bounds); | 34 Init(bounds); |
24 } | 35 } |
25 | 36 |
26 AppListView::~AppListView() { | 37 AppListView::~AppListView() { |
27 } | 38 } |
28 | 39 |
29 void AppListView::Close() { | 40 void AppListView::Close() { |
30 if (GetWidget()->IsVisible()) | 41 if (GetWidget()->IsVisible()) |
31 Shell::GetInstance()->ToggleAppList(); | 42 Shell::GetInstance()->ToggleAppList(); |
32 } | 43 } |
33 | 44 |
34 void AppListView::Init(const gfx::Rect& bounds) { | 45 void AppListView::Init(const gfx::Rect& bounds) { |
35 SetLayoutManager(new views::FillLayout); | 46 model_view_ = new AppListModelView(this); |
36 AppListGroupsView* groups_view = new AppListGroupsView(model_.get(), this); | 47 AddChildView(model_view_); |
37 AddChildView(groups_view); | |
38 | 48 |
39 views::Widget::InitParams widget_params( | 49 views::Widget::InitParams widget_params( |
40 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 50 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
41 widget_params.bounds = bounds; | |
42 widget_params.delegate = this; | 51 widget_params.delegate = this; |
43 widget_params.keep_on_top = true; | 52 widget_params.keep_on_top = true; |
44 widget_params.transparent = true; | 53 widget_params.transparent = true; |
45 | 54 |
46 views::Widget* widget = new views::Widget; | 55 views::Widget* widget = new views::Widget; |
47 widget->Init(widget_params); | 56 widget->Init(widget_params); |
48 widget->SetContentsView(this); | 57 widget->SetContentsView(this); |
| 58 widget->SetBounds(bounds); |
49 | 59 |
50 if (groups_view->GetFocusedTile()) | 60 UpdateModel(); |
51 groups_view->GetFocusedTile()->RequestFocus(); | 61 } |
| 62 |
| 63 void AppListView::UpdateModel() { |
| 64 if (delegate_.get()) { |
| 65 scoped_ptr<AppListModel> new_model(new AppListModel); |
| 66 delegate_->BuildAppListModel(std::string(), new_model.get()); |
| 67 model_view_->SetModel(new_model.get()); |
| 68 model_.reset(new_model.release()); |
| 69 } |
| 70 } |
| 71 |
| 72 views::View* AppListView::GetInitiallyFocusedView() { |
| 73 return model_view_; |
| 74 } |
| 75 |
| 76 void AppListView::Layout() { |
| 77 gfx::Rect rect(GetContentsBounds()); |
| 78 if (rect.IsEmpty()) |
| 79 return; |
| 80 |
| 81 // Gets work area rect, which is in screen coordinates. |
| 82 gfx::Rect workarea = gfx::Screen::GetMonitorWorkAreaNearestWindow( |
| 83 GetWidget()->GetNativeView()); |
| 84 |
| 85 // Converts |workarea| into view's coordinates. |
| 86 gfx::Point origin(workarea.origin()); |
| 87 views::View::ConvertPointFromScreen(this, &origin); |
| 88 workarea.Offset(-origin.x(), -origin.y()); |
| 89 |
| 90 rect = rect.Intersect(workarea); |
| 91 rect.Inset(kMargin, kMargin); |
| 92 model_view_->SetBoundsRect(rect); |
52 } | 93 } |
53 | 94 |
54 bool AppListView::OnKeyPressed(const views::KeyEvent& event) { | 95 bool AppListView::OnKeyPressed(const views::KeyEvent& event) { |
55 if (event.key_code() == ui::VKEY_ESCAPE) { | 96 if (event.key_code() == ui::VKEY_ESCAPE) { |
56 Close(); | 97 Close(); |
57 return true; | 98 return true; |
58 } | 99 } |
59 | 100 |
60 return false; | 101 return false; |
61 } | 102 } |
62 | 103 |
63 bool AppListView::OnMousePressed(const views::MouseEvent& event) { | 104 bool AppListView::OnMousePressed(const views::MouseEvent& event) { |
64 // If mouse click reaches us, this means user clicks on blank area. So close. | 105 // If mouse click reaches us, this means user clicks on blank area. So close. |
65 Close(); | 106 Close(); |
66 | 107 |
67 return true; | 108 return true; |
68 } | 109 } |
69 | 110 |
70 void AppListView::AppListItemActivated(AppListItemView* sender, | 111 void AppListView::ButtonPressed(views::Button* sender, |
71 int event_flags) { | 112 const views::Event& event) { |
72 if (delegate_.get()) | 113 if (sender->GetClassName() != AppListItemView::kViewClassName) |
73 delegate_->OnAppListItemActivated(sender->model(), event_flags); | 114 return; |
| 115 |
| 116 if (delegate_.get()) { |
| 117 delegate_->OnAppListItemActivated( |
| 118 static_cast<AppListItemView*>(sender)->model(), |
| 119 event.flags()); |
| 120 } |
74 Close(); | 121 Close(); |
75 } | 122 } |
76 | 123 |
77 } // namespace ash | 124 } // namespace ash |
OLD | NEW |