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

Side by Side Diff: ui/app_list/views/app_list_view.cc

Issue 2898743002: Draggable peeking/fullscreen launcher with transparent background. (Closed)
Patch Set: addressed msw@'s comments. Created 3 years, 6 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
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 "ui/app_list/views/app_list_view.h" 5 #include "ui/app_list/views/app_list_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 #include "ui/views/views_delegate.h" 46 #include "ui/views/views_delegate.h"
47 #include "ui/views/widget/widget.h" 47 #include "ui/views/widget/widget.h"
48 #include "ui/wm/core/masked_window_targeter.h" 48 #include "ui/wm/core/masked_window_targeter.h"
49 #include "ui/wm/core/shadow_types.h" 49 #include "ui/wm/core/shadow_types.h"
50 50
51 namespace app_list { 51 namespace app_list {
52 52
53 namespace { 53 namespace {
54 54
55 // The margin from the edge to the speech UI. 55 // The margin from the edge to the speech UI.
56 const int kSpeechUIMargin = 12; 56 constexpr int kSpeechUIMargin = 12;
57
58 // The height/width of the shelf.
59 constexpr int kShelfSize = 48;
60
61 // The height of the peeking app list.
62 constexpr int kPeekingAppListHeight = 320;
63
64 // The fraction of app list height that the app list must be released at in
65 // order to transition to the next state.
66 constexpr int kAppListThresholdDenominator = 3;
67
68 // The velocity the app list must be dragged in order to transition to the next
69 // state, measured in DIPs/event.
70 constexpr int kAppListDragVelocityThreshold = 25;
71
72 // The opacity of the app list background.
73 constexpr float kAppListOpacity = 0.8;
57 74
58 // The vertical position for the appearing animation of the speech UI. 75 // The vertical position for the appearing animation of the speech UI.
59 const float kSpeechUIAppearingPosition = 12; 76 constexpr float kSpeechUIAppearingPosition = 12;
77
78 bool IsFullscreenAppListEnabled() {
79 // Cache this value to avoid repeated lookup.
80 static bool cached_value = features::IsFullscreenAppListEnabled();
81 return cached_value;
82 }
60 83
61 // This view forwards the focus to the search box widget by providing it as a 84 // This view forwards the focus to the search box widget by providing it as a
62 // FocusTraversable when a focus search is provided. 85 // FocusTraversable when a focus search is provided.
63 class SearchBoxFocusHost : public views::View { 86 class SearchBoxFocusHost : public views::View {
64 public: 87 public:
65 explicit SearchBoxFocusHost(views::Widget* search_box_widget) 88 explicit SearchBoxFocusHost(views::Widget* search_box_widget)
66 : search_box_widget_(search_box_widget) {} 89 : search_box_widget_(search_box_widget) {}
67 90
68 ~SearchBoxFocusHost() override {} 91 ~SearchBoxFocusHost() override {}
69 92
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 //////////////////////////////////////////////////////////////////////////////// 190 ////////////////////////////////////////////////////////////////////////////////
168 // AppListView: 191 // AppListView:
169 192
170 AppListView::AppListView(AppListViewDelegate* delegate) 193 AppListView::AppListView(AppListViewDelegate* delegate)
171 : delegate_(delegate), 194 : delegate_(delegate),
172 app_list_main_view_(nullptr), 195 app_list_main_view_(nullptr),
173 speech_view_(nullptr), 196 speech_view_(nullptr),
174 search_box_focus_host_(nullptr), 197 search_box_focus_host_(nullptr),
175 search_box_widget_(nullptr), 198 search_box_widget_(nullptr),
176 search_box_view_(nullptr), 199 search_box_view_(nullptr),
200 app_list_state_(PEEKING),
201 display_observer_(this),
177 overlay_view_(nullptr), 202 overlay_view_(nullptr),
178 animation_observer_(new HideViewAnimationObserver()) { 203 animation_observer_(new HideViewAnimationObserver()) {
179 CHECK(delegate); 204 CHECK(delegate);
180 205
181 delegate_->GetSpeechUI()->AddObserver(this); 206 delegate_->GetSpeechUI()->AddObserver(this);
207
208 if (IsFullscreenAppListEnabled())
209 display_observer_.Add(display::Screen::GetScreen());
182 } 210 }
183 211
184 AppListView::~AppListView() { 212 AppListView::~AppListView() {
185 delegate_->GetSpeechUI()->RemoveObserver(this); 213 delegate_->GetSpeechUI()->RemoveObserver(this);
186 animation_observer_.reset(); 214 animation_observer_.reset();
187 // Remove child views first to ensure no remaining dependencies on delegate_. 215 // Remove child views first to ensure no remaining dependencies on delegate_.
188 RemoveAllChildViews(true); 216 RemoveAllChildViews(true);
189 } 217 }
190 218
191 void AppListView::Initialize(gfx::NativeView parent, int initial_apps_page) { 219 void AppListView::Initialize(gfx::NativeView parent, int initial_apps_page) {
192 base::Time start_time = base::Time::Now(); 220 base::Time start_time = base::Time::Now();
193 InitContents(parent, initial_apps_page); 221 InitContents(parent, initial_apps_page);
194 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); 222 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE));
195 set_color(kContentsBackgroundColor); 223 set_color(kContentsBackgroundColor);
196 set_parent_window(parent); 224 set_parent_window(parent);
197 225
198 if (features::IsFullscreenAppListEnabled()) 226 if (IsFullscreenAppListEnabled())
199 InitializeFullscreen(parent, initial_apps_page); 227 InitializeFullscreen(parent, initial_apps_page);
200 else 228 else
201 InitializeBubble(parent, initial_apps_page); 229 InitializeBubble(parent, initial_apps_page);
202 230
203 InitChildWidgets(); 231 InitChildWidgets();
204 AddChildView(overlay_view_); 232 AddChildView(overlay_view_);
233
234 if (IsFullscreenAppListEnabled())
235 SetState(app_list_state_);
236
205 if (delegate_) 237 if (delegate_)
206 delegate_->ViewInitialized(); 238 delegate_->ViewInitialized();
239
207 UMA_HISTOGRAM_TIMES("Apps.AppListCreationTime", 240 UMA_HISTOGRAM_TIMES("Apps.AppListCreationTime",
208 base::Time::Now() - start_time); 241 base::Time::Now() - start_time);
209 } 242 }
210 243
211 void AppListView::SetBubbleArrow(views::BubbleBorder::Arrow arrow) { 244 void AppListView::SetBubbleArrow(views::BubbleBorder::Arrow arrow) {
212 GetBubbleFrameView()->bubble_border()->set_arrow(arrow); 245 GetBubbleFrameView()->bubble_border()->set_arrow(arrow);
213 SizeToContents(); // Recalcuates with new border. 246 SizeToContents(); // Recalcuates with new border.
214 GetBubbleFrameView()->SchedulePaint(); 247 GetBubbleFrameView()->SchedulePaint();
215 } 248 }
216 249
217 void AppListView::MaybeSetAnchorPoint(const gfx::Point& anchor_point) { 250 void AppListView::MaybeSetAnchorPoint(const gfx::Point& anchor_point) {
218 // if the AppListView is a bubble 251 // if the AppListView is a bubble
219 if (!features::IsFullscreenAppListEnabled()) 252 if (!IsFullscreenAppListEnabled())
220 SetAnchorRect(gfx::Rect(anchor_point, gfx::Size())); 253 SetAnchorRect(gfx::Rect(anchor_point, gfx::Size()));
221 } 254 }
222 255
223 void AppListView::SetDragAndDropHostOfCurrentAppList( 256 void AppListView::SetDragAndDropHostOfCurrentAppList(
224 ApplicationDragAndDropHost* drag_and_drop_host) { 257 ApplicationDragAndDropHost* drag_and_drop_host) {
225 app_list_main_view_->SetDragAndDropHostOfCurrentAppList(drag_and_drop_host); 258 app_list_main_view_->SetDragAndDropHostOfCurrentAppList(drag_and_drop_host);
226 } 259 }
227 260
228 void AppListView::ShowWhenReady() { 261 void AppListView::ShowWhenReady() {
229 app_list_main_view_->ShowAppListWhenReady(); 262 app_list_main_view_->ShowAppListWhenReady();
230 } 263 }
231 264
232 void AppListView::CloseAppList() {
233 app_list_main_view_->Close();
234 delegate_->Dismiss();
235 }
236
237 void AppListView::UpdateBounds() { 265 void AppListView::UpdateBounds() {
238 // if the AppListView is a bubble 266 // if the AppListView is a bubble
239 if (!features::IsFullscreenAppListEnabled()) 267 if (!IsFullscreenAppListEnabled())
240 SizeToContents(); 268 SizeToContents();
241 } 269 }
242 270
243 void AppListView::SetAppListOverlayVisible(bool visible) { 271 void AppListView::SetAppListOverlayVisible(bool visible) {
244 DCHECK(overlay_view_); 272 DCHECK(overlay_view_);
245 273
246 // Display the overlay immediately so we can begin the animation. 274 // Display the overlay immediately so we can begin the animation.
247 overlay_view_->SetVisible(true); 275 overlay_view_->SetVisible(true);
248 276
249 ui::ScopedLayerAnimationSettings settings( 277 ui::ScopedLayerAnimationSettings settings(
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 ->pagination_model(); 350 ->pagination_model();
323 } 351 }
324 352
325 void AppListView::InitContents(gfx::NativeView parent, int initial_apps_page) { 353 void AppListView::InitContents(gfx::NativeView parent, int initial_apps_page) {
326 // TODO(vadimt): Remove ScopedTracker below once crbug.com/440224 and 354 // TODO(vadimt): Remove ScopedTracker below once crbug.com/440224 and
327 // crbug.com/441028 are fixed. 355 // crbug.com/441028 are fixed.
328 tracked_objects::ScopedTracker tracking_profile( 356 tracked_objects::ScopedTracker tracking_profile(
329 FROM_HERE_WITH_EXPLICIT_FUNCTION( 357 FROM_HERE_WITH_EXPLICIT_FUNCTION(
330 "440224, 441028 AppListView::InitContents")); 358 "440224, 441028 AppListView::InitContents"));
331 359
332 app_list_main_view_ = new AppListMainView(delegate_); 360 if (IsFullscreenAppListEnabled()) {
361 // The shield view that colors the background of the app list and makes it
362 // transparent.
363 app_list_background_shield_ = new views::View;
364 app_list_background_shield_->SetPaintToLayer(ui::LAYER_SOLID_COLOR);
365 app_list_background_shield_->layer()->SetColor(SK_ColorBLACK);
366 app_list_background_shield_->layer()->SetOpacity(kAppListOpacity);
367 AddChildView(app_list_background_shield_);
368 }
369 app_list_main_view_ = new AppListMainView(delegate_, this);
333 AddChildView(app_list_main_view_); 370 AddChildView(app_list_main_view_);
334 app_list_main_view_->SetPaintToLayer(); 371 app_list_main_view_->SetPaintToLayer();
335 app_list_main_view_->layer()->SetFillsBoundsOpaquely(false); 372 app_list_main_view_->layer()->SetFillsBoundsOpaquely(false);
336 app_list_main_view_->layer()->SetMasksToBounds(true); 373 app_list_main_view_->layer()->SetMasksToBounds(true);
337 // This will be added to the |search_box_widget_| after the app list widget is 374 // This will be added to the |search_box_widget_| after the app list widget is
338 // initialized. 375 // initialized.
339 search_box_view_ = new SearchBoxView(app_list_main_view_, delegate_); 376 search_box_view_ = new SearchBoxView(app_list_main_view_, delegate_, this);
340 search_box_view_->SetPaintToLayer(); 377 search_box_view_->SetPaintToLayer();
341 search_box_view_->layer()->SetFillsBoundsOpaquely(false); 378 search_box_view_->layer()->SetFillsBoundsOpaquely(false);
342 search_box_view_->layer()->SetMasksToBounds(true); 379 search_box_view_->layer()->SetMasksToBounds(true);
343 380
344 // TODO(vadimt): Remove ScopedTracker below once crbug.com/440224 and 381 // TODO(vadimt): Remove ScopedTracker below once crbug.com/440224 and
345 // crbug.com/441028 are fixed. 382 // crbug.com/441028 are fixed.
346 tracked_objects::ScopedTracker tracking_profile1( 383 tracked_objects::ScopedTracker tracking_profile1(
347 FROM_HERE_WITH_EXPLICIT_FUNCTION( 384 FROM_HERE_WITH_EXPLICIT_FUNCTION(
348 "440224, 441028 AppListView::InitContents1")); 385 "440224, 441028 AppListView::InitContents1"));
349 386
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 // Mouse events on the search box shadow should not be captured. 433 // Mouse events on the search box shadow should not be captured.
397 aura::Window* window = search_box_widget_->GetNativeWindow(); 434 aura::Window* window = search_box_widget_->GetNativeWindow();
398 window->SetEventTargeter( 435 window->SetEventTargeter(
399 base::MakeUnique<SearchBoxWindowTargeter>(search_box_view_)); 436 base::MakeUnique<SearchBoxWindowTargeter>(search_box_view_));
400 437
401 app_list_main_view_->contents_view()->Layout(); 438 app_list_main_view_->contents_view()->Layout();
402 } 439 }
403 440
404 void AppListView::InitializeFullscreen(gfx::NativeView parent, 441 void AppListView::InitializeFullscreen(gfx::NativeView parent,
405 int initial_apps_page) { 442 int initial_apps_page) {
406 views::Widget* widget = new views::Widget; 443 gfx::Rect display_work_area_bounds =
444 display::Screen::GetScreen()
445 ->GetDisplayNearestView(parent_window())
446 .work_area();
447
448 gfx::Rect app_list_overlay_view_bounds(
449 display_work_area_bounds.x(),
450 display_work_area_bounds.height() + kShelfSize - kPeekingAppListHeight,
451 display_work_area_bounds.width(),
452 display_work_area_bounds.height() + kShelfSize);
453
454 fullscreen_widget_ = new views::Widget;
407 views::Widget::InitParams app_list_overlay_view_params( 455 views::Widget::InitParams app_list_overlay_view_params(
408 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); 456 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
409 457
458 app_list_overlay_view_params.name = "AppList";
410 app_list_overlay_view_params.parent = parent; 459 app_list_overlay_view_params.parent = parent;
411 app_list_overlay_view_params.delegate = this; 460 app_list_overlay_view_params.delegate = this;
412 app_list_overlay_view_params.opacity = 461 app_list_overlay_view_params.opacity =
413 views::Widget::InitParams::TRANSLUCENT_WINDOW; 462 views::Widget::InitParams::TRANSLUCENT_WINDOW;
414 app_list_overlay_view_params.bounds = 463 app_list_overlay_view_params.bounds = app_list_overlay_view_bounds;
415 display::Screen::GetScreen()-> 464 app_list_overlay_view_params.layer_type = ui::LAYER_SOLID_COLOR;
416 GetDisplayNearestView(parent).work_area(); 465 fullscreen_widget_->Init(app_list_overlay_view_params);
417 widget->Init(app_list_overlay_view_params);
418 widget->GetLayer()->SetBackgroundBlur(10);
419 466
420 overlay_view_ = new AppListOverlayView(0 /* no corners */); 467 overlay_view_ = new AppListOverlayView(0 /* no corners */);
421 } 468 }
422 469
423 void AppListView::InitializeBubble(gfx::NativeView parent, 470 void AppListView::InitializeBubble(gfx::NativeView parent,
424 int initial_apps_page) { 471 int initial_apps_page) {
425 set_margins(gfx::Insets()); 472 set_margins(gfx::Insets());
426 set_close_on_deactivate(false); 473 set_close_on_deactivate(false);
427 set_shadow(views::BubbleBorder::NO_ASSETS); 474 set_shadow(views::BubbleBorder::NO_ASSETS);
428 475
429 // This creates the app list widget. (Before this, child widgets cannot be 476 // This creates the app list widget (Before this, child widgets cannot be
430 // created.) 477 // created).
431 views::BubbleDialogDelegateView::CreateBubble(this); 478 views::BubbleDialogDelegateView::CreateBubble(this);
432 479
433 SetBubbleArrow(views::BubbleBorder::FLOAT); 480 SetBubbleArrow(views::BubbleBorder::FLOAT);
434 // We can now create the internal widgets. 481 // We can now create the internal widgets.
435 482
436 aura::Window* window = GetWidget()->GetNativeWindow(); 483 aura::Window* window = GetWidget()->GetNativeWindow();
437 window->SetEventTargeter(base::MakeUnique<views::BubbleWindowTargeter>(this)); 484 window->SetEventTargeter(base::MakeUnique<views::BubbleWindowTargeter>(this));
438 485
439 const int kOverlayCornerRadius = 486 const int kOverlayCornerRadius =
440 GetBubbleFrameView()->bubble_border()->GetBorderCornerRadius(); 487 GetBubbleFrameView()->bubble_border()->GetBorderCornerRadius();
441 overlay_view_ = new AppListOverlayView(kOverlayCornerRadius); 488 overlay_view_ = new AppListOverlayView(kOverlayCornerRadius);
442 overlay_view_->SetBoundsRect(GetContentsBounds()); 489 overlay_view_->SetBoundsRect(GetContentsBounds());
443 } 490 }
444 491
492 void AppListView::StartDrag(const gfx::Point& location) {
493 initial_drag_point_ = location;
494 }
495
496 void AppListView::UpdateDrag(const gfx::Point& location) {
497 // Update the bounds of the widget while maintaining the
498 // relative position of the top of the widget and the mouse/gesture.
499 // Block drags north of 0 and recalculate the initial_drag_point_.
500 int const new_y_position = location.y() - initial_drag_point_.y() +
501 fullscreen_widget_->GetWindowBoundsInScreen().y();
502 gfx::Rect new_widget_bounds = fullscreen_widget_->GetWindowBoundsInScreen();
503 if (new_y_position < 0) {
504 new_widget_bounds.set_y(0);
505 initial_drag_point_ = location;
506 } else {
507 new_widget_bounds.set_y(new_y_position);
508 }
509 fullscreen_widget_->SetBounds(new_widget_bounds);
510 }
511
512 void AppListView::EndDrag(const gfx::Point& location) {
513 // Change the app list state based on where the drag ended. If fling velocity
514 // was over the threshold, snap to the next state in the direction of the
515 // fling.
516 int const new_y_position = location.y() - initial_drag_point_.y() +
517 fullscreen_widget_->GetWindowBoundsInScreen().y();
518 if (std::abs(last_fling_velocity_) > kAppListDragVelocityThreshold) {
519 // If the user releases drag with velocity over the threshold, snap to
520 // the next state, ignoring the drag release position.
521 if (app_list_state_ == FULLSCREEN) {
522 if (last_fling_velocity_ > 0) {
msw 2017/06/07 17:44:06 optional nit: curlies not needed for this if
newcomer 2017/06/07 19:01:42 Done.
523 SetState(PEEKING);
524 }
525 } else {
526 if (last_fling_velocity_ > 0) {
msw 2017/06/07 17:44:05 optional nit: curlies not needed for this if/else
newcomer 2017/06/07 19:01:41 Done.
527 SetState(CLOSED);
528 } else if (last_fling_velocity_ < 0) {
529 SetState(FULLSCREEN);
530 }
531 }
532 last_fling_velocity_ = 0;
533 } else {
534 int display_height = display::Screen::GetScreen()
535 ->GetDisplayNearestView(parent_window())
536 .work_area()
537 .height();
538 int default_peeking_y = display_height + kShelfSize - kPeekingAppListHeight;
539 // The drag release velocity was too low, so use the release point.
540 int app_list_snap_y =
541 (app_list_state_ == FULLSCREEN) ? 0 : default_peeking_y;
542 // The DIP delta that must be exceeded for the app list to snap to the next
543 // state.
544 int app_list_threshold =
545 (fullscreen_widget_->GetWindowBoundsInScreen().height() + kShelfSize) /
546 kAppListThresholdDenominator;
547 app_list_threshold -=
548 ((app_list_state_ == FULLSCREEN) ? 0 : kPeekingAppListHeight) /
msw 2017/06/07 17:44:05 nit: parens not needed around |app_list_state_ ==
newcomer 2017/06/07 19:01:41 Done.
549 kAppListThresholdDenominator;
550
551 // If the user releases +/- 1/3 of |app_list_threshold|, snap to the
552 // next state.
553 if (std::abs(app_list_snap_y - new_y_position) < app_list_threshold) {
554 // The drag was not far enough so set the app list bounds to the target
555 // bounds for the current state.
556 SetState(app_list_state_);
557 } else if ((app_list_snap_y + app_list_threshold) < new_y_position) {
558 // The drag was far enough to change states and was a downward drag, so
559 // set the app list bounds to the next state.
560 if (app_list_state_ == FULLSCREEN) {
msw 2017/06/07 17:44:05 optional nit: curlies not needed for this if/else
newcomer 2017/06/07 19:01:41 Done.
561 SetState(PEEKING);
562 } else {
563 SetState(CLOSED);
564 }
565 } else {
566 // The drag was far enough to change states and was an upward drag, so
567 // set the app list bounds to the next state.
568 SetState(FULLSCREEN);
569 }
570 }
571 }
572
445 void AppListView::OnBeforeBubbleWidgetInit(views::Widget::InitParams* params, 573 void AppListView::OnBeforeBubbleWidgetInit(views::Widget::InitParams* params,
446 views::Widget* widget) const { 574 views::Widget* widget) const {
447 if (!params->native_widget) { 575 if (!params->native_widget) {
448 views::ViewsDelegate* views_delegate = views::ViewsDelegate::GetInstance(); 576 views::ViewsDelegate* views_delegate = views::ViewsDelegate::GetInstance();
449 if (views_delegate && !views_delegate->native_widget_factory().is_null()) { 577 if (views_delegate && !views_delegate->native_widget_factory().is_null()) {
450 params->native_widget = 578 params->native_widget =
451 views_delegate->native_widget_factory().Run(*params, widget); 579 views_delegate->native_widget_factory().Run(*params, widget);
452 } 580 }
453 } 581 }
454 // Apply a WM-provided shadow (see ui/wm/core/). 582 // Apply a WM-provided shadow (see ui/wm/core/).
(...skipping 13 matching lines...) Expand all
468 return GetBubbleFrameView() != nullptr; 596 return GetBubbleFrameView() != nullptr;
469 } 597 }
470 598
471 void AppListView::GetWidgetHitTestMask(gfx::Path* mask) const { 599 void AppListView::GetWidgetHitTestMask(gfx::Path* mask) const {
472 DCHECK(mask); 600 DCHECK(mask);
473 DCHECK(GetBubbleFrameView()); 601 DCHECK(GetBubbleFrameView());
474 602
475 mask->addRect(gfx::RectToSkRect(GetBubbleFrameView()->GetContentsBounds())); 603 mask->addRect(gfx::RectToSkRect(GetBubbleFrameView()->GetContentsBounds()));
476 } 604 }
477 605
606 void AppListView::OnMouseEvent(ui::MouseEvent* event) {
607 if (!IsFullscreenAppListEnabled())
608 return;
609
610 switch (event->type()) {
611 case ui::ET_MOUSE_PRESSED:
612 StartDrag(event->location());
613 event->SetHandled();
614 break;
615 case ui::ET_MOUSE_DRAGGED:
616 UpdateDrag(event->location());
617 event->SetHandled();
618 break;
619 case ui::ET_MOUSE_RELEASED:
620 EndDrag(event->location());
621 event->SetHandled();
622 break;
623 default:
624 break;
625 }
626 }
627
628 void AppListView::OnGestureEvent(ui::GestureEvent* event) {
629 if (!IsFullscreenAppListEnabled())
630 return;
631
632 switch (event->type()) {
633 case ui::ET_GESTURE_SCROLL_BEGIN:
634 StartDrag(event->location());
635 event->SetHandled();
636 break;
637 case ui::ET_GESTURE_SCROLL_UPDATE:
638 last_fling_velocity_ = event->details().velocity_y();
639 UpdateDrag(event->location());
640 event->SetHandled();
641 break;
642 case ui::ET_GESTURE_END:
643 EndDrag(event->location());
644 event->SetHandled();
645 break;
646 default:
647 break;
648 }
649 }
650
478 bool AppListView::AcceleratorPressed(const ui::Accelerator& accelerator) { 651 bool AppListView::AcceleratorPressed(const ui::Accelerator& accelerator) {
479 DCHECK_EQ(ui::VKEY_ESCAPE, accelerator.key_code()); 652 DCHECK_EQ(ui::VKEY_ESCAPE, accelerator.key_code());
480 653
481 // If the ContentsView does not handle the back action, then this is the 654 // If the ContentsView does not handle the back action, then this is the
482 // top level, so we close the app list. 655 // top level, so we close the app list.
483 if (!app_list_main_view_->contents_view()->Back()) { 656 if (!app_list_main_view_->contents_view()->Back()) {
484 GetWidget()->Deactivate(); 657 GetWidget()->Deactivate();
485 CloseAppList(); 658 SetState(CLOSED);
486 } 659 }
487 660
488 // Don't let DialogClientView handle the accelerator. 661 // Don't let DialogClientView handle the accelerator.
489 return true; 662 return true;
490 } 663 }
491 664
492 void AppListView::Layout() { 665 void AppListView::Layout() {
493 const gfx::Rect contents_bounds = GetContentsBounds(); 666 const gfx::Rect contents_bounds = GetContentsBounds();
494 667
495 // Make sure to layout |app_list_main_view_| and |speech_view_| at the center 668 // Make sure to layout |app_list_main_view_| and |speech_view_| at the center
496 // of the widget. 669 // of the widget.
497 gfx::Rect centered_bounds = contents_bounds; 670 gfx::Rect centered_bounds = contents_bounds;
498 centered_bounds.ClampToCenteredSize(gfx::Size( 671 centered_bounds.ClampToCenteredSize(gfx::Size(
499 app_list_main_view_->contents_view()->GetDefaultContentsBounds().width(), 672 app_list_main_view_->contents_view()->GetDefaultContentsBounds().width(),
500 contents_bounds.height())); 673 contents_bounds.height()));
501 674
502 app_list_main_view_->SetBoundsRect(centered_bounds); 675 app_list_main_view_->SetBoundsRect(centered_bounds);
503 676
504 if (speech_view_) { 677 if (speech_view_) {
505 gfx::Rect speech_bounds = centered_bounds; 678 gfx::Rect speech_bounds = centered_bounds;
506 int preferred_height = speech_view_->GetPreferredSize().height(); 679 int preferred_height = speech_view_->GetPreferredSize().height();
507 speech_bounds.Inset(kSpeechUIMargin, kSpeechUIMargin); 680 speech_bounds.Inset(kSpeechUIMargin, kSpeechUIMargin);
508 speech_bounds.set_height( 681 speech_bounds.set_height(
509 std::min(speech_bounds.height(), preferred_height)); 682 std::min(speech_bounds.height(), preferred_height));
510 speech_bounds.Inset(-speech_view_->GetInsets()); 683 speech_bounds.Inset(-speech_view_->GetInsets());
511 speech_view_->SetBoundsRect(speech_bounds); 684 speech_view_->SetBoundsRect(speech_bounds);
512 } 685 }
686
687 if (IsFullscreenAppListEnabled()) {
688 app_list_main_view_->contents_view()->Layout();
689 app_list_background_shield_->SetBoundsRect(contents_bounds);
690 }
513 } 691 }
514 692
515 void AppListView::SchedulePaintInRect(const gfx::Rect& rect) { 693 void AppListView::SchedulePaintInRect(const gfx::Rect& rect) {
516 BubbleDialogDelegateView::SchedulePaintInRect(rect); 694 BubbleDialogDelegateView::SchedulePaintInRect(rect);
517 if (GetBubbleFrameView()) 695 if (GetBubbleFrameView())
518 GetBubbleFrameView()->SchedulePaint(); 696 GetBubbleFrameView()->SchedulePaint();
519 } 697 }
520 698
699 void AppListView::SetState(AppListState new_state) {
700 gfx::Rect new_widget_bounds = fullscreen_widget_->GetWindowBoundsInScreen();
701 switch (new_state) {
702 case PEEKING: {
703 int display_height = display::Screen::GetScreen()
704 ->GetDisplayNearestView(parent_window())
705 .work_area()
706 .height();
msw 2017/06/07 17:44:06 q: should this be .bottom() in case the work area
newcomer 2017/06/07 19:01:42 Good catch! ty.
707 int default_peeking_y =
708 display_height + kShelfSize - kPeekingAppListHeight;
709 new_widget_bounds.set_y(default_peeking_y);
710 break;
711 }
712 case FULLSCREEN:
713 new_widget_bounds.set_y(0);
714 break;
715 case CLOSED:
716 app_list_main_view_->Close();
717 delegate_->Dismiss();
718 break;
719 default:
msw 2017/06/07 17:44:05 Remove the default case, so adding a new enum valu
newcomer 2017/06/07 19:01:42 Done.
720 NOTREACHED();
721 break;
722 }
723 fullscreen_widget_->SetBounds(new_widget_bounds);
724 app_list_state_ = new_state;
725 }
726
521 void AppListView::OnWidgetDestroying(views::Widget* widget) { 727 void AppListView::OnWidgetDestroying(views::Widget* widget) {
522 BubbleDialogDelegateView::OnWidgetDestroying(widget); 728 BubbleDialogDelegateView::OnWidgetDestroying(widget);
523 if (delegate_ && widget == GetWidget()) 729 if (delegate_ && widget == GetWidget())
524 delegate_->ViewClosing(); 730 delegate_->ViewClosing();
525 } 731 }
526 732
527 void AppListView::OnWidgetVisibilityChanged(views::Widget* widget, 733 void AppListView::OnWidgetVisibilityChanged(views::Widget* widget,
528 bool visible) { 734 bool visible) {
529 BubbleDialogDelegateView::OnWidgetVisibilityChanged(widget, visible); 735 BubbleDialogDelegateView::OnWidgetVisibilityChanged(widget, visible);
530 736
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 } else { 801 } else {
596 app_list_main_view_->SetVisible(true); 802 app_list_main_view_->SetVisible(true);
597 // Refocus the search box. However, if the app list widget does not have 803 // Refocus the search box. However, if the app list widget does not have
598 // focus, it means another window has already taken focus, and we *must not* 804 // focus, it means another window has already taken focus, and we *must not*
599 // focus the search box (or we would steal focus back into the app list). 805 // focus the search box (or we would steal focus back into the app list).
600 if (GetWidget()->IsActive()) 806 if (GetWidget()->IsActive())
601 search_box_view_->search_box()->RequestFocus(); 807 search_box_view_->search_box()->RequestFocus();
602 } 808 }
603 } 809 }
604 810
811 void AppListView::OnDisplayMetricsChanged(const display::Display& display,
812 uint32_t changed_metrics) {
813 if (!IsFullscreenAppListEnabled())
814 return;
815
816 gfx::Rect display_work_area_bounds =
817 display::Screen::GetScreen()
818 ->GetDisplayNearestView(parent_window())
819 .work_area();
820
821 // Set the |fullscreen_widget_| width and height to fit the new display
msw 2017/06/07 17:44:05 nit: s/width and height/size/
newcomer 2017/06/07 19:01:42 Done.
822 // metrics.
823 fullscreen_widget_->SetBounds(
msw 2017/06/07 17:44:06 nit: consider using Widget::SetSize, and maybe doi
newcomer 2017/06/07 19:01:42 I wasn't aware of this. Thanks! Done.
824 gfx::Rect(0, 0, display_work_area_bounds.width(),
825 display_work_area_bounds.height() + kShelfSize));
826
827 // Update the |fullscreen_widget_| bounds to accomodate the new work area.
828 if (app_list_state_ == FULLSCREEN)
msw 2017/06/07 17:44:06 optional nit: SetState(app_list_state_ == FULLSCRE
newcomer 2017/06/07 19:01:42 I went with SetState(app_list_state_).
829 SetState(FULLSCREEN);
830 else
831 SetState(PEEKING);
832 }
833
605 } // namespace app_list 834 } // namespace app_list
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698