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

Unified Diff: ash/wm/overview/window_selector_item.cc

Issue 690103008: Implemented swipe to close in overview mode. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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: ash/wm/overview/window_selector_item.cc
diff --git a/ash/wm/overview/window_selector_item.cc b/ash/wm/overview/window_selector_item.cc
index 0ec1a02858752cb7a358b6ae436ae0cf3de6a6fa..2440605d6762de9107d53ef5a3d37d9e467813f6 100644
--- a/ash/wm/overview/window_selector_item.cc
+++ b/ash/wm/overview/window_selector_item.cc
@@ -35,6 +35,19 @@ namespace ash {
namespace {
+// The minimum opacity used during touch scroll gestures.
+const float kMinimumOpacity = 0.2f;
flackr 2014/11/07 19:10:52 0.f seems like a decent close opacity. If you drag
bruthig 2015/01/02 16:49:17 I consulted with stevet@ with the 0.2f value. If w
+
+// The distance at which the minimum opacity should take effect.
+const float kMinimumOpacityDistance = 200.0f;
flackr 2014/11/07 19:10:52 Shouldn't this be the same as the close distance?
bruthig 2015/01/02 16:49:17 I agree, this should be in sync with the actual cl
+
+// Calculates the window opacity from the given scroll |distance|.
+float CalculateOpacityFromScrollDistance(int distance) {
+ float opacity =
+ 1.0 - static_cast<float>(abs(distance)) / kMinimumOpacityDistance;
+ return std::min(1.0f, std::max(kMinimumOpacity, opacity));
+}
+
gfx::Rect GetTransformedBounds(aura::Window* window) {
gfx::RectF bounds(ScreenUtil::ConvertRectToScreen(window->GetRootWindow(),
window->layer()->bounds()));
@@ -147,6 +160,38 @@ WindowSelectorItem::WindowListItem::WindowListItem(aura::Window* window)
WindowSelectorItem::WindowListItem::~WindowListItem() {
}
+void WindowSelectorItem::WindowListItem::Scroll(int delta_x) {
+ const float opacity = CalculateOpacityFromScrollDistance(delta_x);
+ ScopedTransformOverviewWindow::ScopedAnimationSettings animation_settings;
+ transform_window_->BeginScopedAnimation(
+ OverviewAnimationSettingsProvider::AnimationType::SELECTOR_ITEM_SCROLL,
+ &animation_settings);
+
+ gfx::Transform new_transform;
+ new_transform.Translate(delta_x, 0);
+ new_transform.PreconcatTransform(transform_window_->get_overview_transform());
+ transform_window_->SetTransform(transform_window_->window()->GetRootWindow(),
+ new_transform);
+
+ transform_window_->SetOpacity(opacity);
+}
+
+void WindowSelectorItem::WindowListItem::CancelScroll() {
+ aura::Window* window = transform_window_->window();
+ ScopedTransformOverviewWindow::ScopedAnimationSettings animation_settings;
+ transform_window_->BeginScopedAnimation(
+ OverviewAnimationSettingsProvider::AnimationType::
+ SELECTOR_ITEM_SCROLL_CANCEL,
+ &animation_settings);
+ // The target opacity is set before the transform so that the
+ // WindowSelectorItem::OnWindowTransformed handler can properly
+ // update the opacity of the close button to the window's target
+ // opacity.
+ transform_window_->SetOpacity(1.0);
+ transform_window_->SetTransform(window->GetRootWindow(),
+ transform_window_->get_overview_transform());
+}
+
void WindowSelectorItem::WindowListItem::Select() {
aura::Window* window = transform_window_->window();
wm::GetWindowState(window)->Activate();
@@ -332,6 +377,7 @@ void WindowSelectorItem::SetBounds(aura::Window* root_window,
// SetItemBounds is called before UpdateCloseButtonLayout so the close button
// can properly use the updated windows bounds.
UpdateCloseButtonLayout(animate);
+ SetCloseWindowDistanceMinimum(target_bounds_.size().width() / 2);
UpdateSelectorButtons();
}
@@ -400,12 +446,36 @@ void WindowSelectorItem::OnWindowTransformed(aura::Window* window) {
}
}
+void WindowSelectorItem::Scroll(int delta_x) {
+ for (WindowList::iterator iter = window_list_.begin();
+ iter != window_list_.end();
+ iter++) {
+ (*iter)->Scroll(delta_x);
+ }
+}
+
+void WindowSelectorItem::CancelScroll() {
+ for (WindowList::iterator iter = window_list_.begin();
+ iter != window_list_.end();
+ iter++) {
+ (*iter)->CancelScroll();
+ }
+}
+
void WindowSelectorItem::Select() {
aura::Window* selection_window = SelectionWindow();
if (selection_window)
wm::GetWindowState(selection_window)->Activate();
}
+void WindowSelectorItem::Close() {
+ for (WindowList::iterator iter = window_list_.begin();
+ iter != window_list_.end();
+ iter++) {
+ (*iter)->Close();
+ }
+}
+
void WindowSelectorItem::SetItemBounds(aura::Window* root_window,
const gfx::Rect& target_bounds,
bool animate) {
@@ -556,6 +626,16 @@ void WindowSelectorItem::CreateWindowLabel(const base::string16& title) {
window_label_->Show();
}
+void WindowSelectorItem::SetCloseWindowDistanceMinimum(int distance) {
+ selector_item_activate_window_button_->SetCloseWindowDistanceMinimum(
+ distance);
+ for (WindowList::iterator iter = window_list_.begin();
+ iter != window_list_.end();
+ ++iter) {
+ (*iter)->activate_button()->SetCloseWindowDistanceMinimum(distance);
+ }
+}
+
void WindowSelectorItem::UpdateSelectorButtons() {
selector_item_activate_window_button_->SetBounds(target_bounds());

Powered by Google App Engine
This is Rietveld 408576698