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