diff options
author | sail@chromium.org <sail@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-13 05:03:50 +0000 |
---|---|---|
committer | sail@chromium.org <sail@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-13 05:03:50 +0000 |
commit | 82a96c6ed1372f031bc6e3e1232c81dffc1f3a3d (patch) | |
tree | 00ddcf843b8df90bdba49b6ca755478a451138eb /ui/base | |
parent | e00e478687d5f893a787ff9e2e054bccd8c6cae8 (diff) | |
download | chromium_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
Diffstat (limited to 'ui/base')
-rw-r--r-- | ui/base/cocoa/nsgraphics_context_additions.h | 23 | ||||
-rw-r--r-- | ui/base/cocoa/nsgraphics_context_additions.mm | 20 | ||||
-rw-r--r-- | ui/base/cocoa/nsgraphics_context_additions_unittest.mm | 28 |
3 files changed, 71 insertions, 0 deletions
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]; +} |