OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "webkit/plugins/ppapi/ppb_scrollbar_impl.h" | 5 #include "webkit/plugins/ppapi/ppb_scrollbar_impl.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "ppapi/c/dev/ppp_scrollbar_dev.h" | 9 #include "ppapi/c/dev/ppp_scrollbar_dev.h" |
10 #include "ppapi/thunk/thunk.h" | 10 #include "ppapi/thunk/thunk.h" |
11 #include "skia/ext/platform_canvas.h" | 11 #include "skia/ext/platform_canvas.h" |
12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" | 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebRect.h" | 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebRect.h" |
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScrollbar.h" | 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScrollbar.h" |
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebVector.h" | 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebVector.h" |
16 #include "webkit/plugins/ppapi/common.h" | 16 #include "webkit/plugins/ppapi/common.h" |
17 #include "webkit/plugins/ppapi/event_conversion.h" | 17 #include "webkit/plugins/ppapi/event_conversion.h" |
18 #include "webkit/plugins/ppapi/plugin_module.h" | 18 #include "webkit/plugins/ppapi/plugin_module.h" |
19 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 19 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
20 #include "webkit/plugins/ppapi/ppb_image_data_impl.h" | 20 #include "webkit/plugins/ppapi/ppb_image_data_impl.h" |
| 21 #include "webkit/plugins/ppapi/resource_helper.h" |
21 #include "webkit/glue/webkit_glue.h" | 22 #include "webkit/glue/webkit_glue.h" |
22 | 23 |
23 #if defined(OS_WIN) | 24 #if defined(OS_WIN) |
24 #include "base/win/windows_version.h" | 25 #include "base/win/windows_version.h" |
25 #endif | 26 #endif |
26 | 27 |
27 using ppapi::thunk::PPB_Scrollbar_API; | 28 using ppapi::thunk::PPB_Scrollbar_API; |
28 using WebKit::WebInputEvent; | 29 using WebKit::WebInputEvent; |
29 using WebKit::WebRect; | 30 using WebKit::WebRect; |
30 using WebKit::WebScrollbar; | 31 using WebKit::WebScrollbar; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 &GetValue, | 102 &GetValue, |
102 &SetValue, | 103 &SetValue, |
103 &SetDocumentSize, | 104 &SetDocumentSize, |
104 &SetTickMarks, | 105 &SetTickMarks, |
105 &ScrollBy | 106 &ScrollBy |
106 }; | 107 }; |
107 | 108 |
108 } // namespace | 109 } // namespace |
109 | 110 |
110 // static | 111 // static |
111 PP_Resource PPB_Scrollbar_Impl::Create(PluginInstance* instance, | 112 PP_Resource PPB_Scrollbar_Impl::Create(PP_Instance instance, |
112 bool vertical) { | 113 bool vertical) { |
113 scoped_refptr<PPB_Scrollbar_Impl> scrollbar( | 114 scoped_refptr<PPB_Scrollbar_Impl> scrollbar( |
114 new PPB_Scrollbar_Impl(instance)); | 115 new PPB_Scrollbar_Impl(instance)); |
115 scrollbar->Init(vertical); | 116 scrollbar->Init(vertical); |
116 return scrollbar->GetReference(); | 117 return scrollbar->GetReference(); |
117 } | 118 } |
118 | 119 |
119 PPB_Scrollbar_Impl::PPB_Scrollbar_Impl(PluginInstance* instance) | 120 PPB_Scrollbar_Impl::PPB_Scrollbar_Impl(PP_Instance instance) |
120 : PPB_Widget_Impl(instance), | 121 : PPB_Widget_Impl(instance), |
121 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { | 122 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { |
122 } | 123 } |
123 | 124 |
124 PPB_Scrollbar_Impl::~PPB_Scrollbar_Impl() { | 125 PPB_Scrollbar_Impl::~PPB_Scrollbar_Impl() { |
125 } | 126 } |
126 | 127 |
127 void PPB_Scrollbar_Impl::Init(bool vertical) { | 128 void PPB_Scrollbar_Impl::Init(bool vertical) { |
| 129 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); |
| 130 if (!plugin_instance) |
| 131 return; |
128 scrollbar_.reset(WebScrollbar::createForPlugin( | 132 scrollbar_.reset(WebScrollbar::createForPlugin( |
129 vertical ? WebScrollbar::Vertical : WebScrollbar::Horizontal, | 133 vertical ? WebScrollbar::Vertical : WebScrollbar::Horizontal, |
130 instance()->container(), | 134 ResourceHelper::GetPluginInstance(this)->container(), |
131 static_cast<WebKit::WebScrollbarClient*>(this))); | 135 static_cast<WebKit::WebScrollbarClient*>(this))); |
132 } | 136 } |
133 | 137 |
134 PPB_Scrollbar_API* PPB_Scrollbar_Impl::AsPPB_Scrollbar_API() { | 138 PPB_Scrollbar_API* PPB_Scrollbar_Impl::AsPPB_Scrollbar_API() { |
135 return this; | 139 return this; |
136 } | 140 } |
137 | 141 |
| 142 void PPB_Scrollbar_Impl::InstanceWasDeleted() { |
| 143 Resource::LastPluginRefWasDeleted(); |
| 144 scrollbar_.reset(); |
| 145 } |
| 146 |
138 // static | 147 // static |
139 const PPB_Scrollbar_0_3_Dev* PPB_Scrollbar_Impl::Get0_3Interface() { | 148 const PPB_Scrollbar_0_3_Dev* PPB_Scrollbar_Impl::Get0_3Interface() { |
140 return &ppb_scrollbar_0_3; | 149 return &ppb_scrollbar_0_3; |
141 } | 150 } |
142 | 151 |
143 // static | 152 // static |
144 const PPB_Scrollbar_0_4_Dev* PPB_Scrollbar_Impl::Get0_4Interface() { | 153 const PPB_Scrollbar_0_4_Dev* PPB_Scrollbar_Impl::Get0_4Interface() { |
145 return &ppb_scrollbar_0_4; | 154 return &ppb_scrollbar_0_4; |
146 } | 155 } |
147 | 156 |
148 uint32_t PPB_Scrollbar_Impl::GetThickness() { | 157 uint32_t PPB_Scrollbar_Impl::GetThickness() { |
149 return WebScrollbar::defaultThickness(); | 158 return WebScrollbar::defaultThickness(); |
150 } | 159 } |
151 | 160 |
152 bool PPB_Scrollbar_Impl::IsOverlay() { | 161 bool PPB_Scrollbar_Impl::IsOverlay() { |
153 return scrollbar_->isOverlay(); | 162 return scrollbar_->isOverlay(); |
154 } | 163 } |
155 | 164 |
156 uint32_t PPB_Scrollbar_Impl::GetValue() { | 165 uint32_t PPB_Scrollbar_Impl::GetValue() { |
157 return scrollbar_->value(); | 166 return scrollbar_->value(); |
158 } | 167 } |
159 | 168 |
160 void PPB_Scrollbar_Impl::SetValue(uint32_t value) { | 169 void PPB_Scrollbar_Impl::SetValue(uint32_t value) { |
161 scrollbar_->setValue(value); | 170 if (scrollbar_.get()) |
| 171 scrollbar_->setValue(value); |
162 } | 172 } |
163 | 173 |
164 void PPB_Scrollbar_Impl::SetDocumentSize(uint32_t size) { | 174 void PPB_Scrollbar_Impl::SetDocumentSize(uint32_t size) { |
165 scrollbar_->setDocumentSize(size); | 175 if (scrollbar_.get()) |
| 176 scrollbar_->setDocumentSize(size); |
166 } | 177 } |
167 | 178 |
168 void PPB_Scrollbar_Impl::SetTickMarks(const PP_Rect* tick_marks, | 179 void PPB_Scrollbar_Impl::SetTickMarks(const PP_Rect* tick_marks, |
169 uint32_t count) { | 180 uint32_t count) { |
| 181 if (!scrollbar_.get()) |
| 182 return; |
170 tickmarks_.resize(count); | 183 tickmarks_.resize(count); |
171 for (uint32 i = 0; i < count; ++i) { | 184 for (uint32 i = 0; i < count; ++i) { |
172 tickmarks_[i] = WebRect(tick_marks[i].point.x, | 185 tickmarks_[i] = WebRect(tick_marks[i].point.x, |
173 tick_marks[i].point.y, | 186 tick_marks[i].point.y, |
174 tick_marks[i].size.width, | 187 tick_marks[i].size.width, |
175 tick_marks[i].size.height);; | 188 tick_marks[i].size.height);; |
176 } | 189 } |
177 PP_Rect rect = location(); | 190 PP_Rect rect = location(); |
178 Invalidate(&rect); | 191 Invalidate(&rect); |
179 } | 192 } |
180 | 193 |
181 void PPB_Scrollbar_Impl::ScrollBy(PP_ScrollBy_Dev unit, int32_t multiplier) { | 194 void PPB_Scrollbar_Impl::ScrollBy(PP_ScrollBy_Dev unit, int32_t multiplier) { |
| 195 if (!scrollbar_.get()) |
| 196 return; |
| 197 |
182 WebScrollbar::ScrollDirection direction = multiplier >= 0 ? | 198 WebScrollbar::ScrollDirection direction = multiplier >= 0 ? |
183 WebScrollbar::ScrollForward : WebScrollbar::ScrollBackward; | 199 WebScrollbar::ScrollForward : WebScrollbar::ScrollBackward; |
184 float fmultiplier = 1.0; | 200 float fmultiplier = 1.0; |
185 | 201 |
186 WebScrollbar::ScrollGranularity granularity; | 202 WebScrollbar::ScrollGranularity granularity; |
187 if (unit == PP_SCROLLBY_LINE) { | 203 if (unit == PP_SCROLLBY_LINE) { |
188 granularity = WebScrollbar::ScrollByLine; | 204 granularity = WebScrollbar::ScrollByLine; |
189 } else if (unit == PP_SCROLLBY_PAGE) { | 205 } else if (unit == PP_SCROLLBY_PAGE) { |
190 granularity = WebScrollbar::ScrollByPage; | 206 granularity = WebScrollbar::ScrollByPage; |
191 } else if (unit == PP_SCROLLBY_DOCUMENT) { | 207 } else if (unit == PP_SCROLLBY_DOCUMENT) { |
192 granularity = WebScrollbar::ScrollByDocument; | 208 granularity = WebScrollbar::ScrollByDocument; |
193 } else { | 209 } else { |
194 granularity = WebScrollbar::ScrollByPixel; | 210 granularity = WebScrollbar::ScrollByPixel; |
195 fmultiplier = static_cast<float>(multiplier); | 211 fmultiplier = static_cast<float>(multiplier); |
196 if (fmultiplier < 0) | 212 if (fmultiplier < 0) |
197 fmultiplier *= -1; | 213 fmultiplier *= -1; |
198 } | 214 } |
199 scrollbar_->scroll(direction, granularity, fmultiplier); | 215 scrollbar_->scroll(direction, granularity, fmultiplier); |
200 } | 216 } |
201 | 217 |
202 PP_Bool PPB_Scrollbar_Impl::PaintInternal(const gfx::Rect& rect, | 218 PP_Bool PPB_Scrollbar_Impl::PaintInternal(const gfx::Rect& rect, |
203 PPB_ImageData_Impl* image) { | 219 PPB_ImageData_Impl* image) { |
204 ImageDataAutoMapper mapper(image); | 220 ImageDataAutoMapper mapper(image); |
205 skia::PlatformCanvas* canvas = image->mapped_canvas(); | 221 skia::PlatformCanvas* canvas = image->mapped_canvas(); |
206 if (!canvas) | 222 if (!canvas || !scrollbar_.get()) |
207 return PP_FALSE; | 223 return PP_FALSE; |
208 scrollbar_->paint(webkit_glue::ToWebCanvas(canvas), rect); | 224 scrollbar_->paint(webkit_glue::ToWebCanvas(canvas), rect); |
209 | 225 |
210 #if defined(OS_WIN) | 226 #if defined(OS_WIN) |
211 if (base::win::GetVersion() == base::win::VERSION_XP) | 227 if (base::win::GetVersion() == base::win::VERSION_XP) |
212 skia::MakeOpaque(canvas, rect.x(), rect.y(), rect.width(), rect.height()); | 228 skia::MakeOpaque(canvas, rect.x(), rect.y(), rect.width(), rect.height()); |
213 #endif | 229 #endif |
214 | 230 |
215 return PP_TRUE; | 231 return PP_TRUE; |
216 } | 232 } |
217 | 233 |
218 PP_Bool PPB_Scrollbar_Impl::HandleEventInternal( | 234 PP_Bool PPB_Scrollbar_Impl::HandleEventInternal( |
219 const ::ppapi::InputEventData& data) { | 235 const ::ppapi::InputEventData& data) { |
220 scoped_ptr<WebInputEvent> web_input_event(CreateWebInputEvent(data)); | 236 scoped_ptr<WebInputEvent> web_input_event(CreateWebInputEvent(data)); |
221 if (!web_input_event.get()) | 237 if (!web_input_event.get() || !scrollbar_.get()) |
222 return PP_FALSE; | 238 return PP_FALSE; |
223 | 239 |
224 return PP_FromBool(scrollbar_->handleInputEvent(*web_input_event.get())); | 240 return PP_FromBool(scrollbar_->handleInputEvent(*web_input_event.get())); |
225 } | 241 } |
226 | 242 |
227 void PPB_Scrollbar_Impl::SetLocationInternal(const PP_Rect* location) { | 243 void PPB_Scrollbar_Impl::SetLocationInternal(const PP_Rect* location) { |
| 244 if (!scrollbar_.get()) |
| 245 return; |
228 scrollbar_->setLocation(WebRect(location->point.x, | 246 scrollbar_->setLocation(WebRect(location->point.x, |
229 location->point.y, | 247 location->point.y, |
230 location->size.width, | 248 location->size.width, |
231 location->size.height)); | 249 location->size.height)); |
232 } | 250 } |
233 | 251 |
234 void PPB_Scrollbar_Impl::valueChanged(WebKit::WebScrollbar* scrollbar) { | 252 void PPB_Scrollbar_Impl::valueChanged(WebKit::WebScrollbar* scrollbar) { |
| 253 PluginModule* plugin_module = ResourceHelper::GetPluginModule(this); |
| 254 if (!plugin_module) |
| 255 return; |
| 256 |
235 const PPP_Scrollbar_Dev* ppp_scrollbar = | 257 const PPP_Scrollbar_Dev* ppp_scrollbar = |
236 static_cast<const PPP_Scrollbar_Dev*>(instance()->module()-> | 258 static_cast<const PPP_Scrollbar_Dev*>(plugin_module->GetPluginInterface( |
237 GetPluginInterface(PPP_SCROLLBAR_DEV_INTERFACE)); | 259 PPP_SCROLLBAR_DEV_INTERFACE)); |
238 if (!ppp_scrollbar) { | 260 if (!ppp_scrollbar) { |
239 // Try the old version. This is ok because the old interface is a subset of | 261 // Try the old version. This is ok because the old interface is a subset of |
240 // the new one, and ValueChanged didn't change. | 262 // the new one, and ValueChanged didn't change. |
241 ppp_scrollbar = | 263 ppp_scrollbar = |
242 static_cast<const PPP_Scrollbar_Dev*>(instance()->module()-> | 264 static_cast<const PPP_Scrollbar_Dev*>(plugin_module->GetPluginInterface( |
243 GetPluginInterface(PPP_SCROLLBAR_DEV_INTERFACE_0_2)); | 265 PPP_SCROLLBAR_DEV_INTERFACE_0_2)); |
244 if (!ppp_scrollbar) | 266 if (!ppp_scrollbar) |
245 return; | 267 return; |
246 } | 268 } |
247 ScopedResourceId resource(this); | 269 ppp_scrollbar->ValueChanged(pp_instance(), pp_resource(), |
248 ppp_scrollbar->ValueChanged( | 270 scrollbar_->value()); |
249 instance()->pp_instance(), resource.id, scrollbar_->value()); | |
250 } | 271 } |
251 | 272 |
252 void PPB_Scrollbar_Impl::overlayChanged(WebScrollbar* scrollbar) { | 273 void PPB_Scrollbar_Impl::overlayChanged(WebScrollbar* scrollbar) { |
| 274 PluginModule* plugin_module = ResourceHelper::GetPluginModule(this); |
| 275 if (!plugin_module) |
| 276 return; |
| 277 |
253 const PPP_Scrollbar_Dev* ppp_scrollbar = | 278 const PPP_Scrollbar_Dev* ppp_scrollbar = |
254 static_cast<const PPP_Scrollbar_Dev*>(instance()->module()-> | 279 static_cast<const PPP_Scrollbar_Dev*>(plugin_module->GetPluginInterface( |
255 GetPluginInterface(PPP_SCROLLBAR_DEV_INTERFACE)); | 280 PPP_SCROLLBAR_DEV_INTERFACE)); |
256 if (!ppp_scrollbar) | 281 if (!ppp_scrollbar) |
257 return; | 282 return; |
258 ScopedResourceId resource(this); | 283 ppp_scrollbar->OverlayChanged(pp_instance(), pp_resource(), |
259 ppp_scrollbar->OverlayChanged( | 284 PP_FromBool(IsOverlay())); |
260 instance()->pp_instance(), resource.id, | |
261 PP_FromBool(IsOverlay())); | |
262 } | 285 } |
263 | 286 |
264 void PPB_Scrollbar_Impl::invalidateScrollbarRect( | 287 void PPB_Scrollbar_Impl::invalidateScrollbarRect( |
265 WebKit::WebScrollbar* scrollbar, | 288 WebKit::WebScrollbar* scrollbar, |
266 const WebKit::WebRect& rect) { | 289 const WebKit::WebRect& rect) { |
267 gfx::Rect gfx_rect(rect.x, | 290 gfx::Rect gfx_rect(rect.x, |
268 rect.y, | 291 rect.y, |
269 rect.width, | 292 rect.width, |
270 rect.height); | 293 rect.height); |
271 dirty_ = dirty_.Union(gfx_rect); | 294 dirty_ = dirty_.Union(gfx_rect); |
(...skipping 28 matching lines...) Expand all Loading... |
300 pp_rect.point.y = dirty_.y(); | 323 pp_rect.point.y = dirty_.y(); |
301 pp_rect.size.width = dirty_.width(); | 324 pp_rect.size.width = dirty_.width(); |
302 pp_rect.size.height = dirty_.height(); | 325 pp_rect.size.height = dirty_.height(); |
303 dirty_ = gfx::Rect(); | 326 dirty_ = gfx::Rect(); |
304 Invalidate(&pp_rect); | 327 Invalidate(&pp_rect); |
305 } | 328 } |
306 | 329 |
307 } // namespace ppapi | 330 } // namespace ppapi |
308 } // namespace webkit | 331 } // namespace webkit |
309 | 332 |
OLD | NEW |