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