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" |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 // static | 110 // static |
111 PP_Resource PPB_Scrollbar_Impl::Create(PluginInstance* instance, | 111 PP_Resource PPB_Scrollbar_Impl::Create(PluginInstance* instance, |
112 bool vertical) { | 112 bool vertical) { |
113 scoped_refptr<PPB_Scrollbar_Impl> scrollbar( | 113 scoped_refptr<PPB_Scrollbar_Impl> scrollbar( |
114 new PPB_Scrollbar_Impl(instance)); | 114 new PPB_Scrollbar_Impl(instance)); |
115 scrollbar->Init(vertical); | 115 scrollbar->Init(vertical); |
116 return scrollbar->GetReference(); | 116 return scrollbar->GetReference(); |
117 } | 117 } |
118 | 118 |
119 PPB_Scrollbar_Impl::PPB_Scrollbar_Impl(PluginInstance* instance) | 119 PPB_Scrollbar_Impl::PPB_Scrollbar_Impl(PluginInstance* instance) |
120 : PPB_Widget_Impl(instance) { | 120 : PPB_Widget_Impl(instance), |
| 121 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { |
121 } | 122 } |
122 | 123 |
123 PPB_Scrollbar_Impl::~PPB_Scrollbar_Impl() { | 124 PPB_Scrollbar_Impl::~PPB_Scrollbar_Impl() { |
124 } | 125 } |
125 | 126 |
126 void PPB_Scrollbar_Impl::Init(bool vertical) { | 127 void PPB_Scrollbar_Impl::Init(bool vertical) { |
127 #if defined(WEBSCROLLBAR_SUPPORTS_OVERLAY) | 128 #if defined(WEBSCROLLBAR_SUPPORTS_OVERLAY) |
128 scrollbar_.reset(WebScrollbar::createForPlugin( | 129 scrollbar_.reset(WebScrollbar::createForPlugin( |
129 vertical ? WebScrollbar::Vertical : WebScrollbar::Horizontal, | 130 vertical ? WebScrollbar::Vertical : WebScrollbar::Horizontal, |
130 instance()->container(), | 131 instance()->container(), |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 WebKit::WebScrollbar* scrollbar, | 276 WebKit::WebScrollbar* scrollbar, |
276 const WebKit::WebRect& rect) { | 277 const WebKit::WebRect& rect) { |
277 gfx::Rect gfx_rect(rect.x, | 278 gfx::Rect gfx_rect(rect.x, |
278 rect.y, | 279 rect.y, |
279 rect.width, | 280 rect.width, |
280 rect.height); | 281 rect.height); |
281 dirty_ = dirty_.Union(gfx_rect); | 282 dirty_ = dirty_.Union(gfx_rect); |
282 // Can't call into the client to tell them about the invalidate right away, | 283 // Can't call into the client to tell them about the invalidate right away, |
283 // since the PPB_Scrollbar_Impl code is still in the middle of updating its | 284 // since the PPB_Scrollbar_Impl code is still in the middle of updating its |
284 // internal state. | 285 // internal state. |
| 286 // Note: we use a method factory here instead of NewRunnableMethod because the |
| 287 // latter would modify the lifetime of this object. That might make |
| 288 // WebKit::WebScrollbar outlive WebKit::WebPluginContainer, which is against |
| 289 // its contract. |
285 MessageLoop::current()->PostTask( | 290 MessageLoop::current()->PostTask( |
286 FROM_HERE, | 291 FROM_HERE, |
287 NewRunnableMethod(this, &PPB_Scrollbar_Impl::NotifyInvalidate)); | 292 method_factory_.NewRunnableMethod(&PPB_Scrollbar_Impl::NotifyInvalidate)); |
288 } | 293 } |
289 | 294 |
290 void PPB_Scrollbar_Impl::getTickmarks( | 295 void PPB_Scrollbar_Impl::getTickmarks( |
291 WebKit::WebScrollbar* scrollbar, | 296 WebKit::WebScrollbar* scrollbar, |
292 WebKit::WebVector<WebKit::WebRect>* tick_marks) const { | 297 WebKit::WebVector<WebKit::WebRect>* tick_marks) const { |
293 if (tickmarks_.empty()) { | 298 if (tickmarks_.empty()) { |
294 WebRect* rects = NULL; | 299 WebRect* rects = NULL; |
295 tick_marks->assign(rects, 0); | 300 tick_marks->assign(rects, 0); |
296 } else { | 301 } else { |
297 tick_marks->assign(&tickmarks_[0], tickmarks_.size()); | 302 tick_marks->assign(&tickmarks_[0], tickmarks_.size()); |
298 } | 303 } |
299 } | 304 } |
300 | 305 |
301 void PPB_Scrollbar_Impl::NotifyInvalidate() { | 306 void PPB_Scrollbar_Impl::NotifyInvalidate() { |
302 if (dirty_.IsEmpty()) | 307 if (dirty_.IsEmpty()) |
303 return; | 308 return; |
304 PP_Rect pp_rect; | 309 PP_Rect pp_rect; |
305 pp_rect.point.x = dirty_.x(); | 310 pp_rect.point.x = dirty_.x(); |
306 pp_rect.point.y = dirty_.y(); | 311 pp_rect.point.y = dirty_.y(); |
307 pp_rect.size.width = dirty_.width(); | 312 pp_rect.size.width = dirty_.width(); |
308 pp_rect.size.height = dirty_.height(); | 313 pp_rect.size.height = dirty_.height(); |
309 dirty_ = gfx::Rect(); | 314 dirty_ = gfx::Rect(); |
310 Invalidate(&pp_rect); | 315 Invalidate(&pp_rect); |
311 } | 316 } |
312 | 317 |
313 } // namespace ppapi | 318 } // namespace ppapi |
314 } // namespace webkit | 319 } // namespace webkit |
315 | 320 |
OLD | NEW |