| 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 = ownerWindowFrame.origin.x + |
| 141 origin.y = maxY - NSHeight(windowFrame); | 141 (int)(NSWidth(ownerWindowFrame)/2 - NSWidth(windowFrame)/2); |
| 142 origin.y = ownerWindowFrame.origin.y + maxY - NSHeight(windowFrame); |
| 142 [[self window] setFrameOrigin:origin]; | 143 [[self window] setFrameOrigin:origin]; |
| 143 } | 144 } |
| 144 | 145 |
| 145 - (void)updateURL:(const GURL&)url | 146 - (void)updateURL:(const GURL&)url |
| 146 bubbleType:(FullscreenExitBubbleType)bubbleType { | 147 bubbleType:(FullscreenExitBubbleType)bubbleType { |
| 147 bubbleType_ = bubbleType; | 148 bubbleType_ = bubbleType; |
| 148 | 149 |
| 149 [messageLabel_ setStringValue:[self getLabelText]]; | 150 [messageLabel_ setStringValue:[self getLabelText]]; |
| 150 | 151 |
| 151 // Make sure the bubble is visible. | 152 // Make sure the bubble is visible. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 162 [[self window] setIgnoresMouseEvents:NO]; | 163 [[self window] setIgnoresMouseEvents:NO]; |
| 163 } else { | 164 } else { |
| 164 [self showButtons:NO]; | 165 [self showButtons:NO]; |
| 165 // Only button-less bubbles auto-hide. | 166 // Only button-less bubbles auto-hide. |
| 166 [self hideSoon]; | 167 [self hideSoon]; |
| 167 } | 168 } |
| 168 // TODO(jeremya): show "Press Esc to exit" instead of a link on mouselock. | 169 // TODO(jeremya): show "Press Esc to exit" instead of a link on mouselock. |
| 169 | 170 |
| 170 // Relayout. A bit jumpy, but functional. | 171 // Relayout. A bit jumpy, but functional. |
| 171 [tweaker_ tweakUI:[self window]]; | 172 [tweaker_ tweakUI:[self window]]; |
| 172 NSRect windowFrame = [owner_ window].frame; | 173 [owner_ layoutSubviews]; |
| 173 [self positionInWindowAtTop:NSHeight(windowFrame) width:NSWidth(windowFrame)]; | |
| 174 } | 174 } |
| 175 | 175 |
| 176 // Called when someone clicks on the embedded link. | 176 // Called when someone clicks on the embedded link. |
| 177 - (BOOL) textView:(NSTextView*)textView | 177 - (BOOL) textView:(NSTextView*)textView |
| 178 clickedOnLink:(id)link | 178 clickedOnLink:(id)link |
| 179 atIndex:(NSUInteger)charIndex { | 179 atIndex:(NSUInteger)charIndex { |
| 180 browser_->ExecuteCommand(IDC_FULLSCREEN); | 180 browser_->ExecuteCommand(IDC_FULLSCREEN); |
| 181 return YES; | 181 return YES; |
| 182 } | 182 } |
| 183 | 183 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 [layoutManager ensureLayoutForTextContainer:textContainer]; | 264 [layoutManager ensureLayoutForTextContainer:textContainer]; |
| 265 NSRect textFrame = [layoutManager usedRectForTextContainer:textContainer]; | 265 NSRect textFrame = [layoutManager usedRectForTextContainer:textContainer]; |
| 266 | 266 |
| 267 textFrame.size.width = ceil(NSWidth(textFrame)); | 267 textFrame.size.width = ceil(NSWidth(textFrame)); |
| 268 labelFrame.origin.x += NSWidth(labelFrame) - NSWidth(textFrame); | 268 labelFrame.origin.x += NSWidth(labelFrame) - NSWidth(textFrame); |
| 269 labelFrame.size = textFrame.size; | 269 labelFrame.size = textFrame.size; |
| 270 [exitLabel_ setFrame:labelFrame]; | 270 [exitLabel_ setFrame:labelFrame]; |
| 271 } | 271 } |
| 272 | 272 |
| 273 - (NSString*)getLabelText { | 273 - (NSString*)getLabelText { |
| 274 if (bubbleType_ == FEB_TYPE_NONE) |
| 275 return @""; |
| 274 return SysUTF16ToNSString(fullscreen_bubble::GetLabelTextForType( | 276 return SysUTF16ToNSString(fullscreen_bubble::GetLabelTextForType( |
| 275 bubbleType_, url_, browser_->profile()->GetExtensionService())); | 277 bubbleType_, url_, browser_->profile()->GetExtensionService())); |
| 276 } | 278 } |
| 277 | 279 |
| 278 // This looks at the Main Menu and determines what the user has set as the | 280 // This looks at the Main Menu and determines what the user has set as the |
| 279 // key combination for quit. It then gets the modifiers and builds an object | 281 // key combination for quit. It then gets the modifiers and builds an object |
| 280 // to hold the data. | 282 // to hold the data. |
| 281 + (ui::AcceleratorCocoa)acceleratorForToggleFullscreen { | 283 + (ui::AcceleratorCocoa)acceleratorForToggleFullscreen { |
| 282 NSMenu* mainMenu = [NSApp mainMenu]; | 284 NSMenu* mainMenu = [NSApp mainMenu]; |
| 283 // Get the application menu (i.e. Chromium). | 285 // Get the application menu (i.e. Chromium). |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 - (void)hideSoon { | 327 - (void)hideSoon { |
| 326 hideTimer_.reset( | 328 hideTimer_.reset( |
| 327 [[NSTimer scheduledTimerWithTimeInterval:kInitialDelay | 329 [[NSTimer scheduledTimerWithTimeInterval:kInitialDelay |
| 328 target:self | 330 target:self |
| 329 selector:@selector(hideTimerFired:) | 331 selector:@selector(hideTimerFired:) |
| 330 userInfo:nil | 332 userInfo:nil |
| 331 repeats:NO] retain]); | 333 repeats:NO] retain]); |
| 332 } | 334 } |
| 333 | 335 |
| 334 @end | 336 @end |
| OLD | NEW |