Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(255)

Side by Side Diff: ash/app_list/app_list_view.cc

Issue 10381018: ash: First pass of Applist v2. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: for comments in #1 Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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.h"
8 #include "ash/app_list/app_list_bubble_border.h"
7 #include "ash/app_list/app_list_item_view.h" 9 #include "ash/app_list/app_list_item_view.h"
8 #include "ash/app_list/app_list_model.h" 10 #include "ash/app_list/app_list_model.h"
9 #include "ash/app_list/app_list_model_view.h" 11 #include "ash/app_list/app_list_model_view.h"
10 #include "ash/app_list/app_list_view_delegate.h" 12 #include "ash/app_list/app_list_view_delegate.h"
13 #include "ash/app_list/page_switcher.h"
14 #include "ash/app_list/pagination_model.h"
15 #include "ash/launcher/launcher.h"
11 #include "ash/screen_ash.h" 16 #include "ash/screen_ash.h"
12 #include "ash/shell.h" 17 #include "ash/shell.h"
13 #include "ash/shell_window_ids.h" 18 #include "ash/shell_window_ids.h"
14 #include "ash/wm/shelf_layout_manager.h" 19 #include "ash/wm/shelf_layout_manager.h"
15 #include "ui/gfx/compositor/layer.h" 20 #include "ui/gfx/compositor/layer.h"
16 #include "ui/gfx/compositor/scoped_layer_animation_settings.h" 21 #include "ui/gfx/compositor/scoped_layer_animation_settings.h"
17 #include "ui/gfx/screen.h" 22 #include "ui/gfx/screen.h"
18 #include "ui/gfx/transform_util.h" 23 #include "ui/gfx/transform_util.h"
19 #include "ui/views/background.h" 24 #include "ui/views/background.h"
25 #include "ui/views/bubble/bubble_frame_view.h"
26 #include "ui/views/layout/box_layout.h"
20 #include "ui/views/widget/widget.h" 27 #include "ui/views/widget/widget.h"
21 28
22 namespace ash { 29 namespace ash {
23 30
24 namespace { 31 namespace {
25 32
26 // 0.2 black 33 // 0.2 black
27 const SkColor kBackgroundColor = SkColorSetARGB(0x33, 0, 0, 0); 34 const SkColor kWidgetBackgroundColor = SkColorSetARGB(0x33, 0, 0, 0);
28 35
29 const float kModelViewAnimationScaleFactor = 0.9f; 36 const float kModelViewAnimationScaleFactor = 0.9f;
30 37
38 const int kPreferredIconDimension = 48;
39 const int kPreferredCols = 4;
40 const int kPreferredRows = 4;
41 const int kModelViewFooterPadding = 10;
sky 2012/05/06 22:51:15 nit: this last one isn't that obvious, add a descr
xiyuan 2012/05/07 16:46:10 Done.
42
31 ui::Transform GetScaleTransform(AppListModelView* model_view) { 43 ui::Transform GetScaleTransform(AppListModelView* model_view) {
32 gfx::Rect pixel_bounds = model_view->GetLayerBoundsInPixel(); 44 gfx::Rect pixel_bounds = model_view->GetLayerBoundsInPixel();
33 gfx::Point center(pixel_bounds.width() / 2, pixel_bounds.height() / 2); 45 gfx::Point center(pixel_bounds.width() / 2, pixel_bounds.height() / 2);
34 return ui::GetScaleTransform(center, kModelViewAnimationScaleFactor); 46 return ui::GetScaleTransform(center, kModelViewAnimationScaleFactor);
35 } 47 }
36 48
49 // Bounds returned is used for full screen mode. Use full monitor rect so that
50 // the app list shade goes behind the launcher.
51 gfx::Rect GetFullScreenBounds() {
52 gfx::Point cursor = gfx::Screen::GetCursorScreenPoint();
53 return gfx::Screen::GetMonitorNearestPoint(cursor).bounds();
54 }
55
37 } // namespace 56 } // namespace
38 57
39 AppListView::AppListView( 58 ////////////////////////////////////////////////////////////////////////////////
40 AppListViewDelegate* delegate, 59 // AppListView:
41 const gfx::Rect& bounds) 60
61 AppListView::AppListView(AppListViewDelegate* delegate)
42 : delegate_(delegate), 62 : delegate_(delegate),
63 pagination_model_(new PaginationModel),
64 bubble_style_(false),
65 bubble_border_(NULL),
43 model_view_(NULL) { 66 model_view_(NULL) {
44 set_background(views::Background::CreateSolidBackground(kBackgroundColor)); 67 if (internal::AppList::UseAppListV2())
45 Init(bounds); 68 InitAsBubble();
69 else
70 InitAsFullscreenWidget();
46 } 71 }
47 72
48 AppListView::~AppListView() { 73 AppListView::~AppListView() {
49 // Model is going away, so set to NULL before superclass deletes child views. 74 // Model is going away, so set to NULL before superclass deletes child views.
50 if (model_view_) 75 if (model_view_)
51 model_view_->SetModel(NULL); 76 model_view_->SetModel(NULL);
52 } 77 }
53 78
54 void AppListView::AnimateShow(int duration_ms) { 79 void AppListView::AnimateShow(int duration_ms) {
80 if (bubble_style_)
81 return;
82
55 ui::Layer* layer = model_view_->layer(); 83 ui::Layer* layer = model_view_->layer();
56 ui::ScopedLayerAnimationSettings animation(layer->GetAnimator()); 84 ui::ScopedLayerAnimationSettings animation(layer->GetAnimator());
57 animation.SetTransitionDuration( 85 animation.SetTransitionDuration(
58 base::TimeDelta::FromMilliseconds(duration_ms)); 86 base::TimeDelta::FromMilliseconds(duration_ms));
59 animation.SetTweenType(ui::Tween::EASE_OUT); 87 animation.SetTweenType(ui::Tween::EASE_OUT);
60 model_view_->SetTransform(ui::Transform()); 88 model_view_->SetTransform(ui::Transform());
61 } 89 }
62 90
63 void AppListView::AnimateHide(int duration_ms) { 91 void AppListView::AnimateHide(int duration_ms) {
92 if (bubble_style_)
93 return;
94
64 ui::Layer* layer = model_view_->layer(); 95 ui::Layer* layer = model_view_->layer();
65 ui::ScopedLayerAnimationSettings animation(layer->GetAnimator()); 96 ui::ScopedLayerAnimationSettings animation(layer->GetAnimator());
66 animation.SetTransitionDuration( 97 animation.SetTransitionDuration(
67 base::TimeDelta::FromMilliseconds(duration_ms)); 98 base::TimeDelta::FromMilliseconds(duration_ms));
68 animation.SetTweenType(ui::Tween::EASE_IN); 99 animation.SetTweenType(ui::Tween::EASE_IN);
69 model_view_->SetTransform(GetScaleTransform(model_view_)); 100 model_view_->SetTransform(GetScaleTransform(model_view_));
70 } 101 }
71 102
72 void AppListView::Close() { 103 void AppListView::Close() {
73 if (GetWidget()->IsVisible()) 104 if (GetWidget()->IsVisible())
74 Shell::GetInstance()->ToggleAppList(); 105 Shell::GetInstance()->ToggleAppList();
75 } 106 }
76 107
77 void AppListView::Init(const gfx::Rect& bounds) { 108 void AppListView::UpdateBounds() {
78 model_view_ = new AppListModelView(this); 109 if (bubble_style_)
110 SizeToContents();
111 else
112 GetWidget()->SetBounds(GetFullScreenBounds());
113 }
114
115 void AppListView::InitAsFullscreenWidget() {
116 bubble_style_ = false;
117 set_background(views::Background::CreateSolidBackground(
118 kWidgetBackgroundColor));
119
120 model_view_ = new AppListModelView(this, pagination_model_.get());
79 model_view_->SetPaintToLayer(true); 121 model_view_->SetPaintToLayer(true);
80 model_view_->layer()->SetFillsBoundsOpaquely(false); 122 model_view_->layer()->SetFillsBoundsOpaquely(false);
81 AddChildView(model_view_); 123 AddChildView(model_view_);
82 124
83 views::Widget::InitParams widget_params( 125 views::Widget::InitParams widget_params(
84 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); 126 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
85 widget_params.delegate = this; 127 widget_params.delegate = this;
86 widget_params.keep_on_top = true;
87 widget_params.transparent = true; 128 widget_params.transparent = true;
88 widget_params.parent = Shell::GetInstance()->GetContainer( 129 widget_params.parent = Shell::GetInstance()->GetContainer(
89 internal::kShellWindowId_AppListContainer); 130 internal::kShellWindowId_AppListContainer);
90 131
91 views::Widget* widget = new views::Widget; 132 views::Widget* widget = new views::Widget;
92 widget->Init(widget_params); 133 widget->Init(widget_params);
93 widget->SetContentsView(this); 134 widget->SetContentsView(this);
94 widget->SetBounds(bounds); 135
136 widget->SetBounds(GetFullScreenBounds());
95 137
96 // Turns off default animation. 138 // Turns off default animation.
97 widget->SetVisibilityChangedAnimationsEnabled(false); 139 widget->SetVisibilityChangedAnimationsEnabled(false);
98 140
99 // Sets initial transform. AnimateShow changes it back to identity transform. 141 // Sets initial transform. AnimateShow changes it back to identity transform.
100 model_view_->SetTransform(GetScaleTransform(model_view_)); 142 model_view_->SetTransform(GetScaleTransform(model_view_));
101 UpdateModel(); 143 UpdateModel();
102 } 144 }
103 145
146 void AppListView::InitAsBubble() {
147 bubble_style_ = true;
148 set_background(NULL);
149
150 SetLayoutManager(new views::BoxLayout(
151 views::BoxLayout::kVertical, 0, 0, kModelViewFooterPadding));
152
153 model_view_ = new AppListModelView(this, pagination_model_.get());
154 model_view_->SetLayout(kPreferredIconDimension,
155 kPreferredCols,
156 kPreferredRows);
157 AddChildView(model_view_);
158
159 PageSwitcher* page_switcher = new PageSwitcher(pagination_model_.get());
160 AddChildView(page_switcher);
161
162 set_anchor_view(Shell::GetInstance()->launcher()->GetAppListButtonView());
sky 2012/05/06 22:51:15 Is the launcher always visible when we do this?
xiyuan 2012/05/07 16:46:10 Yes, launcher will always be visible. In ShelfLayo
163 set_parent_window(Shell::GetInstance()->GetContainer(
164 internal::kShellWindowId_AppListContainer));
165 set_close_on_deactivate(false);
166 views::BubbleDelegateView::CreateBubble(this);
167
168 // Resets default background since AppListBubbleBorder paints background.
169 GetBubbleFrameView()->set_background(NULL);
170
171 // Overrides border with AppListBubbleBorder.
172 bubble_border_ = new AppListBubbleBorder(this);
173 GetBubbleFrameView()->SetBubbleBorder(bubble_border_);
174 SizeToContents(); // Recalcuates with new border.
175
176 UpdateModel();
177 }
178
104 void AppListView::UpdateModel() { 179 void AppListView::UpdateModel() {
105 if (delegate_.get()) { 180 if (delegate_.get()) {
106 scoped_ptr<AppListModel> new_model(new AppListModel); 181 scoped_ptr<AppListModel> new_model(new AppListModel);
107 delegate_->SetModel(new_model.get()); 182 delegate_->SetModel(new_model.get());
108 delegate_->UpdateModel(std::string()); 183 delegate_->UpdateModel(std::string());
109 model_view_->SetModel(new_model.get()); 184 model_view_->SetModel(new_model.get());
110 model_.reset(new_model.release()); 185 model_.reset(new_model.release());
111 } 186 }
112 } 187 }
113 188
114 views::View* AppListView::GetInitiallyFocusedView() { 189 views::View* AppListView::GetInitiallyFocusedView() {
115 return model_view_; 190 return model_view_;
116 } 191 }
117 192
118 void AppListView::Layout() { 193 void AppListView::Layout() {
119 gfx::Rect rect(GetContentsBounds()); 194 gfx::Rect rect(GetContentsBounds());
120 if (rect.IsEmpty()) 195 if (rect.IsEmpty())
121 return; 196 return;
122 197
123 // Gets work area rect, which is in screen coordinates. 198 if (bubble_style_) {
124 gfx::Rect workarea = Shell::GetInstance()->shelf()->IsVisible() ? 199 views::View::Layout();
125 ScreenAsh::GetUnmaximizedWorkAreaBounds(GetWidget()->GetNativeView()) : 200 } else {
126 gfx::Screen::GetMonitorNearestWindow( 201 // Gets work area rect, which is in screen coordinates.
127 GetWidget()->GetNativeView()).work_area(); 202 gfx::Rect workarea = Shell::GetInstance()->shelf()->IsVisible() ?
203 ScreenAsh::GetUnmaximizedWorkAreaBounds(GetWidget()->GetNativeView()) :
204 gfx::Screen::GetMonitorNearestWindow(
205 GetWidget()->GetNativeView()).work_area();
128 206
129 // Converts |workarea| into view's coordinates. 207 // Converts |workarea| into view's coordinates.
130 gfx::Point origin(workarea.origin()); 208 gfx::Point origin(workarea.origin());
131 views::View::ConvertPointFromScreen(this, &origin); 209 views::View::ConvertPointFromScreen(this, &origin);
132 workarea.Offset(-origin.x(), -origin.y()); 210 workarea.Offset(-origin.x(), -origin.y());
133 211
134 rect = rect.Intersect(workarea); 212 rect = rect.Intersect(workarea);
135 model_view_->SetBoundsRect(rect); 213 model_view_->SetBoundsRect(rect);
214 }
136 } 215 }
137 216
138 bool AppListView::OnKeyPressed(const views::KeyEvent& event) { 217 bool AppListView::OnKeyPressed(const views::KeyEvent& event) {
139 if (event.key_code() == ui::VKEY_ESCAPE) { 218 if (event.key_code() == ui::VKEY_ESCAPE) {
140 Close(); 219 Close();
141 return true; 220 return true;
142 } 221 }
143 222
144 return false; 223 return false;
145 } 224 }
146 225
147 bool AppListView::OnMousePressed(const views::MouseEvent& event) { 226 bool AppListView::OnMousePressed(const views::MouseEvent& event) {
148 // If mouse click reaches us, this means user clicks on blank area. So close. 227 // For full screen mode, if mouse click reaches us, this means user clicks
149 Close(); 228 // on blank area. So close.
229 if (!bubble_style_)
230 Close();
150 231
151 return true; 232 return true;
152 } 233 }
153 234
154 void AppListView::ButtonPressed(views::Button* sender, 235 void AppListView::ButtonPressed(views::Button* sender,
155 const views::Event& event) { 236 const views::Event& event) {
156 if (sender->GetClassName() != AppListItemView::kViewClassName) 237 if (sender->GetClassName() != AppListItemView::kViewClassName)
157 return; 238 return;
158 239
159 if (delegate_.get()) { 240 if (delegate_.get()) {
160 delegate_->OnAppListItemActivated( 241 delegate_->OnAppListItemActivated(
161 static_cast<AppListItemView*>(sender)->model(), 242 static_cast<AppListItemView*>(sender)->model(),
162 event.flags()); 243 event.flags());
163 } 244 }
164 Close(); 245 Close();
165 } 246 }
166 247
248 gfx::Rect AppListView::GetBubbleBounds() {
249 // This happens before replacing the default border.
250 if (!bubble_border_)
251 return views::BubbleDelegateView::GetBubbleBounds();
252
253 const int old_arrow_offset = bubble_border_->arrow_offset();
254 const gfx::Rect anchor_rect = GetAnchorRect();
255
256 bubble_border_->set_arrow_offset(0);
257 gfx::Rect bubble_rect = GetBubbleFrameView()->GetUpdatedWindowBounds(
258 anchor_rect,
259 GetPreferredSize(),
260 false /* try_mirroring_arrow */);
261
262 gfx::Rect monitor_rect = gfx::Screen::GetMonitorNearestPoint(
263 anchor_rect.CenterPoint()).work_area();
264 if (monitor_rect.IsEmpty() || monitor_rect.Contains(bubble_rect))
265 return bubble_rect;
266
267 int offset = 0;
268 if (bubble_rect.x() < monitor_rect.x())
269 offset = monitor_rect.x() - bubble_rect.x();
270 else if (bubble_rect.right() > monitor_rect.right())
271 offset = monitor_rect.right() - bubble_rect.right();
272
273 bubble_rect.set_x(bubble_rect.x() + offset);
274
275 // Moves bubble arrow in the opposite direction. i.e. If bubble bounds is
276 // moved to right (positive offset), we need to move arrow to left so that
277 // it points to the same position before the move.
278 bubble_border_->set_arrow_offset(-offset);
279
280 // Repaints border if arrow offset is changed.
281 if (bubble_border_->arrow_offset() != old_arrow_offset)
282 GetBubbleFrameView()->SchedulePaint();
283
284 return bubble_rect;
285 }
286
167 } // namespace ash 287 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698