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