| 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/website_settings/permission_bubble_controller.h
" | 5 #import "chrome/browser/ui/cocoa/website_settings/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/mac/foundation_util.h" | 10 #include "base/mac/foundation_util.h" |
| 11 #include "base/mac/mac_util.h" | 11 #include "base/mac/mac_util.h" |
| 12 #include "base/strings/sys_string_conversions.h" | 12 #include "base/strings/sys_string_conversions.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
| 15 #include "chrome/browser/ui/browser_finder.h" | 15 #include "chrome/browser/ui/browser_finder.h" |
| 16 #import "chrome/browser/ui/chrome_style.h" | 16 #import "chrome/browser/ui/chrome_style.h" |
| 17 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 17 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
| 18 #import "chrome/browser/ui/cocoa/browser_window_utils.h" |
| 18 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_button.h" | 19 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_button.h" |
| 19 #import "chrome/browser/ui/cocoa/hover_close_button.h" | 20 #import "chrome/browser/ui/cocoa/hover_close_button.h" |
| 20 #import "chrome/browser/ui/cocoa/hyperlink_text_view.h" | 21 #import "chrome/browser/ui/cocoa/hyperlink_text_view.h" |
| 21 #import "chrome/browser/ui/cocoa/info_bubble_view.h" | 22 #import "chrome/browser/ui/cocoa/info_bubble_view.h" |
| 22 #import "chrome/browser/ui/cocoa/info_bubble_window.h" | 23 #import "chrome/browser/ui/cocoa/info_bubble_window.h" |
| 23 #include "chrome/browser/ui/cocoa/website_settings/permission_bubble_cocoa.h" | 24 #include "chrome/browser/ui/cocoa/website_settings/permission_bubble_cocoa.h" |
| 24 #include "chrome/browser/ui/cocoa/website_settings/permission_selector_button.h" | 25 #include "chrome/browser/ui/cocoa/website_settings/permission_selector_button.h" |
| 25 #include "chrome/browser/ui/cocoa/website_settings/split_block_button.h" | 26 #include "chrome/browser/ui/cocoa/website_settings/split_block_button.h" |
| 26 #include "chrome/browser/ui/cocoa/website_settings/website_settings_utils_cocoa.
h" | 27 #include "chrome/browser/ui/cocoa/website_settings/website_settings_utils_cocoa.
h" |
| 27 #include "chrome/browser/ui/website_settings/permission_bubble_request.h" | 28 #include "chrome/browser/ui/website_settings/permission_bubble_request.h" |
| 28 #include "chrome/browser/ui/website_settings/permission_bubble_view.h" | 29 #include "chrome/browser/ui/website_settings/permission_bubble_view.h" |
| 29 #include "chrome/browser/ui/website_settings/permission_menu_model.h" | 30 #include "chrome/browser/ui/website_settings/permission_menu_model.h" |
| 31 #include "content/public/browser/native_web_keyboard_event.h" |
| 30 #include "content/public/browser/user_metrics.h" | 32 #include "content/public/browser/user_metrics.h" |
| 31 #include "grit/generated_resources.h" | 33 #include "grit/generated_resources.h" |
| 32 #include "skia/ext/skia_utils_mac.h" | 34 #include "skia/ext/skia_utils_mac.h" |
| 33 #import "ui/base/cocoa/menu_controller.h" | 35 #import "ui/base/cocoa/menu_controller.h" |
| 34 #include "ui/base/cocoa/window_size_constants.h" | 36 #include "ui/base/cocoa/window_size_constants.h" |
| 35 #import "ui/base/cocoa/menu_controller.h" | 37 #import "ui/base/cocoa/menu_controller.h" |
| 36 #include "ui/base/l10n/l10n_util_mac.h" | 38 #include "ui/base/l10n/l10n_util_mac.h" |
| 37 #include "ui/base/models/simple_menu_model.h" | 39 #include "ui/base/models/simple_menu_model.h" |
| 38 | 40 |
| 39 using base::UserMetricsAction; | 41 using base::UserMetricsAction; |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 // Adjust the size to fit the current title. Using only -sizeToFit leaves | 122 // Adjust the size to fit the current title. Using only -sizeToFit leaves |
| 121 // an ugly amount of whitespace between the title and the arrows because it | 123 // an ugly amount of whitespace between the title and the arrows because it |
| 122 // will fit to the largest element in the menu, not just the selected item. | 124 // will fit to the largest element in the menu, not just the selected item. |
| 123 [self setFrameSize:SizeForWebsiteSettingsButtonTitle(self, [self title])]; | 125 [self setFrameSize:SizeForWebsiteSettingsButtonTitle(self, [self title])]; |
| 124 } | 126 } |
| 125 return self; | 127 return self; |
| 126 } | 128 } |
| 127 | 129 |
| 128 @end | 130 @end |
| 129 | 131 |
| 132 // The window used for the permission bubble controller. |
| 133 // Subclassed to allow browser-handled keyboard events to be passed from the |
| 134 // permission bubble to its parent window, which is a browser window. |
| 135 @interface PermissionBubbleWindow : InfoBubbleWindow |
| 136 @end |
| 137 |
| 138 @implementation PermissionBubbleWindow |
| 139 - (BOOL)performKeyEquivalent:(NSEvent*)event { |
| 140 content::NativeWebKeyboardEvent wrappedEvent(event); |
| 141 if ([BrowserWindowUtils shouldHandleKeyboardEvent:wrappedEvent]) { |
| 142 return [BrowserWindowUtils handleKeyboardEvent:event |
| 143 inWindow:[self parentWindow]]; |
| 144 } |
| 145 return [super performKeyEquivalent:event]; |
| 146 } |
| 147 @end |
| 148 |
| 130 @interface PermissionBubbleController () | 149 @interface PermissionBubbleController () |
| 131 | 150 |
| 132 // Returns an autoreleased NSView displaying the icon and label for |request|. | 151 // Returns an autoreleased NSView displaying the icon and label for |request|. |
| 133 - (NSView*)labelForRequest:(PermissionBubbleRequest*)request; | 152 - (NSView*)labelForRequest:(PermissionBubbleRequest*)request; |
| 134 | 153 |
| 135 // Returns an autoreleased NSView displaying the title for the bubble | 154 // Returns an autoreleased NSView displaying the title for the bubble |
| 136 // requesting settings for |host|. | 155 // requesting settings for |host|. |
| 137 - (NSView*)titleWithHostname:(const std::string&)host; | 156 - (NSView*)titleWithHostname:(const std::string&)host; |
| 138 | 157 |
| 139 // Returns an autoreleased NSView displaying a menu for |request|. The | 158 // Returns an autoreleased NSView displaying a menu for |request|. The |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 + (void)alignCenterOf:(NSView*)viewA verticallyToCenterOf:(NSView*)viewB; | 202 + (void)alignCenterOf:(NSView*)viewA verticallyToCenterOf:(NSView*)viewB; |
| 184 | 203 |
| 185 @end | 204 @end |
| 186 | 205 |
| 187 @implementation PermissionBubbleController | 206 @implementation PermissionBubbleController |
| 188 | 207 |
| 189 - (id)initWithParentWindow:(NSWindow*)parentWindow | 208 - (id)initWithParentWindow:(NSWindow*)parentWindow |
| 190 bridge:(PermissionBubbleCocoa*)bridge { | 209 bridge:(PermissionBubbleCocoa*)bridge { |
| 191 DCHECK(parentWindow); | 210 DCHECK(parentWindow); |
| 192 DCHECK(bridge); | 211 DCHECK(bridge); |
| 193 base::scoped_nsobject<InfoBubbleWindow> window([[InfoBubbleWindow alloc] | 212 base::scoped_nsobject<PermissionBubbleWindow> window( |
| 194 initWithContentRect:ui::kWindowSizeDeterminedLater | 213 [[PermissionBubbleWindow alloc] |
| 195 styleMask:NSBorderlessWindowMask | 214 initWithContentRect:ui::kWindowSizeDeterminedLater |
| 196 backing:NSBackingStoreBuffered | 215 styleMask:NSBorderlessWindowMask |
| 197 defer:NO]); | 216 backing:NSBackingStoreBuffered |
| 217 defer:NO]); |
| 198 [window setAllowedAnimations:info_bubble::kAnimateNone]; | 218 [window setAllowedAnimations:info_bubble::kAnimateNone]; |
| 199 if ((self = [super initWithWindow:window | 219 if ((self = [super initWithWindow:window |
| 200 parentWindow:parentWindow | 220 parentWindow:parentWindow |
| 201 anchoredAt:NSZeroPoint])) { | 221 anchoredAt:NSZeroPoint])) { |
| 202 [self setShouldCloseOnResignKey:NO]; | 222 [self setShouldCloseOnResignKey:NO]; |
| 203 [[self bubble] setArrowLocation:info_bubble::kTopLeft]; | 223 [[self bubble] setArrowLocation:info_bubble::kTopLeft]; |
| 204 NSNotificationCenter* nc = [NSNotificationCenter defaultCenter]; | 224 NSNotificationCenter* nc = [NSNotificationCenter defaultCenter]; |
| 205 [nc addObserver:self | 225 [nc addObserver:self |
| 206 selector:@selector(parentWindowDidResize:) | 226 selector:@selector(parentWindowDidResize:) |
| 207 name:NSWindowDidResizeNotification | 227 name:NSWindowDidResizeNotification |
| (...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 535 | 555 |
| 536 + (void)alignCenterOf:(NSView*)viewA verticallyToCenterOf:(NSView*)viewB { | 556 + (void)alignCenterOf:(NSView*)viewA verticallyToCenterOf:(NSView*)viewB { |
| 537 NSRect frameA = [viewA frame]; | 557 NSRect frameA = [viewA frame]; |
| 538 NSRect frameB = [viewB frame]; | 558 NSRect frameB = [viewB frame]; |
| 539 frameA.origin.y = | 559 frameA.origin.y = |
| 540 NSMinY(frameB) + std::floor((NSHeight(frameB) - NSHeight(frameA)) / 2); | 560 NSMinY(frameB) + std::floor((NSHeight(frameB) - NSHeight(frameA)) / 2); |
| 541 [viewA setFrameOrigin:frameA.origin]; | 561 [viewA setFrameOrigin:frameA.origin]; |
| 542 } | 562 } |
| 543 | 563 |
| 544 @end // implementation PermissionBubbleController | 564 @end // implementation PermissionBubbleController |
| OLD | NEW |