summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsail@chromium.org <sail@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-13 05:03:50 +0000
committersail@chromium.org <sail@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-13 05:03:50 +0000
commit82a96c6ed1372f031bc6e3e1232c81dffc1f3a3d (patch)
tree00ddcf843b8df90bdba49b6ca755478a451138eb
parente00e478687d5f893a787ff9e2e054bccd8c6cae8 (diff)
downloadchromium_src-82a96c6ed1372f031bc6e3e1232c81dffc1f3a3d.zip
chromium_src-82a96c6ed1372f031bc6e3e1232c81dffc1f3a3d.tar.gz
chromium_src-82a96c6ed1372f031bc6e3e1232c81dffc1f3a3d.tar.bz2
Fix setPatternPhase: for layer backed views
The browser UI drawing code assumes that setPatternPhase: set the phase relative to the bottom left of the window. For example, doing setPatternPhase:NSZeroPoint will correctly line up the pattern image for two sibling views with different origins. For layer backed views the pattern phase is relative to the view origin. This CL fixes pattern drawing by adding a utility method that correctly offsets the pattern phase to be relative to the window origin. BUG=245900 TEST=Run chrome with --use-core-animation. Verify that toolbars draw correct. Apply a theme and verify that the theme's images are lined up across toolbars and the tab strip. TBR=avi@chromium.org Review URL: https://codereview.chromium.org/16576007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@206004 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/ui/cocoa/bookmarks/bookmark_bar_toolbar_view.mm7
-rw-r--r--chrome/browser/ui/cocoa/download/download_shelf_view.mm3
-rw-r--r--chrome/browser/ui/cocoa/find_bar/find_bar_view.mm3
-rw-r--r--chrome/browser/ui/cocoa/gradient_button_cell.mm4
-rw-r--r--chrome/browser/ui/cocoa/styled_text_field_cell.mm4
-rw-r--r--chrome/browser/ui/cocoa/tabs/tab_strip_view.mm3
-rw-r--r--chrome/browser/ui/cocoa/tabs/tab_view.mm3
-rw-r--r--chrome/browser/ui/cocoa/toolbar/toolbar_view.mm3
-rw-r--r--ui/base/cocoa/nsgraphics_context_additions.h23
-rw-r--r--ui/base/cocoa/nsgraphics_context_additions.mm20
-rw-r--r--ui/base/cocoa/nsgraphics_context_additions_unittest.mm28
-rw-r--r--ui/ui.gyp2
-rw-r--r--ui/ui_unittests.gypi1
13 files changed, 94 insertions, 10 deletions
diff --git a/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_toolbar_view.mm b/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_toolbar_view.mm
index c78cd60..7c58eaa 100644
--- a/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_toolbar_view.mm
+++ b/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_toolbar_view.mm
@@ -16,6 +16,7 @@
#include "chrome/browser/ui/search/search_ui.h"
#include "grit/theme_resources.h"
#include "skia/ext/skia_utils_mac.h"
+#import "ui/base/cocoa/nsgraphics_context_additions.h"
#include "ui/base/theme_provider.h"
#include "ui/gfx/canvas_skia_paint.h"
#include "ui/gfx/rect.h"
@@ -50,7 +51,7 @@ const CGFloat kBorderRadius = 3.0;
[self drawAsDetachedBubble];
} else {
NSPoint phase = [[self window] themePatternPhase];
- [[NSGraphicsContext currentContext] setPatternPhase:phase];
+ [[NSGraphicsContext currentContext] cr_setPatternPhase:phase forView:self];
[self drawBackgroundWithOpaque:YES];
}
}
@@ -118,7 +119,7 @@ const CGFloat kBorderRadius = 3.0;
CGContextRef cgContext = static_cast<CGContextRef>([context graphicsPort]);
CGContextSetAlpha(cgContext, 1 - morph);
CGContextBeginTransparencyLayer(cgContext, NULL);
- [context setPatternPhase:[[self window] themePatternPhase]];
+ [context cr_setPatternPhase:[[self window] themePatternPhase] forView:self];
[self drawBackgroundWithOpaque:YES];
CGContextEndTransparencyLayer(cgContext);
}
@@ -171,7 +172,7 @@ const CGFloat kBorderRadius = 3.0;
CGContextRef cgContext = static_cast<CGContextRef>([context graphicsPort]);
CGContextSetAlpha(cgContext, 1 - morph);
CGContextBeginTransparencyLayer(cgContext, NULL);
- [context setPatternPhase:[[self window] themePatternPhase]];
+ [context cr_setPatternPhase:[[self window] themePatternPhase] forView:self];
[self drawBackgroundWithOpaque:YES];
CGContextEndTransparencyLayer(cgContext);
}
diff --git a/chrome/browser/ui/cocoa/download/download_shelf_view.mm b/chrome/browser/ui/cocoa/download/download_shelf_view.mm
index b3084c5..d5a6743 100644
--- a/chrome/browser/ui/cocoa/download/download_shelf_view.mm
+++ b/chrome/browser/ui/cocoa/download/download_shelf_view.mm
@@ -12,6 +12,7 @@
#import "chrome/browser/ui/cocoa/themed_window.h"
#import "chrome/browser/ui/cocoa/view_id_util.h"
#include "grit/theme_resources.h"
+#import "ui/base/cocoa/nsgraphics_context_additions.h"
#include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h"
@implementation DownloadShelfView
@@ -49,7 +50,7 @@
// background matches the toolbar background.
NSPoint phase = NSMakePoint(
0, NSHeight([self bounds]) + [TabStripController defaultTabHeight]);
- [[NSGraphicsContext currentContext] setPatternPhase:phase];
+ [[NSGraphicsContext currentContext] cr_setPatternPhase:phase forView:self];
[self drawBackgroundWithOpaque:YES];
// Draw top stroke
diff --git a/chrome/browser/ui/cocoa/find_bar/find_bar_view.mm b/chrome/browser/ui/cocoa/find_bar/find_bar_view.mm
index 523d090..eb7e9d5 100644
--- a/chrome/browser/ui/cocoa/find_bar/find_bar_view.mm
+++ b/chrome/browser/ui/cocoa/find_bar/find_bar_view.mm
@@ -8,6 +8,7 @@
#import "chrome/browser/ui/cocoa/themed_window.h"
#import "chrome/browser/ui/cocoa/url_drop_target.h"
#import "chrome/browser/ui/cocoa/view_id_util.h"
+#import "ui/base/cocoa/nsgraphics_context_additions.h"
#include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h"
namespace {
@@ -71,7 +72,7 @@ CGFloat kCurveSize = 8;
// Set the pattern phase
NSPoint phase = [[self window] themePatternPhase];
- [context setPatternPhase:phase];
+ [context cr_setPatternPhase:phase forView:self];
[super drawBackgroundWithOpaque:YES];
}
diff --git a/chrome/browser/ui/cocoa/gradient_button_cell.mm b/chrome/browser/ui/cocoa/gradient_button_cell.mm
index e2e96cb..b5b0d51 100644
--- a/chrome/browser/ui/cocoa/gradient_button_cell.mm
+++ b/chrome/browser/ui/cocoa/gradient_button_cell.mm
@@ -15,6 +15,7 @@
#import "chrome/browser/ui/cocoa/rect_path_utils.h"
#include "grit/theme_resources.h"
#import "third_party/GTM/AppKit/GTMNSColor+Luminance.h"
+#import "ui/base/cocoa/nsgraphics_context_additions.h"
#include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h"
@interface GradientButtonCell (Private)
@@ -386,7 +387,8 @@ static const NSTimeInterval kAnimationContinuousCycleDuration = 0.4;
// Set the phase to match window.
NSRect trueRect = [controlView convertRect:cellFrame toView:nil];
[[NSGraphicsContext currentContext]
- setPatternPhase:NSMakePoint(NSMinX(trueRect), NSMaxY(trueRect))];
+ cr_setPatternPhase:NSMakePoint(NSMinX(trueRect), NSMaxY(trueRect))
+ forView:controlView];
[innerPath fill];
} else {
if (showClickedGradient) {
diff --git a/chrome/browser/ui/cocoa/styled_text_field_cell.mm b/chrome/browser/ui/cocoa/styled_text_field_cell.mm
index 25a3edc..fedd3fc 100644
--- a/chrome/browser/ui/cocoa/styled_text_field_cell.mm
+++ b/chrome/browser/ui/cocoa/styled_text_field_cell.mm
@@ -10,6 +10,7 @@
#import "chrome/browser/ui/cocoa/nsview_additions.h"
#import "chrome/browser/ui/cocoa/themed_window.h"
#include "grit/theme_resources.h"
+#import "ui/base/cocoa/nsgraphics_context_additions.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/font.h"
#include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h"
@@ -98,7 +99,8 @@
// Set the phase to match window.
NSRect trueRect = [controlView convertRect:cellFrame toView:nil];
NSPoint midPoint = NSMakePoint(NSMinX(trueRect), NSMaxY(trueRect));
- [[NSGraphicsContext currentContext] setPatternPhase:midPoint];
+ [[NSGraphicsContext currentContext] cr_setPatternPhase:midPoint
+ forView:controlView];
// NOTE(shess): This seems like it should be using a 0.0 inset,
// but AFAICT using a halfLineWidth inset is important in mixing the
diff --git a/chrome/browser/ui/cocoa/tabs/tab_strip_view.mm b/chrome/browser/ui/cocoa/tabs/tab_strip_view.mm
index f86e53f..9748eb0 100644
--- a/chrome/browser/ui/cocoa/tabs/tab_strip_view.mm
+++ b/chrome/browser/ui/cocoa/tabs/tab_strip_view.mm
@@ -17,6 +17,7 @@
#import "chrome/browser/ui/cocoa/view_id_util.h"
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
+#import "ui/base/cocoa/nsgraphics_context_additions.h"
#include "ui/base/l10n/l10n_util_mac.h"
#include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h"
@@ -55,7 +56,7 @@
if (NSMinY(dirtyRect) < backgroundHeight) {
gfx::ScopedNSGraphicsContextSaveGState scopedGState;
NSGraphicsContext *context = [NSGraphicsContext currentContext];
- [context setPatternPhase:[[self window] themePatternPhase]];
+ [context cr_setPatternPhase:[[self window] themePatternPhase] forView:self];
// Themes don't have an inactive image so only look for one if there's no
// theme.
diff --git a/chrome/browser/ui/cocoa/tabs/tab_view.mm b/chrome/browser/ui/cocoa/tabs/tab_view.mm
index b77e9b4..c312444 100644
--- a/chrome/browser/ui/cocoa/tabs/tab_view.mm
+++ b/chrome/browser/ui/cocoa/tabs/tab_view.mm
@@ -14,6 +14,7 @@
#import "chrome/browser/ui/cocoa/view_id_util.h"
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
+#import "ui/base/cocoa/nsgraphics_context_additions.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h"
@@ -312,7 +313,7 @@ const CGFloat kRapidCloseDist = 2.5;
ThemeService* themeProvider =
static_cast<ThemeService*>([[self window] themeProvider]);
- [context setPatternPhase:[[self window] themePatternPhase]];
+ [context cr_setPatternPhase:[[self window] themePatternPhase] forView:self];
CGImageRef mask([self tabClippingMask]);
diff --git a/chrome/browser/ui/cocoa/toolbar/toolbar_view.mm b/chrome/browser/ui/cocoa/toolbar/toolbar_view.mm
index d8d5556..5b9cb46 100644
--- a/chrome/browser/ui/cocoa/toolbar/toolbar_view.mm
+++ b/chrome/browser/ui/cocoa/toolbar/toolbar_view.mm
@@ -6,6 +6,7 @@
#import "chrome/browser/ui/cocoa/themed_window.h"
#import "chrome/browser/ui/cocoa/view_id_util.h"
+#import "ui/base/cocoa/nsgraphics_context_additions.h"
@implementation ToolbarView
@@ -20,7 +21,7 @@
// The toolbar's background pattern is phased relative to the
// tab strip view's background pattern.
NSPoint phase = [[self window] themePatternPhase];
- [[NSGraphicsContext currentContext] setPatternPhase:phase];
+ [[NSGraphicsContext currentContext] cr_setPatternPhase:phase forView:self];
[self drawBackgroundWithOpaque:YES];
}
diff --git a/ui/base/cocoa/nsgraphics_context_additions.h b/ui/base/cocoa/nsgraphics_context_additions.h
new file mode 100644
index 0000000..7a373ef
--- /dev/null
+++ b/ui/base/cocoa/nsgraphics_context_additions.h
@@ -0,0 +1,23 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef UI_BASE_COCOA_NSGRAPHICS_CONTEXT_ADDITIONS_H_
+#define UI_BASE_COCOA_NSGRAPHICS_CONTEXT_ADDITIONS_H_
+
+#import <Cocoa/Cocoa.h>
+
+@interface NSGraphicsContext (CrAdditions)
+
+// When a view is not layer backed the pattern phase is relative to the origin
+// of the window's content view. With a layer backed view the pattern phase is
+// relative to the origin of the view.
+//
+// For layer backed view this method offsets the pattern phase to match the
+// behavior of non layer backed views.
+- (void)cr_setPatternPhase:(NSPoint)phase
+ forView:(NSView*)view;
+
+@end
+
+#endif // UI_BASE_COCOA_NSGRAPHICS_CONTEXT_ADDITIONS_H_
diff --git a/ui/base/cocoa/nsgraphics_context_additions.mm b/ui/base/cocoa/nsgraphics_context_additions.mm
new file mode 100644
index 0000000..11c2b1e
--- /dev/null
+++ b/ui/base/cocoa/nsgraphics_context_additions.mm
@@ -0,0 +1,20 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import "ui/base/cocoa/nsgraphics_context_additions.h"
+
+@implementation NSGraphicsContext (CrAdditions)
+
+- (void)cr_setPatternPhase:(NSPoint)phase
+ forView:(NSView*)view {
+ if ([view layer]) {
+ NSPoint bottomLeft = NSZeroPoint;
+ if ([view isFlipped])
+ bottomLeft.y = NSMaxY([view bounds]);
+ phase.y -= [view convertPoint:bottomLeft toView:nil].y;
+ }
+ [self setPatternPhase:phase];
+}
+
+@end
diff --git a/ui/base/cocoa/nsgraphics_context_additions_unittest.mm b/ui/base/cocoa/nsgraphics_context_additions_unittest.mm
new file mode 100644
index 0000000..88f137d
--- /dev/null
+++ b/ui/base/cocoa/nsgraphics_context_additions_unittest.mm
@@ -0,0 +1,28 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import "ui/base/cocoa/nsgraphics_context_additions.h"
+
+#include "base/memory/scoped_nsobject.h"
+#import "ui/base/test/ui_cocoa_test_helper.h"
+
+typedef ui::CocoaTest NSGraphicsContextCrAdditionsTest;
+
+TEST_F(NSGraphicsContextCrAdditionsTest, PatternPhase) {
+ NSRect frame = NSMakeRect(50, 50, 100, 100);
+ scoped_nsobject<NSView> view([[NSView alloc] initWithFrame:frame]);
+ [[test_window() contentView] addSubview:view];
+
+ [view lockFocus];
+ NSGraphicsContext* context = [NSGraphicsContext currentContext];
+
+ [context cr_setPatternPhase:NSZeroPoint forView:view];
+ EXPECT_EQ(0, [context patternPhase].y);
+
+ [view setWantsLayer:YES];
+ [context cr_setPatternPhase:NSZeroPoint forView:view];
+ EXPECT_EQ(-NSMinY(frame), [context patternPhase].y);
+
+ [view unlockFocus];
+}
diff --git a/ui/ui.gyp b/ui/ui.gyp
index b62489a..ea2ebc3 100644
--- a/ui/ui.gyp
+++ b/ui/ui.gyp
@@ -120,6 +120,8 @@
'base/cocoa/menu_controller.mm',
'base/cocoa/nib_loading.h',
'base/cocoa/nib_loading.mm',
+ 'base/cocoa/nsgraphics_context_additions.h',
+ 'base/cocoa/nsgraphics_context_additions.mm',
'base/cocoa/tracking_area.h',
'base/cocoa/tracking_area.mm',
'base/cocoa/underlay_opengl_hosting_window.h',
diff --git a/ui/ui_unittests.gypi b/ui/ui_unittests.gypi
index 4ddd7b0..32335d8 100644
--- a/ui/ui_unittests.gypi
+++ b/ui/ui_unittests.gypi
@@ -139,6 +139,7 @@
'base/cocoa/fullscreen_window_manager_unittest.mm',
'base/cocoa/hover_image_button_unittest.mm',
'base/cocoa/menu_controller_unittest.mm',
+ 'base/cocoa/nsgraphics_context_additions_unittest.mm',
'base/cocoa/tracking_area_unittest.mm',
'base/events/event_dispatcher_unittest.cc',
'base/events/event_unittest.cc',