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..76d288b4d5c939aea2a6bac8d3cd8cf3d223305c 100644 |
--- a/chrome/browser/ui/cocoa/fullscreen_exit_bubble_controller.mm |
+++ b/chrome/browser/ui/cocoa/fullscreen_exit_bubble_controller.mm |
@@ -7,6 +7,7 @@ |
#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" |
@@ -15,6 +16,7 @@ |
#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" |
#include "grit/generated_resources.h" |
#include "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h" |
#import "third_party/GTM/AppKit/GTMNSAnimation+Duration.h" |
@@ -44,25 +46,76 @@ 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 |
+ showButtons:(BOOL)show_buttons { |
+ NSString* nibPath = |
+ [base::mac::MainAppBundle() pathForResource:@"FullscreenExitBubble" |
+ ofType:@"nib"]; |
+ if ((self = [super initWithWindowNibPath:nibPath owner:self])) { |
browser_ = browser; |
owner_ = owner; |
+ url_ = url; |
+ show_buttons_ = show_buttons; |
} |
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 { |
+ BrowserWindowController* bwc = owner_; |
+ NSWindow* window = [self window]; // completes nib load |
+ [bubble_ setArrowLocation:info_bubble::kNoArrow]; |
+ if (!show_buttons_) { |
+ [self hideButtons]; |
+ [self hideSoon]; |
+ } |
+ CGFloat maxWidth = NSWidth([bwc window].frame); |
+ CGFloat maxY = NSHeight([bwc window].frame); |
Scott Hess - ex-Googler
2011/10/10 23:19:50
Capture the frame once in an NSRect then use NSWid
jeremya
2011/10/11 05:28:48
Done.
|
+ [tweaker_ tweakUI:[self window]]; |
+ [self positionInWindowAtTop:maxY width:maxWidth]; |
+ [[bwc window] addChildWindow:window ordered:NSWindowAbove]; |
+ |
+ [window orderFront:self]; |
+} |
+ |
- (void)awakeFromNib { |
[self initializeLabel]; |
- [self hideSoon]; |
+ NSString* title = |
+ l10n_util::GetNSStringF(IDS_FULLSCREEN_INFOBAR_REQUEST_PERMISSION, |
+ UTF8ToUTF16(url_.host())); |
+ [siteInfoLabel_ setStringValue:title]; |
+ [super awakeFromNib]; |
} |
- (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]; |
+ NSPoint origin = [[self window] frame].origin; |
+ origin.x = (int)(maxWidth/2 - NSWidth([self window].frame)/2); |
+ origin.y = maxY - NSHeight([self window].frame); |
Scott Hess - ex-Googler
2011/10/10 23:19:50
Likewise here, capture the frame once then work on
jeremya
2011/10/11 05:28:48
Done.
|
+ origin.y -= fullscreen_exit_bubble::kBubbleOffsetY; |
+ [[self window] setFrameOrigin:origin]; |
} |
// Called when someone clicks on the embedded link. |
@@ -74,11 +127,18 @@ const int kSlideOutDurationMs = 700; |
} |
- (void)hideTimerFired:(NSTimer*)timer { |
- NSRect endFrame = [[self view] frame]; |
+ [NSAnimationContext beginGrouping]; |
+ // The star currently triggers on mouse down, not mouse up. |
+ [[NSAnimationContext currentContext] |
+ gtm_setDuration:0.2 // TODO: Constantify. |
+ eventMask:NSLeftMouseUpMask|NSLeftMouseDownMask]; |
+ [[[self window] animator] setAlphaValue:0.0]; |
+ [NSAnimationContext endGrouping]; |
+ return; |
+ NSRect endFrame = [[self window] frame]; |
endFrame.origin.y += endFrame.size.height; |
- endFrame.size.height = 0; |
NSDictionary* dict = [NSDictionary dictionaryWithObjectsAndKeys: |
- [self view], NSViewAnimationTargetKey, |
+ [self window], NSViewAnimationTargetKey, |
[NSValue valueWithRect:endFrame], NSViewAnimationEndFrameKey, nil]; |
NSViewAnimation* animation = |
@@ -98,7 +158,7 @@ const int kSlideOutDurationMs = 700; |
} |
- (AnimatableView*)animatableView { |
- return static_cast<AnimatableView*>([self view]); |
+ return static_cast<AnimatableView*>([self window]); |
Scott Hess - ex-Googler
2011/10/10 23:19:50
Is this still a valid conversion?
jeremya
2011/10/11 05:28:48
Nope :) Removed.
|
} |
- (void)dealloc { |
@@ -120,6 +180,7 @@ const int kSlideOutDurationMs = 700; |
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 +189,23 @@ 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]]; |
Scott Hess - ex-Googler
2011/10/10 23:19:50
Merge error?
jeremya
2011/10/11 05:28:48
I don't think so... what makes you say that?
Scott Hess - ex-Googler
2011/10/11 05:32:30
Sorry, brace-counting fail across the lines, compo
|
[(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]; |
+ // TODO: sizeToFit doesn't seem to get quite the right size. |
+ [exitLabel_.get() setVerticallyResizable:NO]; |
+ [exitLabel_.get() setHorizontallyResizable:YES]; |
[exitLabel_.get() sizeToFit]; |
- NSLayoutManager* layoutManager = [exitLabel_.get() layoutManager]; |
- NSTextContainer* textContainer = [exitLabel_.get() 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]; |
+ NSSize frameSize = [exitLabel_ frame].size; |
+ frameSize.width += 30; |
+ [exitLabel_.get() setFrameSize:frameSize]; |
} |
// This looks at the Main Menu and determines what the user has set as the |