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

Side by Side Diff: ash/wm/overview/window_selector_item.cc

Issue 965813003: Removed the "Swipe to close in overview" feature. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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 unified diff | Download patch
« no previous file with comments | « ash/wm/overview/window_selector_item.h ('k') | ash/wm/overview/window_selector_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "ash/wm/overview/window_selector_item.h" 5 #include "ash/wm/overview/window_selector_item.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "ash/screen_util.h" 10 #include "ash/screen_util.h"
(...skipping 19 matching lines...) Expand all
30 #include "ui/views/border.h" 30 #include "ui/views/border.h"
31 #include "ui/views/controls/button/image_button.h" 31 #include "ui/views/controls/button/image_button.h"
32 #include "ui/views/layout/box_layout.h" 32 #include "ui/views/layout/box_layout.h"
33 #include "ui/views/widget/widget.h" 33 #include "ui/views/widget/widget.h"
34 #include "ui/wm/core/window_util.h" 34 #include "ui/wm/core/window_util.h"
35 35
36 namespace ash { 36 namespace ash {
37 37
38 namespace { 38 namespace {
39 39
40 // The minimum fling velocity which will cause a window to be closed. Unit is
41 // pixels per second.
42 const float kMinimumFlingVelocity = 4000.0f;
43
44 // The minimum opacity used during touch scroll gestures.
45 const float kMinimumOpacity = 0.2f;
46
47 // In the conceptual overview table, the window margin is the space reserved 40 // In the conceptual overview table, the window margin is the space reserved
48 // around the window within the cell. This margin does not overlap so the 41 // around the window within the cell. This margin does not overlap so the
49 // closest distance between adjacent windows will be twice this amount. 42 // closest distance between adjacent windows will be twice this amount.
50 static const int kWindowMargin = 30; 43 static const int kWindowMargin = 30;
51 44
52 // Foreground label color. 45 // Foreground label color.
53 static const SkColor kLabelColor = SK_ColorWHITE; 46 static const SkColor kLabelColor = SK_ColorWHITE;
54 47
55 // Label shadow color. 48 // Label shadow color.
56 static const SkColor kLabelShadow = 0xB0000000; 49 static const SkColor kLabelShadow = 0xB0000000;
(...skipping 27 matching lines...) Expand all
84 // long the lay out animations take. 77 // long the lay out animations take.
85 void SetupFadeInAfterLayout(aura::Window* window) { 78 void SetupFadeInAfterLayout(aura::Window* window) {
86 ui::Layer* layer = window->layer(); 79 ui::Layer* layer = window->layer();
87 layer->SetOpacity(0.0f); 80 layer->SetOpacity(0.0f);
88 ScopedOverviewAnimationSettings animation_settings( 81 ScopedOverviewAnimationSettings animation_settings(
89 OverviewAnimationType::OVERVIEW_ANIMATION_ENTER_OVERVIEW_MODE_FADE_IN, 82 OverviewAnimationType::OVERVIEW_ANIMATION_ENTER_OVERVIEW_MODE_FADE_IN,
90 window); 83 window);
91 layer->SetOpacity(1.0f); 84 layer->SetOpacity(1.0f);
92 } 85 }
93 86
94 // Convenience method to fade out a window using the animation settings defined
95 // by OverviewAnimationType::OVERVIEW_ANIMATION_ENTER_OVERVIEW_MODE_FADE_OUT.
96 void SetupFadeOut(aura::Window* window) {
97 ScopedOverviewAnimationSettings animation_settings(
98 OverviewAnimationType::OVERVIEW_ANIMATION_ENTER_OVERVIEW_MODE_FADE_OUT,
99 window);
100 window->layer()->SetOpacity(0.0f);
101 }
102
103 // Calculates the window opacity from the given scroll |distance| and the
104 // |min opacity_distance|.
105 float CalculateOpacityFromScrollDistance(int distance,
106 int min_opacity_distance) {
107 float opacity =
108 1.0f - static_cast<float>(abs(distance)) / min_opacity_distance;
109 return std::min(1.0f, std::max(kMinimumOpacity, opacity));
110 }
111
112 // An image button with a close window icon. 87 // An image button with a close window icon.
113 class OverviewCloseButton : public views::ImageButton { 88 class OverviewCloseButton : public views::ImageButton {
114 public: 89 public:
115 explicit OverviewCloseButton(views::ButtonListener* listener); 90 explicit OverviewCloseButton(views::ButtonListener* listener);
116 ~OverviewCloseButton() override; 91 ~OverviewCloseButton() override;
117 92
118 private: 93 private:
119 DISALLOW_COPY_AND_ASSIGN(OverviewCloseButton); 94 DISALLOW_COPY_AND_ASSIGN(OverviewCloseButton);
120 }; 95 };
121 96
122 OverviewCloseButton::OverviewCloseButton(views::ButtonListener* listener) 97 OverviewCloseButton::OverviewCloseButton(views::ButtonListener* listener)
123 : views::ImageButton(listener) { 98 : views::ImageButton(listener) {
124 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 99 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
125 SetImage(views::CustomButton::STATE_NORMAL, 100 SetImage(views::CustomButton::STATE_NORMAL,
126 rb.GetImageSkiaNamed(IDR_AURA_WINDOW_OVERVIEW_CLOSE)); 101 rb.GetImageSkiaNamed(IDR_AURA_WINDOW_OVERVIEW_CLOSE));
127 SetImage(views::CustomButton::STATE_HOVERED, 102 SetImage(views::CustomButton::STATE_HOVERED,
128 rb.GetImageSkiaNamed(IDR_AURA_WINDOW_OVERVIEW_CLOSE_H)); 103 rb.GetImageSkiaNamed(IDR_AURA_WINDOW_OVERVIEW_CLOSE_H));
129 SetImage(views::CustomButton::STATE_PRESSED, 104 SetImage(views::CustomButton::STATE_PRESSED,
130 rb.GetImageSkiaNamed(IDR_AURA_WINDOW_OVERVIEW_CLOSE_P)); 105 rb.GetImageSkiaNamed(IDR_AURA_WINDOW_OVERVIEW_CLOSE_P));
131 } 106 }
132 107
133 OverviewCloseButton::~OverviewCloseButton() { 108 OverviewCloseButton::~OverviewCloseButton() {
134 } 109 }
135 110
136 } // namespace 111 } // namespace
137 112
138 WindowSelectorItem::OverviewLabelButton::OverviewLabelButton( 113 WindowSelectorItem::OverviewLabelButton::OverviewLabelButton(
139 WindowSelectorItem* selector_item, 114 views::ButtonListener* listener,
140 const base::string16& text) 115 const base::string16& text)
141 : LabelButton(selector_item, text), 116 : LabelButton(listener, text),
142 selector_item_(selector_item),
143 top_padding_(0) { 117 top_padding_(0) {
144 } 118 }
145 119
146 WindowSelectorItem::OverviewLabelButton::~OverviewLabelButton() { 120 WindowSelectorItem::OverviewLabelButton::~OverviewLabelButton() {
147 } 121 }
148 122
149 gfx::Rect WindowSelectorItem::OverviewLabelButton::GetChildAreaBounds() { 123 gfx::Rect WindowSelectorItem::OverviewLabelButton::GetChildAreaBounds() {
150 gfx::Rect bounds = GetLocalBounds(); 124 gfx::Rect bounds = GetLocalBounds();
151 bounds.Inset(0, top_padding_, 0, 0); 125 bounds.Inset(0, top_padding_, 0, 0);
152 return bounds; 126 return bounds;
153 } 127 }
154 128
155 void WindowSelectorItem::OverviewLabelButton::OnGestureEvent(
156 ui::GestureEvent* event) {
157 selector_item_->OnGestureEvent(event);
158 views::LabelButton::OnGestureEvent(event);
159 }
160
161 WindowSelectorItem::WindowSelectorItem(aura::Window* window) 129 WindowSelectorItem::WindowSelectorItem(aura::Window* window)
162 : dimmed_(false), 130 : dimmed_(false),
163 root_window_(window->GetRootWindow()), 131 root_window_(window->GetRootWindow()),
164 transform_window_(window), 132 transform_window_(window),
165 in_bounds_update_(false), 133 in_bounds_update_(false),
166 window_label_button_view_(nullptr), 134 window_label_button_view_(nullptr),
167 close_button_(new OverviewCloseButton(this)) { 135 close_button_(new OverviewCloseButton(this)) {
168 CreateWindowLabel(window->title()); 136 CreateWindowLabel(window->title());
169 views::Widget::InitParams params; 137 views::Widget::InitParams params;
170 params.type = views::Widget::InitParams::TYPE_POPUP; 138 params.type = views::Widget::InitParams::TYPE_POPUP;
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 void WindowSelectorItem::ButtonPressed(views::Button* sender, 221 void WindowSelectorItem::ButtonPressed(views::Button* sender,
254 const ui::Event& event) { 222 const ui::Event& event) {
255 if (sender == close_button_) { 223 if (sender == close_button_) {
256 transform_window_.Close(); 224 transform_window_.Close();
257 return; 225 return;
258 } 226 }
259 CHECK(sender == window_label_button_view_); 227 CHECK(sender == window_label_button_view_);
260 wm::GetWindowState(transform_window_.window())->Activate(); 228 wm::GetWindowState(transform_window_.window())->Activate();
261 } 229 }
262 230
263 void WindowSelectorItem::OnGestureEvent(ui::GestureEvent* event) {
264 if (!Shell::GetInstance()
265 ->window_selector_controller()
266 ->swipe_to_close_enabled())
267 return;
268
269 int delta_x = 0;
270 if (event->type() == ui::ET_GESTURE_SCROLL_BEGIN)
271 scroll_x_origin_ = event->x();
272 else
273 delta_x = event->x() - scroll_x_origin_;
274
275 switch (event->type()) {
276 case ui::ET_GESTURE_SCROLL_BEGIN: {
277 // We need to call SetHandled() for the ET_GESTURE_SCROLL_BEGIN event so
278 // that future ET_GESTURE_SCROLL_* events are sent here.
279 event->SetHandled();
280 close_button_->SetEnabled(false);
281 SetupFadeOut(close_button_widget_.GetNativeWindow());
282 break;
283 }
284 case ui::ET_GESTURE_SCROLL_UPDATE: {
285 event->SetHandled();
286 ScopedTransformOverviewWindow::ScopedAnimationSettings animation_settings;
287 transform_window_.BeginScopedAnimation(
288 OverviewAnimationType::OVERVIEW_ANIMATION_SCROLL_SELECTOR_ITEM,
289 &animation_settings);
290
291 gfx::Transform new_transform;
292 new_transform.Translate(delta_x, 0);
293 new_transform.PreconcatTransform(
294 transform_window_.get_overview_transform());
295 transform_window_.SetTransform(root_window(), new_transform);
296
297 const float opacity = CalculateOpacityFromScrollDistance(
298 delta_x, GetMinimumCloseDistance());
299 transform_window_.SetOpacity(opacity);
300 break;
301 }
302 case ui::ET_GESTURE_SCROLL_END: {
303 event->SetHandled();
304 if (abs(delta_x) > GetMinimumCloseDistance()) {
305 transform_window_.Close();
306 break;
307 }
308 ResetScrolledWindow();
309 break;
310 }
311 case ui::ET_SCROLL_FLING_START: {
312 event->SetHandled();
313 if (abs(delta_x) > GetMinimumCloseDistance() ||
314 fabs(event->details().velocity_x()) > kMinimumFlingVelocity) {
315 transform_window_.Close();
316 break;
317 }
318 ResetScrolledWindow();
319 break;
320 }
321 case ui::ET_GESTURE_END:
322 scroll_x_origin_ = 0;
323 break;
324 default:
325 break;
326 }
327 }
328
329 void WindowSelectorItem::OnWindowDestroying(aura::Window* window) { 231 void WindowSelectorItem::OnWindowDestroying(aura::Window* window) {
330 window->RemoveObserver(this); 232 window->RemoveObserver(this);
331 transform_window_.OnWindowDestroyed(); 233 transform_window_.OnWindowDestroyed();
332 } 234 }
333 235
334 void WindowSelectorItem::OnWindowTitleChanged(aura::Window* window) { 236 void WindowSelectorItem::OnWindowTitleChanged(aura::Window* window) {
335 // TODO(flackr): Maybe add the new title to a vector of titles so that we can 237 // TODO(flackr): Maybe add the new title to a vector of titles so that we can
336 // filter any of the titles the window had while in the overview session. 238 // filter any of the titles the window had while in the overview session.
337 window_label_button_view_->SetText(window->title()); 239 window_label_button_view_->SetText(window->title());
338 UpdateCloseButtonAccessibilityName(); 240 UpdateCloseButtonAccessibilityName();
339 } 241 }
340 242
341 void WindowSelectorItem::ResetScrolledWindow() {
342 ScopedTransformOverviewWindow::ScopedAnimationSettings animation_settings;
343 transform_window_.BeginScopedAnimation(
344 OverviewAnimationType::OVERVIEW_ANIMATION_CANCEL_SELECTOR_ITEM_SCROLL,
345 &animation_settings);
346
347 transform_window_.SetTransform(root_window(),
348 transform_window_.get_overview_transform());
349 transform_window_.SetOpacity(1.0);
350
351 SetupFadeInAfterLayout(close_button_widget_.GetNativeWindow());
352 close_button_->SetEnabled(true);
353 }
354
355 void WindowSelectorItem::SetItemBounds(const gfx::Rect& target_bounds, 243 void WindowSelectorItem::SetItemBounds(const gfx::Rect& target_bounds,
356 OverviewAnimationType animation_type) { 244 OverviewAnimationType animation_type) {
357 DCHECK(root_window_ == GetWindow()->GetRootWindow()); 245 DCHECK(root_window_ == GetWindow()->GetRootWindow());
358 gfx::Rect screen_bounds = transform_window_.GetTargetBoundsInScreen(); 246 gfx::Rect screen_bounds = transform_window_.GetTargetBoundsInScreen();
359 gfx::Rect selector_item_bounds = 247 gfx::Rect selector_item_bounds =
360 ScopedTransformOverviewWindow::ShrinkRectToFitPreservingAspectRatio( 248 ScopedTransformOverviewWindow::ShrinkRectToFitPreservingAspectRatio(
361 screen_bounds, target_bounds); 249 screen_bounds, target_bounds);
362 gfx::Transform transform = 250 gfx::Transform transform =
363 ScopedTransformOverviewWindow::GetTransformForRect(screen_bounds, 251 ScopedTransformOverviewWindow::GetTransformForRect(screen_bounds,
364 selector_item_bounds); 252 selector_item_bounds);
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 close_button_widget_.GetNativeWindow()->SetTransform( 337 close_button_widget_.GetNativeWindow()->SetTransform(
450 close_button_transform); 338 close_button_transform);
451 } 339 }
452 340
453 void WindowSelectorItem::UpdateCloseButtonAccessibilityName() { 341 void WindowSelectorItem::UpdateCloseButtonAccessibilityName() {
454 close_button_->SetAccessibleName(l10n_util::GetStringFUTF16( 342 close_button_->SetAccessibleName(l10n_util::GetStringFUTF16(
455 IDS_ASH_OVERVIEW_CLOSE_ITEM_BUTTON_ACCESSIBLE_NAME, 343 IDS_ASH_OVERVIEW_CLOSE_ITEM_BUTTON_ACCESSIBLE_NAME,
456 GetWindow()->title())); 344 GetWindow()->title()));
457 } 345 }
458 346
459 int WindowSelectorItem::GetMinimumCloseDistance() const {
460 return target_bounds_.size().width() / 2;
461 }
462
463 } // namespace ash 347 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/overview/window_selector_item.h ('k') | ash/wm/overview/window_selector_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698