| 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/infobars/infobar_container_controller.h" | 5 #import "chrome/browser/ui/cocoa/infobars/infobar_container_controller.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/mac/mac_util.h" | 8 #include "base/mac/mac_util.h" |
| 9 #include "chrome/browser/infobars/infobar_service.h" | 9 #include "chrome/browser/infobars/infobar_service.h" |
| 10 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 10 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 @end | 25 @end |
| 26 | 26 |
| 27 | 27 |
| 28 @implementation InfoBarContainerController | 28 @implementation InfoBarContainerController |
| 29 | 29 |
| 30 @synthesize shouldSuppressTopInfoBarTip = shouldSuppressTopInfoBarTip_; | 30 @synthesize shouldSuppressTopInfoBarTip = shouldSuppressTopInfoBarTip_; |
| 31 | 31 |
| 32 - (id)initWithResizeDelegate:(id<ViewResizer>)resizeDelegate { | 32 - (id)initWithResizeDelegate:(id<ViewResizer>)resizeDelegate { |
| 33 DCHECK(resizeDelegate); | 33 DCHECK(resizeDelegate); |
| 34 if ((self = [super initWithNibName:nil bundle:nil])) { | 34 if ((self = [super initWithNibName:nil bundle:nil])) { |
| 35 // This view and its subviews use autoresizing masks, The starting frame |
| 36 // needs to be reasonably large, although its exactly values don't matter. |
| 37 // It cannot be NSZeroRect. |
| 35 base::scoped_nsobject<NSView> view( | 38 base::scoped_nsobject<NSView> view( |
| 36 [[NSView alloc] initWithFrame:NSZeroRect]); | 39 [[NSView alloc] initWithFrame:NSMakeRect(0, 0, 800, 100)]); |
| 37 [view setAutoresizingMask:NSViewWidthSizable | NSViewMinYMargin]; | 40 [view setAutoresizingMask:NSViewWidthSizable | NSViewMinYMargin]; |
| 38 view_id_util::SetID(view, VIEW_ID_INFO_BAR_CONTAINER); | 41 view_id_util::SetID(view, VIEW_ID_INFO_BAR_CONTAINER); |
| 39 [self setView:view]; | 42 [self setView:view]; |
| 40 | 43 |
| 41 resizeDelegate_ = resizeDelegate; | 44 resizeDelegate_ = resizeDelegate; |
| 42 containerCocoa_.reset(new InfoBarContainerCocoa(self)); | 45 containerCocoa_.reset(new InfoBarContainerCocoa(self)); |
| 43 infobarControllers_.reset([[NSMutableArray alloc] init]); | 46 infobarControllers_.reset([[NSMutableArray alloc] init]); |
| 44 } | 47 } |
| 45 return self; | 48 return self; |
| 46 } | 49 } |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 frame.origin.x = NSMinX(containerBounds); | 124 frame.origin.x = NSMinX(containerBounds); |
| 122 frame.origin.y = minY; | 125 frame.origin.y = minY; |
| 123 frame.size.width = NSWidth(containerBounds); | 126 frame.size.width = NSWidth(containerBounds); |
| 124 frame.size.height = [controller infobar]->total_height(); | 127 frame.size.height = [controller infobar]->total_height(); |
| 125 [[controller view] setFrame:frame]; | 128 [[controller view] setFrame:frame]; |
| 126 | 129 |
| 127 minY += NSHeight(frame) - [controller infobar]->arrow_height(); | 130 minY += NSHeight(frame) - [controller infobar]->arrow_height(); |
| 128 [controller layoutArrow]; | 131 [controller layoutArrow]; |
| 129 } | 132 } |
| 130 | 133 |
| 131 int totalHeight = 0; | 134 [resizeDelegate_ resizeView:[self view] newHeight:[self heightOfInfoBars]]; |
| 132 int overlap = containerCocoa_->GetVerticalOverlap(&totalHeight); | |
| 133 | |
| 134 if (NSHeight([[self view] frame]) != totalHeight) { | |
| 135 [resizeDelegate_ resizeView:[self view] newHeight:totalHeight]; | |
| 136 } else if (oldOverlappingTipHeight_ != overlap) { | |
| 137 // If the infobar overlap changed but the height didn't change then | |
| 138 // explicitly ask for a layout. | |
| 139 [[self browserWindowController] layoutInfoBars]; | |
| 140 } | |
| 141 oldOverlappingTipHeight_ = overlap; | |
| 142 } | 135 } |
| 143 | 136 |
| 144 - (void)setShouldSuppressTopInfoBarTip:(BOOL)flag { | 137 - (void)setShouldSuppressTopInfoBarTip:(BOOL)flag { |
| 145 if (shouldSuppressTopInfoBarTip_ == flag) | 138 if (shouldSuppressTopInfoBarTip_ == flag) |
| 146 return; | 139 return; |
| 147 shouldSuppressTopInfoBarTip_ = flag; | 140 shouldSuppressTopInfoBarTip_ = flag; |
| 148 [self positionInfoBarsAndRedraw:isAnimating_]; | 141 [self positionInfoBarsAndRedraw:isAnimating_]; |
| 149 } | 142 } |
| 150 | 143 |
| 151 - (void)removeController:(InfoBarController*)controller { | 144 - (void)removeController:(InfoBarController*)controller { |
| 152 if (![infobarControllers_ containsObject:controller]) | 145 if (![infobarControllers_ containsObject:controller]) |
| 153 return; | 146 return; |
| 154 | 147 |
| 155 // This code can be executed while InfoBarController is still on the stack, so | 148 // This code can be executed while InfoBarController is still on the stack, so |
| 156 // we retain and autorelease the controller to prevent it from being | 149 // we retain and autorelease the controller to prevent it from being |
| 157 // dealloc'ed too early. | 150 // dealloc'ed too early. |
| 158 [[controller retain] autorelease]; | 151 [[controller retain] autorelease]; |
| 159 [[controller view] removeFromSuperview]; | 152 [[controller view] removeFromSuperview]; |
| 160 [infobarControllers_ removeObject:controller]; | 153 [infobarControllers_ removeObject:controller]; |
| 161 } | 154 } |
| 162 | 155 |
| 163 - (void)setMaxTopArrowHeight:(NSInteger)height { | 156 - (void)setMaxTopArrowHeight:(NSInteger)height { |
| 164 containerCocoa_->SetMaxTopArrowHeight(height); | 157 containerCocoa_->SetMaxTopArrowHeight(height); |
| 165 } | 158 } |
| 166 | 159 |
| 160 - (CGFloat)heightOfInfoBars { |
| 161 CGFloat totalHeight = 0; |
| 162 for (InfoBarController* controller in infobarControllers_.get()) { |
| 163 totalHeight += [controller infobar]->total_height() - |
| 164 [controller infobar]->arrow_height(); |
| 165 } |
| 166 return totalHeight; |
| 167 } |
| 168 |
| 167 @end | 169 @end |
| OLD | NEW |