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

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

Issue 987733002: MacViews: Fix WidgetTest.WidgetDeleted_InOnMousePressed (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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 | « ui/views/cocoa/bridged_native_widget.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_nsobject.h" 7 #import "base/mac/scoped_nsobject.h"
8 #import "base/mac/scoped_objc_class_swizzler.h" 8 #import "base/mac/scoped_objc_class_swizzler.h"
9 #include "base/memory/singleton.h" 9 #include "base/memory/singleton.h"
10 #include "ui/events/event_processor.h" 10 #include "ui/events/event_processor.h"
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 void ConvertPointFromHost(const ui::EventTarget* hosted_target, 273 void ConvertPointFromHost(const ui::EventTarget* hosted_target,
274 gfx::Point* point) const override {} 274 gfx::Point* point) const override {}
275 275
276 private: 276 private:
277 friend struct DefaultSingletonTraits<EventGeneratorDelegateMac>; 277 friend struct DefaultSingletonTraits<EventGeneratorDelegateMac>;
278 278
279 EventGeneratorDelegateMac(); 279 EventGeneratorDelegateMac();
280 ~EventGeneratorDelegateMac() override; 280 ~EventGeneratorDelegateMac() override;
281 281
282 ui::test::EventGenerator* owner_; 282 ui::test::EventGenerator* owner_;
283 NSWindow* window_; 283 base::scoped_nsobject<NSWindow> window_;
284 scoped_ptr<base::mac::ScopedObjCClassSwizzler> swizzle_pressed_; 284 scoped_ptr<base::mac::ScopedObjCClassSwizzler> swizzle_pressed_;
285 scoped_ptr<base::mac::ScopedObjCClassSwizzler> swizzle_current_event_; 285 scoped_ptr<base::mac::ScopedObjCClassSwizzler> swizzle_current_event_;
286 base::scoped_nsobject<NSMenu> fake_menu_; 286 base::scoped_nsobject<NSMenu> fake_menu_;
287 287
288 DISALLOW_COPY_AND_ASSIGN(EventGeneratorDelegateMac); 288 DISALLOW_COPY_AND_ASSIGN(EventGeneratorDelegateMac);
289 }; 289 };
290 290
291 EventGeneratorDelegateMac::EventGeneratorDelegateMac() 291 EventGeneratorDelegateMac::EventGeneratorDelegateMac() : owner_(NULL) {
292 : owner_(NULL),
293 window_(NULL) {
294 DCHECK(!ui::test::EventGenerator::default_delegate); 292 DCHECK(!ui::test::EventGenerator::default_delegate);
295 ui::test::EventGenerator::default_delegate = this; 293 ui::test::EventGenerator::default_delegate = this;
296 // Install a fake "edit" menu. This is normally provided by Chrome's 294 // Install a fake "edit" menu. This is normally provided by Chrome's
297 // MainMenu.xib, but src/ui shouldn't depend on that. 295 // MainMenu.xib, but src/ui shouldn't depend on that.
298 fake_menu_.reset([[NSMenu alloc] initWithTitle:@"Edit"]); 296 fake_menu_.reset([[NSMenu alloc] initWithTitle:@"Edit"]);
299 struct { 297 struct {
300 NSString* title; 298 NSString* title;
301 SEL action; 299 SEL action;
302 NSString* key_equivalent; 300 NSString* key_equivalent;
303 } fake_menu_item[] = { 301 } fake_menu_item[] = {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 353
356 EmulateSendEvent(window_, ns_event); 354 EmulateSendEvent(window_, ns_event);
357 } 355 }
358 356
359 void EventGeneratorDelegateMac::SetContext(ui::test::EventGenerator* owner, 357 void EventGeneratorDelegateMac::SetContext(ui::test::EventGenerator* owner,
360 gfx::NativeWindow root_window, 358 gfx::NativeWindow root_window,
361 gfx::NativeWindow window) { 359 gfx::NativeWindow window) {
362 swizzle_pressed_.reset(); 360 swizzle_pressed_.reset();
363 swizzle_current_event_.reset(); 361 swizzle_current_event_.reset();
364 owner_ = owner; 362 owner_ = owner;
365 window_ = window; 363
364 // Retain the NSWindow (note it can be nil). This matches Cocoa's tendency to
365 // have autoreleased objects, or objects still in the event queue, that
366 // reference the NSWindow.
367 window_.reset([window retain]);
366 368
367 // Normally, edit menu items have a `nil` target. This results in -[NSMenu 369 // Normally, edit menu items have a `nil` target. This results in -[NSMenu
368 // performKeyEquivalent:] relying on -[NSApplication targetForAction:to:from:] 370 // performKeyEquivalent:] relying on -[NSApplication targetForAction:to:from:]
369 // to find a target starting at the first responder of the key window. Since 371 // to find a target starting at the first responder of the key window. Since
370 // non-interactive tests have no key window, that won't work. So set (or 372 // non-interactive tests have no key window, that won't work. So set (or
371 // clear) the target explicitly on all menu items. 373 // clear) the target explicitly on all menu items.
372 [[fake_menu_ itemArray] makeObjectsPerformSelector:@selector(setTarget:) 374 [[fake_menu_ itemArray] makeObjectsPerformSelector:@selector(setTarget:)
373 withObject:[window firstResponder]]; 375 withObject:[window firstResponder]];
374 376
375 if (owner_) { 377 if (owner_) {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 - (NSEvent*)currentEvent { 436 - (NSEvent*)currentEvent {
435 if (g_current_event) 437 if (g_current_event)
436 return g_current_event; 438 return g_current_event;
437 439
438 // Find the original implementation and invoke it. 440 // Find the original implementation and invoke it.
439 IMP original = EventGeneratorDelegateMac::GetInstance()->CurrentEventMethod(); 441 IMP original = EventGeneratorDelegateMac::GetInstance()->CurrentEventMethod();
440 return original(self, _cmd); 442 return original(self, _cmd);
441 } 443 }
442 444
443 @end 445 @end
OLDNEW
« no previous file with comments | « ui/views/cocoa/bridged_native_widget.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698