Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(427)

Unified Diff: ui/app_list/views/app_list_view.cc

Issue 2898743002: Draggable peeking/fullscreen launcher with transparent background. (Closed)
Patch Set: adressed comments. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/app_list/views/app_list_view.cc
diff --git a/ui/app_list/views/app_list_view.cc b/ui/app_list/views/app_list_view.cc
index 08ff586e0718196f00aa7d3b2ef2b0615af3deba..336db5a248a327f400eaf0c55ef115d7ae3e407a 100644
--- a/ui/app_list/views/app_list_view.cc
+++ b/ui/app_list/views/app_list_view.cc
@@ -56,6 +56,20 @@ namespace {
// The margin from the edge to the speech UI.
const int kSpeechUIMargin = 12;
+// The height/width of the shelf.
+const int kShelfSize = 48;
xiyuan 2017/05/26 18:27:31 const -> constexpr for all
newcomer 2017/05/26 23:20:22 Done.
+
+// The height of the peeking launcher.
+const int kPeekingLauncherHeight = 320;
+// The fraction of launcher height that the launcher must be released at in
+// order to transition to the next state.
+const int kLauncherThresholdDenominator = 3;
+// The velocity the launcher must be dragged in order to transition to the next
+// state, measured in DIPs/event.
+const int kLauncherDragVelocityThreshold = 25;
+
+const float kLauncherOpacity = 0.8;
vadimt 2017/05/26 17:58:55 Comment!!!!!
newcomer 2017/05/26 23:20:21 Done.
+
// The vertical position for the appearing animation of the speech UI.
const float kSpeechUIAppearingPosition = 12;
@@ -175,14 +189,22 @@ AppListView::AppListView(AppListViewDelegate* delegate)
search_box_focus_host_(nullptr),
search_box_widget_(nullptr),
search_box_view_(nullptr),
+ display_observer_(this),
overlay_view_(nullptr),
animation_observer_(new HideViewAnimationObserver()) {
CHECK(delegate);
delegate_->GetSpeechUI()->AddObserver(this);
+
+ if (features::IsFullscreenAppListEnabled())
+ display_observer_.Add(display::Screen::GetScreen());
}
AppListView::~AppListView() {
+ // Remove this instance from the DisplayManager's list of observers.
+ if (features::IsFullscreenAppListEnabled())
+ display_observer_.Remove(display::Screen::GetScreen());
xiyuan 2017/05/26 18:27:31 nit: Get rid of this since ScopedObsever would do
newcomer 2017/05/26 23:20:22 Done.
+
delegate_->GetSpeechUI()->RemoveObserver(this);
animation_observer_.reset();
// Remove child views first to ensure no remaining dependencies on delegate_.
@@ -203,8 +225,10 @@ void AppListView::Initialize(gfx::NativeView parent, int initial_apps_page) {
InitChildWidgets();
AddChildView(overlay_view_);
+
if (delegate_)
delegate_->ViewInitialized();
+
UMA_HISTOGRAM_TIMES("Apps.AppListCreationTime",
base::Time::Now() - start_time);
}
@@ -237,10 +261,18 @@ void AppListView::CloseAppList() {
void AppListView::UpdateBounds() {
// if the AppListView is a bubble
- if (!features::IsFullscreenAppListEnabled())
+ if (!launcher_background_shield_)
SizeToContents();
}
+void AppListView::UpdateDimensions() {
+ display_work_area_bounds_ = display::Screen::GetScreen()
+ ->GetDisplayNearestView(parent_window())
+ .work_area();
+ default_peeking_launcher_y_ =
+ display_work_area_bounds_.height() + kShelfSize - kPeekingLauncherHeight;
+}
+
void AppListView::SetAppListOverlayVisible(bool visible) {
DCHECK(overlay_view_);
@@ -330,7 +362,16 @@ void AppListView::InitContents(gfx::NativeView parent, int initial_apps_page) {
FROM_HERE_WITH_EXPLICIT_FUNCTION(
"440224, 441028 AppListView::InitContents"));
- app_list_main_view_ = new AppListMainView(delegate_);
+ if (features::IsFullscreenAppListEnabled()) {
+ // The shield view that colors the background of the launcher and makes it
+ // transparent.
+ launcher_background_shield_ = new views::View;
+ launcher_background_shield_->SetPaintToLayer(ui::LAYER_SOLID_COLOR);
+ launcher_background_shield_->layer()->SetColor(SK_ColorBLACK);
+ launcher_background_shield_->layer()->SetOpacity(kLauncherOpacity);
+ AddChildView(launcher_background_shield_);
+ }
+ app_list_main_view_ = new AppListMainView(delegate_, this);
AddChildView(app_list_main_view_);
app_list_main_view_->SetPaintToLayer();
app_list_main_view_->layer()->SetFillsBoundsOpaquely(false);
@@ -338,6 +379,7 @@ void AppListView::InitContents(gfx::NativeView parent, int initial_apps_page) {
// This will be added to the |search_box_widget_| after the app list widget is
// initialized.
search_box_view_ = new SearchBoxView(app_list_main_view_, delegate_);
+ search_box_view_->SetAppListView(this);
search_box_view_->SetPaintToLayer();
search_box_view_->layer()->SetFillsBoundsOpaquely(false);
search_box_view_->layer()->SetMasksToBounds(true);
@@ -404,21 +446,34 @@ void AppListView::InitChildWidgets() {
void AppListView::InitializeFullscreen(gfx::NativeView parent,
int initial_apps_page) {
- views::Widget* widget = new views::Widget;
+ UpdateDimensions();
+
+ gfx::Rect app_list_overlay_view_bounds(
+ display_work_area_bounds_.x(), default_peeking_launcher_y_,
+ display_work_area_bounds_.width(),
+ display_work_area_bounds_.height() + kShelfSize);
+
+ fullscreen_widget_ = new views::Widget;
views::Widget::InitParams app_list_overlay_view_params(
views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
+ app_list_overlay_view_params.name = "AppList";
app_list_overlay_view_params.parent = parent;
app_list_overlay_view_params.delegate = this;
app_list_overlay_view_params.opacity =
views::Widget::InitParams::TRANSLUCENT_WINDOW;
- app_list_overlay_view_params.bounds =
- display::Screen::GetScreen()->
- GetDisplayNearestView(parent).work_area();
- widget->Init(app_list_overlay_view_params);
- widget->GetLayer()->SetBackgroundBlur(10);
+ app_list_overlay_view_params.bounds = app_list_overlay_view_bounds;
+ app_list_overlay_view_params.layer_type = ui::LAYER_SOLID_COLOR;
+ fullscreen_widget_->Init(app_list_overlay_view_params);
+ fullscreen_widget_bounds_ = fullscreen_widget_->GetWindowBoundsInScreen();
overlay_view_ = new AppListOverlayView(0 /* no corners */);
+
+ // Launcher + shelf height, used in HandleDrag.
+ launcher_threshold_ =
+ (default_peeking_launcher_y_ + fullscreen_widget_bounds_.height() -
+ fullscreen_widget_bounds_.y()) /
+ kLauncherThresholdDenominator;
}
void AppListView::InitializeBubble(gfx::NativeView parent,
@@ -428,7 +483,7 @@ void AppListView::InitializeBubble(gfx::NativeView parent,
set_shadow(views::BubbleBorder::NO_ASSETS);
// This creates the app list widget. (Before this, child widgets cannot be
- // created.)
+ // created.
views::BubbleDialogDelegateView::CreateBubble(this);
SetBubbleArrow(views::BubbleBorder::FLOAT);
@@ -443,6 +498,89 @@ void AppListView::InitializeBubble(gfx::NativeView parent,
overlay_view_->SetBoundsRect(GetContentsBounds());
}
+void AppListView::HandleDrag(gfx::Point location, ui::EventType type) {
xiyuan 2017/05/26 18:27:31 nit: Break this into StartDrag, UpdateDrag and End
newcomer 2017/05/26 23:20:21 Done.
+ switch (type) {
+ case ui::ET_GESTURE_SCROLL_BEGIN:
+ case ui::ET_MOUSE_PRESSED: {
+ // Drag start, grab the initial_drag_separation_ to maintain the relative
+ // position of the top of the widget and the mouse/gesture.
+ initial_drag_separation_ = location.y();
+ fullscreen_widget_bounds_ = fullscreen_widget_->GetWindowBoundsInScreen();
+ break;
+ }
+ case ui::ET_GESTURE_SCROLL_UPDATE:
+ case ui::ET_MOUSE_DRAGGED: {
+ // Drag update, 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_separation_.
+ int new_y_position = location.y() - initial_drag_separation_ +
vadimt 2017/05/26 17:58:55 Nit: this can be const.
newcomer 2017/05/26 23:20:22 Done.
+ fullscreen_widget_bounds_.y();
+ if (new_y_position < 0) {
+ fullscreen_widget_bounds_.set_y(0);
+ initial_drag_separation_ = location.y();
+ } else {
+ fullscreen_widget_bounds_.set_y(new_y_position);
+ }
+ fullscreen_widget_->SetBounds(fullscreen_widget_bounds_);
+ break;
+ }
+
+ case ui::ET_GESTURE_END:
+ case ui::ET_MOUSE_RELEASED: {
+ // Drag completion, either snap to fullscreen or close the App List based
+ // on where the drag ended. If fling velocity was over the threshold, snap
+ // to the next state in the direction of the fling.
+ int new_y_position = location.y() - initial_drag_separation_ +
+ fullscreen_widget_bounds_.y();
+ if (std::abs(last_fling_velocity_) > kLauncherDragVelocityThreshold) {
+ // If the user releases drag with velocity over the threshold, snap to
+ // the next state, ignoring the drag release position.
+ if (is_fullscreen_launcher_) {
+ if (last_fling_velocity_ > 0) {
+ ToPeeking();
+ }
+ } else {
+ if (last_fling_velocity_ > 0) {
+ CloseAppList();
+ } else if (last_fling_velocity_ < 0) {
+ ToFullscreen();
+ }
+ }
+ last_fling_velocity_ = 0;
+ } else {
+ // The drag release velocity was too low, so use the release point.
+ int launcher_snap_y =
+ is_fullscreen_launcher_ ? 0 : default_peeking_launcher_y_;
+ // If the user releases +/- 1/3 of launcher_threshold_ , snap to the
+ // next state.
+ if (std::abs(launcher_snap_y - new_y_position) <
+ (launcher_threshold_)) {
+ // If the drag released to the state above.
+ if (is_fullscreen_launcher_) {
+ ToFullscreen();
+ } else {
+ ToPeeking();
+ }
+ } else if ((launcher_snap_y + (launcher_threshold_)) < new_y_position) {
+ // If the user released to the state below.
+ if (is_fullscreen_launcher_) {
+ ToPeeking();
+ } else {
+ CloseAppList();
+ }
+ } else {
+ // if the user released to the state above, go to the state above.
+ ToFullscreen();
+ }
+ }
+ break;
+ }
+ default:
+ NOTREACHED();
+ break;
+ }
+}
+
void AppListView::OnBeforeBubbleWidgetInit(views::Widget::InitParams* params,
views::Widget* widget) const {
if (!params->native_widget) {
@@ -476,6 +614,42 @@ void AppListView::GetWidgetHitTestMask(gfx::Path* mask) const {
mask->addRect(gfx::RectToSkRect(GetBubbleFrameView()->GetContentsBounds()));
}
+void AppListView::OnMouseEvent(ui::MouseEvent* event) {
+ if (!launcher_background_shield_)
+ return;
+
+ switch (event->type()) {
+ case ui::ET_MOUSE_PRESSED:
+ case ui::ET_MOUSE_DRAGGED:
+ case ui::ET_MOUSE_RELEASED:
+ HandleDrag(event->location(), event->type());
+ event->SetHandled();
+ break;
+ default:
+ break;
+ }
+}
+
+void AppListView::OnGestureEvent(ui::GestureEvent* event) {
+ if (!launcher_background_shield_)
+ return;
+
+ switch (event->type()) {
+ case ui::ET_GESTURE_SCROLL_UPDATE:
+ last_fling_velocity_ = event->details().velocity_y();
+ HandleDrag(event->location(), event->type());
+ event->SetHandled();
+ break;
+ case ui::ET_GESTURE_SCROLL_BEGIN:
+ case ui::ET_GESTURE_END:
+ HandleDrag(event->location(), event->type());
+ event->SetHandled();
+ break;
+ default:
+ break;
+ }
+}
+
bool AppListView::AcceleratorPressed(const ui::Accelerator& accelerator) {
DCHECK_EQ(ui::VKEY_ESCAPE, accelerator.key_code());
@@ -491,6 +665,23 @@ bool AppListView::AcceleratorPressed(const ui::Accelerator& accelerator) {
}
void AppListView::Layout() {
+ // If the fullscreen feature has been enabled.
+ if (launcher_background_shield_) {
+ UpdateDimensions();
xiyuan 2017/05/26 18:27:31 Why this is needed? Shouldn't UpdateDimensions() o
newcomer 2017/05/26 23:20:21 You're correct. Thanks for pointing that out.
+
+ gfx::Rect recomputed_fullscreen_widget_bounds(
+ display_work_area_bounds_.x(), default_peeking_launcher_y_,
+ display_work_area_bounds_.width(),
+ display_work_area_bounds_.height() + kShelfSize);
+
+ fullscreen_widget_bounds_ = recomputed_fullscreen_widget_bounds;
xiyuan 2017/05/26 18:27:31 |fullscreen_widget_bounds_| is used to track the b
newcomer 2017/05/26 23:20:21 The bounds need to be updated when the screen rota
+
+ if (is_fullscreen_launcher_) {
+ ToFullscreen();
+ } else {
+ ToPeeking();
+ }
+ }
const gfx::Rect contents_bounds = GetContentsBounds();
// Make sure to layout |app_list_main_view_| and |speech_view_| at the center
@@ -511,6 +702,11 @@ void AppListView::Layout() {
speech_bounds.Inset(-speech_view_->GetInsets());
speech_view_->SetBoundsRect(speech_bounds);
}
+ // If the fullscreen feature has been enabled.
+ if (launcher_background_shield_) {
+ app_list_main_view_->contents_view()->Layout();
+ launcher_background_shield_->SetBoundsRect(contents_bounds);
+ }
}
void AppListView::SchedulePaintInRect(const gfx::Rect& rect) {
@@ -519,6 +715,27 @@ void AppListView::SchedulePaintInRect(const gfx::Rect& rect) {
GetBubbleFrameView()->SchedulePaint();
}
+void AppListView::ToFullscreen() {
+ fullscreen_widget_bounds_.set_y(0);
+ fullscreen_widget_->SetBounds(fullscreen_widget_bounds_);
+ is_fullscreen_launcher_ = true;
+ launcher_threshold_ = (fullscreen_widget_bounds_.height() + kShelfSize) /
+ kLauncherThresholdDenominator;
+}
+
+void AppListView::ToPeeking() {
+ fullscreen_widget_bounds_.set_y(default_peeking_launcher_y_);
+ fullscreen_widget_->SetBounds(fullscreen_widget_bounds_);
+ is_fullscreen_launcher_ = false;
+ launcher_threshold_ = (fullscreen_widget_bounds_.height() + kShelfSize -
+ kPeekingLauncherHeight) /
+ kLauncherThresholdDenominator;
+}
+
+bool AppListView::IsFullscreen() const {
+ return is_fullscreen_launcher_;
+}
+
void AppListView::OnWidgetDestroying(views::Widget* widget) {
BubbleDialogDelegateView::OnWidgetDestroying(widget);
if (delegate_ && widget == GetWidget())
@@ -603,4 +820,9 @@ void AppListView::OnSpeechRecognitionStateChanged(
}
}
+void AppListView::OnDisplayMetricsChanged(const display::Display& display,
+ uint32_t changed_metrics) {
+ Layout();
+}
+
} // namespace app_list

Powered by Google App Engine
This is Rietveld 408576698