Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 #include "chrome/browser/ui/cocoa/extensions/media_galleries_dialog_cocoa.h" | 5 #include "chrome/browser/ui/cocoa/extensions/media_galleries_dialog_cocoa.h" |
| 6 | 6 |
| 7 #include "base/mac/scoped_nsobject.h" | |
| 7 #include "base/strings/sys_string_conversions.h" | 8 #include "base/strings/sys_string_conversions.h" |
| 8 #include "chrome/browser/ui/chrome_style.h" | 9 #include "chrome/browser/ui/chrome_style.h" |
| 9 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_alert.h" | 10 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_alert.h" |
| 10 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_button.h" | 11 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_button.h" |
| 11 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_control_u tils.h" | 12 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_control_u tils.h" |
| 12 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_sh eet.h" | 13 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_sh eet.h" |
| 13 #import "chrome/browser/ui/cocoa/key_equivalent_constants.h" | 14 #import "chrome/browser/ui/cocoa/key_equivalent_constants.h" |
| 14 #include "content/public/browser/web_contents.h" | 15 #include "content/public/browser/web_contents.h" |
| 15 #include "grit/generated_resources.h" | 16 #include "grit/generated_resources.h" |
| 16 #import "ui/base/cocoa/flipped_view.h" | 17 #import "ui/base/cocoa/flipped_view.h" |
| 18 #import "ui/base/cocoa/menu_controller.h" | |
| 19 #import "ui/base/models/menu_model.h" | |
| 17 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" |
| 18 #include "ui/base/resource/resource_bundle.h" | 21 #include "ui/base/resource/resource_bundle.h" |
| 19 | 22 |
| 23 // Controller for UI events on items in the media galleries dialog. | |
| 20 @interface MediaGalleriesCocoaController : NSObject { | 24 @interface MediaGalleriesCocoaController : NSObject { |
| 21 @private | 25 @private |
| 22 MediaGalleriesDialogCocoa* dialog_; | 26 MediaGalleriesDialogCocoa* dialog_; |
| 23 } | 27 } |
| 24 | 28 |
| 25 @property(nonatomic, assign) MediaGalleriesDialogCocoa* dialog; | 29 @property(nonatomic, assign) MediaGalleriesDialogCocoa* dialog; |
| 26 | 30 |
| 27 @end | 31 @end |
| 28 | 32 |
| 29 @implementation MediaGalleriesCocoaController | 33 @implementation MediaGalleriesCocoaController |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 43 dialog_->OnAddFolderClicked(); | 47 dialog_->OnAddFolderClicked(); |
| 44 } | 48 } |
| 45 | 49 |
| 46 - (void)onCheckboxToggled:(id)sender { | 50 - (void)onCheckboxToggled:(id)sender { |
| 47 DCHECK(dialog_); | 51 DCHECK(dialog_); |
| 48 dialog_->OnCheckboxToggled(sender); | 52 dialog_->OnCheckboxToggled(sender); |
| 49 } | 53 } |
| 50 | 54 |
| 51 @end | 55 @end |
| 52 | 56 |
| 57 @interface MediaGalleriesCheckbox : NSButton { | |
| 58 @private | |
| 59 MediaGalleriesDialogCocoa* dialog_; | |
| 60 MediaGalleryPrefId prefId_; | |
| 61 base::scoped_nsobject<MenuController> menu_controller_; | |
| 62 } | |
| 63 | |
| 64 - (NSMenu*)menuForEvent:(NSEvent*)theEvent; | |
|
Avi (use Gerrit)
2013/11/06 22:01:51
Now that you have a custom initializer you need to
Greg Billock
2013/11/06 22:30:18
Done.
| |
| 65 | |
| 66 @end | |
| 67 | |
| 68 @implementation MediaGalleriesCheckbox | |
| 69 | |
| 70 - (id)initWithFrame:(NSRect)frameRect | |
| 71 dialog:(MediaGalleriesDialogCocoa*)dialog | |
| 72 prefId:(MediaGalleryPrefId)prefId { | |
| 73 if ((self = [super initWithFrame:frameRect])) { | |
| 74 dialog_ = dialog; | |
| 75 prefId_ = prefId; | |
| 76 } | |
| 77 return self; | |
| 78 } | |
| 79 | |
| 80 - (NSMenu*)menuForEvent:(NSEvent*)theEvent { | |
| 81 menu_controller_.reset( | |
| 82 [[MenuController alloc] initWithModel:dialog_->GetContextMenuModel(prefId_) | |
| 83 useWithPopUpButtonCell:NO]); | |
| 84 return [menu_controller_ menu]; | |
| 85 } | |
| 86 | |
| 87 @end | |
| 88 | |
| 53 namespace { | 89 namespace { |
| 54 | 90 |
| 55 const CGFloat kCheckboxMargin = 10; | 91 const CGFloat kCheckboxMargin = 10; |
| 56 const CGFloat kCheckboxMaxWidth = 440; | 92 const CGFloat kCheckboxMaxWidth = 440; |
| 57 const CGFloat kScrollAreaHeight = 220; | 93 const CGFloat kScrollAreaHeight = 220; |
| 58 | 94 |
| 59 NSString* GetUniqueIDForGallery(const MediaGalleryPrefInfo& gallery) { | 95 NSString* GetUniqueIDForGallery(const MediaGalleryPrefInfo& gallery) { |
| 60 return base::SysUTF8ToNSString(gallery.device_id + gallery.path.value()); | 96 return base::SysUTF8ToNSString(gallery.device_id + gallery.path.value()); |
| 61 } | 97 } |
| 62 | 98 |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 281 break; | 317 break; |
| 282 } | 318 } |
| 283 } | 319 } |
| 284 | 320 |
| 285 } | 321 } |
| 286 | 322 |
| 287 void MediaGalleriesDialogCocoa::UpdateGalleryCheckbox( | 323 void MediaGalleriesDialogCocoa::UpdateGalleryCheckbox( |
| 288 const MediaGalleryPrefInfo& gallery, | 324 const MediaGalleryPrefInfo& gallery, |
| 289 bool permitted, | 325 bool permitted, |
| 290 CGFloat y_pos) { | 326 CGFloat y_pos) { |
| 291 base::scoped_nsobject<NSButton> checkbox( | 327 base::scoped_nsobject<MediaGalleriesCheckbox> checkbox( |
| 292 [[NSButton alloc] initWithFrame:NSZeroRect]); | 328 [[MediaGalleriesCheckbox alloc] initWithFrame:NSZeroRect |
| 329 dialog:this | |
| 330 prefId:gallery.pref_id]); | |
| 293 NSString* unique_id = GetUniqueIDForGallery(gallery); | 331 NSString* unique_id = GetUniqueIDForGallery(gallery); |
| 294 [[checkbox cell] setRepresentedObject:unique_id]; | 332 [[checkbox cell] setRepresentedObject:unique_id]; |
| 295 [[checkbox cell] setLineBreakMode:NSLineBreakByTruncatingMiddle]; | 333 [[checkbox cell] setLineBreakMode:NSLineBreakByTruncatingMiddle]; |
| 296 [checkbox setButtonType:NSSwitchButton]; | 334 [checkbox setButtonType:NSSwitchButton]; |
| 297 [checkbox setTarget:cocoa_controller_]; | 335 [checkbox setTarget:cocoa_controller_]; |
| 298 [checkbox setAction:@selector(onCheckboxToggled:)]; | 336 [checkbox setAction:@selector(onCheckboxToggled:)]; |
| 299 [checkboxes_ addObject:checkbox]; | 337 [checkboxes_ addObject:checkbox]; |
| 300 | 338 |
| 301 // TODO(gbillock): Would be nice to add middle text elide behavior here. | 339 // TODO(gbillock): Would be nice to add middle text elide behavior here. |
| 302 [checkbox setTitle:base::SysUTF16ToNSString( | 340 [checkbox setTitle:base::SysUTF16ToNSString( |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 340 | 378 |
| 341 void MediaGalleriesDialogCocoa::UpdateGalleries() { | 379 void MediaGalleriesDialogCocoa::UpdateGalleries() { |
| 342 InitDialogControls(); | 380 InitDialogControls(); |
| 343 } | 381 } |
| 344 | 382 |
| 345 void MediaGalleriesDialogCocoa::OnConstrainedWindowClosed( | 383 void MediaGalleriesDialogCocoa::OnConstrainedWindowClosed( |
| 346 ConstrainedWindowMac* window) { | 384 ConstrainedWindowMac* window) { |
| 347 controller_->DialogFinished(accepted_); | 385 controller_->DialogFinished(accepted_); |
| 348 } | 386 } |
| 349 | 387 |
| 388 ui::MenuModel* MediaGalleriesDialogCocoa::GetContextMenuModel( | |
| 389 MediaGalleryPrefId prefid) { | |
| 390 return controller_->GetContextMenuModel(prefid); | |
| 391 } | |
| 392 | |
| 350 // static | 393 // static |
| 351 MediaGalleriesDialog* MediaGalleriesDialog::Create( | 394 MediaGalleriesDialog* MediaGalleriesDialog::Create( |
| 352 MediaGalleriesDialogController* controller) { | 395 MediaGalleriesDialogController* controller) { |
| 353 base::scoped_nsobject<MediaGalleriesCocoaController> cocoa_controller( | 396 base::scoped_nsobject<MediaGalleriesCocoaController> cocoa_controller( |
| 354 [[MediaGalleriesCocoaController alloc] init]); | 397 [[MediaGalleriesCocoaController alloc] init]); |
| 355 return new MediaGalleriesDialogCocoa(controller, cocoa_controller); | 398 return new MediaGalleriesDialogCocoa(controller, cocoa_controller); |
| 356 } | 399 } |
| OLD | NEW |