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