Commit 145528f0 authored by Erik Chen's avatar Erik Chen Committed by Commit Bot

Revert "Show favicon even if there's no enough space"

This reverts commit a5e2fb1d.

Reason for revert: Causes massive memory leaks when the logic is triggered. See https://bugs.chromium.org/p/chromium/issues/detail?id=851506#c26

Original change's description:
> Show favicon even if there's no enough space
>
> In this case, we will do:
> 1. Align favicon ceter.
> 2. Clip favicon to the tab's shape with 1 DIP padding.
>
> In order to do this, a mask layer is set to icon view.
> When there's a attention icon, tab shaped mask and
> circular mask will be combined and then set.
>
> Bug: 813637
> Change-Id: Idbadfcec44ef61d8a2213df4a87b533885e18a25
> Reviewed-on: https://chromium-review.googlesource.com/938875
> Reviewed-by: Elly Fong-Jones <ellyjones@chromium.org>
> Commit-Queue: SangWoo Ko <sangwoo108@gmail.com>
> Cr-Commit-Position: refs/heads/master@{#541323}

TBR=ellyjones@chromium.org,sangwoo108@gmail.com

# Not skipping CQ checks because original CL landed > 1 day ago.

Bug: 813637, 851506
Change-Id: I0712eeb68e84db335ead345c4aa6e39600a85c4b
Reviewed-on: https://chromium-review.googlesource.com/1103677
Commit-Queue: Erik Chen <erikchen@chromium.org>
Reviewed-by: default avatarErik Chen <erikchen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#567872}
parent 6cd49e63
...@@ -307,7 +307,7 @@ class TabControllerTest : public CocoaTest { ...@@ -307,7 +307,7 @@ class TabControllerTest : public CocoaTest {
switch ([controller iconCapacity]) { switch ([controller iconCapacity]) {
case 0: case 0:
EXPECT_FALSE([controller shouldShowCloseButton]); EXPECT_FALSE([controller shouldShowCloseButton]);
EXPECT_TRUE([controller shouldShowIcon]); EXPECT_FALSE([controller shouldShowIcon]);
EXPECT_FALSE([controller shouldShowAlertIndicator]); EXPECT_FALSE([controller shouldShowAlertIndicator]);
break; break;
case 1: case 1:
...@@ -471,23 +471,21 @@ TEST_F(TabControllerTest, ShouldShowIcon) { ...@@ -471,23 +471,21 @@ TEST_F(TabControllerTest, ShouldShowIcon) {
int cap = [controller iconCapacity]; int cap = [controller iconCapacity];
EXPECT_GT(cap, 0); EXPECT_GT(cap, 0);
// Tab is minimum width, close box should be hidden. On the other hand, icon // Tab is minimum width, both icon and close box should be hidden.
// should be visible.
NSRect frame = [[controller view] frame]; NSRect frame = [[controller view] frame];
frame.size.width = [TabController minTabWidth]; frame.size.width = [TabController minTabWidth];
[[controller view] setFrame:frame]; [[controller view] setFrame:frame];
EXPECT_FALSE([controller shouldShowIcon]); EXPECT_FALSE([controller shouldShowIcon]);
EXPECT_FALSE([controller shouldShowCloseButton]); EXPECT_FALSE([controller shouldShowCloseButton]);
// Setting the icon when tab is at min width should show icon (bug 813637). // Setting the icon when tab is at min width should not show icon (bug 18359).
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
base::scoped_nsobject<NSImage> favicon( base::scoped_nsobject<NSImage> favicon(
rb.GetNativeImageNamed(IDR_DEFAULT_FAVICON).CopyNSImage()); rb.GetNativeImageNamed(IDR_DEFAULT_FAVICON).CopyNSImage());
[controller setIconImage:favicon forLoadingState:kTabDone showIcon:YES]; [controller setIconImage:favicon forLoadingState:kTabDone showIcon:YES];
EXPECT_TRUE([controller shouldShowIcon]);
[controller updateVisibility]; [controller updateVisibility];
NSView* newIcon = [controller iconView]; NSView* newIcon = [controller iconView];
EXPECT_FALSE([newIcon isHidden]); EXPECT_TRUE([newIcon isHidden]);
// Tab is at active minimum width. Since it's active, the close box // Tab is at active minimum width. Since it's active, the close box
// should be visible. // should be visible.
...@@ -578,6 +576,7 @@ TEST_F(TabControllerTest, TitleViewLayout) { ...@@ -578,6 +576,7 @@ TEST_F(TabControllerTest, TitleViewLayout) {
[controller updateVisibility]; [controller updateVisibility];
const NSRect originalTabFrame = [[controller view] frame]; const NSRect originalTabFrame = [[controller view] frame];
const NSRect originalIconFrame = [[controller iconView] frame];
const NSRect originalCloseFrame = [[controller closeButton] frame]; const NSRect originalCloseFrame = [[controller closeButton] frame];
const NSRect originalTitleFrame = [[controller tabView] titleFrame]; const NSRect originalTitleFrame = [[controller tabView] titleFrame];
...@@ -591,15 +590,15 @@ TEST_F(TabControllerTest, TitleViewLayout) { ...@@ -591,15 +590,15 @@ TEST_F(TabControllerTest, TitleViewLayout) {
tabFrame.size.width = [TabController minTabWidth]; tabFrame.size.width = [TabController minTabWidth];
[[controller view] setFrame:tabFrame]; [[controller view] setFrame:tabFrame];
// The close button should be hidden and the title view should resize to take // The icon view and close button should be hidden and the title view should
// up it's space. // resize to take up their space.
EXPECT_FALSE([[controller iconView] isHidden]); EXPECT_TRUE([[controller iconView] isHidden]);
EXPECT_TRUE([[controller closeButton] isHidden]); EXPECT_TRUE([[controller closeButton] isHidden]);
EXPECT_GT(NSWidth([[controller view] frame]), EXPECT_GT(NSWidth([[controller view] frame]),
NSWidth([[controller tabView] titleFrame])); NSWidth([[controller tabView] titleFrame]));
EXPECT_LT( EXPECT_EQ(LeftMargin(originalTabFrame, originalIconFrame),
LeftMargin([[controller view] frame], [[controller iconView] frame]), LeftMargin([[controller view] frame],
LeftMargin([[controller view] frame], [[controller tabView] titleFrame])); [[controller tabView] titleFrame]));
EXPECT_EQ(RightMargin(originalTabFrame, originalCloseFrame), EXPECT_EQ(RightMargin(originalTabFrame, originalCloseFrame),
RightMargin([[controller view] frame], RightMargin([[controller view] frame],
[[controller tabView] titleFrame])); [[controller tabView] titleFrame]));
......
...@@ -114,7 +114,6 @@ const SkColor kDefaultTabTextColor = SkColorSetARGB(0xA0, 0x00, 0x00, 0x00); ...@@ -114,7 +114,6 @@ const SkColor kDefaultTabTextColor = SkColorSetARGB(0xA0, 0x00, 0x00, 0x00);
// clear the |controller_| pointer when it is dying. // clear the |controller_| pointer when it is dying.
@interface TabView (TabControllerInterface) @interface TabView (TabControllerInterface)
- (void)setController:(TabController*)controller; - (void)setController:(TabController*)controller;
- (CALayer*)maskLayerWithPadding:(int)padding;
@end @end
#endif // CHROME_BROWSER_UI_COCOA_TABS_TAB_VIEW_H_ #endif // CHROME_BROWSER_UI_COCOA_TABS_TAB_VIEW_H_
...@@ -850,36 +850,6 @@ CGFloat LineWidthFromContext(CGContextRef context) { ...@@ -850,36 +850,6 @@ CGFloat LineWidthFromContext(CGContextRef context) {
controller_ = controller; controller_ = controller;
} }
- (CALayer*)maskLayerWithPadding:(int)padding {
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef maskContext = CGBitmapContextCreate(
NULL, self.bounds.size.width, self.bounds.size.height, 8,
self.bounds.size.width * 4, colorSpace, kCGImageAlphaPremultipliedLast);
CGColorSpaceRelease(colorSpace);
if (!maskContext)
return nil;
NSGraphicsContext* graphicsContext =
[NSGraphicsContext graphicsContextWithGraphicsPort:maskContext
flipped:NO];
[NSGraphicsContext setCurrentContext:graphicsContext];
gfx::ScopedNSGraphicsContextSaveGState scopedGraphicsContext;
// Uses black for alpha mask.
[[NSColor blackColor] setFill];
CGContextFillRect(maskContext, [self bounds]);
GetMaskImage().DrawInRect(NSInsetRect([self bounds], padding, 0),
NSCompositeDestinationIn, 1.0);
CGImageRef alphaMask = CGBitmapContextCreateImage(maskContext);
CALayer* maskLayer = [CALayer layer];
maskLayer.bounds = self.bounds;
maskLayer.bounds.size =
CGSizeMake(self.bounds.size.width, [TabView maskImageFillHeight]);
maskLayer.contents = (id)alphaMask;
return maskLayer;
}
@end // @implementation TabView (TabControllerInterface) @end // @implementation TabView (TabControllerInterface)
@implementation TabView(Private) @implementation TabView(Private)
......
...@@ -121,17 +121,14 @@ bool ShouldTabShowFavicon(int capacity, ...@@ -121,17 +121,14 @@ bool ShouldTabShowFavicon(int capacity,
TabAlertState alert_state) { TabAlertState alert_state) {
if (!has_favicon) if (!has_favicon)
return false; return false;
int required_capacity = 1;
int other_icons = 0;
if (ShouldTabShowCloseButton(capacity, is_pinned_tab, is_active_tab)) if (ShouldTabShowCloseButton(capacity, is_pinned_tab, is_active_tab))
++other_icons; ++required_capacity;
if (ShouldTabShowAlertIndicator(capacity, is_pinned_tab, is_active_tab, if (ShouldTabShowAlertIndicator(capacity, is_pinned_tab, is_active_tab,
has_favicon, alert_state)) has_favicon, alert_state)) {
++other_icons; ++required_capacity;
}
// The favicon can be centered and clipped when it's alone, so if there are no return capacity >= required_capacity;
// other icons to show, we can show the favicon even when there's no capacity.
return !other_icons || (capacity > other_icons);
} }
bool ShouldTabShowAlertIndicator(int capacity, bool ShouldTabShowAlertIndicator(int capacity,
......
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