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

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

Issue 2116103002: mac: Use instantiateWithOwner: instead of deprecated instantiateNibWithOwner: (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: be more thrifty with newlines Created 4 years, 5 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
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 #include "base/mac/sdk_forward_declarations.h"
10 @interface NSNib (MountainLionSDK)
11 - (BOOL)instantiateWithOwner:(nullable id)owner
12 topLevelObjects:(NSArray* __nonnull* __nullable)topLevelObjects;
13 @end
14 10
15 namespace ui { 11 namespace ui {
16 12
17 NSView* GetViewFromNib(NSString* name) { 13 NSView* GetViewFromNib(NSString* name) {
18 base::scoped_nsobject<NSNib> nib( 14 base::scoped_nsobject<NSNib> nib(
19 [[NSNib alloc] initWithNibNamed:name 15 [[NSNib alloc] initWithNibNamed:name
20 bundle:base::mac::FrameworkBundle()]); 16 bundle:base::mac::FrameworkBundle()]);
21 if (!nib) 17 if (!nib)
22 return nil; 18 return nil;
23 19
24 NSArray* objects; 20 NSArray* objects;
25 BOOL success = [nib instantiateWithOwner:nil topLevelObjects:&objects]; 21 BOOL success = [nib instantiateWithOwner:nil topLevelObjects:&objects];
26 if (!success) 22 if (!success)
27 return nil; 23 return nil;
28 24
29 // For some strange reason, even nibs that appear to have but one top-level 25 // For some strange reason, even nibs that appear to have but one top-level
30 // object often have more (an NSApplication, etc.). Filter out what isn't 26 // object often have more (an NSApplication, etc.). Filter out what isn't
31 // desired. 27 // desired.
32 for (NSView* view in objects) { 28 for (NSView* view in objects) {
33 if (![view isKindOfClass:[NSView class]]) 29 if (![view isKindOfClass:[NSView class]])
34 continue; 30 continue;
35 31
36 return [[view retain] autorelease]; 32 return [[view retain] autorelease];
37 } 33 }
38 34
39 return nil; 35 return nil;
40 } 36 }
41 37
42 } // namespace ui 38 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698