OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/constrained_window/constrained_window_alert.h" | 5 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_alert.h" |
6 | 6 |
7 #import "base/logging.h" | 7 #import "base/logging.h" |
8 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_button.h" | 8 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_button.h" |
9 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_control_u
tils.h" | 9 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_control_u
tils.h" |
10 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_wi
ndow.h" | 10 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_wi
ndow.h" |
11 #import "chrome/browser/ui/cocoa/hover_close_button.h" | 11 #import "chrome/browser/ui/cocoa/hover_close_button.h" |
12 #import "chrome/browser/ui/constrained_window.h" | 12 #import "chrome/browser/ui/constrained_window.h" |
| 13 #import "chrome/browser/ui/constrained_window_constants.h" |
13 #include "skia/ext/skia_utils_mac.h" | 14 #include "skia/ext/skia_utils_mac.h" |
14 #include "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h" | 15 #include "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h" |
15 #include "ui/base/cocoa/window_size_constants.h" | 16 #include "ui/base/cocoa/window_size_constants.h" |
16 | 17 |
17 namespace { | 18 namespace { |
18 | 19 |
19 const CGFloat kWindowMinWidth = 500; | 20 const CGFloat kWindowMinWidth = 500; |
20 const CGFloat kButtonGap = 6; | 21 const CGFloat kButtonGap = 6; |
21 const CGFloat kButtonMinWidth = 72; | 22 const CGFloat kButtonMinWidth = 72; |
22 | 23 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 } | 58 } |
58 | 59 |
59 - (NSString*)informativeText { | 60 - (NSString*)informativeText { |
60 return [informativeTextField_ stringValue]; | 61 return [informativeTextField_ stringValue]; |
61 } | 62 } |
62 | 63 |
63 - (void)setInformativeText:(NSString*)string { | 64 - (void)setInformativeText:(NSString*)string { |
64 [informativeTextField_ setAttributedStringValue: | 65 [informativeTextField_ setAttributedStringValue: |
65 constrained_window::GetAttributedLabelString( | 66 constrained_window::GetAttributedLabelString( |
66 string, | 67 string, |
67 ConstrainedWindow::kTextFontStyle, | 68 ConstrainedWindowConstants::kTextFontStyle, |
68 NSNaturalTextAlignment, | 69 NSNaturalTextAlignment, |
69 NSLineBreakByWordWrapping)]; | 70 NSLineBreakByWordWrapping)]; |
70 } | 71 } |
71 | 72 |
72 - (NSString*)messageText { | 73 - (NSString*)messageText { |
73 return [messageTextField_ stringValue]; | 74 return [messageTextField_ stringValue]; |
74 } | 75 } |
75 | 76 |
76 - (void)setMessageText:(NSString*)string { | 77 - (void)setMessageText:(NSString*)string { |
77 [messageTextField_ setAttributedStringValue: | 78 [messageTextField_ setAttributedStringValue: |
78 constrained_window::GetAttributedLabelString( | 79 constrained_window::GetAttributedLabelString( |
79 string, | 80 string, |
80 ConstrainedWindow::kTitleFontStyle, | 81 ConstrainedWindowConstants::kTitleFontStyle, |
81 NSNaturalTextAlignment, | 82 NSNaturalTextAlignment, |
82 NSLineBreakByWordWrapping)]; | 83 NSLineBreakByWordWrapping)]; |
83 } | 84 } |
84 | 85 |
85 - (NSView*)accessoryView { | 86 - (NSView*)accessoryView { |
86 return accessoryView_; | 87 return accessoryView_; |
87 } | 88 } |
88 | 89 |
89 - (void)setAccessoryView:(NSView*)accessoryView { | 90 - (void)setAccessoryView:(NSView*)accessoryView { |
90 [accessoryView_ removeFromSuperview]; | 91 [accessoryView_ removeFromSuperview]; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 } | 133 } |
133 buttonWidth += size.width; | 134 buttonWidth += size.width; |
134 } | 135 } |
135 if ([buttons_ count]) | 136 if ([buttons_ count]) |
136 buttonWidth += ([buttons_ count] - 1) * kButtonGap; | 137 buttonWidth += ([buttons_ count] - 1) * kButtonGap; |
137 | 138 |
138 // Window width. | 139 // Window width. |
139 CGFloat windowWidth = buttonWidth; | 140 CGFloat windowWidth = buttonWidth; |
140 if (accessoryView_.get()) | 141 if (accessoryView_.get()) |
141 windowWidth = std::max(windowWidth, NSWidth([accessoryView_ frame])); | 142 windowWidth = std::max(windowWidth, NSWidth([accessoryView_ frame])); |
142 windowWidth += ConstrainedWindow::kHorizontalPadding * 2; | 143 windowWidth += ConstrainedWindowConstants::kHorizontalPadding * 2; |
143 windowWidth = std::max(windowWidth, kWindowMinWidth); | 144 windowWidth = std::max(windowWidth, kWindowMinWidth); |
144 | 145 |
145 // Layout controls. | 146 // Layout controls. |
146 [self layoutButtonsWithWindowWidth:windowWidth]; | 147 [self layoutButtonsWithWindowWidth:windowWidth]; |
147 CGFloat curY = [buttons_ count] ? NSMaxY([[buttons_ lastObject] frame]) | 148 CGFloat curY = [buttons_ count] ? NSMaxY([[buttons_ lastObject] frame]) |
148 : ConstrainedWindow::kVerticalPadding; | 149 : ConstrainedWindowConstants::kClientBottomPadding; |
149 curY = [self layoutAccessoryViewAtYPos:curY]; | 150 curY = [self layoutAccessoryViewAtYPos:curY]; |
150 curY = [self layoutTextField:informativeTextField_ | 151 curY = [self layoutTextField:informativeTextField_ |
151 yPos:curY | 152 yPos:curY |
152 windowWidth:windowWidth]; | 153 windowWidth:windowWidth]; |
153 CGFloat availableMessageWidth = | 154 CGFloat availableMessageWidth = |
154 windowWidth - ConstrainedWindow::GetCloseButtonSize() - kButtonGap; | 155 windowWidth - ConstrainedWindow::GetCloseButtonSize() - kButtonGap; |
155 curY = [self layoutTextField:messageTextField_ | 156 curY = [self layoutTextField:messageTextField_ |
156 yPos:curY | 157 yPos:curY |
157 windowWidth:availableMessageWidth]; | 158 windowWidth:availableMessageWidth]; |
158 [self layoutCloseButtonWithWindowWidth:windowWidth]; | 159 [self layoutCloseButtonWithWindowWidth:windowWidth]; |
159 | 160 |
160 // Update window frame. | 161 // Update window frame. |
161 curY += ConstrainedWindow::kVerticalPadding; | 162 curY += ConstrainedWindowConstants::kTitleTopPadding; |
162 [window_ setFrame:NSMakeRect(0, 0, windowWidth, curY) | 163 [window_ setFrame:NSMakeRect(0, 0, windowWidth, curY) |
163 display:NO]; | 164 display:NO]; |
164 } | 165 } |
165 | 166 |
166 - (void)layoutButtonsWithWindowWidth:(CGFloat)windowWidth { | 167 - (void)layoutButtonsWithWindowWidth:(CGFloat)windowWidth { |
167 // Layout first 2 button right to left. | 168 // Layout first 2 button right to left. |
168 CGFloat curX = windowWidth - ConstrainedWindow::kHorizontalPadding; | 169 CGFloat curX = windowWidth - ConstrainedWindowConstants::kHorizontalPadding; |
169 const int buttonCount = [buttons_ count]; | 170 const int buttonCount = [buttons_ count]; |
170 for (int i = 0; i < std::min(2, buttonCount); ++i) { | 171 for (int i = 0; i < std::min(2, buttonCount); ++i) { |
171 NSButton* button = [buttons_ objectAtIndex:i]; | 172 NSButton* button = [buttons_ objectAtIndex:i]; |
172 NSRect rect = [button frame]; | 173 NSRect rect = [button frame]; |
173 rect.origin.x = curX - NSWidth(rect); | 174 rect.origin.x = curX - NSWidth(rect); |
174 rect.origin.y = ConstrainedWindow::kVerticalPadding; | 175 rect.origin.y = ConstrainedWindowConstants::kClientBottomPadding; |
175 [button setFrameOrigin:rect.origin]; | 176 [button setFrameOrigin:rect.origin]; |
176 curX = NSMinX(rect) - kButtonGap; | 177 curX = NSMinX(rect) - kButtonGap; |
177 } | 178 } |
178 | 179 |
179 // Layout remaining buttons left to right. | 180 // Layout remaining buttons left to right. |
180 curX = ConstrainedWindow::kHorizontalPadding; | 181 curX = ConstrainedWindowConstants::kHorizontalPadding; |
181 for (int i = buttonCount - 1; i >= 2; --i) { | 182 for (int i = buttonCount - 1; i >= 2; --i) { |
182 NSButton* button = [buttons_ objectAtIndex:i]; | 183 NSButton* button = [buttons_ objectAtIndex:i]; |
183 [button setFrameOrigin: | 184 [button setFrameOrigin: |
184 NSMakePoint(curX, ConstrainedWindow::kVerticalPadding)]; | 185 NSMakePoint(curX, ConstrainedWindowConstants::kClientBottomPadding)]; |
185 curX += NSMaxX([button frame]) + kButtonGap; | 186 curX += NSMaxX([button frame]) + kButtonGap; |
186 } | 187 } |
187 } | 188 } |
188 | 189 |
189 - (CGFloat)layoutTextField:(NSTextField*)textField | 190 - (CGFloat)layoutTextField:(NSTextField*)textField |
190 yPos:(CGFloat)yPos | 191 yPos:(CGFloat)yPos |
191 windowWidth:(CGFloat)windowWidth { | 192 windowWidth:(CGFloat)windowWidth { |
192 if (![[textField stringValue] length]) { | 193 if (![[textField stringValue] length]) { |
193 [textField setHidden:YES]; | 194 [textField setHidden:YES]; |
194 return yPos; | 195 return yPos; |
195 } | 196 } |
196 | 197 |
197 [textField setHidden:NO]; | 198 [textField setHidden:NO]; |
198 NSRect rect; | 199 NSRect rect; |
199 rect.origin.y = yPos + ConstrainedWindow::kRowPadding; | 200 rect.origin.y = yPos + ConstrainedWindowConstants::kRowPadding; |
200 rect.origin.x = ConstrainedWindow::kHorizontalPadding; | 201 rect.origin.x = ConstrainedWindowConstants::kHorizontalPadding; |
201 rect.size.width = windowWidth - ConstrainedWindow::kHorizontalPadding * 2; | 202 rect.size.width = windowWidth - |
| 203 ConstrainedWindowConstants::kHorizontalPadding * 2; |
202 rect.size.height = 1; | 204 rect.size.height = 1; |
203 [textField setFrame:rect]; | 205 [textField setFrame:rect]; |
204 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:textField]; | 206 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:textField]; |
205 return NSMaxY([textField frame]); | 207 return NSMaxY([textField frame]); |
206 } | 208 } |
207 | 209 |
208 - (CGFloat)layoutAccessoryViewAtYPos:(CGFloat)yPos { | 210 - (CGFloat)layoutAccessoryViewAtYPos:(CGFloat)yPos { |
209 if (!accessoryView_.get()) | 211 if (!accessoryView_.get()) |
210 return yPos; | 212 return yPos; |
211 NSRect frame = [accessoryView_ frame]; | 213 NSRect frame = [accessoryView_ frame]; |
212 frame.origin.y = yPos + ConstrainedWindow::kRowPadding; | 214 frame.origin.y = yPos + ConstrainedWindowConstants::kRowPadding; |
213 frame.origin.x = ConstrainedWindow::kHorizontalPadding; | 215 frame.origin.x = ConstrainedWindowConstants::kHorizontalPadding; |
214 [accessoryView_ setFrameOrigin:frame.origin]; | 216 [accessoryView_ setFrameOrigin:frame.origin]; |
215 return NSMaxY(frame); | 217 return NSMaxY(frame); |
216 } | 218 } |
217 | 219 |
218 - (void)layoutCloseButtonWithWindowWidth:(CGFloat)windowWidth { | 220 - (void)layoutCloseButtonWithWindowWidth:(CGFloat)windowWidth { |
219 NSRect frame; | 221 NSRect frame; |
220 frame.size.width = ConstrainedWindow::GetCloseButtonSize(); | 222 frame.size.width = ConstrainedWindow::GetCloseButtonSize(); |
221 frame.size.height = ConstrainedWindow::GetCloseButtonSize(); | 223 frame.size.height = ConstrainedWindow::GetCloseButtonSize(); |
222 frame.origin.x = | 224 frame.origin.x = windowWidth - |
223 windowWidth - ConstrainedWindow::kHorizontalPadding - NSWidth(frame); | 225 ConstrainedWindowConstants::kHorizontalPadding - NSWidth(frame); |
224 frame.origin.y = NSMaxY([messageTextField_ frame]) - NSHeight(frame); | 226 frame.origin.y = NSMaxY([messageTextField_ frame]) - NSHeight(frame); |
225 [closeButton_ setFrame:frame]; | 227 [closeButton_ setFrame:frame]; |
226 } | 228 } |
227 | 229 |
228 @end | 230 @end |
OLD | NEW |