| 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 - (id)initWithFrame:(NSRect)frameRect |
| 65 dialog:(MediaGalleriesDialogCocoa*)dialog |
| 66 prefId:(MediaGalleryPrefId)prefId; |
| 67 - (NSMenu*)menuForEvent:(NSEvent*)theEvent; |
| 68 |
| 69 @end |
| 70 |
| 71 @implementation MediaGalleriesCheckbox |
| 72 |
| 73 - (id)initWithFrame:(NSRect)frameRect |
| 74 dialog:(MediaGalleriesDialogCocoa*)dialog |
| 75 prefId:(MediaGalleryPrefId)prefId { |
| 76 if ((self = [super initWithFrame:frameRect])) { |
| 77 dialog_ = dialog; |
| 78 prefId_ = prefId; |
| 79 } |
| 80 return self; |
| 81 } |
| 82 |
| 83 - (NSMenu*)menuForEvent:(NSEvent*)theEvent { |
| 84 menu_controller_.reset( |
| 85 [[MenuController alloc] initWithModel:dialog_->GetContextMenuModel(prefId_) |
| 86 useWithPopUpButtonCell:NO]); |
| 87 return [menu_controller_ menu]; |
| 88 } |
| 89 |
| 90 @end |
| 91 |
| 53 namespace { | 92 namespace { |
| 54 | 93 |
| 55 const CGFloat kCheckboxMargin = 10; | 94 const CGFloat kCheckboxMargin = 10; |
| 56 const CGFloat kCheckboxMaxWidth = 440; | 95 const CGFloat kCheckboxMaxWidth = 440; |
| 57 const CGFloat kScrollAreaHeight = 220; | 96 const CGFloat kScrollAreaHeight = 220; |
| 58 | 97 |
| 59 NSString* GetUniqueIDForGallery(const MediaGalleryPrefInfo& gallery) { | 98 NSString* GetUniqueIDForGallery(const MediaGalleryPrefInfo& gallery) { |
| 60 return base::SysUTF8ToNSString(gallery.device_id + gallery.path.value()); | 99 return base::SysUTF8ToNSString(gallery.device_id + gallery.path.value()); |
| 61 } | 100 } |
| 62 | 101 |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 break; | 320 break; |
| 282 } | 321 } |
| 283 } | 322 } |
| 284 | 323 |
| 285 } | 324 } |
| 286 | 325 |
| 287 void MediaGalleriesDialogCocoa::UpdateGalleryCheckbox( | 326 void MediaGalleriesDialogCocoa::UpdateGalleryCheckbox( |
| 288 const MediaGalleryPrefInfo& gallery, | 327 const MediaGalleryPrefInfo& gallery, |
| 289 bool permitted, | 328 bool permitted, |
| 290 CGFloat y_pos) { | 329 CGFloat y_pos) { |
| 291 base::scoped_nsobject<NSButton> checkbox( | 330 base::scoped_nsobject<MediaGalleriesCheckbox> checkbox( |
| 292 [[NSButton alloc] initWithFrame:NSZeroRect]); | 331 [[MediaGalleriesCheckbox alloc] initWithFrame:NSZeroRect |
| 332 dialog:this |
| 333 prefId:gallery.pref_id]); |
| 293 NSString* unique_id = GetUniqueIDForGallery(gallery); | 334 NSString* unique_id = GetUniqueIDForGallery(gallery); |
| 294 [[checkbox cell] setRepresentedObject:unique_id]; | 335 [[checkbox cell] setRepresentedObject:unique_id]; |
| 295 [[checkbox cell] setLineBreakMode:NSLineBreakByTruncatingMiddle]; | 336 [[checkbox cell] setLineBreakMode:NSLineBreakByTruncatingMiddle]; |
| 296 [checkbox setButtonType:NSSwitchButton]; | 337 [checkbox setButtonType:NSSwitchButton]; |
| 297 [checkbox setTarget:cocoa_controller_]; | 338 [checkbox setTarget:cocoa_controller_]; |
| 298 [checkbox setAction:@selector(onCheckboxToggled:)]; | 339 [checkbox setAction:@selector(onCheckboxToggled:)]; |
| 299 [checkboxes_ addObject:checkbox]; | 340 [checkboxes_ addObject:checkbox]; |
| 300 | 341 |
| 301 // TODO(gbillock): Would be nice to add middle text elide behavior here. | 342 // TODO(gbillock): Would be nice to add middle text elide behavior here. |
| 302 [checkbox setTitle:base::SysUTF16ToNSString( | 343 [checkbox setTitle:base::SysUTF16ToNSString( |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 | 381 |
| 341 void MediaGalleriesDialogCocoa::UpdateGalleries() { | 382 void MediaGalleriesDialogCocoa::UpdateGalleries() { |
| 342 InitDialogControls(); | 383 InitDialogControls(); |
| 343 } | 384 } |
| 344 | 385 |
| 345 void MediaGalleriesDialogCocoa::OnConstrainedWindowClosed( | 386 void MediaGalleriesDialogCocoa::OnConstrainedWindowClosed( |
| 346 ConstrainedWindowMac* window) { | 387 ConstrainedWindowMac* window) { |
| 347 controller_->DialogFinished(accepted_); | 388 controller_->DialogFinished(accepted_); |
| 348 } | 389 } |
| 349 | 390 |
| 391 ui::MenuModel* MediaGalleriesDialogCocoa::GetContextMenuModel( |
| 392 MediaGalleryPrefId prefid) { |
| 393 return controller_->GetContextMenuModel(prefid); |
| 394 } |
| 395 |
| 350 // static | 396 // static |
| 351 MediaGalleriesDialog* MediaGalleriesDialog::Create( | 397 MediaGalleriesDialog* MediaGalleriesDialog::Create( |
| 352 MediaGalleriesDialogController* controller) { | 398 MediaGalleriesDialogController* controller) { |
| 353 base::scoped_nsobject<MediaGalleriesCocoaController> cocoa_controller( | 399 base::scoped_nsobject<MediaGalleriesCocoaController> cocoa_controller( |
| 354 [[MediaGalleriesCocoaController alloc] init]); | 400 [[MediaGalleriesCocoaController alloc] init]); |
| 355 return new MediaGalleriesDialogCocoa(controller, cocoa_controller); | 401 return new MediaGalleriesDialogCocoa(controller, cocoa_controller); |
| 356 } | 402 } |
| OLD | NEW |