1/*
2 * Copyright (C) 2008, 2009 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. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#import "config.h"
27#import "WebEventRegion.h"
28
29#if ENABLE(TOUCH_EVENTS)
30
31#import "FloatQuad.h"
32
33using namespace WebCore;
34
35@interface WebEventRegion(Private)
36- (FloatQuad)quad;
37@end
38
39@implementation WebEventRegion
40
41- (id)initWithPoints:(CGPoint)inP1 :(CGPoint)inP2 :(CGPoint)inP3 :(CGPoint)inP4
42{
43    if (!(self = [super init]))
44        return nil;
45
46    p1 = inP1;
47    p2 = inP2;
48    p3 = inP3;
49    p4 = inP4;
50    return self;
51}
52
53- (id)copyWithZone:(NSZone *)zone
54{
55    UNUSED_PARAM(zone);
56    return [self retain];
57}
58
59- (NSString *)description
60{
61    return [NSString stringWithFormat:@"p1:{%g, %g} p2:{%g, %g} p3:{%g, %g} p4:{%g, %g}", p1.x, p1.y, p2.x, p2.y, p3.x, p3.y, p4.x, p4.y];
62}
63
64- (BOOL)hitTest:(CGPoint)point
65{
66    return [self quad].containsPoint(point);
67}
68
69// FIXME: Overriding isEqual: without overriding hash will cause trouble if this ever goes into an NSSet or is the key in an NSDictionary,
70// since two equal objects could have different hashes.
71- (BOOL)isEqual:(id)other
72{
73    if (![other isKindOfClass:[WebEventRegion class]])
74        return NO;
75    return CGPointEqualToPoint(p1, ((WebEventRegion *)other)->p1)
76        && CGPointEqualToPoint(p2, ((WebEventRegion *)other)->p2)
77        && CGPointEqualToPoint(p3, ((WebEventRegion *)other)->p3)
78        && CGPointEqualToPoint(p4, ((WebEventRegion *)other)->p4);
79}
80
81- (FloatQuad)quad
82{
83    return FloatQuad(p1, p2, p3, p4);
84}
85
86- (CGPoint)p1
87{
88    return p1;
89}
90
91- (CGPoint)p2
92{
93    return p2;
94}
95
96- (CGPoint)p3
97{
98    return p3;
99}
100
101- (CGPoint)p4
102{
103    return p4;
104}
105
106@end
107
108#endif // ENABLE(TOUCH_EVENTS)
109