| 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 "ui/app_list/app_list_view.h" | 5 #include "ui/app_list/app_list_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | |
| 9 | 8 |
| 10 #include "ui/app_list/app_list_bubble_border.h" | 9 #include "ui/app_list/app_list_bubble_border.h" |
| 11 #include "ui/app_list/app_list_item_view.h" | 10 #include "ui/app_list/app_list_item_view.h" |
| 12 #include "ui/app_list/app_list_model.h" | 11 #include "ui/app_list/app_list_model.h" |
| 13 #include "ui/app_list/app_list_view_delegate.h" | 12 #include "ui/app_list/app_list_view_delegate.h" |
| 14 #include "ui/app_list/apps_grid_view.h" | 13 #include "ui/app_list/apps_grid_view.h" |
| 15 #include "ui/app_list/page_switcher.h" | 14 #include "ui/app_list/page_switcher.h" |
| 16 #include "ui/app_list/pagination_model.h" | 15 #include "ui/app_list/pagination_model.h" |
| 17 #include "ui/app_list/search_box_model.h" | 16 #include "ui/app_list/search_box_model.h" |
| 18 #include "ui/app_list/search_box_view.h" | 17 #include "ui/app_list/search_box_view.h" |
| 19 #include "ui/app_list/search_result_list_view.h" | 18 #include "ui/app_list/search_result_list_view.h" |
| 20 #include "ui/compositor/layer.h" | |
| 21 #include "ui/compositor/scoped_layer_animation_settings.h" | |
| 22 #include "ui/gfx/screen.h" | 19 #include "ui/gfx/screen.h" |
| 23 #include "ui/gfx/transform_util.h" | 20 #include "ui/gfx/transform_util.h" |
| 24 #include "ui/views/background.h" | |
| 25 #include "ui/views/bubble/bubble_frame_view.h" | 21 #include "ui/views/bubble/bubble_frame_view.h" |
| 26 #include "ui/views/controls/textfield/textfield.h" | 22 #include "ui/views/controls/textfield/textfield.h" |
| 27 #include "ui/views/widget/widget.h" | 23 #include "ui/views/widget/widget.h" |
| 28 | 24 |
| 29 namespace app_list { | 25 namespace app_list { |
| 30 | 26 |
| 31 namespace { | 27 namespace { |
| 32 | 28 |
| 33 // 0.2 black | 29 // 0.2 black |
| 34 const SkColor kWidgetBackgroundColor = SkColorSetARGB(0x33, 0, 0, 0); | 30 const SkColor kWidgetBackgroundColor = SkColorSetARGB(0x33, 0, 0, 0); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 49 } | 45 } |
| 50 | 46 |
| 51 } // namespace | 47 } // namespace |
| 52 | 48 |
| 53 //////////////////////////////////////////////////////////////////////////////// | 49 //////////////////////////////////////////////////////////////////////////////// |
| 54 // AppListView: | 50 // AppListView: |
| 55 | 51 |
| 56 AppListView::AppListView(AppListViewDelegate* delegate) | 52 AppListView::AppListView(AppListViewDelegate* delegate) |
| 57 : delegate_(delegate), | 53 : delegate_(delegate), |
| 58 pagination_model_(new PaginationModel), | 54 pagination_model_(new PaginationModel), |
| 59 bubble_style_(false), | |
| 60 bubble_border_(NULL), | 55 bubble_border_(NULL), |
| 61 apps_view_(NULL), | 56 apps_grid_view_(NULL), |
| 62 page_switcher_view_(NULL), | 57 page_switcher_view_(NULL), |
| 63 search_box_view_(NULL), | 58 search_box_view_(NULL), |
| 64 search_results_view_(NULL) { | 59 search_results_view_(NULL) { |
| 65 } | 60 } |
| 66 | 61 |
| 67 AppListView::~AppListView() { | 62 AppListView::~AppListView() { |
| 68 // Deletes all child views while the models are still valid. | 63 // Deletes all child views while the models are still valid. |
| 69 RemoveAllChildViews(true); | 64 RemoveAllChildViews(true); |
| 70 } | 65 } |
| 71 | 66 |
| 72 void AppListView::InitAsFullscreenWidget(gfx::NativeView parent, | |
| 73 const gfx::Rect& screen_bounds, | |
| 74 const gfx::Rect& work_area) { | |
| 75 bubble_style_ = false; | |
| 76 set_background(views::Background::CreateSolidBackground( | |
| 77 kWidgetBackgroundColor)); | |
| 78 work_area_ = work_area; | |
| 79 | |
| 80 apps_view_ = new AppsGridView(this, pagination_model_.get()); | |
| 81 apps_view_->SetPaintToLayer(true); | |
| 82 apps_view_->layer()->SetFillsBoundsOpaquely(false); | |
| 83 AddChildView(apps_view_); | |
| 84 | |
| 85 views::Widget::InitParams widget_params( | |
| 86 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | |
| 87 widget_params.delegate = this; | |
| 88 widget_params.transparent = true; | |
| 89 widget_params.parent = parent; | |
| 90 | |
| 91 views::Widget* widget = new views::Widget; | |
| 92 widget->Init(widget_params); | |
| 93 widget->SetContentsView(this); | |
| 94 widget->SetBounds(screen_bounds); | |
| 95 | |
| 96 // Turns off default animation. | |
| 97 widget->SetVisibilityChangedAnimationsEnabled(false); | |
| 98 | |
| 99 // Sets initial transform. AnimateShow changes it back to identity transform. | |
| 100 apps_view_->SetTransform(GetScaleTransform(apps_view_)); | |
| 101 CreateModel(); | |
| 102 } | |
| 103 | |
| 104 void AppListView::InitAsBubble( | 67 void AppListView::InitAsBubble( |
| 105 gfx::NativeView parent, | 68 gfx::NativeView parent, |
| 106 views::View* anchor, | 69 views::View* anchor, |
| 107 views::BubbleBorder::ArrowLocation arrow_location) { | 70 views::BubbleBorder::ArrowLocation arrow_location) { |
| 108 bubble_style_ = true; | |
| 109 set_background(NULL); | 71 set_background(NULL); |
| 110 | 72 |
| 111 search_box_view_ = new SearchBoxView(this); | 73 search_box_view_ = new SearchBoxView(this); |
| 112 AddChildView(search_box_view_); | 74 AddChildView(search_box_view_); |
| 113 | 75 |
| 114 apps_view_ = new AppsGridView(this, pagination_model_.get()); | 76 apps_grid_view_ = new AppsGridView(this, pagination_model_.get()); |
| 115 apps_view_->SetLayout(kPreferredIconDimension, | 77 apps_grid_view_->SetLayout(kPreferredIconDimension, |
| 116 kPreferredCols, | 78 kPreferredCols, |
| 117 kPreferredRows); | 79 kPreferredRows); |
| 118 AddChildView(apps_view_); | 80 AddChildView(apps_grid_view_); |
| 119 | 81 |
| 120 search_results_view_ = new SearchResultListView(this); | 82 search_results_view_ = new SearchResultListView(this); |
| 121 search_results_view_->SetVisible(false); | 83 search_results_view_->SetVisible(false); |
| 122 AddChildView(search_results_view_); | 84 AddChildView(search_results_view_); |
| 123 | 85 |
| 124 page_switcher_view_ = new PageSwitcher(pagination_model_.get()); | 86 page_switcher_view_ = new PageSwitcher(pagination_model_.get()); |
| 125 AddChildView(page_switcher_view_); | 87 AddChildView(page_switcher_view_); |
| 126 | 88 |
| 127 search_box_view_->set_grid_view(apps_view_); | 89 search_box_view_->set_grid_view(apps_grid_view_); |
| 128 search_box_view_->set_results_view(search_results_view_); | 90 search_box_view_->set_results_view(search_results_view_); |
| 129 | 91 |
| 130 set_anchor_view(anchor); | 92 set_anchor_view(anchor); |
| 131 set_margin(0); | 93 set_margin(0); |
| 132 set_parent_window(parent); | 94 set_parent_window(parent); |
| 133 set_close_on_deactivate(false); | 95 set_close_on_deactivate(false); |
| 134 views::BubbleDelegateView::CreateBubble(this); | 96 views::BubbleDelegateView::CreateBubble(this); |
| 135 | 97 |
| 136 // Resets default background since AppListBubbleBorder paints background. | 98 // Resets default background since AppListBubbleBorder paints background. |
| 137 GetBubbleFrameView()->set_background(NULL); | 99 GetBubbleFrameView()->set_background(NULL); |
| 138 | 100 |
| 139 // Overrides border with AppListBubbleBorder. | 101 // Overrides border with AppListBubbleBorder. |
| 140 bubble_border_ = new AppListBubbleBorder(this, | 102 bubble_border_ = new AppListBubbleBorder(this, |
| 141 search_box_view_, | 103 search_box_view_, |
| 142 apps_view_, | 104 apps_grid_view_, |
| 143 search_results_view_); | 105 search_results_view_); |
| 144 GetBubbleFrameView()->SetBubbleBorder(bubble_border_); | 106 GetBubbleFrameView()->SetBubbleBorder(bubble_border_); |
| 145 SetBubbleArrowLocation(arrow_location); | 107 SetBubbleArrowLocation(arrow_location); |
| 146 | 108 |
| 147 CreateModel(); | 109 CreateModel(); |
| 148 } | 110 } |
| 149 | 111 |
| 150 void AppListView::SetBubbleArrowLocation( | 112 void AppListView::SetBubbleArrowLocation( |
| 151 views::BubbleBorder::ArrowLocation arrow_location) { | 113 views::BubbleBorder::ArrowLocation arrow_location) { |
| 152 DCHECK(bubble_border_); | 114 DCHECK(bubble_border_); |
| 153 bubble_border_->set_arrow_location(arrow_location); | 115 bubble_border_->set_arrow_location(arrow_location); |
| 154 SizeToContents(); // Recalcuates with new border. | 116 SizeToContents(); // Recalcuates with new border. |
| 155 } | 117 } |
| 156 | 118 |
| 157 void AppListView::AnimateShow(int duration_ms) { | |
| 158 if (bubble_style_) | |
| 159 return; | |
| 160 | |
| 161 ui::Layer* layer = apps_view_->layer(); | |
| 162 ui::ScopedLayerAnimationSettings animation(layer->GetAnimator()); | |
| 163 animation.SetTransitionDuration( | |
| 164 base::TimeDelta::FromMilliseconds(duration_ms)); | |
| 165 animation.SetTweenType(ui::Tween::EASE_OUT); | |
| 166 apps_view_->SetTransform(ui::Transform()); | |
| 167 } | |
| 168 | |
| 169 void AppListView::AnimateHide(int duration_ms) { | |
| 170 if (bubble_style_) | |
| 171 return; | |
| 172 | |
| 173 ui::Layer* layer = apps_view_->layer(); | |
| 174 ui::ScopedLayerAnimationSettings animation(layer->GetAnimator()); | |
| 175 animation.SetTransitionDuration( | |
| 176 base::TimeDelta::FromMilliseconds(duration_ms)); | |
| 177 animation.SetTweenType(ui::Tween::EASE_IN); | |
| 178 apps_view_->SetTransform(GetScaleTransform(apps_view_)); | |
| 179 } | |
| 180 | |
| 181 void AppListView::Close() { | 119 void AppListView::Close() { |
| 182 if (delegate_.get()) | 120 if (delegate_.get()) |
| 183 delegate_->Close(); | 121 delegate_->Close(); |
| 184 else | 122 else |
| 185 GetWidget()->Close(); | 123 GetWidget()->Close(); |
| 186 } | 124 } |
| 187 | 125 |
| 188 void AppListView::UpdateBounds(const gfx::Rect& screen_bounds, | 126 void AppListView::UpdateBounds() { |
| 189 const gfx::Rect& work_area) { | 127 SizeToContents(); |
| 190 if (bubble_style_) { | |
| 191 SizeToContents(); | |
| 192 } else { | |
| 193 work_area_ = work_area; | |
| 194 GetWidget()->SetBounds(screen_bounds); | |
| 195 } | |
| 196 } | 128 } |
| 197 | 129 |
| 198 void AppListView::CreateModel() { | 130 void AppListView::CreateModel() { |
| 199 if (delegate_.get()) { | 131 if (delegate_.get()) { |
| 200 // Creates a new model and update all references before releasing old one. | 132 // Creates a new model and update all references before releasing old one. |
| 201 scoped_ptr<AppListModel> new_model(new AppListModel); | 133 scoped_ptr<AppListModel> new_model(new AppListModel); |
| 202 | 134 |
| 203 delegate_->SetModel(new_model.get()); | 135 delegate_->SetModel(new_model.get()); |
| 204 apps_view_->SetModel(new_model->apps()); | 136 apps_grid_view_->SetModel(new_model->apps()); |
| 205 | 137 |
| 206 // search_box_view_ etc are not created for v1. | 138 // search_box_view_ etc are not created for v1. |
| 207 // TODO(xiyuan): Update this after v2 is ready. | 139 // TODO(xiyuan): Update this after v2 is ready. |
| 208 if (search_box_view_) | 140 if (search_box_view_) |
| 209 search_box_view_->SetModel(new_model->search_box()); | 141 search_box_view_->SetModel(new_model->search_box()); |
| 210 if (search_results_view_) | 142 if (search_results_view_) |
| 211 search_results_view_->SetResults(new_model->results()); | 143 search_results_view_->SetResults(new_model->results()); |
| 212 | 144 |
| 213 model_.reset(new_model.release()); | 145 model_.reset(new_model.release()); |
| 214 } | 146 } |
| 215 } | 147 } |
| 216 | 148 |
| 217 views::View* AppListView::GetInitiallyFocusedView() { | 149 views::View* AppListView::GetInitiallyFocusedView() { |
| 218 if (bubble_style_) | 150 return search_box_view_->search_box(); |
| 219 return search_box_view_->search_box(); | |
| 220 else | |
| 221 return apps_view_; | |
| 222 } | 151 } |
| 223 | 152 |
| 224 gfx::Size AppListView::GetPreferredSize() { | 153 gfx::Size AppListView::GetPreferredSize() { |
| 225 if (!bubble_style_) | |
| 226 return View::GetPreferredSize(); | |
| 227 | |
| 228 const gfx::Size search_box_size = search_box_view_->GetPreferredSize(); | 154 const gfx::Size search_box_size = search_box_view_->GetPreferredSize(); |
| 229 const gfx::Size grid_size = apps_view_->GetPreferredSize(); | 155 const gfx::Size grid_size = apps_grid_view_->GetPreferredSize(); |
| 230 const gfx::Size page_switcher_size = page_switcher_view_->GetPreferredSize(); | 156 const gfx::Size page_switcher_size = page_switcher_view_->GetPreferredSize(); |
| 231 const gfx::Size results_size = search_results_view_->GetPreferredSize(); | 157 const gfx::Size results_size = search_results_view_->GetPreferredSize(); |
| 232 | 158 |
| 233 int width = std::max( | 159 int width = std::max( |
| 234 std::max(search_box_size.width(), results_size.width()), | 160 std::max(search_box_size.width(), results_size.width()), |
| 235 std::max(grid_size.width(), page_switcher_size.width())); | 161 std::max(grid_size.width(), page_switcher_size.width())); |
| 236 int height = search_box_size.height() + | 162 int height = search_box_size.height() + |
| 237 std::max(grid_size.height() + page_switcher_size.height(), | 163 std::max(grid_size.height() + page_switcher_size.height(), |
| 238 results_size.height()); | 164 results_size.height()); |
| 239 return gfx::Size(width + 2 * kInnerPadding, | 165 return gfx::Size(width + 2 * kInnerPadding, |
| 240 height + 2 * kInnerPadding); | 166 height + 2 * kInnerPadding); |
| 241 } | 167 } |
| 242 | 168 |
| 243 void AppListView::Layout() { | 169 void AppListView::Layout() { |
| 244 gfx::Rect rect(GetContentsBounds()); | 170 gfx::Rect rect(GetContentsBounds()); |
| 245 if (rect.IsEmpty()) | 171 if (rect.IsEmpty()) |
| 246 return; | 172 return; |
| 247 | 173 |
| 248 if (bubble_style_) { | 174 rect.Inset(kInnerPadding, kInnerPadding); |
| 249 rect.Inset(kInnerPadding, kInnerPadding); | |
| 250 | 175 |
| 251 const int x = rect.x(); | 176 const int x = rect.x(); |
| 252 const int width = rect.width(); | 177 const int width = rect.width(); |
| 253 | 178 |
| 254 // SeachBoxView, AppsGridView and PageSwitcher uses a vertical box layout. | 179 // SeachBoxView, AppsGridView and PageSwitcher uses a vertical box layout. |
| 255 int y = rect.y(); | 180 int y = rect.y(); |
| 256 const int search_box_height = search_box_view_->GetPreferredSize().height(); | 181 const int search_box_height = search_box_view_->GetPreferredSize().height(); |
| 257 gfx::Rect search_box_frame(gfx::Point(x, y), | 182 gfx::Rect search_box_frame(gfx::Point(x, y), |
| 258 gfx::Size(width, search_box_height)); | 183 gfx::Size(width, search_box_height)); |
| 259 search_box_view_->SetBoundsRect(rect.Intersect(search_box_frame)); | 184 search_box_view_->SetBoundsRect(rect.Intersect(search_box_frame)); |
| 260 | 185 |
| 261 y = search_box_view_->bounds().bottom(); | 186 y = search_box_view_->bounds().bottom(); |
| 262 const int grid_height = apps_view_->GetPreferredSize().height(); | 187 const int grid_height = apps_grid_view_->GetPreferredSize().height(); |
| 263 gfx::Rect grid_frame(gfx::Point(x, y), gfx::Size(width, grid_height)); | 188 gfx::Rect grid_frame(gfx::Point(x, y), gfx::Size(width, grid_height)); |
| 264 apps_view_->SetBoundsRect(rect.Intersect(grid_frame)); | 189 apps_grid_view_->SetBoundsRect(rect.Intersect(grid_frame)); |
| 265 | 190 |
| 266 y = apps_view_->bounds().bottom(); | 191 y = apps_grid_view_->bounds().bottom(); |
| 267 const int page_switcher_height = rect.bottom() - y; | 192 const int page_switcher_height = rect.bottom() - y; |
| 268 gfx::Rect page_switcher_frame(gfx::Point(x, y), | 193 gfx::Rect page_switcher_frame(gfx::Point(x, y), |
| 269 gfx::Size(width, page_switcher_height)); | 194 gfx::Size(width, page_switcher_height)); |
| 270 page_switcher_view_->SetBoundsRect(rect.Intersect(page_switcher_frame)); | 195 page_switcher_view_->SetBoundsRect(rect.Intersect(page_switcher_frame)); |
| 271 | 196 |
| 272 // Results view is mutually exclusive with AppsGridView and PageSwitcher. | 197 // Results view is mutually exclusive with AppsGridView and PageSwitcher. |
| 273 // It occupies the same space as those two views. | 198 // It occupies the same space as those two views. |
| 274 gfx::Rect results_frame(grid_frame.Union(page_switcher_frame)); | 199 gfx::Rect results_frame(grid_frame.Union(page_switcher_frame)); |
| 275 search_results_view_->SetBoundsRect(rect.Intersect(results_frame)); | 200 search_results_view_->SetBoundsRect(rect.Intersect(results_frame)); |
| 276 } else { | |
| 277 // Gets work area rect, which is in screen coordinates. | |
| 278 gfx::Rect workarea(work_area_); | |
| 279 | |
| 280 // Converts |workarea| into view's coordinates. | |
| 281 gfx::Point origin(workarea.origin()); | |
| 282 views::View::ConvertPointFromScreen(this, &origin); | |
| 283 workarea.Offset(-origin.x(), -origin.y()); | |
| 284 | |
| 285 rect = rect.Intersect(workarea); | |
| 286 apps_view_->SetBoundsRect(rect); | |
| 287 } | |
| 288 } | 201 } |
| 289 | 202 |
| 290 bool AppListView::OnKeyPressed(const views::KeyEvent& event) { | 203 bool AppListView::OnKeyPressed(const views::KeyEvent& event) { |
| 291 if (event.key_code() == ui::VKEY_ESCAPE) { | 204 if (event.key_code() == ui::VKEY_ESCAPE) { |
| 292 Close(); | 205 Close(); |
| 293 return true; | 206 return true; |
| 294 } | 207 } |
| 295 | 208 |
| 296 return false; | 209 return false; |
| 297 } | 210 } |
| 298 | 211 |
| 299 bool AppListView::OnMousePressed(const views::MouseEvent& event) { | |
| 300 // For full screen mode, if mouse click reaches us, this means user clicks | |
| 301 // on blank area. So close. | |
| 302 if (!bubble_style_) | |
| 303 Close(); | |
| 304 | |
| 305 return true; | |
| 306 } | |
| 307 | |
| 308 void AppListView::ButtonPressed(views::Button* sender, | 212 void AppListView::ButtonPressed(views::Button* sender, |
| 309 const views::Event& event) { | 213 const views::Event& event) { |
| 310 if (sender->GetClassName() != AppListItemView::kViewClassName) | 214 if (sender->GetClassName() != AppListItemView::kViewClassName) |
| 311 return; | 215 return; |
| 312 | 216 |
| 313 if (delegate_.get()) { | 217 if (delegate_.get()) { |
| 314 delegate_->ActivateAppListItem( | 218 delegate_->ActivateAppListItem( |
| 315 static_cast<AppListItemView*>(sender)->model(), | 219 static_cast<AppListItemView*>(sender)->model(), |
| 316 event.flags()); | 220 event.flags()); |
| 317 } | 221 } |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 | 271 |
| 368 if (delegate_.get()) { | 272 if (delegate_.get()) { |
| 369 if (should_show_search) | 273 if (should_show_search) |
| 370 delegate_->StartSearch(); | 274 delegate_->StartSearch(); |
| 371 else | 275 else |
| 372 delegate_->StopSearch(); | 276 delegate_->StopSearch(); |
| 373 } | 277 } |
| 374 | 278 |
| 375 if (showing_search != should_show_search) { | 279 if (showing_search != should_show_search) { |
| 376 // TODO(xiyuan): Animate this transition. | 280 // TODO(xiyuan): Animate this transition. |
| 377 apps_view_->SetVisible(!should_show_search); | 281 apps_grid_view_->SetVisible(!should_show_search); |
| 378 page_switcher_view_->SetVisible(!should_show_search); | 282 page_switcher_view_->SetVisible(!should_show_search); |
| 379 search_results_view_->SetVisible(should_show_search); | 283 search_results_view_->SetVisible(should_show_search); |
| 380 | 284 |
| 381 // TODO(xiyuan): Highlight default match instead of the first. | 285 // TODO(xiyuan): Highlight default match instead of the first. |
| 382 if (search_results_view_->visible()) | 286 if (search_results_view_->visible()) |
| 383 search_results_view_->SetSelectedIndex(0); | 287 search_results_view_->SetSelectedIndex(0); |
| 384 | 288 |
| 385 // Needs to repaint frame as well. | 289 // Needs to repaint frame as well. |
| 386 GetBubbleFrameView()->SchedulePaint(); | 290 GetBubbleFrameView()->SchedulePaint(); |
| 387 } | 291 } |
| 388 } | 292 } |
| 389 | 293 |
| 390 void AppListView::OpenResult(const SearchResult& result, int event_flags) { | 294 void AppListView::OpenResult(const SearchResult& result, int event_flags) { |
| 391 if (delegate_.get()) | 295 if (delegate_.get()) |
| 392 delegate_->OpenSearchResult(result, event_flags); | 296 delegate_->OpenSearchResult(result, event_flags); |
| 393 Close(); | 297 Close(); |
| 394 } | 298 } |
| 395 | 299 |
| 396 } // namespace app_list | 300 } // namespace app_list |
| OLD | NEW |