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 launcher. | |
| 62 constexpr int kPeekingLauncherHeight = 320; | |
| 63 | |
| 64 // The fraction of launcher height that the launcher must be released at in | |
| 65 // order to transition to the next state. | |
| 66 constexpr int kLauncherThresholdDenominator = 3; | |
| 67 | |
| 68 // The velocity the launcher must be dragged in order to transition to the next | |
| 69 // state, measured in DIPs/event. | |
| 70 constexpr int kLauncherDragVelocityThreshold = 25; | |
| 71 | |
| 72 // The opacity of the launcher background. | |
| 73 constexpr float kLauncherOpacity = 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()); | |
| 182 } | 203 } | 
| 183 | 204 | 
| 184 AppListView::~AppListView() { | 205 AppListView::~AppListView() { | 
| 185 delegate_->GetSpeechUI()->RemoveObserver(this); | 206 delegate_->GetSpeechUI()->RemoveObserver(this); | 
| 186 animation_observer_.reset(); | 207 animation_observer_.reset(); | 
| 187 // Remove child views first to ensure no remaining dependencies on delegate_. | 208 // Remove child views first to ensure no remaining dependencies on delegate_. | 
| 188 RemoveAllChildViews(true); | 209 RemoveAllChildViews(true); | 
| 189 } | 210 } | 
| 190 | 211 | 
| 191 void AppListView::Initialize(gfx::NativeView parent, int initial_apps_page) { | 212 void AppListView::Initialize(gfx::NativeView parent, int initial_apps_page) { | 
| 192 base::Time start_time = base::Time::Now(); | 213 base::Time start_time = base::Time::Now(); | 
| 193 InitContents(parent, initial_apps_page); | 214 InitContents(parent, initial_apps_page); | 
| 194 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); | 215 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); | 
| 195 set_color(kContentsBackgroundColor); | 216 set_color(kContentsBackgroundColor); | 
| 196 set_parent_window(parent); | 217 set_parent_window(parent); | 
| 197 | 218 | 
| 198 if (features::IsFullscreenAppListEnabled()) | 219 if (features::IsFullscreenAppListEnabled()) | 
| 199 InitializeFullscreen(parent, initial_apps_page); | 220 InitializeFullscreen(parent, initial_apps_page); | 
| 200 else | 221 else | 
| 201 InitializeBubble(parent, initial_apps_page); | 222 InitializeBubble(parent, initial_apps_page); | 
| 202 | 223 | 
| 203 InitChildWidgets(); | 224 InitChildWidgets(); | 
| 204 AddChildView(overlay_view_); | 225 AddChildView(overlay_view_); | 
| 226 | |
| 205 if (delegate_) | 227 if (delegate_) | 
| 206 delegate_->ViewInitialized(); | 228 delegate_->ViewInitialized(); | 
| 229 | |
| 207 UMA_HISTOGRAM_TIMES("Apps.AppListCreationTime", | 230 UMA_HISTOGRAM_TIMES("Apps.AppListCreationTime", | 
| 208 base::Time::Now() - start_time); | 231 base::Time::Now() - start_time); | 
| 209 } | 232 } | 
| 210 | 233 | 
| 211 void AppListView::SetBubbleArrow(views::BubbleBorder::Arrow arrow) { | 234 void AppListView::SetBubbleArrow(views::BubbleBorder::Arrow arrow) { | 
| 212 GetBubbleFrameView()->bubble_border()->set_arrow(arrow); | 235 GetBubbleFrameView()->bubble_border()->set_arrow(arrow); | 
| 213 SizeToContents(); // Recalcuates with new border. | 236 SizeToContents(); // Recalcuates with new border. | 
| 214 GetBubbleFrameView()->SchedulePaint(); | 237 GetBubbleFrameView()->SchedulePaint(); | 
| 215 } | 238 } | 
| 216 | 239 | 
| (...skipping 12 matching lines...) Expand all Loading... | |
| 229 app_list_main_view_->ShowAppListWhenReady(); | 252 app_list_main_view_->ShowAppListWhenReady(); | 
| 230 } | 253 } | 
| 231 | 254 | 
| 232 void AppListView::CloseAppList() { | 255 void AppListView::CloseAppList() { | 
| 233 app_list_main_view_->Close(); | 256 app_list_main_view_->Close(); | 
| 234 delegate_->Dismiss(); | 257 delegate_->Dismiss(); | 
| 235 } | 258 } | 
| 236 | 259 | 
| 237 void AppListView::UpdateBounds() { | 260 void AppListView::UpdateBounds() { | 
| 238 // if the AppListView is a bubble | 261 // if the AppListView is a bubble | 
| 239 if (!features::IsFullscreenAppListEnabled()) | 262 if (!launcher_background_shield_) | 
| 240 SizeToContents(); | 263 SizeToContents(); | 
| 241 } | 264 } | 
| 242 | 265 | 
| 266 void AppListView::UpdateDimensions() { | |
| 267 display_work_area_bounds_ = display::Screen::GetScreen() | |
| 268 ->GetDisplayNearestView(parent_window()) | |
| 269 .work_area(); | |
| 270 default_peeking_launcher_y_ = | |
| 271 display_work_area_bounds_.height() + kShelfSize - kPeekingLauncherHeight; | |
| 272 } | |
| 273 | |
| 243 void AppListView::SetAppListOverlayVisible(bool visible) { | 274 void AppListView::SetAppListOverlayVisible(bool visible) { | 
| 244 DCHECK(overlay_view_); | 275 DCHECK(overlay_view_); | 
| 245 | 276 | 
| 246 // Display the overlay immediately so we can begin the animation. | 277 // Display the overlay immediately so we can begin the animation. | 
| 247 overlay_view_->SetVisible(true); | 278 overlay_view_->SetVisible(true); | 
| 248 | 279 | 
| 249 ui::ScopedLayerAnimationSettings settings( | 280 ui::ScopedLayerAnimationSettings settings( | 
| 250 overlay_view_->layer()->GetAnimator()); | 281 overlay_view_->layer()->GetAnimator()); | 
| 251 settings.SetTweenType(gfx::Tween::LINEAR); | 282 settings.SetTweenType(gfx::Tween::LINEAR); | 
| 252 | 283 | 
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 322 ->pagination_model(); | 353 ->pagination_model(); | 
| 323 } | 354 } | 
| 324 | 355 | 
| 325 void AppListView::InitContents(gfx::NativeView parent, int initial_apps_page) { | 356 void AppListView::InitContents(gfx::NativeView parent, int initial_apps_page) { | 
| 326 // TODO(vadimt): Remove ScopedTracker below once crbug.com/440224 and | 357 // TODO(vadimt): Remove ScopedTracker below once crbug.com/440224 and | 
| 327 // crbug.com/441028 are fixed. | 358 // crbug.com/441028 are fixed. | 
| 328 tracked_objects::ScopedTracker tracking_profile( | 359 tracked_objects::ScopedTracker tracking_profile( | 
| 329 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 360 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 
| 330 "440224, 441028 AppListView::InitContents")); | 361 "440224, 441028 AppListView::InitContents")); | 
| 331 | 362 | 
| 332 app_list_main_view_ = new AppListMainView(delegate_); | 363 if (features::IsFullscreenAppListEnabled()) { | 
| 364 // The shield view that colors the background of the launcher and makes it | |
| 365 // transparent. | |
| 366 launcher_background_shield_ = new views::View; | |
| 367 launcher_background_shield_->SetPaintToLayer(ui::LAYER_SOLID_COLOR); | |
| 368 launcher_background_shield_->layer()->SetColor(SK_ColorBLACK); | |
| 369 launcher_background_shield_->layer()->SetOpacity(kLauncherOpacity); | |
| 370 AddChildView(launcher_background_shield_); | |
| 371 } | |
| 372 app_list_main_view_ = new AppListMainView(delegate_, this); | |
| 333 AddChildView(app_list_main_view_); | 373 AddChildView(app_list_main_view_); | 
| 334 app_list_main_view_->SetPaintToLayer(); | 374 app_list_main_view_->SetPaintToLayer(); | 
| 335 app_list_main_view_->layer()->SetFillsBoundsOpaquely(false); | 375 app_list_main_view_->layer()->SetFillsBoundsOpaquely(false); | 
| 336 app_list_main_view_->layer()->SetMasksToBounds(true); | 376 app_list_main_view_->layer()->SetMasksToBounds(true); | 
| 337 // This will be added to the |search_box_widget_| after the app list widget is | 377 // This will be added to the |search_box_widget_| after the app list widget is | 
| 338 // initialized. | 378 // initialized. | 
| 339 search_box_view_ = new SearchBoxView(app_list_main_view_, delegate_); | 379 search_box_view_ = new SearchBoxView(app_list_main_view_, delegate_, this); | 
| 340 search_box_view_->SetPaintToLayer(); | 380 search_box_view_->SetPaintToLayer(); | 
| 341 search_box_view_->layer()->SetFillsBoundsOpaquely(false); | 381 search_box_view_->layer()->SetFillsBoundsOpaquely(false); | 
| 342 search_box_view_->layer()->SetMasksToBounds(true); | 382 search_box_view_->layer()->SetMasksToBounds(true); | 
| 343 | 383 | 
| 344 // TODO(vadimt): Remove ScopedTracker below once crbug.com/440224 and | 384 // TODO(vadimt): Remove ScopedTracker below once crbug.com/440224 and | 
| 345 // crbug.com/441028 are fixed. | 385 // crbug.com/441028 are fixed. | 
| 346 tracked_objects::ScopedTracker tracking_profile1( | 386 tracked_objects::ScopedTracker tracking_profile1( | 
| 347 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 387 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 
| 348 "440224, 441028 AppListView::InitContents1")); | 388 "440224, 441028 AppListView::InitContents1")); | 
| 349 | 389 | 
| (...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. | 436 // Mouse events on the search box shadow should not be captured. | 
| 397 aura::Window* window = search_box_widget_->GetNativeWindow(); | 437 aura::Window* window = search_box_widget_->GetNativeWindow(); | 
| 398 window->SetEventTargeter( | 438 window->SetEventTargeter( | 
| 399 base::MakeUnique<SearchBoxWindowTargeter>(search_box_view_)); | 439 base::MakeUnique<SearchBoxWindowTargeter>(search_box_view_)); | 
| 400 | 440 | 
| 401 app_list_main_view_->contents_view()->Layout(); | 441 app_list_main_view_->contents_view()->Layout(); | 
| 402 } | 442 } | 
| 403 | 443 | 
| 404 void AppListView::InitializeFullscreen(gfx::NativeView parent, | 444 void AppListView::InitializeFullscreen(gfx::NativeView parent, | 
| 405 int initial_apps_page) { | 445 int initial_apps_page) { | 
| 406 views::Widget* widget = new views::Widget; | 446 UpdateDimensions(); | 
| 447 | |
| 448 gfx::Rect app_list_overlay_view_bounds( | |
| 449 display_work_area_bounds_.x(), default_peeking_launcher_y_, | |
| 450 display_work_area_bounds_.width(), | |
| 451 display_work_area_bounds_.height() + kShelfSize); | |
| 452 | |
| 453 fullscreen_widget_ = new views::Widget; | |
| 407 views::Widget::InitParams app_list_overlay_view_params( | 454 views::Widget::InitParams app_list_overlay_view_params( | 
| 408 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 455 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 
| 409 | 456 | 
| 457 app_list_overlay_view_params.name = "AppList"; | |
| 410 app_list_overlay_view_params.parent = parent; | 458 app_list_overlay_view_params.parent = parent; | 
| 411 app_list_overlay_view_params.delegate = this; | 459 app_list_overlay_view_params.delegate = this; | 
| 412 app_list_overlay_view_params.opacity = | 460 app_list_overlay_view_params.opacity = | 
| 413 views::Widget::InitParams::TRANSLUCENT_WINDOW; | 461 views::Widget::InitParams::TRANSLUCENT_WINDOW; | 
| 414 app_list_overlay_view_params.bounds = | 462 app_list_overlay_view_params.bounds = app_list_overlay_view_bounds; | 
| 415 display::Screen::GetScreen()-> | 463 app_list_overlay_view_params.layer_type = ui::LAYER_SOLID_COLOR; | 
| 416 GetDisplayNearestView(parent).work_area(); | 464 fullscreen_widget_->Init(app_list_overlay_view_params); | 
| 417 widget->Init(app_list_overlay_view_params); | |
| 418 widget->GetLayer()->SetBackgroundBlur(10); | |
| 419 | 465 | 
| 466 fullscreen_widget_bounds_ = fullscreen_widget_->GetWindowBoundsInScreen(); | |
| 420 overlay_view_ = new AppListOverlayView(0 /* no corners */); | 467 overlay_view_ = new AppListOverlayView(0 /* no corners */); | 
| 468 | |
| 469 // Launcher + shelf height, used in HandleDrag. | |
| 470 launcher_threshold_ = | |
| 471 (default_peeking_launcher_y_ + fullscreen_widget_bounds_.height() - | |
| 472 fullscreen_widget_bounds_.y()) / | |
| 473 kLauncherThresholdDenominator; | |
| 421 } | 474 } | 
| 422 | 475 | 
| 423 void AppListView::InitializeBubble(gfx::NativeView parent, | 476 void AppListView::InitializeBubble(gfx::NativeView parent, | 
| 424 int initial_apps_page) { | 477 int initial_apps_page) { | 
| 425 set_margins(gfx::Insets()); | 478 set_margins(gfx::Insets()); | 
| 426 set_close_on_deactivate(false); | 479 set_close_on_deactivate(false); | 
| 427 set_shadow(views::BubbleBorder::NO_ASSETS); | 480 set_shadow(views::BubbleBorder::NO_ASSETS); | 
| 428 | 481 | 
| 429 // This creates the app list widget. (Before this, child widgets cannot be | 482 // This creates the app list widget. (Before this, child widgets cannot be | 
| 430 // created.) | 483 // created. | 
| 431 views::BubbleDialogDelegateView::CreateBubble(this); | 484 views::BubbleDialogDelegateView::CreateBubble(this); | 
| 432 | 485 | 
| 433 SetBubbleArrow(views::BubbleBorder::FLOAT); | 486 SetBubbleArrow(views::BubbleBorder::FLOAT); | 
| 434 // We can now create the internal widgets. | 487 // We can now create the internal widgets. | 
| 435 | 488 | 
| 436 aura::Window* window = GetWidget()->GetNativeWindow(); | 489 aura::Window* window = GetWidget()->GetNativeWindow(); | 
| 437 window->SetEventTargeter(base::MakeUnique<views::BubbleWindowTargeter>(this)); | 490 window->SetEventTargeter(base::MakeUnique<views::BubbleWindowTargeter>(this)); | 
| 438 | 491 | 
| 439 const int kOverlayCornerRadius = | 492 const int kOverlayCornerRadius = | 
| 440 GetBubbleFrameView()->bubble_border()->GetBorderCornerRadius(); | 493 GetBubbleFrameView()->bubble_border()->GetBorderCornerRadius(); | 
| 441 overlay_view_ = new AppListOverlayView(kOverlayCornerRadius); | 494 overlay_view_ = new AppListOverlayView(kOverlayCornerRadius); | 
| 442 overlay_view_->SetBoundsRect(GetContentsBounds()); | 495 overlay_view_->SetBoundsRect(GetContentsBounds()); | 
| 443 } | 496 } | 
| 444 | 497 | 
| 498 void AppListView::HandleDrag(const gfx::Point& location, ui::EventType type) { | |
| 499 switch (type) { | |
| 500 case ui::ET_GESTURE_SCROLL_BEGIN: | |
| 501 case ui::ET_MOUSE_PRESSED: { | |
| 502 StartDrag(location); | |
| 503 break; | |
| 504 } | |
| 505 case ui::ET_GESTURE_SCROLL_UPDATE: | |
| 506 case ui::ET_MOUSE_DRAGGED: { | |
| 507 UpdateDrag(location); | |
| 508 break; | |
| 509 } | |
| 510 case ui::ET_GESTURE_END: | |
| 511 case ui::ET_MOUSE_RELEASED: { | |
| 512 EndDrag(location); | |
| 513 break; | |
| 514 } | |
| 515 default: | |
| 516 NOTREACHED(); | |
| 517 break; | |
| 518 } | |
| 519 } | |
| 520 | |
| 521 void AppListView::StartDrag(const gfx::Point& location) { | |
| 522 initial_drag_separation_ = location.y(); | |
| 523 fullscreen_widget_bounds_ = fullscreen_widget_->GetWindowBoundsInScreen(); | |
| 524 } | |
| 525 | |
| 526 void AppListView::UpdateDrag(const gfx::Point& location) { | |
| 527 // Update the bounds of the widget while maintaining the | |
| 528 // relative position of the top of the widget and the mouse/gesture. | |
| 529 // Block drags north of 0 and recalculate the initial_drag_separation_. | |
| 530 int const new_y_position = | |
| 531 location.y() - initial_drag_separation_ + fullscreen_widget_bounds_.y(); | |
| 532 if (new_y_position < 0) { | |
| 533 fullscreen_widget_bounds_.set_y(0); | |
| 534 initial_drag_separation_ = location.y(); | |
| 535 } else { | |
| 536 fullscreen_widget_bounds_.set_y(new_y_position); | |
| 537 } | |
| 538 fullscreen_widget_->SetBounds(fullscreen_widget_bounds_); | |
| 539 } | |
| 540 | |
| 541 void AppListView::EndDrag(const gfx::Point& location) { | |
| 542 // Change the launcher state based on where the drag ended. If fling velocity | |
| 543 // was over the threshold, snap to the next state in the direction of the | |
| 544 // fling. | |
| 545 int const new_y_position = | |
| 546 location.y() - initial_drag_separation_ + fullscreen_widget_bounds_.y(); | |
| 547 if (std::abs(last_fling_velocity_) > kLauncherDragVelocityThreshold) { | |
| 548 // If the user releases drag with velocity over the threshold, snap to | |
| 549 // the next state, ignoring the drag release position. | |
| 550 if (is_fullscreen_launcher_) { | |
| 551 if (last_fling_velocity_ > 0) { | |
| 552 ToPeeking(); | |
| 553 } | |
| 554 } else { | |
| 555 if (last_fling_velocity_ > 0) { | |
| 556 CloseAppList(); | |
| 557 } else if (last_fling_velocity_ < 0) { | |
| 558 ToFullscreen(); | |
| 559 } | |
| 560 } | |
| 561 last_fling_velocity_ = 0; | |
| 562 } else { | |
| 563 // The drag release velocity was too low, so use the release point. | |
| 564 int launcher_snap_y = | |
| 565 is_fullscreen_launcher_ ? 0 : default_peeking_launcher_y_; | |
| 566 // If the user releases +/- 1/3 of launcher_threshold_ , snap to the | |
| 567 // next state. | |
| 568 if (std::abs(launcher_snap_y - new_y_position) < (launcher_threshold_)) { | |
| 569 // If the drag released to the state above. | |
| 570 if (is_fullscreen_launcher_) { | |
| 571 ToFullscreen(); | |
| 572 } else { | |
| 573 ToPeeking(); | |
| 574 } | |
| 575 } else if ((launcher_snap_y + (launcher_threshold_)) < new_y_position) { | |
| 576 // If the user released to the state below. | |
| 577 if (is_fullscreen_launcher_) { | |
| 578 ToPeeking(); | |
| 579 } else { | |
| 580 CloseAppList(); | |
| 581 } | |
| 582 } else { | |
| 583 // if the user released to the state above, go to the state above. | |
| 584 ToFullscreen(); | |
| 585 } | |
| 586 } | |
| 587 } | |
| 588 | |
| 445 void AppListView::OnBeforeBubbleWidgetInit(views::Widget::InitParams* params, | 589 void AppListView::OnBeforeBubbleWidgetInit(views::Widget::InitParams* params, | 
| 446 views::Widget* widget) const { | 590 views::Widget* widget) const { | 
| 447 if (!params->native_widget) { | 591 if (!params->native_widget) { | 
| 448 views::ViewsDelegate* views_delegate = views::ViewsDelegate::GetInstance(); | 592 views::ViewsDelegate* views_delegate = views::ViewsDelegate::GetInstance(); | 
| 449 if (views_delegate && !views_delegate->native_widget_factory().is_null()) { | 593 if (views_delegate && !views_delegate->native_widget_factory().is_null()) { | 
| 450 params->native_widget = | 594 params->native_widget = | 
| 451 views_delegate->native_widget_factory().Run(*params, widget); | 595 views_delegate->native_widget_factory().Run(*params, widget); | 
| 452 } | 596 } | 
| 453 } | 597 } | 
| 454 // Apply a WM-provided shadow (see ui/wm/core/). | 598 // Apply a WM-provided shadow (see ui/wm/core/). | 
| (...skipping 13 matching lines...) Expand all Loading... | |
| 468 return GetBubbleFrameView() != nullptr; | 612 return GetBubbleFrameView() != nullptr; | 
| 469 } | 613 } | 
| 470 | 614 | 
| 471 void AppListView::GetWidgetHitTestMask(gfx::Path* mask) const { | 615 void AppListView::GetWidgetHitTestMask(gfx::Path* mask) const { | 
| 472 DCHECK(mask); | 616 DCHECK(mask); | 
| 473 DCHECK(GetBubbleFrameView()); | 617 DCHECK(GetBubbleFrameView()); | 
| 474 | 618 | 
| 475 mask->addRect(gfx::RectToSkRect(GetBubbleFrameView()->GetContentsBounds())); | 619 mask->addRect(gfx::RectToSkRect(GetBubbleFrameView()->GetContentsBounds())); | 
| 476 } | 620 } | 
| 477 | 621 | 
| 622 void AppListView::OnMouseEvent(ui::MouseEvent* event) { | |
| 623 if (!launcher_background_shield_) | |
| 624 return; | |
| 625 | |
| 626 switch (event->type()) { | |
| 627 case ui::ET_MOUSE_PRESSED: | |
| 628 case ui::ET_MOUSE_DRAGGED: | |
| 629 case ui::ET_MOUSE_RELEASED: | |
| 630 HandleDrag(event->location(), event->type()); | |
| 631 event->SetHandled(); | |
| 632 break; | |
| 633 default: | |
| 634 break; | |
| 635 } | |
| 636 } | |
| 637 | |
| 638 void AppListView::OnGestureEvent(ui::GestureEvent* event) { | |
| 639 if (!launcher_background_shield_) | |
| 640 return; | |
| 641 | |
| 642 switch (event->type()) { | |
| 643 case ui::ET_GESTURE_SCROLL_UPDATE: | |
| 644 last_fling_velocity_ = event->details().velocity_y(); | |
| 645 HandleDrag(event->location(), event->type()); | |
| 646 event->SetHandled(); | |
| 647 break; | |
| 648 case ui::ET_GESTURE_SCROLL_BEGIN: | |
| 649 case ui::ET_GESTURE_END: | |
| 650 HandleDrag(event->location(), event->type()); | |
| 651 event->SetHandled(); | |
| 652 break; | |
| 653 default: | |
| 654 break; | |
| 655 } | |
| 656 } | |
| 657 | |
| 478 bool AppListView::AcceleratorPressed(const ui::Accelerator& accelerator) { | 658 bool AppListView::AcceleratorPressed(const ui::Accelerator& accelerator) { | 
| 479 DCHECK_EQ(ui::VKEY_ESCAPE, accelerator.key_code()); | 659 DCHECK_EQ(ui::VKEY_ESCAPE, accelerator.key_code()); | 
| 480 | 660 | 
| 481 // If the ContentsView does not handle the back action, then this is the | 661 // If the ContentsView does not handle the back action, then this is the | 
| 482 // top level, so we close the app list. | 662 // top level, so we close the app list. | 
| 483 if (!app_list_main_view_->contents_view()->Back()) { | 663 if (!app_list_main_view_->contents_view()->Back()) { | 
| 484 GetWidget()->Deactivate(); | 664 GetWidget()->Deactivate(); | 
| 485 CloseAppList(); | 665 CloseAppList(); | 
| 486 } | 666 } | 
| 487 | 667 | 
| (...skipping 15 matching lines...) Expand all Loading... | |
| 503 | 683 | 
| 504 if (speech_view_) { | 684 if (speech_view_) { | 
| 505 gfx::Rect speech_bounds = centered_bounds; | 685 gfx::Rect speech_bounds = centered_bounds; | 
| 506 int preferred_height = speech_view_->GetPreferredSize().height(); | 686 int preferred_height = speech_view_->GetPreferredSize().height(); | 
| 507 speech_bounds.Inset(kSpeechUIMargin, kSpeechUIMargin); | 687 speech_bounds.Inset(kSpeechUIMargin, kSpeechUIMargin); | 
| 508 speech_bounds.set_height( | 688 speech_bounds.set_height( | 
| 509 std::min(speech_bounds.height(), preferred_height)); | 689 std::min(speech_bounds.height(), preferred_height)); | 
| 510 speech_bounds.Inset(-speech_view_->GetInsets()); | 690 speech_bounds.Inset(-speech_view_->GetInsets()); | 
| 511 speech_view_->SetBoundsRect(speech_bounds); | 691 speech_view_->SetBoundsRect(speech_bounds); | 
| 512 } | 692 } | 
| 693 // If the fullscreen feature has been enabled. | |
| 694 if (launcher_background_shield_) { | |
| 695 app_list_main_view_->contents_view()->Layout(); | |
| 696 launcher_background_shield_->SetBoundsRect(contents_bounds); | |
| 697 } | |
| 513 } | 698 } | 
| 514 | 699 | 
| 515 void AppListView::SchedulePaintInRect(const gfx::Rect& rect) { | 700 void AppListView::SchedulePaintInRect(const gfx::Rect& rect) { | 
| 516 BubbleDialogDelegateView::SchedulePaintInRect(rect); | 701 BubbleDialogDelegateView::SchedulePaintInRect(rect); | 
| 517 if (GetBubbleFrameView()) | 702 if (GetBubbleFrameView()) | 
| 518 GetBubbleFrameView()->SchedulePaint(); | 703 GetBubbleFrameView()->SchedulePaint(); | 
| 519 } | 704 } | 
| 520 | 705 | 
| 706 void AppListView::ToFullscreen() { | |
| 707 fullscreen_widget_bounds_.set_y(0); | |
| 708 fullscreen_widget_->SetBounds(fullscreen_widget_bounds_); | |
| 709 is_fullscreen_launcher_ = true; | |
| 710 launcher_threshold_ = (fullscreen_widget_bounds_.height() + kShelfSize) / | |
| 711 kLauncherThresholdDenominator; | |
| 712 } | |
| 713 | |
| 714 void AppListView::ToPeeking() { | |
| 715 fullscreen_widget_bounds_.set_y(default_peeking_launcher_y_); | |
| 716 fullscreen_widget_->SetBounds(fullscreen_widget_bounds_); | |
| 717 is_fullscreen_launcher_ = false; | |
| 718 launcher_threshold_ = (fullscreen_widget_bounds_.height() + kShelfSize - | |
| 719 kPeekingLauncherHeight) / | |
| 720 kLauncherThresholdDenominator; | |
| 721 } | |
| 722 | |
| 723 bool AppListView::IsFullscreen() const { | |
| 724 return is_fullscreen_launcher_; | |
| 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 Loading... | |
| 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 (launcher_background_shield_) { | |
| 
 
xiyuan
2017/05/30 16:32:34
nit: bail out earlier
i.e.
  if (!launcher_backg
 
newcomer
2017/05/30 21:37:03
Done.
 
 | |
| 814 UpdateDimensions(); | |
| 815 | |
| 816 gfx::Rect recomputed_fullscreen_widget_bounds( | |
| 817 display_work_area_bounds_.x(), default_peeking_launcher_y_, | |
| 818 display_work_area_bounds_.width(), | |
| 819 display_work_area_bounds_.height() + kShelfSize); | |
| 820 | |
| 821 fullscreen_widget_bounds_ = recomputed_fullscreen_widget_bounds; | |
| 822 | |
| 823 if (is_fullscreen_launcher_) { | |
| 824 ToFullscreen(); | |
| 825 } else { | |
| 826 ToPeeking(); | |
| 827 } | |
| 828 } | |
| 829 | |
| 830 Layout(); | |
| 
 
xiyuan
2017/05/30 16:32:34
This is probably not needed since it should be cal
 
newcomer
2017/05/30 21:37:03
Done.
 
 | |
| 831 } | |
| 832 | |
| 605 } // namespace app_list | 833 } // namespace app_list | 
| OLD | NEW |