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

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

Issue 2918403006: CrOS Tablet Window management - Split Screen part I (Closed)
Patch Set: Fix failed tests. Created 3 years, 6 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: 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..223c8723779b7acba1f136bc868259a36f1bc8df 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 kPreDragScale = 0.04f;
oshima 2017/06/14 05:45:47 The scale will be applied during drag, correct? Ho
xdai1 2017/06/15 22:11:42 Yes. It will be applied during drag. Done.
+
// 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
+// maximized mode.
class ShieldButton : public views::CustomButton {
public:
ShieldButton(views::ButtonListener* listener, const base::string16& name)
@@ -128,6 +133,66 @@ class ShieldButton : public views::CustomButton {
// after the WindowSelectorItem has been destroyed.
void ResetListener() { listener_ = nullptr; }
+ // views::CustomButton overrides:
+ 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_);
+ }
+
protected:
// views::View:
const char* GetClassName() const override { return "ShieldButton"; }
@@ -398,7 +463,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 +599,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()) {
+ window_selector_->SelectWindow(this);
+ }
}
void WindowSelectorItem::OnWindowDestroying(aura::Window* window) {
@@ -557,6 +626,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 +832,27 @@ aura::Window* WindowSelectorItem::GetOverviewWindowForMinimizedStateForTest() {
return transform_window_.GetOverviewWindowForMinimizedState();
}
+void WindowSelectorItem::PrepareDrag() {
+ gfx::Rect scaled_bounds(target_bounds_);
+ scaled_bounds.Inset(-target_bounds_.width() * kPreDragScale,
+ -target_bounds_.height() * kPreDragScale);
+ OverviewAnimationType animation_type =
+ OverviewAnimationType::OVERVIEW_ANIMATION_CLOSING_SELECTOR_ITEM;
+ SetBounds(scaled_bounds, animation_type);
+
+ aura::Window* widget_window = item_widget_->GetNativeWindow();
+ if (widget_window && widget_window->parent() == GetWindow()->parent()) {
+ widget_window->parent()->StackChildAtTop(widget_window);
+ widget_window->parent()->StackChildBelow(GetWindow(), widget_window);
oshima 2017/06/14 05:45:47 This will not work if there is always on top windo
xdai1 2017/06/15 22:11:42 Done.
+ }
+}
+
+void WindowSelectorItem::EndDrag() {
+ aura::Window* widget_window = item_widget_->GetNativeWindow();
+ if (widget_window && widget_window->parent() == GetWindow()->parent()) {
+ widget_window->parent()->StackChildAtBottom(widget_window);
+ widget_window->parent()->StackChildBelow(GetWindow(), widget_window);
+ }
+}
+
} // namespace ash

Powered by Google App Engine
This is Rietveld 408576698