1/*
2 * Copyright (C) 2012 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#ifndef PDFPluginAnnotation_h
27#define PDFPluginAnnotation_h
28
29#if ENABLE(PDFKIT_PLUGIN)
30
31#include <WebCore/EventListener.h>
32#include <wtf/RefCounted.h>
33#include <wtf/RetainPtr.h>
34
35namespace WebCore {
36class Document;
37class Element;
38}
39
40OBJC_CLASS PDFAnnotation;
41OBJC_CLASS PDFLayerController;
42
43namespace WebKit {
44
45class PDFPlugin;
46
47class PDFPluginAnnotation : public RefCounted<PDFPluginAnnotation> {
48public:
49    static PassRefPtr<PDFPluginAnnotation> create(PDFAnnotation *, PDFLayerController *, PDFPlugin*);
50    virtual ~PDFPluginAnnotation();
51
52    WebCore::Element* element() const { return m_element.get(); }
53    PDFAnnotation *annotation() const { return m_annotation.get(); }
54    PDFPlugin* plugin() const { return m_plugin; }
55
56    virtual void updateGeometry();
57    virtual void commit();
58
59    void attach(WebCore::Element*);
60
61protected:
62    PDFPluginAnnotation(PDFAnnotation *annotation, PDFLayerController *pdfLayerController, PDFPlugin* plugin)
63        : m_parent(0)
64        , m_annotation(annotation)
65        , m_eventListener(PDFPluginAnnotationEventListener::create(this))
66        , m_pdfLayerController(pdfLayerController)
67        , m_plugin(plugin)
68    {
69    }
70
71    WebCore::Element* parent() const { return m_parent; }
72    PDFLayerController *pdfLayerController() const { return m_pdfLayerController; }
73    WebCore::EventListener* eventListener() const { return m_eventListener.get(); }
74
75    virtual bool handleEvent(WebCore::Event*);
76
77private:
78    virtual PassRefPtr<WebCore::Element> createAnnotationElement() = 0;
79
80    class PDFPluginAnnotationEventListener : public WebCore::EventListener {
81    public:
82        static PassRefPtr<PDFPluginAnnotationEventListener> create(PDFPluginAnnotation* annotation)
83        {
84            return adoptRef(new PDFPluginAnnotationEventListener(annotation));
85        }
86
87        virtual bool operator==(const EventListener& listener) OVERRIDE { return this == &listener; }
88
89        void setAnnotation(PDFPluginAnnotation* annotation) { m_annotation = annotation; }
90
91    private:
92
93        PDFPluginAnnotationEventListener(PDFPluginAnnotation* annotation)
94            : WebCore::EventListener(WebCore::EventListener::CPPEventListenerType)
95            , m_annotation(annotation)
96        {
97        }
98
99        virtual void handleEvent(WebCore::ScriptExecutionContext*, WebCore::Event*) OVERRIDE;
100
101        PDFPluginAnnotation* m_annotation;
102    };
103
104    WebCore::Element* m_parent;
105
106    RefPtr<WebCore::Element> m_element;
107    RetainPtr<PDFAnnotation> m_annotation;
108
109    RefPtr<PDFPluginAnnotationEventListener> m_eventListener;
110
111    PDFLayerController *m_pdfLayerController;
112    PDFPlugin* m_plugin;
113};
114
115} // namespace WebKit
116
117#endif // ENABLE(PDFKIT_PLUGIN)
118
119#endif // PDFPluginAnnotation_h
120