Chromium Code Reviews| 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/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 Loading... | |
| 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; | 
| 60 | 77 | 
| 61 // This view forwards the focus to the search box widget by providing it as a | 78 // This view forwards the focus to the search box widget by providing it as a | 
| 62 // FocusTraversable when a focus search is provided. | 79 // FocusTraversable when a focus search is provided. | 
| 63 class SearchBoxFocusHost : public views::View { | 80 class SearchBoxFocusHost : public views::View { | 
| 64 public: | 81 public: | 
| 65 explicit SearchBoxFocusHost(views::Widget* search_box_widget) | 82 explicit SearchBoxFocusHost(views::Widget* search_box_widget) | 
| 66 : search_box_widget_(search_box_widget) {} | 83 : search_box_widget_(search_box_widget) {} | 
| 67 | 84 | 
| 68 ~SearchBoxFocusHost() override {} | 85 ~SearchBoxFocusHost() override {} | 
| 69 | 86 | 
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 167 //////////////////////////////////////////////////////////////////////////////// | 184 //////////////////////////////////////////////////////////////////////////////// | 
| 168 // AppListView: | 185 // AppListView: | 
| 169 | 186 | 
| 170 AppListView::AppListView(AppListViewDelegate* delegate) | 187 AppListView::AppListView(AppListViewDelegate* delegate) | 
| 171 : delegate_(delegate), | 188 : delegate_(delegate), | 
| 172 app_list_main_view_(nullptr), | 189 app_list_main_view_(nullptr), | 
| 173 speech_view_(nullptr), | 190 speech_view_(nullptr), | 
| 174 search_box_focus_host_(nullptr), | 191 search_box_focus_host_(nullptr), | 
| 175 search_box_widget_(nullptr), | 192 search_box_widget_(nullptr), | 
| 176 search_box_view_(nullptr), | 193 search_box_view_(nullptr), | 
| 194 display_observer_(this), | |
| 177 overlay_view_(nullptr), | 195 overlay_view_(nullptr), | 
| 178 animation_observer_(new HideViewAnimationObserver()) { | 196 animation_observer_(new HideViewAnimationObserver()) { | 
| 179 CHECK(delegate); | 197 CHECK(delegate); | 
| 180 | 198 | 
| 181 delegate_->GetSpeechUI()->AddObserver(this); | 199 delegate_->GetSpeechUI()->AddObserver(this); | 
| 200 | |
| 201 if (features::IsFullscreenAppListEnabled()) { | |
| 202 display_observer_.Add(display::Screen::GetScreen()); | |
| 203 is_fullscreen_app_list_enabled_ = true; | |
| 204 } | |
| 182 } | 205 } | 
| 183 | 206 | 
| 184 AppListView::~AppListView() { | 207 AppListView::~AppListView() { | 
| 185 delegate_->GetSpeechUI()->RemoveObserver(this); | 208 delegate_->GetSpeechUI()->RemoveObserver(this); | 
| 186 animation_observer_.reset(); | 209 animation_observer_.reset(); | 
| 187 // Remove child views first to ensure no remaining dependencies on delegate_. | 210 // Remove child views first to ensure no remaining dependencies on delegate_. | 
| 188 RemoveAllChildViews(true); | 211 RemoveAllChildViews(true); | 
| 189 } | 212 } | 
| 190 | 213 | 
| 191 void AppListView::Initialize(gfx::NativeView parent, int initial_apps_page) { | 214 void AppListView::Initialize(gfx::NativeView parent, int initial_apps_page) { | 
| 192 base::Time start_time = base::Time::Now(); | 215 base::Time start_time = base::Time::Now(); | 
| 193 InitContents(parent, initial_apps_page); | 216 InitContents(parent, initial_apps_page); | 
| 194 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); | 217 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); | 
| 195 set_color(kContentsBackgroundColor); | 218 set_color(kContentsBackgroundColor); | 
| 196 set_parent_window(parent); | 219 set_parent_window(parent); | 
| 197 | 220 | 
| 198 if (features::IsFullscreenAppListEnabled()) | 221 if (is_fullscreen_app_list_enabled_) | 
| 199 InitializeFullscreen(parent, initial_apps_page); | 222 InitializeFullscreen(parent, initial_apps_page); | 
| 200 else | 223 else | 
| 201 InitializeBubble(parent, initial_apps_page); | 224 InitializeBubble(parent, initial_apps_page); | 
| 202 | 225 | 
| 203 InitChildWidgets(); | 226 InitChildWidgets(); | 
| 204 AddChildView(overlay_view_); | 227 AddChildView(overlay_view_); | 
| 228 | |
| 229 if (is_fullscreen_app_list_enabled_) | |
| 230 ChangeState(PEEKING); | |
| 231 | |
| 205 if (delegate_) | 232 if (delegate_) | 
| 206 delegate_->ViewInitialized(); | 233 delegate_->ViewInitialized(); | 
| 234 | |
| 207 UMA_HISTOGRAM_TIMES("Apps.AppListCreationTime", | 235 UMA_HISTOGRAM_TIMES("Apps.AppListCreationTime", | 
| 208 base::Time::Now() - start_time); | 236 base::Time::Now() - start_time); | 
| 209 } | 237 } | 
| 210 | 238 | 
| 211 void AppListView::SetBubbleArrow(views::BubbleBorder::Arrow arrow) { | 239 void AppListView::SetBubbleArrow(views::BubbleBorder::Arrow arrow) { | 
| 212 GetBubbleFrameView()->bubble_border()->set_arrow(arrow); | 240 GetBubbleFrameView()->bubble_border()->set_arrow(arrow); | 
| 213 SizeToContents(); // Recalcuates with new border. | 241 SizeToContents(); // Recalcuates with new border. | 
| 214 GetBubbleFrameView()->SchedulePaint(); | 242 GetBubbleFrameView()->SchedulePaint(); | 
| 215 } | 243 } | 
| 216 | 244 | 
| 217 void AppListView::MaybeSetAnchorPoint(const gfx::Point& anchor_point) { | 245 void AppListView::MaybeSetAnchorPoint(const gfx::Point& anchor_point) { | 
| 218 // if the AppListView is a bubble | 246 // if the AppListView is a bubble | 
| 219 if (!features::IsFullscreenAppListEnabled()) | 247 if (!is_fullscreen_app_list_enabled_) | 
| 220 SetAnchorRect(gfx::Rect(anchor_point, gfx::Size())); | 248 SetAnchorRect(gfx::Rect(anchor_point, gfx::Size())); | 
| 221 } | 249 } | 
| 222 | 250 | 
| 223 void AppListView::SetDragAndDropHostOfCurrentAppList( | 251 void AppListView::SetDragAndDropHostOfCurrentAppList( | 
| 224 ApplicationDragAndDropHost* drag_and_drop_host) { | 252 ApplicationDragAndDropHost* drag_and_drop_host) { | 
| 225 app_list_main_view_->SetDragAndDropHostOfCurrentAppList(drag_and_drop_host); | 253 app_list_main_view_->SetDragAndDropHostOfCurrentAppList(drag_and_drop_host); | 
| 226 } | 254 } | 
| 227 | 255 | 
| 228 void AppListView::ShowWhenReady() { | 256 void AppListView::ShowWhenReady() { | 
| 229 app_list_main_view_->ShowAppListWhenReady(); | 257 app_list_main_view_->ShowAppListWhenReady(); | 
| 230 } | 258 } | 
| 231 | 259 | 
| 232 void AppListView::CloseAppList() { | 260 void AppListView::CloseAppList() { | 
| 233 app_list_main_view_->Close(); | 261 app_list_main_view_->Close(); | 
| 234 delegate_->Dismiss(); | 262 delegate_->Dismiss(); | 
| 235 } | 263 } | 
| 236 | 264 | 
| 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 (!is_fullscreen_app_list_enabled_) | 
| 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 Loading... | |
| 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 (is_fullscreen_app_list_enabled_) { | 
| 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 Loading... | |
| 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 app_list_state_ = INITIAL; | 
| 444 gfx::Rect display_work_area_bounds = | |
| 445 display::Screen::GetScreen() | |
| 446 ->GetDisplayNearestView(parent_window()) | |
| 447 .work_area(); | |
| 448 | |
| 449 gfx::Rect app_list_overlay_view_bounds( | |
| 450 display_work_area_bounds.x(), | |
| 451 display_work_area_bounds.height() + kShelfSize - kPeekingAppListHeight, | |
| 452 display_work_area_bounds.width(), | |
| 453 display_work_area_bounds.height() + kShelfSize); | |
| 454 | |
| 455 fullscreen_widget_ = new views::Widget; | |
| 407 views::Widget::InitParams app_list_overlay_view_params( | 456 views::Widget::InitParams app_list_overlay_view_params( | 
| 408 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 457 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 
| 409 | 458 | 
| 459 app_list_overlay_view_params.name = "AppList"; | |
| 410 app_list_overlay_view_params.parent = parent; | 460 app_list_overlay_view_params.parent = parent; | 
| 411 app_list_overlay_view_params.delegate = this; | 461 app_list_overlay_view_params.delegate = this; | 
| 412 app_list_overlay_view_params.opacity = | 462 app_list_overlay_view_params.opacity = | 
| 413 views::Widget::InitParams::TRANSLUCENT_WINDOW; | 463 views::Widget::InitParams::TRANSLUCENT_WINDOW; | 
| 414 app_list_overlay_view_params.bounds = | 464 app_list_overlay_view_params.bounds = app_list_overlay_view_bounds; | 
| 415 display::Screen::GetScreen()-> | 465 app_list_overlay_view_params.layer_type = ui::LAYER_SOLID_COLOR; | 
| 416 GetDisplayNearestView(parent).work_area(); | 466 fullscreen_widget_->Init(app_list_overlay_view_params); | 
| 417 widget->Init(app_list_overlay_view_params); | |
| 418 widget->GetLayer()->SetBackgroundBlur(10); | |
| 419 | 467 | 
| 468 fullscreen_widget_bounds_ = fullscreen_widget_->GetWindowBoundsInScreen(); | |
| 420 overlay_view_ = new AppListOverlayView(0 /* no corners */); | 469 overlay_view_ = new AppListOverlayView(0 /* no corners */); | 
| 421 } | 470 } | 
| 422 | 471 | 
| 423 void AppListView::InitializeBubble(gfx::NativeView parent, | 472 void AppListView::InitializeBubble(gfx::NativeView parent, | 
| 424 int initial_apps_page) { | 473 int initial_apps_page) { | 
| 425 set_margins(gfx::Insets()); | 474 set_margins(gfx::Insets()); | 
| 426 set_close_on_deactivate(false); | 475 set_close_on_deactivate(false); | 
| 427 set_shadow(views::BubbleBorder::NO_ASSETS); | 476 set_shadow(views::BubbleBorder::NO_ASSETS); | 
| 428 | 477 | 
| 429 // This creates the app list widget. (Before this, child widgets cannot be | 478 // This creates the app list widget (Before this, child widgets cannot be | 
| 430 // created.) | 479 // created). | 
| 431 views::BubbleDialogDelegateView::CreateBubble(this); | 480 views::BubbleDialogDelegateView::CreateBubble(this); | 
| 432 | 481 | 
| 433 SetBubbleArrow(views::BubbleBorder::FLOAT); | 482 SetBubbleArrow(views::BubbleBorder::FLOAT); | 
| 434 // We can now create the internal widgets. | 483 // We can now create the internal widgets. | 
| 435 | 484 | 
| 436 aura::Window* window = GetWidget()->GetNativeWindow(); | 485 aura::Window* window = GetWidget()->GetNativeWindow(); | 
| 437 window->SetEventTargeter(base::MakeUnique<views::BubbleWindowTargeter>(this)); | 486 window->SetEventTargeter(base::MakeUnique<views::BubbleWindowTargeter>(this)); | 
| 438 | 487 | 
| 439 const int kOverlayCornerRadius = | 488 const int kOverlayCornerRadius = | 
| 440 GetBubbleFrameView()->bubble_border()->GetBorderCornerRadius(); | 489 GetBubbleFrameView()->bubble_border()->GetBorderCornerRadius(); | 
| 441 overlay_view_ = new AppListOverlayView(kOverlayCornerRadius); | 490 overlay_view_ = new AppListOverlayView(kOverlayCornerRadius); | 
| 442 overlay_view_->SetBoundsRect(GetContentsBounds()); | 491 overlay_view_->SetBoundsRect(GetContentsBounds()); | 
| 443 } | 492 } | 
| 444 | 493 | 
| 494 void AppListView::StartDrag(const gfx::Point& location) { | |
| 495 initial_drag_point_ = location; | |
| 496 fullscreen_widget_bounds_ = fullscreen_widget_->GetWindowBoundsInScreen(); | |
| 497 } | |
| 498 | |
| 499 void AppListView::UpdateDrag(const gfx::Point& location) { | |
| 500 // Update the bounds of the widget while maintaining the | |
| 501 // relative position of the top of the widget and the mouse/gesture. | |
| 502 // Block drags north of 0 and recalculate the initial_drag_point_. | |
| 503 int const new_y_position = location.y() - initial_drag_point_.y() + | |
| 504 fullscreen_widget_->GetWindowBoundsInScreen().y(); | |
| 505 gfx::Rect new_widget_bounds = fullscreen_widget_->GetWindowBoundsInScreen(); | |
| 506 if (new_y_position < 0) { | |
| 507 new_widget_bounds.set_y(0); | |
| 508 initial_drag_point_ = location; | |
| 509 } else { | |
| 510 new_widget_bounds.set_y(new_y_position); | |
| 511 } | |
| 512 fullscreen_widget_->SetBounds(new_widget_bounds); | |
| 513 } | |
| 514 | |
| 515 void AppListView::EndDrag(const gfx::Point& location) { | |
| 516 // Change the app list state based on where the drag ended. If fling velocity | |
| 517 // was over the threshold, snap to the next state in the direction of the | |
| 518 // fling. | |
| 519 int const new_y_position = location.y() - initial_drag_point_.y() + | |
| 520 fullscreen_widget_->GetWindowBoundsInScreen().y(); | |
| 521 if (std::abs(last_fling_velocity_) > kAppListDragVelocityThreshold) { | |
| 522 // If the user releases drag with velocity over the threshold, snap to | |
| 523 // the next state, ignoring the drag release position. | |
| 524 if (app_list_state_ == FULLSCREEN) { | |
| 525 if (last_fling_velocity_ > 0) { | |
| 526 ChangeState(PEEKING); | |
| 527 } | |
| 528 } else { | |
| 529 if (last_fling_velocity_ > 0) { | |
| 530 CloseAppList(); | |
| 531 } else if (last_fling_velocity_ < 0) { | |
| 532 ChangeState(FULLSCREEN); | |
| 533 } | |
| 534 } | |
| 535 last_fling_velocity_ = 0; | |
| 536 } else { | |
| 537 int display_height = display::Screen::GetScreen() | |
| 538 ->GetDisplayNearestView(parent_window()) | |
| 539 .work_area() | |
| 540 .height(); | |
| 541 int default_peeking_y = display_height + kShelfSize - kPeekingAppListHeight; | |
| 542 // The drag release velocity was too low, so use the release point. | |
| 543 int app_list_snap_y = | |
| 544 (app_list_state_ == FULLSCREEN) ? 0 : default_peeking_y; | |
| 545 // The DIP delta that must be exceeded for the app list to snap to the next | |
| 546 // state. | |
| 547 int app_list_threshold = | |
| 548 (fullscreen_widget_->GetWindowBoundsInScreen().height() + kShelfSize) / | |
| 549 kAppListThresholdDenominator; | |
| 550 app_list_threshold -= | |
| 551 ((app_list_state_ == FULLSCREEN) ? 0 : kPeekingAppListHeight) / | |
| 552 kAppListThresholdDenominator; | |
| 553 | |
| 554 // If the user releases +/- 1/3 of |app_list_threshold|, snap to the | |
| 555 // next state. | |
| 556 if (std::abs(app_list_snap_y - new_y_position) < app_list_threshold) { | |
| 557 // The drag was not far enough so set the app list bounds to the target | |
| 558 // bounds for the current state. | |
| 559 ChangeState(app_list_state_); | |
| 560 } else if ((app_list_snap_y + app_list_threshold) < new_y_position) { | |
| 561 // The drag was far enough to change states and was a downward drag, so | |
| 562 // set the app list bounds to the next state. | |
| 563 if (app_list_state_ == FULLSCREEN) { | |
| 564 ChangeState(PEEKING); | |
| 565 } else { | |
| 566 CloseAppList(); | |
| 567 } | |
| 568 } else { | |
| 569 // The drag was far enough to change states and was an upward drag, so | |
| 570 // set the app list bounds to the next state. | |
| 571 ChangeState(FULLSCREEN); | |
| 572 } | |
| 573 } | |
| 574 } | |
| 575 | |
| 445 void AppListView::OnBeforeBubbleWidgetInit(views::Widget::InitParams* params, | 576 void AppListView::OnBeforeBubbleWidgetInit(views::Widget::InitParams* params, | 
| 446 views::Widget* widget) const { | 577 views::Widget* widget) const { | 
| 447 if (!params->native_widget) { | 578 if (!params->native_widget) { | 
| 448 views::ViewsDelegate* views_delegate = views::ViewsDelegate::GetInstance(); | 579 views::ViewsDelegate* views_delegate = views::ViewsDelegate::GetInstance(); | 
| 449 if (views_delegate && !views_delegate->native_widget_factory().is_null()) { | 580 if (views_delegate && !views_delegate->native_widget_factory().is_null()) { | 
| 450 params->native_widget = | 581 params->native_widget = | 
| 451 views_delegate->native_widget_factory().Run(*params, widget); | 582 views_delegate->native_widget_factory().Run(*params, widget); | 
| 452 } | 583 } | 
| 453 } | 584 } | 
| 454 // Apply a WM-provided shadow (see ui/wm/core/). | 585 // Apply a WM-provided shadow (see ui/wm/core/). | 
| (...skipping 13 matching lines...) Expand all Loading... | |
| 468 return GetBubbleFrameView() != nullptr; | 599 return GetBubbleFrameView() != nullptr; | 
| 469 } | 600 } | 
| 470 | 601 | 
| 471 void AppListView::GetWidgetHitTestMask(gfx::Path* mask) const { | 602 void AppListView::GetWidgetHitTestMask(gfx::Path* mask) const { | 
| 472 DCHECK(mask); | 603 DCHECK(mask); | 
| 473 DCHECK(GetBubbleFrameView()); | 604 DCHECK(GetBubbleFrameView()); | 
| 474 | 605 | 
| 475 mask->addRect(gfx::RectToSkRect(GetBubbleFrameView()->GetContentsBounds())); | 606 mask->addRect(gfx::RectToSkRect(GetBubbleFrameView()->GetContentsBounds())); | 
| 476 } | 607 } | 
| 477 | 608 | 
| 609 void AppListView::OnMouseEvent(ui::MouseEvent* event) { | |
| 
 
msw
2017/06/07 02:31:38
Should OnMouseEvent and OnGestureEvent invoke the
 
newcomer
2017/06/07 17:21:37
Handled offline.
 
msw
2017/06/07 17:44:05
For potentially interested readers, the offline di
 
newcomer
2017/06/07 19:01:41
Acknowledged.
 
 | |
| 610 if (!is_fullscreen_app_list_enabled_) | |
| 611 return; | |
| 612 | |
| 613 switch (event->type()) { | |
| 614 case ui::ET_MOUSE_PRESSED: | |
| 615 StartDrag(event->location()); | |
| 616 event->SetHandled(); | |
| 617 break; | |
| 618 case ui::ET_MOUSE_DRAGGED: | |
| 619 UpdateDrag(event->location()); | |
| 620 event->SetHandled(); | |
| 621 break; | |
| 622 case ui::ET_MOUSE_RELEASED: | |
| 623 EndDrag(event->location()); | |
| 624 event->SetHandled(); | |
| 625 break; | |
| 626 default: | |
| 627 break; | |
| 628 } | |
| 629 } | |
| 630 | |
| 631 void AppListView::OnGestureEvent(ui::GestureEvent* event) { | |
| 632 if (!is_fullscreen_app_list_enabled_) | |
| 633 return; | |
| 634 | |
| 635 switch (event->type()) { | |
| 636 case ui::ET_GESTURE_SCROLL_BEGIN: | |
| 637 StartDrag(event->location()); | |
| 638 event->SetHandled(); | |
| 639 break; | |
| 640 case ui::ET_GESTURE_SCROLL_UPDATE: | |
| 641 last_fling_velocity_ = event->details().velocity_y(); | |
| 642 UpdateDrag(event->location()); | |
| 643 event->SetHandled(); | |
| 644 break; | |
| 645 case ui::ET_GESTURE_END: | |
| 646 EndDrag(event->location()); | |
| 647 event->SetHandled(); | |
| 648 break; | |
| 649 default: | |
| 650 break; | |
| 651 } | |
| 652 } | |
| 653 | |
| 478 bool AppListView::AcceleratorPressed(const ui::Accelerator& accelerator) { | 654 bool AppListView::AcceleratorPressed(const ui::Accelerator& accelerator) { | 
| 479 DCHECK_EQ(ui::VKEY_ESCAPE, accelerator.key_code()); | 655 DCHECK_EQ(ui::VKEY_ESCAPE, accelerator.key_code()); | 
| 480 | 656 | 
| 481 // If the ContentsView does not handle the back action, then this is the | 657 // If the ContentsView does not handle the back action, then this is the | 
| 482 // top level, so we close the app list. | 658 // top level, so we close the app list. | 
| 483 if (!app_list_main_view_->contents_view()->Back()) { | 659 if (!app_list_main_view_->contents_view()->Back()) { | 
| 484 GetWidget()->Deactivate(); | 660 GetWidget()->Deactivate(); | 
| 485 CloseAppList(); | 661 CloseAppList(); | 
| 486 } | 662 } | 
| 487 | 663 | 
| (...skipping 15 matching lines...) Expand all Loading... | |
| 503 | 679 | 
| 504 if (speech_view_) { | 680 if (speech_view_) { | 
| 505 gfx::Rect speech_bounds = centered_bounds; | 681 gfx::Rect speech_bounds = centered_bounds; | 
| 506 int preferred_height = speech_view_->GetPreferredSize().height(); | 682 int preferred_height = speech_view_->GetPreferredSize().height(); | 
| 507 speech_bounds.Inset(kSpeechUIMargin, kSpeechUIMargin); | 683 speech_bounds.Inset(kSpeechUIMargin, kSpeechUIMargin); | 
| 508 speech_bounds.set_height( | 684 speech_bounds.set_height( | 
| 509 std::min(speech_bounds.height(), preferred_height)); | 685 std::min(speech_bounds.height(), preferred_height)); | 
| 510 speech_bounds.Inset(-speech_view_->GetInsets()); | 686 speech_bounds.Inset(-speech_view_->GetInsets()); | 
| 511 speech_view_->SetBoundsRect(speech_bounds); | 687 speech_view_->SetBoundsRect(speech_bounds); | 
| 512 } | 688 } | 
| 689 | |
| 690 if (is_fullscreen_app_list_enabled_) { | |
| 691 app_list_main_view_->contents_view()->Layout(); | |
| 692 app_list_background_shield_->SetBoundsRect(contents_bounds); | |
| 693 } | |
| 513 } | 694 } | 
| 514 | 695 | 
| 515 void AppListView::SchedulePaintInRect(const gfx::Rect& rect) { | 696 void AppListView::SchedulePaintInRect(const gfx::Rect& rect) { | 
| 516 BubbleDialogDelegateView::SchedulePaintInRect(rect); | 697 BubbleDialogDelegateView::SchedulePaintInRect(rect); | 
| 517 if (GetBubbleFrameView()) | 698 if (GetBubbleFrameView()) | 
| 518 GetBubbleFrameView()->SchedulePaint(); | 699 GetBubbleFrameView()->SchedulePaint(); | 
| 519 } | 700 } | 
| 520 | 701 | 
| 702 void AppListView::ToFullscreen() { | |
| 703 gfx::Rect new_widget_bounds = fullscreen_widget_->GetWindowBoundsInScreen(); | |
| 704 new_widget_bounds.set_y(0); | |
| 705 fullscreen_widget_->SetBounds(new_widget_bounds); | |
| 706 app_list_state_ = FULLSCREEN; | |
| 707 } | |
| 708 | |
| 709 void AppListView::ToPeeking() { | |
| 710 int display_height = display::Screen::GetScreen() | |
| 711 ->GetDisplayNearestView(parent_window()) | |
| 712 .work_area() | |
| 713 .height(); | |
| 714 int default_peeking_y = display_height + kShelfSize - kPeekingAppListHeight; | |
| 715 gfx::Rect new_widget_bounds = fullscreen_widget_->GetWindowBoundsInScreen(); | |
| 716 | |
| 717 new_widget_bounds.set_y(default_peeking_y); | |
| 718 fullscreen_widget_->SetBounds(new_widget_bounds); | |
| 719 app_list_state_ = PEEKING; | |
| 720 } | |
| 721 | |
| 722 void AppListView::ChangeState(AppListState new_state) { | |
| 723 gfx::Rect new_widget_bounds = fullscreen_widget_->GetWindowBoundsInScreen(); | |
| 724 int display_height = display::Screen::GetScreen() | |
| 
 
msw
2017/06/07 02:31:38
nit: |display_height| and |default_peeking_y| are
 
newcomer
2017/06/07 17:21:37
Done.
 
 | |
| 725 ->GetDisplayNearestView(parent_window()) | |
| 726 .work_area() | |
| 727 .height(); | |
| 728 int default_peeking_y = display_height + kShelfSize - kPeekingAppListHeight; | |
| 729 switch (new_state) { | |
| 730 case PEEKING: | |
| 731 new_widget_bounds.set_y(default_peeking_y); | |
| 732 break; | |
| 733 case FULLSCREEN: | |
| 734 new_widget_bounds.set_y(0); | |
| 735 break; | |
| 736 default: | |
| 737 NOTREACHED(); | |
| 738 break; | |
| 739 } | |
| 740 fullscreen_widget_->SetBounds(new_widget_bounds); | |
| 741 app_list_state_ = new_state; | |
| 742 } | |
| 743 | |
| 744 bool AppListView::IsFullscreen() const { | |
| 745 return app_list_state_ == FULLSCREEN; | |
| 746 } | |
| 747 | |
| 521 void AppListView::OnWidgetDestroying(views::Widget* widget) { | 748 void AppListView::OnWidgetDestroying(views::Widget* widget) { | 
| 522 BubbleDialogDelegateView::OnWidgetDestroying(widget); | 749 BubbleDialogDelegateView::OnWidgetDestroying(widget); | 
| 523 if (delegate_ && widget == GetWidget()) | 750 if (delegate_ && widget == GetWidget()) | 
| 524 delegate_->ViewClosing(); | 751 delegate_->ViewClosing(); | 
| 525 } | 752 } | 
| 526 | 753 | 
| 527 void AppListView::OnWidgetVisibilityChanged(views::Widget* widget, | 754 void AppListView::OnWidgetVisibilityChanged(views::Widget* widget, | 
| 528 bool visible) { | 755 bool visible) { | 
| 529 BubbleDialogDelegateView::OnWidgetVisibilityChanged(widget, visible); | 756 BubbleDialogDelegateView::OnWidgetVisibilityChanged(widget, visible); | 
| 530 | 757 | 
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 595 } else { | 822 } else { | 
| 596 app_list_main_view_->SetVisible(true); | 823 app_list_main_view_->SetVisible(true); | 
| 597 // Refocus the search box. However, if the app list widget does not have | 824 // 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* | 825 // 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). | 826 // focus the search box (or we would steal focus back into the app list). | 
| 600 if (GetWidget()->IsActive()) | 827 if (GetWidget()->IsActive()) | 
| 601 search_box_view_->search_box()->RequestFocus(); | 828 search_box_view_->search_box()->RequestFocus(); | 
| 602 } | 829 } | 
| 603 } | 830 } | 
| 604 | 831 | 
| 832 void AppListView::OnDisplayMetricsChanged(const display::Display& display, | |
| 833 uint32_t changed_metrics) { | |
| 834 if (!is_fullscreen_app_list_enabled_) | |
| 835 return; | |
| 836 | |
| 837 gfx::Rect display_work_area_bounds = | |
| 838 display::Screen::GetScreen() | |
| 839 ->GetDisplayNearestView(parent_window()) | |
| 840 .work_area(); | |
| 841 | |
| 842 gfx::Rect recomputed_fullscreen_widget_bounds( | |
| 
 
msw
2017/06/07 02:31:38
Remove this, it's no longer used.
 
newcomer
2017/06/07 17:21:37
Done.
 
 | |
| 843 display_work_area_bounds.x(), | |
| 844 display_work_area_bounds.height() + kShelfSize - kPeekingAppListHeight, | |
| 845 display_work_area_bounds.width(), | |
| 846 display_work_area_bounds.height() + kShelfSize); | |
| 847 | |
| 848 fullscreen_widget_->SetBounds(gfx::Rect( | |
| 849 display_work_area_bounds.x(), | |
| 850 display_work_area_bounds.height() + kShelfSize - kPeekingAppListHeight, | |
| 
 
msw
2017/06/07 02:31:38
nit: you should probably replace display_work_area
 
newcomer
2017/06/07 17:21:37
Actually this value is meaningless because y gets
 
 | |
| 851 display_work_area_bounds.width(), | |
| 852 display_work_area_bounds.height() + kShelfSize)); | |
| 853 | |
| 854 if (app_list_state_ == FULLSCREEN) | |
| 
 
msw
2017/06/07 02:31:38
nit: add a comment like "Update the window's bound
 
newcomer
2017/06/07 17:21:37
Done.
 
 | |
| 855 ChangeState(FULLSCREEN); | |
| 856 else | |
| 857 ChangeState(PEEKING); | |
| 858 } | |
| 859 | |
| 605 } // namespace app_list | 860 } // namespace app_list | 
| OLD | NEW |