Chromium Code Reviews| Index: chrome/browser/ui/cocoa/fullscreen_exit_bubble_controller.mm |
| diff --git a/chrome/browser/ui/cocoa/fullscreen_exit_bubble_controller.mm b/chrome/browser/ui/cocoa/fullscreen_exit_bubble_controller.mm |
| index b3829bd5d9a601e14be9a02befa80583d4d08801..42cea83ca1ed9b34756ede5e7068c50316edc06b 100644 |
| --- a/chrome/browser/ui/cocoa/fullscreen_exit_bubble_controller.mm |
| +++ b/chrome/browser/ui/cocoa/fullscreen_exit_bubble_controller.mm |
| @@ -7,23 +7,33 @@ |
| #include "base/logging.h" // for NOTREACHED() |
| #include "base/mac/mac_util.h" |
| #include "base/sys_string_conversions.h" |
| +#include "base/utf_string_conversions.h" |
| #include "chrome/app/chrome_command_ids.h" |
| #include "chrome/browser/ui/browser.h" |
| #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| -#import "chrome/browser/ui/cocoa/animatable_view.h" |
| #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
| #include "chrome/browser/ui/cocoa/event_utils.h" |
| #import "chrome/browser/ui/cocoa/fullscreen_exit_bubble_controller.h" |
| #import "chrome/browser/ui/cocoa/hyperlink_text_view.h" |
| +#import "chrome/browser/ui/cocoa/info_bubble_view.h" |
| +#import "chrome/browser/ui/cocoa/info_bubble_window.h" |
| #include "grit/generated_resources.h" |
| #include "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h" |
| #import "third_party/GTM/AppKit/GTMNSAnimation+Duration.h" |
| +#import "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h" |
| #include "ui/base/models/accelerator_cocoa.h" |
| #include "ui/base/l10n/l10n_util_mac.h" |
| -const int kPaddingPx = 8; |
| const int kInitialDelayMs = 3800; |
| -const int kSlideOutDurationMs = 700; |
| +const int kHideDurationMs = 700; |
| + |
| +@interface OneClickHyperlinkTextView : HyperlinkTextView |
| +@end |
| +@implementation OneClickHyperlinkTextView |
| +- (BOOL)acceptsFirstMouse:(NSEvent*)event { |
| + return YES; |
| +} |
| +@end |
| @interface FullscreenExitBubbleController (PrivateMethods) |
| // Sets |exitLabel_| based on |exitLabelPlaceholder_|, |
| @@ -44,25 +54,75 @@ const int kSlideOutDurationMs = 700; |
| @implementation FullscreenExitBubbleController |
| -- (id)initWithOwner:(BrowserWindowController*)owner browser:(Browser*)browser { |
| - if ((self = [super initWithNibName:@"FullscreenExitBubble" |
| - bundle:base::mac::MainAppBundle()])) { |
| +- (id)initWithOwner:(BrowserWindowController*)owner |
| + browser:(Browser*)browser |
| + forURL:(const GURL&)url |
| + askPermission:(BOOL)askPermission { |
| + NSString* nibPath = |
| + [base::mac::MainAppBundle() pathForResource:@"FullscreenExitBubble" |
| + ofType:@"nib"]; |
|
Scott Hess - ex-Googler
2011/10/13 20:30:27
Indentation.
|
| + if ((self = [super initWithWindowNibPath:nibPath owner:self])) { |
| browser_ = browser; |
| owner_ = owner; |
| + url_ = url; |
| + showButtons_ = askPermission; |
| } |
| return self; |
| } |
| +- (void)allow:(id)sender { |
| + [self hideButtons]; |
| + browser_->OnAcceptFullscreenPermission(url_); |
| + [self hideSoon]; |
| +} |
| + |
| +- (void)deny:(id)sender { |
| + browser_->ToggleFullscreenMode(false); |
| +} |
| + |
| +- (void)hideButtons { |
| + [allowButton_ setHidden:YES]; |
| + [denyButton_ setHidden:YES]; |
| + [exitLabel_ setHidden:NO]; |
| +} |
| + |
| +// We want this to be a child of a browser window. addChildWindow: |
| +// (called from this function) will bring the window on-screen; |
| +// unfortunately, [NSWindowController showWindow:] will also bring it |
| +// on-screen (but will cause unexpected changes to the window's |
| +// position). We cannot have an addChildWindow: and a subsequent |
| +// showWindow:. Thus, we have our own version. |
| +- (void)showWindow { |
| + NSWindow* window = [self window]; // completes nib load |
|
Scott Hess - ex-Googler
2011/10/13 20:30:27
I'd make this InfoBubbleWindow*, then use that in
koz (OOO until 15th September)
2011/10/14 00:35:16
Done.
|
| + [bubble_ setArrowLocation:info_bubble::kNoArrow]; |
| + [(InfoBubbleWindow*)[self window] setCanBecomeKey:NO]; |
|
Scott Hess - ex-Googler
2011/10/13 20:30:27
If I were REALLY pedantic I'd say -setCanBecomeKey
koz (OOO until 15th September)
2011/10/14 00:35:16
Done.
|
| + if (!showButtons_) { |
| + [self hideButtons]; |
| + [self hideSoon]; |
| + } |
| + NSRect windowFrame = [owner_ window].frame; |
| + [tweaker_ tweakUI:[self window]]; |
| + [self positionInWindowAtTop:NSHeight(windowFrame) width:NSWidth(windowFrame)]; |
| + [[owner_ window] addChildWindow:window ordered:NSWindowAbove]; |
| + |
| + [window orderFront:self]; |
| +} |
| + |
| - (void)awakeFromNib { |
| + NSString* title = |
| + l10n_util::GetNSStringF(IDS_FULLSCREEN_INFOBAR_REQUEST_PERMISSION, |
| + UTF8ToUTF16(url_.host())); |
| + [messageLabel_ setStringValue:title]; |
| [self initializeLabel]; |
| - [self hideSoon]; |
| } |
| - (void)positionInWindowAtTop:(CGFloat)maxY width:(CGFloat)maxWidth { |
| - NSRect bubbleFrame = [[self view] frame]; |
| - bubbleFrame.origin.x = (int)(maxWidth/2 - NSWidth(bubbleFrame)/2); |
| - bubbleFrame.origin.y = maxY - NSHeight(bubbleFrame); |
| - [[self view] setFrame:bubbleFrame]; |
| + NSRect windowFrame = [self window].frame; |
| + NSPoint origin = windowFrame.origin; |
|
Scott Hess - ex-Googler
2011/10/13 20:30:27
You just overwrite origin below.
koz (OOO until 15th September)
2011/10/14 00:35:16
Done.
|
| + origin.x = (int)(maxWidth/2 - NSWidth(windowFrame)/2); |
| + origin.y = maxY - NSHeight(windowFrame); |
| + origin.y -= fullscreen_exit_bubble::kBubbleOffsetY; |
| + [[self window] setFrameOrigin:origin]; |
| } |
| // Called when someone clicks on the embedded link. |
| @@ -74,21 +134,13 @@ const int kSlideOutDurationMs = 700; |
| } |
| - (void)hideTimerFired:(NSTimer*)timer { |
| - NSRect endFrame = [[self view] frame]; |
| - endFrame.origin.y += endFrame.size.height; |
| - endFrame.size.height = 0; |
| - NSDictionary* dict = [NSDictionary dictionaryWithObjectsAndKeys: |
| - [self view], NSViewAnimationTargetKey, |
| - [NSValue valueWithRect:endFrame], NSViewAnimationEndFrameKey, nil]; |
| - |
| - NSViewAnimation* animation = |
| - [[NSViewAnimation alloc] |
| - initWithViewAnimations:[NSArray arrayWithObjects:dict, nil]]; |
| - [animation gtm_setDuration:kSlideOutDurationMs/1000.0 |
| - eventMask:NSLeftMouseUpMask]; |
| - [animation setDelegate:self]; |
| - [animation startAnimation]; |
| - hideAnimation_.reset(animation); |
| + [NSAnimationContext beginGrouping]; |
| + [[NSAnimationContext currentContext] |
| + gtm_setDuration:kHideDurationMs/1000.0 |
|
Scott Hess - ex-Googler
2011/10/13 20:30:27
Any reason not to just have kHideDuration just be
koz (OOO until 15th September)
2011/10/14 00:35:16
Done.
|
| + eventMask:NSLeftMouseUpMask|NSLeftMouseDownMask]; |
| + [[[self window] animator] setAlphaValue:0.0]; |
| + [NSAnimationContext endGrouping]; |
| + return; |
|
Scott Hess - ex-Googler
2011/10/13 20:30:27
Extraneous return.
|
| } |
| - (void)animationDidEnd:(NSAnimation*)animation { |
| @@ -97,10 +149,6 @@ const int kSlideOutDurationMs = 700; |
| } |
| } |
| -- (AnimatableView*)animatableView { |
| - return static_cast<AnimatableView*>([self view]); |
| -} |
| - |
| - (void)dealloc { |
| [hideAnimation_.get() stopAnimation]; |
| [hideTimer_ invalidate]; |
| @@ -116,10 +164,11 @@ const int kSlideOutDurationMs = 700; |
| // The former doesn't show links in a nice way, but the latter can't be added |
| // in IB without a containing scroll view, so create the NSTextView |
| // programmatically. |
| - exitLabel_.reset([[HyperlinkTextView alloc] |
| + exitLabel_.reset([[OneClickHyperlinkTextView alloc] |
| initWithFrame:[exitLabelPlaceholder_ frame]]); |
| [exitLabel_.get() setAutoresizingMask: |
| [exitLabelPlaceholder_ autoresizingMask]]; |
| + [exitLabel_.get() setHidden:[exitLabelPlaceholder_ isHidden]]; |
| [[exitLabelPlaceholder_ superview] |
| replaceSubview:exitLabelPlaceholder_ with:exitLabel_.get()]; |
| exitLabelPlaceholder_ = nil; // Now released. |
| @@ -128,25 +177,32 @@ const int kSlideOutDurationMs = 700; |
| NSString *message = l10n_util::GetNSStringF(IDS_EXIT_FULLSCREEN_MODE, |
| base::SysNSStringToUTF16([[self class] keyCommandString])); |
| + NSFont* font = [NSFont systemFontOfSize: |
| + [NSFont systemFontSizeForControlSize:NSRegularControlSize]]; |
| [(HyperlinkTextView*)exitLabel_.get() |
| setMessageAndLink:@"" |
| withLink:message |
| atOffset:0 |
| - font:[NSFont systemFontOfSize:18] |
| - messageColor:[NSColor whiteColor] |
| - linkColor:[NSColor whiteColor]]; |
| + font:font |
| + messageColor:[NSColor blackColor] |
| + linkColor:[NSColor blueColor]]; |
| + [exitLabel_.get() setAlignment:NSRightTextAlignment]; |
| - [exitLabel_.get() sizeToFit]; |
| - NSLayoutManager* layoutManager = [exitLabel_.get() layoutManager]; |
| - NSTextContainer* textContainer = [exitLabel_.get() textContainer]; |
| + NSRect labelFrame = [exitLabel_ frame]; |
| + |
| + // NSTextView's sizeToFit: method seems to enjoy wrapping lines. Temporarily |
| + // set the size large to force it not to. |
| + NSRect windowFrame = [[self window] frame]; |
| + [exitLabel_ setFrameSize:NSMakeSize(NSWidth(windowFrame), |
| + NSHeight(windowFrame))]; |
|
Scott Hess - ex-Googler
2011/10/13 20:30:27
How about windowFrame.size?
koz (OOO until 15th September)
2011/10/14 00:35:16
Done.
|
| + NSLayoutManager* layoutManager = [exitLabel_ layoutManager]; |
| + NSTextContainer* textContainer = [exitLabel_ textContainer]; |
| [layoutManager ensureLayoutForTextContainer:textContainer]; |
| NSRect textFrame = [layoutManager usedRectForTextContainer:textContainer]; |
| - NSRect frame = [[self view] frame]; |
| - NSSize textSize = textFrame.size; |
| - frame.size.width = textSize.width + 2 * kPaddingPx; |
| - [[self view] setFrame:frame]; |
| - textFrame.origin.x = textFrame.origin.y = kPaddingPx; |
| - [exitLabel_.get() setFrame:textFrame]; |
| + |
| + labelFrame.origin.x += NSWidth(labelFrame) - NSWidth(textFrame); |
| + labelFrame.size = textFrame.size; |
| + [exitLabel_ setFrame:labelFrame]; |
| } |
| // This looks at the Main Menu and determines what the user has set as the |