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

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

Issue 2921083003: [Mac] Touch Bar Support for Dialogs (Closed)
Patch Set: Added test and renamed methods 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([[ui::NSTouchBar() alloc] init]);
221 [touchBar
222 setCustomizationIdentifier:ui::GetTouchBarId(kBookmarkBubbleTouchBarId)];
223 [touchBar setDelegate:self];
224
225 NSArray* dialogItems = @[
226 ui::GetTouchBarItemId(kBookmarkBubbleTouchBarId, kRemoveTouchBarId),
227 ui::GetTouchBarItemId(kBookmarkBubbleTouchBarId, kEditTouchBarId),
228 ui::GetTouchBarItemId(kBookmarkBubbleTouchBarId, kDoneTouchBarId)
229 ];
230
231 [touchBar setDefaultItemIdentifiers:dialogItems];
232 [touchBar setCustomizationAllowedItemIdentifiers:dialogItems];
233 return touchBar.autorelease();
234 }
235
236 - (NSTouchBarItem*)touchBar:(NSTouchBar*)touchBar
237 makeItemForIdentifier:(NSTouchBarItemIdentifier)identifier {
238 NSButton* button = nil;
239 if ([identifier hasSuffix:kRemoveTouchBarId]) {
240 button = [NSButton buttonWithTitle:l10n_util::GetNSString(
241 IDS_BOOKMARK_BUBBLE_REMOVE_BOOKMARK)
242 target:self
243 action:@selector(remove:)];
244 } else if ([identifier hasSuffix:kEditTouchBarId]) {
245 button = [NSButton
246 buttonWithTitle:l10n_util::GetNSString(IDS_BOOKMARK_BUBBLE_OPTIONS)
247 target:self
248 action:@selector(edit:)];
249 } else if ([identifier hasSuffix:kDoneTouchBarId]) {
250 button = ui::GetBlueTouchBarButton(l10n_util::GetNSString(IDS_DONE), self,
251 @selector(ok:));
252 } else {
253 return nil;
254 }
255
256 base::scoped_nsobject<NSCustomTouchBarItem> item(
257 [[ui::NSCustomTouchBarItem() alloc] initWithIdentifier:identifier]);
258 [item setView:button];
259 return item.autorelease();
260 }
261
262 // Delegate method: see |NSWindowDelegate| protocol.
263 - (id)windowWillReturnFieldEditor:(NSWindow*)sender toObject:(id)obj {
264 if (obj != nameTextField_)
265 return nil;
266
267 if (!textFieldEditor_)
268 textFieldEditor_.reset([[DialogTextFieldEditor alloc] init]);
269
270 return textFieldEditor_.get();
271 }
272
199 // Shows the bookmark editor sheet for more advanced editing. 273 // Shows the bookmark editor sheet for more advanced editing.
200 - (void)showEditor { 274 - (void)showEditor {
201 [self ok:self]; 275 [self ok:self];
202 // Send the action up through the responder chain. 276 // Send the action up through the responder chain.
203 [NSApp sendAction:@selector(editBookmarkNode:) to:nil from:self]; 277 [NSApp sendAction:@selector(editBookmarkNode:) to:nil from:self];
204 } 278 }
205 279
206 - (IBAction)edit:(id)sender { 280 - (IBAction)edit:(id)sender {
207 base::RecordAction(UserMetricsAction("BookmarkBubble_Edit")); 281 base::RecordAction(UserMetricsAction("BookmarkBubble_Edit"));
208 [self showEditor]; 282 [self showEditor];
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 NSInteger idx = [menu indexOfItemWithRepresentedObject:parentValue]; 464 NSInteger idx = [menu indexOfItemWithRepresentedObject:parentValue];
391 DCHECK(idx != -1); 465 DCHECK(idx != -1);
392 [folderPopUpButton_ selectItemAtIndex:idx]; 466 [folderPopUpButton_ selectItemAtIndex:idx];
393 } 467 }
394 468
395 - (NSPopUpButton*)folderPopUpButton { 469 - (NSPopUpButton*)folderPopUpButton {
396 return folderPopUpButton_; 470 return folderPopUpButton_;
397 } 471 }
398 472
399 @end // implementation BookmarkBubbleController(ExposedForUnitTesting) 473 @end // implementation BookmarkBubbleController(ExposedForUnitTesting)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698