Commit 082bcd2a authored by Jayson Adams's avatar Jayson Adams Committed by Commit Bot

[Mac] Fix regression with incognito tab close button.

https://chromium-review.googlesource.com/769238 cleans up the TabView
initialization code but the reordering causes the TabView to never
receive a pointer to its closeButton. This cl ensures closeButton
creation occurs before TabView creation.

Bug: 786326, 786387
Change-Id: Id1fce1b8dcd1014ae015b7806df3541981d08253
Reviewed-on: https://chromium-review.googlesource.com/777394Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Commit-Queue: Jayson Adams <shrike@chromium.org>
Cr-Commit-Position: refs/heads/master@{#517843}
parent 3538c8ab
...@@ -133,7 +133,23 @@ static const CGFloat kPinnedTabWidth = kDefaultTabHeight * 2; ...@@ -133,7 +133,23 @@ static const CGFloat kPinnedTabWidth = kDefaultTabHeight * 2;
- (id)init { - (id)init {
if ((self = [super init])) { if ((self = [super init])) {
// Create the TabView. BOOL isRTL = cocoa_l10n_util::ShouldDoExperimentalRTLLayout();
// Create the close button.
const CGFloat closeButtonXOrigin =
isRTL ? kTabTrailingPadding
: kInitialTabWidth - kCloseButtonSize - kTabTrailingPadding;
NSRect closeButtonFrame = NSMakeRect(closeButtonXOrigin, kTabElementYOrigin,
kCloseButtonSize, kCloseButtonSize);
closeButton_.reset(
[[HoverCloseButton alloc] initWithFrame:closeButtonFrame]);
[closeButton_
setAutoresizingMask:isRTL ? NSViewMaxXMargin : NSViewMinXMargin];
[closeButton_ setTarget:self];
[closeButton_ setAction:@selector(closeTab:)];
// Create the TabView. The TabView works directly with the closeButton so
// here (the TabView handles adding it as a subview).
base::scoped_nsobject<TabView> tabView([[TabView alloc] base::scoped_nsobject<TabView> tabView([[TabView alloc]
initWithFrame:NSMakeRect(0, 0, kInitialTabWidth, initWithFrame:NSMakeRect(0, 0, kInitialTabWidth,
[TabController defaultTabHeight]) [TabController defaultTabHeight])
...@@ -144,8 +160,6 @@ static const CGFloat kPinnedTabWidth = kDefaultTabHeight * 2; ...@@ -144,8 +160,6 @@ static const CGFloat kPinnedTabWidth = kDefaultTabHeight * 2;
[tabView setPostsBoundsChangedNotifications:NO]; [tabView setPostsBoundsChangedNotifications:NO];
[super setView:tabView]; [super setView:tabView];
BOOL isRTL = cocoa_l10n_util::ShouldDoExperimentalRTLLayout();
// Add the favicon view. // Add the favicon view.
NSRect iconViewFrame = NSRect iconViewFrame =
NSMakeRect(0, kTabElementYOrigin, gfx::kFaviconSize, gfx::kFaviconSize); NSMakeRect(0, kTabElementYOrigin, gfx::kFaviconSize, gfx::kFaviconSize);
...@@ -154,6 +168,7 @@ static const CGFloat kPinnedTabWidth = kDefaultTabHeight * 2; ...@@ -154,6 +168,7 @@ static const CGFloat kPinnedTabWidth = kDefaultTabHeight * 2;
: NSViewMaxXMargin | NSViewMinYMargin]; : NSViewMaxXMargin | NSViewMinYMargin];
[self updateIconViewFrameWithAnimation:NO]; [self updateIconViewFrameWithAnimation:NO];
[tabView addSubview:iconView_]; [tabView addSubview:iconView_];
isIconShowing_ = YES;
// Set up the title. // Set up the title.
const CGFloat titleXOrigin = const CGFloat titleXOrigin =
...@@ -164,22 +179,6 @@ static const CGFloat kPinnedTabWidth = kDefaultTabHeight * 2; ...@@ -164,22 +179,6 @@ static const CGFloat kPinnedTabWidth = kDefaultTabHeight * 2;
kInitialTitleWidth, kTitleHeight); kInitialTitleWidth, kTitleHeight);
[tabView setTitleFrame:titleFrame]; [tabView setTitleFrame:titleFrame];
// Add the close button.
const CGFloat closeButtonXOrigin =
isRTL ? kTabTrailingPadding
: kInitialTabWidth - kCloseButtonSize - kTabTrailingPadding;
NSRect closeButtonFrame = NSMakeRect(closeButtonXOrigin, kTabElementYOrigin,
kCloseButtonSize, kCloseButtonSize);
closeButton_.reset([[HoverCloseButton alloc] initWithFrame:
closeButtonFrame]);
[closeButton_
setAutoresizingMask:isRTL ? NSViewMaxXMargin : NSViewMinXMargin];
[closeButton_ setTarget:self];
[closeButton_ setAction:@selector(closeTab:)];
[tabView addSubview:closeButton_];
isIconShowing_ = YES;
NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter]; NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter];
[defaultCenter addObserver:self [defaultCenter addObserver:self
selector:@selector(themeChangedNotification:) selector:@selector(themeChangedNotification:)
......
...@@ -88,11 +88,6 @@ const CGFloat kRapidCloseDist = 2.5; ...@@ -88,11 +88,6 @@ const CGFloat kRapidCloseDist = 2.5;
+ (void)setTabEdgeStrokeColor; + (void)setTabEdgeStrokeColor;
@end @end
@interface TabController(Private)
// The TabView's close button.
- (HoverCloseButton*)closeButton;
@end
extern NSString* const _Nonnull NSWorkspaceAccessibilityDisplayOptionsDidChangeNotification; extern NSString* const _Nonnull NSWorkspaceAccessibilityDisplayOptionsDidChangeNotification;
namespace { namespace {
...@@ -223,6 +218,7 @@ CGFloat LineWidthFromContext(CGContextRef context) { ...@@ -223,6 +218,7 @@ CGFloat LineWidthFromContext(CGContextRef context) {
if (self) { if (self) {
controller_ = controller; controller_ = controller;
closeButton_ = closeButton; closeButton_ = closeButton;
[self addSubview:closeButton_];
// Make a text field for the title, but don't add it as a subview. // Make a text field for the title, but don't add it as a subview.
// We will use the cell to draw the text directly into our layer, // We will use the cell to draw the text directly into our layer,
...@@ -719,9 +715,9 @@ CGFloat LineWidthFromContext(CGContextRef context) { ...@@ -719,9 +715,9 @@ CGFloat LineWidthFromContext(CGContextRef context) {
AlertIndicatorButton* const indicator = [controller_ alertIndicatorButton]; AlertIndicatorButton* const indicator = [controller_ alertIndicatorButton];
const int indicatorLeft = (!indicator || [indicator isHidden]) ? const int indicatorLeft = (!indicator || [indicator isHidden]) ?
NSWidth([self frame]) : NSMinX([indicator frame]); NSWidth([self frame]) : NSMinX([indicator frame]);
HoverCloseButton* const closeButton = [controller_ closeButton]; const int closeButtonLeft = (!closeButton_ || [closeButton_ isHidden])
const int closeButtonLeft = (!closeButton || [closeButton isHidden]) ? ? NSWidth([self frame])
NSWidth([self frame]) : NSMinX([closeButton frame]); : NSMinX([closeButton_ frame]);
return std::min(indicatorLeft, closeButtonLeft); return std::min(indicatorLeft, closeButtonLeft);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment