| 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 #import "chrome/browser/ui/cocoa/content_settings/content_setting_bubble_cocoa.h
" | 5 #import "chrome/browser/ui/cocoa/content_settings/content_setting_bubble_cocoa.h
" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "base/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 NSTextField* LabelWithFrame(NSString* text, const NSRect& frame) { | 83 NSTextField* LabelWithFrame(NSString* text, const NSRect& frame) { |
| 84 NSTextField* label = [[NSTextField alloc] initWithFrame:frame]; | 84 NSTextField* label = [[NSTextField alloc] initWithFrame:frame]; |
| 85 [label setStringValue:text]; | 85 [label setStringValue:text]; |
| 86 [label setSelectable:NO]; | 86 [label setSelectable:NO]; |
| 87 [label setBezeled:NO]; | 87 [label setBezeled:NO]; |
| 88 return [label autorelease]; | 88 return [label autorelease]; |
| 89 } | 89 } |
| 90 | 90 |
| 91 // Sets the title for the popup button. | 91 // Sets the title for the popup button. |
| 92 void SetTitleForPopUpButton(NSPopUpButton* button, NSString* title) { | 92 void SetTitleForPopUpButton(NSPopUpButton* button, NSString* title) { |
| 93 scoped_nsobject<NSMenuItem> titleItem([[NSMenuItem alloc] init]); | 93 base::scoped_nsobject<NSMenuItem> titleItem([[NSMenuItem alloc] init]); |
| 94 [titleItem setTitle:title]; | 94 [titleItem setTitle:title]; |
| 95 [[button cell] setUsesItemFromMenu:NO]; | 95 [[button cell] setUsesItemFromMenu:NO]; |
| 96 [[button cell] setMenuItem:titleItem.get()]; | 96 [[button cell] setMenuItem:titleItem.get()]; |
| 97 } | 97 } |
| 98 | 98 |
| 99 // Builds the popup button menu from the menu model and returns the width of the | 99 // Builds the popup button menu from the menu model and returns the width of the |
| 100 // longgest item as the width of the popup menu. | 100 // longgest item as the width of the popup menu. |
| 101 CGFloat BuildPopUpMenuFromModel(NSPopUpButton* button, | 101 CGFloat BuildPopUpMenuFromModel(NSPopUpButton* button, |
| 102 ContentSettingMediaMenuModel* model, | 102 ContentSettingMediaMenuModel* model, |
| 103 const std::string& title) { | 103 const std::string& title) { |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 sizeToFitView:allowBlockRadioGroup_].height; | 286 sizeToFitView:allowBlockRadioGroup_].height; |
| 287 NSRect windowFrame = [[self window] frame]; | 287 NSRect windowFrame = [[self window] frame]; |
| 288 windowFrame.size.height += radioDeltaY; | 288 windowFrame.size.height += radioDeltaY; |
| 289 [[self window] setFrame:windowFrame display:NO]; | 289 [[self window] setFrame:windowFrame display:NO]; |
| 290 } | 290 } |
| 291 | 291 |
| 292 - (NSButton*)hyperlinkButtonWithFrame:(NSRect)frame | 292 - (NSButton*)hyperlinkButtonWithFrame:(NSRect)frame |
| 293 title:(NSString*)title | 293 title:(NSString*)title |
| 294 icon:(NSImage*)icon | 294 icon:(NSImage*)icon |
| 295 referenceFrame:(NSRect)referenceFrame { | 295 referenceFrame:(NSRect)referenceFrame { |
| 296 scoped_nsobject<HyperlinkButtonCell> cell([[HyperlinkButtonCell alloc] | 296 base::scoped_nsobject<HyperlinkButtonCell> cell( |
| 297 initTextCell:title]); | 297 [[HyperlinkButtonCell alloc] initTextCell:title]); |
| 298 [cell.get() setAlignment:NSNaturalTextAlignment]; | 298 [cell.get() setAlignment:NSNaturalTextAlignment]; |
| 299 if (icon) { | 299 if (icon) { |
| 300 [cell.get() setImagePosition:NSImageLeft]; | 300 [cell.get() setImagePosition:NSImageLeft]; |
| 301 [cell.get() setImage:icon]; | 301 [cell.get() setImage:icon]; |
| 302 } else { | 302 } else { |
| 303 [cell.get() setImagePosition:NSNoImage]; | 303 [cell.get() setImagePosition:NSNoImage]; |
| 304 } | 304 } |
| 305 [cell.get() setControlSize:NSSmallControlSize]; | 305 [cell.get() setControlSize:NSSmallControlSize]; |
| 306 | 306 |
| 307 NSButton* button = [[[NSButton alloc] initWithFrame:frame] autorelease]; | 307 NSButton* button = [[[NSButton alloc] initWithFrame:frame] autorelease]; |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 // Cocoa has its origin in the lower left corner. This means elements are | 403 // Cocoa has its origin in the lower left corner. This means elements are |
| 404 // added from bottom to top, which explains why loops run backwards and the | 404 // added from bottom to top, which explains why loops run backwards and the |
| 405 // order of operations is the other way than on Linux/Windows. | 405 // order of operations is the other way than on Linux/Windows. |
| 406 const ContentSettingBubbleModel::BubbleContent& content = | 406 const ContentSettingBubbleModel::BubbleContent& content = |
| 407 contentSettingBubbleModel_->bubble_content(); | 407 contentSettingBubbleModel_->bubble_content(); |
| 408 NSRect containerFrame = [contentsContainer_ frame]; | 408 NSRect containerFrame = [contentsContainer_ frame]; |
| 409 NSRect frame = NSMakeRect(0, 0, NSWidth(containerFrame), kGeoLabelHeight); | 409 NSRect frame = NSMakeRect(0, 0, NSWidth(containerFrame), kGeoLabelHeight); |
| 410 | 410 |
| 411 // "Clear" button / text field. | 411 // "Clear" button / text field. |
| 412 if (!content.custom_link.empty()) { | 412 if (!content.custom_link.empty()) { |
| 413 scoped_nsobject<NSControl> control; | 413 base::scoped_nsobject<NSControl> control; |
| 414 if(content.custom_link_enabled) { | 414 if(content.custom_link_enabled) { |
| 415 NSRect buttonFrame = NSMakeRect(0, 0, | 415 NSRect buttonFrame = NSMakeRect(0, 0, |
| 416 NSWidth(containerFrame), | 416 NSWidth(containerFrame), |
| 417 kGeoClearButtonHeight); | 417 kGeoClearButtonHeight); |
| 418 NSButton* button = [[NSButton alloc] initWithFrame:buttonFrame]; | 418 NSButton* button = [[NSButton alloc] initWithFrame:buttonFrame]; |
| 419 control.reset(button); | 419 control.reset(button); |
| 420 [button setTitle:base::SysUTF8ToNSString(content.custom_link)]; | 420 [button setTitle:base::SysUTF8ToNSString(content.custom_link)]; |
| 421 [button setTarget:self]; | 421 [button setTarget:self]; |
| 422 [button setAction:@selector(clearGeolocationForCurrentHost:)]; | 422 [button setAction:@selector(clearGeolocationForCurrentHost:)]; |
| 423 [button setBezelStyle:NSRoundRectBezelStyle]; | 423 [button setBezelStyle:NSRoundRectBezelStyle]; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 505 LabelWithFrame(base::SysUTF8ToNSString(it->second.label), labelFrame); | 505 LabelWithFrame(base::SysUTF8ToNSString(it->second.label), labelFrame); |
| 506 SetControlSize(label, NSSmallControlSize); | 506 SetControlSize(label, NSSmallControlSize); |
| 507 NSCell* cell = [label cell]; | 507 NSCell* cell = [label cell]; |
| 508 [cell setAlignment:NSRightTextAlignment]; | 508 [cell setAlignment:NSRightTextAlignment]; |
| 509 [GTMUILocalizerAndLayoutTweaker sizeToFitView:label]; | 509 [GTMUILocalizerAndLayoutTweaker sizeToFitView:label]; |
| 510 maxLabelWidth = std::max(maxLabelWidth, [label frame].size.width); | 510 maxLabelWidth = std::max(maxLabelWidth, [label frame].size.width); |
| 511 [[self bubble] addSubview:label]; | 511 [[self bubble] addSubview:label]; |
| 512 | 512 |
| 513 // |buttonFrame| will be resized and repositioned later on. | 513 // |buttonFrame| will be resized and repositioned later on. |
| 514 NSRect buttonFrame = NSMakeRect(NSMinX(radioFrame), 0, 0, 0); | 514 NSRect buttonFrame = NSMakeRect(NSMinX(radioFrame), 0, 0, 0); |
| 515 scoped_nsobject<NSPopUpButton> button( | 515 base::scoped_nsobject<NSPopUpButton> button( |
| 516 [[NSPopUpButton alloc] initWithFrame:buttonFrame]); | 516 [[NSPopUpButton alloc] initWithFrame:buttonFrame]); |
| 517 [button setTarget:self]; | 517 [button setTarget:self]; |
| 518 | 518 |
| 519 // Store the |label| and |button| into MediaMenuParts struct and build | 519 // Store the |label| and |button| into MediaMenuParts struct and build |
| 520 // the popup menu from the menu model. | 520 // the popup menu from the menu model. |
| 521 content_setting_bubble::MediaMenuParts* menuParts = | 521 content_setting_bubble::MediaMenuParts* menuParts = |
| 522 new content_setting_bubble::MediaMenuParts(it->first, label); | 522 new content_setting_bubble::MediaMenuParts(it->first, label); |
| 523 menuParts->model.reset(new ContentSettingMediaMenuModel( | 523 menuParts->model.reset(new ContentSettingMediaMenuModel( |
| 524 it->first, contentSettingBubbleModel_.get(), | 524 it->first, contentSettingBubbleModel_.get(), |
| 525 ContentSettingMediaMenuModel::MenuLabelChangedCallback())); | 525 ContentSettingMediaMenuModel::MenuLabelChangedCallback())); |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 692 button, base::SysUTF16ToNSString(it->second->model->GetLabelAt(index))); | 692 button, base::SysUTF16ToNSString(it->second->model->GetLabelAt(index))); |
| 693 | 693 |
| 694 it->second->model->ExecuteCommand(index, 0); | 694 it->second->model->ExecuteCommand(index, 0); |
| 695 } | 695 } |
| 696 | 696 |
| 697 - (content_setting_bubble::MediaMenuPartsMap*)mediaMenus { | 697 - (content_setting_bubble::MediaMenuPartsMap*)mediaMenus { |
| 698 return &mediaMenus_; | 698 return &mediaMenus_; |
| 699 } | 699 } |
| 700 | 700 |
| 701 @end // ContentSettingBubbleController | 701 @end // ContentSettingBubbleController |
| OLD | NEW |