| OLD | NEW |
| 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 Loading... |
| 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) { | |
| 53 if (!hostedView_) | 52 if (!hostedView_) |
| 54 return nil; | 53 return nil; |
| 55 | 54 |
| 56 if ([identifier isEqualToString:kTouchBarDialogButtonsGroupId]) { | 55 if ([identifier isEqualToString:kTouchBarDialogButtonsGroupId]) { |
| 57 NSMutableArray* items = [NSMutableArray arrayWithCapacity:2]; | 56 NSMutableArray* items = [NSMutableArray arrayWithCapacity:2]; |
| 58 for (NSTouchBarItemIdentifier i in @[ kTouchBarCancelId, kTouchBarOKId ]) { | 57 for (NSTouchBarItemIdentifier i in @[ kTouchBarCancelId, kTouchBarOKId ]) { |
| 59 NSTouchBarItem* item = [self touchBar:touchBar makeItemForIdentifier:i]; | 58 NSTouchBarItem* item = [self touchBar:touchBar makeItemForIdentifier:i]; |
| 60 if (item) | 59 if (item) |
| 61 [items addObject:item]; | 60 [items addObject:item]; |
| 62 } | 61 } |
| 63 if ([items count] == 0) | 62 if ([items count] == 0) |
| 64 return nil; | 63 return nil; |
| 65 return [NSClassFromString(@"NSGroupTouchBarItem") | 64 return [NSGroupTouchBarItem groupItemWithIdentifier:identifier items:items]; |
| 66 groupItemWithIdentifier:identifier | |
| 67 items:items]; | |
| 68 } | 65 } |
| 69 | 66 |
| 70 ui::DialogButton type = ui::DIALOG_BUTTON_NONE; | 67 ui::DialogButton type = ui::DIALOG_BUTTON_NONE; |
| 71 if ([identifier isEqualToString:kTouchBarOKId]) | 68 if ([identifier isEqualToString:kTouchBarOKId]) |
| 72 type = ui::DIALOG_BUTTON_OK; | 69 type = ui::DIALOG_BUTTON_OK; |
| 73 else if ([identifier isEqualToString:kTouchBarCancelId]) | 70 else if ([identifier isEqualToString:kTouchBarCancelId]) |
| 74 type = ui::DIALOG_BUTTON_CANCEL; | 71 type = ui::DIALOG_BUTTON_CANCEL; |
| 75 else | 72 else |
| 76 return nil; | 73 return nil; |
| 77 | 74 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 97 alpha:1.0]]; | 94 alpha:1.0]]; |
| 98 } | 95 } |
| 99 [button setEnabled:model->IsDialogButtonEnabled(type)]; | 96 [button setEnabled:model->IsDialogButtonEnabled(type)]; |
| 100 [button setTag:type]; | 97 [button setTag:type]; |
| 101 [item setView:button]; | 98 [item setView:button]; |
| 102 return item.autorelease(); | 99 return item.autorelease(); |
| 103 } | 100 } |
| 104 | 101 |
| 105 // NSTouchBarProvider protocol implementation (via NSResponder category). | 102 // NSTouchBarProvider protocol implementation (via NSResponder category). |
| 106 | 103 |
| 107 - (NSTouchBar*)makeTouchBar NS_AVAILABLE_MAC(10_12_1) { | 104 - (NSTouchBar*)makeTouchBar { |
| 108 if (!hostedView_) | 105 if (!hostedView_) |
| 109 return nil; | 106 return nil; |
| 110 | 107 |
| 111 ui::DialogModel* model = | 108 ui::DialogModel* model = |
| 112 hostedView_->GetWidget()->widget_delegate()->AsDialogDelegate(); | 109 hostedView_->GetWidget()->widget_delegate()->AsDialogDelegate(); |
| 113 if (!model || !model->GetDialogButtons()) | 110 if (!model || !model->GetDialogButtons()) |
| 114 return nil; | 111 return nil; |
| 115 | 112 |
| 116 base::scoped_nsobject<NSTouchBar> bar( | 113 base::scoped_nsobject<NSTouchBar> bar( |
| 117 [[NSClassFromString(@"NSTouchBar") alloc] init]); | 114 [[NSClassFromString(@"NSTouchBar") alloc] init]); |
| 118 [bar setDelegate:self]; | 115 [bar setDelegate:self]; |
| 119 | 116 |
| 120 // Use a group rather than individual items so they can be centered together. | 117 // Use a group rather than individual items so they can be centered together. |
| 121 [bar setDefaultItemIdentifiers:@[ kTouchBarDialogButtonsGroupId ]]; | 118 [bar setDefaultItemIdentifiers:@[ kTouchBarDialogButtonsGroupId ]]; |
| 122 | 119 |
| 123 // Setting the group as principal will center it in the TouchBar. | 120 // Setting the group as principal will center it in the TouchBar. |
| 124 [bar setPrincipalItemIdentifier:kTouchBarDialogButtonsGroupId]; | 121 [bar setPrincipalItemIdentifier:kTouchBarDialogButtonsGroupId]; |
| 125 return bar.autorelease(); | 122 return bar.autorelease(); |
| 126 } | 123 } |
| 127 | 124 |
| 128 @end | 125 @end |
| OLD | NEW |