Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "ash/wm/toplevel_window_event_handler.h" |
| 6 | |
| 7 | #include "ash/shell.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 8 | #include "ash/wm/resize_shadow_controller.h" |
| 9 | #include "ash/wm/window_resizer.h" |
Torne (Richard Coles) | 68043e1 | 2013-09-26 13:24:57 +0100 | [diff] [blame] | 10 | #include "ash/wm/window_state.h" |
Torne (Richard Coles) | 4e180b6 | 2013-10-18 15:46:22 +0100 | [diff] [blame] | 11 | #include "ash/wm/window_state_observer.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 12 | #include "ash/wm/window_util.h" |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 13 | #include "ash/wm/wm_event.h" |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 14 | #include "base/message_loop/message_loop.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 15 | #include "base/run_loop.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 16 | #include "ui/aura/client/cursor_client.h" |
| 17 | #include "ui/aura/env.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 18 | #include "ui/aura/window.h" |
| 19 | #include "ui/aura/window_delegate.h" |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 20 | #include "ui/aura/window_event_dispatcher.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 21 | #include "ui/aura/window_observer.h" |
Torne (Richard Coles) | 23730a6 | 2014-03-21 14:25:57 +0000 | [diff] [blame] | 22 | #include "ui/aura/window_tree_host.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 23 | #include "ui/base/cursor/cursor.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 24 | #include "ui/base/hit_test.h" |
| 25 | #include "ui/base/ui_base_types.h" |
Torne (Richard Coles) | d0247b1 | 2013-09-19 22:36:51 +0100 | [diff] [blame] | 26 | #include "ui/events/event.h" |
| 27 | #include "ui/events/event_utils.h" |
Torne (Richard Coles) | 68043e1 | 2013-09-26 13:24:57 +0100 | [diff] [blame] | 28 | #include "ui/events/gestures/gesture_recognizer.h" |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 29 | #include "ui/gfx/geometry/point_conversions.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 30 | #include "ui/gfx/screen.h" |
| 31 | |
| 32 | namespace { |
| 33 | const double kMinHorizVelocityForWindowSwipe = 1100; |
| 34 | const double kMinVertVelocityForWindowMinimize = 1000; |
| 35 | } |
| 36 | |
| 37 | namespace ash { |
| 38 | |
| 39 | namespace { |
| 40 | |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 41 | // Returns whether |window| can be moved via a two finger drag given |
| 42 | // the hittest results of the two fingers. |
| 43 | bool CanStartTwoFingerMove(aura::Window* window, |
| 44 | int window_component1, |
| 45 | int window_component2) { |
| 46 | // We allow moving a window via two fingers when the hittest components are |
| 47 | // HTCLIENT. This is done so that a window can be dragged via two fingers when |
| 48 | // the tab strip is full and hitting the caption area is difficult. We check |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 49 | // the window type and the state type so that we do not steal touches from the |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 50 | // web contents. |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 51 | if (!wm::GetWindowState(window)->IsNormalOrSnapped() || |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 52 | window->type() != ui::wm::WINDOW_TYPE_NORMAL) { |
| 53 | return false; |
| 54 | } |
| 55 | int component1_behavior = |
| 56 | WindowResizer::GetBoundsChangeForWindowComponent(window_component1); |
| 57 | int component2_behavior = |
| 58 | WindowResizer::GetBoundsChangeForWindowComponent(window_component2); |
| 59 | return (component1_behavior & WindowResizer::kBoundsChange_Resizes) == 0 && |
| 60 | (component2_behavior & WindowResizer::kBoundsChange_Resizes) == 0; |
| 61 | } |
| 62 | |
| 63 | // Returns whether |window| can be moved or resized via one finger given |
| 64 | // |window_component|. |
| 65 | bool CanStartOneFingerDrag(int window_component) { |
| 66 | return WindowResizer::GetBoundsChangeForWindowComponent( |
| 67 | window_component) != 0; |
| 68 | } |
| 69 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 70 | gfx::Point ConvertPointToParent(aura::Window* window, |
| 71 | const gfx::Point& point) { |
| 72 | gfx::Point result(point); |
| 73 | aura::Window::ConvertPointToTarget(window, window->parent(), &result); |
| 74 | return result; |
| 75 | } |
| 76 | |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 77 | // Returns the window component containing |event|'s location. |
| 78 | int GetWindowComponent(aura::Window* window, const ui::LocatedEvent& event) { |
| 79 | return window->delegate()->GetNonClientComponent(event.location()); |
| 80 | } |
| 81 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 82 | } // namespace |
| 83 | |
| 84 | // ScopedWindowResizer --------------------------------------------------------- |
| 85 | |
| 86 | // Wraps a WindowResizer and installs an observer on its target window. When |
| 87 | // the window is destroyed ResizerWindowDestroyed() is invoked back on the |
| 88 | // ToplevelWindowEventHandler to clean up. |
| 89 | class ToplevelWindowEventHandler::ScopedWindowResizer |
Torne (Richard Coles) | 4e180b6 | 2013-10-18 15:46:22 +0100 | [diff] [blame] | 90 | : public aura::WindowObserver, |
| 91 | public wm::WindowStateObserver { |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 92 | public: |
| 93 | ScopedWindowResizer(ToplevelWindowEventHandler* handler, |
| 94 | WindowResizer* resizer); |
| 95 | virtual ~ScopedWindowResizer(); |
| 96 | |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 97 | // Returns true if the drag moves the window and does not resize. |
| 98 | bool IsMove() const; |
| 99 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 100 | WindowResizer* resizer() { return resizer_.get(); } |
| 101 | |
| 102 | // WindowObserver overrides: |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 103 | virtual void OnWindowDestroying(aura::Window* window) OVERRIDE; |
| 104 | |
Torne (Richard Coles) | 4e180b6 | 2013-10-18 15:46:22 +0100 | [diff] [blame] | 105 | // WindowStateObserver overrides: |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 106 | virtual void OnPreWindowStateTypeChange(wm::WindowState* window_state, |
| 107 | wm::WindowStateType type) OVERRIDE; |
Torne (Richard Coles) | 4e180b6 | 2013-10-18 15:46:22 +0100 | [diff] [blame] | 108 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 109 | private: |
| 110 | ToplevelWindowEventHandler* handler_; |
| 111 | scoped_ptr<WindowResizer> resizer_; |
| 112 | |
| 113 | DISALLOW_COPY_AND_ASSIGN(ScopedWindowResizer); |
| 114 | }; |
| 115 | |
| 116 | ToplevelWindowEventHandler::ScopedWindowResizer::ScopedWindowResizer( |
| 117 | ToplevelWindowEventHandler* handler, |
| 118 | WindowResizer* resizer) |
| 119 | : handler_(handler), |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 120 | resizer_(resizer) { |
| 121 | resizer_->GetTarget()->AddObserver(this); |
| 122 | wm::GetWindowState(resizer_->GetTarget())->AddObserver(this); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | ToplevelWindowEventHandler::ScopedWindowResizer::~ScopedWindowResizer() { |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 126 | resizer_->GetTarget()->RemoveObserver(this); |
| 127 | wm::GetWindowState(resizer_->GetTarget())->RemoveObserver(this); |
| 128 | } |
| 129 | |
| 130 | bool ToplevelWindowEventHandler::ScopedWindowResizer::IsMove() const { |
| 131 | return resizer_->details().bounds_change == |
| 132 | WindowResizer::kBoundsChange_Repositions; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 133 | } |
| 134 | |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 135 | void |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 136 | ToplevelWindowEventHandler::ScopedWindowResizer::OnPreWindowStateTypeChange( |
Torne (Richard Coles) | 4e180b6 | 2013-10-18 15:46:22 +0100 | [diff] [blame] | 137 | wm::WindowState* window_state, |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 138 | wm::WindowStateType old) { |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 139 | handler_->CompleteDrag(DRAG_COMPLETE); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | void ToplevelWindowEventHandler::ScopedWindowResizer::OnWindowDestroying( |
| 143 | aura::Window* window) { |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 144 | DCHECK_EQ(resizer_->GetTarget(), window); |
| 145 | handler_->ResizerWindowDestroyed(); |
| 146 | } |
| 147 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 148 | // ToplevelWindowEventHandler -------------------------------------------------- |
| 149 | |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 150 | ToplevelWindowEventHandler::ToplevelWindowEventHandler() |
| 151 | : first_finger_hittest_(HTNOWHERE), |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 152 | in_move_loop_(false), |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 153 | in_gesture_drag_(false), |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 154 | drag_reverted_(false), |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 155 | destroyed_(NULL) { |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 156 | Shell::GetInstance()->display_controller()->AddObserver(this); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | ToplevelWindowEventHandler::~ToplevelWindowEventHandler() { |
| 160 | Shell::GetInstance()->display_controller()->RemoveObserver(this); |
| 161 | if (destroyed_) |
| 162 | *destroyed_ = true; |
| 163 | } |
| 164 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 165 | void ToplevelWindowEventHandler::OnKeyEvent(ui::KeyEvent* event) { |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 166 | if (window_resizer_.get() && event->type() == ui::ET_KEY_PRESSED && |
| 167 | event->key_code() == ui::VKEY_ESCAPE) { |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 168 | CompleteDrag(DRAG_REVERT); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 169 | } |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 170 | } |
| 171 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 172 | void ToplevelWindowEventHandler::OnMouseEvent( |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 173 | ui::MouseEvent* event) { |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 174 | if (event->handled()) |
| 175 | return; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 176 | if ((event->flags() & |
| 177 | (ui::EF_MIDDLE_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON)) != 0) |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 178 | return; |
| 179 | |
| 180 | if (in_gesture_drag_) |
| 181 | return; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 182 | |
| 183 | aura::Window* target = static_cast<aura::Window*>(event->target()); |
| 184 | switch (event->type()) { |
| 185 | case ui::ET_MOUSE_PRESSED: |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 186 | HandleMousePressed(target, event); |
| 187 | break; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 188 | case ui::ET_MOUSE_DRAGGED: |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 189 | HandleDrag(target, event); |
| 190 | break; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 191 | case ui::ET_MOUSE_CAPTURE_CHANGED: |
| 192 | case ui::ET_MOUSE_RELEASED: |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 193 | HandleMouseReleased(target, event); |
| 194 | break; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 195 | case ui::ET_MOUSE_MOVED: |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 196 | HandleMouseMoved(target, event); |
| 197 | break; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 198 | case ui::ET_MOUSE_EXITED: |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 199 | HandleMouseExited(target, event); |
| 200 | break; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 201 | default: |
| 202 | break; |
| 203 | } |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 204 | } |
| 205 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 206 | void ToplevelWindowEventHandler::OnGestureEvent(ui::GestureEvent* event) { |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 207 | if (event->handled()) |
| 208 | return; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 209 | aura::Window* target = static_cast<aura::Window*>(event->target()); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 210 | if (!target->delegate()) |
| 211 | return; |
| 212 | |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 213 | if (window_resizer_.get() && !in_gesture_drag_) |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 214 | return; |
| 215 | |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 216 | if (window_resizer_.get() && |
| 217 | window_resizer_->resizer()->GetTarget() != target) { |
| 218 | return; |
| 219 | } |
| 220 | |
| 221 | if (event->details().touch_points() > 2) { |
| 222 | if (window_resizer_.get()) { |
| 223 | CompleteDrag(DRAG_COMPLETE); |
| 224 | event->StopPropagation(); |
| 225 | } |
| 226 | return; |
| 227 | } |
| 228 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 229 | switch (event->type()) { |
Ben Murdoch | ba5b9a6 | 2013-08-12 14:20:17 +0100 | [diff] [blame] | 230 | case ui::ET_GESTURE_TAP_DOWN: { |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 231 | int component = GetWindowComponent(target, *event); |
Ben Murdoch | ba5b9a6 | 2013-08-12 14:20:17 +0100 | [diff] [blame] | 232 | if (!(WindowResizer::GetBoundsChangeForWindowComponent(component) & |
| 233 | WindowResizer::kBoundsChange_Resizes)) |
| 234 | return; |
Ben Murdoch | c5cede9 | 2014-04-10 11:22:14 +0100 | [diff] [blame] | 235 | ResizeShadowController* controller = |
Ben Murdoch | ba5b9a6 | 2013-08-12 14:20:17 +0100 | [diff] [blame] | 236 | Shell::GetInstance()->resize_shadow_controller(); |
| 237 | if (controller) |
| 238 | controller->ShowShadow(target, component); |
| 239 | return; |
| 240 | } |
| 241 | case ui::ET_GESTURE_END: { |
Ben Murdoch | c5cede9 | 2014-04-10 11:22:14 +0100 | [diff] [blame] | 242 | ResizeShadowController* controller = |
Ben Murdoch | ba5b9a6 | 2013-08-12 14:20:17 +0100 | [diff] [blame] | 243 | Shell::GetInstance()->resize_shadow_controller(); |
| 244 | if (controller) |
| 245 | controller->HideShadow(target); |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 246 | |
| 247 | if (window_resizer_.get() && |
| 248 | (event->details().touch_points() == 1 || |
| 249 | !CanStartOneFingerDrag(first_finger_hittest_))) { |
| 250 | CompleteDrag(DRAG_COMPLETE); |
| 251 | event->StopPropagation(); |
| 252 | } |
| 253 | return; |
| 254 | } |
| 255 | case ui::ET_GESTURE_BEGIN: { |
| 256 | if (event->details().touch_points() == 1) { |
| 257 | first_finger_hittest_ = GetWindowComponent(target, *event); |
| 258 | } else if (window_resizer_.get()) { |
| 259 | if (!window_resizer_->IsMove()) { |
| 260 | // The transition from resizing with one finger to resizing with two |
| 261 | // fingers causes unintended resizing because the location of |
| 262 | // ET_GESTURE_SCROLL_UPDATE jumps from the position of the first |
| 263 | // finger to the position in the middle of the two fingers. For this |
| 264 | // reason two finger resizing is not supported. |
| 265 | CompleteDrag(DRAG_COMPLETE); |
| 266 | event->StopPropagation(); |
| 267 | } |
| 268 | } else { |
| 269 | int second_finger_hittest = GetWindowComponent(target, *event); |
| 270 | if (CanStartTwoFingerMove( |
| 271 | target, first_finger_hittest_, second_finger_hittest)) { |
| 272 | gfx::Point location_in_parent = |
| 273 | event->details().bounding_box().CenterPoint(); |
| 274 | AttemptToStartDrag(target, location_in_parent, HTCAPTION, |
| 275 | aura::client::WINDOW_MOVE_SOURCE_TOUCH); |
| 276 | event->StopPropagation(); |
| 277 | } |
| 278 | } |
Ben Murdoch | ba5b9a6 | 2013-08-12 14:20:17 +0100 | [diff] [blame] | 279 | return; |
| 280 | } |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 281 | case ui::ET_GESTURE_SCROLL_BEGIN: { |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 282 | // The one finger drag is not started in ET_GESTURE_BEGIN to avoid the |
| 283 | // window jumping upon initiating a two finger drag. When a one finger |
| 284 | // drag is converted to a two finger drag, a jump occurs because the |
| 285 | // location of the ET_GESTURE_SCROLL_UPDATE event switches from the single |
| 286 | // finger's position to the position in the middle of the two fingers. |
| 287 | if (window_resizer_.get()) |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 288 | return; |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 289 | int component = GetWindowComponent(target, *event); |
| 290 | if (!CanStartOneFingerDrag(component)) |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 291 | return; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 292 | gfx::Point location_in_parent( |
| 293 | ConvertPointToParent(target, event->location())); |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 294 | AttemptToStartDrag(target, location_in_parent, component, |
| 295 | aura::client::WINDOW_MOVE_SOURCE_TOUCH); |
| 296 | event->StopPropagation(); |
| 297 | return; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 298 | } |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 299 | default: |
| 300 | break; |
| 301 | } |
| 302 | |
| 303 | if (!window_resizer_.get()) |
| 304 | return; |
| 305 | |
| 306 | switch (event->type()) { |
| 307 | case ui::ET_GESTURE_SCROLL_UPDATE: |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 308 | HandleDrag(target, event); |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 309 | event->StopPropagation(); |
| 310 | return; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 311 | case ui::ET_GESTURE_SCROLL_END: |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 312 | // We must complete the drag here instead of as a result of ET_GESTURE_END |
| 313 | // because otherwise the drag will be reverted when EndMoveLoop() is |
| 314 | // called. |
| 315 | // TODO(pkotwicz): Pass drag completion status to |
| 316 | // WindowMoveClient::EndMoveLoop(). |
| 317 | CompleteDrag(DRAG_COMPLETE); |
| 318 | event->StopPropagation(); |
| 319 | return; |
| 320 | case ui::ET_SCROLL_FLING_START: |
| 321 | CompleteDrag(DRAG_COMPLETE); |
| 322 | |
| 323 | // TODO(pkotwicz): Fix tests which inadvertantly start flings and check |
| 324 | // window_resizer_->IsMove() instead of the hittest component at |event|'s |
| 325 | // location. |
| 326 | if (GetWindowComponent(target, *event) != HTCAPTION || |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 327 | !wm::GetWindowState(target)->IsNormalOrSnapped()) { |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 328 | return; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 329 | } |
| 330 | |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 331 | if (event->details().velocity_y() > kMinVertVelocityForWindowMinimize) { |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 332 | SetWindowStateTypeFromGesture(target, wm::WINDOW_STATE_TYPE_MINIMIZED); |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 333 | } else if (event->details().velocity_y() < |
| 334 | -kMinVertVelocityForWindowMinimize) { |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 335 | SetWindowStateTypeFromGesture(target, wm::WINDOW_STATE_TYPE_MAXIMIZED); |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 336 | } else if (event->details().velocity_x() > |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 337 | kMinHorizVelocityForWindowSwipe) { |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 338 | SetWindowStateTypeFromGesture(target, |
| 339 | wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED); |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 340 | } else if (event->details().velocity_x() < |
| 341 | -kMinHorizVelocityForWindowSwipe) { |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 342 | SetWindowStateTypeFromGesture(target, |
| 343 | wm::WINDOW_STATE_TYPE_LEFT_SNAPPED); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 344 | } |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 345 | event->StopPropagation(); |
| 346 | return; |
Torne (Richard Coles) | cedac22 | 2014-06-03 10:58:34 +0100 | [diff] [blame] | 347 | case ui::ET_GESTURE_SWIPE: |
| 348 | DCHECK_GT(event->details().touch_points(), 0); |
| 349 | if (event->details().touch_points() == 1) |
| 350 | return; |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 351 | if (!wm::GetWindowState(target)->IsNormalOrSnapped()) |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 352 | return; |
| 353 | |
| 354 | CompleteDrag(DRAG_COMPLETE); |
| 355 | |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 356 | if (event->details().swipe_down()) { |
| 357 | SetWindowStateTypeFromGesture(target, wm::WINDOW_STATE_TYPE_MINIMIZED); |
| 358 | } else if (event->details().swipe_up()) { |
| 359 | SetWindowStateTypeFromGesture(target, wm::WINDOW_STATE_TYPE_MAXIMIZED); |
| 360 | } else if (event->details().swipe_right()) { |
| 361 | SetWindowStateTypeFromGesture(target, |
| 362 | wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED); |
| 363 | } else { |
| 364 | SetWindowStateTypeFromGesture(target, |
| 365 | wm::WINDOW_STATE_TYPE_LEFT_SNAPPED); |
| 366 | } |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 367 | event->StopPropagation(); |
| 368 | return; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 369 | default: |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 370 | return; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 371 | } |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | aura::client::WindowMoveResult ToplevelWindowEventHandler::RunMoveLoop( |
| 375 | aura::Window* source, |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 376 | const gfx::Vector2d& drag_offset, |
| 377 | aura::client::WindowMoveSource move_source) { |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 378 | DCHECK(!in_move_loop_); // Can only handle one nested loop at a time. |
Torne (Richard Coles) | 1e9bf3e | 2013-10-31 11:16:26 +0000 | [diff] [blame] | 379 | aura::Window* root_window = source->GetRootWindow(); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 380 | DCHECK(root_window); |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 381 | // TODO(tdresser): Use gfx::PointF. See crbug.com/337824. |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 382 | gfx::Point drag_location; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 383 | if (move_source == aura::client::WINDOW_MOVE_SOURCE_TOUCH && |
| 384 | aura::Env::GetInstance()->is_touch_down()) { |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 385 | gfx::PointF drag_location_f; |
Torne (Richard Coles) | 8bcbed8 | 2013-10-22 16:41:35 +0100 | [diff] [blame] | 386 | bool has_point = ui::GestureRecognizer::Get()-> |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 387 | GetLastTouchPointForTarget(source, &drag_location_f); |
| 388 | drag_location = gfx::ToFlooredPoint(drag_location_f); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 389 | DCHECK(has_point); |
| 390 | } else { |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 391 | drag_location = |
| 392 | root_window->GetHost()->dispatcher()->GetLastMouseLocationInRoot(); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 393 | aura::Window::ConvertPointToTarget( |
| 394 | root_window, source->parent(), &drag_location); |
| 395 | } |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 396 | // Set the cursor before calling AttemptToStartDrag(), as that will |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 397 | // eventually call LockCursor() and prevent the cursor from changing. |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 398 | aura::client::CursorClient* cursor_client = |
| 399 | aura::client::GetCursorClient(root_window); |
| 400 | if (cursor_client) |
| 401 | cursor_client->SetCursor(ui::kCursorPointer); |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 402 | if (!AttemptToStartDrag(source, drag_location, HTCAPTION, move_source)) |
| 403 | return aura::client::MOVE_CANCELED; |
| 404 | |
| 405 | in_move_loop_ = true; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 406 | bool destroyed = false; |
| 407 | destroyed_ = &destroyed; |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 408 | base::MessageLoopForUI* loop = base::MessageLoopForUI::current(); |
| 409 | base::MessageLoop::ScopedNestableTaskAllower allow_nested(loop); |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 410 | base::RunLoop run_loop; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 411 | quit_closure_ = run_loop.QuitClosure(); |
| 412 | run_loop.Run(); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 413 | if (destroyed) |
| 414 | return aura::client::MOVE_CANCELED; |
| 415 | destroyed_ = NULL; |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 416 | in_move_loop_ = false; |
| 417 | return drag_reverted_ ? aura::client::MOVE_CANCELED : |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 418 | aura::client::MOVE_SUCCESSFUL; |
| 419 | } |
| 420 | |
| 421 | void ToplevelWindowEventHandler::EndMoveLoop() { |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 422 | if (in_move_loop_) |
| 423 | CompleteDrag(DRAG_REVERT); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 424 | } |
| 425 | |
| 426 | void ToplevelWindowEventHandler::OnDisplayConfigurationChanging() { |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 427 | CompleteDrag(DRAG_REVERT); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 428 | } |
| 429 | |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 430 | bool ToplevelWindowEventHandler::AttemptToStartDrag( |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 431 | aura::Window* window, |
| 432 | const gfx::Point& point_in_parent, |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 433 | int window_component, |
| 434 | aura::client::WindowMoveSource source) { |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 435 | if (window_resizer_.get()) |
| 436 | return false; |
| 437 | WindowResizer* resizer = CreateWindowResizer(window, point_in_parent, |
| 438 | window_component, source).release(); |
| 439 | if (!resizer) |
| 440 | return false; |
| 441 | |
| 442 | window_resizer_.reset(new ScopedWindowResizer(this, resizer)); |
| 443 | |
| 444 | pre_drag_window_bounds_ = window->bounds(); |
| 445 | in_gesture_drag_ = (source == aura::client::WINDOW_MOVE_SOURCE_TOUCH); |
| 446 | return true; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 447 | } |
| 448 | |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 449 | void ToplevelWindowEventHandler::CompleteDrag(DragCompletionStatus status) { |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 450 | scoped_ptr<ScopedWindowResizer> resizer(window_resizer_.release()); |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 451 | if (resizer) { |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 452 | if (status == DRAG_COMPLETE) |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 453 | resizer->resizer()->CompleteDrag(); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 454 | else |
| 455 | resizer->resizer()->RevertDrag(); |
| 456 | } |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 457 | drag_reverted_ = (status == DRAG_REVERT); |
| 458 | |
| 459 | first_finger_hittest_ = HTNOWHERE; |
| 460 | in_gesture_drag_ = false; |
| 461 | if (in_move_loop_) |
| 462 | quit_closure_.Run(); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 463 | } |
| 464 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 465 | void ToplevelWindowEventHandler::HandleMousePressed( |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 466 | aura::Window* target, |
| 467 | ui::MouseEvent* event) { |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 468 | if (event->phase() != ui::EP_PRETARGET || !target->delegate()) |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 469 | return; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 470 | |
| 471 | // We also update the current window component here because for the |
| 472 | // mouse-drag-release-press case, where the mouse is released and |
| 473 | // pressed without mouse move event. |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 474 | int component = GetWindowComponent(target, *event); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 475 | if ((event->flags() & |
| 476 | (ui::EF_IS_DOUBLE_CLICK | ui::EF_IS_TRIPLE_CLICK)) == 0 && |
| 477 | WindowResizer::GetBoundsChangeForWindowComponent(component)) { |
| 478 | gfx::Point location_in_parent( |
| 479 | ConvertPointToParent(target, event->location())); |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 480 | AttemptToStartDrag(target, location_in_parent, component, |
| 481 | aura::client::WINDOW_MOVE_SOURCE_MOUSE); |
Ben Murdoch | 0529e5d | 2014-04-24 10:50:13 +0100 | [diff] [blame] | 482 | // Set as handled so that other event handlers do no act upon the event |
| 483 | // but still receive it so that they receive both parts of each pressed/ |
| 484 | // released pair. |
| 485 | event->SetHandled(); |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 486 | } else { |
| 487 | CompleteDrag(DRAG_COMPLETE); |
| 488 | } |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 489 | } |
| 490 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 491 | void ToplevelWindowEventHandler::HandleMouseReleased( |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 492 | aura::Window* target, |
| 493 | ui::MouseEvent* event) { |
| 494 | if (event->phase() != ui::EP_PRETARGET) |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 495 | return; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 496 | |
| 497 | CompleteDrag(event->type() == ui::ET_MOUSE_RELEASED ? |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 498 | DRAG_COMPLETE : DRAG_REVERT); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 499 | // Completing the drag may result in hiding the window. If this happens |
Ben Murdoch | 0529e5d | 2014-04-24 10:50:13 +0100 | [diff] [blame] | 500 | // mark the event as handled so no other handlers/observers act upon the |
| 501 | // event. They should see the event on a hidden window, to determine targets |
| 502 | // of destructive actions such as hiding. They should not act upon them. |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 503 | if (window_resizer_ && |
| 504 | event->type() == ui::ET_MOUSE_CAPTURE_CHANGED && |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 505 | !target->IsVisible()) { |
Ben Murdoch | 0529e5d | 2014-04-24 10:50:13 +0100 | [diff] [blame] | 506 | event->SetHandled(); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 507 | } |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 508 | } |
| 509 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 510 | void ToplevelWindowEventHandler::HandleDrag( |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 511 | aura::Window* target, |
| 512 | ui::LocatedEvent* event) { |
| 513 | // This function only be triggered to move window |
| 514 | // by mouse drag or touch move event. |
| 515 | DCHECK(event->type() == ui::ET_MOUSE_DRAGGED || |
| 516 | event->type() == ui::ET_TOUCH_MOVED || |
| 517 | event->type() == ui::ET_GESTURE_SCROLL_UPDATE); |
| 518 | |
| 519 | // Drag actions are performed pre-target handling to prevent spurious mouse |
| 520 | // moves from the move/size operation from being sent to the target. |
| 521 | if (event->phase() != ui::EP_PRETARGET) |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 522 | return; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 523 | |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 524 | if (!window_resizer_) |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 525 | return; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 526 | window_resizer_->resizer()->Drag( |
| 527 | ConvertPointToParent(target, event->location()), event->flags()); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 528 | event->StopPropagation(); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 529 | } |
| 530 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 531 | void ToplevelWindowEventHandler::HandleMouseMoved( |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 532 | aura::Window* target, |
| 533 | ui::LocatedEvent* event) { |
| 534 | // Shadow effects are applied after target handling. Note that we don't |
| 535 | // respect ER_HANDLED here right now since we have not had a reason to allow |
| 536 | // the target to cancel shadow rendering. |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 537 | if (event->phase() != ui::EP_POSTTARGET || !target->delegate()) |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 538 | return; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 539 | |
| 540 | // TODO(jamescook): Move the resize cursor update code into here from |
| 541 | // CompoundEventFilter? |
Ben Murdoch | c5cede9 | 2014-04-10 11:22:14 +0100 | [diff] [blame] | 542 | ResizeShadowController* controller = |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 543 | Shell::GetInstance()->resize_shadow_controller(); |
| 544 | if (controller) { |
| 545 | if (event->flags() & ui::EF_IS_NON_CLIENT) { |
| 546 | int component = |
| 547 | target->delegate()->GetNonClientComponent(event->location()); |
Ben Murdoch | ba5b9a6 | 2013-08-12 14:20:17 +0100 | [diff] [blame] | 548 | controller->ShowShadow(target, component); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 549 | } else { |
| 550 | controller->HideShadow(target); |
| 551 | } |
| 552 | } |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 553 | } |
| 554 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 555 | void ToplevelWindowEventHandler::HandleMouseExited( |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 556 | aura::Window* target, |
| 557 | ui::LocatedEvent* event) { |
| 558 | // Shadow effects are applied after target handling. Note that we don't |
| 559 | // respect ER_HANDLED here right now since we have not had a reason to allow |
| 560 | // the target to cancel shadow rendering. |
| 561 | if (event->phase() != ui::EP_POSTTARGET) |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 562 | return; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 563 | |
Ben Murdoch | c5cede9 | 2014-04-10 11:22:14 +0100 | [diff] [blame] | 564 | ResizeShadowController* controller = |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 565 | Shell::GetInstance()->resize_shadow_controller(); |
| 566 | if (controller) |
| 567 | controller->HideShadow(target); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 568 | } |
| 569 | |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 570 | void ToplevelWindowEventHandler::SetWindowStateTypeFromGesture( |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 571 | aura::Window* window, |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 572 | wm::WindowStateType new_state_type) { |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 573 | wm::WindowState* window_state = ash::wm::GetWindowState(window); |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 574 | // TODO(oshima): Move extra logic (set_unminimize_to_restore_bounds, |
| 575 | // SetRestoreBoundsInParent) that modifies the window state |
| 576 | // into WindowState. |
| 577 | switch (new_state_type) { |
| 578 | case wm::WINDOW_STATE_TYPE_MINIMIZED: |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 579 | if (window_state->CanMinimize()) { |
| 580 | window_state->Minimize(); |
| 581 | window_state->set_unminimize_to_restore_bounds(true); |
| 582 | window_state->SetRestoreBoundsInParent(pre_drag_window_bounds_); |
| 583 | } |
| 584 | break; |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 585 | case wm::WINDOW_STATE_TYPE_MAXIMIZED: |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 586 | if (window_state->CanMaximize()) { |
| 587 | window_state->SetRestoreBoundsInParent(pre_drag_window_bounds_); |
| 588 | window_state->Maximize(); |
| 589 | } |
| 590 | break; |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 591 | case wm::WINDOW_STATE_TYPE_LEFT_SNAPPED: |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 592 | if (window_state->CanSnap()) { |
| 593 | window_state->SetRestoreBoundsInParent(pre_drag_window_bounds_); |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 594 | const wm::WMEvent event(wm::WM_EVENT_SNAP_LEFT); |
| 595 | window_state->OnWMEvent(&event); |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 596 | } |
| 597 | break; |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 598 | case wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED: |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 599 | if (window_state->CanSnap()) { |
| 600 | window_state->SetRestoreBoundsInParent(pre_drag_window_bounds_); |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 601 | const wm::WMEvent event(wm::WM_EVENT_SNAP_RIGHT); |
| 602 | window_state->OnWMEvent(&event); |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 603 | } |
| 604 | break; |
| 605 | default: |
| 606 | NOTREACHED(); |
| 607 | } |
| 608 | } |
| 609 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 610 | void ToplevelWindowEventHandler::ResizerWindowDestroyed() { |
| 611 | // We explicitly don't invoke RevertDrag() since that may do things to window. |
| 612 | // Instead we destroy the resizer. |
| 613 | window_resizer_.reset(); |
| 614 | |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 615 | CompleteDrag(DRAG_REVERT); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 616 | } |
| 617 | |
| 618 | } // namespace ash |