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_item_view.h" | 7 #include "ash/app_list/app_list_item_view.h" |
8 #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" | 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/gfx/compositor/layer.h" |
| 13 #include "ui/gfx/compositor/scoped_layer_animation_settings.h" |
12 #include "ui/gfx/screen.h" | 14 #include "ui/gfx/screen.h" |
| 15 #include "ui/gfx/transform_util.h" |
13 #include "ui/views/background.h" | 16 #include "ui/views/background.h" |
14 #include "ui/views/widget/widget.h" | 17 #include "ui/views/widget/widget.h" |
15 | 18 |
16 namespace ash { | 19 namespace ash { |
17 | 20 |
18 namespace { | 21 namespace { |
19 | 22 |
20 // Margins in pixels from work area edges. | 23 // Margins in pixels from work area edges. |
21 const int kMargin = 50; | 24 const int kLeftRightMargin = 45; |
| 25 const int kTopBottomMargin = 32; |
22 | 26 |
23 // 0.4 black | 27 // 0.2 black |
24 const SkColor kBackgroundColor = SkColorSetARGB(0x66, 0, 0, 0); | 28 const SkColor kBackgroundColor = SkColorSetARGB(0x33, 0, 0, 0); |
| 29 |
| 30 const float kModelViewAnimationScaleFactor = 0.9f; |
25 | 31 |
26 } // namespace | 32 } // namespace |
27 | 33 |
28 AppListView::AppListView( | 34 AppListView::AppListView( |
29 AppListViewDelegate* delegate, | 35 AppListViewDelegate* delegate, |
30 const gfx::Rect& bounds) | 36 const gfx::Rect& bounds) |
31 : delegate_(delegate), | 37 : delegate_(delegate), |
32 model_view_(NULL) { | 38 model_view_(NULL) { |
33 set_background(views::Background::CreateSolidBackground(kBackgroundColor)); | 39 set_background(views::Background::CreateSolidBackground(kBackgroundColor)); |
34 Init(bounds); | 40 Init(bounds); |
35 } | 41 } |
36 | 42 |
37 AppListView::~AppListView() { | 43 AppListView::~AppListView() { |
38 } | 44 } |
39 | 45 |
| 46 void AppListView::AnimateShow() { |
| 47 ui::Layer* layer = model_view_->layer(); |
| 48 ui::ScopedLayerAnimationSettings animation(layer->GetAnimator()); |
| 49 model_view_->SetTransform(ui::Transform()); |
| 50 } |
| 51 |
| 52 void AppListView::AnimateHide() { |
| 53 ui::Layer* layer = model_view_->layer(); |
| 54 ui::ScopedLayerAnimationSettings animation(layer->GetAnimator()); |
| 55 model_view_->SetTransform( |
| 56 ui::GetScaleTransform(gfx::Point(model_view_->width() / 2, |
| 57 model_view_->height() / 2), |
| 58 kModelViewAnimationScaleFactor)); |
| 59 } |
| 60 |
40 void AppListView::Close() { | 61 void AppListView::Close() { |
41 if (GetWidget()->IsVisible()) | 62 if (GetWidget()->IsVisible()) |
42 Shell::GetInstance()->ToggleAppList(); | 63 Shell::GetInstance()->ToggleAppList(); |
43 } | 64 } |
44 | 65 |
45 void AppListView::Init(const gfx::Rect& bounds) { | 66 void AppListView::Init(const gfx::Rect& bounds) { |
46 model_view_ = new AppListModelView(this); | 67 model_view_ = new AppListModelView(this); |
| 68 model_view_->SetPaintToLayer(true); |
| 69 model_view_->layer()->SetFillsBoundsOpaquely(false); |
47 AddChildView(model_view_); | 70 AddChildView(model_view_); |
48 | 71 |
49 views::Widget::InitParams widget_params( | 72 views::Widget::InitParams widget_params( |
50 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 73 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
51 widget_params.delegate = this; | 74 widget_params.delegate = this; |
52 widget_params.keep_on_top = true; | 75 widget_params.keep_on_top = true; |
53 widget_params.transparent = true; | 76 widget_params.transparent = true; |
54 | 77 |
55 views::Widget* widget = new views::Widget; | 78 views::Widget* widget = new views::Widget; |
56 widget->Init(widget_params); | 79 widget->Init(widget_params); |
57 widget->SetContentsView(this); | 80 widget->SetContentsView(this); |
58 widget->SetBounds(bounds); | 81 widget->SetBounds(bounds); |
59 | 82 |
| 83 // Turns off default animation. |
| 84 widget->SetVisibilityChangedAnimationsEnabled(false); |
| 85 |
| 86 // Sets initial transform. AnimateShow changes it back to identity transform. |
| 87 model_view_->SetTransform( |
| 88 ui::GetScaleTransform(gfx::Point(model_view_->width() / 2, |
| 89 model_view_->height() / 2), |
| 90 kModelViewAnimationScaleFactor)); |
| 91 |
60 UpdateModel(); | 92 UpdateModel(); |
61 } | 93 } |
62 | 94 |
63 void AppListView::UpdateModel() { | 95 void AppListView::UpdateModel() { |
64 if (delegate_.get()) { | 96 if (delegate_.get()) { |
65 scoped_ptr<AppListModel> new_model(new AppListModel); | 97 scoped_ptr<AppListModel> new_model(new AppListModel); |
66 delegate_->BuildAppListModel(std::string(), new_model.get()); | 98 delegate_->BuildAppListModel(std::string(), new_model.get()); |
67 model_view_->SetModel(new_model.get()); | 99 model_view_->SetModel(new_model.get()); |
68 model_.reset(new_model.release()); | 100 model_.reset(new_model.release()); |
69 } | 101 } |
(...skipping 11 matching lines...) Expand all Loading... |
81 // Gets work area rect, which is in screen coordinates. | 113 // Gets work area rect, which is in screen coordinates. |
82 gfx::Rect workarea = gfx::Screen::GetMonitorWorkAreaNearestWindow( | 114 gfx::Rect workarea = gfx::Screen::GetMonitorWorkAreaNearestWindow( |
83 GetWidget()->GetNativeView()); | 115 GetWidget()->GetNativeView()); |
84 | 116 |
85 // Converts |workarea| into view's coordinates. | 117 // Converts |workarea| into view's coordinates. |
86 gfx::Point origin(workarea.origin()); | 118 gfx::Point origin(workarea.origin()); |
87 views::View::ConvertPointFromScreen(this, &origin); | 119 views::View::ConvertPointFromScreen(this, &origin); |
88 workarea.Offset(-origin.x(), -origin.y()); | 120 workarea.Offset(-origin.x(), -origin.y()); |
89 | 121 |
90 rect = rect.Intersect(workarea); | 122 rect = rect.Intersect(workarea); |
91 rect.Inset(kMargin, kMargin); | 123 rect.Inset(kLeftRightMargin, kTopBottomMargin); |
92 model_view_->SetBoundsRect(rect); | 124 model_view_->SetBoundsRect(rect); |
93 } | 125 } |
94 | 126 |
95 bool AppListView::OnKeyPressed(const views::KeyEvent& event) { | 127 bool AppListView::OnKeyPressed(const views::KeyEvent& event) { |
96 if (event.key_code() == ui::VKEY_ESCAPE) { | 128 if (event.key_code() == ui::VKEY_ESCAPE) { |
97 Close(); | 129 Close(); |
98 return true; | 130 return true; |
99 } | 131 } |
100 | 132 |
101 return false; | 133 return false; |
(...skipping 13 matching lines...) Expand all Loading... |
115 | 147 |
116 if (delegate_.get()) { | 148 if (delegate_.get()) { |
117 delegate_->OnAppListItemActivated( | 149 delegate_->OnAppListItemActivated( |
118 static_cast<AppListItemView*>(sender)->model(), | 150 static_cast<AppListItemView*>(sender)->model(), |
119 event.flags()); | 151 event.flags()); |
120 } | 152 } |
121 Close(); | 153 Close(); |
122 } | 154 } |
123 | 155 |
124 } // namespace ash | 156 } // namespace ash |
OLD | NEW |