| 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" |
| 11 #include "chrome/app/chrome_command_ids.h" | 11 #include "chrome/app/chrome_command_ids.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/ui/browser.h" | |
| 14 #include "chrome/browser/ui/browser_commands.h" | 13 #include "chrome/browser/ui/browser_commands.h" |
| 15 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | |
| 16 #import "chrome/browser/ui/cocoa/exclusive_access_bubble_window_controller.h" | 14 #import "chrome/browser/ui/cocoa/exclusive_access_bubble_window_controller.h" |
| 17 #import "chrome/browser/ui/cocoa/info_bubble_view.h" | 15 #import "chrome/browser/ui/cocoa/info_bubble_view.h" |
| 18 #import "chrome/browser/ui/cocoa/info_bubble_window.h" | 16 #import "chrome/browser/ui/cocoa/info_bubble_window.h" |
| 17 #import "chrome/browser/ui/cocoa/tabs/tab_window_controller.h" |
| 19 #include "chrome/browser/ui/exclusive_access/exclusive_access_bubble_type.h" | 18 #include "chrome/browser/ui/exclusive_access/exclusive_access_bubble_type.h" |
| 19 #include "chrome/browser/ui/exclusive_access/exclusive_access_manager.h" |
| 20 #include "chrome/browser/ui/exclusive_access/fullscreen_controller.h" | 20 #include "chrome/browser/ui/exclusive_access/fullscreen_controller.h" |
| 21 #include "chrome/grit/generated_resources.h" | 21 #include "chrome/grit/generated_resources.h" |
| 22 #include "extensions/browser/extension_registry.h" | 22 #include "extensions/browser/extension_registry.h" |
| 23 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMNSAnimation+Duration.h
" | 23 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMNSAnimation+Duration.h
" |
| 24 #include "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutT
weaker.h" | 24 #include "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutT
weaker.h" |
| 25 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTw
eaker.h" | 25 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTw
eaker.h" |
| 26 #include "ui/base/accelerators/platform_accelerator_cocoa.h" | 26 #include "ui/base/accelerators/platform_accelerator_cocoa.h" |
| 27 #import "ui/base/cocoa/controls/hyperlink_text_view.h" | 27 #import "ui/base/cocoa/controls/hyperlink_text_view.h" |
| 28 #include "ui/base/l10n/l10n_util.h" | 28 #include "ui/base/l10n/l10n_util.h" |
| 29 #include "ui/base/l10n/l10n_util_mac.h" | 29 #include "ui/base/l10n/l10n_util_mac.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 58 // Returns a string representation fit for display of | 58 // Returns a string representation fit for display of |
| 59 // +acceleratorForToggleFullscreen. | 59 // +acceleratorForToggleFullscreen. |
| 60 + (NSString*)keyCommandString; | 60 + (NSString*)keyCommandString; |
| 61 | 61 |
| 62 + (NSString*)keyCombinationForAccelerator: | 62 + (NSString*)keyCombinationForAccelerator: |
| 63 (const ui::PlatformAcceleratorCocoa&)item; | 63 (const ui::PlatformAcceleratorCocoa&)item; |
| 64 @end | 64 @end |
| 65 | 65 |
| 66 @implementation ExclusiveAccessBubbleWindowController | 66 @implementation ExclusiveAccessBubbleWindowController |
| 67 | 67 |
| 68 - (id)initWithOwner:(BrowserWindowController*)owner | 68 - (id)initWithOwner:(NSWindowController*)owner |
| 69 browser:(Browser*)browser | 69 exclusive_access_manager:(ExclusiveAccessManager*)exclusive_access_manager |
| 70 url:(const GURL&)url | 70 profile:(Profile*)profile |
| 71 bubbleType:(ExclusiveAccessBubbleType)bubbleType { | 71 url:(const GURL&)url |
| 72 bubbleType:(ExclusiveAccessBubbleType)bubbleType { |
| 72 NSString* nibPath = | 73 NSString* nibPath = |
| 73 [base::mac::FrameworkBundle() pathForResource:@"ExclusiveAccessBubble" | 74 [base::mac::FrameworkBundle() pathForResource:@"ExclusiveAccessBubble" |
| 74 ofType:@"nib"]; | 75 ofType:@"nib"]; |
| 75 if ((self = [super initWithWindowNibPath:nibPath owner:self])) { | 76 if ((self = [super initWithWindowNibPath:nibPath owner:self])) { |
| 76 browser_ = browser; | 77 exclusive_access_manager_ = exclusive_access_manager; |
| 78 profile_ = profile; |
| 77 owner_ = owner; | 79 owner_ = owner; |
| 78 url_ = url; | 80 url_ = url; |
| 79 bubbleType_ = bubbleType; | 81 bubbleType_ = bubbleType; |
| 80 // Mouse lock expects mouse events to reach the main window immediately. | 82 // Mouse lock expects mouse events to reach the main window immediately. |
| 81 // Make the bubble transparent for mouse events if mouse lock is enabled. | 83 // Make the bubble transparent for mouse events if mouse lock is enabled. |
| 82 if (bubbleType_ == | 84 if (bubbleType_ == |
| 83 EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_MOUSELOCK_EXIT_INSTRUCTION |
| | 85 EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_MOUSELOCK_EXIT_INSTRUCTION |
| |
| 84 bubbleType_ == EXCLUSIVE_ACCESS_BUBBLE_TYPE_MOUSELOCK_EXIT_INSTRUCTION) | 86 bubbleType_ == EXCLUSIVE_ACCESS_BUBBLE_TYPE_MOUSELOCK_EXIT_INSTRUCTION) |
| 85 [[self window] setIgnoresMouseEvents:YES]; | 87 [[self window] setIgnoresMouseEvents:YES]; |
| 86 } | 88 } |
| 87 return self; | 89 return self; |
| 88 } | 90 } |
| 89 | 91 |
| 90 - (void)allow:(id)sender { | 92 - (void)allow:(id)sender { |
| 91 // The mouselock code expects that mouse events reach the main window | 93 // The mouselock code expects that mouse events reach the main window |
| 92 // immediately, but the cursor is still over the bubble, which eats the | 94 // immediately, but the cursor is still over the bubble, which eats the |
| 93 // mouse events. Make the bubble transparent for mouse events. | 95 // mouse events. Make the bubble transparent for mouse events. |
| 94 if (bubbleType_ == | 96 if (bubbleType_ == |
| 95 EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_MOUSELOCK_BUTTONS || | 97 EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_MOUSELOCK_BUTTONS || |
| 96 bubbleType_ == EXCLUSIVE_ACCESS_BUBBLE_TYPE_MOUSELOCK_BUTTONS) | 98 bubbleType_ == EXCLUSIVE_ACCESS_BUBBLE_TYPE_MOUSELOCK_BUTTONS) |
| 97 [[self window] setIgnoresMouseEvents:YES]; | 99 [[self window] setIgnoresMouseEvents:YES]; |
| 98 | 100 |
| 99 DCHECK(exclusive_access_bubble::ShowButtonsForType(bubbleType_)); | 101 DCHECK(exclusive_access_bubble::ShowButtonsForType(bubbleType_)); |
| 100 browser_->exclusive_access_manager()->OnAcceptExclusiveAccessPermission(); | 102 exclusive_access_manager_->OnAcceptExclusiveAccessPermission(); |
| 101 } | 103 } |
| 102 | 104 |
| 103 - (void)deny:(id)sender { | 105 - (void)deny:(id)sender { |
| 104 DCHECK(exclusive_access_bubble::ShowButtonsForType(bubbleType_)); | 106 DCHECK(exclusive_access_bubble::ShowButtonsForType(bubbleType_)); |
| 105 browser_->exclusive_access_manager()->OnDenyExclusiveAccessPermission(); | 107 exclusive_access_manager_->OnDenyExclusiveAccessPermission(); |
| 106 } | 108 } |
| 107 | 109 |
| 108 - (void)showButtons:(BOOL)show { | 110 - (void)showButtons:(BOOL)show { |
| 109 [allowButton_ setHidden:!show]; | 111 [allowButton_ setHidden:!show]; |
| 110 [denyButton_ setHidden:!show]; | 112 [denyButton_ setHidden:!show]; |
| 111 [exitLabel_ setHidden:show]; | 113 [exitLabel_ setHidden:show]; |
| 112 } | 114 } |
| 113 | 115 |
| 114 // We want this to be a child of a browser window. addChildWindow: | 116 // We want this to be a child of a browser window. addChildWindow: |
| 115 // (called from this function) will bring the window on-screen; | 117 // (called from this function) will bring the window on-screen; |
| 116 // unfortunately, [NSWindowController showWindow:] will also bring it | 118 // unfortunately, [NSWindowController showWindow:] will also bring it |
| 117 // on-screen (but will cause unexpected changes to the window's | 119 // on-screen (but will cause unexpected changes to the window's |
| 118 // position). We cannot have an addChildWindow: and a subsequent | 120 // position). We cannot have an addChildWindow: and a subsequent |
| 119 // showWindow:. Thus, we have our own version. | 121 // showWindow:. Thus, we have our own version. |
| 120 - (void)showWindow { | 122 - (void)showWindow { |
| 121 // Completes nib load. | 123 // Completes nib load. |
| 122 InfoBubbleWindow* info_bubble = static_cast<InfoBubbleWindow*>([self window]); | 124 InfoBubbleWindow* info_bubble = static_cast<InfoBubbleWindow*>([self window]); |
| 123 [info_bubble setCanBecomeKeyWindow:NO]; | 125 [info_bubble setCanBecomeKeyWindow:NO]; |
| 124 if (!exclusive_access_bubble::ShowButtonsForType(bubbleType_)) { | 126 if (!exclusive_access_bubble::ShowButtonsForType(bubbleType_)) { |
| 125 [self hideSoon]; | 127 [self hideSoon]; |
| 126 } | 128 } |
| 127 [tweaker_ tweakUI:info_bubble]; | 129 [tweaker_ tweakUI:info_bubble]; |
| 128 [[owner_ window] addChildWindow:info_bubble ordered:NSWindowAbove]; | 130 [[owner_ window] addChildWindow:info_bubble ordered:NSWindowAbove]; |
| 129 [owner_ layoutSubviews]; | 131 |
| 132 if ([owner_ respondsToSelector:@selector(layoutSubviews)]) |
| 133 [(id)owner_ layoutSubviews]; |
| 130 | 134 |
| 131 [info_bubble orderFront:self]; | 135 [info_bubble orderFront:self]; |
| 132 } | 136 } |
| 133 | 137 |
| 134 - (void)awakeFromNib { | 138 - (void)awakeFromNib { |
| 135 DCHECK([[self window] isKindOfClass:[InfoBubbleWindow class]]); | 139 DCHECK([[self window] isKindOfClass:[InfoBubbleWindow class]]); |
| 136 [messageLabel_ setStringValue:[self getLabelText]]; | 140 [messageLabel_ setStringValue:[self getLabelText]]; |
| 137 [self initializeLabelAndButton]; | 141 [self initializeLabelAndButton]; |
| 138 } | 142 } |
| 139 | 143 |
| 140 - (void)positionInWindowAtTop:(CGFloat)maxY width:(CGFloat)maxWidth { | 144 - (void)positionInWindowAtTop:(CGFloat)maxY width:(CGFloat)maxWidth { |
| 141 NSRect windowFrame = [self window].frame; | 145 NSRect windowFrame = [self window].frame; |
| 142 NSRect ownerWindowFrame = [owner_ window].frame; | 146 NSRect ownerWindowFrame = [owner_ window].frame; |
| 143 NSPoint origin; | 147 NSPoint origin; |
| 144 origin.x = ownerWindowFrame.origin.x + | 148 origin.x = ownerWindowFrame.origin.x + |
| 145 (int)(NSWidth(ownerWindowFrame) / 2 - NSWidth(windowFrame) / 2); | 149 (int)(NSWidth(ownerWindowFrame) / 2 - NSWidth(windowFrame) / 2); |
| 146 origin.y = ownerWindowFrame.origin.y + maxY - NSHeight(windowFrame); | 150 origin.y = ownerWindowFrame.origin.y + maxY - NSHeight(windowFrame); |
| 147 [[self window] setFrameOrigin:origin]; | 151 [[self window] setFrameOrigin:origin]; |
| 148 } | 152 } |
| 149 | 153 |
| 150 // Called when someone clicks on the embedded link. | 154 // Called when someone clicks on the embedded link. |
| 151 - (BOOL)textView:(NSTextView*)textView | 155 - (BOOL)textView:(NSTextView*)textView |
| 152 clickedOnLink:(id)link | 156 clickedOnLink:(id)link |
| 153 atIndex:(NSUInteger)charIndex { | 157 atIndex:(NSUInteger)charIndex { |
| 154 browser_->exclusive_access_manager() | 158 exclusive_access_manager_->fullscreen_controller() |
| 155 ->fullscreen_controller() | |
| 156 ->ExitExclusiveAccessToPreviousState(); | 159 ->ExitExclusiveAccessToPreviousState(); |
| 157 return YES; | 160 return YES; |
| 158 } | 161 } |
| 159 | 162 |
| 160 - (void)hideTimerFired:(NSTimer*)timer { | 163 - (void)hideTimerFired:(NSTimer*)timer { |
| 161 // This might fire racily for buttoned bubbles, even though the timer is | 164 // This might fire racily for buttoned bubbles, even though the timer is |
| 162 // cancelled for them. Explicitly check for this case. | 165 // cancelled for them. Explicitly check for this case. |
| 163 if (exclusive_access_bubble::ShowButtonsForType(bubbleType_)) | 166 if (exclusive_access_bubble::ShowButtonsForType(bubbleType_)) |
| 164 return; | 167 return; |
| 165 | 168 |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 [allowButton_ setTitle:allowButtonText]; | 277 [allowButton_ setTitle:allowButtonText]; |
| 275 } else { | 278 } else { |
| 276 [self showButtons:NO]; | 279 [self showButtons:NO]; |
| 277 } | 280 } |
| 278 } | 281 } |
| 279 | 282 |
| 280 - (NSString*)getLabelText { | 283 - (NSString*)getLabelText { |
| 281 if (bubbleType_ == EXCLUSIVE_ACCESS_BUBBLE_TYPE_NONE) | 284 if (bubbleType_ == EXCLUSIVE_ACCESS_BUBBLE_TYPE_NONE) |
| 282 return @""; | 285 return @""; |
| 283 extensions::ExtensionRegistry* registry = | 286 extensions::ExtensionRegistry* registry = |
| 284 extensions::ExtensionRegistry::Get(browser_->profile()); | 287 extensions::ExtensionRegistry::Get(profile_); |
| 285 return SysUTF16ToNSString(exclusive_access_bubble::GetLabelTextForType( | 288 return SysUTF16ToNSString(exclusive_access_bubble::GetLabelTextForType( |
| 286 bubbleType_, url_, registry)); | 289 bubbleType_, url_, registry)); |
| 287 } | 290 } |
| 288 | 291 |
| 289 // This looks at the Main Menu and determines what the user has set as the | 292 // This looks at the Main Menu and determines what the user has set as the |
| 290 // key combination for quit. It then gets the modifiers and builds an object | 293 // key combination for quit. It then gets the modifiers and builds an object |
| 291 // to hold the data. | 294 // to hold the data. |
| 292 + (scoped_ptr<ui::PlatformAcceleratorCocoa>)acceleratorForToggleFullscreen { | 295 + (scoped_ptr<ui::PlatformAcceleratorCocoa>)acceleratorForToggleFullscreen { |
| 293 NSMenu* mainMenu = [NSApp mainMenu]; | 296 NSMenu* mainMenu = [NSApp mainMenu]; |
| 294 // Get the application menu (i.e. Chromium). | 297 // Get the application menu (i.e. Chromium). |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 - (void)hideSoon { | 343 - (void)hideSoon { |
| 341 hideTimer_.reset( | 344 hideTimer_.reset( |
| 342 [[NSTimer scheduledTimerWithTimeInterval:kInitialDelay | 345 [[NSTimer scheduledTimerWithTimeInterval:kInitialDelay |
| 343 target:self | 346 target:self |
| 344 selector:@selector(hideTimerFired:) | 347 selector:@selector(hideTimerFired:) |
| 345 userInfo:nil | 348 userInfo:nil |
| 346 repeats:NO] retain]); | 349 repeats:NO] retain]); |
| 347 } | 350 } |
| 348 | 351 |
| 349 @end | 352 @end |
| OLD | NEW |