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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 49 #include "ui/wm/core/masked_window_targeter.h" | 49 #include "ui/wm/core/masked_window_targeter.h" | 
| 50 #include "ui/wm/core/shadow_types.h" | 50 #include "ui/wm/core/shadow_types.h" | 
| 51 | 51 | 
| 52 namespace app_list { | 52 namespace app_list { | 
| 53 | 53 | 
| 54 namespace { | 54 namespace { | 
| 55 | 55 | 
| 56 // The margin from the edge to the speech UI. | 56 // The margin from the edge to the speech UI. | 
| 57 const int kSpeechUIMargin = 12; | 57 const int kSpeechUIMargin = 12; | 
| 58 | 58 | 
| 59 // The height/width of the shelf. | |
| 60 int kShelfSize = 48; | |
| 
 
vadimt
2017/05/26 01:27:57
I hope there is no constant or literal with the sa
 
newcomer
2017/05/26 17:11:27
There is, but it is in Ash which we cannot access
 
vadimt
2017/05/26 17:58:55
Nah, you can just leave this.
 
newcomer
2017/05/26 23:20:20
Acknowledged.
 
 | |
| 61 | |
| 62 // The height of the peeking launcher. | |
| 63 int kPeekingLauncherHeight = 320; | |
| 64 | |
| 65 int kLauncherThresholdDenominator = 3; | |
| 
 
vadimt
2017/05/26 01:27:57
Comments.
 
newcomer
2017/05/26 17:11:27
Done.
 
 | |
| 66 int kLauncherDragVelocityThreshold = 25; | |
| 
 
vadimt
2017/05/26 01:27:57
Comment; it should make it clear what the units ar
 
newcomer
2017/05/26 17:11:27
Done.
 
 | |
| 67 | |
| 59 // The vertical position for the appearing animation of the speech UI. | 68 // The vertical position for the appearing animation of the speech UI. | 
| 60 const float kSpeechUIAppearingPosition = 12; | 69 const float kSpeechUIAppearingPosition = 12; | 
| 61 | 70 | 
| 62 // This view forwards the focus to the search box widget by providing it as a | 71 // This view forwards the focus to the search box widget by providing it as a | 
| 63 // FocusTraversable when a focus search is provided. | 72 // FocusTraversable when a focus search is provided. | 
| 64 class SearchBoxFocusHost : public views::View { | 73 class SearchBoxFocusHost : public views::View { | 
| 65 public: | 74 public: | 
| 66 explicit SearchBoxFocusHost(views::Widget* search_box_widget) | 75 explicit SearchBoxFocusHost(views::Widget* search_box_widget) | 
| 67 : search_box_widget_(search_box_widget) {} | 76 : search_box_widget_(search_box_widget) {} | 
| 68 | 77 | 
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 168 //////////////////////////////////////////////////////////////////////////////// | 177 //////////////////////////////////////////////////////////////////////////////// | 
| 169 // AppListView: | 178 // AppListView: | 
| 170 | 179 | 
| 171 AppListView::AppListView(AppListViewDelegate* delegate) | 180 AppListView::AppListView(AppListViewDelegate* delegate) | 
| 172 : delegate_(delegate), | 181 : delegate_(delegate), | 
| 173 app_list_main_view_(nullptr), | 182 app_list_main_view_(nullptr), | 
| 174 speech_view_(nullptr), | 183 speech_view_(nullptr), | 
| 175 search_box_focus_host_(nullptr), | 184 search_box_focus_host_(nullptr), | 
| 176 search_box_widget_(nullptr), | 185 search_box_widget_(nullptr), | 
| 177 search_box_view_(nullptr), | 186 search_box_view_(nullptr), | 
| 187 fullscreen_widget_bounds_(), | |
| 
 
vadimt
2017/05/26 01:27:57
No need for default constructor here.
 
newcomer
2017/05/26 17:11:27
Done.
 
 | |
| 188 display_observer_(this), | |
| 178 overlay_view_(nullptr), | 189 overlay_view_(nullptr), | 
| 179 animation_observer_(new HideViewAnimationObserver()) { | 190 animation_observer_(new HideViewAnimationObserver()) { | 
| 180 CHECK(delegate); | 191 CHECK(delegate); | 
| 181 | 192 | 
| 182 delegate_->GetSpeechUI()->AddObserver(this); | 193 delegate_->GetSpeechUI()->AddObserver(this); | 
| 194 | |
| 195 if (features::IsFullscreenAppListEnabled()) | |
| 196 display_observer_.Add(display::Screen::GetScreen()); | |
| 197 | |
| 198 // display::Screen::GetScreen()->AddObserver(this); | |
| 
 
vadimt
2017/05/26 01:27:57
Remove
 
newcomer
2017/05/26 17:11:27
Done.
 
 | |
| 183 } | 199 } | 
| 184 | 200 | 
| 185 AppListView::~AppListView() { | 201 AppListView::~AppListView() { | 
| 202 // Remove this instance from the DisplayManager's list of observers. | |
| 203 if (features::IsFullscreenAppListEnabled()) | |
| 204 display_observer_.Remove(display::Screen::GetScreen()); | |
| 205 // display::Screen::GetScreen()->RemoveObserver(this); | |
| 
 
vadimt
2017/05/26 01:27:56
Remove
 
newcomer
2017/05/26 17:11:27
Done.
 
 | |
| 206 | |
| 186 delegate_->GetSpeechUI()->RemoveObserver(this); | 207 delegate_->GetSpeechUI()->RemoveObserver(this); | 
| 187 animation_observer_.reset(); | 208 animation_observer_.reset(); | 
| 188 // Remove child views first to ensure no remaining dependencies on delegate_. | 209 // Remove child views first to ensure no remaining dependencies on delegate_. | 
| 189 RemoveAllChildViews(true); | 210 RemoveAllChildViews(true); | 
| 190 } | 211 } | 
| 191 | 212 | 
| 192 void AppListView::Initialize(gfx::NativeView parent, int initial_apps_page) { | 213 void AppListView::Initialize(gfx::NativeView parent, int initial_apps_page) { | 
| 193 base::Time start_time = base::Time::Now(); | 214 base::Time start_time = base::Time::Now(); | 
| 194 InitContents(parent, initial_apps_page); | 215 InitContents(parent, initial_apps_page); | 
| 195 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); | 216 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); | 
| 196 set_color(kContentsBackgroundColor); | 217 set_color(kContentsBackgroundColor); | 
| 197 set_parent_window(parent); | 218 set_parent_window(parent); | 
| 198 | 219 | 
| 199 if (features::IsFullscreenAppListEnabled()) | 220 if (features::IsFullscreenAppListEnabled()) | 
| 200 InitializeFullscreen(parent, initial_apps_page); | 221 InitializeFullscreen(parent, initial_apps_page); | 
| 201 else | 222 else | 
| 202 InitializeBubble(parent, initial_apps_page); | 223 InitializeBubble(parent, initial_apps_page); | 
| 203 | 224 | 
| 204 InitChildWidgets(); | 225 InitChildWidgets(); | 
| 205 AddChildView(overlay_view_); | 226 AddChildView(overlay_view_); | 
| 227 | |
| 206 if (delegate_) | 228 if (delegate_) | 
| 207 delegate_->ViewInitialized(); | 229 delegate_->ViewInitialized(); | 
| 230 | |
| 208 UMA_HISTOGRAM_TIMES("Apps.AppListCreationTime", | 231 UMA_HISTOGRAM_TIMES("Apps.AppListCreationTime", | 
| 209 base::Time::Now() - start_time); | 232 base::Time::Now() - start_time); | 
| 210 } | 233 } | 
| 211 | 234 | 
| 212 void AppListView::SetBubbleArrow(views::BubbleBorder::Arrow arrow) { | 235 void AppListView::SetBubbleArrow(views::BubbleBorder::Arrow arrow) { | 
| 213 GetBubbleFrameView()->bubble_border()->set_arrow(arrow); | 236 GetBubbleFrameView()->bubble_border()->set_arrow(arrow); | 
| 214 SizeToContents(); // Recalcuates with new border. | 237 SizeToContents(); // Recalcuates with new border. | 
| 215 GetBubbleFrameView()->SchedulePaint(); | 238 GetBubbleFrameView()->SchedulePaint(); | 
| 216 } | 239 } | 
| 217 | 240 | 
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 323 ->pagination_model(); | 346 ->pagination_model(); | 
| 324 } | 347 } | 
| 325 | 348 | 
| 326 void AppListView::InitContents(gfx::NativeView parent, int initial_apps_page) { | 349 void AppListView::InitContents(gfx::NativeView parent, int initial_apps_page) { | 
| 327 // TODO(vadimt): Remove ScopedTracker below once crbug.com/440224 and | 350 // TODO(vadimt): Remove ScopedTracker below once crbug.com/440224 and | 
| 328 // crbug.com/441028 are fixed. | 351 // crbug.com/441028 are fixed. | 
| 329 tracked_objects::ScopedTracker tracking_profile( | 352 tracked_objects::ScopedTracker tracking_profile( | 
| 330 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 353 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 
| 331 "440224, 441028 AppListView::InitContents")); | 354 "440224, 441028 AppListView::InitContents")); | 
| 332 | 355 | 
| 356 if (features::IsFullscreenAppListEnabled()) { | |
| 357 // The shield view that colors the background of the launcher and makes it | |
| 358 // transparent. | |
| 359 launcher_background_shield_ = new views::View; | |
| 360 launcher_background_shield_->SetPaintToLayer(ui::LAYER_SOLID_COLOR); | |
| 361 launcher_background_shield_->layer()->SetColor(SK_ColorBLACK); | |
| 362 launcher_background_shield_->layer()->SetOpacity(0.8f); | |
| 
 
vadimt
2017/05/26 01:27:57
Constant.
 
newcomer
2017/05/26 17:11:27
Done.
 
 | |
| 363 AddChildView(launcher_background_shield_); | |
| 364 } | |
| 333 app_list_main_view_ = new AppListMainView(delegate_); | 365 app_list_main_view_ = new AppListMainView(delegate_); | 
| 334 AddChildView(app_list_main_view_); | 366 AddChildView(app_list_main_view_); | 
| 335 app_list_main_view_->SetPaintToLayer(); | 367 app_list_main_view_->SetPaintToLayer(); | 
| 336 app_list_main_view_->layer()->SetFillsBoundsOpaquely(false); | 368 app_list_main_view_->layer()->SetFillsBoundsOpaquely(false); | 
| 337 app_list_main_view_->layer()->SetMasksToBounds(true); | 369 app_list_main_view_->layer()->SetMasksToBounds(true); | 
| 338 // This will be added to the |search_box_widget_| after the app list widget is | 370 // This will be added to the |search_box_widget_| after the app list widget is | 
| 339 // initialized. | 371 // initialized. | 
| 340 search_box_view_ = new SearchBoxView(app_list_main_view_, delegate_); | 372 search_box_view_ = new SearchBoxView(app_list_main_view_, delegate_); | 
| 373 search_box_view_->SetAppListView(this); | |
| 341 search_box_view_->SetPaintToLayer(); | 374 search_box_view_->SetPaintToLayer(); | 
| 342 search_box_view_->layer()->SetFillsBoundsOpaquely(false); | 375 search_box_view_->layer()->SetFillsBoundsOpaquely(false); | 
| 343 search_box_view_->layer()->SetMasksToBounds(true); | 376 search_box_view_->layer()->SetMasksToBounds(true); | 
| 344 | 377 | 
| 345 // TODO(vadimt): Remove ScopedTracker below once crbug.com/440224 and | 378 // TODO(vadimt): Remove ScopedTracker below once crbug.com/440224 and | 
| 346 // crbug.com/441028 are fixed. | 379 // crbug.com/441028 are fixed. | 
| 347 tracked_objects::ScopedTracker tracking_profile1( | 380 tracked_objects::ScopedTracker tracking_profile1( | 
| 348 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 381 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 
| 349 "440224, 441028 AppListView::InitContents1")); | 382 "440224, 441028 AppListView::InitContents1")); | 
| 350 | 383 | 
| 351 app_list_main_view_->Init(parent, initial_apps_page, search_box_view_); | 384 app_list_main_view_->Init(parent, initial_apps_page, search_box_view_, this); | 
| 352 | 385 | 
| 353 // TODO(vadimt): Remove ScopedTracker below once crbug.com/440224 and | 386 // TODO(vadimt): Remove ScopedTracker below once crbug.com/440224 and | 
| 354 // crbug.com/441028 are fixed. | 387 // crbug.com/441028 are fixed. | 
| 355 tracked_objects::ScopedTracker tracking_profile2( | 388 tracked_objects::ScopedTracker tracking_profile2( | 
| 356 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 389 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 
| 357 "440224, 441028 AppListView::InitContents2")); | 390 "440224, 441028 AppListView::InitContents2")); | 
| 358 | 391 | 
| 359 // Speech recognition is available only when the start page exists. | 392 // Speech recognition is available only when the start page exists. | 
| 360 if (delegate_ && delegate_->IsSpeechRecognitionEnabled()) { | 393 if (delegate_ && delegate_->IsSpeechRecognitionEnabled()) { | 
| 361 speech_view_ = new SpeechView(delegate_); | 394 speech_view_ = new SpeechView(delegate_); | 
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 397 // Mouse events on the search box shadow should not be captured. | 430 // Mouse events on the search box shadow should not be captured. | 
| 398 aura::Window* window = search_box_widget_->GetNativeWindow(); | 431 aura::Window* window = search_box_widget_->GetNativeWindow(); | 
| 399 window->SetEventTargeter( | 432 window->SetEventTargeter( | 
| 400 base::MakeUnique<SearchBoxWindowTargeter>(search_box_view_)); | 433 base::MakeUnique<SearchBoxWindowTargeter>(search_box_view_)); | 
| 401 | 434 | 
| 402 app_list_main_view_->contents_view()->Layout(); | 435 app_list_main_view_->contents_view()->Layout(); | 
| 403 } | 436 } | 
| 404 | 437 | 
| 405 void AppListView::InitializeFullscreen(gfx::NativeView parent, | 438 void AppListView::InitializeFullscreen(gfx::NativeView parent, | 
| 406 int initial_apps_page) { | 439 int initial_apps_page) { | 
| 407 views::Widget* widget = new views::Widget; | 440 UpdateDimensions(); | 
| 441 | |
| 442 gfx::Rect app_list_overlay_view_bounds( | |
| 443 display_work_area_bounds_.x(), default_peeking_launcher_y_, | |
| 444 display_work_area_bounds_.width(), | |
| 445 display_work_area_bounds_.height() + kShelfSize); | |
| 446 | |
| 447 fullscreen_widget_ = new views::Widget; | |
| 408 views::Widget::InitParams app_list_overlay_view_params( | 448 views::Widget::InitParams app_list_overlay_view_params( | 
| 409 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 449 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 
| 410 | 450 | 
| 451 app_list_overlay_view_params.name = "AppList"; | |
| 411 app_list_overlay_view_params.parent = parent; | 452 app_list_overlay_view_params.parent = parent; | 
| 412 app_list_overlay_view_params.delegate = this; | 453 app_list_overlay_view_params.delegate = this; | 
| 413 app_list_overlay_view_params.opacity = | 454 app_list_overlay_view_params.opacity = | 
| 414 views::Widget::InitParams::TRANSLUCENT_WINDOW; | 455 views::Widget::InitParams::TRANSLUCENT_WINDOW; | 
| 415 app_list_overlay_view_params.bounds = | 456 app_list_overlay_view_params.bounds = app_list_overlay_view_bounds; | 
| 416 display::Screen::GetScreen()-> | 457 app_list_overlay_view_params.layer_type = ui::LAYER_SOLID_COLOR; | 
| 417 GetDisplayNearestView(parent).work_area(); | 458 fullscreen_widget_->Init(app_list_overlay_view_params); | 
| 418 widget->Init(app_list_overlay_view_params); | |
| 419 widget->GetLayer()->SetBackgroundBlur(10); | |
| 420 | 459 | 
| 460 fullscreen_widget_bounds_ = fullscreen_widget_->GetWindowBoundsInScreen(); | |
| 421 overlay_view_ = new AppListOverlayView(0 /* no corners */); | 461 overlay_view_ = new AppListOverlayView(0 /* no corners */); | 
| 462 | |
| 463 // Launcher + shelf height, used in HandleDrag. | |
| 464 launcher_threshold_ = | |
| 465 (default_peeking_launcher_y_ + fullscreen_widget_bounds_.height() - | |
| 466 fullscreen_widget_bounds_.y()) / | |
| 467 kLauncherThresholdDenominator; | |
| 422 } | 468 } | 
| 423 | 469 | 
| 424 void AppListView::InitializeBubble(gfx::NativeView parent, | 470 void AppListView::InitializeBubble(gfx::NativeView parent, | 
| 425 int initial_apps_page) { | 471 int initial_apps_page) { | 
| 426 set_margins(gfx::Insets()); | 472 set_margins(gfx::Insets()); | 
| 427 set_close_on_deactivate(false); | 473 set_close_on_deactivate(false); | 
| 428 set_shadow(views::BubbleBorder::NO_ASSETS); | 474 set_shadow(views::BubbleBorder::NO_ASSETS); | 
| 429 | 475 | 
| 430 // 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 | 
| 431 // created.) | 477 // created. | 
| 432 views::BubbleDialogDelegateView::CreateBubble(this); | 478 views::BubbleDialogDelegateView::CreateBubble(this); | 
| 433 | 479 | 
| 434 SetBubbleArrow(views::BubbleBorder::FLOAT); | 480 SetBubbleArrow(views::BubbleBorder::FLOAT); | 
| 435 // We can now create the internal widgets. | 481 // We can now create the internal widgets. | 
| 436 | 482 | 
| 437 aura::Window* window = GetWidget()->GetNativeWindow(); | 483 aura::Window* window = GetWidget()->GetNativeWindow(); | 
| 438 window->SetEventTargeter(base::MakeUnique<views::BubbleWindowTargeter>(this)); | 484 window->SetEventTargeter(base::MakeUnique<views::BubbleWindowTargeter>(this)); | 
| 439 | 485 | 
| 440 const int kOverlayCornerRadius = | 486 const int kOverlayCornerRadius = | 
| 441 GetBubbleFrameView()->bubble_border()->GetBorderCornerRadius(); | 487 GetBubbleFrameView()->bubble_border()->GetBorderCornerRadius(); | 
| 442 overlay_view_ = new AppListOverlayView(kOverlayCornerRadius); | 488 overlay_view_ = new AppListOverlayView(kOverlayCornerRadius); | 
| 443 overlay_view_->SetBoundsRect(GetContentsBounds()); | 489 overlay_view_->SetBoundsRect(GetContentsBounds()); | 
| 444 } | 490 } | 
| 445 | 491 | 
| 492 void AppListView::HandleDrag(gfx::Point location, ui::EventType type) { | |
| 493 int new_y_position; | |
| 
 
vadimt
2017/05/26 01:27:57
Make a constant variable in each switch branches,
 
newcomer
2017/05/26 17:11:27
Done.
 
 | |
| 494 switch (type) { | |
| 495 case ui::ET_GESTURE_SCROLL_BEGIN: | |
| 496 case ui::ET_MOUSE_PRESSED: { | |
| 497 // Drag start, grab the initial_drag_separation_ to maintain the relative | |
| 498 // position of the top of the widget and the mouse/gesture. | |
| 499 initial_drag_separation_ = location.y(); | |
| 500 fullscreen_widget_bounds_ = fullscreen_widget_->GetWindowBoundsInScreen(); | |
| 501 break; | |
| 502 } | |
| 503 case ui::ET_GESTURE_SCROLL_UPDATE: | |
| 504 case ui::ET_MOUSE_DRAGGED: { | |
| 505 // Drag update, update the bounds of the widget while maintaining the | |
| 506 // relative position of the top of the widget and the mouse/gesture. | |
| 507 // Block drags north of 0 and recalculate the initial_drag_separation_. | |
| 508 new_y_position = location.y() - initial_drag_separation_ + | |
| 509 fullscreen_widget_bounds_.y(); | |
| 510 if (new_y_position < 0) { | |
| 511 fullscreen_widget_bounds_.set_y(0); | |
| 512 initial_drag_separation_ = location.y(); | |
| 513 } else { | |
| 514 fullscreen_widget_bounds_.set_y(new_y_position); | |
| 515 } | |
| 516 fullscreen_widget_->SetBounds(fullscreen_widget_bounds_); | |
| 517 break; | |
| 518 } | |
| 519 | |
| 520 case ui::ET_GESTURE_END: | |
| 521 case ui::ET_MOUSE_RELEASED: { | |
| 522 // Drag completion, either snap to fullscreen or close the App List based | |
| 523 // on where the drag ended. If fling velocity was over the threshold, snap | |
| 524 // to the next state in the direction of the fling. | |
| 525 new_y_position = location.y() - initial_drag_separation_ + | |
| 526 fullscreen_widget_bounds_.y(); | |
| 527 if (std::abs(last_fling_velocity_) > kLauncherDragVelocityThreshold) { | |
| 528 // If the user releases drag with velocity over the threshold, snap to | |
| 529 // the next state, ignoring the drag release position. | |
| 530 if (is_fullscreen_launcher_) { | |
| 531 if (last_fling_velocity_ > 0) | |
| 532 ToPeeking(); | |
| 
 
vadimt
2017/05/26 01:27:57
{}, as this is a complex if
 
newcomer
2017/05/26 17:11:27
Done.
 
 | |
| 533 } else { | |
| 534 if (last_fling_velocity_ > 0) { | |
| 
 
vadimt
2017/05/26 01:27:57
No need for placing 'else' contents in {}, unless
 
newcomer
2017/05/26 17:11:27
I did it for clarity but I see how it isn't necess
 
 | |
| 535 CloseAppList(); | |
| 536 } else if (last_fling_velocity_ < 0) { | |
| 537 ToFullscreen(); | |
| 538 } | |
| 539 } | |
| 540 last_fling_velocity_ = 0; | |
| 541 } else { | |
| 542 // The drag release velocity was too low, so use the release point. | |
| 543 int launcher_snap_y = | |
| 544 is_fullscreen_launcher_ ? 0 : default_peeking_launcher_y_; | |
| 545 // If the user releases +/- 1/3 of launcher_threshold_ , snap to the | |
| 546 // next state. | |
| 547 if (std::abs(launcher_snap_y - new_y_position) < | |
| 548 (launcher_threshold_)) { | |
| 549 // If the drag released to the state above. | |
| 550 if (is_fullscreen_launcher_) { | |
| 551 ToFullscreen(); | |
| 552 } else { | |
| 553 ToPeeking(); | |
| 554 } | |
| 555 } else if ((launcher_snap_y + (launcher_threshold_)) < new_y_position) { | |
| 556 // If the user released to the state below. | |
| 557 if (is_fullscreen_launcher_) { | |
| 558 ToPeeking(); | |
| 559 } else { | |
| 560 CloseAppList(); | |
| 561 } | |
| 562 } else { | |
| 563 // if the user released to the state above, go to the state above. | |
| 564 ToFullscreen(); | |
| 565 } | |
| 566 } | |
| 567 break; | |
| 568 } | |
| 569 default: | |
| 570 NOTREACHED(); | |
| 571 break; | |
| 572 } | |
| 573 } | |
| 574 | |
| 446 void AppListView::OnBeforeBubbleWidgetInit(views::Widget::InitParams* params, | 575 void AppListView::OnBeforeBubbleWidgetInit(views::Widget::InitParams* params, | 
| 447 views::Widget* widget) const { | 576 views::Widget* widget) const { | 
| 448 if (!params->native_widget) { | 577 if (!params->native_widget) { | 
| 449 views::ViewsDelegate* views_delegate = views::ViewsDelegate::GetInstance(); | 578 views::ViewsDelegate* views_delegate = views::ViewsDelegate::GetInstance(); | 
| 450 if (views_delegate && !views_delegate->native_widget_factory().is_null()) { | 579 if (views_delegate && !views_delegate->native_widget_factory().is_null()) { | 
| 451 params->native_widget = | 580 params->native_widget = | 
| 452 views_delegate->native_widget_factory().Run(*params, widget); | 581 views_delegate->native_widget_factory().Run(*params, widget); | 
| 453 } | 582 } | 
| 454 } | 583 } | 
| 455 // Apply a WM-provided shadow (see ui/wm/core/). | 584 // Apply a WM-provided shadow (see ui/wm/core/). | 
| (...skipping 13 matching lines...) Expand all Loading... | |
| 469 return GetBubbleFrameView() != nullptr; | 598 return GetBubbleFrameView() != nullptr; | 
| 470 } | 599 } | 
| 471 | 600 | 
| 472 void AppListView::GetWidgetHitTestMask(gfx::Path* mask) const { | 601 void AppListView::GetWidgetHitTestMask(gfx::Path* mask) const { | 
| 473 DCHECK(mask); | 602 DCHECK(mask); | 
| 474 DCHECK(GetBubbleFrameView()); | 603 DCHECK(GetBubbleFrameView()); | 
| 475 | 604 | 
| 476 mask->addRect(gfx::RectToSkRect(GetBubbleFrameView()->GetContentsBounds())); | 605 mask->addRect(gfx::RectToSkRect(GetBubbleFrameView()->GetContentsBounds())); | 
| 477 } | 606 } | 
| 478 | 607 | 
| 608 void AppListView::OnMouseEvent(ui::MouseEvent* event) { | |
| 609 if (!launcher_background_shield_) | |
| 610 return; | |
| 611 | |
| 612 switch (event->type()) { | |
| 613 case ui::ET_MOUSE_PRESSED: | |
| 614 case ui::ET_MOUSE_DRAGGED: | |
| 615 case ui::ET_MOUSE_RELEASED: | |
| 616 HandleDrag(event->location(), event->type()); | |
| 617 event->SetHandled(); | |
| 618 break; | |
| 619 default: | |
| 620 break; | |
| 621 } | |
| 622 } | |
| 623 | |
| 624 void AppListView::OnGestureEvent(ui::GestureEvent* event) { | |
| 625 if (!launcher_background_shield_) | |
| 626 return; | |
| 627 switch (event->type()) { | |
| 
 
vadimt
2017/05/26 01:27:57
Empty line before.
 
newcomer
2017/05/26 17:11:27
Done.
 
 | |
| 628 case ui::ET_GESTURE_SCROLL_UPDATE: | |
| 629 last_fling_velocity_ = event->details().velocity_y(); | |
| 
 
vadimt
2017/05/26 01:27:57
break;
If this is what you wanted, this don't use
 
newcomer
2017/05/26 17:11:27
Done.
 
 | |
| 630 case ui::ET_GESTURE_SCROLL_BEGIN: | |
| 631 case ui::ET_GESTURE_END: | |
| 632 HandleDrag(event->location(), event->type()); | |
| 633 event->SetHandled(); | |
| 634 break; | |
| 635 default: | |
| 636 break; | |
| 637 } | |
| 638 } | |
| 639 | |
| 479 bool AppListView::AcceleratorPressed(const ui::Accelerator& accelerator) { | 640 bool AppListView::AcceleratorPressed(const ui::Accelerator& accelerator) { | 
| 480 DCHECK_EQ(ui::VKEY_ESCAPE, accelerator.key_code()); | 641 DCHECK_EQ(ui::VKEY_ESCAPE, accelerator.key_code()); | 
| 481 | 642 | 
| 482 // If the ContentsView does not handle the back action, then this is the | 643 // If the ContentsView does not handle the back action, then this is the | 
| 483 // top level, so we close the app list. | 644 // top level, so we close the app list. | 
| 484 if (!app_list_main_view_->contents_view()->Back()) { | 645 if (!app_list_main_view_->contents_view()->Back()) { | 
| 485 GetWidget()->Deactivate(); | 646 GetWidget()->Deactivate(); | 
| 486 CloseAppList(); | 647 CloseAppList(); | 
| 487 } | 648 } | 
| 488 | 649 | 
| 489 // Don't let DialogClientView handle the accelerator. | 650 // Don't let DialogClientView handle the accelerator. | 
| 490 return true; | 651 return true; | 
| 491 } | 652 } | 
| 492 | 653 | 
| 493 void AppListView::Layout() { | 654 void AppListView::Layout() { | 
| 655 // If the fullscreen feature has been enabled. | |
| 656 if (launcher_background_shield_) { | |
| 657 UpdateDimensions(); | |
| 658 | |
| 659 gfx::Rect recomputed_fullscreen_widget_bounds( | |
| 660 display_work_area_bounds_.x(), default_peeking_launcher_y_, | |
| 661 display_work_area_bounds_.width(), | |
| 662 display_work_area_bounds_.height() + kShelfSize); | |
| 663 | |
| 664 fullscreen_widget_bounds_ = recomputed_fullscreen_widget_bounds; | |
| 665 | |
| 666 if (is_fullscreen_launcher_) { | |
| 667 ToFullscreen(); | |
| 668 } else { | |
| 669 ToPeeking(); | |
| 670 } | |
| 671 } | |
| 494 const gfx::Rect contents_bounds = GetContentsBounds(); | 672 const gfx::Rect contents_bounds = GetContentsBounds(); | 
| 495 | 673 | 
| 496 // Make sure to layout |app_list_main_view_| and |speech_view_| at the center | 674 // Make sure to layout |app_list_main_view_| and |speech_view_| at the center | 
| 497 // of the widget. | 675 // of the widget. | 
| 498 gfx::Rect centered_bounds = contents_bounds; | 676 gfx::Rect centered_bounds = contents_bounds; | 
| 499 centered_bounds.ClampToCenteredSize(gfx::Size( | 677 centered_bounds.ClampToCenteredSize(gfx::Size( | 
| 500 app_list_main_view_->contents_view()->GetDefaultContentsBounds().width(), | 678 app_list_main_view_->contents_view()->GetDefaultContentsBounds().width(), | 
| 501 contents_bounds.height())); | 679 contents_bounds.height())); | 
| 502 | 680 | 
| 503 app_list_main_view_->SetBoundsRect(centered_bounds); | 681 app_list_main_view_->SetBoundsRect(centered_bounds); | 
| 504 | 682 | 
| 505 if (speech_view_) { | 683 if (speech_view_) { | 
| 506 gfx::Rect speech_bounds = centered_bounds; | 684 gfx::Rect speech_bounds = centered_bounds; | 
| 507 int preferred_height = speech_view_->GetPreferredSize().height(); | 685 int preferred_height = speech_view_->GetPreferredSize().height(); | 
| 508 speech_bounds.Inset(kSpeechUIMargin, kSpeechUIMargin); | 686 speech_bounds.Inset(kSpeechUIMargin, kSpeechUIMargin); | 
| 509 speech_bounds.set_height( | 687 speech_bounds.set_height( | 
| 510 std::min(speech_bounds.height(), preferred_height)); | 688 std::min(speech_bounds.height(), preferred_height)); | 
| 511 speech_bounds.Inset(-speech_view_->GetInsets()); | 689 speech_bounds.Inset(-speech_view_->GetInsets()); | 
| 512 speech_view_->SetBoundsRect(speech_bounds); | 690 speech_view_->SetBoundsRect(speech_bounds); | 
| 513 } | 691 } | 
| 692 // If the fullscreen feature has been enabled. | |
| 693 if (launcher_background_shield_) { | |
| 694 app_list_main_view_->contents_view()->Layout(); | |
| 695 launcher_background_shield_->SetBoundsRect(contents_bounds); | |
| 696 } | |
| 514 } | 697 } | 
| 515 | 698 | 
| 516 void AppListView::SchedulePaintInRect(const gfx::Rect& rect) { | 699 void AppListView::SchedulePaintInRect(const gfx::Rect& rect) { | 
| 517 BubbleDialogDelegateView::SchedulePaintInRect(rect); | 700 BubbleDialogDelegateView::SchedulePaintInRect(rect); | 
| 518 if (GetBubbleFrameView()) | 701 if (GetBubbleFrameView()) | 
| 519 GetBubbleFrameView()->SchedulePaint(); | 702 GetBubbleFrameView()->SchedulePaint(); | 
| 520 } | 703 } | 
| 521 | 704 | 
| 705 void AppListView::UpdateDimensions() { | |
| 706 display_work_area_bounds_ = display::Screen::GetScreen() | |
| 707 ->GetDisplayNearestView(parent_window()) | |
| 708 .work_area(); | |
| 709 default_peeking_launcher_y_ = | |
| 710 display_work_area_bounds_.height() + kShelfSize - kPeekingLauncherHeight; | |
| 711 } | |
| 712 | |
| 713 void AppListView::ToFullscreen() { | |
| 714 fullscreen_widget_bounds_.set_y(0); | |
| 715 fullscreen_widget_->SetBounds(fullscreen_widget_bounds_); | |
| 716 is_fullscreen_launcher_ = true; | |
| 717 launcher_threshold_ = (fullscreen_widget_bounds_.height() + kShelfSize) / | |
| 718 kLauncherThresholdDenominator; | |
| 719 } | |
| 720 | |
| 721 void AppListView::ToPeeking() { | |
| 722 fullscreen_widget_bounds_.set_y(default_peeking_launcher_y_); | |
| 723 fullscreen_widget_->SetBounds(fullscreen_widget_bounds_); | |
| 724 is_fullscreen_launcher_ = false; | |
| 725 launcher_threshold_ = (fullscreen_widget_bounds_.height() + kShelfSize - | |
| 726 kPeekingLauncherHeight) / | |
| 727 kLauncherThresholdDenominator; | |
| 728 } | |
| 729 | |
| 730 bool AppListView::IsFullscreen() const { | |
| 731 return is_fullscreen_launcher_; | |
| 732 } | |
| 733 | |
| 522 void AppListView::OnWidgetDestroying(views::Widget* widget) { | 734 void AppListView::OnWidgetDestroying(views::Widget* widget) { | 
| 523 BubbleDialogDelegateView::OnWidgetDestroying(widget); | 735 BubbleDialogDelegateView::OnWidgetDestroying(widget); | 
| 524 if (delegate_ && widget == GetWidget()) | 736 if (delegate_ && widget == GetWidget()) | 
| 525 delegate_->ViewClosing(); | 737 delegate_->ViewClosing(); | 
| 526 } | 738 } | 
| 527 | 739 | 
| 528 void AppListView::OnWidgetVisibilityChanged(views::Widget* widget, | 740 void AppListView::OnWidgetVisibilityChanged(views::Widget* widget, | 
| 529 bool visible) { | 741 bool visible) { | 
| 530 BubbleDialogDelegateView::OnWidgetVisibilityChanged(widget, visible); | 742 BubbleDialogDelegateView::OnWidgetVisibilityChanged(widget, visible); | 
| 531 | 743 | 
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 596 } else { | 808 } else { | 
| 597 app_list_main_view_->SetVisible(true); | 809 app_list_main_view_->SetVisible(true); | 
| 598 // Refocus the search box. However, if the app list widget does not have | 810 // Refocus the search box. However, if the app list widget does not have | 
| 599 // focus, it means another window has already taken focus, and we *must not* | 811 // focus, it means another window has already taken focus, and we *must not* | 
| 600 // focus the search box (or we would steal focus back into the app list). | 812 // focus the search box (or we would steal focus back into the app list). | 
| 601 if (GetWidget()->IsActive()) | 813 if (GetWidget()->IsActive()) | 
| 602 search_box_view_->search_box()->RequestFocus(); | 814 search_box_view_->search_box()->RequestFocus(); | 
| 603 } | 815 } | 
| 604 } | 816 } | 
| 605 | 817 | 
| 818 void AppListView::OnDisplayMetricsChanged(const display::Display& display, | |
| 819 uint32_t changed_metrics) { | |
| 820 Layout(); | |
| 821 } | |
| 822 | |
| 606 } // namespace app_list | 823 } // namespace app_list | 
| OLD | NEW |