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 0cf23ccd1da399f56cd8452c3f8d2d16bc9c96ef..7f5c3885785aeee747925d880a4d658435699790 100644 |
--- a/ash/wm/overview/window_selector_item.cc |
+++ b/ash/wm/overview/window_selector_item.cc |
@@ -99,6 +99,10 @@ static const int kExitFadeInMilliseconds = 30; |
// this fraction of size. |
static const float kPreCloseScale = 0.02f; |
+// Before dragging an overview window, the window will scale up |kPreDragScale| |
+// to indicate its selection. |
+static const float kDragWindowScale = 0.04f; |
+ |
// Convenience method to fade in a Window with predefined animation settings. |
// Note: The fade in animation will occur after a delay where the delay is how |
// long the lay out animations take. |
@@ -111,8 +115,9 @@ void SetupFadeInAfterLayout(views::Widget* widget) { |
window->layer()->SetOpacity(1.0f); |
} |
-// A Button that has a listener and listens to mouse clicks on the visible part |
-// of an overview window. |
+// A Button that has a listener and listens to mouse / gesture events on the |
+// visible part of an overview window. Note the drag events are only handled in |
varkha
2017/06/21 01:51:53
nit: "Note:" or "Note that"
xdai1
2017/06/22 21:46:34
Done.
|
+// maximized mode. |
class ShieldButton : public views::CustomButton { |
public: |
ShieldButton(views::ButtonListener* listener, const base::string16& name) |
@@ -128,6 +133,65 @@ class ShieldButton : public views::CustomButton { |
// after the WindowSelectorItem has been destroyed. |
void ResetListener() { listener_ = nullptr; } |
+ // views::CustomButton overrides: |
varkha
2017/06/21 01:51:53
nit: "// views::CustomButton:" for consistency.
xdai1
2017/06/22 21:46:34
Done.
|
+ bool OnMousePressed(const ui::MouseEvent& event) override { |
+ if (listener() && SplitViewController::ShouldAllowSplitView()) { |
+ gfx::Point location(event.location()); |
+ views::View::ConvertPointToScreen(this, &location); |
+ listener()->HandlePressEvent(location); |
+ return true; |
+ } |
+ return views::CustomButton::OnMousePressed(event); |
+ } |
+ |
+ void OnMouseReleased(const ui::MouseEvent& event) override { |
+ if (listener() && SplitViewController::ShouldAllowSplitView()) { |
+ gfx::Point location(event.location()); |
+ views::View::ConvertPointToScreen(this, &location); |
+ listener()->HandleReleaseEvent(location); |
+ return; |
+ } |
+ views::CustomButton::OnMouseReleased(event); |
+ } |
+ |
+ bool OnMouseDragged(const ui::MouseEvent& event) override { |
+ if (listener() && SplitViewController::ShouldAllowSplitView()) { |
+ gfx::Point location(event.location()); |
+ views::View::ConvertPointToScreen(this, &location); |
+ listener()->HandleDragEvent(location); |
+ return true; |
+ } |
+ return views::CustomButton::OnMouseDragged(event); |
+ } |
+ |
+ void OnGestureEvent(ui::GestureEvent* event) override { |
+ if (listener() && SplitViewController::ShouldAllowSplitView()) { |
+ gfx::Point location(event->location()); |
+ views::View::ConvertPointToScreen(this, &location); |
+ switch (event->type()) { |
+ case ui::ET_GESTURE_SCROLL_BEGIN: |
+ case ui::ET_GESTURE_TAP_DOWN: |
+ listener()->HandlePressEvent(location); |
+ break; |
+ case ui::ET_GESTURE_SCROLL_UPDATE: |
+ listener()->HandleDragEvent(location); |
+ break; |
+ case ui::ET_GESTURE_END: |
+ listener()->HandleReleaseEvent(location); |
+ break; |
+ default: |
+ break; |
+ } |
+ event->SetHandled(); |
+ return; |
+ } |
+ views::CustomButton::OnGestureEvent(event); |
+ } |
+ |
+ WindowSelectorItem* listener() { |
+ return static_cast<WindowSelectorItem*>(listener_); |
varkha
2017/06/21 01:51:53
Since this is a local class, I think it would look
xdai1
2017/06/22 21:46:34
|listener_| is a class member variable from the ba
varkha
2017/06/26 16:40:07
Acknowledged.
|
+ } |
+ |
protected: |
// views::View: |
const char* GetClassName() const override { return "ShieldButton"; } |
@@ -398,7 +462,7 @@ WindowSelectorItem::WindowSelectorItem(aura::Window* window, |
WindowSelector* window_selector) |
: dimmed_(false), |
root_window_(window->GetRootWindow()), |
- transform_window_(window), |
+ transform_window_(this, window), |
in_bounds_update_(false), |
selected_(false), |
caption_container_view_(nullptr), |
@@ -534,7 +598,11 @@ void WindowSelectorItem::ButtonPressed(views::Button* sender, |
return; |
} |
CHECK(sender == caption_container_view_->listener_button()); |
- window_selector_->SelectWindow(this); |
+ |
+ // For other cases, the event is handled in OverviewWindowDragController. |
+ if (!SplitViewController::ShouldAllowSplitView()) { |
varkha
2017/06/21 01:51:53
nit: no {}
xdai1
2017/06/22 21:46:34
Done.
|
+ window_selector_->SelectWindow(this); |
+ } |
} |
void WindowSelectorItem::OnWindowDestroying(aura::Window* window) { |
@@ -557,6 +625,22 @@ float WindowSelectorItem::GetItemScale(const gfx::Size& size) { |
close_button_->GetPreferredSize().height()); |
} |
+void WindowSelectorItem::HandlePressEvent( |
+ const gfx::Point& location_in_screen) { |
+ PrepareDrag(); |
+ window_selector_->InitiateDrag(this, location_in_screen); |
+} |
+ |
+void WindowSelectorItem::HandleReleaseEvent( |
+ const gfx::Point& location_in_screen) { |
+ EndDrag(); |
+ window_selector_->CompleteDrag(this); |
+} |
+ |
+void WindowSelectorItem::HandleDragEvent(const gfx::Point& location_in_screen) { |
+ window_selector_->Drag(this, location_in_screen); |
+} |
+ |
gfx::Rect WindowSelectorItem::GetTargetBoundsInScreen() const { |
return transform_window_.GetTargetBoundsInScreen(); |
} |
@@ -747,4 +831,29 @@ aura::Window* WindowSelectorItem::GetOverviewWindowForMinimizedStateForTest() { |
return transform_window_.GetOverviewWindowForMinimizedState(); |
} |
+void WindowSelectorItem::PrepareDrag() { |
+ gfx::Rect scaled_bounds(target_bounds_); |
+ scaled_bounds.Inset(-target_bounds_.width() * kDragWindowScale, |
+ -target_bounds_.height() * kDragWindowScale); |
+ OverviewAnimationType animation_type = |
+ OverviewAnimationType::OVERVIEW_ANIMATION_CLOSING_SELECTOR_ITEM; |
+ SetBounds(scaled_bounds, animation_type); |
varkha
2017/06/21 01:51:53
Don't you need to revert this somewhere?
xdai1
2017/06/22 21:46:34
I don't think it's necessary since if the window w
varkha
2017/06/26 16:40:07
Acknowledged.
|
+ |
+ aura::Window* widget_window = item_widget_->GetNativeWindow(); |
+ if (widget_window && widget_window->parent() == GetWindow()->parent()) { |
+ // TODO(xdai): This might not work if there is an always on top window. |
+ // See crbug.com/733760. |
+ widget_window->parent()->StackChildAtTop(widget_window); |
+ widget_window->parent()->StackChildBelow(GetWindow(), widget_window); |
+ } |
+} |
+ |
+void WindowSelectorItem::EndDrag() { |
+ aura::Window* widget_window = item_widget_->GetNativeWindow(); |
+ if (widget_window && widget_window->parent() == GetWindow()->parent()) { |
+ widget_window->parent()->StackChildAtBottom(widget_window); |
varkha
2017/06/21 01:51:53
I don't think we should be changing the order rela
xdai1
2017/06/22 21:46:34
I changed the animation time and confirmed that th
|
+ widget_window->parent()->StackChildBelow(GetWindow(), widget_window); |
+ } |
+} |
+ |
} // namespace ash |