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

Side by Side Diff: ui/base/cocoa/nib_loading.mm

Issue 1836363002: Mac: Remove use of deprecated [NSNib instantiateNibWithOwner:topLevelObjects:]. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@20160329-Mac-DeploymentTarget
Patch Set: Add forward declare Created 4 years, 8 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ui/base/cocoa/nib_loading.h" 5 #import "ui/base/cocoa/nib_loading.h"
6 6
7 #include "base/mac/bundle_locations.h" 7 #include "base/mac/bundle_locations.h"
8 #include "base/mac/scoped_nsobject.h" 8 #include "base/mac/scoped_nsobject.h"
9 9
10 @interface NSNib (MountainLionSDK)
11 - (BOOL)instantiateWithOwner:(nullable id)owner
12 topLevelObjects:(NSArray* __nonnull* __nullable)topLevelObjects;
13 @end
14
10 namespace ui { 15 namespace ui {
11 16
12 NSView* GetViewFromNib(NSString* name) { 17 NSView* GetViewFromNib(NSString* name) {
13 base::scoped_nsobject<NSNib> nib( 18 base::scoped_nsobject<NSNib> nib(
14 [[NSNib alloc] initWithNibNamed:name 19 [[NSNib alloc] initWithNibNamed:name
15 bundle:base::mac::FrameworkBundle()]); 20 bundle:base::mac::FrameworkBundle()]);
16 if (!nib) 21 if (!nib)
17 return nil; 22 return nil;
18 23
19 NSArray* objects; 24 NSArray* objects;
20 BOOL success = [nib instantiateNibWithOwner:nil 25 BOOL success = [nib instantiateWithOwner:nil topLevelObjects:&objects];
21 topLevelObjects:&objects];
22 if (!success) 26 if (!success)
23 return nil; 27 return nil;
24 28
25 // When loading a nib manually (as opposed to using an NSWindowController or
26 // NSViewController), all the top-level objects need to be explicitly
27 // released. See
28 // http://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/Loadi ngResources/CocoaNibs/CocoaNibs.html#//apple_ref/doc/uid/10000051i-CH4-SW10
29 // for more information.
30 [objects makeObjectsPerformSelector:@selector(release)];
31
32 // For some strange reason, even nibs that appear to have but one top-level 29 // For some strange reason, even nibs that appear to have but one top-level
33 // object often have more (an NSApplication, etc.). Filter out what isn't 30 // object often have more (an NSApplication, etc.). Filter out what isn't
34 // desired. 31 // desired.
35 for (NSView* view in objects) { 32 for (NSView* view in objects) {
36 if (![view isKindOfClass:[NSView class]]) 33 if (![view isKindOfClass:[NSView class]])
37 continue; 34 continue;
38 35
39 return [[view retain] autorelease]; 36 return [[view retain] autorelease];
40 } 37 }
41 38
42 return nil; 39 return nil;
43 } 40 }
44 41
45 } // namespace ui 42 } // namespace ui
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