| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/sys_string_conversions.h" | 10 #include "base/sys_string_conversions.h" |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 // position). We cannot have an addChildWindow: and a subsequent | 113 // position). We cannot have an addChildWindow: and a subsequent |
| 114 // showWindow:. Thus, we have our own version. | 114 // showWindow:. Thus, we have our own version. |
| 115 - (void)showWindow { | 115 - (void)showWindow { |
| 116 // Completes nib load. | 116 // Completes nib load. |
| 117 InfoBubbleWindow* info_bubble = static_cast<InfoBubbleWindow*>([self window]); | 117 InfoBubbleWindow* info_bubble = static_cast<InfoBubbleWindow*>([self window]); |
| 118 [info_bubble setCanBecomeKeyWindow:NO]; | 118 [info_bubble setCanBecomeKeyWindow:NO]; |
| 119 if (!fullscreen_bubble::ShowButtonsForType(bubbleType_)) { | 119 if (!fullscreen_bubble::ShowButtonsForType(bubbleType_)) { |
| 120 [self showButtons:NO]; | 120 [self showButtons:NO]; |
| 121 [self hideSoon]; | 121 [self hideSoon]; |
| 122 } | 122 } |
| 123 NSRect windowFrame = [owner_ window].frame; | |
| 124 [tweaker_ tweakUI:info_bubble]; | 123 [tweaker_ tweakUI:info_bubble]; |
| 125 [self positionInWindowAtTop:NSHeight(windowFrame) width:NSWidth(windowFrame)]; | |
| 126 [[owner_ window] addChildWindow:info_bubble ordered:NSWindowAbove]; | 124 [[owner_ window] addChildWindow:info_bubble ordered:NSWindowAbove]; |
| 125 [owner_ layoutSubviews]; |
| 127 | 126 |
| 128 [info_bubble orderFront:self]; | 127 [info_bubble orderFront:self]; |
| 129 } | 128 } |
| 130 | 129 |
| 131 - (void)awakeFromNib { | 130 - (void)awakeFromNib { |
| 132 DCHECK([[self window] isKindOfClass:[InfoBubbleWindow class]]); | 131 DCHECK([[self window] isKindOfClass:[InfoBubbleWindow class]]); |
| 133 [messageLabel_ setStringValue:[self getLabelText]]; | 132 [messageLabel_ setStringValue:[self getLabelText]]; |
| 134 [self initializeLabel]; | 133 [self initializeLabel]; |
| 135 } | 134 } |
| 136 | 135 |
| 137 - (void)positionInWindowAtTop:(CGFloat)maxY width:(CGFloat)maxWidth { | 136 - (void)positionInWindowAtTop:(CGFloat)maxY width:(CGFloat)maxWidth { |
| 138 NSRect windowFrame = [self window].frame; | 137 NSRect windowFrame = [self window].frame; |
| 138 NSRect ownerWindowFrame = [owner_ window].frame; |
| 139 NSPoint origin; | 139 NSPoint origin; |
| 140 origin.x = (int)(maxWidth/2 - NSWidth(windowFrame)/2); | 140 origin.x = (int)(maxWidth/2 - NSWidth(windowFrame)/2); |
| 141 origin.y = maxY - NSHeight(windowFrame); | 141 origin.y = maxY - NSHeight(windowFrame); |
| 142 |
| 143 origin.x = ownerWindowFrame.origin.x + |
| 144 (int)(NSWidth(ownerWindowFrame)/2 - NSWidth(windowFrame)/2); |
| 145 origin.y = ownerWindowFrame.origin.y + maxY - NSHeight(windowFrame); |
| 142 [[self window] setFrameOrigin:origin]; | 146 [[self window] setFrameOrigin:origin]; |
| 143 } | 147 } |
| 144 | 148 |
| 145 - (void)updateURL:(const GURL&)url | 149 - (void)updateURL:(const GURL&)url |
| 146 bubbleType:(FullscreenExitBubbleType)bubbleType { | 150 bubbleType:(FullscreenExitBubbleType)bubbleType { |
| 147 bubbleType_ = bubbleType; | 151 bubbleType_ = bubbleType; |
| 148 | 152 |
| 149 [messageLabel_ setStringValue:[self getLabelText]]; | 153 [messageLabel_ setStringValue:[self getLabelText]]; |
| 150 | 154 |
| 151 // Make sure the bubble is visible. | 155 // Make sure the bubble is visible. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 162 [[self window] setIgnoresMouseEvents:NO]; | 166 [[self window] setIgnoresMouseEvents:NO]; |
| 163 } else { | 167 } else { |
| 164 [self showButtons:NO]; | 168 [self showButtons:NO]; |
| 165 // Only button-less bubbles auto-hide. | 169 // Only button-less bubbles auto-hide. |
| 166 [self hideSoon]; | 170 [self hideSoon]; |
| 167 } | 171 } |
| 168 // TODO(jeremya): show "Press Esc to exit" instead of a link on mouselock. | 172 // TODO(jeremya): show "Press Esc to exit" instead of a link on mouselock. |
| 169 | 173 |
| 170 // Relayout. A bit jumpy, but functional. | 174 // Relayout. A bit jumpy, but functional. |
| 171 [tweaker_ tweakUI:[self window]]; | 175 [tweaker_ tweakUI:[self window]]; |
| 172 NSRect windowFrame = [owner_ window].frame; | 176 [owner_ layoutSubviews]; |
| 173 [self positionInWindowAtTop:NSHeight(windowFrame) width:NSWidth(windowFrame)]; | |
| 174 } | 177 } |
| 175 | 178 |
| 176 // Called when someone clicks on the embedded link. | 179 // Called when someone clicks on the embedded link. |
| 177 - (BOOL) textView:(NSTextView*)textView | 180 - (BOOL) textView:(NSTextView*)textView |
| 178 clickedOnLink:(id)link | 181 clickedOnLink:(id)link |
| 179 atIndex:(NSUInteger)charIndex { | 182 atIndex:(NSUInteger)charIndex { |
| 180 browser_->ExecuteCommand(IDC_FULLSCREEN); | 183 browser_->ExecuteCommand(IDC_FULLSCREEN); |
| 181 return YES; | 184 return YES; |
| 182 } | 185 } |
| 183 | 186 |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 - (void)hideSoon { | 328 - (void)hideSoon { |
| 326 hideTimer_.reset( | 329 hideTimer_.reset( |
| 327 [[NSTimer scheduledTimerWithTimeInterval:kInitialDelay | 330 [[NSTimer scheduledTimerWithTimeInterval:kInitialDelay |
| 328 target:self | 331 target:self |
| 329 selector:@selector(hideTimerFired:) | 332 selector:@selector(hideTimerFired:) |
| 330 userInfo:nil | 333 userInfo:nil |
| 331 repeats:NO] retain]); | 334 repeats:NO] retain]); |
| 332 } | 335 } |
| 333 | 336 |
| 334 @end | 337 @end |
| OLD | NEW |