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 "chrome/browser/ui/cocoa/global_error_bubble_controller.h" | 5 #import "chrome/browser/ui/cocoa/global_error_bubble_controller.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/sys_string_conversions.h" | 8 #include "base/sys_string_conversions.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/browser/search_engines/util.h" | 10 #include "chrome/browser/search_engines/util.h" |
11 #import "chrome/browser/ui/browser.h" | 11 #import "chrome/browser/ui/browser.h" |
12 #import "chrome/browser/ui/browser_window.h" | 12 #import "chrome/browser/ui/browser_window.h" |
13 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 13 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
14 #import "chrome/browser/ui/cocoa/l10n_util.h" | 14 #import "chrome/browser/ui/cocoa/l10n_util.h" |
15 #import "chrome/browser/ui/cocoa/info_bubble_view.h" | 15 #import "chrome/browser/ui/cocoa/info_bubble_view.h" |
16 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" | 16 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" |
17 #import "chrome/browser/ui/global_error.h" | 17 #import "chrome/browser/ui/global_error.h" |
18 #include "grit/generated_resources.h" | 18 #include "grit/generated_resources.h" |
19 #import "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h" | |
19 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" |
20 #include "ui/base/resource/resource_bundle.h" | 21 #include "ui/base/resource/resource_bundle.h" |
21 #include "ui/gfx/image/image.h" | 22 #include "ui/gfx/image/image.h" |
22 | 23 |
23 namespace { | 24 namespace { |
24 | 25 |
25 // The vertical offset of the wrench bubble from the wrench menu button. | 26 // The vertical offset of the wrench bubble from the wrench menu button. |
26 const CGFloat kWrenchBubblePointOffsetY = 6; | 27 const CGFloat kWrenchBubblePointOffsetY = 6; |
27 | 28 |
28 } // namespace | 29 } // namespace |
(...skipping 30 matching lines...) Expand all Loading... | |
59 [title_ setStringValue:SysUTF16ToNSString(error_->GetBubbleViewTitle())]; | 60 [title_ setStringValue:SysUTF16ToNSString(error_->GetBubbleViewTitle())]; |
60 [message_ setStringValue:SysUTF16ToNSString(error_->GetBubbleViewMessage())]; | 61 [message_ setStringValue:SysUTF16ToNSString(error_->GetBubbleViewMessage())]; |
61 [acceptButton_ setTitle: | 62 [acceptButton_ setTitle: |
62 SysUTF16ToNSString(error_->GetBubbleViewAcceptButtonLabel())]; | 63 SysUTF16ToNSString(error_->GetBubbleViewAcceptButtonLabel())]; |
63 string16 cancelLabel = error_->GetBubbleViewCancelButtonLabel(); | 64 string16 cancelLabel = error_->GetBubbleViewCancelButtonLabel(); |
64 if (cancelLabel.empty()) | 65 if (cancelLabel.empty()) |
65 [cancelButton_ setHidden:YES]; | 66 [cancelButton_ setHidden:YES]; |
66 else | 67 else |
67 [cancelButton_ setTitle:SysUTF16ToNSString(cancelLabel)]; | 68 [cancelButton_ setTitle:SysUTF16ToNSString(cancelLabel)]; |
68 | 69 |
69 // Adapt window size to bottom buttons. Do this before all other layouting. | 70 // First make sure that the window is wide enough to accomidate the buttons. |
Robert Sesek
2011/11/04 15:35:27
I think you can do all this within the XIB.
sail
2011/11/04 20:16:59
I couldn't figure out a way to do this from the XI
| |
71 NSRect frame = [[self window] frame]; | |
72 [layoutTweaker_ tweakUI:buttonContainer_]; | |
73 CGFloat delta = NSWidth([buttonContainer_ frame]) - NSWidth(frame); | |
74 if (delta > 0) { | |
75 frame.size.width += NSWidth([buttonContainer_ frame]) - NSWidth(frame); | |
Robert Sesek
2011/11/15 16:01:28
+= delta
sail
2011/11/15 19:12:44
Done.
| |
76 [[self window] setFrame:frame display:NO]; | |
77 } | |
78 | |
79 // Adapt window height to bottom buttons. Do this before all other layouting. | |
70 NSArray* views = [NSArray arrayWithObjects: | 80 NSArray* views = [NSArray arrayWithObjects: |
71 title_, message_, [acceptButton_ superview], nil]; | 81 title_, message_, buttonContainer_, nil]; |
72 NSSize ds = NSMakeSize(0, cocoa_l10n_util::VerticallyReflowGroup(views)); | 82 NSSize ds = NSMakeSize(0, cocoa_l10n_util::VerticallyReflowGroup(views)); |
73 ds = [[self bubble] convertSize:ds toView:nil]; | 83 ds = [[self bubble] convertSize:ds toView:nil]; |
74 | 84 |
75 NSRect frame = [[self window] frame]; | |
76 frame.origin.y -= ds.height; | 85 frame.origin.y -= ds.height; |
77 frame.size.height += ds.height; | 86 frame.size.height += ds.height; |
78 [[self window] setFrame:frame display:YES]; | 87 [[self window] setFrame:frame display:YES]; |
79 } | 88 } |
80 | 89 |
81 - (void)showWindow:(id)sender { | 90 - (void)showWindow:(id)sender { |
82 BrowserWindowController* bwc = [BrowserWindowController | 91 BrowserWindowController* bwc = [BrowserWindowController |
83 browserWindowControllerForWindow:[self parentWindow]]; | 92 browserWindowControllerForWindow:[self parentWindow]]; |
84 [bwc lockBarVisibilityForOwner:self withAnimation:NO delay:NO]; | 93 [bwc lockBarVisibilityForOwner:self withAnimation:NO delay:NO]; |
85 [super showWindow:sender]; | 94 [super showWindow:sender]; |
(...skipping 17 matching lines...) Expand all Loading... | |
103 - (IBAction)onCancel:(id)sender { | 112 - (IBAction)onCancel:(id)sender { |
104 error_->BubbleViewCancelButtonPressed(); | 113 error_->BubbleViewCancelButtonPressed(); |
105 [self close]; | 114 [self close]; |
106 } | 115 } |
107 | 116 |
108 @end | 117 @end |
109 | 118 |
110 void GlobalError::ShowBubbleView(Browser* browser, GlobalError* error) { | 119 void GlobalError::ShowBubbleView(Browser* browser, GlobalError* error) { |
111 [GlobalErrorBubbleController showForBrowser:browser error:error]; | 120 [GlobalErrorBubbleController showForBrowser:browser error:error]; |
112 } | 121 } |
OLD | NEW |