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/foundation_util.h" | 9 #include "base/mac/foundation_util.h" |
10 #include "base/mac/mac_util.h" | 10 #include "base/mac/mac_util.h" |
11 #include "base/strings/sys_string_conversions.h" | 11 #include "base/strings/sys_string_conversions.h" |
12 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
13 #include "chrome/browser/ui/browser_finder.h" | 13 #include "chrome/browser/ui/browser_finder.h" |
14 #import "chrome/browser/ui/chrome_style.h" | 14 #import "chrome/browser/ui/chrome_style.h" |
15 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 15 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
16 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_button.h" | 16 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_button.h" |
| 17 #import "chrome/browser/ui/cocoa/hover_close_button.h" |
17 #import "chrome/browser/ui/cocoa/hyperlink_text_view.h" | 18 #import "chrome/browser/ui/cocoa/hyperlink_text_view.h" |
18 #import "chrome/browser/ui/cocoa/info_bubble_view.h" | 19 #import "chrome/browser/ui/cocoa/info_bubble_view.h" |
19 #import "chrome/browser/ui/cocoa/info_bubble_window.h" | 20 #import "chrome/browser/ui/cocoa/info_bubble_window.h" |
20 #include "chrome/browser/ui/cocoa/website_settings/permission_bubble_cocoa.h" | 21 #include "chrome/browser/ui/cocoa/website_settings/permission_bubble_cocoa.h" |
21 #include "chrome/browser/ui/website_settings/permission_bubble_request.h" | 22 #include "chrome/browser/ui/website_settings/permission_bubble_request.h" |
22 #include "chrome/browser/ui/website_settings/permission_bubble_view.h" | 23 #include "chrome/browser/ui/website_settings/permission_bubble_view.h" |
23 #include "content/public/browser/user_metrics.h" | 24 #include "content/public/browser/user_metrics.h" |
24 #include "grit/generated_resources.h" | 25 #include "grit/generated_resources.h" |
25 #include "skia/ext/skia_utils_mac.h" | 26 #include "skia/ext/skia_utils_mac.h" |
26 #include "ui/base/cocoa/window_size_constants.h" | 27 #include "ui/base/cocoa/window_size_constants.h" |
27 #include "ui/base/l10n/l10n_util_mac.h" | 28 #include "ui/base/l10n/l10n_util_mac.h" |
28 | 29 |
29 using base::UserMetricsAction; | 30 using base::UserMetricsAction; |
30 | 31 |
31 namespace { | 32 namespace { |
32 const CGFloat kHorizontalPadding = 20.0f; | 33 const CGFloat kHorizontalPadding = 20.0f; |
33 const CGFloat kVerticalPadding = 20.0f; | 34 const CGFloat kVerticalPadding = 20.0f; |
34 const CGFloat kButtonPadding = 10.0f; | 35 const CGFloat kButtonPadding = 10.0f; |
35 const CGFloat kCheckboxYAdjustment = 2.0f; | 36 const CGFloat kCheckboxYAdjustment = 2.0f; |
36 | 37 |
37 const CGFloat kFontSize = 15.0f; | 38 const CGFloat kFontSize = 15.0f; |
38 const base::char16 kBulletPoint = 0x2022; | 39 const base::char16 kBulletPoint = 0x2022; |
39 | 40 |
40 } // namespace | 41 } // namespace |
41 | 42 |
42 @interface PermissionBubbleController () | 43 @interface PermissionBubbleController () |
43 | 44 |
| 45 // Returns an autoreleased NSView displaying the label for |request|. |
| 46 - (NSView*)labelForRequest:(PermissionBubbleRequest*)request |
| 47 isSingleRequest:(BOOL)singleRequest; |
| 48 |
| 49 // Returns an autoreleased NSView displaying the title for the bubble if |
| 50 // there are multiple requests. |
| 51 - (NSView*)titleForMultipleRequests; |
| 52 |
| 53 // Returns an autoreleased NSView displaying a checkbox for |request|. The |
| 54 // checkbox will be initialized as checked if |checked| is YES. |
| 55 - (NSView*)checkboxForRequest:(PermissionBubbleRequest*)request |
| 56 checked:(BOOL)checked; |
| 57 |
| 58 // Returns an autoreleased NSView displaying the customize button. |
| 59 - (NSView*)customizationButton; |
| 60 |
| 61 // Returns an autoreleased NSView of a button with |title| and |action|. |
| 62 // If |pairedButton| is non-nil, the size of both buttons will be set to be |
| 63 // equal to the size of the larger of the two. |
| 64 - (NSView*)buttonWithTitle:(NSString*)title |
| 65 action:(SEL)action |
| 66 pairedWith:(NSView*)pairedButton; |
| 67 |
| 68 // Returns an autoreleased NSView displaying the close 'x' button. |
| 69 - (NSView*)closeButton; |
| 70 |
44 // Called when the 'ok' button is pressed. | 71 // Called when the 'ok' button is pressed. |
45 - (void)ok:(id)sender; | 72 - (void)ok:(id)sender; |
46 | 73 |
47 // Called when the 'allow' button is pressed. | 74 // Called when the 'allow' button is pressed. |
48 - (void)onAllow:(id)sender; | 75 - (void)onAllow:(id)sender; |
49 | 76 |
50 // Called when the 'block' button is pressed. | 77 // Called when the 'block' button is pressed. |
51 - (void)onBlock:(id)sender; | 78 - (void)onBlock:(id)sender; |
52 | 79 |
| 80 // Called when the 'close' button is pressed. |
| 81 - (void)onClose:(id)sender; |
| 82 |
53 // Called when the 'customize' button is pressed. | 83 // Called when the 'customize' button is pressed. |
54 - (void)onCustomize:(id)sender; | 84 - (void)onCustomize:(id)sender; |
55 | 85 |
56 // Called when a checkbox changes from checked to unchecked, or vice versa. | 86 // Called when a checkbox changes from checked to unchecked, or vice versa. |
57 - (void)onCheckboxChanged:(id)sender; | 87 - (void)onCheckboxChanged:(id)sender; |
58 | 88 |
| 89 |
59 @end | 90 @end |
60 | 91 |
61 @implementation PermissionBubbleController | 92 @implementation PermissionBubbleController |
62 | 93 |
63 - (id)initWithParentWindow:(NSWindow*)parentWindow | 94 - (id)initWithParentWindow:(NSWindow*)parentWindow |
64 bridge:(PermissionBubbleCocoa*)bridge { | 95 bridge:(PermissionBubbleCocoa*)bridge { |
65 DCHECK(parentWindow); | 96 DCHECK(parentWindow); |
66 DCHECK(bridge); | 97 DCHECK(bridge); |
67 base::scoped_nsobject<InfoBubbleWindow> window([[InfoBubbleWindow alloc] | 98 base::scoped_nsobject<InfoBubbleWindow> window([[InfoBubbleWindow alloc] |
68 initWithContentRect:ui::kWindowSizeDeterminedLater | 99 initWithContentRect:ui::kWindowSizeDeterminedLater |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 | 167 |
137 // The maximum width of the above permissions will dictate the width of the | 168 // The maximum width of the above permissions will dictate the width of the |
138 // bubble. It is calculated here so that it can be used for the positioning | 169 // bubble. It is calculated here so that it can be used for the positioning |
139 // of the buttons. | 170 // of the buttons. |
140 NSRect bubbleFrame = NSZeroRect; | 171 NSRect bubbleFrame = NSZeroRect; |
141 for (NSView* view in [contentView subviews]) { | 172 for (NSView* view in [contentView subviews]) { |
142 bubbleFrame = NSUnionRect( | 173 bubbleFrame = NSUnionRect( |
143 bubbleFrame, NSInsetRect([view frame], -kHorizontalPadding, 0)); | 174 bubbleFrame, NSInsetRect([view frame], -kHorizontalPadding, 0)); |
144 } | 175 } |
145 | 176 |
| 177 // 'x' button in the upper-right-hand corner. |
| 178 base::scoped_nsobject<NSView> closeButton([[self closeButton] retain]); |
| 179 // Place the close button at the rightmost edge of the bubble. |
| 180 [closeButton setFrameOrigin:NSMakePoint( |
| 181 NSMaxX(bubbleFrame), yOffset - chrome_style::kCloseButtonPadding)]; |
| 182 // Increase the size of the bubble by the width of the close button and its |
| 183 // padding. |
| 184 bubbleFrame.size.width += |
| 185 NSWidth([closeButton frame]) + chrome_style::kCloseButtonPadding; |
| 186 [contentView addSubview:closeButton]; |
| 187 |
146 // Position the allow/ok button. | 188 // Position the allow/ok button. |
147 CGFloat xOrigin = NSWidth(bubbleFrame) - NSWidth([allowOrOkButton frame]) - | 189 CGFloat xOrigin = NSWidth(bubbleFrame) - NSWidth([allowOrOkButton frame]) - |
148 kHorizontalPadding; | 190 kHorizontalPadding; |
149 [allowOrOkButton setFrameOrigin:NSMakePoint(xOrigin, kVerticalPadding)]; | 191 [allowOrOkButton setFrameOrigin:NSMakePoint(xOrigin, kVerticalPadding)]; |
150 [contentView addSubview:allowOrOkButton]; | 192 [contentView addSubview:allowOrOkButton]; |
151 | 193 |
152 if (!customizationMode) { | 194 if (!customizationMode) { |
153 base::scoped_nsobject<NSView> blockButton( | 195 base::scoped_nsobject<NSView> blockButton( |
154 [[self buttonWithTitle:@"Block" | 196 [[self buttonWithTitle:@"Block" |
155 action:@selector(onBlock:) | 197 action:@selector(onBlock:) |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 if (pairedButton) { | 315 if (pairedButton) { |
274 NSRect buttonFrame = [button frame]; | 316 NSRect buttonFrame = [button frame]; |
275 NSRect pairedFrame = [pairedButton frame]; | 317 NSRect pairedFrame = [pairedButton frame]; |
276 CGFloat width = std::max(NSWidth(buttonFrame), NSWidth(pairedFrame)); | 318 CGFloat width = std::max(NSWidth(buttonFrame), NSWidth(pairedFrame)); |
277 [button setFrameSize:NSMakeSize(width, buttonFrame.size.height)]; | 319 [button setFrameSize:NSMakeSize(width, buttonFrame.size.height)]; |
278 [pairedButton setFrameSize:NSMakeSize(width, pairedFrame.size.height)]; | 320 [pairedButton setFrameSize:NSMakeSize(width, pairedFrame.size.height)]; |
279 } | 321 } |
280 return button.autorelease(); | 322 return button.autorelease(); |
281 } | 323 } |
282 | 324 |
| 325 - (NSView*)closeButton { |
| 326 int dimension = chrome_style::GetCloseButtonSize(); |
| 327 NSRect frame = NSMakeRect(0, 0, dimension, dimension); |
| 328 base::scoped_nsobject<NSButton> button( |
| 329 [[WebUIHoverCloseButton alloc] initWithFrame:frame]); |
| 330 [button setAction:@selector(onClose:)]; |
| 331 [button setTarget:self]; |
| 332 return button.autorelease(); |
| 333 } |
| 334 |
283 - (void)ok:(id)sender { | 335 - (void)ok:(id)sender { |
284 DCHECK(delegate_); | 336 DCHECK(delegate_); |
285 delegate_->Closing(); | 337 delegate_->Closing(); |
286 } | 338 } |
287 | 339 |
288 - (void)onAllow:(id)sender { | 340 - (void)onAllow:(id)sender { |
289 DCHECK(delegate_); | 341 DCHECK(delegate_); |
290 delegate_->Accept(); | 342 delegate_->Accept(); |
291 } | 343 } |
292 | 344 |
293 - (void)onBlock:(id)sender { | 345 - (void)onBlock:(id)sender { |
294 DCHECK(delegate_); | 346 DCHECK(delegate_); |
295 delegate_->Deny(); | 347 delegate_->Deny(); |
296 } | 348 } |
297 | 349 |
| 350 - (void)onClose:(id)sender { |
| 351 DCHECK(delegate_); |
| 352 delegate_->Closing(); |
| 353 } |
| 354 |
298 - (void)onCustomize:(id)sender { | 355 - (void)onCustomize:(id)sender { |
299 DCHECK(delegate_); | 356 DCHECK(delegate_); |
300 delegate_->SetCustomizationMode(); | 357 delegate_->SetCustomizationMode(); |
301 } | 358 } |
302 | 359 |
303 - (void)onCheckboxChanged:(id)sender { | 360 - (void)onCheckboxChanged:(id)sender { |
304 DCHECK(delegate_); | 361 DCHECK(delegate_); |
305 NSButton* checkbox = base::mac::ObjCCastStrict<NSButton>(sender); | 362 NSButton* checkbox = base::mac::ObjCCastStrict<NSButton>(sender); |
306 delegate_->ToggleAccept([checkbox tag], [checkbox state] == NSOnState); | 363 delegate_->ToggleAccept([checkbox tag], [checkbox state] == NSOnState); |
307 } | 364 } |
308 | 365 |
309 @end // implementation PermissionBubbleController | 366 @end // implementation PermissionBubbleController |
OLD | NEW |