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

Side by Side Diff: ui/views/test/event_generator_delegate_mac.mm

Issue 2455143003: Fix mouse wheel events processing. (Closed)
Patch Set: Fix review issues. Created 4 years, 1 month 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 | ui/views/widget/native_widget_aura.cc » ('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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #import <Cocoa/Cocoa.h> 5 #import <Cocoa/Cocoa.h>
6 #include <stddef.h> 6 #include <stddef.h>
7 7
8 #import "base/mac/scoped_nsobject.h" 8 #import "base/mac/scoped_nsobject.h"
9 #import "base/mac/scoped_objc_class_swizzler.h" 9 #import "base/mac/scoped_objc_class_swizzler.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 location:point 210 location:point
211 modifierFlags:modifiers 211 modifierFlags:modifiers
212 timestamp:0 212 timestamp:0
213 windowNumber:[window windowNumber] 213 windowNumber:[window windowNumber]
214 context:nil 214 context:nil
215 eventNumber:0 215 eventNumber:0
216 clickCount:click_count 216 clickCount:click_count
217 pressure:1.0]; 217 pressure:1.0];
218 } 218 }
219 219
220 NSEvent* CreateMouseWheelEventInWindow(NSWindow* window,
221 const ui::MouseEvent* mouse_event) {
222 DCHECK_EQ(mouse_event->type(), ui::ET_MOUSEWHEEL);
223 const ui::MouseWheelEvent* mouse_wheel_event =
224 mouse_event->AsMouseWheelEvent();
225 return cocoa_test_event_utils::TestScrollEvent(
226 ConvertRootPointToTarget(window, mouse_wheel_event->location()), window,
227 mouse_wheel_event->x_offset(), mouse_wheel_event->y_offset(), false,
228 NSEventPhaseNone, NSEventPhaseNone);
229 }
230
220 // Implementation of ui::test::EventGeneratorDelegate for Mac. Everything 231 // Implementation of ui::test::EventGeneratorDelegate for Mac. Everything
221 // defined inline is just a stub. Interesting overrides are defined below the 232 // defined inline is just a stub. Interesting overrides are defined below the
222 // class. 233 // class.
223 class EventGeneratorDelegateMac : public ui::EventTarget, 234 class EventGeneratorDelegateMac : public ui::EventTarget,
224 public ui::EventSource, 235 public ui::EventSource,
225 public ui::EventHandler, 236 public ui::EventHandler,
226 public ui::EventProcessor, 237 public ui::EventProcessor,
227 public ui::EventTargeter, 238 public ui::EventTargeter,
228 public ui::test::EventGeneratorDelegate { 239 public ui::test::EventGeneratorDelegate {
229 public: 240 public:
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 ui::test::EventGenerator::default_delegate = nullptr; 353 ui::test::EventGenerator::default_delegate = nullptr;
343 } 354 }
344 355
345 std::unique_ptr<ui::EventTargetIterator> 356 std::unique_ptr<ui::EventTargetIterator>
346 EventGeneratorDelegateMac::GetChildIterator() const { 357 EventGeneratorDelegateMac::GetChildIterator() const {
347 // Return nullptr to dispatch all events to the result of GetRootTarget(). 358 // Return nullptr to dispatch all events to the result of GetRootTarget().
348 return nullptr; 359 return nullptr;
349 } 360 }
350 361
351 void EventGeneratorDelegateMac::OnMouseEvent(ui::MouseEvent* event) { 362 void EventGeneratorDelegateMac::OnMouseEvent(ui::MouseEvent* event) {
352 NSEvent* ns_event = CreateMouseEventInWindow(window_, 363 NSEvent* ns_event =
353 event->type(), 364 event->type() == ui::ET_MOUSEWHEEL
354 event->location(), 365 ? CreateMouseWheelEventInWindow(window_, event)
355 event->changed_button_flags()); 366 : CreateMouseEventInWindow(window_, event->type(), event->location(),
367 event->changed_button_flags());
368
356 if (owner_->targeting_application()) 369 if (owner_->targeting_application())
357 [NSApp sendEvent:ns_event]; 370 [NSApp sendEvent:ns_event];
358 else 371 else
359 EmulateSendEvent(window_, ns_event); 372 EmulateSendEvent(window_, ns_event);
360 } 373 }
361 374
362 void EventGeneratorDelegateMac::OnKeyEvent(ui::KeyEvent* event) { 375 void EventGeneratorDelegateMac::OnKeyEvent(ui::KeyEvent* event) {
363 NSUInteger modifiers = EventFlagsToModifiers(event->flags()); 376 NSUInteger modifiers = EventFlagsToModifiers(event->flags());
364 NSEvent* ns_event = cocoa_test_event_utils::SynthesizeKeyEvent( 377 NSEvent* ns_event = cocoa_test_event_utils::SynthesizeKeyEvent(
365 window_, event->type() == ui::ET_KEY_PRESSED, event->key_code(), 378 window_, event->type() == ui::ET_KEY_PRESSED, event->key_code(),
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 - (NSEvent*)currentEvent { 504 - (NSEvent*)currentEvent {
492 if (g_current_event) 505 if (g_current_event)
493 return g_current_event; 506 return g_current_event;
494 507
495 // Find the original implementation and invoke it. 508 // Find the original implementation and invoke it.
496 IMP original = EventGeneratorDelegateMac::GetInstance()->CurrentEventMethod(); 509 IMP original = EventGeneratorDelegateMac::GetInstance()->CurrentEventMethod();
497 return original(self, _cmd); 510 return original(self, _cmd);
498 } 511 }
499 512
500 @end 513 @end
OLDNEW
« no previous file with comments | « no previous file | ui/views/widget/native_widget_aura.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698