Chromium Code Reviews| 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 | 33 |
| 34 namespace { | 34 namespace { |
| 35 const float kInitialDelay = 3.8; | 35 const float kInitialDelay = 3.8; |
| 36 const float kHideDuration = 0.7; | 36 const float kHideDuration = 0.7; |
| 37 } // namespace | 37 } // namespace |
| 38 | 38 |
| 39 @interface OneClickHyperlinkTextView : HyperlinkTextView | 39 @interface OneClickHyperlinkTextView : HyperlinkTextView |
| 40 @end | 40 @end |
| 41 @implementation OneClickHyperlinkTextView | 41 @implementation OneClickHyperlinkTextView |
| 42 - (BOOL)acceptsFirstMouse:(NSEvent*)event { | 42 - (BOOL)acceptsFirstMouse:(NSEvent*)event { |
| 43 return YES; | 43 return YES; |
| 44 } | 44 } |
| 45 @end | 45 @end |
| 46 | 46 |
| 47 @interface FullscreenExitBubbleController (PrivateMethods) | 47 @interface ExclusiveAccessBubbleWindowController (PrivateMethods) |
| 48 // Sets |exitLabel_| based on |exitLabelPlaceholder_|, | 48 // Sets |exitLabel_| based on |exitLabelPlaceholder_|, |
| 49 // sets |exitLabelPlaceholder_| to nil. | 49 // sets |exitLabelPlaceholder_| to nil. |
| 50 - (void)initializeLabel; | 50 - (void)initializeLabel; |
| 51 | 51 |
| 52 - (NSString*)getLabelText; | 52 - (NSString*)getLabelText; |
| 53 | 53 |
| 54 - (void)hideSoon; | 54 - (void)hideSoon; |
| 55 | 55 |
| 56 // Returns the Accelerator for the Toggle Fullscreen menu item. | 56 // Returns the Accelerator for the Toggle Fullscreen menu item. |
| 57 + (scoped_ptr<ui::PlatformAcceleratorCocoa>)acceleratorForToggleFullscreen; | 57 + (scoped_ptr<ui::PlatformAcceleratorCocoa>)acceleratorForToggleFullscreen; |
| 58 | 58 |
| 59 // Returns a string representation fit for display of | 59 // Returns a string representation fit for display of |
| 60 // +acceleratorForToggleFullscreen. | 60 // +acceleratorForToggleFullscreen. |
| 61 + (NSString*)keyCommandString; | 61 + (NSString*)keyCommandString; |
| 62 | 62 |
| 63 + (NSString*)keyCombinationForAccelerator: | 63 + (NSString*)keyCombinationForAccelerator: |
| 64 (const ui::PlatformAcceleratorCocoa&)item; | 64 (const ui::PlatformAcceleratorCocoa&)item; |
| 65 @end | 65 @end |
| 66 | 66 |
| 67 @implementation FullscreenExitBubbleController | 67 @implementation ExclusiveAccessBubbleWindowController |
| 68 | 68 |
| 69 - (id)initWithOwner:(BrowserWindowController*)owner | 69 - (id)initWithOwner:(BrowserWindowController*)owner |
| 70 browser:(Browser*)browser | 70 browser:(Browser*)browser |
| 71 url:(const GURL&)url | 71 url:(const GURL&)url |
| 72 bubbleType:(FullscreenExitBubbleType)bubbleType { | 72 bubbleType:(ExclusiveAccessBubbleType)bubbleType { |
| 73 NSString* nibPath = | 73 NSString* nibPath = |
| 74 [base::mac::FrameworkBundle() pathForResource:@"FullscreenExitBubble" | 74 [base::mac::FrameworkBundle() pathForResource:@"ExclusiveAccessBubble" |
| 75 ofType:@"nib"]; | 75 ofType:@"nib"]; |
| 76 if ((self = [super initWithWindowNibPath:nibPath owner:self])) { | 76 if ((self = [super initWithWindowNibPath:nibPath owner:self])) { |
| 77 browser_ = browser; | 77 browser_ = browser; |
| 78 owner_ = owner; | 78 owner_ = owner; |
| 79 url_ = url; | 79 url_ = url; |
| 80 bubbleType_ = bubbleType; | 80 bubbleType_ = bubbleType; |
| 81 // Mouse lock expects mouse events to reach the main window immediately. | 81 // Mouse lock expects mouse events to reach the main window immediately. |
| 82 // Make the bubble transparent for mouse events if mouse lock is enabled. | 82 // Make the bubble transparent for mouse events if mouse lock is enabled. |
| 83 if (bubbleType_ == FEB_TYPE_FULLSCREEN_MOUSELOCK_EXIT_INSTRUCTION || | 83 if (bubbleType_ == EAB_TYPE_FULLSCREEN_MOUSELOCK_EXIT_INSTRUCTION || |
|
sky
2014/12/12 00:00:37
I get why you went with EAB here, but IMO the supe
| |
| 84 bubbleType_ == FEB_TYPE_MOUSELOCK_EXIT_INSTRUCTION) | 84 bubbleType_ == EAB_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_ == EAB_TYPE_FULLSCREEN_MOUSELOCK_BUTTONS || |
| 95 bubbleType_ == FEB_TYPE_MOUSELOCK_BUTTONS) | 95 bubbleType_ == EAB_TYPE_MOUSELOCK_BUTTONS) |
| 96 [[self window] setIgnoresMouseEvents:YES]; | 96 [[self window] setIgnoresMouseEvents:YES]; |
| 97 | 97 |
| 98 DCHECK(fullscreen_bubble::ShowButtonsForType(bubbleType_)); | 98 DCHECK(exclusive_access_bubble::ShowButtonsForType(bubbleType_)); |
| 99 browser_->fullscreen_controller()->OnAcceptFullscreenPermission(); | 99 browser_->fullscreen_controller()->OnAcceptFullscreenPermission(); |
| 100 } | 100 } |
| 101 | 101 |
| 102 - (void)deny:(id)sender { | 102 - (void)deny:(id)sender { |
| 103 DCHECK(fullscreen_bubble::ShowButtonsForType(bubbleType_)); | 103 DCHECK(exclusive_access_bubble::ShowButtonsForType(bubbleType_)); |
| 104 browser_->fullscreen_controller()->OnDenyFullscreenPermission(); | 104 browser_->fullscreen_controller()->OnDenyFullscreenPermission(); |
| 105 } | 105 } |
| 106 | 106 |
| 107 - (void)showButtons:(BOOL)show { | 107 - (void)showButtons:(BOOL)show { |
| 108 [allowButton_ setHidden:!show]; | 108 [allowButton_ setHidden:!show]; |
| 109 [denyButton_ setHidden:!show]; | 109 [denyButton_ setHidden:!show]; |
| 110 [exitLabel_ setHidden:show]; | 110 [exitLabel_ setHidden:show]; |
| 111 } | 111 } |
| 112 | 112 |
| 113 // We want this to be a child of a browser window. addChildWindow: | 113 // We want this to be a child of a browser window. addChildWindow: |
| 114 // (called from this function) will bring the window on-screen; | 114 // (called from this function) will bring the window on-screen; |
| 115 // unfortunately, [NSWindowController showWindow:] will also bring it | 115 // unfortunately, [NSWindowController showWindow:] will also bring it |
| 116 // on-screen (but will cause unexpected changes to the window's | 116 // on-screen (but will cause unexpected changes to the window's |
| 117 // position). We cannot have an addChildWindow: and a subsequent | 117 // position). We cannot have an addChildWindow: and a subsequent |
| 118 // showWindow:. Thus, we have our own version. | 118 // showWindow:. Thus, we have our own version. |
| 119 - (void)showWindow { | 119 - (void)showWindow { |
| 120 // Completes nib load. | 120 // Completes nib load. |
| 121 InfoBubbleWindow* info_bubble = static_cast<InfoBubbleWindow*>([self window]); | 121 InfoBubbleWindow* info_bubble = static_cast<InfoBubbleWindow*>([self window]); |
| 122 [info_bubble setCanBecomeKeyWindow:NO]; | 122 [info_bubble setCanBecomeKeyWindow:NO]; |
| 123 if (!fullscreen_bubble::ShowButtonsForType(bubbleType_)) { | 123 if (!exclusive_access_bubble::ShowButtonsForType(bubbleType_)) { |
| 124 [self showButtons:NO]; | 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 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 152 clickedOnLink:(id)link | 152 clickedOnLink:(id)link |
| 153 atIndex:(NSUInteger)charIndex { | 153 atIndex:(NSUInteger)charIndex { |
| 154 browser_->fullscreen_controller()-> | 154 browser_->fullscreen_controller()-> |
| 155 ExitTabOrBrowserFullscreenToPreviousState(); | 155 ExitTabOrBrowserFullscreenToPreviousState(); |
| 156 return YES; | 156 return YES; |
| 157 } | 157 } |
| 158 | 158 |
| 159 - (void)hideTimerFired:(NSTimer*)timer { | 159 - (void)hideTimerFired:(NSTimer*)timer { |
| 160 // This might fire racily for buttoned bubbles, even though the timer is | 160 // This might fire racily for buttoned bubbles, even though the timer is |
| 161 // cancelled for them. Explicitly check for this case. | 161 // cancelled for them. Explicitly check for this case. |
| 162 if (fullscreen_bubble::ShowButtonsForType(bubbleType_)) | 162 if (exclusive_access_bubble::ShowButtonsForType(bubbleType_)) |
| 163 return; | 163 return; |
| 164 | 164 |
| 165 [NSAnimationContext beginGrouping]; | 165 [NSAnimationContext beginGrouping]; |
| 166 [[NSAnimationContext currentContext] | 166 [[NSAnimationContext currentContext] |
| 167 gtm_setDuration:kHideDuration | 167 gtm_setDuration:kHideDuration |
| 168 eventMask:NSLeftMouseUpMask|NSLeftMouseDownMask]; | 168 eventMask:NSLeftMouseUpMask|NSLeftMouseDownMask]; |
| 169 [[[self window] animator] setAlphaValue:0.0]; | 169 [[[self window] animator] setAlphaValue:0.0]; |
| 170 [NSAnimationContext endGrouping]; | 170 [NSAnimationContext endGrouping]; |
| 171 } | 171 } |
| 172 | 172 |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 188 } | 188 } |
| 189 | 189 |
| 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 FullscreenExitBubbleController (PrivateMethods) | 198 @implementation ExclusiveAccessBubbleWindowController (PrivateMethods) |
| 199 | 199 |
| 200 - (void)initializeLabel { | 200 - (void)initializeLabel { |
| 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() setAutoresizingMask: | 207 [exitLabel_.get() setAutoresizingMask: |
| 208 [exitLabelPlaceholder_ autoresizingMask]]; | 208 [exitLabelPlaceholder_ autoresizingMask]]; |
| 209 [exitLabel_.get() setHidden:[exitLabelPlaceholder_ isHidden]]; | 209 [exitLabel_.get() setHidden:[exitLabelPlaceholder_ isHidden]]; |
| 210 [[exitLabelPlaceholder_ superview] | 210 [[exitLabelPlaceholder_ superview] |
| 211 replaceSubview:exitLabelPlaceholder_ with:exitLabel_.get()]; | 211 replaceSubview:exitLabelPlaceholder_ with:exitLabel_.get()]; |
| 212 exitLabelPlaceholder_ = nil; // Now released. | 212 exitLabelPlaceholder_ = nil; // Now released. |
| 213 [exitLabel_.get() setDelegate:self]; | 213 [exitLabel_.get() setDelegate:self]; |
| 214 | 214 |
| 215 NSString* exitLinkText; | 215 NSString* exitLinkText; |
| 216 NSString* exitUnlinkedText; | 216 NSString* exitUnlinkedText; |
| 217 if (bubbleType_ == FEB_TYPE_FULLSCREEN_MOUSELOCK_EXIT_INSTRUCTION || | 217 if (bubbleType_ == EAB_TYPE_FULLSCREEN_MOUSELOCK_EXIT_INSTRUCTION || |
| 218 bubbleType_ == FEB_TYPE_MOUSELOCK_EXIT_INSTRUCTION) { | 218 bubbleType_ == EAB_TYPE_MOUSELOCK_EXIT_INSTRUCTION) { |
| 219 exitLinkText = @""; | 219 exitLinkText = @""; |
| 220 exitUnlinkedText = [@" " stringByAppendingString: | 220 exitUnlinkedText = [@" " stringByAppendingString: |
| 221 l10n_util::GetNSStringF(IDS_FULLSCREEN_PRESS_ESC_TO_EXIT, | 221 l10n_util::GetNSStringF(IDS_FULLSCREEN_PRESS_ESC_TO_EXIT, |
| 222 l10n_util::GetStringUTF16(IDS_APP_ESC_KEY))]; | 222 l10n_util::GetStringUTF16(IDS_APP_ESC_KEY))]; |
| 223 } else { | 223 } else { |
| 224 exitLinkText = l10n_util::GetNSString(IDS_EXIT_FULLSCREEN_MODE); | 224 exitLinkText = l10n_util::GetNSString(IDS_EXIT_FULLSCREEN_MODE); |
| 225 exitUnlinkedText = [@" " stringByAppendingString: | 225 exitUnlinkedText = [@" " stringByAppendingString: |
| 226 l10n_util::GetNSStringF(IDS_EXIT_FULLSCREEN_MODE_ACCELERATOR, | 226 l10n_util::GetNSStringF(IDS_EXIT_FULLSCREEN_MODE_ACCELERATOR, |
| 227 l10n_util::GetStringUTF16(IDS_APP_ESC_KEY))]; | 227 l10n_util::GetStringUTF16(IDS_APP_ESC_KEY))]; |
| 228 } | 228 } |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 249 [layoutManager ensureLayoutForTextContainer:textContainer]; | 249 [layoutManager ensureLayoutForTextContainer:textContainer]; |
| 250 NSRect textFrame = [layoutManager usedRectForTextContainer:textContainer]; | 250 NSRect textFrame = [layoutManager usedRectForTextContainer:textContainer]; |
| 251 | 251 |
| 252 textFrame.size.width = ceil(NSWidth(textFrame)); | 252 textFrame.size.width = ceil(NSWidth(textFrame)); |
| 253 labelFrame.origin.x += NSWidth(labelFrame) - NSWidth(textFrame); | 253 labelFrame.origin.x += NSWidth(labelFrame) - NSWidth(textFrame); |
| 254 labelFrame.size = textFrame.size; | 254 labelFrame.size = textFrame.size; |
| 255 [exitLabel_ setFrame:labelFrame]; | 255 [exitLabel_ setFrame:labelFrame]; |
| 256 } | 256 } |
| 257 | 257 |
| 258 - (NSString*)getLabelText { | 258 - (NSString*)getLabelText { |
| 259 if (bubbleType_ == FEB_TYPE_NONE) | 259 if (bubbleType_ == EAB_TYPE_NONE) |
| 260 return @""; | 260 return @""; |
| 261 extensions::ExtensionRegistry* registry = | 261 extensions::ExtensionRegistry* registry = |
| 262 extensions::ExtensionRegistry::Get(browser_->profile()); | 262 extensions::ExtensionRegistry::Get(browser_->profile()); |
| 263 return SysUTF16ToNSString( | 263 return SysUTF16ToNSString( |
| 264 fullscreen_bubble::GetLabelTextForType(bubbleType_, url_, registry)); | 264 exclusive_access_bubble::GetLabelTextForType(bubbleType_, |
| 265 url_, | |
| 266 registry)); | |
| 265 } | 267 } |
| 266 | 268 |
| 267 // This looks at the Main Menu and determines what the user has set as the | 269 // 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 | 270 // key combination for quit. It then gets the modifiers and builds an object |
| 269 // to hold the data. | 271 // to hold the data. |
| 270 + (scoped_ptr<ui::PlatformAcceleratorCocoa>)acceleratorForToggleFullscreen { | 272 + (scoped_ptr<ui::PlatformAcceleratorCocoa>)acceleratorForToggleFullscreen { |
| 271 NSMenu* mainMenu = [NSApp mainMenu]; | 273 NSMenu* mainMenu = [NSApp mainMenu]; |
| 272 // Get the application menu (i.e. Chromium). | 274 // Get the application menu (i.e. Chromium). |
| 273 for (NSMenuItem* menu in [mainMenu itemArray]) { | 275 for (NSMenuItem* menu in [mainMenu itemArray]) { |
| 274 for (NSMenuItem* item in [[menu submenu] itemArray]) { | 276 for (NSMenuItem* item in [[menu submenu] itemArray]) { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 317 - (void)hideSoon { | 319 - (void)hideSoon { |
| 318 hideTimer_.reset( | 320 hideTimer_.reset( |
| 319 [[NSTimer scheduledTimerWithTimeInterval:kInitialDelay | 321 [[NSTimer scheduledTimerWithTimeInterval:kInitialDelay |
| 320 target:self | 322 target:self |
| 321 selector:@selector(hideTimerFired:) | 323 selector:@selector(hideTimerFired:) |
| 322 userInfo:nil | 324 userInfo:nil |
| 323 repeats:NO] retain]); | 325 repeats:NO] retain]); |
| 324 } | 326 } |
| 325 | 327 |
| 326 @end | 328 @end |
| OLD | NEW |