| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/glue/plugins/pepper_scrollbar.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 "skia/ext/platform_canvas.h" | 10 #include "skia/ext/platform_canvas.h" |
| 11 #include "third_party/WebKit/WebKit/chromium/public/WebInputEvent.h" | 11 #include "third_party/WebKit/WebKit/chromium/public/WebInputEvent.h" |
| 12 #include "third_party/WebKit/WebKit/chromium/public/WebRect.h" | 12 #include "third_party/WebKit/WebKit/chromium/public/WebRect.h" |
| 13 #include "third_party/WebKit/WebKit/chromium/public/WebScrollbar.h" | 13 #include "third_party/WebKit/WebKit/chromium/public/WebScrollbar.h" |
| 14 #include "third_party/WebKit/WebKit/chromium/public/WebVector.h" | 14 #include "third_party/WebKit/WebKit/chromium/public/WebVector.h" |
| 15 #include "webkit/glue/plugins/pepper_common.h" | 15 #include "webkit/plugins/ppapi/common.h" |
| 16 #include "webkit/glue/plugins/pepper_event_conversion.h" | 16 #include "webkit/plugins/ppapi/event_conversion.h" |
| 17 #include "webkit/glue/plugins/pepper_image_data.h" | 17 #include "webkit/plugins/ppapi/plugin_instance.h" |
| 18 #include "webkit/glue/plugins/pepper_plugin_instance.h" | 18 #include "webkit/plugins/ppapi/plugin_module.h" |
| 19 #include "webkit/glue/plugins/pepper_plugin_module.h" | 19 #include "webkit/plugins/ppapi/ppb_image_data_impl.h" |
| 20 #include "webkit/glue/webkit_glue.h" | 20 #include "webkit/glue/webkit_glue.h" |
| 21 | 21 |
| 22 #if defined(OS_WIN) | 22 #if defined(OS_WIN) |
| 23 #include "base/win/windows_version.h" | 23 #include "base/win/windows_version.h" |
| 24 #endif | 24 #endif |
| 25 | 25 |
| 26 using WebKit::WebInputEvent; | 26 using WebKit::WebInputEvent; |
| 27 using WebKit::WebRect; | 27 using WebKit::WebRect; |
| 28 using WebKit::WebScrollbar; | 28 using WebKit::WebScrollbar; |
| 29 | 29 |
| 30 namespace pepper { | 30 namespace webkit { |
| 31 namespace plugins { |
| 32 namespace ppapi { |
| 31 | 33 |
| 32 namespace { | 34 namespace { |
| 33 | 35 |
| 34 PP_Resource Create(PP_Instance instance_id, PP_Bool vertical) { | 36 PP_Resource Create(PP_Instance instance_id, PP_Bool vertical) { |
| 35 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); | 37 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); |
| 36 if (!instance) | 38 if (!instance) |
| 37 return 0; | 39 return 0; |
| 38 | 40 |
| 39 scoped_refptr<Scrollbar> scrollbar(new Scrollbar(instance, | 41 scoped_refptr<PPB_Scrollbar_Impl> scrollbar( |
| 40 PPBoolToBool(vertical))); | 42 new PPB_Scrollbar_Impl(instance, PPBoolToBool(vertical))); |
| 41 return scrollbar->GetReference(); | 43 return scrollbar->GetReference(); |
| 42 } | 44 } |
| 43 | 45 |
| 44 PP_Bool IsScrollbar(PP_Resource resource) { | 46 PP_Bool IsScrollbar(PP_Resource resource) { |
| 45 return BoolToPPBool(!!Resource::GetAs<Scrollbar>(resource)); | 47 return BoolToPPBool(!!Resource::GetAs<PPB_Scrollbar_Impl>(resource)); |
| 46 } | 48 } |
| 47 | 49 |
| 48 uint32_t GetThickness() { | 50 uint32_t GetThickness() { |
| 49 return WebScrollbar::defaultThickness(); | 51 return WebScrollbar::defaultThickness(); |
| 50 } | 52 } |
| 51 | 53 |
| 52 uint32_t GetValue(PP_Resource resource) { | 54 uint32_t GetValue(PP_Resource resource) { |
| 53 scoped_refptr<Scrollbar> scrollbar(Resource::GetAs<Scrollbar>(resource)); | 55 scoped_refptr<PPB_Scrollbar_Impl> scrollbar( |
| 56 Resource::GetAs<PPB_Scrollbar_Impl>(resource)); |
| 54 if (!scrollbar) | 57 if (!scrollbar) |
| 55 return 0; | 58 return 0; |
| 56 return scrollbar->GetValue(); | 59 return scrollbar->GetValue(); |
| 57 } | 60 } |
| 58 | 61 |
| 59 void SetValue(PP_Resource resource, uint32_t value) { | 62 void SetValue(PP_Resource resource, uint32_t value) { |
| 60 scoped_refptr<Scrollbar> scrollbar(Resource::GetAs<Scrollbar>(resource)); | 63 scoped_refptr<PPB_Scrollbar_Impl> scrollbar( |
| 64 Resource::GetAs<PPB_Scrollbar_Impl>(resource)); |
| 61 if (scrollbar) | 65 if (scrollbar) |
| 62 scrollbar->SetValue(value); | 66 scrollbar->SetValue(value); |
| 63 } | 67 } |
| 64 | 68 |
| 65 void SetDocumentSize(PP_Resource resource, uint32_t size) { | 69 void SetDocumentSize(PP_Resource resource, uint32_t size) { |
| 66 scoped_refptr<Scrollbar> scrollbar(Resource::GetAs<Scrollbar>(resource)); | 70 scoped_refptr<PPB_Scrollbar_Impl> scrollbar( |
| 71 Resource::GetAs<PPB_Scrollbar_Impl>(resource)); |
| 67 if (scrollbar) | 72 if (scrollbar) |
| 68 scrollbar->SetDocumentSize(size); | 73 scrollbar->SetDocumentSize(size); |
| 69 } | 74 } |
| 70 | 75 |
| 71 void SetTickMarks(PP_Resource resource, | 76 void SetTickMarks(PP_Resource resource, |
| 72 const PP_Rect* tick_marks, | 77 const PP_Rect* tick_marks, |
| 73 uint32_t count) { | 78 uint32_t count) { |
| 74 scoped_refptr<Scrollbar> scrollbar(Resource::GetAs<Scrollbar>(resource)); | 79 scoped_refptr<PPB_Scrollbar_Impl> scrollbar( |
| 80 Resource::GetAs<PPB_Scrollbar_Impl>(resource)); |
| 75 if (scrollbar) | 81 if (scrollbar) |
| 76 scrollbar->SetTickMarks(tick_marks, count); | 82 scrollbar->SetTickMarks(tick_marks, count); |
| 77 } | 83 } |
| 78 | 84 |
| 79 void ScrollBy(PP_Resource resource, PP_ScrollBy_Dev unit, int32_t multiplier) { | 85 void ScrollBy(PP_Resource resource, PP_ScrollBy_Dev unit, int32_t multiplier) { |
| 80 scoped_refptr<Scrollbar> scrollbar(Resource::GetAs<Scrollbar>(resource)); | 86 scoped_refptr<PPB_Scrollbar_Impl> scrollbar( |
| 87 Resource::GetAs<PPB_Scrollbar_Impl>(resource)); |
| 81 if (scrollbar) | 88 if (scrollbar) |
| 82 scrollbar->ScrollBy(unit, multiplier); | 89 scrollbar->ScrollBy(unit, multiplier); |
| 83 } | 90 } |
| 84 | 91 |
| 85 const PPB_Scrollbar_Dev ppb_scrollbar = { | 92 const PPB_Scrollbar_Dev ppb_scrollbar = { |
| 86 &Create, | 93 &Create, |
| 87 &IsScrollbar, | 94 &IsScrollbar, |
| 88 &GetThickness, | 95 &GetThickness, |
| 89 &GetValue, | 96 &GetValue, |
| 90 &SetValue, | 97 &SetValue, |
| 91 &SetDocumentSize, | 98 &SetDocumentSize, |
| 92 &SetTickMarks, | 99 &SetTickMarks, |
| 93 &ScrollBy | 100 &ScrollBy |
| 94 }; | 101 }; |
| 95 | 102 |
| 96 } // namespace | 103 } // namespace |
| 97 | 104 |
| 98 Scrollbar::Scrollbar(PluginInstance* instance, bool vertical) | 105 PPB_Scrollbar_Impl::PPB_Scrollbar_Impl(PluginInstance* instance, bool vertical) |
| 99 : Widget(instance) { | 106 : PPB_Widget_Impl(instance) { |
| 100 scrollbar_.reset(WebScrollbar::create( | 107 scrollbar_.reset(WebScrollbar::create( |
| 101 static_cast<WebKit::WebScrollbarClient*>(this), | 108 static_cast<WebKit::WebScrollbarClient*>(this), |
| 102 vertical ? WebScrollbar::Vertical : WebScrollbar::Horizontal)); | 109 vertical ? WebScrollbar::Vertical : WebScrollbar::Horizontal)); |
| 103 } | 110 } |
| 104 | 111 |
| 105 Scrollbar::~Scrollbar() { | 112 PPB_Scrollbar_Impl::~PPB_Scrollbar_Impl() { |
| 106 } | 113 } |
| 107 | 114 |
| 108 // static | 115 // static |
| 109 const PPB_Scrollbar_Dev* Scrollbar::GetInterface() { | 116 const PPB_Scrollbar_Dev* PPB_Scrollbar_Impl::GetInterface() { |
| 110 return &ppb_scrollbar; | 117 return &ppb_scrollbar; |
| 111 } | 118 } |
| 112 | 119 |
| 113 Scrollbar* Scrollbar::AsScrollbar() { | 120 PPB_Scrollbar_Impl* PPB_Scrollbar_Impl::AsScrollbar() { |
| 114 return this; | 121 return this; |
| 115 } | 122 } |
| 116 | 123 |
| 117 uint32_t Scrollbar::GetValue() { | 124 uint32_t PPB_Scrollbar_Impl::GetValue() { |
| 118 return scrollbar_->value(); | 125 return scrollbar_->value(); |
| 119 } | 126 } |
| 120 | 127 |
| 121 void Scrollbar::SetValue(uint32_t value) { | 128 void PPB_Scrollbar_Impl::SetValue(uint32_t value) { |
| 122 scrollbar_->setValue(value); | 129 scrollbar_->setValue(value); |
| 123 } | 130 } |
| 124 | 131 |
| 125 void Scrollbar::SetDocumentSize(uint32_t size) { | 132 void PPB_Scrollbar_Impl::SetDocumentSize(uint32_t size) { |
| 126 scrollbar_->setDocumentSize(size); | 133 scrollbar_->setDocumentSize(size); |
| 127 } | 134 } |
| 128 | 135 |
| 129 void Scrollbar::SetTickMarks(const PP_Rect* tick_marks, uint32_t count) { | 136 void PPB_Scrollbar_Impl::SetTickMarks(const PP_Rect* tick_marks, |
| 137 uint32_t count) { |
| 130 tickmarks_.resize(count); | 138 tickmarks_.resize(count); |
| 131 for (uint32 i = 0; i < count; ++i) { | 139 for (uint32 i = 0; i < count; ++i) { |
| 132 tickmarks_[i] = WebRect(tick_marks[i].point.x, | 140 tickmarks_[i] = WebRect(tick_marks[i].point.x, |
| 133 tick_marks[i].point.y, | 141 tick_marks[i].point.y, |
| 134 tick_marks[i].size.width, | 142 tick_marks[i].size.width, |
| 135 tick_marks[i].size.height);; | 143 tick_marks[i].size.height);; |
| 136 } | 144 } |
| 137 PP_Rect rect = location(); | 145 PP_Rect rect = location(); |
| 138 Invalidate(&rect); | 146 Invalidate(&rect); |
| 139 } | 147 } |
| 140 | 148 |
| 141 void Scrollbar::ScrollBy(PP_ScrollBy_Dev unit, int32_t multiplier) { | 149 void PPB_Scrollbar_Impl::ScrollBy(PP_ScrollBy_Dev unit, int32_t multiplier) { |
| 142 WebScrollbar::ScrollDirection direction = multiplier >= 0 ? | 150 WebScrollbar::ScrollDirection direction = multiplier >= 0 ? |
| 143 WebScrollbar::ScrollForward : WebScrollbar::ScrollBackward; | 151 WebScrollbar::ScrollForward : WebScrollbar::ScrollBackward; |
| 144 float fmultiplier = 1.0; | 152 float fmultiplier = 1.0; |
| 145 | 153 |
| 146 WebScrollbar::ScrollGranularity granularity; | 154 WebScrollbar::ScrollGranularity granularity; |
| 147 if (unit == PP_SCROLLBY_LINE) { | 155 if (unit == PP_SCROLLBY_LINE) { |
| 148 granularity = WebScrollbar::ScrollByLine; | 156 granularity = WebScrollbar::ScrollByLine; |
| 149 } else if (unit == PP_SCROLLBY_PAGE) { | 157 } else if (unit == PP_SCROLLBY_PAGE) { |
| 150 granularity = WebScrollbar::ScrollByPage; | 158 granularity = WebScrollbar::ScrollByPage; |
| 151 } else if (unit == PP_SCROLLBY_DOCUMENT) { | 159 } else if (unit == PP_SCROLLBY_DOCUMENT) { |
| 152 granularity = WebScrollbar::ScrollByDocument; | 160 granularity = WebScrollbar::ScrollByDocument; |
| 153 } else { | 161 } else { |
| 154 granularity = WebScrollbar::ScrollByPixel; | 162 granularity = WebScrollbar::ScrollByPixel; |
| 155 fmultiplier = static_cast<float>(multiplier); | 163 fmultiplier = static_cast<float>(multiplier); |
| 156 if (fmultiplier < 0) | 164 if (fmultiplier < 0) |
| 157 fmultiplier *= -1; | 165 fmultiplier *= -1; |
| 158 } | 166 } |
| 159 scrollbar_->scroll(direction, granularity, fmultiplier); | 167 scrollbar_->scroll(direction, granularity, fmultiplier); |
| 160 } | 168 } |
| 161 | 169 |
| 162 bool Scrollbar::Paint(const PP_Rect* rect, ImageData* image) { | 170 bool PPB_Scrollbar_Impl::Paint(const PP_Rect* rect, PPB_ImageData_Impl* image) { |
| 163 gfx::Rect gfx_rect(rect->point.x, | 171 gfx::Rect gfx_rect(rect->point.x, |
| 164 rect->point.y, | 172 rect->point.y, |
| 165 rect->size.width, | 173 rect->size.width, |
| 166 rect->size.height); | 174 rect->size.height); |
| 167 skia::PlatformCanvas* canvas = image->mapped_canvas(); | 175 skia::PlatformCanvas* canvas = image->mapped_canvas(); |
| 168 if (!canvas) | 176 if (!canvas) |
| 169 return false; | 177 return false; |
| 170 scrollbar_->paint(webkit_glue::ToWebCanvas(canvas), gfx_rect); | 178 scrollbar_->paint(webkit_glue::ToWebCanvas(canvas), gfx_rect); |
| 171 | 179 |
| 172 #if defined(OS_WIN) | 180 #if defined(OS_WIN) |
| 173 if (base::win::GetVersion() == base::win::VERSION_XP) { | 181 if (base::win::GetVersion() == base::win::VERSION_XP) { |
| 174 canvas->getTopPlatformDevice().makeOpaque( | 182 canvas->getTopPlatformDevice().makeOpaque( |
| 175 gfx_rect.x(), gfx_rect.y(), gfx_rect.width(), gfx_rect.height()); | 183 gfx_rect.x(), gfx_rect.y(), gfx_rect.width(), gfx_rect.height()); |
| 176 } | 184 } |
| 177 #endif | 185 #endif |
| 178 | 186 |
| 179 return true; | 187 return true; |
| 180 } | 188 } |
| 181 | 189 |
| 182 bool Scrollbar::HandleEvent(const PP_InputEvent* event) { | 190 bool PPB_Scrollbar_Impl::HandleEvent(const PP_InputEvent* event) { |
| 183 scoped_ptr<WebInputEvent> web_input_event(CreateWebInputEvent(*event)); | 191 scoped_ptr<WebInputEvent> web_input_event(CreateWebInputEvent(*event)); |
| 184 if (!web_input_event.get()) | 192 if (!web_input_event.get()) |
| 185 return false; | 193 return false; |
| 186 | 194 |
| 187 return scrollbar_->handleInputEvent(*web_input_event.get()); | 195 return scrollbar_->handleInputEvent(*web_input_event.get()); |
| 188 } | 196 } |
| 189 | 197 |
| 190 void Scrollbar::SetLocationInternal(const PP_Rect* location) { | 198 void PPB_Scrollbar_Impl::SetLocationInternal(const PP_Rect* location) { |
| 191 scrollbar_->setLocation(WebRect(location->point.x, | 199 scrollbar_->setLocation(WebRect(location->point.x, |
| 192 location->point.y, | 200 location->point.y, |
| 193 location->size.width, | 201 location->size.width, |
| 194 location->size.height)); | 202 location->size.height)); |
| 195 } | 203 } |
| 196 | 204 |
| 197 void Scrollbar::valueChanged(WebKit::WebScrollbar* scrollbar) { | 205 void PPB_Scrollbar_Impl::valueChanged(WebKit::WebScrollbar* scrollbar) { |
| 198 const PPP_Scrollbar_Dev* ppp_scrollbar = | 206 const PPP_Scrollbar_Dev* ppp_scrollbar = |
| 199 static_cast<const PPP_Scrollbar_Dev*>( | 207 static_cast<const PPP_Scrollbar_Dev*>( |
| 200 module()->GetPluginInterface(PPP_SCROLLBAR_DEV_INTERFACE)); | 208 module()->GetPluginInterface(PPP_SCROLLBAR_DEV_INTERFACE)); |
| 201 if (!ppp_scrollbar) | 209 if (!ppp_scrollbar) |
| 202 return; | 210 return; |
| 203 ScopedResourceId resource(this); | 211 ScopedResourceId resource(this); |
| 204 ppp_scrollbar->ValueChanged( | 212 ppp_scrollbar->ValueChanged( |
| 205 instance()->pp_instance(), resource.id, scrollbar_->value()); | 213 instance()->pp_instance(), resource.id, scrollbar_->value()); |
| 206 } | 214 } |
| 207 | 215 |
| 208 void Scrollbar::invalidateScrollbarRect(WebKit::WebScrollbar* scrollbar, | 216 void PPB_Scrollbar_Impl::invalidateScrollbarRect( |
| 209 const WebKit::WebRect& rect) { | 217 WebKit::WebScrollbar* scrollbar, |
| 218 const WebKit::WebRect& rect) { |
| 210 gfx::Rect gfx_rect(rect.x, | 219 gfx::Rect gfx_rect(rect.x, |
| 211 rect.y, | 220 rect.y, |
| 212 rect.width, | 221 rect.width, |
| 213 rect.height); | 222 rect.height); |
| 214 dirty_ = dirty_.Union(gfx_rect); | 223 dirty_ = dirty_.Union(gfx_rect); |
| 215 // Can't call into the client to tell them about the invalidate right away, | 224 // Can't call into the client to tell them about the invalidate right away, |
| 216 // since the Scrollbar code is still in the middle of updating its internal | 225 // since the PPB_Scrollbar_Impl code is still in the middle of updating its |
| 217 // state. | 226 // internal state. |
| 218 MessageLoop::current()->PostTask( | 227 MessageLoop::current()->PostTask( |
| 219 FROM_HERE, | 228 FROM_HERE, |
| 220 NewRunnableMethod(this, &Scrollbar::NotifyInvalidate)); | 229 NewRunnableMethod(this, &PPB_Scrollbar_Impl::NotifyInvalidate)); |
| 221 } | 230 } |
| 222 | 231 |
| 223 void Scrollbar::getTickmarks( | 232 void PPB_Scrollbar_Impl::getTickmarks( |
| 224 WebKit::WebScrollbar* scrollbar, | 233 WebKit::WebScrollbar* scrollbar, |
| 225 WebKit::WebVector<WebKit::WebRect>* tick_marks) const { | 234 WebKit::WebVector<WebKit::WebRect>* tick_marks) const { |
| 226 if (tickmarks_.empty()) { | 235 if (tickmarks_.empty()) { |
| 227 WebRect* rects = NULL; | 236 WebRect* rects = NULL; |
| 228 tick_marks->assign(rects, 0); | 237 tick_marks->assign(rects, 0); |
| 229 } else { | 238 } else { |
| 230 tick_marks->assign(&tickmarks_[0], tickmarks_.size()); | 239 tick_marks->assign(&tickmarks_[0], tickmarks_.size()); |
| 231 } | 240 } |
| 232 } | 241 } |
| 233 | 242 |
| 234 void Scrollbar::NotifyInvalidate() { | 243 void PPB_Scrollbar_Impl::NotifyInvalidate() { |
| 235 if (dirty_.IsEmpty()) | 244 if (dirty_.IsEmpty()) |
| 236 return; | 245 return; |
| 237 PP_Rect pp_rect; | 246 PP_Rect pp_rect; |
| 238 pp_rect.point.x = dirty_.x(); | 247 pp_rect.point.x = dirty_.x(); |
| 239 pp_rect.point.y = dirty_.y(); | 248 pp_rect.point.y = dirty_.y(); |
| 240 pp_rect.size.width = dirty_.width(); | 249 pp_rect.size.width = dirty_.width(); |
| 241 pp_rect.size.height = dirty_.height(); | 250 pp_rect.size.height = dirty_.height(); |
| 242 dirty_ = gfx::Rect(); | 251 dirty_ = gfx::Rect(); |
| 243 Invalidate(&pp_rect); | 252 Invalidate(&pp_rect); |
| 244 } | 253 } |
| 245 | 254 |
| 246 } // namespace pepper | 255 } // namespace ppapi |
| 256 } // namespace plugins |
| 257 } // namespace webkit |
| 258 |
| OLD | NEW |