summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
Diffstat (limited to 'ui')
-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
5 files changed, 74 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];
+}
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',