Commit 9cceb8fa authored by ellyjones's avatar ellyjones Committed by Commit bot

cocoa browser: remove non-material toolbar support

This is part 1 of removing non-material top chrome support.

BUG=649368

Review-Url: https://codereview.chromium.org/2361153002
Cr-Commit-Position: refs/heads/master@{#420593}
parent cfa01627
......@@ -52,7 +52,6 @@ class AppMenuButtonIconPainterDelegateMac :
}
- (gfx::VectorIconId)vectorIconId {
CHECK(ui::MaterialDesignController::IsModeMaterial());
switch (type_) {
case AppMenuIconController::IconType::NONE:
DCHECK_EQ(severity_, AppMenuIconPainter::SEVERITY_NONE);
......
......@@ -89,39 +89,8 @@ const int kReloadMenuCommands[] = {
// Forcibly remove any stale tooltip which is being displayed.
[self removeAllToolTips];
id cell = [self cell];
[self setTag:anInt];
// The old way of doing things.
if (!ui::MaterialDesignController::IsModeMaterial()) {
if (anInt == IDC_RELOAD) {
[cell setImageID:IDR_RELOAD
forButtonState:image_button_cell::kDefaultState];
[cell setImageID:IDR_RELOAD_H
forButtonState:image_button_cell::kHoverState];
[cell setImageID:IDR_RELOAD_P
forButtonState:image_button_cell::kPressedState];
// The stop button has a disabled image but the reload button doesn't. To
// unset it we have to explicilty change the image ID to 0.
[cell setImageID:0
forButtonState:image_button_cell::kDisabledState];
[self setToolTip:l10n_util::GetNSStringWithFixup(IDS_TOOLTIP_RELOAD)];
} else if (anInt == IDC_STOP) {
[cell setImageID:IDR_STOP
forButtonState:image_button_cell::kDefaultState];
[cell setImageID:IDR_STOP_H
forButtonState:image_button_cell::kHoverState];
[cell setImageID:IDR_STOP_P
forButtonState:image_button_cell::kPressedState];
[cell setImageID:IDR_STOP_D
forButtonState:image_button_cell::kDisabledState];
[self setToolTip:l10n_util::GetNSStringWithFixup(IDS_TOOLTIP_STOP)];
} else {
NOTREACHED();
}
return;
}
[self resetButtonStateImages];
if (anInt == IDC_RELOAD) {
[self setToolTip:l10n_util::GetNSStringWithFixup(IDS_TOOLTIP_RELOAD)];
......@@ -154,28 +123,16 @@ const int kReloadMenuCommands[] = {
} else if ([self tag] == IDC_STOP &&
!pendingReloadTimer_ &&
[[self cell] isMouseInside]) {
id cell = [self cell];
if (ui::MaterialDesignController::IsModeMaterial()) {
[self resetButtonStateImages];
NSImage* disabledStopImage =
[[self cell] imageForState:image_button_cell::kDisabledState
view:self];
[cell setImage:disabledStopImage
forButtonState:image_button_cell::kDefaultState];
[cell setImage:disabledStopImage
forButtonState:image_button_cell::kHoverState];
[cell setImage:disabledStopImage
forButtonState:image_button_cell::kPressedState];
} else {
[cell setImageID:IDR_STOP_D
[self resetButtonStateImages];
NSImage* disabledStopImage =
[[self cell] imageForState:image_button_cell::kDisabledState
view:self];
[[self cell] setImage:disabledStopImage
forButtonState:image_button_cell::kDefaultState];
[cell setImageID:IDR_STOP_D
forButtonState:image_button_cell::kDisabledState];
[cell setImageID:IDR_STOP_D
[[self cell] setImage:disabledStopImage
forButtonState:image_button_cell::kHoverState];
[cell setImageID:IDR_STOP_D
[[self cell] setImage:disabledStopImage
forButtonState:image_button_cell::kPressedState];
}
pendingReloadTimer_ =
[NSTimer timerWithTimeInterval:kPendingReloadTimeout
target:self
......
......@@ -153,10 +153,6 @@ const NSSize kMDButtonIconSize = NSMakeSize(16, 16);
@synthesize handleMiddleClick = handleMiddleClick_;
+ (NSSize)toolbarButtonSize {
if (!ui::MaterialDesignController::IsModeMaterial()) {
return NSMakeSize(29, 29);
}
return kMDButtonBounds.size;
}
......@@ -235,11 +231,7 @@ const NSSize kMDButtonIconSize = NSMakeSize(16, 16);
[[BrowserToolsImageRep alloc]
initWithDrawSelector:@selector(drawBrowserToolsIcon:)
delegate:[BrowserToolsImageRep class]]);
if (!ui::MaterialDesignController::IsModeMaterial()) {
[imageRep setFillColor:skia::SkColorToCalibratedNSColor(fillColor)];
} else {
[imageRep setFillColor:skia::SkColorToSRGBNSColor(fillColor)];
}
[imageRep setFillColor:skia::SkColorToSRGBNSColor(fillColor)];
// Create the image from the image rep.
NSImage* browserToolsIcon =
......@@ -271,19 +263,11 @@ const NSSize kMDButtonIconSize = NSMakeSize(16, 16);
}
- (NSImage*)image {
if (!ui::MaterialDesignController::IsModeMaterial()) {
return [super image];
}
// setImage: stores the image in an ivar.
return image_.get();
}
- (void)setImage:(NSImage*)anImage {
if (!ui::MaterialDesignController::IsModeMaterial()) {
[super setImage:anImage];
return;
}
// We want to set the default image as the image for kDefaultState. Setting it
// as the default image (via setImage:) can cause ghosting from the two
// default images being drawn over each other. However we also need to keep
......@@ -294,8 +278,6 @@ const NSSize kMDButtonIconSize = NSMakeSize(16, 16);
}
- (void)resetButtonStateImages {
DCHECK(ui::MaterialDesignController::IsModeMaterial());
NSImage* normalIcon = nil;
NSImage* disabledIcon = nil;
BOOL isDarkTheme = NO;
......@@ -383,7 +365,7 @@ const NSSize kMDButtonIconSize = NSMakeSize(16, 16);
// In Material Design we want to catch when the button is attached to its
// window so that we can configure its appearance based on the window's
// theme.
if ([self window] && ui::MaterialDesignController::IsModeMaterial()) {
if ([self window]) {
[self resetButtonStateImages];
}
}
......@@ -392,9 +374,7 @@ const NSSize kMDButtonIconSize = NSMakeSize(16, 16);
- (void)windowDidChangeTheme {
// Update the hover and pressed image backgrounds to match the current theme.
if (ui::MaterialDesignController::IsModeMaterial()) {
[self resetButtonStateImages];
}
[self resetButtonStateImages];
}
- (void)windowDidChangeActive {
......
......@@ -230,18 +230,10 @@ class NotificationBridge : public AppMenuIconController::Delegate {
@synthesize browser = browser_;
+ (CGFloat)locationBarHeight {
if (!ui::MaterialDesignController::IsModeMaterial()) {
return 29;
}
return kMaterialDesignLocationBarHeight;
}
+ (CGFloat)appMenuLeftPadding {
if (!ui::MaterialDesignController::IsModeMaterial()) {
return 3;
}
return kMaterialDesignElementPadding;
}
......@@ -302,141 +294,89 @@ class NotificationBridge : public AppMenuIconController::Delegate {
}
// Make Material Design layout adjustments to the NIB items.
bool isModeMaterial = ui::MaterialDesignController::IsModeMaterial();
if (isModeMaterial) {
ToolbarView* toolbarView = [self toolbarView];
NSRect toolbarBounds = [toolbarView bounds];
NSSize toolbarButtonSize = [ToolbarButton toolbarButtonSize];
// Set the toolbar height.
NSRect frame = [toolbarView frame];
frame.size.height = [self baseToolbarHeight];
[toolbarView setFrame:frame];
NSRect backButtonFrame = [backButton_ frame];
backButtonFrame.origin.x =
kMaterialDesignElementPadding + kMaterialDesignButtonInset;
backButtonFrame.origin.y = NSMaxY(toolbarBounds) -
kMaterialDesignElementPadding - toolbarButtonSize.height;
backButtonFrame.size = toolbarButtonSize;
[backButton_ setFrame:backButtonFrame];
NSRect forwardButtonFrame = [forwardButton_ frame];
forwardButtonFrame.origin.x =
NSMaxX(backButtonFrame) + 2 * kMaterialDesignButtonInset;
forwardButtonFrame.origin.y = backButtonFrame.origin.y;
forwardButtonFrame.size = toolbarButtonSize;
[forwardButton_ setFrame:forwardButtonFrame];
NSRect reloadButtonFrame = [reloadButton_ frame];
reloadButtonFrame.origin.x =
NSMaxX(forwardButtonFrame) + 2 * kMaterialDesignButtonInset;
reloadButtonFrame.origin.y = forwardButtonFrame.origin.y;
reloadButtonFrame.size = toolbarButtonSize;
[reloadButton_ setFrame:reloadButtonFrame];
NSRect homeButtonFrame = [homeButton_ frame];
homeButtonFrame.origin.x =
NSMaxX(reloadButtonFrame) + 2 * kMaterialDesignButtonInset;
homeButtonFrame.origin.y = reloadButtonFrame.origin.y;
homeButtonFrame.size = toolbarButtonSize;
[homeButton_ setFrame:homeButtonFrame];
// Replace the app button from the nib with an AppToolbarButton instance for
// Material Design.
AppToolbarButton* newMenuButton =
[[[AppToolbarButton alloc] initWithFrame:[appMenuButton_ frame]]
autorelease];
[newMenuButton setAutoresizingMask:[appMenuButton_ autoresizingMask]];
[[appMenuButton_ superview] addSubview:newMenuButton];
[appMenuButton_ removeFromSuperview];
appMenuButton_ = newMenuButton;
// Adjust the menu button's position.
NSRect menuButtonFrame = [appMenuButton_ frame];
CGFloat menuButtonFrameMaxX =
NSMaxX(toolbarBounds) - [ToolbarController appMenuLeftPadding];
menuButtonFrame.origin.x =
menuButtonFrameMaxX - kMaterialDesignButtonInset -
toolbarButtonSize.width;
menuButtonFrame.origin.y = homeButtonFrame.origin.y;
menuButtonFrame.size = toolbarButtonSize;
[appMenuButton_ setFrame:menuButtonFrame];
// Adjust the size and location on the location bar to take up the
// space between the reload and menu buttons.
NSRect locationBarFrame = [locationBar_ frame];
locationBarFrame.origin.x = NSMaxX(homeButtonFrame) +
kMaterialDesignButtonInset;
if (![homeButton_ isHidden]) {
// Ensure proper spacing between the home button and the location bar.
locationBarFrame.origin.x += kMaterialDesignElementPadding;
}
locationBarFrame.origin.y = NSMaxY(toolbarBounds) -
kMaterialDesignLocationBarPadding - kMaterialDesignLocationBarHeight;
locationBarFrame.size.width =
menuButtonFrame.origin.x -
locationBarFrame.origin.x;
locationBarFrame.size.height = kMaterialDesignLocationBarHeight;
[locationBar_ setFrame:locationBarFrame];
// Correctly position the extension buttons' container view.
NSRect containerFrame = [browserActionsContainerView_ frame];
containerFrame.size.width += kMaterialDesignButtonInset;
containerFrame.origin.y =
locationBarFrame.origin.y + kMaterialDesignContainerYOffset;
containerFrame.size.height = toolbarButtonSize.height;
[browserActionsContainerView_ setFrame:containerFrame];
} else {
[[backButton_ cell] setImageID:IDR_BACK
forButtonState:image_button_cell::kDefaultState];
[[backButton_ cell] setImageID:IDR_BACK_H
forButtonState:image_button_cell::kHoverState];
[[backButton_ cell] setImageID:IDR_BACK_P
forButtonState:image_button_cell::kPressedState];
[[backButton_ cell] setImageID:IDR_BACK_D
forButtonState:image_button_cell::kDisabledState];
[[forwardButton_ cell] setImageID:IDR_FORWARD
forButtonState:image_button_cell::kDefaultState];
[[forwardButton_ cell] setImageID:IDR_FORWARD_H
forButtonState:image_button_cell::kHoverState];
[[forwardButton_ cell] setImageID:IDR_FORWARD_P
forButtonState:image_button_cell::kPressedState];
[[forwardButton_ cell] setImageID:IDR_FORWARD_D
forButtonState:image_button_cell::kDisabledState];
[[reloadButton_ cell] setImageID:IDR_RELOAD
forButtonState:image_button_cell::kDefaultState];
[[reloadButton_ cell] setImageID:IDR_RELOAD_H
forButtonState:image_button_cell::kHoverState];
[[reloadButton_ cell] setImageID:IDR_RELOAD_P
forButtonState:image_button_cell::kPressedState];
[[homeButton_ cell] setImageID:IDR_HOME
forButtonState:image_button_cell::kDefaultState];
[[homeButton_ cell] setImageID:IDR_HOME_H
forButtonState:image_button_cell::kHoverState];
[[homeButton_ cell] setImageID:IDR_HOME_P
forButtonState:image_button_cell::kPressedState];
[[appMenuButton_ cell] setImageID:IDR_TOOLS
forButtonState:image_button_cell::kDefaultState];
[[appMenuButton_ cell] setImageID:IDR_TOOLS_H
forButtonState:image_button_cell::kHoverState];
[[appMenuButton_ cell] setImageID:IDR_TOOLS_P
forButtonState:image_button_cell::kPressedState];
// Adjust the toolbar height if running on Retina - see the comment in
// -baseToolbarHeight.
CGFloat toolbarHeight = [self baseToolbarHeight];
ToolbarView* toolbarView = [self toolbarView];
NSRect toolbarFrame = [toolbarView frame];
if (toolbarFrame.size.height != toolbarHeight) {
toolbarFrame.size.height = toolbarHeight;
[toolbarView setFrame:toolbarFrame];
}
ToolbarView* toolbarView = [self toolbarView];
NSRect toolbarBounds = [toolbarView bounds];
NSSize toolbarButtonSize = [ToolbarButton toolbarButtonSize];
// Set the toolbar height.
NSRect frame = [toolbarView frame];
frame.size.height = [self baseToolbarHeight];
[toolbarView setFrame:frame];
NSRect backButtonFrame = [backButton_ frame];
backButtonFrame.origin.x =
kMaterialDesignElementPadding + kMaterialDesignButtonInset;
backButtonFrame.origin.y = NSMaxY(toolbarBounds) -
kMaterialDesignElementPadding - toolbarButtonSize.height;
backButtonFrame.size = toolbarButtonSize;
[backButton_ setFrame:backButtonFrame];
NSRect forwardButtonFrame = [forwardButton_ frame];
forwardButtonFrame.origin.x =
NSMaxX(backButtonFrame) + 2 * kMaterialDesignButtonInset;
forwardButtonFrame.origin.y = backButtonFrame.origin.y;
forwardButtonFrame.size = toolbarButtonSize;
[forwardButton_ setFrame:forwardButtonFrame];
NSRect reloadButtonFrame = [reloadButton_ frame];
reloadButtonFrame.origin.x =
NSMaxX(forwardButtonFrame) + 2 * kMaterialDesignButtonInset;
reloadButtonFrame.origin.y = forwardButtonFrame.origin.y;
reloadButtonFrame.size = toolbarButtonSize;
[reloadButton_ setFrame:reloadButtonFrame];
NSRect homeButtonFrame = [homeButton_ frame];
homeButtonFrame.origin.x =
NSMaxX(reloadButtonFrame) + 2 * kMaterialDesignButtonInset;
homeButtonFrame.origin.y = reloadButtonFrame.origin.y;
homeButtonFrame.size = toolbarButtonSize;
[homeButton_ setFrame:homeButtonFrame];
// Replace the app button from the nib with an AppToolbarButton instance for
// Material Design.
AppToolbarButton* newMenuButton =
[[[AppToolbarButton alloc] initWithFrame:[appMenuButton_ frame]]
autorelease];
[newMenuButton setAutoresizingMask:[appMenuButton_ autoresizingMask]];
[[appMenuButton_ superview] addSubview:newMenuButton];
[appMenuButton_ removeFromSuperview];
appMenuButton_ = newMenuButton;
// Adjust the menu button's position.
NSRect menuButtonFrame = [appMenuButton_ frame];
CGFloat menuButtonFrameMaxX =
NSMaxX(toolbarBounds) - [ToolbarController appMenuLeftPadding];
menuButtonFrame.origin.x =
menuButtonFrameMaxX - kMaterialDesignButtonInset -
toolbarButtonSize.width;
menuButtonFrame.origin.y = homeButtonFrame.origin.y;
menuButtonFrame.size = toolbarButtonSize;
[appMenuButton_ setFrame:menuButtonFrame];
// Adjust the size and location on the location bar to take up the
// space between the reload and menu buttons.
NSRect locationBarFrame = [locationBar_ frame];
locationBarFrame.origin.x = NSMaxX(homeButtonFrame) +
kMaterialDesignButtonInset;
if (![homeButton_ isHidden]) {
// Ensure proper spacing between the home button and the location bar.
locationBarFrame.origin.x += kMaterialDesignElementPadding;
}
locationBarFrame.origin.y = NSMaxY(toolbarBounds) -
kMaterialDesignLocationBarPadding - kMaterialDesignLocationBarHeight;
locationBarFrame.size.width =
menuButtonFrame.origin.x -
locationBarFrame.origin.x;
locationBarFrame.size.height = kMaterialDesignLocationBarHeight;
[locationBar_ setFrame:locationBarFrame];
// Correctly position the extension buttons' container view.
NSRect containerFrame = [browserActionsContainerView_ frame];
containerFrame.size.width += kMaterialDesignButtonInset;
containerFrame.origin.y =
locationBarFrame.origin.y + kMaterialDesignContainerYOffset;
containerFrame.size.height = toolbarButtonSize.height;
[browserActionsContainerView_ setFrame:containerFrame];
notificationBridge_.reset(
new ToolbarControllerInternal::NotificationBridge(self));
......@@ -472,10 +412,6 @@ class NotificationBridge : public AppMenuIconController::Delegate {
relativeTo:locationBar_];
}
if (!isModeMaterial) {
[locationBar_ setFont:[NSFont systemFontOfSize:[NSFont systemFontSize]]];
}
// Register pref observers for the optional home and page/options buttons
// and then add them to the toolbar based on those prefs.
PrefService* prefs = profile_->GetPrefs();
......@@ -507,17 +443,17 @@ class NotificationBridge : public AppMenuIconController::Delegate {
NSTrackingActiveAlways
owner:self
userInfo:nil]);
NSView* toolbarView = [self view];
[toolbarView addTrackingArea:trackingArea_.get()];
NSView* parentView = [self view];
[parentView addTrackingArea:trackingArea_.get()];
// If the user has any Browser Actions installed, the container view for them
// may have to be resized depending on the width of the toolbar frame.
[toolbarView setPostsFrameChangedNotifications:YES];
[parentView setPostsFrameChangedNotifications:YES];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(toolbarFrameChanged)
name:NSViewFrameDidChangeNotification
object:toolbarView];
object:parentView];
// Set ViewIDs for toolbar elements which don't have their dedicated class.
// ViewIDs of |toolbarView|, |reloadButton_|, |locationBar_| and
......@@ -800,12 +736,8 @@ class NotificationBridge : public AppMenuIconController::Delegate {
// since the frame edges of each button are right on top of each other. When
// hiding the button, reverse the direction of the movement (to the left).
CGFloat moveX = [homeButton_ frame].size.width;
if (!ui::MaterialDesignController::IsModeMaterial()) {
moveX -= 1.0;
} else {
// Ensure proper spacing between the home button and the location bar.
moveX += kMaterialDesignElementPadding;
}
// Ensure proper spacing between the home button and the location bar.
moveX += kMaterialDesignElementPadding;
if (hide)
moveX *= -1; // Reverse the direction of the move.
......@@ -829,12 +761,6 @@ class NotificationBridge : public AppMenuIconController::Delegate {
- (void)updateAppMenuButtonSeverity:(AppMenuIconPainter::Severity)severity
iconType:(AppMenuIconController::IconType)iconType
animate:(BOOL)animate {
if (!ui::MaterialDesignController::IsModeMaterial()) {
AppToolbarButtonCell* cell =
base::mac::ObjCCastStrict<AppToolbarButtonCell>([appMenuButton_ cell]);
[cell setSeverity:severity shouldAnimate:animate];
return;
}
AppToolbarButton* appMenuButton =
base::mac::ObjCCastStrict<AppToolbarButton>(appMenuButton_);
[appMenuButton setSeverity:severity iconType:iconType shouldAnimate:animate];
......@@ -927,9 +853,7 @@ class NotificationBridge : public AppMenuIconController::Delegate {
locationBarXPos;
// Equalize the distance between the location bar and the first extension
// button, and the distance between the location bar and home/reload button.
if (ui::MaterialDesignController::IsModeMaterial()) {
leftDistance -= kMaterialDesignButtonInset;
}
leftDistance -= kMaterialDesignButtonInset;
}
if (leftDistance != 0.0)
[self adjustLocationSizeBy:leftDistance animate:animate];
......@@ -960,20 +884,8 @@ class NotificationBridge : public AppMenuIconController::Delegate {
// it afterwards.
[browserActionsContainerView_ stopAnimation];
NSRect containerFrame = [browserActionsContainerView_ frame];
if (!ui::MaterialDesignController::IsModeMaterial()) {
CGFloat elementTopPadding =
kMaterialDesignElementPadding + kMaterialDesignButtonInset;
// Pre-Material Design, this value is calculated from the values in
// Toolbar.xib: the height of the toolbar (35) minus the height of the
// child elements (29) minus the y-origin of the elements (4).
elementTopPadding = 2;
containerFrame.origin.y =
NSHeight([[self view] frame]) - NSHeight(containerFrame) -
elementTopPadding;
} else {
containerFrame.origin.y =
[locationBar_ frame].origin.y + kMaterialDesignContainerYOffset;
}
containerFrame.origin.y =
[locationBar_ frame].origin.y + kMaterialDesignContainerYOffset;
[browserActionsContainerView_ setFrame:containerFrame];
[self pinLocationBarToLeftOfBrowserActionsContainerAndAnimate:NO];
}
......@@ -1078,26 +990,8 @@ class NotificationBridge : public AppMenuIconController::Delegate {
- (CGFloat)baseToolbarHeight {
// Height of the toolbar in pixels when the bookmark bar is closed.
const bool kIsModeMaterial = ui::MaterialDesignController::IsModeMaterial();
const CGFloat kBaseToolbarHeightNormal = kIsModeMaterial ? 37 : 35;
// Not all lines are drawn at 2x normal height when running on Retina, which
// causes the toolbar controls to be visually 1pt too high within the toolbar
// area. It's not possible to adjust the control y-positions by 0.5pt and have
// them appear 0.5pt lower (they are still drawn at their original locations),
// so instead shave off 1pt from the bottom of the toolbar. Note that there's
// an offsetting change in -[BookmarkBarController preferredHeight] to
// maintain the proper spacing between bookmark icons and toolbar items. See
// https://crbug.com/326245 .
const CGFloat kLineWidth = [[self view] cr_lineWidth];
const BOOL kIsRetina = (kLineWidth < 1);
BOOL reduceHeight = NO;
// Only adjust the height if Retina and not Material Design.
reduceHeight = kIsRetina && !kIsModeMaterial;
return reduceHeight ? kBaseToolbarHeightNormal - 1
: kBaseToolbarHeightNormal;
const CGFloat kBaseToolbarHeightNormal = 37;
return kBaseToolbarHeightNormal;
}
- (CGFloat)desiredHeightForCompression:(CGFloat)compressByHeight {
......
......@@ -21,15 +21,6 @@
[self drawBackground:dirtyRect];
}
// Override of |-[BackgroundGradientView strokeColor]|; make it respect opacity.
- (NSColor*)strokeColor {
// Only return a transparent color if not Material Design.
if (!ui::MaterialDesignController::IsModeMaterial()) {
return [[super strokeColor] colorWithAlphaComponent:[self dividerOpacity]];
}
return [super strokeColor];
}
- (BOOL)accessibilityIsIgnored {
return NO;
}
......
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