OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "extension_installed_bubble_controller.h" | 5 #import "extension_installed_bubble_controller.h" |
6 | 6 |
7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
8 #include "base/mac_util.h" | 8 #include "base/mac_util.h" |
9 #include "base/sys_string_conversions.h" | 9 #include "base/sys_string_conversions.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
83 if ((self = [super initWithWindowNibPath:nibPath owner:self])) { | 83 if ((self = [super initWithWindowNibPath:nibPath owner:self])) { |
84 DCHECK(parentWindow); | 84 DCHECK(parentWindow); |
85 parentWindow_ = parentWindow; | 85 parentWindow_ = parentWindow; |
86 DCHECK(extension); | 86 DCHECK(extension); |
87 extension_ = extension; | 87 extension_ = extension; |
88 DCHECK(browser); | 88 DCHECK(browser); |
89 browser_ = browser; | 89 browser_ = browser; |
90 icon_.reset([gfx::SkBitmapToNSImage(icon) retain]); | 90 icon_.reset([gfx::SkBitmapToNSImage(icon) retain]); |
91 pageActionRemoved_ = NO; | 91 pageActionRemoved_ = NO; |
92 | 92 |
93 if (extension->browser_action()) { | 93 if (!extension->omnibox_keyword().empty()) { |
94 type_ = extension_installed_bubble::kOmniboxKeyword; | |
95 } else if (extension->browser_action()) { | |
94 type_ = extension_installed_bubble::kBrowserAction; | 96 type_ = extension_installed_bubble::kBrowserAction; |
95 } else if (extension->page_action() && | 97 } else if (extension->page_action() && |
96 !extension->page_action()->default_icon_path().empty()) { | 98 !extension->page_action()->default_icon_path().empty()) { |
97 type_ = extension_installed_bubble::kPageAction; | 99 type_ = extension_installed_bubble::kPageAction; |
98 } else { | 100 } else { |
99 NOTREACHED(); // kGeneric installs handled in the extension_install_ui. | 101 NOTREACHED(); // kGeneric installs handled in the extension_install_ui. |
100 } | 102 } |
101 | 103 |
102 // Start showing window only after extension has fully loaded. | 104 // Start showing window only after extension has fully loaded. |
103 extensionObserver_.reset(new ExtensionLoadedNotificationObserver( | 105 extensionObserver_.reset(new ExtensionLoadedNotificationObserver( |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
167 // We need to calculate the location of these icons and the size of the | 169 // We need to calculate the location of these icons and the size of the |
168 // message itself (which varies with the title of the extension) in order | 170 // message itself (which varies with the title of the extension) in order |
169 // to figure out the origin point for the extension installed bubble. | 171 // to figure out the origin point for the extension installed bubble. |
170 // TODO(mirandac): add framework to easily test extension UI components! | 172 // TODO(mirandac): add framework to easily test extension UI components! |
171 - (NSPoint)calculateArrowPoint { | 173 - (NSPoint)calculateArrowPoint { |
172 BrowserWindowCocoa* window = | 174 BrowserWindowCocoa* window = |
173 static_cast<BrowserWindowCocoa*>(browser_->window()); | 175 static_cast<BrowserWindowCocoa*>(browser_->window()); |
174 NSPoint arrowPoint = NSZeroPoint; | 176 NSPoint arrowPoint = NSZeroPoint; |
175 | 177 |
176 switch(type_) { | 178 switch(type_) { |
179 case extension_installed_bubble::kOmniboxKeyword: { | |
180 LocationBarViewMac* locationBarView = | |
181 [window->cocoa_controller() locationBarBridge]; | |
182 arrowPoint = locationBarView->GetPageInfoBubblePoint(); | |
183 break; | |
184 } | |
177 case extension_installed_bubble::kBrowserAction: { | 185 case extension_installed_bubble::kBrowserAction: { |
178 BrowserActionsController* controller = | 186 BrowserActionsController* controller = |
179 [[window->cocoa_controller() toolbarController] | 187 [[window->cocoa_controller() toolbarController] |
180 browserActionsController]; | 188 browserActionsController]; |
181 arrowPoint = [controller popupPointForBrowserAction:extension_]; | 189 arrowPoint = [controller popupPointForBrowserAction:extension_]; |
182 break; | 190 break; |
183 } | 191 } |
184 case extension_installed_bubble::kPageAction: { | 192 case extension_installed_bubble::kPageAction: { |
185 LocationBarViewMac* locationBarView = | 193 LocationBarViewMac* locationBarView = |
186 [window->cocoa_controller() locationBarBridge]; | 194 [window->cocoa_controller() locationBarBridge]; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
228 | 236 |
229 // Now that we have resized the window, adjust y pos of the messages. | 237 // Now that we have resized the window, adjust y pos of the messages. |
230 [self setMessageFrames:newWindowHeight]; | 238 [self setMessageFrames:newWindowHeight]; |
231 | 239 |
232 // Find window origin, taking into account bubble size and arrow location. | 240 // Find window origin, taking into account bubble size and arrow location. |
233 NSPoint origin = | 241 NSPoint origin = |
234 [parentWindow_ convertBaseToScreen:[self calculateArrowPoint]]; | 242 [parentWindow_ convertBaseToScreen:[self calculateArrowPoint]]; |
235 NSSize offsets = NSMakeSize(info_bubble::kBubbleArrowXOffset + | 243 NSSize offsets = NSMakeSize(info_bubble::kBubbleArrowXOffset + |
236 info_bubble::kBubbleArrowWidth / 2.0, 0); | 244 info_bubble::kBubbleArrowWidth / 2.0, 0); |
237 offsets = [[window contentView] convertSize:offsets toView:nil]; | 245 offsets = [[window contentView] convertSize:offsets toView:nil]; |
238 origin.x -= NSWidth([window frame]) - offsets.width; | 246 if ([infoBubbleView_ arrowLocation] == info_bubble::kTopRight) |
247 origin.x -= NSWidth([window frame]) - offsets.width; | |
239 origin.y -= NSHeight([window frame]); | 248 origin.y -= NSHeight([window frame]); |
240 [window setFrameOrigin:origin]; | 249 [window setFrameOrigin:origin]; |
241 | 250 |
242 [parentWindow_ addChildWindow:window | 251 [parentWindow_ addChildWindow:window |
243 ordered:NSWindowAbove]; | 252 ordered:NSWindowAbove]; |
244 [window makeKeyAndOrderFront:self]; | 253 [window makeKeyAndOrderFront:self]; |
245 } | 254 } |
246 | 255 |
247 // Finish nib loading, set arrow location and load icon into window. This | 256 // Finish nib loading, set arrow location and load icon into window. This |
248 // function is exposed for unit testing. | 257 // function is exposed for unit testing. |
249 - (NSWindow*)initializeWindow { | 258 - (NSWindow*)initializeWindow { |
250 NSWindow* window = [self window]; // completes nib load | 259 NSWindow* window = [self window]; // completes nib load |
251 [infoBubbleView_ setArrowLocation:info_bubble::kTopRight]; | 260 |
261 if (type_ == extension_installed_bubble::kOmniboxKeyword) { | |
262 [infoBubbleView_ setArrowLocation:info_bubble::kTopLeft]; | |
Bons
2010/11/11 19:28:57
is there a default arrow position? I ask because i
Matt Perry
2010/11/12 07:20:25
There is, but it feels safer not relying on the de
| |
263 } else { | |
264 [infoBubbleView_ setArrowLocation:info_bubble::kTopRight]; | |
265 } | |
252 | 266 |
253 // Set appropriate icon, resizing if necessary. | 267 // Set appropriate icon, resizing if necessary. |
254 if ([icon_ size].width > extension_installed_bubble::kIconSize) { | 268 if ([icon_ size].width > extension_installed_bubble::kIconSize) { |
255 [icon_ setSize:NSMakeSize(extension_installed_bubble::kIconSize, | 269 [icon_ setSize:NSMakeSize(extension_installed_bubble::kIconSize, |
256 extension_installed_bubble::kIconSize)]; | 270 extension_installed_bubble::kIconSize)]; |
257 } | 271 } |
258 [iconImage_ setImage:icon_]; | 272 [iconImage_ setImage:icon_]; |
259 [iconImage_ setNeedsDisplay:YES]; | 273 [iconImage_ setNeedsDisplay:YES]; |
260 return window; | 274 return window; |
261 } | 275 } |
262 | 276 |
263 // Calculate the height of each install message, resizing messages in their | 277 // Calculate the height of each install message, resizing messages in their |
264 // frames to fit window width. Return the new window height, based on the | 278 // frames to fit window width. Return the new window height, based on the |
265 // total of all message heights. | 279 // total of all message heights. |
266 - (int)calculateWindowHeight { | 280 - (int)calculateWindowHeight { |
267 // Adjust the window height to reflect the sum height of all messages | 281 // Adjust the window height to reflect the sum height of all messages |
268 // and vertical padding. | 282 // and vertical padding. |
269 int newWindowHeight = 2 * extension_installed_bubble::kOuterVerticalMargin; | 283 int newWindowHeight = 2 * extension_installed_bubble::kOuterVerticalMargin; |
270 | 284 |
271 // First part of extension installed message. | 285 // First part of extension installed message. |
272 [extensionInstalledMsg_ setStringValue:l10n_util::GetNSStringF( | 286 [extensionInstalledMsg_ setStringValue:l10n_util::GetNSStringF( |
273 IDS_EXTENSION_INSTALLED_HEADING, UTF8ToUTF16(extension_->name()))]; | 287 IDS_EXTENSION_INSTALLED_HEADING, UTF8ToUTF16(extension_->name()))]; |
274 [GTMUILocalizerAndLayoutTweaker | 288 [GTMUILocalizerAndLayoutTweaker |
275 sizeToFitFixedWidthTextField:extensionInstalledMsg_]; | 289 sizeToFitFixedWidthTextField:extensionInstalledMsg_]; |
276 newWindowHeight += [extensionInstalledMsg_ frame].size.height + | 290 newWindowHeight += [extensionInstalledMsg_ frame].size.height + |
277 extension_installed_bubble::kInnerVerticalMargin; | 291 extension_installed_bubble::kInnerVerticalMargin; |
278 | 292 |
279 // If type is page action, include a special message about page actions. | 293 // If type is page action, include a special message about page actions. |
280 if (type_ == extension_installed_bubble::kPageAction) { | 294 if (type_ == extension_installed_bubble::kPageAction) { |
281 [pageActionInfoMsg_ setHidden:NO]; | 295 [extraInfoMsg_ setHidden:NO]; |
282 [[pageActionInfoMsg_ cell] | 296 [[extraInfoMsg_ cell] |
283 setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; | 297 setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; |
284 [GTMUILocalizerAndLayoutTweaker | 298 [GTMUILocalizerAndLayoutTweaker |
285 sizeToFitFixedWidthTextField:pageActionInfoMsg_]; | 299 sizeToFitFixedWidthTextField:extraInfoMsg_]; |
286 newWindowHeight += [pageActionInfoMsg_ frame].size.height + | 300 newWindowHeight += [extraInfoMsg_ frame].size.height + |
287 extension_installed_bubble::kInnerVerticalMargin; | 301 extension_installed_bubble::kInnerVerticalMargin; |
288 } | 302 } |
289 | 303 |
304 // If type is omnibox keyword, include a special message about the keyword. | |
305 if (type_ == extension_installed_bubble::kOmniboxKeyword) { | |
306 [extraInfoMsg_ setStringValue:l10n_util::GetNSStringF( | |
307 IDS_EXTENSION_INSTALLED_OMNIBOX_KEYWORD_INFO, | |
308 UTF8ToUTF16(extension_->omnibox_keyword()))]; | |
309 [extraInfoMsg_ setHidden:NO]; | |
310 [[extraInfoMsg_ cell] | |
311 setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; | |
312 [GTMUILocalizerAndLayoutTweaker | |
313 sizeToFitFixedWidthTextField:extraInfoMsg_]; | |
314 newWindowHeight += [extraInfoMsg_ frame].size.height + | |
315 extension_installed_bubble::kInnerVerticalMargin; | |
316 } | |
317 | |
290 // Second part of extension installed message. | 318 // Second part of extension installed message. |
291 [[extensionInstalledInfoMsg_ cell] | 319 [[extensionInstalledInfoMsg_ cell] |
292 setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; | 320 setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; |
293 [GTMUILocalizerAndLayoutTweaker | 321 [GTMUILocalizerAndLayoutTweaker |
294 sizeToFitFixedWidthTextField:extensionInstalledInfoMsg_]; | 322 sizeToFitFixedWidthTextField:extensionInstalledInfoMsg_]; |
295 newWindowHeight += [extensionInstalledInfoMsg_ frame].size.height; | 323 newWindowHeight += [extensionInstalledInfoMsg_ frame].size.height; |
296 | 324 |
297 return newWindowHeight; | 325 return newWindowHeight; |
298 } | 326 } |
299 | 327 |
300 // Adjust y-position of messages to sit properly in new window height. | 328 // Adjust y-position of messages to sit properly in new window height. |
301 - (void)setMessageFrames:(int)newWindowHeight { | 329 - (void)setMessageFrames:(int)newWindowHeight { |
302 // The extension messages will always be shown. | 330 // The extension messages will always be shown. |
303 NSRect extensionMessageFrame1 = [extensionInstalledMsg_ frame]; | 331 NSRect extensionMessageFrame1 = [extensionInstalledMsg_ frame]; |
304 NSRect extensionMessageFrame2 = [extensionInstalledInfoMsg_ frame]; | 332 NSRect extensionMessageFrame2 = [extensionInstalledInfoMsg_ frame]; |
305 | 333 |
306 extensionMessageFrame1.origin.y = newWindowHeight - ( | 334 extensionMessageFrame1.origin.y = newWindowHeight - ( |
307 extensionMessageFrame1.size.height + | 335 extensionMessageFrame1.size.height + |
308 extension_installed_bubble::kOuterVerticalMargin); | 336 extension_installed_bubble::kOuterVerticalMargin); |
309 [extensionInstalledMsg_ setFrame:extensionMessageFrame1]; | 337 [extensionInstalledMsg_ setFrame:extensionMessageFrame1]; |
310 if (type_ == extension_installed_bubble::kPageAction) { | 338 if (type_ == extension_installed_bubble::kPageAction || |
311 // The page action message is only shown when appropriate. | 339 type_ == extension_installed_bubble::kOmniboxKeyword) { |
312 NSRect pageActionMessageFrame = [pageActionInfoMsg_ frame]; | 340 // The extra message is only shown when appropriate. |
313 pageActionMessageFrame.origin.y = extensionMessageFrame1.origin.y - ( | 341 NSRect extraMessageFrame = [extraInfoMsg_ frame]; |
314 pageActionMessageFrame.size.height + | 342 extraMessageFrame.origin.y = extensionMessageFrame1.origin.y - ( |
343 extraMessageFrame.size.height + | |
315 extension_installed_bubble::kInnerVerticalMargin); | 344 extension_installed_bubble::kInnerVerticalMargin); |
316 [pageActionInfoMsg_ setFrame:pageActionMessageFrame]; | 345 [extraInfoMsg_ setFrame:extraMessageFrame]; |
317 extensionMessageFrame2.origin.y = pageActionMessageFrame.origin.y - ( | 346 extensionMessageFrame2.origin.y = extraMessageFrame.origin.y - ( |
318 extensionMessageFrame2.size.height + | 347 extensionMessageFrame2.size.height + |
319 extension_installed_bubble::kInnerVerticalMargin); | 348 extension_installed_bubble::kInnerVerticalMargin); |
320 } else { | 349 } else { |
321 extensionMessageFrame2.origin.y = extensionMessageFrame1.origin.y - ( | 350 extensionMessageFrame2.origin.y = extensionMessageFrame1.origin.y - ( |
322 extensionMessageFrame2.size.height + | 351 extensionMessageFrame2.size.height + |
323 extension_installed_bubble::kInnerVerticalMargin); | 352 extension_installed_bubble::kInnerVerticalMargin); |
324 } | 353 } |
325 [extensionInstalledInfoMsg_ setFrame:extensionMessageFrame2]; | 354 [extensionInstalledInfoMsg_ setFrame:extensionMessageFrame2]; |
326 } | 355 } |
327 | 356 |
328 // Exposed for unit testing. | 357 // Exposed for unit testing. |
329 - (NSRect)getExtensionInstalledMsgFrame { | 358 - (NSRect)getExtensionInstalledMsgFrame { |
330 return [extensionInstalledMsg_ frame]; | 359 return [extensionInstalledMsg_ frame]; |
331 } | 360 } |
332 | 361 |
333 - (NSRect)getPageActionInfoMsgFrame { | 362 - (NSRect)getPageActionInfoMsgFrame { |
Bons
2010/11/11 19:28:57
i guess this method should be renamed as well.
Matt Perry
2010/11/12 07:20:25
Done.
| |
334 return [pageActionInfoMsg_ frame]; | 363 return [extraInfoMsg_ frame]; |
335 } | 364 } |
336 | 365 |
337 - (NSRect)getExtensionInstalledInfoMsgFrame { | 366 - (NSRect)getExtensionInstalledInfoMsgFrame { |
338 return [extensionInstalledInfoMsg_ frame]; | 367 return [extensionInstalledInfoMsg_ frame]; |
339 } | 368 } |
340 | 369 |
341 - (void)extensionUnloaded:(id)sender { | 370 - (void)extensionUnloaded:(id)sender { |
342 extension_ = NULL; | 371 extension_ = NULL; |
343 } | 372 } |
344 | 373 |
345 @end | 374 @end |
OLD | NEW |