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 <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" |
11 #include "grit/ui_resources.h" | 11 #include "grit/ui_resources.h" |
12 #include "chrome/browser/api/infobars/confirm_infobar_delegate.h" | 12 #include "chrome/browser/api/infobars/confirm_infobar_delegate.h" |
13 #include "chrome/browser/api/infobars/infobar_service.h" | 13 #include "chrome/browser/api/infobars/infobar_service.h" |
14 #include "chrome/browser/api/infobars/link_infobar_delegate.h" | 14 #include "chrome/browser/infobars/alternate_nav_infobar_delegate.h" |
15 #import "chrome/browser/ui/cocoa/animatable_view.h" | 15 #import "chrome/browser/ui/cocoa/animatable_view.h" |
16 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 16 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
17 #include "chrome/browser/ui/cocoa/event_utils.h" | 17 #include "chrome/browser/ui/cocoa/event_utils.h" |
18 #import "chrome/browser/ui/cocoa/hyperlink_text_view.h" | 18 #import "chrome/browser/ui/cocoa/hyperlink_text_view.h" |
19 #import "chrome/browser/ui/cocoa/image_button_cell.h" | 19 #import "chrome/browser/ui/cocoa/image_button_cell.h" |
20 #include "chrome/browser/ui/cocoa/infobars/infobar.h" | 20 #include "chrome/browser/ui/cocoa/infobars/infobar.h" |
21 #import "chrome/browser/ui/cocoa/infobars/infobar_container_controller.h" | 21 #import "chrome/browser/ui/cocoa/infobars/infobar_container_controller.h" |
22 #import "chrome/browser/ui/cocoa/infobars/infobar_controller.h" | 22 #import "chrome/browser/ui/cocoa/infobars/infobar_controller.h" |
23 #import "chrome/browser/ui/cocoa/infobars/infobar_gradient_view.h" | 23 #import "chrome/browser/ui/cocoa/infobars/infobar_gradient_view.h" |
24 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" | 24 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
280 } | 280 } |
281 | 281 |
282 LocationBarViewMac* locationBar = [windowController locationBarBridge]; | 282 LocationBarViewMac* locationBar = [windowController locationBarBridge]; |
283 return locationBar->GetPageInfoBubblePoint(); | 283 return locationBar->GetPageInfoBubblePoint(); |
284 } | 284 } |
285 | 285 |
286 @end | 286 @end |
287 | 287 |
288 | 288 |
289 ///////////////////////////////////////////////////////////////////////// | 289 ///////////////////////////////////////////////////////////////////////// |
290 // LinkInfoBarController implementation | 290 // AlternateNavInfoBarController implementation |
291 | 291 |
292 @implementation LinkInfoBarController | 292 @implementation AlternateNavInfoBarController |
Peter Kasting
2013/01/04 01:09:07
Nit: Shouldn't all this sort of thing live in a se
tfarina
2013/01/07 15:31:32
Hi Peter, I started a new patch to address this.
| |
293 | 293 |
294 // Link infobars have a text message, of which part is linkified. We | 294 // Link infobars have a text message, of which part is linkified. We |
295 // use an NSAttributedString to display styled text, and we set a | 295 // use an NSAttributedString to display styled text, and we set a |
296 // NSLink attribute on the hyperlink portion of the message. Infobars | 296 // NSLink attribute on the hyperlink portion of the message. Infobars |
297 // use a custom NSTextField subclass, which allows us to override | 297 // use a custom NSTextField subclass, which allows us to override |
298 // textView:clickedOnLink:atIndex: and intercept clicks. | 298 // textView:clickedOnLink:atIndex: and intercept clicks. |
299 // | 299 // |
300 - (void)addAdditionalControls { | 300 - (void)addAdditionalControls { |
301 // No buttons. | 301 // No buttons. |
302 [self removeButtons]; | 302 [self removeButtons]; |
303 | 303 |
304 LinkInfoBarDelegate* delegate = delegate_->AsLinkInfoBarDelegate(); | 304 AlternateNavInfoBarDelegate* delegate = |
305 delegate_->AsAlternateNavInfoBarDelegate(); | |
305 DCHECK(delegate); | 306 DCHECK(delegate); |
306 size_t offset = string16::npos; | 307 size_t offset = string16::npos; |
307 string16 message = delegate->GetMessageTextWithOffset(&offset); | 308 string16 message = delegate->GetMessageTextWithOffset(&offset); |
308 string16 link = delegate->GetLinkText(); | 309 string16 link = delegate->GetLinkText(); |
309 NSFont* font = [NSFont labelFontOfSize: | 310 NSFont* font = [NSFont labelFontOfSize: |
310 [NSFont systemFontSizeForControlSize:NSRegularControlSize]]; | 311 [NSFont systemFontSizeForControlSize:NSRegularControlSize]]; |
311 HyperlinkTextView* view = (HyperlinkTextView*)label_.get(); | 312 HyperlinkTextView* view = (HyperlinkTextView*)label_.get(); |
312 [view setMessageAndLink:base::SysUTF16ToNSString(message) | 313 [view setMessageAndLink:base::SysUTF16ToNSString(message) |
313 withLink:base::SysUTF16ToNSString(link) | 314 withLink:base::SysUTF16ToNSString(link) |
314 atOffset:offset | 315 atOffset:offset |
315 font:font | 316 font:font |
316 messageColor:[NSColor blackColor] | 317 messageColor:[NSColor blackColor] |
317 linkColor:[NSColor blueColor]]; | 318 linkColor:[NSColor blueColor]]; |
318 } | 319 } |
319 | 320 |
320 // Called when someone clicks on the link in the infobar. This method | 321 // Called when someone clicks on the link in the infobar. This method |
321 // is called by the InfobarTextField on its delegate (the | 322 // is called by the InfobarTextField on its delegate (the |
322 // LinkInfoBarController). | 323 // AlternateNavInfoBarController). |
323 - (void)linkClicked { | 324 - (void)linkClicked { |
324 if (![self isOwned]) | 325 if (![self isOwned]) |
325 return; | 326 return; |
326 WindowOpenDisposition disposition = | 327 WindowOpenDisposition disposition = |
327 event_utils::WindowOpenDispositionFromNSEvent([NSApp currentEvent]); | 328 event_utils::WindowOpenDispositionFromNSEvent([NSApp currentEvent]); |
328 if (delegate_->AsLinkInfoBarDelegate()->LinkClicked(disposition)) | 329 if (delegate_->AsAlternateNavInfoBarDelegate()->LinkClicked(disposition)) |
329 [self removeSelf]; | 330 [self removeSelf]; |
330 } | 331 } |
331 | 332 |
332 @end | 333 @end |
333 | 334 |
334 | 335 |
335 ///////////////////////////////////////////////////////////////////////// | 336 ///////////////////////////////////////////////////////////////////////// |
336 // ConfirmInfoBarController implementation | 337 // ConfirmInfoBarController implementation |
337 | 338 |
338 @implementation ConfirmInfoBarController | 339 @implementation ConfirmInfoBarController |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
439 [view setMessageAndLink:message | 440 [view setMessageAndLink:message |
440 withLink:base::SysUTF16ToNSString(link) | 441 withLink:base::SysUTF16ToNSString(link) |
441 atOffset:[message length] | 442 atOffset:[message length] |
442 font:font | 443 font:font |
443 messageColor:[NSColor blackColor] | 444 messageColor:[NSColor blackColor] |
444 linkColor:[NSColor blueColor]]; | 445 linkColor:[NSColor blueColor]]; |
445 } | 446 } |
446 | 447 |
447 // Called when someone clicks on the link in the infobar. This method | 448 // Called when someone clicks on the link in the infobar. This method |
448 // is called by the InfobarTextField on its delegate (the | 449 // is called by the InfobarTextField on its delegate (the |
449 // LinkInfoBarController). | 450 // AlternateNavInfoBarController). |
450 - (void)linkClicked { | 451 - (void)linkClicked { |
451 if (![self isOwned]) | 452 if (![self isOwned]) |
452 return; | 453 return; |
453 WindowOpenDisposition disposition = | 454 WindowOpenDisposition disposition = |
454 event_utils::WindowOpenDispositionFromNSEvent([NSApp currentEvent]); | 455 event_utils::WindowOpenDispositionFromNSEvent([NSApp currentEvent]); |
455 if (delegate_->AsConfirmInfoBarDelegate()->LinkClicked(disposition)) | 456 if (delegate_->AsConfirmInfoBarDelegate()->LinkClicked(disposition)) |
456 [self removeSelf]; | 457 [self removeSelf]; |
457 } | 458 } |
458 | 459 |
459 @end | 460 @end |
460 | 461 |
461 | 462 |
462 ////////////////////////////////////////////////////////////////////////// | 463 ////////////////////////////////////////////////////////////////////////// |
463 // CreateInfoBar() implementations | 464 // CreateInfoBar() implementations |
464 | 465 |
465 InfoBar* LinkInfoBarDelegate::CreateInfoBar(InfoBarService* owner) { | 466 InfoBar* AlternateNavInfoBarDelegate::CreateInfoBar(InfoBarService* owner) { |
466 LinkInfoBarController* controller = | 467 AlternateNavInfoBarController* controller = |
467 [[LinkInfoBarController alloc] initWithDelegate:this owner:owner]; | 468 [[AlternateNavInfoBarController alloc] initWithDelegate:this owner:owner]; |
468 return new InfoBar(controller, this); | 469 return new InfoBar(controller, this); |
469 } | 470 } |
470 | 471 |
471 InfoBar* ConfirmInfoBarDelegate::CreateInfoBar(InfoBarService* owner) { | 472 InfoBar* ConfirmInfoBarDelegate::CreateInfoBar(InfoBarService* owner) { |
472 ConfirmInfoBarController* controller = | 473 ConfirmInfoBarController* controller = |
473 [[ConfirmInfoBarController alloc] initWithDelegate:this owner:owner]; | 474 [[ConfirmInfoBarController alloc] initWithDelegate:this owner:owner]; |
474 return new InfoBar(controller, this); | 475 return new InfoBar(controller, this); |
475 } | 476 } |
OLD | NEW |