Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(104)

Side by Side Diff: chrome/browser/ui/cocoa/website_settings/permission_bubble_controller.mm

Issue 186643005: Adds close button to cocoa permissions bubble. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 137
137 // The maximum width of the above permissions will dictate the width of the 138 // 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 139 // bubble. It is calculated here so that it can be used for the positioning
139 // of the buttons. 140 // of the buttons.
140 NSRect bubbleFrame = NSZeroRect; 141 NSRect bubbleFrame = NSZeroRect;
141 for (NSView* view in [contentView subviews]) { 142 for (NSView* view in [contentView subviews]) {
142 bubbleFrame = NSUnionRect( 143 bubbleFrame = NSUnionRect(
143 bubbleFrame, NSInsetRect([view frame], -kHorizontalPadding, 0)); 144 bubbleFrame, NSInsetRect([view frame], -kHorizontalPadding, 0));
144 } 145 }
145 146
147 // 'x' button in the upper-right-hand corner.
148 base::scoped_nsobject<NSView> closeButton([[self closeButton] retain]);
groby-ooo-7-16 2014/03/04 21:04:01 I'm surprised this doesn't generate a warning - yo
leng 2014/03/04 23:35:52 There are a bunch of these.
149 [closeButton setFrameOrigin:NSMakePoint(
150 NSMaxX(bubbleFrame), yOffset - chrome_style::kCloseButtonPadding)];
151 bubbleFrame.size.width +=
152 NSWidth([closeButton frame]) + chrome_style::kCloseButtonPadding;
groby-ooo-7-16 2014/03/04 21:04:01 Wait - why is this adding twice the width? Border
leng 2014/03/04 23:35:52 I don't think I'm adding the width twice? I've pu
groby-ooo-7-16 2014/03/05 00:19:05 Never mind. kCloseButtonPadding somehow looked lik
153 [contentView addSubview:closeButton];
154
146 // Position the allow/ok button. 155 // Position the allow/ok button.
147 CGFloat xOrigin = NSWidth(bubbleFrame) - NSWidth([allowOrOkButton frame]) - 156 CGFloat xOrigin = NSWidth(bubbleFrame) - NSWidth([allowOrOkButton frame]) -
148 kHorizontalPadding; 157 kHorizontalPadding;
149 [allowOrOkButton setFrameOrigin:NSMakePoint(xOrigin, kVerticalPadding)]; 158 [allowOrOkButton setFrameOrigin:NSMakePoint(xOrigin, kVerticalPadding)];
150 [contentView addSubview:allowOrOkButton]; 159 [contentView addSubview:allowOrOkButton];
151 160
152 if (!customizationMode) { 161 if (!customizationMode) {
153 base::scoped_nsobject<NSView> blockButton( 162 base::scoped_nsobject<NSView> blockButton(
154 [[self buttonWithTitle:@"Block" 163 [[self buttonWithTitle:@"Block"
155 action:@selector(onBlock:) 164 action:@selector(onBlock:)
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 if (pairedButton) { 282 if (pairedButton) {
274 NSRect buttonFrame = [button frame]; 283 NSRect buttonFrame = [button frame];
275 NSRect pairedFrame = [pairedButton frame]; 284 NSRect pairedFrame = [pairedButton frame];
276 CGFloat width = std::max(NSWidth(buttonFrame), NSWidth(pairedFrame)); 285 CGFloat width = std::max(NSWidth(buttonFrame), NSWidth(pairedFrame));
277 [button setFrameSize:NSMakeSize(width, buttonFrame.size.height)]; 286 [button setFrameSize:NSMakeSize(width, buttonFrame.size.height)];
278 [pairedButton setFrameSize:NSMakeSize(width, pairedFrame.size.height)]; 287 [pairedButton setFrameSize:NSMakeSize(width, pairedFrame.size.height)];
279 } 288 }
280 return button.autorelease(); 289 return button.autorelease();
281 } 290 }
282 291
292 - (NSView*)closeButton {
groby-ooo-7-16 2014/03/04 21:04:01 Please add to private api.
leng 2014/03/04 23:35:52 Done.
293 int dimension = chrome_style::GetCloseButtonSize();
294 NSRect frame = NSMakeRect(0, 0, dimension, dimension);
295 base::scoped_nsobject<NSButton> button(
296 [[WebUIHoverCloseButton alloc] initWithFrame:frame]);
297 [button setAction:@selector(onBlock:)];
groby-ooo-7-16 2014/03/04 21:04:01 Is "close" really the same as "block"? Shouldn't i
leng 2014/03/04 23:35:52 Done.
298 [button setTarget:self];
299 return button.autorelease();
300 }
301
283 - (void)ok:(id)sender { 302 - (void)ok:(id)sender {
284 DCHECK(delegate_); 303 DCHECK(delegate_);
285 delegate_->Closing(); 304 delegate_->Closing();
286 } 305 }
287 306
288 - (void)onAllow:(id)sender { 307 - (void)onAllow:(id)sender {
289 DCHECK(delegate_); 308 DCHECK(delegate_);
290 delegate_->Accept(); 309 delegate_->Accept();
291 } 310 }
292 311
293 - (void)onBlock:(id)sender { 312 - (void)onBlock:(id)sender {
294 DCHECK(delegate_); 313 DCHECK(delegate_);
295 delegate_->Deny(); 314 delegate_->Deny();
296 } 315 }
297 316
298 - (void)onCustomize:(id)sender { 317 - (void)onCustomize:(id)sender {
299 DCHECK(delegate_); 318 DCHECK(delegate_);
300 delegate_->SetCustomizationMode(); 319 delegate_->SetCustomizationMode();
301 } 320 }
302 321
303 - (void)onCheckboxChanged:(id)sender { 322 - (void)onCheckboxChanged:(id)sender {
304 DCHECK(delegate_); 323 DCHECK(delegate_);
305 NSButton* checkbox = base::mac::ObjCCastStrict<NSButton>(sender); 324 NSButton* checkbox = base::mac::ObjCCastStrict<NSButton>(sender);
306 delegate_->ToggleAccept([checkbox tag], [checkbox state] == NSOnState); 325 delegate_->ToggleAccept([checkbox tag], [checkbox state] == NSOnState);
307 } 326 }
308 327
309 @end // implementation PermissionBubbleController 328 @end // implementation PermissionBubbleController
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698