Skip to content

Commit

Permalink
Update opacity of the fullscreen app list during dragging from shelf.
Browse files Browse the repository at this point in the history
1. Update the app list background opacity based on the shelf's original opacity.
Shelf changes to fully transparent if app list is opened.
Relationship:
    Applist background opacity = (Opacity of app list) * t + (1 - t) * (opacity of shelf)
    t = gesture_drag_amount / (3.0 * shelfsize)

2. Update the opacity of all the items in the app list.
Includeing, searchbox view, suggested_apps_indicator, suggested_apps, all_apps_indicator,
            all apps in the first page, page switcher
Formula:
Opacity of item = (work_area_bottom - centroid of the item's screen bounds) / (2.0 * shelfsize)

Bug: 748620
Change-Id: Ia1fc25628423fcc1ffad666319e04292837aae2c
Reviewed-on: https://chromium-review.googlesource.com/585398
Reviewed-by: Mitsuru Oshima <oshima@chromium.org>
Reviewed-by: Mustafa Emre Acer <meacer@chromium.org>
Reviewed-by: Jenny Zhang <jennyz@chromium.org>
Commit-Queue: min c <minch@chromium.org>
Cr-Commit-Position: refs/heads/master@{#490786}
  • Loading branch information
MinChen authored and Commit Bot committed Jul 31, 2017
1 parent 43acf4e commit eafaa52
Show file tree
Hide file tree
Showing 29 changed files with 246 additions and 41 deletions.
28 changes: 23 additions & 5 deletions ash/shelf/shelf_layout_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "base/command_line.h"
#include "base/i18n/rtl.h"
#include "ui/app_list/app_list_features.h"
#include "ui/app_list/views/app_list_view.h"
#include "ui/base/ui_base_switches.h"
#include "ui/compositor/layer.h"
#include "ui/compositor/layer_animation_observer.h"
Expand Down Expand Up @@ -1115,9 +1116,12 @@ void ShelfLayoutManager::StartGestureDrag(
const ui::GestureEvent& gesture_in_screen) {
if (CanStartFullscreenAppListDrag(
gesture_in_screen.details().scroll_y_hint())) {
Shell::Get()->ShowAppList();
Shell::Get()->SetAppListYPosition(gesture_in_screen.location().y());
gesture_drag_status_ = GESTURE_DRAG_APPLIST_IN_PROGRESS;
Shell::Get()->ShowAppList();
Shell::Get()->UpdateAppListYPositionAndOpacity(
gesture_in_screen.location().y(),
GetAppListBackgroundOpacityOnShelfOpacity(),
false /* is_end_gesture */);
} else {
// Disable the shelf dragging if the fullscreen app list is opened.
if (app_list::features::IsFullscreenAppListEnabled() &&
Expand Down Expand Up @@ -1146,7 +1150,10 @@ void ShelfLayoutManager::UpdateGestureDrag(
gesture_drag_status_ = GESTURE_DRAG_NONE;
return;
}
Shell::Get()->SetAppListYPosition(gesture_in_screen.location().y());
Shell::Get()->UpdateAppListYPositionAndOpacity(
gesture_in_screen.location().y(),
GetAppListBackgroundOpacityOnShelfOpacity(),
false /* is_end_gesture */);
gesture_drag_amount_ += gesture_in_screen.details().scroll_y();
} else {
gesture_drag_amount_ +=
Expand Down Expand Up @@ -1226,11 +1233,12 @@ void ShelfLayoutManager::CompleteAppListDrag(
}

if (should_show_app_list) {
Shell::Get()->SetAppListYPosition(
Shell::Get()->UpdateAppListYPositionAndOpacity(
display::Screen::GetScreen()
->GetDisplayNearestWindow(shelf_widget_->GetNativeWindow())
.work_area()
.y());
.y(),
GetAppListBackgroundOpacityOnShelfOpacity(), true /* is_end_gesture */);
} else {
Shell::Get()->DismissAppList();
}
Expand Down Expand Up @@ -1279,6 +1287,16 @@ bool ShelfLayoutManager::CanStartFullscreenAppListDrag(
return true;
}

float ShelfLayoutManager::GetAppListBackgroundOpacityOnShelfOpacity() {
float shelf_opacity = HasVisibleWindow() ? 1.0f : 0.0f;
float coefficient =
std::min(std::abs(gesture_drag_amount_) /
((app_list::AppListView::kNumOfShelfSize + 1) * kShelfSize),
1.0f);
return app_list::AppListView::kAppListOpacity * coefficient +
(1 - coefficient) * shelf_opacity;
}

bool ShelfLayoutManager::IsSwipingCorrectDirection() {
switch (shelf_->alignment()) {
case SHELF_ALIGNMENT_BOTTOM:
Expand Down
1 change: 1 addition & 0 deletions ash/shelf/shelf_layout_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ class ASH_EXPORT ShelfLayoutManager
void CompleteAppListDrag(const ui::GestureEvent& gesture_in_screen);
void CancelGestureDrag();
bool CanStartFullscreenAppListDrag(float scroll_y_hint) const;
float GetAppListBackgroundOpacityOnShelfOpacity();

// Returns true if the gesture is swiping up on a hidden shelf or swiping down
// on a visible shelf; other gestures should not change shelf visibility.
Expand Down
7 changes: 5 additions & 2 deletions ash/shell.cc
Original file line number Diff line number Diff line change
Expand Up @@ -493,8 +493,11 @@ void Shell::ShowAppList() {
.id());
}

void Shell::SetAppListYPosition(int y_position_in_screen) {
app_list_->SetYPosition(y_position_in_screen);
void Shell::UpdateAppListYPositionAndOpacity(int y_position_in_screen,
float app_list_background_opacity,
bool is_end_gesture) {
app_list_->UpdateYPositionAndOpacity(
y_position_in_screen, app_list_background_opacity, is_end_gesture);
}

void Shell::DismissAppList() {
Expand Down
8 changes: 6 additions & 2 deletions ash/shell.h
Original file line number Diff line number Diff line change
Expand Up @@ -543,8 +543,12 @@ class ASH_EXPORT Shell : public SessionObserver,
// Shows the app list on the active root window.
void ShowAppList();

// Set y position of app list bounds to |y_location_in_screen|.
void SetAppListYPosition(int y_position_in_screen);
// Updates y position and opacity of app list. |is_end_gesture| means it is
// the end of the gesture dragging of app list from shelf and should restore
// the opacity of the app list.
void UpdateAppListYPositionAndOpacity(int y_position_in_screen,
float app_list_background_opacity,
bool is_end_gesture);

// Dismisses the app list.
void DismissAppList();
Expand Down
5 changes: 4 additions & 1 deletion ash/shell/example_app_list_presenter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ void ExampleAppListPresenter::ToggleAppList(int64_t display_id) {

void ExampleAppListPresenter::StartVoiceInteractionSession() {}

void ExampleAppListPresenter::SetYPosition(int new_y_position) {}
void ExampleAppListPresenter::UpdateYPositionAndOpacity(
int new_y_position,
float background_opacity,
bool is_end_gesture) {}

} // namespace shell
} // namespace ash
4 changes: 3 additions & 1 deletion ash/shell/example_app_list_presenter.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ class ExampleAppListPresenter : public app_list::mojom::AppListPresenter {
void Dismiss() override;
void ToggleAppList(int64_t display_id) override;
void StartVoiceInteractionSession() override;
void SetYPosition(int new_y_position) override;
void UpdateYPositionAndOpacity(int new_y_position,
float background_opacity,
bool is_end_gesture) override;

private:
mojo::Binding<app_list::mojom::AppListPresenter> binding_;
Expand Down
8 changes: 6 additions & 2 deletions chrome/browser/ui/ash/app_list/app_list_presenter_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,12 @@ void AppListPresenterService::StartVoiceInteractionSession() {
service->StartSessionFromUserInteraction(gfx::Rect());
}

void AppListPresenterService::SetYPosition(int y_position_in_screen) {
GetPresenter()->SetYPosition(y_position_in_screen);
void AppListPresenterService::UpdateYPositionAndOpacity(
int y_position_in_screen,
float background_opacity,
bool is_end_gesture) {
GetPresenter()->UpdateYPositionAndOpacity(y_position_in_screen,
background_opacity, is_end_gesture);
}

app_list::AppListPresenterImpl* AppListPresenterService::GetPresenter() {
Expand Down
4 changes: 3 additions & 1 deletion chrome/browser/ui/ash/app_list/app_list_presenter_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ class AppListPresenterService : public app_list::mojom::AppListPresenter {
void Dismiss() override;
void ToggleAppList(int64_t display_id) override;
void StartVoiceInteractionSession() override;
void SetYPosition(int y_position_in_screen) override;
void UpdateYPositionAndOpacity(int y_position_in_screen,
float background_opacity,
bool is_end_gesture) override;

private:
app_list::AppListPresenterImpl* GetPresenter();
Expand Down
10 changes: 7 additions & 3 deletions ui/app_list/presenter/app_list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,13 @@ void AppList::Show(int64_t display_id) {
presenter_->Show(display_id);
}

void AppList::SetYPosition(int y_position_in_screen) {
if (presenter_)
presenter_->SetYPosition(y_position_in_screen);
void AppList::UpdateYPositionAndOpacity(int y_position_in_screen,
float background_opacity,
bool is_end_gesture) {
if (presenter_) {
presenter_->UpdateYPositionAndOpacity(y_position_in_screen,
background_opacity, is_end_gesture);
}
}

void AppList::Dismiss() {
Expand Down
4 changes: 3 additions & 1 deletion ui/app_list/presenter/app_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ class APP_LIST_PRESENTER_EXPORT AppList : public mojom::AppList {

// Helper functions to call the underlying functionality on the presenter.
void Show(int64_t display_id);
void SetYPosition(int y_position_in_screen);
void UpdateYPositionAndOpacity(int y_position_in_screen,
float background_opacity,
bool is_end_gesture);

void Dismiss();
void ToggleAppList(int64_t display_id);
Expand Down
8 changes: 6 additions & 2 deletions ui/app_list/presenter/app_list_presenter.mojom
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ interface AppListPresenter {
// Starts a voice interaction session.
StartVoiceInteractionSession();

// Sets y position of the app list bounds to |y_position_in_screen|.
SetYPosition(int32 y_position_in_screen);
// Updates y position and opacity of app list. |is_end_gesture| means it is
// the end of the gesture dragging of app list from shelf and should restore
// the opacity of the app list.
UpdateYPositionAndOpacity(int32 y_position_in_screen,
float background_opacity,
bool is_end_gesture);
};
10 changes: 7 additions & 3 deletions ui/app_list/presenter/app_list_presenter_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,13 @@ void AppListPresenterImpl::Show(int64_t display_id) {
base::RecordAction(base::UserMetricsAction("Launcher_Show"));
}

void AppListPresenterImpl::SetYPosition(int y_position_in_screen) {
if (view_)
view_->SetYPosition(y_position_in_screen);
void AppListPresenterImpl::UpdateYPositionAndOpacity(int y_position_in_screen,
float background_opacity,
bool is_end_gesture) {
if (view_) {
view_->UpdateYPositionAndOpacity(y_position_in_screen, background_opacity,
is_end_gesture);
}
}

void AppListPresenterImpl::Dismiss() {
Expand Down
8 changes: 6 additions & 2 deletions ui/app_list/presenter/app_list_presenter_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,12 @@ class APP_LIST_PRESENTER_EXPORT AppListPresenterImpl
// display (in which the |window| exists) the app list should be shown.
void Show(int64_t display_id);

// Sets y position of the app list bounds to |y_position_in_screen|.
void SetYPosition(int y_position_in_screen);
// Updates y position and opacity of app list. |is_end_gesture| means it is
// the end of the gesture dragging of app list from shelf and should restore
// the opacity of the app list.
void UpdateYPositionAndOpacity(int y_position_in_screen,
float background_opacity,
bool is_end_gesture);

// Invoked to dismiss app list. This may leave the view open but hidden from
// the user.
Expand Down
4 changes: 3 additions & 1 deletion ui/app_list/presenter/test/test_app_list_presenter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ void TestAppListPresenter::StartVoiceInteractionSession() {
voice_session_count_++;
}

void TestAppListPresenter::SetYPosition(int y_position_in_screen) {
void TestAppListPresenter::UpdateYPositionAndOpacity(int y_position_in_screen,
float background_opacity,
bool is_end_gesture) {
set_y_position_count_++;
}

Expand Down
4 changes: 3 additions & 1 deletion ui/app_list/presenter/test/test_app_list_presenter.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ class TestAppListPresenter : public app_list::mojom::AppListPresenter {
void Dismiss() override;
void ToggleAppList(int64_t display_id) override;
void StartVoiceInteractionSession() override;
void SetYPosition(int y_position_in_screen) override;
void UpdateYPositionAndOpacity(int y_position_in_screen,
float background_opacity,
bool is_end_gesture) override;

size_t show_count() const { return show_count_; }
size_t dismiss_count() const { return dismiss_count_; }
Expand Down
32 changes: 20 additions & 12 deletions ui/app_list/views/app_list_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ namespace {
// The margin from the edge to the speech UI.
constexpr int kSpeechUIMargin = 12;

// The height/width of the shelf from the bottom/side of the screen.
constexpr int kShelfSize = 48;

// The height of the peeking app list from the bottom of the screen.
constexpr int kPeekingAppListHeight = 320;

Expand All @@ -79,9 +76,6 @@ constexpr int kAppListMinScrollToSwitchStates = 20;
// the |app_list_state_|.
constexpr int kAppListBezelMargin = 50;

// The opacity of the app list background.
constexpr float kAppListOpacity = 0.8;

// The vertical position for the appearing animation of the speech UI.
constexpr float kSpeechUIAppearingPosition = 12;

Expand Down Expand Up @@ -488,12 +482,16 @@ void AppListView::UpdateDrag(const gfx::Point& location) {
// Update the bounds of the widget while maintaining the
// relative position of the top of the widget and the mouse/gesture.
// Block drags north of 0 and recalculate the initial_drag_point_.
int new_y_position = location.y() - initial_drag_point_.y() +
fullscreen_widget_->GetWindowBoundsInScreen().y();

if (new_y_position < 0)
int const new_y_position = location.y() - initial_drag_point_.y() +
fullscreen_widget_->GetWindowBoundsInScreen().y();
gfx::Rect new_widget_bounds = fullscreen_widget_->GetWindowBoundsInScreen();
if (new_y_position < 0) {
new_widget_bounds.set_y(0);
initial_drag_point_ = location;
SetYPosition(new_y_position);
} else {
new_widget_bounds.set_y(new_y_position);
}
fullscreen_widget_->SetBounds(new_widget_bounds);
}

void AppListView::EndDrag(const gfx::Point& location) {
Expand Down Expand Up @@ -959,10 +957,20 @@ void AppListView::SetStateFromSearchBoxView(bool search_box_is_empty) {
}
}

void AppListView::SetYPosition(int y_position_in_screen) {
void AppListView::UpdateYPositionAndOpacity(int y_position_in_screen,
float background_opacity,
bool is_end_gesture) {
gfx::Rect new_widget_bounds = fullscreen_widget_->GetWindowBoundsInScreen();
new_widget_bounds.set_y(std::max(y_position_in_screen, 0));
fullscreen_widget_->SetBounds(new_widget_bounds);

app_list_background_shield_->layer()->SetOpacity(background_opacity);
gfx::Rect work_area_bounds = fullscreen_widget_->GetWorkAreaBoundsInScreen();
search_box_view_->UpdateOpacity(work_area_bounds.bottom(), is_end_gesture);
app_list_main_view_->contents_view()
->apps_container_view()
->apps_grid_view()
->UpdateOpacity(work_area_bounds.bottom(), is_end_gesture);
}

PaginationModel* AppListView::GetAppsPaginationModel() {
Expand Down
18 changes: 16 additions & 2 deletions ui/app_list/views/app_list_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ class APP_LIST_EXPORT AppListView : public views::BubbleDialogDelegateView,
public SpeechUIModelObserver,
public display::DisplayObserver {
public:
// The height/width of the shelf from the bottom/side of the screen.
static constexpr int kShelfSize = 48;

// Number of the size of shelf. Used to determine the opacity of items in the
// app list during dragging.
static constexpr float kNumOfShelfSize = 2.0;

// The opacity of the app list background.
static constexpr float kAppListOpacity = 0.8;

enum AppListState {
// Closes |app_list_main_view_| and dismisses the delegate.
CLOSED = 0,
Expand Down Expand Up @@ -127,8 +137,12 @@ class APP_LIST_EXPORT AppListView : public views::BubbleDialogDelegateView,
// whether the search box is empty.
void SetStateFromSearchBoxView(bool search_box_is_empty);

// Sets y position of the app list bounds to |y_position_in_screen|.
void SetYPosition(int y_position_in_screen);
// Updates y position and opacity of app list. |is_end_gesture| means it is
// the end of the gesture dragging of app list from shelf and should restore
// the opacity of the app list.
void UpdateYPositionAndOpacity(int y_position_in_screen,
float background_opacity,
bool is_end_gesture);

// Gets the PaginationModel owned by this view's apps grid.
PaginationModel* GetAppsPaginationModel();
Expand Down
Loading

0 comments on commit eafaa52

Please sign in to comment.