| 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/mac/mac_util.h" | 9 #include "base/mac/mac_util.h" |
| 10 #include "base/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "chrome/app/chrome_command_ids.h" | 12 #include "chrome/app/chrome_command_ids.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
| 15 #include "chrome/browser/ui/browser_commands.h" | 15 #include "chrome/browser/ui/browser_commands.h" |
| 16 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 16 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
| 17 #import "chrome/browser/ui/cocoa/fullscreen_exit_bubble_controller.h" | 17 #import "chrome/browser/ui/cocoa/exclusive_access_bubble_window_controller.h" |
| 18 #import "chrome/browser/ui/cocoa/info_bubble_view.h" | 18 #import "chrome/browser/ui/cocoa/info_bubble_view.h" |
| 19 #import "chrome/browser/ui/cocoa/info_bubble_window.h" | 19 #import "chrome/browser/ui/cocoa/info_bubble_window.h" |
| 20 #include "chrome/browser/ui/fullscreen/exclusive_access_bubble_type.h" |
| 20 #include "chrome/browser/ui/fullscreen/fullscreen_controller.h" | 21 #include "chrome/browser/ui/fullscreen/fullscreen_controller.h" |
| 21 #include "chrome/browser/ui/fullscreen/fullscreen_exit_bubble_type.h" | |
| 22 #include "chrome/grit/generated_resources.h" | 22 #include "chrome/grit/generated_resources.h" |
| 23 #include "extensions/browser/extension_registry.h" | 23 #include "extensions/browser/extension_registry.h" |
| 24 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMNSAnimation+Duration.h
" | 24 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMNSAnimation+Duration.h
" |
| 25 #include "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutT
weaker.h" | 25 #include "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutT
weaker.h" |
| 26 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTw
eaker.h" | 26 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTw
eaker.h" |
| 27 #include "ui/base/accelerators/platform_accelerator_cocoa.h" | 27 #include "ui/base/accelerators/platform_accelerator_cocoa.h" |
| 28 #import "ui/base/cocoa/controls/hyperlink_text_view.h" | 28 #import "ui/base/cocoa/controls/hyperlink_text_view.h" |
| 29 #include "ui/base/l10n/l10n_util.h" | 29 #include "ui/base/l10n/l10n_util.h" |
| 30 #include "ui/base/l10n/l10n_util_mac.h" | 30 #include "ui/base/l10n/l10n_util_mac.h" |
| 31 #include "ui/strings/grit/ui_strings.h" | 31 #include "ui/strings/grit/ui_strings.h" |
| 32 | 32 |
| 33 | |
| 34 namespace { | 33 namespace { |
| 35 const float kInitialDelay = 3.8; | 34 const float kInitialDelay = 3.8; |
| 36 const float kHideDuration = 0.7; | 35 const float kHideDuration = 0.7; |
| 37 } // namespace | 36 } // namespace |
| 38 | 37 |
| 39 @interface OneClickHyperlinkTextView : HyperlinkTextView | 38 @interface OneClickHyperlinkTextView : HyperlinkTextView |
| 40 @end | 39 @end |
| 41 @implementation OneClickHyperlinkTextView | 40 @implementation OneClickHyperlinkTextView |
| 42 - (BOOL)acceptsFirstMouse:(NSEvent*)event { | 41 - (BOOL)acceptsFirstMouse:(NSEvent*)event { |
| 43 return YES; | 42 return YES; |
| 44 } | 43 } |
| 45 @end | 44 @end |
| 46 | 45 |
| 47 @interface FullscreenExitBubbleController (PrivateMethods) | 46 @interface ExclusiveAccessBubbleWindowController (PrivateMethods) |
| 48 // Sets |exitLabel_| based on |exitLabelPlaceholder_|, | 47 // Sets |exitLabel_| based on |exitLabelPlaceholder_|, |
| 49 // sets |exitLabelPlaceholder_| to nil. | 48 // sets |exitLabelPlaceholder_| to nil. |
| 50 - (void)initializeLabel; | 49 - (void)initializeLabel; |
| 51 | 50 |
| 52 - (NSString*)getLabelText; | 51 - (NSString*)getLabelText; |
| 53 | 52 |
| 54 - (void)hideSoon; | 53 - (void)hideSoon; |
| 55 | 54 |
| 56 // Returns the Accelerator for the Toggle Fullscreen menu item. | 55 // Returns the Accelerator for the Toggle Fullscreen menu item. |
| 57 + (scoped_ptr<ui::PlatformAcceleratorCocoa>)acceleratorForToggleFullscreen; | 56 + (scoped_ptr<ui::PlatformAcceleratorCocoa>)acceleratorForToggleFullscreen; |
| 58 | 57 |
| 59 // Returns a string representation fit for display of | 58 // Returns a string representation fit for display of |
| 60 // +acceleratorForToggleFullscreen. | 59 // +acceleratorForToggleFullscreen. |
| 61 + (NSString*)keyCommandString; | 60 + (NSString*)keyCommandString; |
| 62 | 61 |
| 63 + (NSString*)keyCombinationForAccelerator: | 62 + (NSString*)keyCombinationForAccelerator: |
| 64 (const ui::PlatformAcceleratorCocoa&)item; | 63 (const ui::PlatformAcceleratorCocoa&)item; |
| 65 @end | 64 @end |
| 66 | 65 |
| 67 @implementation FullscreenExitBubbleController | 66 @implementation ExclusiveAccessBubbleWindowController |
| 68 | 67 |
| 69 - (id)initWithOwner:(BrowserWindowController*)owner | 68 - (id)initWithOwner:(BrowserWindowController*)owner |
| 70 browser:(Browser*)browser | 69 browser:(Browser*)browser |
| 71 url:(const GURL&)url | 70 url:(const GURL&)url |
| 72 bubbleType:(FullscreenExitBubbleType)bubbleType { | 71 bubbleType:(ExclusiveAccessBubbleType)bubbleType { |
| 73 NSString* nibPath = | 72 NSString* nibPath = |
| 74 [base::mac::FrameworkBundle() pathForResource:@"FullscreenExitBubble" | 73 [base::mac::FrameworkBundle() pathForResource:@"ExclusiveAccessBubble" |
| 75 ofType:@"nib"]; | 74 ofType:@"nib"]; |
| 76 if ((self = [super initWithWindowNibPath:nibPath owner:self])) { | 75 if ((self = [super initWithWindowNibPath:nibPath owner:self])) { |
| 77 browser_ = browser; | 76 browser_ = browser; |
| 78 owner_ = owner; | 77 owner_ = owner; |
| 79 url_ = url; | 78 url_ = url; |
| 80 bubbleType_ = bubbleType; | 79 bubbleType_ = bubbleType; |
| 81 // Mouse lock expects mouse events to reach the main window immediately. | 80 // Mouse lock expects mouse events to reach the main window immediately. |
| 82 // Make the bubble transparent for mouse events if mouse lock is enabled. | 81 // Make the bubble transparent for mouse events if mouse lock is enabled. |
| 83 if (bubbleType_ == FEB_TYPE_FULLSCREEN_MOUSELOCK_EXIT_INSTRUCTION || | 82 if (bubbleType_ == |
| 84 bubbleType_ == FEB_TYPE_MOUSELOCK_EXIT_INSTRUCTION) | 83 EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_MOUSELOCK_EXIT_INSTRUCTION |
| |
| 84 bubbleType_ == EXCLUSIVE_ACCESS_BUBBLE_TYPE_MOUSELOCK_EXIT_INSTRUCTION) |
| 85 [[self window] setIgnoresMouseEvents:YES]; | 85 [[self window] setIgnoresMouseEvents:YES]; |
| 86 } | 86 } |
| 87 return self; | 87 return self; |
| 88 } | 88 } |
| 89 | 89 |
| 90 - (void)allow:(id)sender { | 90 - (void)allow:(id)sender { |
| 91 // The mouselock code expects that mouse events reach the main window | 91 // The mouselock code expects that mouse events reach the main window |
| 92 // immediately, but the cursor is still over the bubble, which eats the | 92 // immediately, but the cursor is still over the bubble, which eats the |
| 93 // mouse events. Make the bubble transparent for mouse events. | 93 // mouse events. Make the bubble transparent for mouse events. |
| 94 if (bubbleType_ == FEB_TYPE_FULLSCREEN_MOUSELOCK_BUTTONS || | 94 if (bubbleType_ == |
| 95 bubbleType_ == FEB_TYPE_MOUSELOCK_BUTTONS) | 95 EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_MOUSELOCK_BUTTONS || |
| 96 bubbleType_ == EXCLUSIVE_ACCESS_BUBBLE_TYPE_MOUSELOCK_BUTTONS) |
| 96 [[self window] setIgnoresMouseEvents:YES]; | 97 [[self window] setIgnoresMouseEvents:YES]; |
| 97 | 98 |
| 98 DCHECK(fullscreen_bubble::ShowButtonsForType(bubbleType_)); | 99 DCHECK(exclusive_access_bubble::ShowButtonsForType(bubbleType_)); |
| 99 browser_->fullscreen_controller()->OnAcceptFullscreenPermission(); | 100 browser_->fullscreen_controller()->OnAcceptFullscreenPermission(); |
| 100 } | 101 } |
| 101 | 102 |
| 102 - (void)deny:(id)sender { | 103 - (void)deny:(id)sender { |
| 103 DCHECK(fullscreen_bubble::ShowButtonsForType(bubbleType_)); | 104 DCHECK(exclusive_access_bubble::ShowButtonsForType(bubbleType_)); |
| 104 browser_->fullscreen_controller()->OnDenyFullscreenPermission(); | 105 browser_->fullscreen_controller()->OnDenyFullscreenPermission(); |
| 105 } | 106 } |
| 106 | 107 |
| 107 - (void)showButtons:(BOOL)show { | 108 - (void)showButtons:(BOOL)show { |
| 108 [allowButton_ setHidden:!show]; | 109 [allowButton_ setHidden:!show]; |
| 109 [denyButton_ setHidden:!show]; | 110 [denyButton_ setHidden:!show]; |
| 110 [exitLabel_ setHidden:show]; | 111 [exitLabel_ setHidden:show]; |
| 111 } | 112 } |
| 112 | 113 |
| 113 // We want this to be a child of a browser window. addChildWindow: | 114 // We want this to be a child of a browser window. addChildWindow: |
| 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 (!fullscreen_bubble::ShowButtonsForType(bubbleType_)) { | 124 if (!exclusive_access_bubble::ShowButtonsForType(bubbleType_)) { |
| 124 [self showButtons:NO]; | 125 [self showButtons:NO]; |
| 125 [self hideSoon]; | 126 [self hideSoon]; |
| 126 } | 127 } |
| 127 [tweaker_ tweakUI:info_bubble]; | 128 [tweaker_ tweakUI:info_bubble]; |
| 128 [[owner_ window] addChildWindow:info_bubble ordered:NSWindowAbove]; | 129 [[owner_ window] addChildWindow:info_bubble ordered:NSWindowAbove]; |
| 129 [owner_ layoutSubviews]; | 130 [owner_ layoutSubviews]; |
| 130 | 131 |
| 131 [info_bubble orderFront:self]; | 132 [info_bubble orderFront:self]; |
| 132 } | 133 } |
| 133 | 134 |
| 134 - (void)awakeFromNib { | 135 - (void)awakeFromNib { |
| 135 DCHECK([[self window] isKindOfClass:[InfoBubbleWindow class]]); | 136 DCHECK([[self window] isKindOfClass:[InfoBubbleWindow class]]); |
| 136 [messageLabel_ setStringValue:[self getLabelText]]; | 137 [messageLabel_ setStringValue:[self getLabelText]]; |
| 137 [self initializeLabel]; | 138 [self initializeLabel]; |
| 138 } | 139 } |
| 139 | 140 |
| 140 - (void)positionInWindowAtTop:(CGFloat)maxY width:(CGFloat)maxWidth { | 141 - (void)positionInWindowAtTop:(CGFloat)maxY width:(CGFloat)maxWidth { |
| 141 NSRect windowFrame = [self window].frame; | 142 NSRect windowFrame = [self window].frame; |
| 142 NSRect ownerWindowFrame = [owner_ window].frame; | 143 NSRect ownerWindowFrame = [owner_ window].frame; |
| 143 NSPoint origin; | 144 NSPoint origin; |
| 144 origin.x = ownerWindowFrame.origin.x + | 145 origin.x = ownerWindowFrame.origin.x + |
| 145 (int)(NSWidth(ownerWindowFrame)/2 - NSWidth(windowFrame)/2); | 146 (int)(NSWidth(ownerWindowFrame) / 2 - NSWidth(windowFrame) / 2); |
| 146 origin.y = ownerWindowFrame.origin.y + maxY - NSHeight(windowFrame); | 147 origin.y = ownerWindowFrame.origin.y + maxY - NSHeight(windowFrame); |
| 147 [[self window] setFrameOrigin:origin]; | 148 [[self window] setFrameOrigin:origin]; |
| 148 } | 149 } |
| 149 | 150 |
| 150 // Called when someone clicks on the embedded link. | 151 // Called when someone clicks on the embedded link. |
| 151 - (BOOL) textView:(NSTextView*)textView | 152 - (BOOL)textView:(NSTextView*)textView |
| 152 clickedOnLink:(id)link | 153 clickedOnLink:(id)link |
| 153 atIndex:(NSUInteger)charIndex { | 154 atIndex:(NSUInteger)charIndex { |
| 154 browser_->fullscreen_controller()-> | 155 browser_->fullscreen_controller() |
| 155 ExitTabOrBrowserFullscreenToPreviousState(); | 156 ->ExitTabOrBrowserFullscreenToPreviousState(); |
| 156 return YES; | 157 return YES; |
| 157 } | 158 } |
| 158 | 159 |
| 159 - (void)hideTimerFired:(NSTimer*)timer { | 160 - (void)hideTimerFired:(NSTimer*)timer { |
| 160 // This might fire racily for buttoned bubbles, even though the timer is | 161 // This might fire racily for buttoned bubbles, even though the timer is |
| 161 // cancelled for them. Explicitly check for this case. | 162 // cancelled for them. Explicitly check for this case. |
| 162 if (fullscreen_bubble::ShowButtonsForType(bubbleType_)) | 163 if (exclusive_access_bubble::ShowButtonsForType(bubbleType_)) |
| 163 return; | 164 return; |
| 164 | 165 |
| 165 [NSAnimationContext beginGrouping]; | 166 [NSAnimationContext beginGrouping]; |
| 166 [[NSAnimationContext currentContext] | 167 [[NSAnimationContext currentContext] |
| 167 gtm_setDuration:kHideDuration | 168 gtm_setDuration:kHideDuration |
| 168 eventMask:NSLeftMouseUpMask|NSLeftMouseDownMask]; | 169 eventMask:NSLeftMouseUpMask | NSLeftMouseDownMask]; |
| 169 [[[self window] animator] setAlphaValue:0.0]; | 170 [[[self window] animator] setAlphaValue:0.0]; |
| 170 [NSAnimationContext endGrouping]; | 171 [NSAnimationContext endGrouping]; |
| 171 } | 172 } |
| 172 | 173 |
| 173 - (void)animationDidEnd:(NSAnimation*)animation { | 174 - (void)animationDidEnd:(NSAnimation*)animation { |
| 174 if (animation == hideAnimation_.get()) { | 175 if (animation == hideAnimation_.get()) { |
| 175 hideAnimation_.reset(); | 176 hideAnimation_.reset(); |
| 176 } | 177 } |
| 177 } | 178 } |
| 178 | 179 |
| 179 - (void)closeImmediately { | 180 - (void)closeImmediately { |
| 180 // Without this, quitting fullscreen with esc will let the bubble reappear | 181 // Without this, quitting fullscreen with esc will let the bubble reappear |
| 181 // once the "exit fullscreen" animation is done on lion. | 182 // once the "exit fullscreen" animation is done on lion. |
| 182 InfoBubbleWindow* infoBubble = static_cast<InfoBubbleWindow*>([self window]); | 183 InfoBubbleWindow* infoBubble = static_cast<InfoBubbleWindow*>([self window]); |
| 183 [[infoBubble parentWindow] removeChildWindow:infoBubble]; | 184 [[infoBubble parentWindow] removeChildWindow:infoBubble]; |
| 184 [hideAnimation_.get() stopAnimation]; | 185 [hideAnimation_.get() stopAnimation]; |
| 185 [hideTimer_ invalidate]; | 186 [hideTimer_ invalidate]; |
| 186 [infoBubble setAllowedAnimations:info_bubble::kAnimateNone]; | 187 [infoBubble setAllowedAnimations:info_bubble::kAnimateNone]; |
| 187 [self close]; | 188 [self close]; |
| 188 } | 189 } |
| 189 | 190 |
| 190 - (void)dealloc { | 191 - (void)dealloc { |
| 191 [hideAnimation_.get() stopAnimation]; | 192 [hideAnimation_.get() stopAnimation]; |
| 192 [hideTimer_ invalidate]; | 193 [hideTimer_ invalidate]; |
| 193 [super dealloc]; | 194 [super dealloc]; |
| 194 } | 195 } |
| 195 | 196 |
| 196 @end | 197 @end |
| 197 | 198 |
| 198 @implementation FullscreenExitBubbleController (PrivateMethods) | 199 @implementation ExclusiveAccessBubbleWindowController (PrivateMethods) |
| 199 | 200 |
| 200 - (void)initializeLabel { | 201 - (void)initializeLabel { |
| 201 // Replace the label placeholder NSTextField with the real label NSTextView. | 202 // 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 | 203 // 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 | 204 // in IB without a containing scroll view, so create the NSTextView |
| 204 // programmatically. | 205 // programmatically. |
| 205 exitLabel_.reset([[OneClickHyperlinkTextView alloc] | 206 exitLabel_.reset([[OneClickHyperlinkTextView alloc] |
| 206 initWithFrame:[exitLabelPlaceholder_ frame]]); | 207 initWithFrame:[exitLabelPlaceholder_ frame]]); |
| 207 [exitLabel_.get() setAutoresizingMask: | 208 [exitLabel_.get() |
| 208 [exitLabelPlaceholder_ autoresizingMask]]; | 209 setAutoresizingMask:[exitLabelPlaceholder_ autoresizingMask]]; |
| 209 [exitLabel_.get() setHidden:[exitLabelPlaceholder_ isHidden]]; | 210 [exitLabel_.get() setHidden:[exitLabelPlaceholder_ isHidden]]; |
| 210 [[exitLabelPlaceholder_ superview] | 211 [[exitLabelPlaceholder_ superview] replaceSubview:exitLabelPlaceholder_ |
| 211 replaceSubview:exitLabelPlaceholder_ with:exitLabel_.get()]; | 212 with:exitLabel_.get()]; |
| 212 exitLabelPlaceholder_ = nil; // Now released. | 213 exitLabelPlaceholder_ = nil; // Now released. |
| 213 [exitLabel_.get() setDelegate:self]; | 214 [exitLabel_.get() setDelegate:self]; |
| 214 | 215 |
| 215 NSString* exitLinkText; | 216 NSString* exitLinkText; |
| 216 NSString* exitUnlinkedText; | 217 NSString* exitUnlinkedText; |
| 217 if (bubbleType_ == FEB_TYPE_FULLSCREEN_MOUSELOCK_EXIT_INSTRUCTION || | 218 if (bubbleType_ == |
| 218 bubbleType_ == FEB_TYPE_MOUSELOCK_EXIT_INSTRUCTION) { | 219 EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_MOUSELOCK_EXIT_INSTRUCTION || |
| 220 bubbleType_ == EXCLUSIVE_ACCESS_BUBBLE_TYPE_MOUSELOCK_EXIT_INSTRUCTION) { |
| 219 exitLinkText = @""; | 221 exitLinkText = @""; |
| 220 exitUnlinkedText = [@" " stringByAppendingString: | 222 exitUnlinkedText = |
| 221 l10n_util::GetNSStringF(IDS_FULLSCREEN_PRESS_ESC_TO_EXIT, | 223 [@" " stringByAppendingString:l10n_util::GetNSStringF( |
| 222 l10n_util::GetStringUTF16(IDS_APP_ESC_KEY))]; | 224 IDS_FULLSCREEN_PRESS_ESC_TO_EXIT, |
| 225 l10n_util::GetStringUTF16( |
| 226 IDS_APP_ESC_KEY))]; |
| 223 } else { | 227 } else { |
| 224 exitLinkText = l10n_util::GetNSString(IDS_EXIT_FULLSCREEN_MODE); | 228 exitLinkText = l10n_util::GetNSString(IDS_EXIT_FULLSCREEN_MODE); |
| 225 exitUnlinkedText = [@" " stringByAppendingString: | 229 exitUnlinkedText = |
| 226 l10n_util::GetNSStringF(IDS_EXIT_FULLSCREEN_MODE_ACCELERATOR, | 230 [@" " stringByAppendingString:l10n_util::GetNSStringF( |
| 227 l10n_util::GetStringUTF16(IDS_APP_ESC_KEY))]; | 231 IDS_EXIT_FULLSCREEN_MODE_ACCELERATOR, |
| 232 l10n_util::GetStringUTF16( |
| 233 IDS_APP_ESC_KEY))]; |
| 228 } | 234 } |
| 229 | 235 |
| 230 NSFont* font = [NSFont systemFontOfSize: | 236 NSFont* font = [NSFont |
| 231 [NSFont systemFontSizeForControlSize:NSRegularControlSize]]; | 237 systemFontOfSize:[NSFont |
| 232 [(HyperlinkTextView*)exitLabel_.get() | 238 systemFontSizeForControlSize:NSRegularControlSize]]; |
| 233 setMessageAndLink:exitUnlinkedText | 239 [(HyperlinkTextView*)exitLabel_.get() setMessageAndLink:exitUnlinkedText |
| 234 withLink:exitLinkText | 240 withLink:exitLinkText |
| 235 atOffset:0 | 241 atOffset:0 |
| 236 font:font | 242 font:font |
| 237 messageColor:[NSColor blackColor] | 243 messageColor:[NSColor blackColor] |
| 238 linkColor:[NSColor blueColor]]; | 244 linkColor:[NSColor blueColor]]; |
| 239 [exitLabel_.get() setAlignment:NSRightTextAlignment]; | 245 [exitLabel_.get() setAlignment:NSRightTextAlignment]; |
| 240 | 246 |
| 241 NSRect labelFrame = [exitLabel_ frame]; | 247 NSRect labelFrame = [exitLabel_ frame]; |
| 242 | 248 |
| 243 // NSTextView's sizeToFit: method seems to enjoy wrapping lines. Temporarily | 249 // NSTextView's sizeToFit: method seems to enjoy wrapping lines. Temporarily |
| 244 // set the size large to force it not to. | 250 // set the size large to force it not to. |
| 245 NSRect windowFrame = [[self window] frame]; | 251 NSRect windowFrame = [[self window] frame]; |
| 246 [exitLabel_ setFrameSize:windowFrame.size]; | 252 [exitLabel_ setFrameSize:windowFrame.size]; |
| 247 NSLayoutManager* layoutManager = [exitLabel_ layoutManager]; | 253 NSLayoutManager* layoutManager = [exitLabel_ layoutManager]; |
| 248 NSTextContainer* textContainer = [exitLabel_ textContainer]; | 254 NSTextContainer* textContainer = [exitLabel_ textContainer]; |
| 249 [layoutManager ensureLayoutForTextContainer:textContainer]; | 255 [layoutManager ensureLayoutForTextContainer:textContainer]; |
| 250 NSRect textFrame = [layoutManager usedRectForTextContainer:textContainer]; | 256 NSRect textFrame = [layoutManager usedRectForTextContainer:textContainer]; |
| 251 | 257 |
| 252 textFrame.size.width = ceil(NSWidth(textFrame)); | 258 textFrame.size.width = ceil(NSWidth(textFrame)); |
| 253 labelFrame.origin.x += NSWidth(labelFrame) - NSWidth(textFrame); | 259 labelFrame.origin.x += NSWidth(labelFrame) - NSWidth(textFrame); |
| 254 labelFrame.size = textFrame.size; | 260 labelFrame.size = textFrame.size; |
| 255 [exitLabel_ setFrame:labelFrame]; | 261 [exitLabel_ setFrame:labelFrame]; |
| 256 } | 262 } |
| 257 | 263 |
| 258 - (NSString*)getLabelText { | 264 - (NSString*)getLabelText { |
| 259 if (bubbleType_ == FEB_TYPE_NONE) | 265 if (bubbleType_ == EXCLUSIVE_ACCESS_BUBBLE_TYPE_NONE) |
| 260 return @""; | 266 return @""; |
| 261 extensions::ExtensionRegistry* registry = | 267 extensions::ExtensionRegistry* registry = |
| 262 extensions::ExtensionRegistry::Get(browser_->profile()); | 268 extensions::ExtensionRegistry::Get(browser_->profile()); |
| 263 return SysUTF16ToNSString( | 269 return SysUTF16ToNSString(exclusive_access_bubble::GetLabelTextForType( |
| 264 fullscreen_bubble::GetLabelTextForType(bubbleType_, url_, registry)); | 270 bubbleType_, url_, registry)); |
| 265 } | 271 } |
| 266 | 272 |
| 267 // This looks at the Main Menu and determines what the user has set as the | 273 // This looks at the Main Menu and determines what the user has set as the |
| 268 // key combination for quit. It then gets the modifiers and builds an object | 274 // key combination for quit. It then gets the modifiers and builds an object |
| 269 // to hold the data. | 275 // to hold the data. |
| 270 + (scoped_ptr<ui::PlatformAcceleratorCocoa>)acceleratorForToggleFullscreen { | 276 + (scoped_ptr<ui::PlatformAcceleratorCocoa>)acceleratorForToggleFullscreen { |
| 271 NSMenu* mainMenu = [NSApp mainMenu]; | 277 NSMenu* mainMenu = [NSApp mainMenu]; |
| 272 // Get the application menu (i.e. Chromium). | 278 // Get the application menu (i.e. Chromium). |
| 273 for (NSMenuItem* menu in [mainMenu itemArray]) { | 279 for (NSMenuItem* menu in [mainMenu itemArray]) { |
| 274 for (NSMenuItem* item in [[menu submenu] itemArray]) { | 280 for (NSMenuItem* item in [[menu submenu] itemArray]) { |
| 275 // Find the toggle presentation mode item. | 281 // Find the toggle presentation mode item. |
| 276 if ([item tag] == IDC_PRESENTATION_MODE) { | 282 if ([item tag] == IDC_PRESENTATION_MODE) { |
| 277 return scoped_ptr<ui::PlatformAcceleratorCocoa>( | 283 return scoped_ptr<ui::PlatformAcceleratorCocoa>( |
| 278 new ui::PlatformAcceleratorCocoa([item keyEquivalent], | 284 new ui::PlatformAcceleratorCocoa([item keyEquivalent], |
| 279 [item keyEquivalentModifierMask])); | 285 [item keyEquivalentModifierMask])); |
| 280 } | 286 } |
| 281 } | 287 } |
| 282 } | 288 } |
| 283 // Default to Cmd+Shift+F. | 289 // Default to Cmd+Shift+F. |
| 284 return scoped_ptr<ui::PlatformAcceleratorCocoa>( | 290 return scoped_ptr<ui::PlatformAcceleratorCocoa>( |
| 285 new ui::PlatformAcceleratorCocoa(@"f", NSCommandKeyMask|NSShiftKeyMask)); | 291 new ui::PlatformAcceleratorCocoa(@"f", |
| 292 NSCommandKeyMask | NSShiftKeyMask)); |
| 286 } | 293 } |
| 287 | 294 |
| 288 // This looks at the Main Menu and determines what the user has set as the | 295 // This looks at the Main Menu and determines what the user has set as the |
| 289 // key combination for quit. It then gets the modifiers and builds a string | 296 // key combination for quit. It then gets the modifiers and builds a string |
| 290 // to display them. | 297 // to display them. |
| 291 + (NSString*)keyCommandString { | 298 + (NSString*)keyCommandString { |
| 292 scoped_ptr<ui::PlatformAcceleratorCocoa> accelerator( | 299 scoped_ptr<ui::PlatformAcceleratorCocoa> accelerator( |
| 293 [[self class] acceleratorForToggleFullscreen]); | 300 [[self class] acceleratorForToggleFullscreen]); |
| 294 return [[self class] keyCombinationForAccelerator:*accelerator]; | 301 return [[self class] keyCombinationForAccelerator:*accelerator]; |
| 295 } | 302 } |
| 296 | 303 |
| 297 + (NSString*)keyCombinationForAccelerator: | 304 + (NSString*)keyCombinationForAccelerator: |
| 298 (const ui::PlatformAcceleratorCocoa&)item { | 305 (const ui::PlatformAcceleratorCocoa&)item { |
| 299 NSMutableString* string = [NSMutableString string]; | 306 NSMutableString* string = [NSMutableString string]; |
| 300 NSUInteger modifiers = item.modifier_mask(); | 307 NSUInteger modifiers = item.modifier_mask(); |
| 301 | 308 |
| 302 if (modifiers & NSCommandKeyMask) | 309 if (modifiers & NSCommandKeyMask) |
| 303 [string appendString:@"\u2318"]; | 310 [string appendString:@"\u2318"]; |
| 304 if (modifiers & NSControlKeyMask) | 311 if (modifiers & NSControlKeyMask) |
| 305 [string appendString:@"\u2303"]; | 312 [string appendString:@"\u2303"]; |
| 306 if (modifiers & NSAlternateKeyMask) | 313 if (modifiers & NSAlternateKeyMask) |
| 307 [string appendString:@"\u2325"]; | 314 [string appendString:@"\u2325"]; |
| 308 BOOL isUpperCase = [[NSCharacterSet uppercaseLetterCharacterSet] | 315 BOOL isUpperCase = [[NSCharacterSet uppercaseLetterCharacterSet] |
| 309 characterIsMember:[item.characters() characterAtIndex:0]]; | 316 characterIsMember:[item.characters() characterAtIndex:0]]; |
| 310 if (modifiers & NSShiftKeyMask || isUpperCase) | 317 if (modifiers & NSShiftKeyMask || isUpperCase) |
| 311 [string appendString:@"\u21E7"]; | 318 [string appendString:@"\u21E7"]; |
| 312 | 319 |
| 313 [string appendString:[item.characters() uppercaseString]]; | 320 [string appendString:[item.characters() uppercaseString]]; |
| 314 return string; | 321 return string; |
| 315 } | 322 } |
| 316 | 323 |
| 317 - (void)hideSoon { | 324 - (void)hideSoon { |
| 318 hideTimer_.reset( | 325 hideTimer_.reset( |
| 319 [[NSTimer scheduledTimerWithTimeInterval:kInitialDelay | 326 [[NSTimer scheduledTimerWithTimeInterval:kInitialDelay |
| 320 target:self | 327 target:self |
| 321 selector:@selector(hideTimerFired:) | 328 selector:@selector(hideTimerFired:) |
| 322 userInfo:nil | 329 userInfo:nil |
| 323 repeats:NO] retain]); | 330 repeats:NO] retain]); |
| 324 } | 331 } |
| 325 | 332 |
| 326 @end | 333 @end |
| OLD | NEW |