| 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 <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/mac_util.h" | 8 #include "base/mac/mac_util.h" |
| 9 #include "base/sys_string_conversions.h" | 9 #include "base/sys_string_conversions.h" |
| 10 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" | 10 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" |
| 11 #include "chrome/browser/tab_contents/link_infobar_delegate.h" | 11 #include "chrome/browser/tab_contents/link_infobar_delegate.h" |
| 12 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 12 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 13 #import "chrome/browser/ui/cocoa/animatable_view.h" | 13 #import "chrome/browser/ui/cocoa/animatable_view.h" |
| 14 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
| 14 #include "chrome/browser/ui/cocoa/event_utils.h" | 15 #include "chrome/browser/ui/cocoa/event_utils.h" |
| 15 #include "chrome/browser/ui/cocoa/infobars/infobar.h" | 16 #include "chrome/browser/ui/cocoa/infobars/infobar.h" |
| 16 #import "chrome/browser/ui/cocoa/infobars/infobar_container_controller.h" | 17 #import "chrome/browser/ui/cocoa/infobars/infobar_container_controller.h" |
| 17 #import "chrome/browser/ui/cocoa/infobars/infobar_controller.h" | 18 #import "chrome/browser/ui/cocoa/infobars/infobar_controller.h" |
| 18 #import "chrome/browser/ui/cocoa/infobars/infobar_gradient_view.h" | 19 #import "chrome/browser/ui/cocoa/infobars/infobar_gradient_view.h" |
| 20 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" |
| 19 #include "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h" | 21 #include "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h" |
| 20 #include "ui/gfx/image/image.h" | 22 #include "ui/gfx/image/image.h" |
| 21 #include "webkit/glue/window_open_disposition.h" | 23 #include "webkit/glue/window_open_disposition.h" |
| 22 | 24 |
| 23 namespace { | 25 namespace { |
| 24 // Durations set to match the default SlideAnimation duration. | 26 // Durations set to match the default SlideAnimation duration. |
| 25 const float kAnimateOpenDuration = 0.12; | 27 const float kAnimateOpenDuration = 0.12; |
| 26 const float kAnimateCloseDuration = 0.12; | 28 const float kAnimateCloseDuration = 0.12; |
| 27 } | 29 } |
| 28 | 30 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 // Performs final cleanup after an animation is finished or stopped, including | 89 // Performs final cleanup after an animation is finished or stopped, including |
| 88 // notifying the InfoBarDelegate that the infobar was closed and removing the | 90 // notifying the InfoBarDelegate that the infobar was closed and removing the |
| 89 // infobar from its container, if necessary. | 91 // infobar from its container, if necessary. |
| 90 - (void)cleanUpAfterAnimation:(BOOL)finished; | 92 - (void)cleanUpAfterAnimation:(BOOL)finished; |
| 91 | 93 |
| 92 // Sets the info bar message to the specified |message|, with a hypertext | 94 // Sets the info bar message to the specified |message|, with a hypertext |
| 93 // style link. |link| will be inserted into message at |linkOffset|. | 95 // style link. |link| will be inserted into message at |linkOffset|. |
| 94 - (void)setLabelToMessage:(NSString*)message | 96 - (void)setLabelToMessage:(NSString*)message |
| 95 withLink:(NSString*)link | 97 withLink:(NSString*)link |
| 96 atOffset:(NSUInteger)linkOffset; | 98 atOffset:(NSUInteger)linkOffset; |
| 99 |
| 100 // Returns the point, in gradient view coordinates, at which the apex of the |
| 101 // infobar tip should be drawn. |
| 102 - (NSPoint)pointForTipApex; |
| 97 @end | 103 @end |
| 98 | 104 |
| 99 @implementation InfoBarController | 105 @implementation InfoBarController |
| 100 | 106 |
| 101 @synthesize containerController = containerController_; | 107 @synthesize containerController = containerController_; |
| 102 @synthesize delegate = delegate_; | 108 @synthesize delegate = delegate_; |
| 103 | 109 |
| 104 - (id)initWithDelegate:(InfoBarDelegate*)delegate | 110 - (id)initWithDelegate:(InfoBarDelegate*)delegate |
| 105 owner:(TabContentsWrapper*)owner { | 111 owner:(TabContentsWrapper*)owner { |
| 106 DCHECK(delegate); | 112 DCHECK(delegate); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 125 NSRect labelFrame = [labelPlaceholder_ frame]; | 131 NSRect labelFrame = [labelPlaceholder_ frame]; |
| 126 labelFrame.size.width += NSMinX(imageFrame) - NSMinX(labelFrame); | 132 labelFrame.size.width += NSMinX(imageFrame) - NSMinX(labelFrame); |
| 127 labelFrame.origin.x = imageFrame.origin.x; | 133 labelFrame.origin.x = imageFrame.origin.x; |
| 128 [image_ removeFromSuperview]; | 134 [image_ removeFromSuperview]; |
| 129 [labelPlaceholder_ setFrame:labelFrame]; | 135 [labelPlaceholder_ setFrame:labelFrame]; |
| 130 } | 136 } |
| 131 [self initializeLabel]; | 137 [self initializeLabel]; |
| 132 | 138 |
| 133 [self addAdditionalControls]; | 139 [self addAdditionalControls]; |
| 134 | 140 |
| 141 infoBarView_.tipApex = [self pointForTipApex]; |
| 135 [infoBarView_ setInfobarType:delegate_->GetInfoBarType()]; | 142 [infoBarView_ setInfobarType:delegate_->GetInfoBarType()]; |
| 136 } | 143 } |
| 137 | 144 |
| 138 // Called when someone clicks on the embedded link. | 145 // Called when someone clicks on the embedded link. |
| 139 - (BOOL) textView:(NSTextView*)textView | 146 - (BOOL) textView:(NSTextView*)textView |
| 140 clickedOnLink:(id)link | 147 clickedOnLink:(id)link |
| 141 atIndex:(NSUInteger)charIndex { | 148 atIndex:(NSUInteger)charIndex { |
| 142 if ([self respondsToSelector:@selector(linkClicked)]) | 149 if ([self respondsToSelector:@selector(linkClicked)]) |
| 143 [self performSelector:@selector(linkClicked)]; | 150 [self performSelector:@selector(linkClicked)]; |
| 144 return YES; | 151 return YES; |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 // Insert the link text into the string at the appropriate offset. | 353 // Insert the link text into the string at the appropriate offset. |
| 347 scoped_nsobject<NSAttributedString> attributedString( | 354 scoped_nsobject<NSAttributedString> attributedString( |
| 348 [[NSAttributedString alloc] initWithString:link | 355 [[NSAttributedString alloc] initWithString:link |
| 349 attributes:linkAttributes]); | 356 attributes:linkAttributes]); |
| 350 [infoText.get() insertAttributedString:attributedString.get() | 357 [infoText.get() insertAttributedString:attributedString.get() |
| 351 atIndex:linkOffset]; | 358 atIndex:linkOffset]; |
| 352 // Update the label view with the new text. | 359 // Update the label view with the new text. |
| 353 [[label_.get() textStorage] setAttributedString:infoText]; | 360 [[label_.get() textStorage] setAttributedString:infoText]; |
| 354 } | 361 } |
| 355 | 362 |
| 363 - (NSPoint)pointForTipApex { |
| 364 BrowserWindowController* windowController = |
| 365 [containerController_ browserWindowController]; |
| 366 if (!windowController) { |
| 367 // This should only happen in unit tests. |
| 368 return NSZeroPoint; |
| 369 } |
| 370 |
| 371 LocationBarViewMac* locationBar = [windowController locationBarBridge]; |
| 372 NSPoint point = locationBar->GetPageInfoBubblePoint(); |
| 373 point = [infoBarView_ convertPoint:point fromView:nil]; |
| 374 return point; |
| 375 } |
| 376 |
| 356 @end | 377 @end |
| 357 | 378 |
| 358 | 379 |
| 359 ///////////////////////////////////////////////////////////////////////// | 380 ///////////////////////////////////////////////////////////////////////// |
| 360 // LinkInfoBarController implementation | 381 // LinkInfoBarController implementation |
| 361 | 382 |
| 362 @implementation LinkInfoBarController | 383 @implementation LinkInfoBarController |
| 363 | 384 |
| 364 // Link infobars have a text message, of which part is linkified. We | 385 // Link infobars have a text message, of which part is linkified. We |
| 365 // use an NSAttributedString to display styled text, and we set a | 386 // use an NSAttributedString to display styled text, and we set a |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 532 LinkInfoBarController* controller = | 553 LinkInfoBarController* controller = |
| 533 [[LinkInfoBarController alloc] initWithDelegate:this owner:owner]; | 554 [[LinkInfoBarController alloc] initWithDelegate:this owner:owner]; |
| 534 return new InfoBar(controller, this); | 555 return new InfoBar(controller, this); |
| 535 } | 556 } |
| 536 | 557 |
| 537 InfoBar* ConfirmInfoBarDelegate::CreateInfoBar(TabContentsWrapper* owner) { | 558 InfoBar* ConfirmInfoBarDelegate::CreateInfoBar(TabContentsWrapper* owner) { |
| 538 ConfirmInfoBarController* controller = | 559 ConfirmInfoBarController* controller = |
| 539 [[ConfirmInfoBarController alloc] initWithDelegate:this owner:owner]; | 560 [[ConfirmInfoBarController alloc] initWithDelegate:this owner:owner]; |
| 540 return new InfoBar(controller, this); | 561 return new InfoBar(controller, this); |
| 541 } | 562 } |
| OLD | NEW |