| 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 // The velocity the app list must be dragged in order to transition to the next | 68 // The velocity the app list must be dragged in order to transition to the next |
| 69 // state, measured in DIPs/event. | 69 // state, measured in DIPs/event. |
| 70 constexpr int kAppListDragVelocityThreshold = 25; | 70 constexpr int kAppListDragVelocityThreshold = 25; |
| 71 | 71 |
| 72 // The opacity of the app list background. | 72 // The opacity of the app list background. |
| 73 constexpr float kAppListOpacity = 0.8; | 73 constexpr float kAppListOpacity = 0.8; |
| 74 | 74 |
| 75 // The vertical position for the appearing animation of the speech UI. | 75 // The vertical position for the appearing animation of the speech UI. |
| 76 constexpr float kSpeechUIAppearingPosition = 12; | 76 constexpr float kSpeechUIAppearingPosition = 12; |
| 77 | 77 |
| 78 bool IsFullscreenAppListEnabled() { | |
| 79 // Cache this value to avoid repeated lookup. | |
| 80 static bool cached_value = features::IsFullscreenAppListEnabled(); | |
| 81 return cached_value; | |
| 82 } | |
| 83 | |
| 84 // 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 |
| 85 // FocusTraversable when a focus search is provided. | 79 // FocusTraversable when a focus search is provided. |
| 86 class SearchBoxFocusHost : public views::View { | 80 class SearchBoxFocusHost : public views::View { |
| 87 public: | 81 public: |
| 88 explicit SearchBoxFocusHost(views::Widget* search_box_widget) | 82 explicit SearchBoxFocusHost(views::Widget* search_box_widget) |
| 89 : search_box_widget_(search_box_widget) {} | 83 : search_box_widget_(search_box_widget) {} |
| 90 | 84 |
| 91 ~SearchBoxFocusHost() override {} | 85 ~SearchBoxFocusHost() override {} |
| 92 | 86 |
| 93 views::FocusTraversable* GetFocusTraversable() override { | 87 views::FocusTraversable* GetFocusTraversable() override { |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 //////////////////////////////////////////////////////////////////////////////// | 184 //////////////////////////////////////////////////////////////////////////////// |
| 191 // AppListView: | 185 // AppListView: |
| 192 | 186 |
| 193 AppListView::AppListView(AppListViewDelegate* delegate) | 187 AppListView::AppListView(AppListViewDelegate* delegate) |
| 194 : delegate_(delegate), | 188 : delegate_(delegate), |
| 195 app_list_main_view_(nullptr), | 189 app_list_main_view_(nullptr), |
| 196 speech_view_(nullptr), | 190 speech_view_(nullptr), |
| 197 search_box_focus_host_(nullptr), | 191 search_box_focus_host_(nullptr), |
| 198 search_box_widget_(nullptr), | 192 search_box_widget_(nullptr), |
| 199 search_box_view_(nullptr), | 193 search_box_view_(nullptr), |
| 194 is_fullscreen_app_list_enabled_(features::IsFullscreenAppListEnabled()), |
| 200 app_list_state_(PEEKING), | 195 app_list_state_(PEEKING), |
| 201 display_observer_(this), | 196 display_observer_(this), |
| 202 overlay_view_(nullptr), | 197 overlay_view_(nullptr), |
| 203 animation_observer_(new HideViewAnimationObserver()) { | 198 animation_observer_(new HideViewAnimationObserver()) { |
| 204 CHECK(delegate); | 199 CHECK(delegate); |
| 205 | |
| 206 delegate_->GetSpeechUI()->AddObserver(this); | 200 delegate_->GetSpeechUI()->AddObserver(this); |
| 207 | 201 |
| 208 if (IsFullscreenAppListEnabled()) | 202 if (is_fullscreen_app_list_enabled_) |
| 209 display_observer_.Add(display::Screen::GetScreen()); | 203 display_observer_.Add(display::Screen::GetScreen()); |
| 210 } | 204 } |
| 211 | 205 |
| 212 AppListView::~AppListView() { | 206 AppListView::~AppListView() { |
| 213 delegate_->GetSpeechUI()->RemoveObserver(this); | 207 delegate_->GetSpeechUI()->RemoveObserver(this); |
| 214 animation_observer_.reset(); | 208 animation_observer_.reset(); |
| 215 // Remove child views first to ensure no remaining dependencies on delegate_. | 209 // Remove child views first to ensure no remaining dependencies on delegate_. |
| 216 RemoveAllChildViews(true); | 210 RemoveAllChildViews(true); |
| 217 } | 211 } |
| 218 | 212 |
| 219 void AppListView::Initialize(gfx::NativeView parent, int initial_apps_page) { | 213 void AppListView::Initialize(gfx::NativeView parent, int initial_apps_page) { |
| 220 base::Time start_time = base::Time::Now(); | 214 base::Time start_time = base::Time::Now(); |
| 221 InitContents(parent, initial_apps_page); | 215 InitContents(parent, initial_apps_page); |
| 222 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); | 216 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); |
| 223 set_color(kContentsBackgroundColor); | 217 set_color(kContentsBackgroundColor); |
| 224 set_parent_window(parent); | 218 set_parent_window(parent); |
| 225 | 219 |
| 226 if (IsFullscreenAppListEnabled()) | 220 if (is_fullscreen_app_list_enabled_) |
| 227 InitializeFullscreen(parent, initial_apps_page); | 221 InitializeFullscreen(parent, initial_apps_page); |
| 228 else | 222 else |
| 229 InitializeBubble(parent, initial_apps_page); | 223 InitializeBubble(parent, initial_apps_page); |
| 230 | 224 |
| 231 InitChildWidgets(); | 225 InitChildWidgets(); |
| 232 AddChildView(overlay_view_); | 226 AddChildView(overlay_view_); |
| 233 | 227 |
| 234 if (IsFullscreenAppListEnabled()) | 228 if (is_fullscreen_app_list_enabled_) |
| 235 SetState(app_list_state_); | 229 SetState(app_list_state_); |
| 236 | 230 |
| 237 if (delegate_) | 231 if (delegate_) |
| 238 delegate_->ViewInitialized(); | 232 delegate_->ViewInitialized(); |
| 239 | 233 |
| 240 UMA_HISTOGRAM_TIMES("Apps.AppListCreationTime", | 234 UMA_HISTOGRAM_TIMES("Apps.AppListCreationTime", |
| 241 base::Time::Now() - start_time); | 235 base::Time::Now() - start_time); |
| 242 } | 236 } |
| 243 | 237 |
| 244 void AppListView::SetBubbleArrow(views::BubbleBorder::Arrow arrow) { | 238 void AppListView::SetBubbleArrow(views::BubbleBorder::Arrow arrow) { |
| 245 GetBubbleFrameView()->bubble_border()->set_arrow(arrow); | 239 GetBubbleFrameView()->bubble_border()->set_arrow(arrow); |
| 246 SizeToContents(); // Recalcuates with new border. | 240 SizeToContents(); // Recalcuates with new border. |
| 247 GetBubbleFrameView()->SchedulePaint(); | 241 GetBubbleFrameView()->SchedulePaint(); |
| 248 } | 242 } |
| 249 | 243 |
| 250 void AppListView::MaybeSetAnchorPoint(const gfx::Point& anchor_point) { | 244 void AppListView::MaybeSetAnchorPoint(const gfx::Point& anchor_point) { |
| 251 // if the AppListView is a bubble | 245 // if the AppListView is a bubble |
| 252 if (!IsFullscreenAppListEnabled()) | 246 if (!is_fullscreen_app_list_enabled_) |
| 253 SetAnchorRect(gfx::Rect(anchor_point, gfx::Size())); | 247 SetAnchorRect(gfx::Rect(anchor_point, gfx::Size())); |
| 254 } | 248 } |
| 255 | 249 |
| 256 void AppListView::SetDragAndDropHostOfCurrentAppList( | 250 void AppListView::SetDragAndDropHostOfCurrentAppList( |
| 257 ApplicationDragAndDropHost* drag_and_drop_host) { | 251 ApplicationDragAndDropHost* drag_and_drop_host) { |
| 258 app_list_main_view_->SetDragAndDropHostOfCurrentAppList(drag_and_drop_host); | 252 app_list_main_view_->SetDragAndDropHostOfCurrentAppList(drag_and_drop_host); |
| 259 } | 253 } |
| 260 | 254 |
| 261 void AppListView::ShowWhenReady() { | 255 void AppListView::ShowWhenReady() { |
| 262 app_list_main_view_->ShowAppListWhenReady(); | 256 app_list_main_view_->ShowAppListWhenReady(); |
| 263 } | 257 } |
| 264 | 258 |
| 265 void AppListView::UpdateBounds() { | 259 void AppListView::UpdateBounds() { |
| 266 // if the AppListView is a bubble | 260 // if the AppListView is a bubble |
| 267 if (!IsFullscreenAppListEnabled()) | 261 if (!is_fullscreen_app_list_enabled_) |
| 268 SizeToContents(); | 262 SizeToContents(); |
| 269 } | 263 } |
| 270 | 264 |
| 271 void AppListView::SetAppListOverlayVisible(bool visible) { | 265 void AppListView::SetAppListOverlayVisible(bool visible) { |
| 272 DCHECK(overlay_view_); | 266 DCHECK(overlay_view_); |
| 273 | 267 |
| 274 // Display the overlay immediately so we can begin the animation. | 268 // Display the overlay immediately so we can begin the animation. |
| 275 overlay_view_->SetVisible(true); | 269 overlay_view_->SetVisible(true); |
| 276 | 270 |
| 277 ui::ScopedLayerAnimationSettings settings( | 271 ui::ScopedLayerAnimationSettings settings( |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 ->pagination_model(); | 344 ->pagination_model(); |
| 351 } | 345 } |
| 352 | 346 |
| 353 void AppListView::InitContents(gfx::NativeView parent, int initial_apps_page) { | 347 void AppListView::InitContents(gfx::NativeView parent, int initial_apps_page) { |
| 354 // TODO(vadimt): Remove ScopedTracker below once crbug.com/440224 and | 348 // TODO(vadimt): Remove ScopedTracker below once crbug.com/440224 and |
| 355 // crbug.com/441028 are fixed. | 349 // crbug.com/441028 are fixed. |
| 356 tracked_objects::ScopedTracker tracking_profile( | 350 tracked_objects::ScopedTracker tracking_profile( |
| 357 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 351 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 358 "440224, 441028 AppListView::InitContents")); | 352 "440224, 441028 AppListView::InitContents")); |
| 359 | 353 |
| 360 if (IsFullscreenAppListEnabled()) { | 354 if (is_fullscreen_app_list_enabled_) { |
| 361 // The shield view that colors the background of the app list and makes it | 355 // The shield view that colors the background of the app list and makes it |
| 362 // transparent. | 356 // transparent. |
| 363 app_list_background_shield_ = new views::View; | 357 app_list_background_shield_ = new views::View; |
| 364 app_list_background_shield_->SetPaintToLayer(ui::LAYER_SOLID_COLOR); | 358 app_list_background_shield_->SetPaintToLayer(ui::LAYER_SOLID_COLOR); |
| 365 app_list_background_shield_->layer()->SetColor(SK_ColorBLACK); | 359 app_list_background_shield_->layer()->SetColor(SK_ColorBLACK); |
| 366 app_list_background_shield_->layer()->SetOpacity(kAppListOpacity); | 360 app_list_background_shield_->layer()->SetOpacity(kAppListOpacity); |
| 367 AddChildView(app_list_background_shield_); | 361 AddChildView(app_list_background_shield_); |
| 368 } | 362 } |
| 369 app_list_main_view_ = new AppListMainView(delegate_, this); | 363 app_list_main_view_ = new AppListMainView(delegate_, this); |
| 370 AddChildView(app_list_main_view_); | 364 AddChildView(app_list_main_view_); |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 589 } | 583 } |
| 590 | 584 |
| 591 void AppListView::GetWidgetHitTestMask(gfx::Path* mask) const { | 585 void AppListView::GetWidgetHitTestMask(gfx::Path* mask) const { |
| 592 DCHECK(mask); | 586 DCHECK(mask); |
| 593 DCHECK(GetBubbleFrameView()); | 587 DCHECK(GetBubbleFrameView()); |
| 594 | 588 |
| 595 mask->addRect(gfx::RectToSkRect(GetBubbleFrameView()->GetContentsBounds())); | 589 mask->addRect(gfx::RectToSkRect(GetBubbleFrameView()->GetContentsBounds())); |
| 596 } | 590 } |
| 597 | 591 |
| 598 void AppListView::OnMouseEvent(ui::MouseEvent* event) { | 592 void AppListView::OnMouseEvent(ui::MouseEvent* event) { |
| 599 if (!IsFullscreenAppListEnabled()) | 593 if (!is_fullscreen_app_list_enabled_) |
| 600 return; | 594 return; |
| 601 | 595 |
| 602 switch (event->type()) { | 596 switch (event->type()) { |
| 603 case ui::ET_MOUSE_PRESSED: | 597 case ui::ET_MOUSE_PRESSED: |
| 604 StartDrag(event->location()); | 598 StartDrag(event->location()); |
| 605 event->SetHandled(); | 599 event->SetHandled(); |
| 606 break; | 600 break; |
| 607 case ui::ET_MOUSE_DRAGGED: | 601 case ui::ET_MOUSE_DRAGGED: |
| 608 UpdateDrag(event->location()); | 602 UpdateDrag(event->location()); |
| 609 event->SetHandled(); | 603 event->SetHandled(); |
| 610 break; | 604 break; |
| 611 case ui::ET_MOUSE_RELEASED: | 605 case ui::ET_MOUSE_RELEASED: |
| 612 EndDrag(event->location()); | 606 EndDrag(event->location()); |
| 613 event->SetHandled(); | 607 event->SetHandled(); |
| 614 break; | 608 break; |
| 615 default: | 609 default: |
| 616 break; | 610 break; |
| 617 } | 611 } |
| 618 } | 612 } |
| 619 | 613 |
| 620 void AppListView::OnGestureEvent(ui::GestureEvent* event) { | 614 void AppListView::OnGestureEvent(ui::GestureEvent* event) { |
| 621 if (!IsFullscreenAppListEnabled()) | 615 if (!is_fullscreen_app_list_enabled_) |
| 622 return; | 616 return; |
| 623 | 617 |
| 624 switch (event->type()) { | 618 switch (event->type()) { |
| 625 case ui::ET_GESTURE_SCROLL_BEGIN: | 619 case ui::ET_GESTURE_SCROLL_BEGIN: |
| 626 StartDrag(event->location()); | 620 StartDrag(event->location()); |
| 627 event->SetHandled(); | 621 event->SetHandled(); |
| 628 break; | 622 break; |
| 629 case ui::ET_GESTURE_SCROLL_UPDATE: | 623 case ui::ET_GESTURE_SCROLL_UPDATE: |
| 630 last_fling_velocity_ = event->details().velocity_y(); | 624 last_fling_velocity_ = event->details().velocity_y(); |
| 631 UpdateDrag(event->location()); | 625 UpdateDrag(event->location()); |
| 632 event->SetHandled(); | 626 event->SetHandled(); |
| 633 break; | 627 break; |
| 634 case ui::ET_GESTURE_END: | 628 case ui::ET_GESTURE_END: |
| 635 EndDrag(event->location()); | 629 EndDrag(event->location()); |
| 636 event->SetHandled(); | 630 event->SetHandled(); |
| 637 break; | 631 break; |
| 638 default: | 632 default: |
| 639 break; | 633 break; |
| 640 } | 634 } |
| 641 } | 635 } |
| 642 | 636 |
| 643 bool AppListView::AcceleratorPressed(const ui::Accelerator& accelerator) { | 637 bool AppListView::AcceleratorPressed(const ui::Accelerator& accelerator) { |
| 644 DCHECK_EQ(ui::VKEY_ESCAPE, accelerator.key_code()); | 638 DCHECK_EQ(ui::VKEY_ESCAPE, accelerator.key_code()); |
| 645 | 639 |
| 646 // If the ContentsView does not handle the back action, then this is the | 640 // If the ContentsView does not handle the back action, then this is the |
| 647 // top level, so we close the app list. | 641 // top level, so we close the app list. |
| 648 if (!app_list_main_view_->contents_view()->Back()) { | 642 if (!app_list_main_view_->contents_view()->Back()) { |
| 649 if (IsFullscreenAppListEnabled()) { | 643 if (is_fullscreen_app_list_enabled_) { |
| 650 SetState(CLOSED); | 644 SetState(CLOSED); |
| 651 } else { | 645 } else { |
| 652 app_list_main_view_->Close(); | 646 app_list_main_view_->Close(); |
| 653 delegate_->Dismiss(); | 647 delegate_->Dismiss(); |
| 654 } | 648 } |
| 655 GetWidget()->Deactivate(); | 649 GetWidget()->Deactivate(); |
| 656 } | 650 } |
| 657 | 651 |
| 658 // Don't let DialogClientView handle the accelerator. | 652 // Don't let DialogClientView handle the accelerator. |
| 659 return true; | 653 return true; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 674 if (speech_view_) { | 668 if (speech_view_) { |
| 675 gfx::Rect speech_bounds = centered_bounds; | 669 gfx::Rect speech_bounds = centered_bounds; |
| 676 int preferred_height = speech_view_->GetPreferredSize().height(); | 670 int preferred_height = speech_view_->GetPreferredSize().height(); |
| 677 speech_bounds.Inset(kSpeechUIMargin, kSpeechUIMargin); | 671 speech_bounds.Inset(kSpeechUIMargin, kSpeechUIMargin); |
| 678 speech_bounds.set_height( | 672 speech_bounds.set_height( |
| 679 std::min(speech_bounds.height(), preferred_height)); | 673 std::min(speech_bounds.height(), preferred_height)); |
| 680 speech_bounds.Inset(-speech_view_->GetInsets()); | 674 speech_bounds.Inset(-speech_view_->GetInsets()); |
| 681 speech_view_->SetBoundsRect(speech_bounds); | 675 speech_view_->SetBoundsRect(speech_bounds); |
| 682 } | 676 } |
| 683 | 677 |
| 684 if (IsFullscreenAppListEnabled()) { | 678 if (is_fullscreen_app_list_enabled_) { |
| 685 app_list_main_view_->contents_view()->Layout(); | 679 app_list_main_view_->contents_view()->Layout(); |
| 686 app_list_background_shield_->SetBoundsRect(contents_bounds); | 680 app_list_background_shield_->SetBoundsRect(contents_bounds); |
| 687 } | 681 } |
| 688 } | 682 } |
| 689 | 683 |
| 690 void AppListView::SchedulePaintInRect(const gfx::Rect& rect) { | 684 void AppListView::SchedulePaintInRect(const gfx::Rect& rect) { |
| 691 BubbleDialogDelegateView::SchedulePaintInRect(rect); | 685 BubbleDialogDelegateView::SchedulePaintInRect(rect); |
| 692 if (GetBubbleFrameView()) | 686 if (GetBubbleFrameView()) |
| 693 GetBubbleFrameView()->SchedulePaint(); | 687 GetBubbleFrameView()->SchedulePaint(); |
| 694 } | 688 } |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 797 // Refocus the search box. However, if the app list widget does not have | 791 // Refocus the search box. However, if the app list widget does not have |
| 798 // focus, it means another window has already taken focus, and we *must not* | 792 // focus, it means another window has already taken focus, and we *must not* |
| 799 // focus the search box (or we would steal focus back into the app list). | 793 // focus the search box (or we would steal focus back into the app list). |
| 800 if (GetWidget()->IsActive()) | 794 if (GetWidget()->IsActive()) |
| 801 search_box_view_->search_box()->RequestFocus(); | 795 search_box_view_->search_box()->RequestFocus(); |
| 802 } | 796 } |
| 803 } | 797 } |
| 804 | 798 |
| 805 void AppListView::OnDisplayMetricsChanged(const display::Display& display, | 799 void AppListView::OnDisplayMetricsChanged(const display::Display& display, |
| 806 uint32_t changed_metrics) { | 800 uint32_t changed_metrics) { |
| 807 if (!IsFullscreenAppListEnabled()) | 801 if (!is_fullscreen_app_list_enabled_) |
| 808 return; | 802 return; |
| 809 | 803 |
| 810 // Set the |fullscreen_widget_| size to fit the new display metrics. | 804 // Set the |fullscreen_widget_| size to fit the new display metrics. |
| 811 gfx::Size size = display::Screen::GetScreen() | 805 gfx::Size size = display::Screen::GetScreen() |
| 812 ->GetDisplayNearestView(parent_window()) | 806 ->GetDisplayNearestView(parent_window()) |
| 813 .work_area() | 807 .work_area() |
| 814 .size(); | 808 .size(); |
| 815 size.Enlarge(0, kShelfSize); | 809 size.Enlarge(0, kShelfSize); |
| 816 fullscreen_widget_->SetSize(size); | 810 fullscreen_widget_->SetSize(size); |
| 817 | 811 |
| 818 // Update the |fullscreen_widget_| bounds to accomodate the new work area. | 812 // Update the |fullscreen_widget_| bounds to accomodate the new work area. |
| 819 SetState(app_list_state_); | 813 SetState(app_list_state_); |
| 820 } | 814 } |
| 821 | 815 |
| 822 } // namespace app_list | 816 } // namespace app_list |
| OLD | NEW |