Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / ui / base / cocoa / nsgraphics_context_additions.mm
blob9e85fad24f248e65504bd6fe0972edfd2c9ea531
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #import "ui/base/cocoa/nsgraphics_context_additions.h"
7 @implementation NSGraphicsContext (CrAdditions)
9 - (void)cr_setPatternPhase:(NSPoint)phase
10                    forView:(NSView*)view {
11   NSView* ancestorWithLayer = view;
12   while (ancestorWithLayer && ![ancestorWithLayer layer])
13     ancestorWithLayer = [ancestorWithLayer superview];
14   if (ancestorWithLayer) {
15     NSPoint bottomLeft = NSZeroPoint;
16     if ([ancestorWithLayer isFlipped])
17       bottomLeft.y = NSMaxY([ancestorWithLayer bounds]);
18     NSPoint offset = [ancestorWithLayer convertPoint:bottomLeft toView:nil];
19     phase.x -= offset.x;
20     phase.y -= offset.y;
21   }
22   [self setPatternPhase:phase];
25 @end