Chromium Code Reviews| Index: ash/wm/overview/transparent_activate_window_button.cc |
| diff --git a/ash/wm/overview/transparent_activate_window_button.cc b/ash/wm/overview/transparent_activate_window_button.cc |
| index a50e104e2062d8179d6097875e87919bf0941d74..a9d14a29389bbd2b584868bccd0485bf5f5983ec 100644 |
| --- a/ash/wm/overview/transparent_activate_window_button.cc |
| +++ b/ash/wm/overview/transparent_activate_window_button.cc |
| @@ -6,9 +6,11 @@ |
| #include <vector> |
| +#include "ash/ash_switches.h" |
| #include "ash/shell.h" |
| #include "ash/shell_window_ids.h" |
| #include "ash/wm/overview/transparent_activate_window_button_delegate.h" |
| +#include "base/command_line.h" |
| #include "ui/events/event.h" |
| #include "ui/events/gesture_event_details.h" |
| #include "ui/views/controls/button/custom_button.h" |
| @@ -19,6 +21,13 @@ namespace ash { |
| namespace { |
| const char kTransparentButtonName[] = "TransparentButton"; |
| +// The default close window distance minimum. |
| +const int kDefaultCloseWindowDistanceMinimum = 100; |
|
flackr
2014/11/07 19:10:52
Looks like this will never actually be used since
bruthig
2015/01/02 16:49:17
That is correct. I'm not sure if you are suggesti
|
| + |
| +// The minimum fling velocity which will cause a window to be closed. Unit is |
| +// pixels per second. |
| +const float kMinimumFlingVelocity = 4000.0f; |
|
jonross
2014/11/12 23:57:03
Won't be needed if we decide to just close on flin
bruthig
2015/01/02 16:49:17
Windows are closed too easily if using all flings.
|
| + |
| // Initializes the event handler transparent window. |
| views::Widget* InitEventHandler(aura::Window* root_window) { |
| views::Widget* widget = new views::Widget; |
| @@ -52,6 +61,10 @@ class TransparentButton : public views::CustomButton { |
| TransparentActivateWindowButtonDelegate* delegate() { return delegate_; } |
| + void set_close_window_distance_minimum(int distance) { |
| + close_window_distance_minimum_ = distance; |
|
flackr
2014/11/07 19:10:52
I think setting the close distance to a proportion
bruthig
2015/01/02 16:49:17
Not 100% sure I understand but I will take a shot.
jonross
2015/01/06 15:02:27
Can the size of the WindowSelectionItem be accesse
|
| + } |
| + |
| // views::View: |
| virtual void OnGestureEvent(ui::GestureEvent* event) override; |
| virtual void OnMouseEvent(ui::MouseEvent* event) override; |
| @@ -63,6 +76,21 @@ class TransparentButton : public views::CustomButton { |
| private: |
| TransparentActivateWindowButtonDelegate* delegate_; |
| + // True if the swipe to close feature is disabled. |
| + const bool swipe_to_close_disabled_; |
|
flackr
2014/11/07 19:10:52
Follow the pattern used by kEnableTouchFeedback to
pkotwicz
2014/12/21 00:09:32
Drive by:
I dislike the pattern used with kEnable
bruthig
2015/01/02 16:49:17
This is a very good example of how statics are pro
jonross
2015/01/06 15:02:27
It does add a complexity, however you can have one
|
| + |
| + // The original X location for a tap down event. |original_x_| is in the local |
| + // coordinate space as |this|. |
| + float original_x_; |
| + |
| + // The velocity of the current fling gesture. A fling is active iff |
| + // |flint_velocity_x_| has a value greater than 0. |
| + float fling_velocity_x_; |
| + |
| + // The minimum distance, in pixels, for which a touch drag should cause a |
| + // window to be closed. |
| + int close_window_distance_minimum_; |
| + |
| DISALLOW_COPY_AND_ASSIGN(TransparentButton); |
| }; |
| @@ -70,7 +98,11 @@ TransparentButton::TransparentButton( |
| views::ButtonListener* listener, |
| TransparentActivateWindowButtonDelegate* delegate) |
| : CustomButton(listener), |
| - delegate_(delegate) { |
| + delegate_(delegate), |
| + swipe_to_close_disabled_(CommandLine::ForCurrentProcess()->HasSwitch( |
| + switches::kAshDisableSwipeToCloseInOverviewMode)), |
| + fling_velocity_x_(0.0f), |
| + close_window_distance_minimum_(kDefaultCloseWindowDistanceMinimum) { |
| } |
| TransparentButton::~TransparentButton() { |
| @@ -81,6 +113,8 @@ void TransparentButton::OnMouseEvent(ui::MouseEvent* event) { |
| // TransparentActivateWindowButton. |
| if (GetWidget()->HasCapture() && event->type() == ui::ET_MOUSE_PRESSED) { |
| GetWidget()->ReleaseCapture(); |
| + if (!swipe_to_close_disabled_) |
| + delegate_->CancelScroll(); |
| event->StopPropagation(); |
| return; |
| } |
| @@ -102,6 +136,40 @@ void TransparentButton::OnGestureEvent(ui::GestureEvent* event) { |
| GetWidget()->ReleaseCapture(); |
| } |
| + if (swipe_to_close_disabled_) { |
| + CustomButton::OnGestureEvent(event); |
| + return; |
| + } |
| + |
| + int delta_x = event->x() - original_x_; |
| + |
| + switch (event->type()) { |
| + case ui::ET_GESTURE_TAP_DOWN: |
| + original_x_ = event->x(); |
| + break; |
| + case ui::ET_GESTURE_SCROLL_BEGIN: |
| + case ui::ET_GESTURE_SCROLL_UPDATE: |
| + delegate_->Scroll(delta_x); |
| + break; |
| + case ui::ET_SCROLL_FLING_START: |
| + case ui::ET_SCROLL_FLING_CANCEL: |
|
flackr
2014/11/07 19:10:52
I don't think we need to worry about fling cancel
bruthig
2015/01/02 16:49:17
Done.
|
| + // event->details().velocity_x() will be zero when event->type() is |
| + // ui::ET_SCROLL_FLING_CANCEL. |
| + fling_velocity_x_ = fabs(event->details().velocity_x()); |
|
flackr
2014/11/07 19:10:52
Why do we need to save the fling velocity? If I re
jonross
2014/11/12 23:57:03
Currently used on line 162 to determine if fling i
bruthig
2015/01/02 16:49:17
It's easier IMO to only evaluate for one event typ
|
| + break; |
| + case ui::ET_GESTURE_END: |
| + if (abs(delta_x) > close_window_distance_minimum_ || |
| + fling_velocity_x_ > kMinimumFlingVelocity) { |
| + delegate_->Close(); |
| + } else { |
| + delegate_->CancelScroll(); |
| + } |
| + original_x_ = 0; |
| + fling_velocity_x_ = 0.0f; |
| + break; |
| + default: |
| + break; |
| + } |
| CustomButton::OnGestureEvent(event); |
| event->StopPropagation(); |
| } |
| @@ -126,6 +194,11 @@ void TransparentActivateWindowButton::SetBounds(const gfx::Rect& bounds) { |
| event_handler_widget_->SetBounds(bounds); |
| } |
| +void TransparentActivateWindowButton::SetCloseWindowDistanceMinimum( |
| + int distance) { |
| + transparent_button_->set_close_window_distance_minimum(distance); |
| +} |
| + |
| void TransparentActivateWindowButton::SendFocusAlert() const { |
| event_handler_widget_->GetContentsView()-> |
| NotifyAccessibilityEvent(ui::AX_EVENT_FOCUS, true); |