OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #import "chrome/browser/ui/cocoa/global_error_bubble_controller.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "base/sys_string_conversions.h" |
| 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/search_engines/util.h" |
| 11 #import "chrome/browser/ui/browser.h" |
| 12 #import "chrome/browser/ui/browser_window.h" |
| 13 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
| 14 #import "chrome/browser/ui/cocoa/l10n_util.h" |
| 15 #import "chrome/browser/ui/cocoa/info_bubble_view.h" |
| 16 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" |
| 17 #import "chrome/browser/ui/global_error_bubble_view.h" |
| 18 #import "chrome/browser/ui/global_error_delegate.h" |
| 19 #include "grit/generated_resources.h" |
| 20 #include "ui/base/l10n/l10n_util.h" |
| 21 #include "ui/base/resource/resource_bundle.h" |
| 22 #include "ui/gfx/image/image.h" |
| 23 |
| 24 @implementation GlobalErrorBubbleController |
| 25 |
| 26 - (id)initWithDelegate:(GlobalErrorDelegate*)delegate |
| 27 parentWindow:(NSWindow*)parentWindow |
| 28 anchoredAt:(NSPoint)anchoredAt { |
| 29 if ((self = [super initWithWindowNibPath:@"GlobalErrorBubble" |
| 30 parentWindow:parentWindow |
| 31 anchoredAt:anchoredAt])) { |
| 32 delegate_ = delegate; |
| 33 } |
| 34 return self; |
| 35 } |
| 36 |
| 37 - (void)awakeFromNib { |
| 38 [super awakeFromNib]; |
| 39 |
| 40 DCHECK(delegate_); |
| 41 |
| 42 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 43 [iconView_ setImage: |
| 44 rb.GetImageNamed(delegate_->GetBubbleViewIconResourceID()).ToNSImage()]; |
| 45 |
| 46 [title_ setStringValue:SysUTF16ToNSString(delegate_->GetBubbleViewTitle())]; |
| 47 [message_ setStringValue:SysUTF16ToNSString( |
| 48 delegate_->GetBubbleViewMessage())]; |
| 49 [acceptButton_ setTitle: |
| 50 SysUTF16ToNSString(delegate_->GetBubbleViewAcceptButtonLabel())]; |
| 51 string16 cancelLabel = delegate_->GetBubbleViewCancelButtonLabel(); |
| 52 if (cancelLabel.empty()) |
| 53 [cancelButton_ setHidden:YES]; |
| 54 else |
| 55 [cancelButton_ setTitle:SysUTF16ToNSString(cancelLabel)]; |
| 56 |
| 57 // Adapt window size to bottom buttons. Do this before all other layouting. |
| 58 NSArray *views = [NSArray arrayWithObjects: |
| 59 title_, message_, [acceptButton_ superview], nil]; |
| 60 CGFloat dy = cocoa_l10n_util::VerticallyReflowGroup(views); |
| 61 NSSize ds = NSMakeSize(0, dy); |
| 62 ds = [[self bubble] convertSize:ds toView:nil]; |
| 63 |
| 64 NSRect frame = [[self window] frame]; |
| 65 frame.origin.y -= ds.height; |
| 66 frame.size.height += ds.height; |
| 67 [[self window] setFrame:frame display:YES]; |
| 68 } |
| 69 |
| 70 - (void)showWindow:(id)sender { |
| 71 BrowserWindowController* bwc = [BrowserWindowController |
| 72 browserWindowControllerForWindow:[self parentWindow]]; |
| 73 [bwc lockBarVisibilityForOwner:self withAnimation:NO delay:NO]; |
| 74 [super showWindow:sender]; |
| 75 } |
| 76 |
| 77 - (void)close { |
| 78 BrowserWindowController* bwc = [BrowserWindowController |
| 79 browserWindowControllerForWindow:[self parentWindow]]; |
| 80 [bwc releaseBarVisibilityForOwner:self withAnimation:YES delay:NO]; |
| 81 [super close]; |
| 82 } |
| 83 |
| 84 |
| 85 |
| 86 @end |
| 87 |
| 88 void GlobalErrorBubbleView::Show(GlobalErrorDelegate* delegate, |
| 89 Browser* browser, |
| 90 const gfx::Rect& position_relative_to) { |
| 91 NSWindow* parentWindow = browser->window()->GetNativeHandle(); |
| 92 BrowserWindowController* bwc = [BrowserWindowController |
| 93 browserWindowControllerForWindow:parentWindow]; |
| 94 NSPoint anchoredAt = [[bwc toolbarController] wrenchButtonBubblePoint]; |
| 95 anchoredAt = [parentWindow convertBaseToScreen:anchoredAt]; |
| 96 |
| 97 // The controller will be automatically deleted when the bubble is closed. |
| 98 GlobalErrorBubbleController* controller = [[GlobalErrorBubbleController alloc] |
| 99 initWithDelegate:delegate |
| 100 parentWindow:parentWindow |
| 101 anchoredAt:anchoredAt]; |
| 102 [controller showWindow:nil]; |
| 103 } |
OLD | NEW |