[Cocoa] More tweaks and refactoring to prepare for ARC
[WebKit.git] / Tools / DumpRenderTree / TestNetscapePlugIn / PluginObjectMac.mm
1 /*
2  * Copyright (C) 2010 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
24  */
25
26 #include "PluginObject.h"
27
28 #include <QuartzCore/QuartzCore.h>
29
30 @interface TestPluginLayer : CALayer
31 @end
32
33 @implementation TestPluginLayer
34
35 - (void)drawInContext:(CGContextRef)context
36 {
37     CGRect bounds = [self bounds];
38     const char* text = "Test Plug-in";
39     CGContextSelectFont(context, "Helvetica", 24, kCGEncodingMacRoman);
40     CGContextShowTextAtPoint(context, bounds.origin.x + 3.0f, bounds.origin.y + bounds.size.height - 30.0f, text, strlen(text));
41 }
42
43 @end
44
45 const void* createCoreAnimationLayer()
46 {
47     CALayer *caLayer = [[TestPluginLayer alloc] init];
48
49     NSNull *nullValue = [NSNull null];
50     NSDictionary *actions = [NSDictionary dictionaryWithObjectsAndKeys:
51                              nullValue, @"anchorPoint",
52                              nullValue, @"bounds",
53                              nullValue, @"contents",
54                              nullValue, @"contentsRect",
55                              nullValue, @"opacity",
56                              nullValue, @"position",
57                              nullValue, @"shadowColor",
58                              nullValue, @"sublayerTransform",
59                              nullValue, @"sublayers",
60                              nullValue, @"transform",
61                              nullValue, @"zPosition",
62                              nil];
63     // Turn off default animations.
64     [caLayer setStyle:[NSDictionary dictionaryWithObject:actions forKey:@"actions"]];
65     [caLayer setNeedsDisplayOnBoundsChange:YES];
66
67     [caLayer setBounds:CGRectMake(0, 0, 200, 100)];
68     [caLayer setAnchorPoint:CGPointZero];
69     
70     CGColorRef color = CGColorCreateGenericRGB(0.5, 0.5, 1, 1);
71     [caLayer setBackgroundColor:color];
72     CGColorRelease(color);
73     
74     [caLayer setLayoutManager:[CAConstraintLayoutManager layoutManager]];
75
76     CALayer *sublayer = [CALayer layer];
77     // Turn off default animations.
78     [sublayer setStyle:[NSDictionary dictionaryWithObject:actions forKey:@"actions"]];
79
80     color = CGColorCreateGenericRGB(0, 0, 0, 0.75);
81     [sublayer setBackgroundColor:color];
82     CGColorRelease(color);
83     [sublayer setBounds:CGRectMake(0, 0, 180, 20)];
84
85     [sublayer addConstraint:[CAConstraint constraintWithAttribute:kCAConstraintMinY
86                                                      relativeTo:@"superlayer"
87                                                       attribute:kCAConstraintMinY]];
88     [sublayer addConstraint:[CAConstraint constraintWithAttribute:kCAConstraintMinX
89                                                      relativeTo:@"superlayer"
90                                                       attribute:kCAConstraintMinX]];
91     [sublayer addConstraint:[CAConstraint constraintWithAttribute:kCAConstraintMaxX
92                                                      relativeTo:@"superlayer"
93                                                       attribute:kCAConstraintMaxX]];
94
95     [caLayer addSublayer:sublayer];
96     return CFBridgingRetain(caLayer);
97 }