Commit 4a9f8298 authored by Weidong Guo's avatar Weidong Guo Committed by Commit Bot

Move expand arrow to ContentsView

1. Currently expand arrow exists in AppsContainerView, so opening search
   results page will move it off screen. To make it stay where it is and
   fade it out, we need to move it to ContentsView.
2. Make expand arrow focusable only in peeking state.

Demo: https://drive.google.com/open?id=1hgSqEDgEW1wZr5Dxw8WQmGpEosy4sDgP

Bug: 866690,868107
Change-Id: I965703041f498f8ad1e64c6db47718e7bf69c8f8
Reviewed-on: https://chromium-review.googlesource.com/1150900
Commit-Queue: Weidong Guo <weidongg@chromium.org>
Reviewed-by: default avatarYury Khmel <khmel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#579494}
parent 3c5ca5b9
...@@ -1431,7 +1431,7 @@ void AppListView::DraggingLayout() { ...@@ -1431,7 +1431,7 @@ void AppListView::DraggingLayout() {
// Updates the opacity of the items in the app list. // Updates the opacity of the items in the app list.
search_box_view_->UpdateOpacity(); search_box_view_->UpdateOpacity();
GetAppsContainerView()->UpdateOpacity(); app_list_main_view_->contents_view()->UpdateOpacity();
Layout(); Layout();
} }
......
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
#include "ash/app_list/views/app_list_view.h" #include "ash/app_list/views/app_list_view.h"
#include "ash/app_list/views/apps_grid_view.h" #include "ash/app_list/views/apps_grid_view.h"
#include "ash/app_list/views/contents_view.h" #include "ash/app_list/views/contents_view.h"
#include "ash/app_list/views/expand_arrow_view.h"
#include "ash/app_list/views/folder_background_view.h" #include "ash/app_list/views/folder_background_view.h"
#include "ash/app_list/views/horizontal_page_container.h" #include "ash/app_list/views/horizontal_page_container.h"
#include "ash/app_list/views/page_switcher.h" #include "ash/app_list/views/page_switcher.h"
...@@ -58,11 +57,6 @@ constexpr int kAppsGridPageSwitcherSpacing = 8; ...@@ -58,11 +57,6 @@ constexpr int kAppsGridPageSwitcherSpacing = 8;
constexpr float kSuggestionChipOpacityStartProgress = 0; constexpr float kSuggestionChipOpacityStartProgress = 0;
constexpr float kSuggestionChipOpacityEndProgress = 0.67; constexpr float kSuggestionChipOpacityEndProgress = 0.67;
// The range of app list transition progress in which the expand arrow'
// opacity changes from 0 to 1.
constexpr float kExpandArrowOpacityStartProgress = 0;
constexpr float kExpandArrowOpacityEndProgress = 0.62;
} // namespace } // namespace
AppsContainerView::AppsContainerView(ContentsView* contents_view, AppsContainerView::AppsContainerView(ContentsView* contents_view,
...@@ -70,10 +64,6 @@ AppsContainerView::AppsContainerView(ContentsView* contents_view, ...@@ -70,10 +64,6 @@ AppsContainerView::AppsContainerView(ContentsView* contents_view,
: contents_view_(contents_view), : contents_view_(contents_view),
is_new_style_launcher_enabled_(features::IsNewStyleLauncherEnabled()) { is_new_style_launcher_enabled_(features::IsNewStyleLauncherEnabled()) {
if (is_new_style_launcher_enabled_) { if (is_new_style_launcher_enabled_) {
expand_arrow_view_ =
new ExpandArrowView(contents_view_, contents_view_->app_list_view());
AddChildView(expand_arrow_view_);
suggestion_chip_container_view_ = suggestion_chip_container_view_ =
new SuggestionChipContainerView(contents_view); new SuggestionChipContainerView(contents_view);
AddChildView(suggestion_chip_container_view_); AddChildView(suggestion_chip_container_view_);
...@@ -202,20 +192,6 @@ void AppsContainerView::UpdateOpacity() { ...@@ -202,20 +192,6 @@ void AppsContainerView::UpdateOpacity() {
suggestion_chip_container_view_->layer()->SetOpacity( suggestion_chip_container_view_->layer()->SetOpacity(
should_restore_opacity ? 1.0f : chips_opacity); should_restore_opacity ? 1.0f : chips_opacity);
} }
if (expand_arrow_view_) {
// Changes the opacity of expand arrow between 0 and 1 when app list
// transition progress changes between |kExpandArrowOpacityStartProgress|
// and |kExpandArrowOpacityEndProgress|.
float arrow_opacity =
std::min(std::max((progress - kExpandArrowOpacityStartProgress) /
(kExpandArrowOpacityEndProgress -
kExpandArrowOpacityStartProgress),
0.f),
1.0f);
expand_arrow_view_->layer()->SetOpacity(
should_restore_opacity ? 1.0f : arrow_opacity);
}
} }
gfx::Size AppsContainerView::CalculatePreferredSize() const { gfx::Size AppsContainerView::CalculatePreferredSize() const {
...@@ -237,14 +213,6 @@ void AppsContainerView::Layout() { ...@@ -237,14 +213,6 @@ void AppsContainerView::Layout() {
switch (show_state_) { switch (show_state_) {
case SHOW_APPS: { case SHOW_APPS: {
if (is_new_style_launcher_enabled_) { if (is_new_style_launcher_enabled_) {
// Layout expand arrow.
gfx::Rect arrow_rect(rect);
const gfx::Size arrow_size(expand_arrow_view_->GetPreferredSize());
arrow_rect.set_height(arrow_size.height());
arrow_rect.ClampToCenteredSize(arrow_size);
expand_arrow_view_->SetBoundsRect(arrow_rect);
expand_arrow_view_->SchedulePaint();
// Layout suggestion chips. // Layout suggestion chips.
gfx::Rect chip_container_rect(rect); gfx::Rect chip_container_rect(rect);
const float progress = const float progress =
......
...@@ -21,7 +21,6 @@ class AppListFolderItem; ...@@ -21,7 +21,6 @@ class AppListFolderItem;
class AppListFolderView; class AppListFolderView;
class AppListModel; class AppListModel;
class ContentsView; class ContentsView;
class ExpandArrowView;
class FolderBackgroundView; class FolderBackgroundView;
class PageSwitcher; class PageSwitcher;
class SuggestionChipContainerView; class SuggestionChipContainerView;
...@@ -121,7 +120,6 @@ class APP_LIST_EXPORT AppsContainerView : public HorizontalPage { ...@@ -121,7 +120,6 @@ class APP_LIST_EXPORT AppsContainerView : public HorizontalPage {
AppListFolderView* app_list_folder_view_ = nullptr; AppListFolderView* app_list_folder_view_ = nullptr;
PageSwitcher* page_switcher_ = nullptr; PageSwitcher* page_switcher_ = nullptr;
FolderBackgroundView* folder_background_view_ = nullptr; FolderBackgroundView* folder_background_view_ = nullptr;
ExpandArrowView* expand_arrow_view_ = nullptr;
ShowState show_state_ = SHOW_NONE; ShowState show_state_ = SHOW_NONE;
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "ash/app_list/views/app_list_view.h" #include "ash/app_list/views/app_list_view.h"
#include "ash/app_list/views/apps_container_view.h" #include "ash/app_list/views/apps_container_view.h"
#include "ash/app_list/views/apps_grid_view.h" #include "ash/app_list/views/apps_grid_view.h"
#include "ash/app_list/views/expand_arrow_view.h"
#include "ash/app_list/views/horizontal_page_container.h" #include "ash/app_list/views/horizontal_page_container.h"
#include "ash/app_list/views/search_box_view.h" #include "ash/app_list/views/search_box_view.h"
#include "ash/app_list/views/search_result_answer_card_view.h" #include "ash/app_list/views/search_result_answer_card_view.h"
...@@ -34,6 +35,11 @@ namespace app_list { ...@@ -34,6 +35,11 @@ namespace app_list {
namespace { namespace {
// The range of app list transition progress in which the expand arrow'
// opacity changes from 0 to 1.
constexpr float kExpandArrowOpacityStartProgress = 0;
constexpr float kExpandArrowOpacityEndProgress = 0.62;
void DoAnimation(base::TimeDelta animation_duration, void DoAnimation(base::TimeDelta animation_duration,
ui::Layer* layer, ui::Layer* layer,
float target_opacity) { float target_opacity) {
...@@ -84,6 +90,11 @@ void ContentsView::Init(AppListModel* model) { ...@@ -84,6 +90,11 @@ void ContentsView::Init(AppListModel* model) {
results, search_result_answer_card_view_); results, search_result_answer_card_view_);
} }
if (features::IsNewStyleLauncherEnabled()) {
expand_arrow_view_ = new ExpandArrowView(this, app_list_view_);
AddChildView(expand_arrow_view_);
}
search_result_tile_item_list_view_ = new SearchResultTileItemListView( search_result_tile_item_list_view_ = new SearchResultTileItemListView(
search_results_page_view_, GetSearchBoxView()->search_box(), search_results_page_view_, GetSearchBoxView()->search_box(),
view_delegate); view_delegate);
...@@ -218,6 +229,8 @@ void ContentsView::ActivePageChanged() { ...@@ -218,6 +229,8 @@ void ContentsView::ActivePageChanged() {
app_list_pages_[GetActivePageIndex()]->OnWillBeShown(); app_list_pages_[GetActivePageIndex()]->OnWillBeShown();
GetAppListMainView()->model()->SetState(state); GetAppListMainView()->model()->SetState(state);
UpdateExpandArrowFocusBehavior(state);
} }
void ContentsView::ShowSearchResults(bool show) { void ContentsView::ShowSearchResults(bool show) {
...@@ -267,6 +280,9 @@ void ContentsView::UpdatePageBounds() { ...@@ -267,6 +280,9 @@ void ContentsView::UpdatePageBounds() {
// Update the search box. // Update the search box.
UpdateSearchBox(progress, current_state, target_state); UpdateSearchBox(progress, current_state, target_state);
// Update the expand arrow view's opacity.
UpdateExpandArrowOpacity(progress, current_state, target_state);
} }
void ContentsView::UpdateSearchBox(double progress, void ContentsView::UpdateSearchBox(double progress,
...@@ -291,6 +307,41 @@ void ContentsView::UpdateSearchBox(double progress, ...@@ -291,6 +307,41 @@ void ContentsView::UpdateSearchBox(double progress,
ConvertRectToWidget(search_box_rect))); ConvertRectToWidget(search_box_rect)));
} }
void ContentsView::UpdateExpandArrowOpacity(double progress,
ash::AppListState current_state,
ash::AppListState target_state) {
if (!expand_arrow_view_)
return;
if (current_state == ash::AppListState::kStateSearchResults &&
(target_state == ash::AppListState::kStateStart ||
target_state == ash::AppListState::kStateApps)) {
// Fade in the expand arrow when search results page is opened.
expand_arrow_view_->layer()->SetOpacity(
gfx::Tween::FloatValueBetween(progress, 0, 1));
} else if (target_state == ash::AppListState::kStateSearchResults &&
(current_state == ash::AppListState::kStateStart ||
current_state == ash::AppListState::kStateApps)) {
// Fade out the expand arrow when search results page is closed.
expand_arrow_view_->layer()->SetOpacity(
gfx::Tween::FloatValueBetween(progress, 1, 0));
}
}
void ContentsView::UpdateExpandArrowFocusBehavior(
ash::AppListState current_state) {
if (!expand_arrow_view_)
return;
if (current_state == ash::AppListState::kStateStart) {
// The expand arrow is only focusable in peeking state.
expand_arrow_view_->SetFocusBehavior(FocusBehavior::ALWAYS);
return;
}
expand_arrow_view_->SetFocusBehavior(FocusBehavior::NEVER);
}
PaginationModel* ContentsView::GetAppsPaginationModel() { PaginationModel* ContentsView::GetAppsPaginationModel() {
return GetAppsContainerView()->apps_grid_view()->pagination_model(); return GetAppsContainerView()->apps_grid_view()->pagination_model();
} }
...@@ -397,9 +448,20 @@ gfx::Size ContentsView::CalculatePreferredSize() const { ...@@ -397,9 +448,20 @@ gfx::Size ContentsView::CalculatePreferredSize() const {
} }
void ContentsView::Layout() { void ContentsView::Layout() {
if (GetContentsBounds().IsEmpty()) const gfx::Rect rect = GetContentsBounds();
if (rect.IsEmpty())
return; return;
if (expand_arrow_view_) {
// Layout expand arrow.
gfx::Rect arrow_rect(rect);
const gfx::Size arrow_size(expand_arrow_view_->GetPreferredSize());
arrow_rect.set_height(arrow_size.height());
arrow_rect.ClampToCenteredSize(arrow_size);
expand_arrow_view_->SetBoundsRect(arrow_rect);
expand_arrow_view_->SchedulePaint();
}
UpdatePageBounds(); UpdatePageBounds();
} }
...@@ -454,6 +516,30 @@ views::View* ContentsView::GetSelectedView() const { ...@@ -454,6 +516,30 @@ views::View* ContentsView::GetSelectedView() const {
return app_list_pages_[GetActivePageIndex()]->GetSelectedView(); return app_list_pages_[GetActivePageIndex()]->GetSelectedView();
} }
void ContentsView::UpdateOpacity() {
if (expand_arrow_view_) {
const bool should_restore_opacity =
!app_list_view_->is_in_drag() &&
(app_list_view_->app_list_state() != AppListViewState::CLOSED);
// Changes the opacity of expand arrow between 0 and 1 when app list
// transition progress changes between |kExpandArrowOpacityStartProgress|
// and |kExpandArrowOpacityEndProgress|.
expand_arrow_view_->layer()->SetOpacity(
should_restore_opacity
? 1.0f
: std::min(
std::max((app_list_view_->GetAppListTransitionProgress() -
kExpandArrowOpacityStartProgress) /
(kExpandArrowOpacityEndProgress -
kExpandArrowOpacityStartProgress),
0.f),
1.0f));
}
GetAppsContainerView()->UpdateOpacity();
}
bool ContentsView::ShouldLayoutPage(AppListPage* page, bool ContentsView::ShouldLayoutPage(AppListPage* page,
ash::AppListState current_state, ash::AppListState current_state,
ash::AppListState target_state) const { ash::AppListState target_state) const {
......
...@@ -33,6 +33,7 @@ class AppListFolderItem; ...@@ -33,6 +33,7 @@ class AppListFolderItem;
class AppListMainView; class AppListMainView;
class AppsContainerView; class AppsContainerView;
class AppsGridView; class AppsGridView;
class ExpandArrowView;
class HorizontalPageContainer; class HorizontalPageContainer;
class PaginationModel; class PaginationModel;
class SearchBoxView; class SearchBoxView;
...@@ -169,6 +170,9 @@ class APP_LIST_EXPORT ContentsView : public views::View, ...@@ -169,6 +170,9 @@ class APP_LIST_EXPORT ContentsView : public views::View,
// Returns selected view in active page. // Returns selected view in active page.
views::View* GetSelectedView() const; views::View* GetSelectedView() const;
// Updates the opacity of the items in this view during dragging.
void UpdateOpacity();
private: private:
// Sets the active launcher page, accounting for whether the change is for // Sets the active launcher page, accounting for whether the change is for
// search results. // search results.
...@@ -190,6 +194,15 @@ class APP_LIST_EXPORT ContentsView : public views::View, ...@@ -190,6 +194,15 @@ class APP_LIST_EXPORT ContentsView : public views::View,
ash::AppListState current_state, ash::AppListState current_state,
ash::AppListState target_state); ash::AppListState target_state);
// Updates the expand arrow's opacity based on the progress of transition from
// current state to target state.
void UpdateExpandArrowOpacity(double progress,
ash::AppListState current_state,
ash::AppListState target_state);
// Updates the expand arrow's focus behavior based on the current state.
void UpdateExpandArrowFocusBehavior(ash::AppListState current_state);
// Adds |view| as a new page to the end of the list of launcher pages. The // Adds |view| as a new page to the end of the list of launcher pages. The
// view is inserted as a child of the ContentsView. There is no name // view is inserted as a child of the ContentsView. There is no name
// associated with the page. Returns the index of the new page. // associated with the page. Returns the index of the new page.
...@@ -227,6 +240,9 @@ class APP_LIST_EXPORT ContentsView : public views::View, ...@@ -227,6 +240,9 @@ class APP_LIST_EXPORT ContentsView : public views::View,
// Owned by the views hierarchy. // Owned by the views hierarchy.
AppListView* const app_list_view_; AppListView* const app_list_view_;
// Owned by the views hierarchy.
ExpandArrowView* expand_arrow_view_ = nullptr;
// Maps State onto |view_model_| indices. // Maps State onto |view_model_| indices.
std::map<ash::AppListState, int> state_to_view_; std::map<ash::AppListState, int> state_to_view_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment