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/enter.h" |
10 #include "ppapi/thunk/thunk.h" | 11 #include "ppapi/thunk/thunk.h" |
11 #include "skia/ext/platform_canvas.h" | 12 #include "skia/ext/platform_canvas.h" |
12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" | 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebRect.h" | 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebRect.h" |
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScrollbar.h" | 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScrollbar.h" |
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebVector.h" | 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebVector.h" |
16 #include "webkit/plugins/ppapi/common.h" | 17 #include "webkit/plugins/ppapi/common.h" |
17 #include "webkit/plugins/ppapi/event_conversion.h" | 18 #include "webkit/plugins/ppapi/event_conversion.h" |
18 #include "webkit/plugins/ppapi/plugin_module.h" | 19 #include "webkit/plugins/ppapi/plugin_module.h" |
19 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 20 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
20 #include "webkit/plugins/ppapi/ppb_image_data_impl.h" | 21 #include "webkit/plugins/ppapi/ppb_image_data_impl.h" |
| 22 #include "webkit/plugins/ppapi/ppb_scrollbar_group_impl.h" |
21 #include "webkit/glue/webkit_glue.h" | 23 #include "webkit/glue/webkit_glue.h" |
22 | 24 |
23 #if defined(OS_WIN) | 25 #if defined(OS_WIN) |
24 #include "base/win/windows_version.h" | 26 #include "base/win/windows_version.h" |
25 #endif | 27 #endif |
26 | 28 |
| 29 using ppapi::thunk::EnterResourceNoLock; |
27 using ppapi::thunk::PPB_Scrollbar_API; | 30 using ppapi::thunk::PPB_Scrollbar_API; |
| 31 using ppapi::thunk::PPB_ScrollbarGroup_API; |
28 using WebKit::WebInputEvent; | 32 using WebKit::WebInputEvent; |
29 using WebKit::WebRect; | 33 using WebKit::WebRect; |
30 using WebKit::WebScrollbar; | 34 using WebKit::WebScrollbar; |
31 | 35 |
32 namespace webkit { | 36 namespace webkit { |
33 namespace ppapi { | 37 namespace ppapi { |
34 | 38 |
35 namespace { | 39 // static |
| 40 PP_Resource PPB_Scrollbar_Impl::Create(PluginInstance* instance, |
| 41 PP_Resource scrollbar_group, |
| 42 bool vertical) { |
| 43 EnterResourceNoLock<PPB_ScrollbarGroup_API> enter_request( |
| 44 scrollbar_group, true); |
| 45 if (enter_request.failed()) |
| 46 return PP_ERROR_BADARGUMENT; |
| 47 PPB_ScrollbarGroup_Impl* scrollbar_group_impl = |
| 48 static_cast<PPB_ScrollbarGroup_Impl*>(enter_request.object()); |
36 | 49 |
37 // Version 0.3 implementation -------------------------------------------------- | 50 scoped_refptr<PPB_Scrollbar_Impl> scrollbar( |
38 // | 51 new PPB_Scrollbar_Impl(instance, scrollbar_group_impl)); |
39 // TODO(brettw) remove this when we remove support for version 0.3 interface. | 52 scrollbar->Init(vertical); |
40 // This just forwards everything to the new version of the interface except for | 53 return scrollbar->GetReference(); |
41 // the GetThickness call which has no parameters. | |
42 | |
43 PP_Resource Create(PP_Instance instance, PP_Bool vertical) { | |
44 return ::ppapi::thunk::GetPPB_Scrollbar_Thunk()->Create(instance, vertical); | |
45 } | 54 } |
46 | 55 |
47 PP_Bool IsScrollbar(PP_Resource resource) { | 56 PPB_Scrollbar_Impl::PPB_Scrollbar_Impl( |
48 return ::ppapi::thunk::GetPPB_Scrollbar_Thunk()->IsScrollbar(resource); | 57 PluginInstance* instance, |
49 } | 58 PPB_ScrollbarGroup_Impl* scrollbar_group) |
50 | 59 : PPB_Widget_Impl(instance), |
51 uint32_t GetThickness() { | 60 scrollbar_group_(scrollbar_group) { |
52 return WebScrollbar::defaultThickness(); | |
53 } | |
54 | |
55 uint32_t GetValue(PP_Resource resource) { | |
56 return ::ppapi::thunk::GetPPB_Scrollbar_Thunk()->GetValue(resource); | |
57 } | |
58 | |
59 void SetValue(PP_Resource resource, uint32_t value) { | |
60 return ::ppapi::thunk::GetPPB_Scrollbar_Thunk()->SetValue(resource, value); | |
61 } | |
62 | |
63 void SetDocumentSize(PP_Resource resource, uint32_t size) { | |
64 return ::ppapi::thunk::GetPPB_Scrollbar_Thunk()->SetDocumentSize(resource, | |
65 size); | |
66 } | |
67 | |
68 void SetTickMarks(PP_Resource resource, | |
69 const PP_Rect* tick_marks, | |
70 uint32_t count) { | |
71 return ::ppapi::thunk::GetPPB_Scrollbar_Thunk()->SetTickMarks(resource, | |
72 tick_marks, | |
73 count); | |
74 } | |
75 | |
76 void ScrollBy(PP_Resource resource, PP_ScrollBy_Dev unit, int32_t multiplier) { | |
77 return ::ppapi::thunk::GetPPB_Scrollbar_Thunk()->ScrollBy(resource, | |
78 unit, | |
79 multiplier); | |
80 } | |
81 | |
82 const PPB_Scrollbar_0_3_Dev ppb_scrollbar_0_3 = { | |
83 &Create, | |
84 &IsScrollbar, | |
85 &GetThickness, | |
86 &GetValue, | |
87 &SetValue, | |
88 &SetDocumentSize, | |
89 &SetTickMarks, | |
90 &ScrollBy | |
91 }; | |
92 | |
93 } // namespace | |
94 | |
95 PPB_Scrollbar_Impl::PPB_Scrollbar_Impl(PluginInstance* instance, bool vertical) | |
96 : PPB_Widget_Impl(instance) { | |
97 scrollbar_.reset(WebScrollbar::create( | |
98 static_cast<WebKit::WebScrollbarClient*>(this), | |
99 vertical ? WebScrollbar::Vertical : WebScrollbar::Horizontal)); | |
100 } | 61 } |
101 | 62 |
102 PPB_Scrollbar_Impl::~PPB_Scrollbar_Impl() { | 63 PPB_Scrollbar_Impl::~PPB_Scrollbar_Impl() { |
103 } | 64 } |
104 | 65 |
| 66 void PPB_Scrollbar_Impl::Init(bool vertical) { |
| 67 scrollbar_.reset(WebScrollbar::create( |
| 68 static_cast<WebKit::WebScrollbarClient*>(this), |
| 69 scrollbar_group_->GetWebScrollbarGroup(), |
| 70 vertical ? WebScrollbar::Vertical : WebScrollbar::Horizontal)); |
| 71 } |
| 72 |
105 PPB_Scrollbar_API* PPB_Scrollbar_Impl::AsPPB_Scrollbar_API() { | 73 PPB_Scrollbar_API* PPB_Scrollbar_Impl::AsPPB_Scrollbar_API() { |
106 return this; | 74 return this; |
107 } | 75 } |
108 | 76 |
109 // static | 77 uint32_t PPB_Scrollbar_Impl::GetThickness() { |
110 const PPB_Scrollbar_0_3_Dev* PPB_Scrollbar_Impl::Get0_3Interface() { | 78 return WebScrollbar::defaultThickness(); |
111 return &ppb_scrollbar_0_3; | |
112 } | 79 } |
113 | 80 |
114 uint32_t PPB_Scrollbar_Impl::GetThickness() { | 81 bool PPB_Scrollbar_Impl::IsOverlay() { |
115 return WebScrollbar::defaultThickness(); | 82 // TODO(jam): take this out once WebKit is rolled. |
| 83 #if defined(WEBSCROLLBAR_SUPPORTS_OVERLAY) |
| 84 return scrollbar_->isOverlay(); |
| 85 #else |
| 86 return false; |
| 87 #endif |
116 } | 88 } |
117 | 89 |
118 uint32_t PPB_Scrollbar_Impl::GetValue() { | 90 uint32_t PPB_Scrollbar_Impl::GetValue() { |
119 return scrollbar_->value(); | 91 return scrollbar_->value(); |
120 } | 92 } |
121 | 93 |
122 void PPB_Scrollbar_Impl::SetValue(uint32_t value) { | 94 void PPB_Scrollbar_Impl::SetValue(uint32_t value) { |
123 scrollbar_->setValue(value); | 95 scrollbar_->setValue(value); |
124 } | 96 } |
125 | 97 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 scrollbar_->setLocation(WebRect(location->point.x, | 162 scrollbar_->setLocation(WebRect(location->point.x, |
191 location->point.y, | 163 location->point.y, |
192 location->size.width, | 164 location->size.width, |
193 location->size.height)); | 165 location->size.height)); |
194 } | 166 } |
195 | 167 |
196 void PPB_Scrollbar_Impl::valueChanged(WebKit::WebScrollbar* scrollbar) { | 168 void PPB_Scrollbar_Impl::valueChanged(WebKit::WebScrollbar* scrollbar) { |
197 const PPP_Scrollbar_Dev* ppp_scrollbar = | 169 const PPP_Scrollbar_Dev* ppp_scrollbar = |
198 static_cast<const PPP_Scrollbar_Dev*>(instance()->module()-> | 170 static_cast<const PPP_Scrollbar_Dev*>(instance()->module()-> |
199 GetPluginInterface(PPP_SCROLLBAR_DEV_INTERFACE)); | 171 GetPluginInterface(PPP_SCROLLBAR_DEV_INTERFACE)); |
| 172 if (!ppp_scrollbar) { |
| 173 // Try the old version. |
| 174 ppp_scrollbar = |
| 175 static_cast<const PPP_Scrollbar_Dev*>(instance()->module()-> |
| 176 GetPluginInterface(PPP_SCROLLBAR_DEV_INTERFACE_0_2)); |
| 177 if (!ppp_scrollbar) |
| 178 return; |
| 179 } |
| 180 ScopedResourceId resource(this); |
| 181 ppp_scrollbar->ValueChanged( |
| 182 instance()->pp_instance(), resource.id, scrollbar_->value()); |
| 183 } |
| 184 |
| 185 void PPB_Scrollbar_Impl::overlayChanged(WebScrollbar* scrollbar) { |
| 186 const PPP_Scrollbar_Dev* ppp_scrollbar = |
| 187 static_cast<const PPP_Scrollbar_Dev*>(instance()->module()-> |
| 188 GetPluginInterface(PPP_SCROLLBAR_DEV_INTERFACE)); |
200 if (!ppp_scrollbar) | 189 if (!ppp_scrollbar) |
201 return; | 190 return; |
202 ScopedResourceId resource(this); | 191 ScopedResourceId resource(this); |
203 ppp_scrollbar->ValueChanged( | 192 ppp_scrollbar->OverlayChanged( |
204 instance()->pp_instance(), resource.id, scrollbar_->value()); | 193 instance()->pp_instance(), resource.id, |
| 194 PP_FromBool(IsOverlay())); |
205 } | 195 } |
206 | 196 |
207 void PPB_Scrollbar_Impl::invalidateScrollbarRect( | 197 void PPB_Scrollbar_Impl::invalidateScrollbarRect( |
208 WebKit::WebScrollbar* scrollbar, | 198 WebKit::WebScrollbar* scrollbar, |
209 const WebKit::WebRect& rect) { | 199 const WebKit::WebRect& rect) { |
210 gfx::Rect gfx_rect(rect.x, | 200 gfx::Rect gfx_rect(rect.x, |
211 rect.y, | 201 rect.y, |
212 rect.width, | 202 rect.width, |
213 rect.height); | 203 rect.height); |
214 dirty_ = dirty_.Union(gfx_rect); | 204 dirty_ = dirty_.Union(gfx_rect); |
(...skipping 24 matching lines...) Expand all Loading... |
239 pp_rect.point.y = dirty_.y(); | 229 pp_rect.point.y = dirty_.y(); |
240 pp_rect.size.width = dirty_.width(); | 230 pp_rect.size.width = dirty_.width(); |
241 pp_rect.size.height = dirty_.height(); | 231 pp_rect.size.height = dirty_.height(); |
242 dirty_ = gfx::Rect(); | 232 dirty_ = gfx::Rect(); |
243 Invalidate(&pp_rect); | 233 Invalidate(&pp_rect); |
244 } | 234 } |
245 | 235 |
246 } // namespace ppapi | 236 } // namespace ppapi |
247 } // namespace webkit | 237 } // namespace webkit |
248 | 238 |
OLD | NEW |