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

Side by Side Diff: mash/simple_wm/move_loop.cc

Issue 2655303004: Add id properties to PointerEvent (Closed)
Patch Set: pointer id Created 3 years, 10 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/simple_wm/move_loop.h" 5 #include "mash/simple_wm/move_loop.h"
6 6
7 #include "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "ui/aura/client/aura_constants.h" 9 #include "ui/aura/client/aura_constants.h"
10 #include "ui/aura/window.h" 10 #include "ui/aura/window.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 VerticalLocation v_loc; 45 VerticalLocation v_loc;
46 if (!DetermineType(ht_location, &type, &h_loc, &v_loc)) 46 if (!DetermineType(ht_location, &type, &h_loc, &v_loc))
47 return nullptr; 47 return nullptr;
48 48
49 return base::WrapUnique(new MoveLoop(target, event, type, h_loc, v_loc)); 49 return base::WrapUnique(new MoveLoop(target, event, type, h_loc, v_loc));
50 } 50 }
51 51
52 MoveLoop::MoveResult MoveLoop::Move(const ui::PointerEvent& event) { 52 MoveLoop::MoveResult MoveLoop::Move(const ui::PointerEvent& event) {
53 switch (event.type()) { 53 switch (event.type()) {
54 case ui::ET_POINTER_CANCELLED: 54 case ui::ET_POINTER_CANCELLED:
55 if (event.pointer_id() == pointer_id_) { 55 if (event.pointer_details().id == pointer_id_) {
56 if (target_) 56 if (target_)
57 Revert(); 57 Revert();
58 return MoveResult::DONE; 58 return MoveResult::DONE;
59 } 59 }
60 return MoveResult::CONTINUE; 60 return MoveResult::CONTINUE;
61 61
62 case ui::ET_POINTER_MOVED: 62 case ui::ET_POINTER_MOVED:
63 if (target_ && event.pointer_id() == pointer_id_) 63 if (target_ && event.pointer_details().id == pointer_id_)
64 MoveImpl(event); 64 MoveImpl(event);
65 return MoveResult::CONTINUE; 65 return MoveResult::CONTINUE;
66 66
67 case ui::ET_POINTER_UP: 67 case ui::ET_POINTER_UP:
68 if (event.pointer_id() == pointer_id_) { 68 if (event.pointer_details().id == pointer_id_) {
69 // TODO(sky): need to support changed_flags. 69 // TODO(sky): need to support changed_flags.
70 if (target_) 70 if (target_)
71 MoveImpl(event); 71 MoveImpl(event);
72 return MoveResult::DONE; 72 return MoveResult::DONE;
73 } 73 }
74 return MoveResult::CONTINUE; 74 return MoveResult::CONTINUE;
75 75
76 default: 76 default:
77 break; 77 break;
78 } 78 }
79 return MoveResult::CONTINUE; 79 return MoveResult::CONTINUE;
80 } 80 }
81 81
82 void MoveLoop::Revert() { 82 void MoveLoop::Revert() {
83 if (!target_) 83 if (!target_)
84 return; 84 return;
85 85
86 base::AutoReset<bool> resetter(&changing_bounds_, true); 86 base::AutoReset<bool> resetter(&changing_bounds_, true);
87 target_->SetBounds(initial_window_bounds_); 87 target_->SetBounds(initial_window_bounds_);
88 //SetWindowUserSetBounds(target_, initial_user_set_bounds_);
89 } 88 }
90 89
91 MoveLoop::MoveLoop(aura::Window* target, 90 MoveLoop::MoveLoop(aura::Window* target,
92 const ui::PointerEvent& event, 91 const ui::PointerEvent& event,
93 Type type, 92 Type type,
94 HorizontalLocation h_loc, 93 HorizontalLocation h_loc,
95 VerticalLocation v_loc) 94 VerticalLocation v_loc)
96 : target_(target), 95 : target_(target),
97 type_(type), 96 type_(type),
98 h_loc_(h_loc), 97 h_loc_(h_loc),
99 v_loc_(v_loc), 98 v_loc_(v_loc),
100 pointer_id_(event.pointer_id()), 99 pointer_id_(event.pointer_details().id),
101 initial_event_screen_location_(event.root_location()), 100 initial_event_screen_location_(event.root_location()),
102 initial_window_bounds_(target->bounds()), 101 initial_window_bounds_(target->bounds()),
103 initial_user_set_bounds_(target->bounds()), 102 initial_user_set_bounds_(target->bounds()),
104 // GetWindowUserSetBounds(target)),
105 changing_bounds_(false) { 103 changing_bounds_(false) {
106 target->AddObserver(this); 104 target->AddObserver(this);
107 } 105 }
108 106
109 // static 107 // static
110 bool MoveLoop::DetermineType(int ht_location, 108 bool MoveLoop::DetermineType(int ht_location,
111 Type* type, 109 Type* type,
112 HorizontalLocation* h_loc, 110 HorizontalLocation* h_loc,
113 VerticalLocation* v_loc) { 111 VerticalLocation* v_loc) {
114 *h_loc = HorizontalLocation::OTHER; 112 *h_loc = HorizontalLocation::OTHER;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 // need to take some action to recenter the window relative to 172 // need to take some action to recenter the window relative to
175 // the pointer position within the titlebar. 173 // the pointer position within the titlebar.
176 initial_window_bounds_.set_width(restored_bounds.width()); 174 initial_window_bounds_.set_width(restored_bounds.width());
177 initial_window_bounds_.set_height(restored_bounds.height()); 175 initial_window_bounds_.set_height(restored_bounds.height());
178 } 176 }
179 const gfx::Vector2d delta = 177 const gfx::Vector2d delta =
180 event.root_location() - initial_event_screen_location_; 178 event.root_location() - initial_event_screen_location_;
181 const gfx::Rect new_bounds(DetermineBoundsFromDelta(delta)); 179 const gfx::Rect new_bounds(DetermineBoundsFromDelta(delta));
182 base::AutoReset<bool> resetter(&changing_bounds_, true); 180 base::AutoReset<bool> resetter(&changing_bounds_, true);
183 target_->SetBounds(new_bounds); 181 target_->SetBounds(new_bounds);
184 //SetWindowUserSetBounds(target_, new_bounds);
185 } 182 }
186 183
187 void MoveLoop::Cancel() { 184 void MoveLoop::Cancel() {
188 target_->RemoveObserver(this); 185 target_->RemoveObserver(this);
189 target_ = nullptr; 186 target_ = nullptr;
190 } 187 }
191 188
192 gfx::Rect MoveLoop::DetermineBoundsFromDelta(const gfx::Vector2d& delta) { 189 gfx::Rect MoveLoop::DetermineBoundsFromDelta(const gfx::Vector2d& delta) {
193 if (type_ == Type::MOVE) { 190 if (type_ == Type::MOVE) {
194 return gfx::Rect(initial_window_bounds_.origin() + delta, 191 return gfx::Rect(initial_window_bounds_.origin() + delta,
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 if (!changing_bounds_) 228 if (!changing_bounds_)
232 Cancel(); 229 Cancel();
233 } 230 }
234 231
235 void MoveLoop::OnWindowVisibilityChanged(aura::Window* window, bool visible) { 232 void MoveLoop::OnWindowVisibilityChanged(aura::Window* window, bool visible) {
236 DCHECK_EQ(window, target_); 233 DCHECK_EQ(window, target_);
237 Cancel(); 234 Cancel();
238 } 235 }
239 236
240 } // namespace simple_wm 237 } // namespace simple_wm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698