|
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. 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 #include "NetscapePlugin.h" |
|
27 |
|
28 #include <WebCore/GraphicsContext.h> |
|
29 |
|
30 using namespace WebCore; |
|
31 |
|
32 namespace WebKit { |
|
33 |
|
34 NPError NetscapePlugin::setDrawingModel(NPDrawingModel drawingModel) |
|
35 { |
|
36 // The drawing model can only be set from NPP_New. |
|
37 if (!m_inNPPNew) |
|
38 return NPERR_GENERIC_ERROR; |
|
39 |
|
40 switch (drawingModel) { |
|
41 #ifndef NP_NO_QUICKDRAW |
|
42 case NPDrawingModelQuickDraw: |
|
43 #endif |
|
44 case NPDrawingModelCoreGraphics: |
|
45 case NPDrawingModelCoreAnimation: |
|
46 m_drawingModel = drawingModel; |
|
47 break; |
|
48 |
|
49 default: |
|
50 return NPERR_GENERIC_ERROR; |
|
51 } |
|
52 |
|
53 return NPERR_NO_ERROR; |
|
54 } |
|
55 |
|
56 NPError NetscapePlugin::setEventModel(NPEventModel eventModel) |
|
57 { |
|
58 // The event model can only be set from NPP_New. |
|
59 if (!m_inNPPNew) |
|
60 return NPERR_GENERIC_ERROR; |
|
61 |
|
62 switch (eventModel) { |
|
63 #ifndef NP_NO_CARBON |
|
64 case NPEventModelCarbon: |
|
65 #endif |
|
66 case NPEventModelCocoa: |
|
67 m_eventModel = eventModel; |
|
68 break; |
|
69 |
|
70 default: |
|
71 return NPERR_GENERIC_ERROR; |
|
72 } |
|
73 |
|
74 return NPERR_NO_ERROR; |
|
75 } |
|
76 |
|
77 bool NetscapePlugin::platformPostInitialize() |
|
78 { |
|
79 if (m_drawingModel == static_cast<NPDrawingModel>(-1)) { |
|
80 #ifndef NP_NO_QUICKDRAW |
|
81 // Default to QuickDraw if the plugin did not specify a drawing model. |
|
82 m_drawingModel = NPDrawingModelQuickDraw; |
|
83 #else |
|
84 // QuickDraw is not available, so we can't default to it. Instead, default to CoreGraphics. |
|
85 m_drawingModel = NPDrawingModelCoreGraphics; |
|
86 #endif |
|
87 } |
|
88 |
|
89 if (m_eventModel == static_cast<NPEventModel>(-1)) { |
|
90 // If the plug-in did not specify a drawing model we default to Carbon when it is available. |
|
91 #ifndef NP_NO_CARBON |
|
92 m_eventModel = NPEventModelCarbon; |
|
93 #else |
|
94 m_eventModel = NPEventModelCocoa; |
|
95 #endif // NP_NO_CARBON |
|
96 } |
|
97 |
|
98 #if !defined(NP_NO_CARBON) && !defined(NP_NO_QUICKDRAW) |
|
99 // The CA drawing model does not work with the Carbon event model. |
|
100 if (m_drawingModel == NPDrawingModelCoreAnimation && m_eventModel == NPEventModelCarbon) |
|
101 return false; |
|
102 |
|
103 // The Cocoa event model does not work with the QuickDraw drawing model. |
|
104 if (m_eventModel == NPEventModelCocoa && m_drawingModel == NPDrawingModelQuickDraw) |
|
105 return false; |
|
106 #endif |
|
107 |
|
108 #ifndef NP_NO_QUICKDRAW |
|
109 // Right now we don't support the QuickDraw drawing model at all |
|
110 if (m_drawingModel == NPDrawingModelQuickDraw) |
|
111 return false; |
|
112 #endif |
|
113 |
|
114 return true; |
|
115 } |
|
116 |
|
117 static inline NPCocoaEvent initializeEvent(NPCocoaEventType type) |
|
118 { |
|
119 NPCocoaEvent event; |
|
120 |
|
121 event.type = type; |
|
122 event.version = 0; |
|
123 |
|
124 return event; |
|
125 } |
|
126 |
|
127 void NetscapePlugin::platformPaint(GraphicsContext* context, const IntRect& dirtyRect) |
|
128 { |
|
129 switch (m_eventModel) { |
|
130 case NPEventModelCocoa: { |
|
131 NPCocoaEvent event = initializeEvent(NPCocoaEventDrawRect); |
|
132 |
|
133 event.data.draw.context = context->platformContext(); |
|
134 event.data.draw.x = dirtyRect.x() - m_frameRect.x(); |
|
135 event.data.draw.y = dirtyRect.y() - m_frameRect.y(); |
|
136 event.data.draw.width = dirtyRect.width(); |
|
137 event.data.draw.height = dirtyRect.height(); |
|
138 |
|
139 m_pluginModule->pluginFuncs().event(&m_npp, &event); |
|
140 break; |
|
141 } |
|
142 |
|
143 default: |
|
144 ASSERT_NOT_REACHED(); |
|
145 } |
|
146 } |
|
147 |
|
148 } // namespace WebKit |