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

Side by Side Diff: chrome/browser/ui/cocoa/bookmarks/bookmark_bubble_controller.mm

Issue 2921083003: [Mac] Touch Bar Support for Dialogs (Closed)
Patch Set: nits Created 3 years, 6 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 "chrome/browser/ui/cocoa/bookmarks/bookmark_bubble_controller.h" 5 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bubble_controller.h"
6 6
7 #include "base/mac/bundle_locations.h" 7 #include "base/mac/bundle_locations.h"
8 #import "base/mac/sdk_forward_declarations.h"
8 #include "base/metrics/user_metrics.h" 9 #include "base/metrics/user_metrics.h"
9 #include "base/strings/sys_string_conversions.h" 10 #include "base/strings/sys_string_conversions.h"
10 #include "chrome/browser/ui/bookmarks/bookmark_bubble_observer.h" 11 #include "chrome/browser/ui/bookmarks/bookmark_bubble_observer.h"
11 #include "chrome/browser/ui/browser.h" 12 #include "chrome/browser/ui/browser.h"
12 #include "chrome/browser/ui/browser_finder.h" 13 #include "chrome/browser/ui/browser_finder.h"
13 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_button.h" 14 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_button.h"
14 #import "chrome/browser/ui/cocoa/browser_window_controller.h" 15 #import "chrome/browser/ui/cocoa/browser_window_controller.h"
15 #import "chrome/browser/ui/cocoa/bubble_sync_promo_controller.h" 16 #import "chrome/browser/ui/cocoa/bubble_sync_promo_controller.h"
17 #import "chrome/browser/ui/cocoa/dialog_text_field_editor.h"
16 #import "chrome/browser/ui/cocoa/info_bubble_view.h" 18 #import "chrome/browser/ui/cocoa/info_bubble_view.h"
17 #import "chrome/browser/ui/cocoa/l10n_util.h" 19 #import "chrome/browser/ui/cocoa/l10n_util.h"
18 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" 20 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h"
19 #import "chrome/browser/ui/cocoa/location_bar/star_decoration.h" 21 #import "chrome/browser/ui/cocoa/location_bar/star_decoration.h"
20 #include "chrome/browser/ui/sync/sync_promo_ui.h" 22 #include "chrome/browser/ui/sync/sync_promo_ui.h"
23 #include "chrome/common/chrome_features.h"
21 #include "chrome/grit/chromium_strings.h" 24 #include "chrome/grit/chromium_strings.h"
22 #include "chrome/grit/generated_resources.h" 25 #include "chrome/grit/generated_resources.h"
23 #include "components/bookmarks/browser/bookmark_model.h" 26 #include "components/bookmarks/browser/bookmark_model.h"
24 #include "components/bookmarks/browser/bookmark_utils.h" 27 #include "components/bookmarks/browser/bookmark_utils.h"
25 #include "components/bookmarks/managed/managed_bookmark_service.h" 28 #include "components/bookmarks/managed/managed_bookmark_service.h"
26 #include "components/signin/core/browser/signin_metrics.h" 29 #include "components/signin/core/browser/signin_metrics.h"
30 #include "components/strings/grit/components_strings.h"
27 #include "content/public/browser/notification_observer.h" 31 #include "content/public/browser/notification_observer.h"
28 #include "content/public/browser/notification_registrar.h" 32 #include "content/public/browser/notification_registrar.h"
29 #include "content/public/browser/notification_service.h" 33 #include "content/public/browser/notification_service.h"
30 #include "ui/base/cocoa/cocoa_base_utils.h" 34 #include "ui/base/cocoa/cocoa_base_utils.h"
35 #import "ui/base/cocoa/touch_bar_util.h"
31 #include "ui/base/l10n/l10n_util_mac.h" 36 #include "ui/base/l10n/l10n_util_mac.h"
32 37
33 using base::UserMetricsAction; 38 using base::UserMetricsAction;
34 using bookmarks::BookmarkModel; 39 using bookmarks::BookmarkModel;
35 using bookmarks::BookmarkNode; 40 using bookmarks::BookmarkNode;
36 41
42 namespace {
43
44 // Touch bar identifier.
45 NSString* const kBookmarkBubbleTouchBarId = @"bookmark-bubble";
46
47 // Touch bar item identifiers.
48 NSString* const kRemoveTouchBarId = @"REMOVE";
49 NSString* const kEditTouchBarId = @"EDIT";
50 NSString* const kDoneTouchBarId = @"DONE";
51
52 } // end namespace
53
37 @interface BookmarkBubbleController (PrivateAPI) 54 @interface BookmarkBubbleController (PrivateAPI)
38 - (void)updateBookmarkNode; 55 - (void)updateBookmarkNode;
39 - (void)fillInFolderList; 56 - (void)fillInFolderList;
40 @end 57 @end
41 58
42 @implementation BookmarkBubbleController 59 @implementation BookmarkBubbleController
43 60
44 @synthesize node = node_; 61 @synthesize node = node_;
45 62
46 // Singleton object to act as a representedObject for the "choose another 63 // Singleton object to act as a representedObject for the "choose another
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 } 206 }
190 207
191 - (void)close { 208 - (void)close {
192 [[BrowserWindowController browserWindowControllerForWindow:self.parentWindow] 209 [[BrowserWindowController browserWindowControllerForWindow:self.parentWindow]
193 releaseToolbarVisibilityForOwner:self 210 releaseToolbarVisibilityForOwner:self
194 withAnimation:YES]; 211 withAnimation:YES];
195 212
196 [super close]; 213 [super close];
197 } 214 }
198 215
216 - (NSTouchBar*)makeTouchBar {
217 if (!base::FeatureList::IsEnabled(features::kBrowserTouchBar))
218 return nil;
219
220 base::scoped_nsobject<NSTouchBar> touchBar(
221 [[NSClassFromString(@"NSTouchBar") alloc] init]);
222 [touchBar setCustomizationIdentifier:ui::CreateTouchBarId(
223 kBookmarkBubbleTouchBarId)];
224 [touchBar setDelegate:self];
225
226 NSArray* dialogItems = @[
227 ui::CreateTouchBarItemId(kBookmarkBubbleTouchBarId, kRemoveTouchBarId),
228 ui::CreateTouchBarItemId(kBookmarkBubbleTouchBarId, kEditTouchBarId),
229 ui::CreateTouchBarItemId(kBookmarkBubbleTouchBarId, kDoneTouchBarId)
230 ];
231
232 [touchBar setDefaultItemIdentifiers:dialogItems];
233 [touchBar setCustomizationAllowedItemIdentifiers:dialogItems];
234 return touchBar.autorelease();
235 }
236
237 - (NSTouchBarItem*)touchBar:(NSTouchBar*)touchBar
238 makeItemForIdentifier:(NSTouchBarItemIdentifier)identifier {
239 NSButton* button = nil;
240 if ([identifier hasSuffix:kRemoveTouchBarId]) {
241 button = [NSButton buttonWithTitle:l10n_util::GetNSString(
242 IDS_BOOKMARK_BUBBLE_REMOVE_BOOKMARK)
243 target:self
244 action:@selector(remove:)];
245 } else if ([identifier hasSuffix:kEditTouchBarId]) {
246 button = [NSButton
247 buttonWithTitle:l10n_util::GetNSString(IDS_BOOKMARK_BUBBLE_OPTIONS)
248 target:self
249 action:@selector(edit:)];
250 } else if ([identifier hasSuffix:kDoneTouchBarId]) {
251 button = ui::CreateBlueTouchBarButton(l10n_util::GetNSString(IDS_DONE),
252 self, @selector(ok:));
253 } else {
254 return nil;
255 }
256
257 base::scoped_nsobject<NSCustomTouchBarItem> item([[NSClassFromString(
258 @"NSCustomTouchBarItem") alloc] initWithIdentifier:identifier]);
259 [item setView:button];
260 return item.autorelease();
261 }
262
263 // Delegate method: see |NSWindowDelegate| protocol.
264 - (id)windowWillReturnFieldEditor:(NSWindow*)sender toObject:(id)obj {
265 if (obj != nameTextField_)
266 return nil;
267
268 if (!textFieldEditor_)
269 textFieldEditor_.reset([[DialogTextFieldEditor alloc] init]);
270
271 return textFieldEditor_.get();
272 }
273
199 // Shows the bookmark editor sheet for more advanced editing. 274 // Shows the bookmark editor sheet for more advanced editing.
200 - (void)showEditor { 275 - (void)showEditor {
201 [self ok:self]; 276 [self ok:self];
202 // Send the action up through the responder chain. 277 // Send the action up through the responder chain.
203 [NSApp sendAction:@selector(editBookmarkNode:) to:nil from:self]; 278 [NSApp sendAction:@selector(editBookmarkNode:) to:nil from:self];
204 } 279 }
205 280
206 - (IBAction)edit:(id)sender { 281 - (IBAction)edit:(id)sender {
207 base::RecordAction(UserMetricsAction("BookmarkBubble_Edit")); 282 base::RecordAction(UserMetricsAction("BookmarkBubble_Edit"));
208 [self showEditor]; 283 [self showEditor];
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 NSInteger idx = [menu indexOfItemWithRepresentedObject:parentValue]; 465 NSInteger idx = [menu indexOfItemWithRepresentedObject:parentValue];
391 DCHECK(idx != -1); 466 DCHECK(idx != -1);
392 [folderPopUpButton_ selectItemAtIndex:idx]; 467 [folderPopUpButton_ selectItemAtIndex:idx];
393 } 468 }
394 469
395 - (NSPopUpButton*)folderPopUpButton { 470 - (NSPopUpButton*)folderPopUpButton {
396 return folderPopUpButton_; 471 return folderPopUpButton_;
397 } 472 }
398 473
399 @end // implementation BookmarkBubbleController(ExposedForUnitTesting) 474 @end // implementation BookmarkBubbleController(ExposedForUnitTesting)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698