Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/permission_bubble/permission_bubble_controller. h" | 5 #import "chrome/browser/ui/cocoa/permission_bubble/permission_bubble_controller. h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/mac/bind_objc_block.h" | 9 #include "base/mac/bind_objc_block.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 24 #import "chrome/browser/ui/cocoa/info_bubble_window.h" | 24 #import "chrome/browser/ui/cocoa/info_bubble_window.h" |
| 25 #import "chrome/browser/ui/cocoa/location_bar/location_bar_decoration.h" | 25 #import "chrome/browser/ui/cocoa/location_bar/location_bar_decoration.h" |
| 26 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" | 26 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" |
| 27 #include "chrome/browser/ui/cocoa/page_info/page_info_utils_cocoa.h" | 27 #include "chrome/browser/ui/cocoa/page_info/page_info_utils_cocoa.h" |
| 28 #include "chrome/browser/ui/cocoa/page_info/permission_selector_button.h" | 28 #include "chrome/browser/ui/cocoa/page_info/permission_selector_button.h" |
| 29 #include "chrome/browser/ui/cocoa/page_info/split_block_button.h" | 29 #include "chrome/browser/ui/cocoa/page_info/split_block_button.h" |
| 30 #include "chrome/browser/ui/cocoa/permission_bubble/permission_bubble_cocoa.h" | 30 #include "chrome/browser/ui/cocoa/permission_bubble/permission_bubble_cocoa.h" |
| 31 #include "chrome/browser/ui/exclusive_access/exclusive_access_context.h" | 31 #include "chrome/browser/ui/exclusive_access/exclusive_access_context.h" |
| 32 #include "chrome/browser/ui/exclusive_access/exclusive_access_manager.h" | 32 #include "chrome/browser/ui/exclusive_access/exclusive_access_manager.h" |
| 33 #include "chrome/browser/ui/exclusive_access/fullscreen_controller.h" | 33 #include "chrome/browser/ui/exclusive_access/fullscreen_controller.h" |
| 34 #include "chrome/browser/ui/page_info/permission_menu_model.h" | |
| 35 #include "chrome/browser/ui/permission_bubble/permission_prompt.h" | 34 #include "chrome/browser/ui/permission_bubble/permission_prompt.h" |
| 36 #include "chrome/common/pref_names.h" | 35 #include "chrome/common/pref_names.h" |
| 37 #include "chrome/grit/generated_resources.h" | 36 #include "chrome/grit/generated_resources.h" |
| 38 #include "components/prefs/pref_service.h" | 37 #include "components/prefs/pref_service.h" |
| 39 #include "components/strings/grit/components_strings.h" | 38 #include "components/strings/grit/components_strings.h" |
| 40 #include "components/url_formatter/elide_url.h" | 39 #include "components/url_formatter/elide_url.h" |
| 41 #include "content/public/browser/native_web_keyboard_event.h" | 40 #include "content/public/browser/native_web_keyboard_event.h" |
| 42 #include "skia/ext/skia_utils_mac.h" | 41 #include "skia/ext/skia_utils_mac.h" |
| 43 #include "ui/base/cocoa/a11y_util.h" | 42 #include "ui/base/cocoa/a11y_util.h" |
| 44 #include "ui/base/cocoa/cocoa_base_utils.h" | 43 #include "ui/base/cocoa/cocoa_base_utils.h" |
| 45 #import "ui/base/cocoa/controls/hyperlink_text_view.h" | 44 #import "ui/base/cocoa/controls/hyperlink_text_view.h" |
| 46 #import "ui/base/cocoa/menu_controller.h" | |
| 47 #include "ui/base/cocoa/window_size_constants.h" | 45 #include "ui/base/cocoa/window_size_constants.h" |
| 48 #include "ui/base/l10n/l10n_util_mac.h" | 46 #include "ui/base/l10n/l10n_util_mac.h" |
| 49 #include "ui/base/models/simple_menu_model.h" | |
| 50 #include "ui/gfx/color_palette.h" | 47 #include "ui/gfx/color_palette.h" |
| 51 #include "ui/gfx/image/image_skia_util_mac.h" | 48 #include "ui/gfx/image/image_skia_util_mac.h" |
| 52 #include "ui/gfx/paint_vector_icon.h" | 49 #include "ui/gfx/paint_vector_icon.h" |
| 53 #include "url/gurl.h" | 50 #include "url/gurl.h" |
| 54 | 51 |
| 55 using base::UserMetricsAction; | 52 using base::UserMetricsAction; |
| 56 | 53 |
| 57 namespace { | 54 namespace { |
| 58 | 55 |
| 59 // Distance between permission icon and permission label. | 56 // Distance between permission icon and permission label. |
| 60 const CGFloat kHorizontalIconPadding = 8.0f; | 57 const CGFloat kHorizontalIconPadding = 8.0f; |
| 61 | 58 |
| 62 // Distance between two permission labels. | 59 // Distance between two permission labels. |
| 63 const CGFloat kVerticalPermissionPadding = 2.0f; | 60 const CGFloat kVerticalPermissionPadding = 2.0f; |
| 64 | 61 |
| 65 const CGFloat kHorizontalPadding = 13.0f; | 62 const CGFloat kHorizontalPadding = 13.0f; |
| 66 const CGFloat kVerticalPadding = 15.0f; | 63 const CGFloat kVerticalPadding = 15.0f; |
| 67 const CGFloat kBetweenButtonsPadding = 10.0f; | 64 const CGFloat kBetweenButtonsPadding = 10.0f; |
| 68 const CGFloat kButtonRightEdgePadding = 17.0f; | 65 const CGFloat kButtonRightEdgePadding = 17.0f; |
| 69 const CGFloat kTitlePaddingX = 50.0f; | 66 const CGFloat kTitlePaddingX = 50.0f; |
| 70 const CGFloat kBubbleMinWidth = 315.0f; | 67 const CGFloat kBubbleMinWidth = 315.0f; |
| 71 const NSSize kPermissionIconSize = {18, 18}; | 68 const NSSize kPermissionIconSize = {18, 18}; |
| 72 | 69 |
| 73 } // namespace | 70 } // namespace |
| 74 | 71 |
| 75 // NSPopUpButton with a menu containing two items: allow and block. | |
| 76 // One AllowBlockMenuButton is used for each requested permission when there are | |
| 77 // multiple permissions in the bubble. | |
| 78 @interface AllowBlockMenuButton : NSPopUpButton { | |
| 79 @private | |
| 80 std::unique_ptr<PermissionMenuModel> menuModel_; | |
| 81 base::scoped_nsobject<MenuController> menuController_; | |
| 82 } | |
| 83 | |
| 84 - (id)initForURL:(const GURL&)url | |
| 85 allowed:(BOOL)allow | |
| 86 index:(int)index | |
| 87 delegate:(PermissionPrompt::Delegate*)delegate | |
| 88 profile:(Profile*)profile; | |
| 89 | |
| 90 // Returns the maximum width of its possible titles. | |
| 91 - (CGFloat)maximumTitleWidth; | |
| 92 @end | |
| 93 | |
| 94 @implementation AllowBlockMenuButton | |
| 95 | |
| 96 - (id)initForURL:(const GURL&)url | |
| 97 allowed:(BOOL)allow | |
| 98 index:(int)index | |
| 99 delegate:(PermissionPrompt::Delegate*)delegate | |
| 100 profile:(Profile*)profile { | |
| 101 if (self = [super initWithFrame:NSZeroRect pullsDown:NO]) { | |
| 102 ContentSetting setting = | |
| 103 allow ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; | |
| 104 [self setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; | |
| 105 [self setBordered:NO]; | |
| 106 | |
| 107 __block PermissionPrompt::Delegate* blockDelegate = delegate; | |
| 108 __block AllowBlockMenuButton* blockSelf = self; | |
| 109 PermissionMenuModel::ChangeCallback changeCallback = | |
| 110 base::BindBlock(^(const PageInfoUI::PermissionInfo& permission) { | |
| 111 blockDelegate->ToggleAccept( | |
| 112 index, permission.setting == CONTENT_SETTING_ALLOW); | |
| 113 [blockSelf setFrameSize:SizeForPageInfoButtonTitle( | |
| 114 blockSelf, [blockSelf title])]; | |
| 115 }); | |
| 116 | |
| 117 menuModel_.reset( | |
| 118 new PermissionMenuModel(profile, url, setting, changeCallback)); | |
| 119 menuController_.reset([[MenuController alloc] initWithModel:menuModel_.get() | |
| 120 useWithPopUpButtonCell:NO]); | |
| 121 [self setMenu:[menuController_ menu]]; | |
| 122 [self selectItemAtIndex:menuModel_->GetIndexOfCommandId(setting)]; | |
| 123 // Although the frame is reset, below, this sizes the cell properly. | |
| 124 [self sizeToFit]; | |
| 125 // Adjust the size to fit the current title. Using only -sizeToFit leaves | |
| 126 // an ugly amount of whitespace between the title and the arrows because it | |
| 127 // will fit to the largest element in the menu, not just the selected item. | |
| 128 [self setFrameSize:SizeForPageInfoButtonTitle(self, [self title])]; | |
| 129 } | |
| 130 return self; | |
| 131 } | |
| 132 | |
| 133 - (CGFloat)maximumTitleWidth { | |
| 134 CGFloat maxTitleWidth = 0; | |
| 135 for (NSMenuItem* item in [self itemArray]) { | |
| 136 NSSize size = SizeForPageInfoButtonTitle(self, [item title]); | |
| 137 maxTitleWidth = std::max(maxTitleWidth, size.width); | |
| 138 } | |
| 139 return maxTitleWidth; | |
| 140 } | |
| 141 | |
| 142 @end | |
| 143 | |
| 144 @interface PermissionBubbleController () | 72 @interface PermissionBubbleController () |
| 145 | 73 |
| 146 // Determines if the bubble has an anchor in a corner or no anchor at all. | 74 // Determines if the bubble has an anchor in a corner or no anchor at all. |
| 147 - (info_bubble::BubbleArrowLocation)getExpectedArrowLocation; | 75 - (info_bubble::BubbleArrowLocation)getExpectedArrowLocation; |
| 148 | 76 |
| 149 // Returns the expected parent for this bubble. | 77 // Returns the expected parent for this bubble. |
| 150 - (NSWindow*)getExpectedParentWindow; | 78 - (NSWindow*)getExpectedParentWindow; |
| 151 | 79 |
| 152 // Returns an autoreleased NSView displaying the icon and label for |request|. | 80 // Returns an autoreleased NSView displaying the icon and label for |request|. |
| 153 - (NSView*)labelForRequest:(PermissionRequest*)request; | 81 - (NSView*)labelForRequest:(PermissionRequest*)request; |
| 154 | 82 |
| 155 // Returns an autoreleased NSView displaying the title for the bubble | 83 // Returns an autoreleased NSView displaying the title for the bubble |
| 156 // requesting settings for |host|. | 84 // requesting settings for |host|. |
| 157 - (NSView*)titleWithOrigin:(const GURL&)origin; | 85 - (NSView*)titleWithOrigin:(const GURL&)origin; |
| 158 | 86 |
| 159 // Returns an autoreleased NSView displaying a menu for |request|. The | |
| 160 // menu will be initialized as 'allow' if |allow| is YES. | |
| 161 - (NSView*)menuForRequest:(PermissionRequest*)request | |
| 162 atIndex:(int)index | |
| 163 allow:(BOOL)allow; | |
| 164 | |
| 165 // Returns an autoreleased NSView of a button with |title| and |action|. | 87 // Returns an autoreleased NSView of a button with |title| and |action|. |
| 166 - (NSView*)buttonWithTitle:(NSString*)title | 88 - (NSView*)buttonWithTitle:(NSString*)title |
| 167 action:(SEL)action; | 89 action:(SEL)action; |
| 168 | 90 |
| 169 // Returns an autoreleased NSView displaying a block button. | 91 // Returns an autoreleased NSView displaying a block button. |
| 170 - (NSView*)blockButton; | 92 - (NSView*)blockButton; |
| 171 | 93 |
| 172 // Returns an autoreleased NSView displaying the close 'x' button. | 94 // Returns an autoreleased NSView displaying the close 'x' button. |
| 173 - (NSView*)closeButton; | 95 - (NSView*)closeButton; |
| 174 | 96 |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 284 - (void)showWithDelegate:(PermissionPrompt::Delegate*)delegate { | 206 - (void)showWithDelegate:(PermissionPrompt::Delegate*)delegate { |
| 285 DCHECK(delegate); | 207 DCHECK(delegate); |
| 286 delegate_ = delegate; | 208 delegate_ = delegate; |
| 287 | 209 |
| 288 const std::vector<PermissionRequest*>& requests = delegate->Requests(); | 210 const std::vector<PermissionRequest*>& requests = delegate->Requests(); |
| 289 DCHECK(!requests.empty()); | 211 DCHECK(!requests.empty()); |
| 290 | 212 |
| 291 NSView* contentView = [[self window] contentView]; | 213 NSView* contentView = [[self window] contentView]; |
| 292 [contentView setSubviews:@[]]; | 214 [contentView setSubviews:@[]]; |
| 293 | 215 |
| 294 BOOL singlePermission = requests.size() == 1; | |
| 295 | |
| 296 // Create one button to use as a guide for the permissions' y-offsets. | 216 // Create one button to use as a guide for the permissions' y-offsets. |
| 297 base::scoped_nsobject<NSView> allowOrOkButton; | 217 NSString* allowTitle = l10n_util::GetNSString(IDS_PERMISSION_ALLOW); |
| 298 if (singlePermission) { | 218 base::scoped_nsobject<NSView> allowButton( |
| 299 NSString* allowTitle = l10n_util::GetNSString(IDS_PERMISSION_ALLOW); | 219 [[self buttonWithTitle:allowTitle action:@selector(onAllow:)] retain]); |
| 300 allowOrOkButton.reset([[self buttonWithTitle:allowTitle | 220 CGFloat yOffset = 2 * kVerticalPadding + NSMaxY([allowButton frame]); |
| 301 action:@selector(onAllow:)] retain]); | |
| 302 } else { | |
| 303 NSString* okTitle = l10n_util::GetNSString(IDS_OK); | |
| 304 allowOrOkButton.reset([[self buttonWithTitle:okTitle | |
| 305 action:@selector(ok:)] retain]); | |
| 306 } | |
| 307 CGFloat yOffset = 2 * kVerticalPadding + NSMaxY([allowOrOkButton frame]); | |
| 308 | |
| 309 base::scoped_nsobject<NSMutableArray> permissionMenus; | |
| 310 if (!singlePermission) | |
| 311 permissionMenus.reset([[NSMutableArray alloc] init]); | |
| 312 | 221 |
| 313 CGFloat maxPermissionLineWidth = 0; | 222 CGFloat maxPermissionLineWidth = 0; |
| 314 CGFloat verticalPadding = 0.0f; | 223 CGFloat verticalPadding = 0.0f; |
| 315 for (auto it = requests.begin(); it != requests.end(); it++) { | 224 for (auto it = requests.begin(); it != requests.end(); it++) { |
| 316 base::scoped_nsobject<NSView> permissionView( | 225 base::scoped_nsobject<NSView> permissionView( |
| 317 [[self labelForRequest:(*it)] retain]); | 226 [[self labelForRequest:(*it)] retain]); |
| 318 NSPoint origin = [permissionView frame].origin; | 227 NSPoint origin = [permissionView frame].origin; |
| 319 origin.x += kHorizontalPadding; | 228 origin.x += kHorizontalPadding; |
| 320 origin.y += yOffset + verticalPadding; | 229 origin.y += yOffset + verticalPadding; |
| 321 [permissionView setFrameOrigin:origin]; | 230 [permissionView setFrameOrigin:origin]; |
| 322 [contentView addSubview:permissionView]; | 231 [contentView addSubview:permissionView]; |
| 323 | 232 |
| 324 if (!singlePermission) { | |
| 325 int index = it - requests.begin(); | |
| 326 base::scoped_nsobject<NSView> menu([[self | |
| 327 menuForRequest:(*it)atIndex:index | |
| 328 allow:delegate->AcceptStates()[index] ? YES : NO] retain]); | |
| 329 // Align vertically. Horizontal alignment will be adjusted once the | |
| 330 // widest permission is know. | |
| 331 [PermissionBubbleController alignCenterOf:menu | |
| 332 verticallyToCenterOf:permissionView]; | |
| 333 [permissionMenus addObject:menu]; | |
| 334 [contentView addSubview:menu]; | |
| 335 } | |
| 336 maxPermissionLineWidth = std::max( | 233 maxPermissionLineWidth = std::max( |
| 337 maxPermissionLineWidth, NSMaxX([permissionView frame])); | 234 maxPermissionLineWidth, NSMaxX([permissionView frame])); |
| 338 yOffset += NSHeight([permissionView frame]); | 235 yOffset += NSHeight([permissionView frame]); |
| 339 | 236 |
| 340 // Add extra padding for all but first permission. | 237 // Add extra padding for all but first permission. |
| 341 verticalPadding = kVerticalPermissionPadding; | 238 verticalPadding = kVerticalPermissionPadding; |
| 342 } | 239 } |
| 343 | 240 |
| 344 base::scoped_nsobject<NSView> titleView( | 241 base::scoped_nsobject<NSView> titleView( |
| 345 [[self titleWithOrigin:requests[0]->GetOrigin()] retain]); | 242 [[self titleWithOrigin:requests[0]->GetOrigin()] retain]); |
| 346 [contentView addSubview:titleView]; | 243 [contentView addSubview:titleView]; |
| 347 [titleView setFrameOrigin:NSMakePoint(kHorizontalPadding, | 244 [titleView setFrameOrigin:NSMakePoint(kHorizontalPadding, |
| 348 kVerticalPadding + yOffset)]; | 245 kVerticalPadding + yOffset)]; |
| 349 | 246 |
| 350 // 'x' button in the upper-right-hand corner. | 247 // 'x' button in the upper-right-hand corner. |
| 351 base::scoped_nsobject<NSView> closeButton([[self closeButton] retain]); | 248 base::scoped_nsobject<NSView> closeButton([[self closeButton] retain]); |
| 352 | 249 |
| 353 // Determine the dimensions of the bubble. | 250 // Determine the dimensions of the bubble. |
| 354 // Once the height and width are set, the buttons and permission menus can | 251 // Once the height and width are set, the buttons can be laid out correctly. |
| 355 // be laid out correctly. | |
| 356 NSRect bubbleFrame = NSMakeRect(0, 0, kBubbleMinWidth, 0); | 252 NSRect bubbleFrame = NSMakeRect(0, 0, kBubbleMinWidth, 0); |
| 357 | 253 |
| 358 // Fix the height of the bubble relative to the title. | 254 // Fix the height of the bubble relative to the title. |
| 359 bubbleFrame.size.height = NSMaxY([titleView frame]) + kVerticalPadding + | 255 bubbleFrame.size.height = NSMaxY([titleView frame]) + kVerticalPadding + |
| 360 info_bubble::kBubbleArrowHeight; | 256 info_bubble::kBubbleArrowHeight; |
| 361 | 257 |
| 362 if (!singlePermission) { | |
| 363 // Add the maximum menu width to the bubble width. | |
| 364 CGFloat maxMenuWidth = 0; | |
| 365 for (AllowBlockMenuButton* button in permissionMenus.get()) { | |
| 366 maxMenuWidth = std::max(maxMenuWidth, [button maximumTitleWidth]); | |
| 367 } | |
| 368 maxPermissionLineWidth += maxMenuWidth; | |
| 369 } | |
| 370 | |
| 371 // The title and 'x' button row must fit within the bubble. | 258 // The title and 'x' button row must fit within the bubble. |
| 372 CGFloat titleRowWidth = NSMaxX([titleView frame]) + | 259 CGFloat titleRowWidth = NSMaxX([titleView frame]) + |
| 373 NSWidth([closeButton frame]) + | 260 NSWidth([closeButton frame]) + |
| 374 chrome_style::kCloseButtonPadding; | 261 chrome_style::kCloseButtonPadding; |
| 375 | 262 |
| 376 bubbleFrame.size.width = | 263 bubbleFrame.size.width = |
| 377 std::max(NSWidth(bubbleFrame), | 264 std::max(NSWidth(bubbleFrame), |
| 378 std::max(titleRowWidth, maxPermissionLineWidth)) + | 265 std::max(titleRowWidth, maxPermissionLineWidth)) + |
| 379 kHorizontalPadding; | 266 kHorizontalPadding; |
| 380 | 267 |
| 381 // Now that the bubble's dimensions have been set, lay out the buttons and | 268 // Now that the bubble's dimensions have been set, lay out the buttons. |
| 382 // menus. | |
| 383 | 269 |
| 384 // Place the close button at the upper-right-hand corner of the bubble. | 270 // Place the close button at the upper-right-hand corner of the bubble. |
| 385 NSPoint closeButtonOrigin = | 271 NSPoint closeButtonOrigin = |
| 386 NSMakePoint(NSWidth(bubbleFrame) - NSWidth([closeButton frame]) - | 272 NSMakePoint(NSWidth(bubbleFrame) - NSWidth([closeButton frame]) - |
| 387 chrome_style::kCloseButtonPadding, | 273 chrome_style::kCloseButtonPadding, |
| 388 NSHeight(bubbleFrame) - NSWidth([closeButton frame]) - | 274 NSHeight(bubbleFrame) - NSWidth([closeButton frame]) - |
| 389 chrome_style::kCloseButtonPadding); | 275 chrome_style::kCloseButtonPadding); |
| 390 // Account for the bubble's arrow. | 276 // Account for the bubble's arrow. |
| 391 closeButtonOrigin.y -= info_bubble::kBubbleArrowHeight; | 277 closeButtonOrigin.y -= info_bubble::kBubbleArrowHeight; |
| 392 | 278 |
| 393 [closeButton setFrameOrigin:closeButtonOrigin]; | 279 [closeButton setFrameOrigin:closeButtonOrigin]; |
| 394 [contentView addSubview:closeButton]; | 280 [contentView addSubview:closeButton]; |
| 395 | 281 |
| 396 // Position the allow/ok button. | 282 // Position the allow/ok button. |
| 397 CGFloat xOrigin = NSWidth(bubbleFrame) - NSWidth([allowOrOkButton frame]) - | 283 CGFloat xOrigin = NSWidth(bubbleFrame) - NSWidth([allowButton frame]) - |
| 398 kButtonRightEdgePadding; | 284 kButtonRightEdgePadding; |
| 399 [allowOrOkButton setFrameOrigin:NSMakePoint(xOrigin, kVerticalPadding)]; | 285 [allowButton setFrameOrigin:NSMakePoint(xOrigin, kVerticalPadding)]; |
| 400 [contentView addSubview:allowOrOkButton]; | 286 [contentView addSubview:allowButton]; |
| 401 | 287 |
| 402 if (singlePermission) { | 288 base::scoped_nsobject<NSView> blockButton; |
| 403 base::scoped_nsobject<NSView> blockButton; | 289 blockButton.reset([[self blockButton] retain]); |
|
tapted
2017/06/06 08:06:03
Hrm. It's weird to make this scoped_nsobject - the
| |
| 404 blockButton.reset([[self blockButton] retain]); | 290 CGFloat width = |
| 405 CGFloat width = [PermissionBubbleController matchWidthsOf:blockButton | 291 [PermissionBubbleController matchWidthsOf:blockButton andOf:allowButton]; |
| 406 andOf:allowOrOkButton]; | 292 // Ensure the allow/ok button is still in the correct position. |
| 407 // Ensure the allow/ok button is still in the correct position. | 293 xOrigin = NSWidth(bubbleFrame) - width - kHorizontalPadding; |
| 408 xOrigin = NSWidth(bubbleFrame) - width - kHorizontalPadding; | 294 [allowButton setFrameOrigin:NSMakePoint(xOrigin, kVerticalPadding)]; |
| 409 [allowOrOkButton setFrameOrigin:NSMakePoint(xOrigin, kVerticalPadding)]; | 295 // Line up the block button. |
| 410 // Line up the block button. | 296 xOrigin = NSMinX([allowButton frame]) - width - kBetweenButtonsPadding; |
| 411 xOrigin = NSMinX([allowOrOkButton frame]) - width - kBetweenButtonsPadding; | 297 [blockButton setFrameOrigin:NSMakePoint(xOrigin, kVerticalPadding)]; |
| 412 [blockButton setFrameOrigin:NSMakePoint(xOrigin, kVerticalPadding)]; | 298 [contentView addSubview:blockButton]; |
| 413 [contentView addSubview:blockButton]; | |
| 414 } else { | |
| 415 // Adjust the horizontal origin for each menu so that its right edge | |
| 416 // lines up with the right edge of the ok button. | |
| 417 CGFloat rightEdge = NSMaxX([allowOrOkButton frame]); | |
| 418 for (NSView* view in permissionMenus.get()) { | |
| 419 [view setFrameOrigin:NSMakePoint(rightEdge - NSWidth([view frame]), | |
| 420 NSMinY([view frame]))]; | |
| 421 } | |
| 422 } | |
| 423 | 299 |
| 424 bubbleFrame = [[self window] frameRectForContentRect:bubbleFrame]; | 300 bubbleFrame = [[self window] frameRectForContentRect:bubbleFrame]; |
| 425 if ([[self window] isVisible]) { | 301 if ([[self window] isVisible]) { |
| 426 // Unfortunately, calling -setFrame followed by -setFrameOrigin (called | 302 // Unfortunately, calling -setFrame followed by -setFrameOrigin (called |
| 427 // within -setAnchorPoint) causes flickering. Avoid the flickering by | 303 // within -setAnchorPoint) causes flickering. Avoid the flickering by |
| 428 // manually adjusting the new frame's origin so that the top left stays the | 304 // manually adjusting the new frame's origin so that the top left stays the |
| 429 // same, and only calling -setFrame. | 305 // same, and only calling -setFrame. |
| 430 NSRect currentWindowFrame = [[self window] frame]; | 306 NSRect currentWindowFrame = [[self window] frame]; |
| 431 bubbleFrame.origin = currentWindowFrame.origin; | 307 bubbleFrame.origin = currentWindowFrame.origin; |
| 432 bubbleFrame.origin.y = bubbleFrame.origin.y + | 308 bubbleFrame.origin.y = bubbleFrame.origin.y + |
| 433 currentWindowFrame.size.height - bubbleFrame.size.height; | 309 currentWindowFrame.size.height - bubbleFrame.size.height; |
| 434 [[self window] setFrame:bubbleFrame display:YES]; | 310 [[self window] setFrame:bubbleFrame display:YES]; |
| 435 } else { | 311 } else { |
| 436 [[self window] setFrame:bubbleFrame display:NO]; | 312 [[self window] setFrame:bubbleFrame display:NO]; |
| 437 [self setAnchorPoint:[self getExpectedAnchorPoint]]; | 313 [self setAnchorPoint:[self getExpectedAnchorPoint]]; |
| 438 [self showWindow:nil]; | 314 [self showWindow:nil]; |
| 439 [[self window] makeFirstResponder:nil]; | 315 [[self window] makeFirstResponder:nil]; |
| 440 [[self window] setInitialFirstResponder:allowOrOkButton.get()]; | 316 [[self window] setInitialFirstResponder:allowButton.get()]; |
| 441 } | 317 } |
| 442 } | 318 } |
| 443 | 319 |
| 444 - (void)updateAnchorPosition { | 320 - (void)updateAnchorPosition { |
| 445 [self setParentWindow:[self getExpectedParentWindow]]; | 321 [self setParentWindow:[self getExpectedParentWindow]]; |
| 446 [self setAnchorPoint:[self getExpectedAnchorPoint]]; | 322 [self setAnchorPoint:[self getExpectedAnchorPoint]]; |
| 447 [[self bubble] setArrowLocation:[self getExpectedArrowLocation]]; | 323 [[self bubble] setArrowLocation:[self getExpectedArrowLocation]]; |
| 448 } | 324 } |
| 449 | 325 |
| 450 - (NSPoint)getExpectedAnchorPoint { | 326 - (NSPoint)getExpectedAnchorPoint { |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 525 origin, url_formatter::SchemeDisplay:: | 401 origin, url_formatter::SchemeDisplay:: |
| 526 OMIT_CRYPTOGRAPHIC))]; | 402 OMIT_CRYPTOGRAPHIC))]; |
| 527 [titleView setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; | 403 [titleView setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; |
| 528 [titleView sizeToFit]; | 404 [titleView sizeToFit]; |
| 529 NSRect titleFrame = [titleView frame]; | 405 NSRect titleFrame = [titleView frame]; |
| 530 [titleView setFrameSize:NSMakeSize(NSWidth(titleFrame) + kTitlePaddingX, | 406 [titleView setFrameSize:NSMakeSize(NSWidth(titleFrame) + kTitlePaddingX, |
| 531 NSHeight(titleFrame))]; | 407 NSHeight(titleFrame))]; |
| 532 return titleView.autorelease(); | 408 return titleView.autorelease(); |
| 533 } | 409 } |
| 534 | 410 |
| 535 - (NSView*)menuForRequest:(PermissionRequest*)request | |
| 536 atIndex:(int)index | |
| 537 allow:(BOOL)allow { | |
| 538 DCHECK(request); | |
| 539 DCHECK(delegate_); | |
| 540 base::scoped_nsobject<AllowBlockMenuButton> button( | |
| 541 [[AllowBlockMenuButton alloc] initForURL:request->GetOrigin() | |
| 542 allowed:allow | |
| 543 index:index | |
| 544 delegate:delegate_ | |
| 545 profile:browser_->profile()]); | |
| 546 return button.autorelease(); | |
| 547 } | |
| 548 | |
| 549 - (NSView*)buttonWithTitle:(NSString*)title | 411 - (NSView*)buttonWithTitle:(NSString*)title |
| 550 action:(SEL)action { | 412 action:(SEL)action { |
| 551 base::scoped_nsobject<NSButton> button( | 413 base::scoped_nsobject<NSButton> button( |
| 552 [[ConstrainedWindowButton alloc] initWithFrame:NSZeroRect]); | 414 [[ConstrainedWindowButton alloc] initWithFrame:NSZeroRect]); |
| 553 [button setButtonType:NSMomentaryPushInButton]; | 415 [button setButtonType:NSMomentaryPushInButton]; |
| 554 [button setTitle:title]; | 416 [button setTitle:title]; |
| 555 [button setTarget:self]; | 417 [button setTarget:self]; |
| 556 [button setAction:action]; | 418 [button setAction:action]; |
| 557 [button sizeToFit]; | 419 [button sizeToFit]; |
| 558 return button.autorelease(); | 420 return button.autorelease(); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 620 } | 482 } |
| 621 | 483 |
| 622 - (IBAction)cancel:(id)sender { | 484 - (IBAction)cancel:(id)sender { |
| 623 // This is triggered by ESC when the bubble has focus. | 485 // This is triggered by ESC when the bubble has focus. |
| 624 if (delegate_) | 486 if (delegate_) |
| 625 delegate_->Closing(); | 487 delegate_->Closing(); |
| 626 [super cancel:sender]; | 488 [super cancel:sender]; |
| 627 } | 489 } |
| 628 | 490 |
| 629 @end // implementation PermissionBubbleController | 491 @end // implementation PermissionBubbleController |
| OLD | NEW |