summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorandresantoso <andresantoso@chromium.org>2015-02-05 11:08:31 -0800
committerCommit bot <commit-bot@chromium.org>2015-02-05 19:09:31 +0000
commit51fe497c74cf1378f40159250fa1d627e893cf01 (patch)
tree157c3d14e88b07eeed1f3f6f4c3f8f9272f4cfe2
parent731ba26a6f6e4a5a28e4b163622d4c60f07eb9c2 (diff)
downloadchromium_src-51fe497c74cf1378f40159250fa1d627e893cf01.zip
chromium_src-51fe497c74cf1378f40159250fa1d627e893cf01.tar.gz
chromium_src-51fe497c74cf1378f40159250fa1d627e893cf01.tar.bz2
Mac: Clean up outdated use of NSThemeFrame
We have now moved to a better place where we no longer swizzle NSThemeFrame's drawRect, and use a subview instead (TabStripBackgroundView). We also no longer add subviews to NSThemeFrame (with the exception of TabStripBackgroundView), and use a full-size content view instead. This is a clean-up of code that relies on outdated assumptions. For example, FramedBrowserWindow was unnecessarily calling setNeedsDisplay and setNeedsDisplayInRect. BUG=453996 Review URL: https://codereview.chromium.org/871423004 Cr-Commit-Position: refs/heads/master@{#314845}
-rw-r--r--chrome/browser/ui/cocoa/browser_window_controller.h9
-rw-r--r--chrome/browser/ui/cocoa/browser_window_controller_private.mm2
-rw-r--r--chrome/browser/ui/cocoa/framed_browser_window.mm77
-rw-r--r--chrome/browser/ui/cocoa/tabs/tab_window_controller.h9
-rw-r--r--chrome/browser/ui/cocoa/tabs/tab_window_controller.mm16
-rw-r--r--chrome/browser/ui/cocoa/themed_window.h9
6 files changed, 13 insertions, 109 deletions
diff --git a/chrome/browser/ui/cocoa/browser_window_controller.h b/chrome/browser/ui/cocoa/browser_window_controller.h
index 16ba21ee..23c8d1d 100644
--- a/chrome/browser/ui/cocoa/browser_window_controller.h
+++ b/chrome/browser/ui/cocoa/browser_window_controller.h
@@ -353,11 +353,10 @@ class Command;
// Gets the window style.
- (ThemedWindowStyle)themedWindowStyle;
-// Returns the position in the coordinates of the root view
-// ([[self contentView] superview]) that the top left of a theme image with
-// |alignment| should be painted at. If the window does not have a tab strip,
-// the offset for THEME_IMAGE_ALIGN_WITH_FRAME is always returned. The result of
-// this method can be used in conjunction with
+// Returns the position in window coordinates that the top left of a theme
+// image with |alignment| should be painted at. If the window does not have a
+// tab strip, the offset for THEME_IMAGE_ALIGN_WITH_FRAME is always returned.
+// The result of this method can be used in conjunction with
// [NSGraphicsContext cr_setPatternPhase:] to set the offset of pattern colors.
- (NSPoint)themeImagePositionForAlignment:(ThemeImageAlignment)alignment;
diff --git a/chrome/browser/ui/cocoa/browser_window_controller_private.mm b/chrome/browser/ui/cocoa/browser_window_controller_private.mm
index 1ed775b..042f5b3 100644
--- a/chrome/browser/ui/cocoa/browser_window_controller_private.mm
+++ b/chrome/browser/ui/cocoa/browser_window_controller_private.mm
@@ -377,7 +377,7 @@ willPositionSheet:(NSWindow*)sheet
// Add the tab strip after setting the content view and moving the incognito
// badge (if any), so that the tab strip will be on top (in the z-order).
if ([self hasTabStrip])
- [self insertTabStripView:tabStripView intoWindow:destWindow];
+ [[destWindow contentView] addSubview:tabStripView];
[sourceWindow setWindowController:nil];
[self setWindow:destWindow];
diff --git a/chrome/browser/ui/cocoa/framed_browser_window.mm b/chrome/browser/ui/cocoa/framed_browser_window.mm
index c290f70..7ad1990 100644
--- a/chrome/browser/ui/cocoa/framed_browser_window.mm
+++ b/chrome/browser/ui/cocoa/framed_browser_window.mm
@@ -41,7 +41,6 @@ const CGFloat kWindowGradientHeight = 24.0;
- (void)adjustZoomButton:(NSNotification*)notification;
- (void)adjustButton:(NSButton*)button
ofKind:(NSWindowButton)kind;
-- (NSView*)frameView;
@end
@@ -111,10 +110,6 @@ const CGFloat kWindowGradientHeight = 24.0;
selector:@selector(adjustZoomButton:)
name:NSViewFrameDidChangeNotification
object:zoomButton_];
- [center addObserver:self
- selector:@selector(themeDidChangeNotification:)
- name:kBrowserThemeDidChangeNotification
- object:nil];
}
return self;
@@ -143,7 +138,6 @@ const CGFloat kWindowGradientHeight = 24.0;
- (void)adjustButton:(NSButton*)button
ofKind:(NSWindowButton)kind {
NSRect buttonFrame = [button frame];
- NSRect frameViewBounds = [[self frameView] bounds];
CGFloat xOffset = hasTabStrip_
? kFramedWindowButtonsWithTabStripOffsetFromLeft
@@ -152,7 +146,7 @@ const CGFloat kWindowGradientHeight = 24.0;
? kFramedWindowButtonsWithTabStripOffsetFromTop
: kFramedWindowButtonsWithoutTabStripOffsetFromTop;
buttonFrame.origin =
- NSMakePoint(xOffset, (NSHeight(frameViewBounds) -
+ NSMakePoint(xOffset, (NSHeight([self frame]) -
NSHeight(buttonFrame) - yOffset));
switch (kind) {
@@ -174,10 +168,6 @@ const CGFloat kWindowGradientHeight = 24.0;
[button setPostsFrameChangedNotifications:didPost];
}
-- (NSView*)frameView {
- return [[self contentView] superview];
-}
-
// The tab strip view covers our window buttons. So we add hit testing here
// to find them properly and return them to the accessibility system.
- (id)accessibilityHitTest:(NSPoint)point {
@@ -196,60 +186,6 @@ const CGFloat kWindowGradientHeight = 24.0;
return value;
}
-- (void)windowMainStatusChanged {
- NSView* frameView = [self frameView];
- NSView* contentView = [self contentView];
- NSRect updateRect = [frameView frame];
- NSRect contentRect = [contentView frame];
- CGFloat tabStripHeight = [TabStripController defaultTabHeight];
- updateRect.size.height -= NSHeight(contentRect) - tabStripHeight;
- updateRect.origin.y = NSMaxY(contentRect) - tabStripHeight;
- [[self frameView] setNeedsDisplayInRect:updateRect];
-}
-
-- (void)becomeMainWindow {
- [self windowMainStatusChanged];
- [super becomeMainWindow];
-}
-
-- (void)resignMainWindow {
- [self windowMainStatusChanged];
- [super resignMainWindow];
-}
-
-// Called after the current theme has changed.
-- (void)themeDidChangeNotification:(NSNotification*)aNotification {
- [[self frameView] setNeedsDisplay:YES];
-}
-
-- (void)sendEvent:(NSEvent*)event {
- // For Cocoa windows, clicking on the close and the miniaturize buttons (but
- // not the zoom button) while a window is in the background does NOT bring
- // that window to the front. We don't get that behavior for free (probably
- // because the tab strip view covers those buttons), so we handle it here.
- // Zoom buttons do bring the window to the front. Note that Finder windows (in
- // Leopard) behave differently in this regard in that zoom buttons don't bring
- // the window to the foreground.
- BOOL eventHandled = NO;
- if (![self isMainWindow]) {
- if ([event type] == NSLeftMouseDown) {
- NSView* frameView = [self frameView];
- NSPoint mouse = [frameView convertPoint:[event locationInWindow]
- fromView:nil];
- if (NSPointInRect(mouse, [closeButton_ frame])) {
- [closeButton_ mouseDown:event];
- eventHandled = YES;
- } else if (NSPointInRect(mouse, [miniaturizeButton_ frame])) {
- [miniaturizeButton_ mouseDown:event];
- eventHandled = YES;
- }
- }
- }
- if (!eventHandled) {
- [super sendEvent:event];
- }
-}
-
- (void)setShouldHideTitle:(BOOL)flag {
shouldHideTitle_ = flag;
}
@@ -367,14 +303,6 @@ const CGFloat kWindowGradientHeight = 24.0;
NSPoint position = [[view window] themeImagePositionForAlignment:
THEME_IMAGE_ALIGN_WITH_FRAME];
-
- // Align the phase to physical pixels so resizing the window under HiDPI
- // doesn't cause wiggling of the theme.
- NSView* frameView = [[[view window] contentView] superview];
- position = [frameView convertPointToBase:position];
- position.x = floor(position.x);
- position.y = floor(position.y);
- position = [frameView convertPointFromBase:position];
[[NSGraphicsContext currentContext] cr_setPatternPhase:position
forView:view];
@@ -400,10 +328,9 @@ const CGFloat kWindowGradientHeight = 24.0;
if (overlayImage) {
// Anchor to top-left and don't scale.
- NSView* frameView = [[[view window] contentView] superview];
NSPoint position = [[view window] themeImagePositionForAlignment:
THEME_IMAGE_ALIGN_WITH_FRAME];
- position = [view convertPoint:position fromView:frameView];
+ position = [view convertPoint:position fromView:nil];
NSSize overlaySize = [overlayImage size];
NSRect imageFrame = NSMakeRect(0, 0, overlaySize.width, overlaySize.height);
[overlayImage drawAtPoint:NSMakePoint(position.x,
diff --git a/chrome/browser/ui/cocoa/tabs/tab_window_controller.h b/chrome/browser/ui/cocoa/tabs/tab_window_controller.h
index 9cbe669..0a5f724 100644
--- a/chrome/browser/ui/cocoa/tabs/tab_window_controller.h
+++ b/chrome/browser/ui/cocoa/tabs/tab_window_controller.h
@@ -154,15 +154,6 @@
// during a drag.
- (void)deferPerformClose;
-// The tab strip should always be inserted directly above the content view.
-- (void)insertTabStripView:(NSView*)tabStripView intoWindow:(NSWindow*)window;
-
-// The tab strip background view should always be inserted as the back-most
-// subview of the root view. It cannot be a subview of the contentView, as that
-// would cause it to become layer backed, which would cause it to draw on top
-// of non-layer backed content like the window controls.
-- (void)insertTabStripBackgroundViewIntoWindow:(NSWindow*)window;
-
@end
@interface TabWindowController(ProtectedMethods)
diff --git a/chrome/browser/ui/cocoa/tabs/tab_window_controller.mm b/chrome/browser/ui/cocoa/tabs/tab_window_controller.mm
index d49e5e7..0100d03 100644
--- a/chrome/browser/ui/cocoa/tabs/tab_window_controller.mm
+++ b/chrome/browser/ui/cocoa/tabs/tab_window_controller.mm
@@ -101,7 +101,7 @@
[tabStripView_ setAutoresizingMask:NSViewWidthSizable |
NSViewMinYMargin];
if (hasTabStrip)
- [self insertTabStripView:tabStripView_ intoWindow:[self window]];
+ [windowView addSubview:tabStripView_];
}
return self;
}
@@ -189,7 +189,7 @@
positioned:NSWindowBelow
relativeTo:nil];
originalContentView_.frame = [[window contentView] bounds];
- [self insertTabStripView:[self tabStripView] intoWindow:window];
+ [[window contentView] addSubview:[self tabStripView]];
[[window contentView] updateTrackingAreas];
[focusBeforeOverlay_ restoreFocusInWindow:window];
@@ -327,18 +327,6 @@
closeDeferred_ = YES;
}
-- (void)insertTabStripView:(NSView*)tabStripView intoWindow:(NSWindow*)window {
- NSView* contentParent = [window contentView];
- if (contentParent == [[window contentView] superview]) {
- // Add the tab strip directly above the content view, if they are siblings.
- [contentParent addSubview:tabStripView
- positioned:NSWindowAbove
- relativeTo:[window contentView]];
- } else {
- [contentParent addSubview:tabStripView];
- }
-}
-
- (void)insertTabStripBackgroundViewIntoWindow:(NSWindow*)window {
DCHECK(tabStripBackgroundView_);
NSView* rootView = [[window contentView] superview];
diff --git a/chrome/browser/ui/cocoa/themed_window.h b/chrome/browser/ui/cocoa/themed_window.h
index ab4b18c..0a55c2b 100644
--- a/chrome/browser/ui/cocoa/themed_window.h
+++ b/chrome/browser/ui/cocoa/themed_window.h
@@ -36,11 +36,10 @@ enum ThemeImageAlignment {
- (ThemeProvider*)themeProvider;
- (ThemedWindowStyle)themedWindowStyle;
-// Returns the position in the coordinates of the root view
-// ([[self contentView] superview]) that the top left of a theme image with
-// |alignment| should be painted at. The result of this method can be used in
-// conjunction with [NSGraphicsContext cr_setPatternPhase:] to set the offset of
-// pattern colors.
+// Returns the position in window coordinates that the top left of a theme
+// image with |alignment| should be painted at. The result of this method can
+// be used in conjunction with [NSGraphicsContext cr_setPatternPhase:] to set
+// the offset of pattern colors.
- (NSPoint)themeImagePositionForAlignment:(ThemeImageAlignment)alignment;
@end