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

Side by Side Diff: components/exo/pointer.cc

Issue 2342413002: exo: Send pointer location before button event (Closed)
Patch Set: send pointer updates before event specific events Created 4 years, 3 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 | « no previous file | no next file » | 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 "components/exo/pointer.h" 5 #include "components/exo/pointer.h"
6 6
7 #include "ash/common/shell_window_ids.h" 7 #include "ash/common/shell_window_ids.h"
8 #include "ash/display/display_manager.h" 8 #include "ash/display/display_manager.h"
9 #include "components/exo/pointer_delegate.h" 9 #include "components/exo/pointer_delegate.h"
10 #include "components/exo/pointer_stylus_delegate.h" 10 #include "components/exo/pointer_stylus_delegate.h"
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 } 164 }
165 delegate_->OnPointerFrame(); 165 delegate_->OnPointerFrame();
166 } 166 }
167 167
168 // Report changes in pointer type. 168 // Report changes in pointer type.
169 if (focus_ && stylus_delegate_ && new_pointer_type != pointer_type_) { 169 if (focus_ && stylus_delegate_ && new_pointer_type != pointer_type_) {
170 stylus_delegate_->OnPointerToolChange(new_pointer_type); 170 stylus_delegate_->OnPointerToolChange(new_pointer_type);
171 pointer_type_ = new_pointer_type; 171 pointer_type_ = new_pointer_type;
172 } 172 }
173 173
174 if (focus_) {
175 bool send_frame = false;
176 // Generate motion event if location changed. We need to check location
177 // here as mouse movement can generate both "moved" and "entered" events
178 // but OnPointerMotion should only be called if location changed since
179 // OnPointerEnter was called.
180 if (!SameLocation(event, location_)) {
181 location_ = event->location_f();
182 delegate_->OnPointerMotion(event->time_stamp(), location_);
183 send_frame = true;
184 }
185 if (stylus_delegate_ &&
186 pointer_type_ != ui::EventPointerType::POINTER_TYPE_MOUSE) {
187 constexpr float kEpsilon = std::numeric_limits<float>::epsilon();
188 gfx::Vector2dF new_tilt = gfx::Vector2dF(event->pointer_details().tilt_x,
189 event->pointer_details().tilt_y);
190 if (std::abs(new_tilt.x() - tilt_.x()) > kEpsilon ||
191 std::abs(new_tilt.y() - tilt_.y()) > kEpsilon) {
192 tilt_ = new_tilt;
193 stylus_delegate_->OnPointerTilt(event->time_stamp(), new_tilt);
194 send_frame = true;
195 }
196
197 float new_force = event->pointer_details().force;
198 if (std::abs(new_force - force_) > kEpsilon) {
199 force_ = new_force;
200 stylus_delegate_->OnPointerForce(event->time_stamp(), new_force);
201 send_frame = true;
202 }
203 }
204 if (send_frame)
205 delegate_->OnPointerFrame();
reveman 2016/09/16 17:36:29 nit: can we delay this until after the switch stat
206 }
207
174 switch (event->type()) { 208 switch (event->type()) {
175 case ui::ET_MOUSE_PRESSED: 209 case ui::ET_MOUSE_PRESSED:
176 case ui::ET_MOUSE_RELEASED: 210 case ui::ET_MOUSE_RELEASED:
177 if (focus_) { 211 if (focus_) {
178 delegate_->OnPointerButton(event->time_stamp(), 212 delegate_->OnPointerButton(event->time_stamp(),
179 event->changed_button_flags(), 213 event->changed_button_flags(),
180 event->type() == ui::ET_MOUSE_PRESSED); 214 event->type() == ui::ET_MOUSE_PRESSED);
181 delegate_->OnPointerFrame(); 215 delegate_->OnPointerFrame();
182 } 216 }
183 break; 217 break;
184 case ui::ET_MOUSE_MOVED:
185 case ui::ET_MOUSE_DRAGGED:
186 if (focus_) {
187 bool send_frame = false;
188 // Generate motion event if location changed. We need to check location
189 // here as mouse movement can generate both "moved" and "entered" events
190 // but OnPointerMotion should only be called if location changed since
191 // OnPointerEnter was called.
192 if (!SameLocation(event, location_)) {
193 location_ = event->location_f();
194 delegate_->OnPointerMotion(event->time_stamp(), location_);
195 send_frame = true;
196 }
197 if (stylus_delegate_ &&
198 pointer_type_ != ui::EventPointerType::POINTER_TYPE_MOUSE) {
199 constexpr float kEpsilon = std::numeric_limits<float>::epsilon();
200 gfx::Vector2dF new_tilt = gfx::Vector2dF(
201 event->pointer_details().tilt_x, event->pointer_details().tilt_y);
202 if (std::abs(new_tilt.x() - tilt_.x()) > kEpsilon ||
203 std::abs(new_tilt.y() - tilt_.y()) > kEpsilon) {
204 tilt_ = new_tilt;
205 stylus_delegate_->OnPointerTilt(event->time_stamp(), new_tilt);
206 send_frame = true;
207 }
208
209 float new_force = event->pointer_details().force;
210 if (std::abs(new_force - force_) > kEpsilon) {
211 force_ = new_force;
212 stylus_delegate_->OnPointerForce(event->time_stamp(), new_force);
213 send_frame = true;
214 }
215 }
216 if (send_frame)
217 delegate_->OnPointerFrame();
218 }
219 break;
220 case ui::ET_SCROLL: 218 case ui::ET_SCROLL:
221 if (focus_) { 219 if (focus_) {
222 ui::ScrollEvent* scroll_event = static_cast<ui::ScrollEvent*>(event); 220 ui::ScrollEvent* scroll_event = static_cast<ui::ScrollEvent*>(event);
223 delegate_->OnPointerScroll( 221 delegate_->OnPointerScroll(
224 event->time_stamp(), 222 event->time_stamp(),
225 gfx::Vector2dF(scroll_event->x_offset(), scroll_event->y_offset()), 223 gfx::Vector2dF(scroll_event->x_offset(), scroll_event->y_offset()),
226 false); 224 false);
227 delegate_->OnPointerFrame(); 225 delegate_->OnPointerFrame();
228 } 226 }
229 break; 227 break;
(...skipping 10 matching lines...) Expand all
240 delegate_->OnPointerScrollStop(event->time_stamp()); 238 delegate_->OnPointerScrollStop(event->time_stamp());
241 delegate_->OnPointerFrame(); 239 delegate_->OnPointerFrame();
242 } 240 }
243 break; 241 break;
244 case ui::ET_SCROLL_FLING_CANCEL: 242 case ui::ET_SCROLL_FLING_CANCEL:
245 if (focus_) { 243 if (focus_) {
246 delegate_->OnPointerScrollCancel(event->time_stamp()); 244 delegate_->OnPointerScrollCancel(event->time_stamp());
247 delegate_->OnPointerFrame(); 245 delegate_->OnPointerFrame();
248 } 246 }
249 break; 247 break;
248 case ui::ET_MOUSE_MOVED:
249 case ui::ET_MOUSE_DRAGGED:
250 case ui::ET_MOUSE_ENTERED: 250 case ui::ET_MOUSE_ENTERED:
251 case ui::ET_MOUSE_EXITED: 251 case ui::ET_MOUSE_EXITED:
252 case ui::ET_MOUSE_CAPTURE_CHANGED: 252 case ui::ET_MOUSE_CAPTURE_CHANGED:
253 break; 253 break;
254 default: 254 default:
255 NOTREACHED(); 255 NOTREACHED();
256 break; 256 break;
257 } 257 }
258 258
259 if ((event->flags() & ui::EF_IS_SYNTHESIZED) == 0) 259 if ((event->flags() & ui::EF_IS_SYNTHESIZED) == 0)
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 362
363 if (ui_scale != cursor_scale_) { 363 if (ui_scale != cursor_scale_) {
364 gfx::Transform transform; 364 gfx::Transform transform;
365 transform.Scale(ui_scale, ui_scale); 365 transform.Scale(ui_scale, ui_scale);
366 widget_->GetNativeWindow()->SetTransform(transform); 366 widget_->GetNativeWindow()->SetTransform(transform);
367 cursor_scale_ = ui_scale; 367 cursor_scale_ = ui_scale;
368 } 368 }
369 } 369 }
370 370
371 } // namespace exo 371 } // namespace exo
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698