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

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

Issue 345243007: Add ScopedObjCClassSwizzler in base/mac, absorbs objc_method_swizzle and ScopedClassSwizzler (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Inlude in shiny new gn base_unittests target Created 6 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « ui/events/test/cocoa_test_event_utils.mm ('k') | 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 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 6
7 #import "base/mac/scoped_objc_class_swizzler.h"
7 #include "base/memory/singleton.h" 8 #include "base/memory/singleton.h"
8 #include "ui/events/event_processor.h" 9 #include "ui/events/event_processor.h"
9 #include "ui/events/event_target.h" 10 #include "ui/events/event_target.h"
10 #include "ui/events/event_target_iterator.h" 11 #include "ui/events/event_target_iterator.h"
11 #include "ui/events/event_targeter.h" 12 #include "ui/events/event_targeter.h"
12 #include "ui/events/test/event_generator.h" 13 #include "ui/events/test/event_generator.h"
13 #import "ui/events/test/cocoa_test_event_utils.h"
14 #include "ui/gfx/mac/coordinate_conversion.h" 14 #include "ui/gfx/mac/coordinate_conversion.h"
15 15
16 namespace { 16 namespace {
17 17
18 // Singleton to provide state for swizzled Objective C methods. 18 // Singleton to provide state for swizzled Objective C methods.
19 ui::test::EventGenerator* g_active_generator = NULL; 19 ui::test::EventGenerator* g_active_generator = NULL;
20 20
21 } // namespace 21 } // namespace
22 22
23 @interface NSEventDonor : NSObject 23 @interface NSEventDonor : NSObject
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 gfx::Point* point) const OVERRIDE {} 286 gfx::Point* point) const OVERRIDE {}
287 287
288 private: 288 private:
289 friend struct DefaultSingletonTraits<EventGeneratorDelegateMac>; 289 friend struct DefaultSingletonTraits<EventGeneratorDelegateMac>;
290 290
291 EventGeneratorDelegateMac(); 291 EventGeneratorDelegateMac();
292 virtual ~EventGeneratorDelegateMac(); 292 virtual ~EventGeneratorDelegateMac();
293 293
294 ui::test::EventGenerator* owner_; 294 ui::test::EventGenerator* owner_;
295 NSWindow* window_; 295 NSWindow* window_;
296 scoped_ptr<ScopedClassSwizzler> swizzle_pressed_; 296 scoped_ptr<base::mac::ScopedObjCClassSwizzler> swizzle_pressed_;
297 297
298 DISALLOW_COPY_AND_ASSIGN(EventGeneratorDelegateMac); 298 DISALLOW_COPY_AND_ASSIGN(EventGeneratorDelegateMac);
299 }; 299 };
300 300
301 EventGeneratorDelegateMac::EventGeneratorDelegateMac() 301 EventGeneratorDelegateMac::EventGeneratorDelegateMac()
302 : owner_(NULL), 302 : owner_(NULL),
303 window_(NULL) { 303 window_(NULL) {
304 DCHECK(!ui::test::EventGenerator::default_delegate); 304 DCHECK(!ui::test::EventGenerator::default_delegate);
305 ui::test::EventGenerator::default_delegate = this; 305 ui::test::EventGenerator::default_delegate = this;
306 } 306 }
(...skipping 18 matching lines...) Expand all
325 event->changed_button_flags()); 325 event->changed_button_flags());
326 } 326 }
327 327
328 void EventGeneratorDelegateMac::SetContext(ui::test::EventGenerator* owner, 328 void EventGeneratorDelegateMac::SetContext(ui::test::EventGenerator* owner,
329 gfx::NativeWindow root_window, 329 gfx::NativeWindow root_window,
330 gfx::NativeWindow window) { 330 gfx::NativeWindow window) {
331 swizzle_pressed_.reset(); 331 swizzle_pressed_.reset();
332 owner_ = owner; 332 owner_ = owner;
333 window_ = window; 333 window_ = window;
334 if (owner_) { 334 if (owner_) {
335 swizzle_pressed_.reset(new ScopedClassSwizzler( 335 swizzle_pressed_.reset(new base::mac::ScopedObjCClassSwizzler(
336 [NSEvent class], 336 [NSEvent class],
337 [NSEventDonor class], 337 [NSEventDonor class],
338 @selector(pressedMouseButtons))); 338 @selector(pressedMouseButtons)));
339 } 339 }
340 } 340 }
341 341
342 gfx::Point EventGeneratorDelegateMac::CenterOfTarget( 342 gfx::Point EventGeneratorDelegateMac::CenterOfTarget(
343 const ui::EventTarget* target) const { 343 const ui::EventTarget* target) const {
344 DCHECK_EQ(target, this); 344 DCHECK_EQ(target, this);
345 return CenterOfWindow(window_); 345 return CenterOfWindow(window_);
346 } 346 }
347 347
348 gfx::Point EventGeneratorDelegateMac::CenterOfWindow( 348 gfx::Point EventGeneratorDelegateMac::CenterOfWindow(
349 gfx::NativeWindow window) const { 349 gfx::NativeWindow window) const {
350 DCHECK_EQ(window, window_); 350 DCHECK_EQ(window, window_);
351 return gfx::ScreenRectFromNSRect([window frame]).CenterPoint(); 351 return gfx::ScreenRectFromNSRect([window frame]).CenterPoint();
352 } 352 }
353 353
354 } // namespace 354 } // namespace
355 355
356 namespace views { 356 namespace views {
357 namespace test { 357 namespace test {
358 358
359 void InitializeMacEventGeneratorDelegate() { 359 void InitializeMacEventGeneratorDelegate() {
360 EventGeneratorDelegateMac::GetInstance(); 360 EventGeneratorDelegateMac::GetInstance();
361 } 361 }
362 362
363 } // namespace test 363 } // namespace test
364 } // namespace views 364 } // namespace views
OLDNEW
« no previous file with comments | « ui/events/test/cocoa_test_event_utils.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698