| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 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 "mash/wm/frame/move_event_handler.h" | |
| 6 | |
| 7 #include "components/mus/public/cpp/window.h" | |
| 8 #include "components/mus/public/cpp/window_manager_delegate.h" | |
| 9 #include "components/mus/public/interfaces/cursor.mojom.h" | |
| 10 #include "mash/wm/bridge/wm_window_mus.h" | |
| 11 #include "mash/wm/bridge/wm_window_mus.h" | |
| 12 #include "ui/aura/window.h" | |
| 13 #include "ui/base/hit_test.h" | |
| 14 #include "ui/events/event.h" | |
| 15 | |
| 16 namespace mash { | |
| 17 namespace wm { | |
| 18 namespace { | |
| 19 | |
| 20 mus::mojom::Cursor CursorForWindowComponent(int window_component) { | |
| 21 switch (window_component) { | |
| 22 case HTBOTTOM: | |
| 23 return mus::mojom::Cursor::SOUTH_RESIZE; | |
| 24 case HTBOTTOMLEFT: | |
| 25 return mus::mojom::Cursor::SOUTH_WEST_RESIZE; | |
| 26 case HTBOTTOMRIGHT: | |
| 27 return mus::mojom::Cursor::SOUTH_EAST_RESIZE; | |
| 28 case HTLEFT: | |
| 29 return mus::mojom::Cursor::WEST_RESIZE; | |
| 30 case HTRIGHT: | |
| 31 return mus::mojom::Cursor::EAST_RESIZE; | |
| 32 case HTTOP: | |
| 33 return mus::mojom::Cursor::NORTH_RESIZE; | |
| 34 case HTTOPLEFT: | |
| 35 return mus::mojom::Cursor::NORTH_WEST_RESIZE; | |
| 36 case HTTOPRIGHT: | |
| 37 return mus::mojom::Cursor::NORTH_EAST_RESIZE; | |
| 38 default: | |
| 39 return mus::mojom::Cursor::CURSOR_NULL; | |
| 40 } | |
| 41 } | |
| 42 | |
| 43 } // namespace | |
| 44 | |
| 45 MoveEventHandler::MoveEventHandler( | |
| 46 mus::Window* mus_window, | |
| 47 mus::WindowManagerClient* window_manager_client, | |
| 48 aura::Window* aura_window) | |
| 49 : wm_window_(WmWindowMus::Get(mus_window)), | |
| 50 window_manager_client_(window_manager_client), | |
| 51 root_window_(aura_window->GetRootWindow()), | |
| 52 toplevel_window_event_handler_(wm_window_->GetGlobals()) { | |
| 53 root_window_->AddObserver(this); | |
| 54 root_window_->AddPreTargetHandler(this); | |
| 55 } | |
| 56 | |
| 57 MoveEventHandler::~MoveEventHandler() { | |
| 58 Detach(); | |
| 59 } | |
| 60 | |
| 61 void MoveEventHandler::Detach() { | |
| 62 if (!root_window_) | |
| 63 return; | |
| 64 | |
| 65 root_window_->RemoveObserver(this); | |
| 66 root_window_->RemovePreTargetHandler(this); | |
| 67 root_window_ = nullptr; | |
| 68 } | |
| 69 | |
| 70 void MoveEventHandler::OnMouseEvent(ui::MouseEvent* event) { | |
| 71 toplevel_window_event_handler_.OnMouseEvent(event, wm_window_); | |
| 72 if (!toplevel_window_event_handler_.is_drag_in_progress() && | |
| 73 (event->type() == ui::ET_POINTER_MOVED || | |
| 74 event->type() == ui::ET_MOUSE_MOVED)) { | |
| 75 const int hit_test_location = | |
| 76 wm_window_->GetNonClientComponent(event->location()); | |
| 77 window_manager_client_->SetNonClientCursor( | |
| 78 wm_window_->mus_window(), CursorForWindowComponent(hit_test_location)); | |
| 79 } | |
| 80 } | |
| 81 | |
| 82 void MoveEventHandler::OnGestureEvent(ui::GestureEvent* event) { | |
| 83 toplevel_window_event_handler_.OnGestureEvent(event, wm_window_); | |
| 84 } | |
| 85 | |
| 86 void MoveEventHandler::OnCancelMode(ui::CancelModeEvent* event) { | |
| 87 toplevel_window_event_handler_.RevertDrag(); | |
| 88 } | |
| 89 | |
| 90 void MoveEventHandler::OnWindowDestroying(aura::Window* window) { | |
| 91 DCHECK_EQ(root_window_, window); | |
| 92 Detach(); | |
| 93 } | |
| 94 | |
| 95 } // namespace wm | |
| 96 } // namespace mash | |
| OLD | NEW |