| 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 <Cocoa/Cocoa.h> | 5 #import <Cocoa/Cocoa.h> |
| 6 | 6 |
| 7 #include "base/logging.h" // for NOTREACHED() | 7 #include "base/logging.h" // for NOTREACHED() |
| 8 #include "base/mac/bundle_locations.h" | 8 #include "base/mac/bundle_locations.h" |
| 9 #include "base/strings/sys_string_conversions.h" | 9 #include "base/strings/sys_string_conversions.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 @interface OneClickHyperlinkTextView : HyperlinkTextView | 37 @interface OneClickHyperlinkTextView : HyperlinkTextView |
| 38 @end | 38 @end |
| 39 @implementation OneClickHyperlinkTextView | 39 @implementation OneClickHyperlinkTextView |
| 40 - (BOOL)acceptsFirstMouse:(NSEvent*)event { | 40 - (BOOL)acceptsFirstMouse:(NSEvent*)event { |
| 41 return YES; | 41 return YES; |
| 42 } | 42 } |
| 43 @end | 43 @end |
| 44 | 44 |
| 45 @interface ExclusiveAccessBubbleWindowController (PrivateMethods) | 45 @interface ExclusiveAccessBubbleWindowController (PrivateMethods) |
| 46 // Sets |exitLabel_| based on |exitLabelPlaceholder_|, | 46 // Sets |exitLabel_| based on |exitLabelPlaceholder_|, |
| 47 // sets |exitLabelPlaceholder_| to nil. | 47 // sets |exitLabelPlaceholder_| to nil, |
| 48 - (void)initializeLabel; | 48 // sets |denyButton_| text based on |bubbleType_|. |
| 49 - (void)initializeLabelAndButton; |
| 49 | 50 |
| 50 - (NSString*)getLabelText; | 51 - (NSString*)getLabelText; |
| 51 | 52 |
| 52 - (void)hideSoon; | 53 - (void)hideSoon; |
| 53 | 54 |
| 54 // Returns the Accelerator for the Toggle Fullscreen menu item. | 55 // Returns the Accelerator for the Toggle Fullscreen menu item. |
| 55 + (scoped_ptr<ui::PlatformAcceleratorCocoa>)acceleratorForToggleFullscreen; | 56 + (scoped_ptr<ui::PlatformAcceleratorCocoa>)acceleratorForToggleFullscreen; |
| 56 | 57 |
| 57 // Returns a string representation fit for display of | 58 // Returns a string representation fit for display of |
| 58 // +acceleratorForToggleFullscreen. | 59 // +acceleratorForToggleFullscreen. |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 // (called from this function) will bring the window on-screen; | 115 // (called from this function) will bring the window on-screen; |
| 115 // unfortunately, [NSWindowController showWindow:] will also bring it | 116 // unfortunately, [NSWindowController showWindow:] will also bring it |
| 116 // on-screen (but will cause unexpected changes to the window's | 117 // on-screen (but will cause unexpected changes to the window's |
| 117 // position). We cannot have an addChildWindow: and a subsequent | 118 // position). We cannot have an addChildWindow: and a subsequent |
| 118 // showWindow:. Thus, we have our own version. | 119 // showWindow:. Thus, we have our own version. |
| 119 - (void)showWindow { | 120 - (void)showWindow { |
| 120 // Completes nib load. | 121 // Completes nib load. |
| 121 InfoBubbleWindow* info_bubble = static_cast<InfoBubbleWindow*>([self window]); | 122 InfoBubbleWindow* info_bubble = static_cast<InfoBubbleWindow*>([self window]); |
| 122 [info_bubble setCanBecomeKeyWindow:NO]; | 123 [info_bubble setCanBecomeKeyWindow:NO]; |
| 123 if (!exclusive_access_bubble::ShowButtonsForType(bubbleType_)) { | 124 if (!exclusive_access_bubble::ShowButtonsForType(bubbleType_)) { |
| 124 [self showButtons:NO]; | |
| 125 [self hideSoon]; | 125 [self hideSoon]; |
| 126 } | 126 } |
| 127 [tweaker_ tweakUI:info_bubble]; | 127 [tweaker_ tweakUI:info_bubble]; |
| 128 [[owner_ window] addChildWindow:info_bubble ordered:NSWindowAbove]; | 128 [[owner_ window] addChildWindow:info_bubble ordered:NSWindowAbove]; |
| 129 [owner_ layoutSubviews]; | 129 [owner_ layoutSubviews]; |
| 130 | 130 |
| 131 [info_bubble orderFront:self]; | 131 [info_bubble orderFront:self]; |
| 132 } | 132 } |
| 133 | 133 |
| 134 - (void)awakeFromNib { | 134 - (void)awakeFromNib { |
| 135 DCHECK([[self window] isKindOfClass:[InfoBubbleWindow class]]); | 135 DCHECK([[self window] isKindOfClass:[InfoBubbleWindow class]]); |
| 136 [messageLabel_ setStringValue:[self getLabelText]]; | 136 [messageLabel_ setStringValue:[self getLabelText]]; |
| 137 [self initializeLabel]; | 137 [self initializeLabelAndButton]; |
| 138 } | 138 } |
| 139 | 139 |
| 140 - (void)positionInWindowAtTop:(CGFloat)maxY width:(CGFloat)maxWidth { | 140 - (void)positionInWindowAtTop:(CGFloat)maxY width:(CGFloat)maxWidth { |
| 141 NSRect windowFrame = [self window].frame; | 141 NSRect windowFrame = [self window].frame; |
| 142 NSRect ownerWindowFrame = [owner_ window].frame; | 142 NSRect ownerWindowFrame = [owner_ window].frame; |
| 143 NSPoint origin; | 143 NSPoint origin; |
| 144 origin.x = ownerWindowFrame.origin.x + | 144 origin.x = ownerWindowFrame.origin.x + |
| 145 (int)(NSWidth(ownerWindowFrame) / 2 - NSWidth(windowFrame) / 2); | 145 (int)(NSWidth(ownerWindowFrame) / 2 - NSWidth(windowFrame) / 2); |
| 146 origin.y = ownerWindowFrame.origin.y + maxY - NSHeight(windowFrame); | 146 origin.y = ownerWindowFrame.origin.y + maxY - NSHeight(windowFrame); |
| 147 [[self window] setFrameOrigin:origin]; | 147 [[self window] setFrameOrigin:origin]; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 - (void)dealloc { | 190 - (void)dealloc { |
| 191 [hideAnimation_.get() stopAnimation]; | 191 [hideAnimation_.get() stopAnimation]; |
| 192 [hideTimer_ invalidate]; | 192 [hideTimer_ invalidate]; |
| 193 [super dealloc]; | 193 [super dealloc]; |
| 194 } | 194 } |
| 195 | 195 |
| 196 @end | 196 @end |
| 197 | 197 |
| 198 @implementation ExclusiveAccessBubbleWindowController (PrivateMethods) | 198 @implementation ExclusiveAccessBubbleWindowController (PrivateMethods) |
| 199 | 199 |
| 200 - (void)initializeLabel { | 200 - (void)initializeLabelAndButton { |
| 201 // Replace the label placeholder NSTextField with the real label NSTextView. | 201 // Replace the label placeholder NSTextField with the real label NSTextView. |
| 202 // The former doesn't show links in a nice way, but the latter can't be added | 202 // The former doesn't show links in a nice way, but the latter can't be added |
| 203 // in IB without a containing scroll view, so create the NSTextView | 203 // in IB without a containing scroll view, so create the NSTextView |
| 204 // programmatically. | 204 // programmatically. |
| 205 exitLabel_.reset([[OneClickHyperlinkTextView alloc] | 205 exitLabel_.reset([[OneClickHyperlinkTextView alloc] |
| 206 initWithFrame:[exitLabelPlaceholder_ frame]]); | 206 initWithFrame:[exitLabelPlaceholder_ frame]]); |
| 207 [exitLabel_.get() | 207 [exitLabel_.get() |
| 208 setAutoresizingMask:[exitLabelPlaceholder_ autoresizingMask]]; | 208 setAutoresizingMask:[exitLabelPlaceholder_ autoresizingMask]]; |
| 209 [exitLabel_.get() setHidden:[exitLabelPlaceholder_ isHidden]]; | 209 [exitLabel_.get() setHidden:[exitLabelPlaceholder_ isHidden]]; |
| 210 [[exitLabelPlaceholder_ superview] replaceSubview:exitLabelPlaceholder_ | 210 [[exitLabelPlaceholder_ superview] replaceSubview:exitLabelPlaceholder_ |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 [exitLabel_ setFrameSize:windowFrame.size]; | 251 [exitLabel_ setFrameSize:windowFrame.size]; |
| 252 NSLayoutManager* layoutManager = [exitLabel_ layoutManager]; | 252 NSLayoutManager* layoutManager = [exitLabel_ layoutManager]; |
| 253 NSTextContainer* textContainer = [exitLabel_ textContainer]; | 253 NSTextContainer* textContainer = [exitLabel_ textContainer]; |
| 254 [layoutManager ensureLayoutForTextContainer:textContainer]; | 254 [layoutManager ensureLayoutForTextContainer:textContainer]; |
| 255 NSRect textFrame = [layoutManager usedRectForTextContainer:textContainer]; | 255 NSRect textFrame = [layoutManager usedRectForTextContainer:textContainer]; |
| 256 | 256 |
| 257 textFrame.size.width = ceil(NSWidth(textFrame)); | 257 textFrame.size.width = ceil(NSWidth(textFrame)); |
| 258 labelFrame.origin.x += NSWidth(labelFrame) - NSWidth(textFrame); | 258 labelFrame.origin.x += NSWidth(labelFrame) - NSWidth(textFrame); |
| 259 labelFrame.size = textFrame.size; | 259 labelFrame.size = textFrame.size; |
| 260 [exitLabel_ setFrame:labelFrame]; | 260 [exitLabel_ setFrame:labelFrame]; |
| 261 |
| 262 // Update the title of denyButton_ according to the current bubbleType_, |
| 263 // or show no button at all. |
| 264 if (exclusive_access_bubble::ShowButtonsForType(bubbleType_)) { |
| 265 NSString* denyButtonText = |
| 266 SysUTF16ToNSString( |
| 267 exclusive_access_bubble::GetDenyButtonTextForType(bubbleType_)); |
| 268 [denyButton_ setTitle:denyButtonText]; |
| 269 } else { |
| 270 [self showButtons:NO]; |
| 271 } |
| 261 } | 272 } |
| 262 | 273 |
| 263 - (NSString*)getLabelText { | 274 - (NSString*)getLabelText { |
| 264 if (bubbleType_ == EXCLUSIVE_ACCESS_BUBBLE_TYPE_NONE) | 275 if (bubbleType_ == EXCLUSIVE_ACCESS_BUBBLE_TYPE_NONE) |
| 265 return @""; | 276 return @""; |
| 266 extensions::ExtensionRegistry* registry = | 277 extensions::ExtensionRegistry* registry = |
| 267 extensions::ExtensionRegistry::Get(browser_->profile()); | 278 extensions::ExtensionRegistry::Get(browser_->profile()); |
| 268 return SysUTF16ToNSString(exclusive_access_bubble::GetLabelTextForType( | 279 return SysUTF16ToNSString(exclusive_access_bubble::GetLabelTextForType( |
| 269 bubbleType_, url_, registry)); | 280 bubbleType_, url_, registry)); |
| 270 } | 281 } |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 - (void)hideSoon { | 334 - (void)hideSoon { |
| 324 hideTimer_.reset( | 335 hideTimer_.reset( |
| 325 [[NSTimer scheduledTimerWithTimeInterval:kInitialDelay | 336 [[NSTimer scheduledTimerWithTimeInterval:kInitialDelay |
| 326 target:self | 337 target:self |
| 327 selector:@selector(hideTimerFired:) | 338 selector:@selector(hideTimerFired:) |
| 328 userInfo:nil | 339 userInfo:nil |
| 329 repeats:NO] retain]); | 340 repeats:NO] retain]); |
| 330 } | 341 } |
| 331 | 342 |
| 332 @end | 343 @end |
| OLD | NEW |