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

Side by Side Diff: mash/wm/frame/move_event_handler.cc

Issue 2002243002: Gets mash to use WmToplevelWindowEventHandler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: feedback Created 4 years, 7 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 unified diff | Download patch
« no previous file with comments | « mash/wm/frame/move_event_handler.h ('k') | mash/wm/frame/move_loop.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "mash/wm/frame/move_event_handler.h" 5 #include "mash/wm/frame/move_event_handler.h"
6 6
7 #include "components/mus/public/cpp/window.h" 7 #include "components/mus/public/cpp/window.h"
8 #include "components/mus/public/cpp/window_manager_delegate.h" 8 #include "components/mus/public/cpp/window_manager_delegate.h"
9 #include "components/mus/public/interfaces/cursor.mojom.h" 9 #include "components/mus/public/interfaces/cursor.mojom.h"
10 #include "mash/wm/frame/move_loop.h" 10 #include "mash/wm/bridge/wm_window_mus.h"
11 #include "mojo/converters/input_events/input_events_type_converters.h" 11 #include "mash/wm/bridge/wm_window_mus.h"
12 #include "ui/aura/window.h" 12 #include "ui/aura/window.h"
13 #include "ui/aura/window_delegate.h"
14 #include "ui/base/hit_test.h" 13 #include "ui/base/hit_test.h"
15 #include "ui/events/event.h" 14 #include "ui/events/event.h"
16 15
17 namespace mash { 16 namespace mash {
18 namespace wm { 17 namespace wm {
19 namespace { 18 namespace {
20 19
21 mus::mojom::Cursor CursorForWindowComponent(int window_component) { 20 mus::mojom::Cursor CursorForWindowComponent(int window_component) {
22 switch (window_component) { 21 switch (window_component) {
23 case HTBOTTOM: 22 case HTBOTTOM:
(...skipping 16 matching lines...) Expand all
40 return mus::mojom::Cursor::CURSOR_NULL; 39 return mus::mojom::Cursor::CURSOR_NULL;
41 } 40 }
42 } 41 }
43 42
44 } // namespace 43 } // namespace
45 44
46 MoveEventHandler::MoveEventHandler( 45 MoveEventHandler::MoveEventHandler(
47 mus::Window* mus_window, 46 mus::Window* mus_window,
48 mus::WindowManagerClient* window_manager_client, 47 mus::WindowManagerClient* window_manager_client,
49 aura::Window* aura_window) 48 aura::Window* aura_window)
50 : mus_window_(mus_window), 49 : wm_window_(WmWindowMus::Get(mus_window)),
51 window_manager_client_(window_manager_client), 50 window_manager_client_(window_manager_client),
52 aura_window_(aura_window), 51 root_window_(aura_window->GetRootWindow()),
53 root_window_(aura_window->GetRootWindow()) { 52 toplevel_window_event_handler_(wm_window_->GetGlobals()) {
54 root_window_->AddObserver(this); 53 root_window_->AddObserver(this);
55 root_window_->AddPreTargetHandler(this); 54 root_window_->AddPreTargetHandler(this);
56 } 55 }
57 56
58 MoveEventHandler::~MoveEventHandler() { 57 MoveEventHandler::~MoveEventHandler() {
59 Detach(); 58 Detach();
60 } 59 }
61 60
62 void MoveEventHandler::ProcessLocatedEvent(ui::LocatedEvent* event) {
63 const bool had_move_loop = move_loop_.get() != nullptr;
64 DCHECK(event->IsMouseEvent() || event->IsTouchEvent());
65
66 // This event handler can receive mouse events like ET_MOUSE_CAPTURE_CHANGED
67 // that cannot be converted to PointerEvents. Ignore them because they aren't
68 // needed for move handling.
69 if (!ui::PointerEvent::CanConvertFrom(*event))
70 return;
71
72 // TODO(moshayedi): no need for this once MoveEventHandler directly receives
73 // pointer events.
74 std::unique_ptr<ui::PointerEvent> pointer_event;
75 if (event->IsMouseEvent())
76 pointer_event.reset(new ui::PointerEvent(*event->AsMouseEvent()));
77 else
78 pointer_event.reset(new ui::PointerEvent(*event->AsTouchEvent()));
79
80 if (move_loop_) {
81 if (move_loop_->Move(*pointer_event.get()) == MoveLoop::DONE)
82 move_loop_.reset();
83 } else if (pointer_event->type() == ui::ET_POINTER_DOWN) {
84 const int ht_location = GetNonClientComponentForEvent(pointer_event.get());
85 if (ht_location != HTNOWHERE) {
86 move_loop_ =
87 MoveLoop::Create(mus_window_, ht_location, *pointer_event.get());
88 }
89 } else if (pointer_event->type() == ui::ET_POINTER_MOVED) {
90 const int ht_location = GetNonClientComponentForEvent(pointer_event.get());
91 window_manager_client_->SetNonClientCursor(
92 mus_window_, CursorForWindowComponent(ht_location));
93 }
94 if (had_move_loop || move_loop_)
95 event->SetHandled();
96 }
97
98 int MoveEventHandler::GetNonClientComponentForEvent(
99 const ui::LocatedEvent* event) {
100 return aura_window_->delegate()->GetNonClientComponent(event->location());
101 }
102
103 void MoveEventHandler::Detach() { 61 void MoveEventHandler::Detach() {
104 if (!root_window_) 62 if (!root_window_)
105 return; 63 return;
106 64
107 root_window_->RemoveObserver(this); 65 root_window_->RemoveObserver(this);
108 root_window_->RemovePreTargetHandler(this); 66 root_window_->RemovePreTargetHandler(this);
109 root_window_ = nullptr; 67 root_window_ = nullptr;
110 } 68 }
111 69
112 void MoveEventHandler::OnMouseEvent(ui::MouseEvent* event) { 70 void MoveEventHandler::OnMouseEvent(ui::MouseEvent* event) {
113 ProcessLocatedEvent(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 const int hit_test_location =
75 wm_window_->GetNonClientComponent(event->location());
76 window_manager_client_->SetNonClientCursor(
77 wm_window_->mus_window(), CursorForWindowComponent(hit_test_location));
78 }
114 } 79 }
115 80
116 void MoveEventHandler::OnTouchEvent(ui::TouchEvent* event) { 81 void MoveEventHandler::OnGestureEvent(ui::GestureEvent* event) {
117 ProcessLocatedEvent(event); 82 toplevel_window_event_handler_.OnGestureEvent(event, wm_window_);
118 } 83 }
119 84
120 void MoveEventHandler::OnCancelMode(ui::CancelModeEvent* event) { 85 void MoveEventHandler::OnCancelMode(ui::CancelModeEvent* event) {
121 if (!move_loop_) 86 toplevel_window_event_handler_.RevertDrag();
122 return;
123
124 move_loop_->Revert();
125 move_loop_.reset();
126 event->SetHandled();
127 } 87 }
128 88
129 void MoveEventHandler::OnWindowDestroying(aura::Window* window) { 89 void MoveEventHandler::OnWindowDestroying(aura::Window* window) {
130 DCHECK_EQ(root_window_, window); 90 DCHECK_EQ(root_window_, window);
131 Detach(); 91 Detach();
132 } 92 }
133 93
134 } // namespace wm 94 } // namespace wm
135 } // namespace mash 95 } // namespace mash
OLDNEW
« no previous file with comments | « mash/wm/frame/move_event_handler.h ('k') | mash/wm/frame/move_loop.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698