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

Side by Side Diff: ui/views/cocoa/bridged_content_view_touch_bar.mm

Issue 2519563002: [Mac] Switch from NSObject categories to forward declarations for Touch Bar support. (Closed)
Patch Set: Tweak comment, change `retain` back to `strong` in interfaces from Apple headers. Created 4 years 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/base/cocoa/touch_bar_forward_declarations.h ('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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "base/mac/scoped_nsobject.h" 5 #import "base/mac/scoped_nsobject.h"
6 #import "base/mac/sdk_forward_declarations.h" 6 #import "base/mac/sdk_forward_declarations.h"
7 #include "base/strings/sys_string_conversions.h" 7 #include "base/strings/sys_string_conversions.h"
8 #import "ui/base/cocoa/touch_bar_forward_declarations.h" 8 #import "ui/base/cocoa/touch_bar_forward_declarations.h"
9 #include "ui/base/models/dialog_model.h" 9 #include "ui/base/models/dialog_model.h"
10 #import "ui/views/cocoa/bridged_content_view.h" 10 #import "ui/views/cocoa/bridged_content_view.h"
(...skipping 30 matching lines...) Expand all
41 return; 41 return;
42 } 42 }
43 43
44 DCHECK_EQ([sender tag], ui::DIALOG_BUTTON_CANCEL); 44 DCHECK_EQ([sender tag], ui::DIALOG_BUTTON_CANCEL);
45 client->CancelWindow(); 45 client->CancelWindow();
46 } 46 }
47 47
48 // NSTouchBarDelegate protocol implementation. 48 // NSTouchBarDelegate protocol implementation.
49 49
50 - (NSTouchBarItem*)touchBar:(NSTouchBar*)touchBar 50 - (NSTouchBarItem*)touchBar:(NSTouchBar*)touchBar
51 makeItemForIdentifier:(NSTouchBarItemIdentifier)identifier { 51 makeItemForIdentifier:(NSTouchBarItemIdentifier)identifier
52 NS_AVAILABLE_MAC(10_12_1) {
52 if (!hostedView_) 53 if (!hostedView_)
53 return nil; 54 return nil;
54 55
55 if ([identifier isEqualToString:kTouchBarDialogButtonsGroupId]) { 56 if ([identifier isEqualToString:kTouchBarDialogButtonsGroupId]) {
56 NSMutableArray* items = [NSMutableArray arrayWithCapacity:2]; 57 NSMutableArray* items = [NSMutableArray arrayWithCapacity:2];
57 for (NSTouchBarItemIdentifier i in @[ kTouchBarCancelId, kTouchBarOKId ]) { 58 for (NSTouchBarItemIdentifier i in @[ kTouchBarCancelId, kTouchBarOKId ]) {
58 NSTouchBarItem* item = [self touchBar:touchBar makeItemForIdentifier:i]; 59 NSTouchBarItem* item = [self touchBar:touchBar makeItemForIdentifier:i];
59 if (item) 60 if (item)
60 [items addObject:item]; 61 [items addObject:item];
61 } 62 }
62 if ([items count] == 0) 63 if ([items count] == 0)
63 return nil; 64 return nil;
64 return [NSGroupTouchBarItem groupItemWithIdentifier:identifier items:items]; 65 return [NSClassFromString(@"NSGroupTouchBarItem")
66 groupItemWithIdentifier:identifier
67 items:items];
65 } 68 }
66 69
67 ui::DialogButton type = ui::DIALOG_BUTTON_NONE; 70 ui::DialogButton type = ui::DIALOG_BUTTON_NONE;
68 if ([identifier isEqualToString:kTouchBarOKId]) 71 if ([identifier isEqualToString:kTouchBarOKId])
69 type = ui::DIALOG_BUTTON_OK; 72 type = ui::DIALOG_BUTTON_OK;
70 else if ([identifier isEqualToString:kTouchBarCancelId]) 73 else if ([identifier isEqualToString:kTouchBarCancelId])
71 type = ui::DIALOG_BUTTON_CANCEL; 74 type = ui::DIALOG_BUTTON_CANCEL;
72 else 75 else
73 return nil; 76 return nil;
74 77
(...skipping 19 matching lines...) Expand all
94 alpha:1.0]]; 97 alpha:1.0]];
95 } 98 }
96 [button setEnabled:model->IsDialogButtonEnabled(type)]; 99 [button setEnabled:model->IsDialogButtonEnabled(type)];
97 [button setTag:type]; 100 [button setTag:type];
98 [item setView:button]; 101 [item setView:button];
99 return item.autorelease(); 102 return item.autorelease();
100 } 103 }
101 104
102 // NSTouchBarProvider protocol implementation (via NSResponder category). 105 // NSTouchBarProvider protocol implementation (via NSResponder category).
103 106
104 - (NSTouchBar*)makeTouchBar { 107 - (NSTouchBar*)makeTouchBar NS_AVAILABLE_MAC(10_12_1) {
105 if (!hostedView_) 108 if (!hostedView_)
106 return nil; 109 return nil;
107 110
108 ui::DialogModel* model = 111 ui::DialogModel* model =
109 hostedView_->GetWidget()->widget_delegate()->AsDialogDelegate(); 112 hostedView_->GetWidget()->widget_delegate()->AsDialogDelegate();
110 if (!model || !model->GetDialogButtons()) 113 if (!model || !model->GetDialogButtons())
111 return nil; 114 return nil;
112 115
113 base::scoped_nsobject<NSTouchBar> bar( 116 base::scoped_nsobject<NSTouchBar> bar(
114 [[NSClassFromString(@"NSTouchBar") alloc] init]); 117 [[NSClassFromString(@"NSTouchBar") alloc] init]);
115 [bar setDelegate:self]; 118 [bar setDelegate:self];
116 119
117 // Use a group rather than individual items so they can be centered together. 120 // Use a group rather than individual items so they can be centered together.
118 [bar setDefaultItemIdentifiers:@[ kTouchBarDialogButtonsGroupId ]]; 121 [bar setDefaultItemIdentifiers:@[ kTouchBarDialogButtonsGroupId ]];
119 122
120 // Setting the group as principal will center it in the TouchBar. 123 // Setting the group as principal will center it in the TouchBar.
121 [bar setPrincipalItemIdentifier:kTouchBarDialogButtonsGroupId]; 124 [bar setPrincipalItemIdentifier:kTouchBarDialogButtonsGroupId];
122 return bar.autorelease(); 125 return bar.autorelease();
123 } 126 }
124 127
125 @end 128 @end
OLDNEW
« no previous file with comments | « ui/base/cocoa/touch_bar_forward_declarations.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698