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(PP_Resource scrollbar_group, |
| 41 bool vertical) { |
| 42 EnterResourceNoLock<PPB_ScrollbarGroup_API> enter_request( |
| 43 scrollbar_group, true); |
| 44 if (enter_request.failed()) |
| 45 return PP_ERROR_BADARGUMENT; |
| 46 PPB_ScrollbarGroup_Impl* scrollbar_group_impl = |
| 47 static_cast<PPB_ScrollbarGroup_Impl*>(enter_request.object()); |
36 | 48 |
37 // Version 0.3 implementation -------------------------------------------------- | 49 scoped_refptr<PPB_Scrollbar_Impl> scrollbar( |
38 // | 50 new PPB_Scrollbar_Impl(scrollbar_group_impl)); |
39 // TODO(brettw) remove this when we remove support for version 0.3 interface. | 51 scrollbar->Init(vertical); |
40 // This just forwards everything to the new version of the interface except for | 52 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 } | 53 } |
46 | 54 |
47 PP_Bool IsScrollbar(PP_Resource resource) { | 55 PPB_Scrollbar_Impl::PPB_Scrollbar_Impl(PPB_ScrollbarGroup_Impl* scrollbar_group) |
48 return ::ppapi::thunk::GetPPB_Scrollbar_Thunk()->IsScrollbar(resource); | 56 : PPB_Widget_Impl(scrollbar_group->instance()), |
49 } | 57 scrollbar_group_(scrollbar_group) { |
50 | |
51 uint32_t GetThickness() { | |
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 } | 58 } |
101 | 59 |
102 PPB_Scrollbar_Impl::~PPB_Scrollbar_Impl() { | 60 PPB_Scrollbar_Impl::~PPB_Scrollbar_Impl() { |
103 } | 61 } |
104 | 62 |
| 63 void PPB_Scrollbar_Impl::Init(bool vertical) { |
| 64 scrollbar_.reset(WebScrollbar::create( |
| 65 static_cast<WebKit::WebScrollbarClient*>(this), |
| 66 scrollbar_group_->GetWebScrollbarGroup(), |
| 67 vertical ? WebScrollbar::Vertical : WebScrollbar::Horizontal)); |
| 68 } |
| 69 |
105 PPB_Scrollbar_API* PPB_Scrollbar_Impl::AsPPB_Scrollbar_API() { | 70 PPB_Scrollbar_API* PPB_Scrollbar_Impl::AsPPB_Scrollbar_API() { |
106 return this; | 71 return this; |
107 } | 72 } |
108 | 73 |
109 // static | 74 uint32_t PPB_Scrollbar_Impl::GetThickness() { |
110 const PPB_Scrollbar_0_3_Dev* PPB_Scrollbar_Impl::Get0_3Interface() { | 75 return WebScrollbar::defaultThickness(); |
111 return &ppb_scrollbar_0_3; | |
112 } | 76 } |
113 | 77 |
114 uint32_t PPB_Scrollbar_Impl::GetThickness() { | 78 bool PPB_Scrollbar_Impl::IsOverlay() { |
115 return WebScrollbar::defaultThickness(); | 79 // TODO(jam): take this out once WebKit is rolled. |
| 80 #if defined(WEBSCROLLBAR_SUPPORTS_OVERLAY) |
| 81 return scrollbar_->isOverlay(); |
| 82 #else |
| 83 return false; |
| 84 #endif |
116 } | 85 } |
117 | 86 |
118 uint32_t PPB_Scrollbar_Impl::GetValue() { | 87 uint32_t PPB_Scrollbar_Impl::GetValue() { |
119 return scrollbar_->value(); | 88 return scrollbar_->value(); |
120 } | 89 } |
121 | 90 |
122 void PPB_Scrollbar_Impl::SetValue(uint32_t value) { | 91 void PPB_Scrollbar_Impl::SetValue(uint32_t value) { |
123 scrollbar_->setValue(value); | 92 scrollbar_->setValue(value); |
124 } | 93 } |
125 | 94 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 scrollbar_->setLocation(WebRect(location->point.x, | 159 scrollbar_->setLocation(WebRect(location->point.x, |
191 location->point.y, | 160 location->point.y, |
192 location->size.width, | 161 location->size.width, |
193 location->size.height)); | 162 location->size.height)); |
194 } | 163 } |
195 | 164 |
196 void PPB_Scrollbar_Impl::valueChanged(WebKit::WebScrollbar* scrollbar) { | 165 void PPB_Scrollbar_Impl::valueChanged(WebKit::WebScrollbar* scrollbar) { |
197 const PPP_Scrollbar_Dev* ppp_scrollbar = | 166 const PPP_Scrollbar_Dev* ppp_scrollbar = |
198 static_cast<const PPP_Scrollbar_Dev*>(instance()->module()-> | 167 static_cast<const PPP_Scrollbar_Dev*>(instance()->module()-> |
199 GetPluginInterface(PPP_SCROLLBAR_DEV_INTERFACE)); | 168 GetPluginInterface(PPP_SCROLLBAR_DEV_INTERFACE)); |
| 169 if (!ppp_scrollbar) { |
| 170 // Try the old version. |
| 171 ppp_scrollbar = |
| 172 static_cast<const PPP_Scrollbar_Dev*>(instance()->module()-> |
| 173 GetPluginInterface(PPP_SCROLLBAR_DEV_INTERFACE_0_2)); |
| 174 if (!ppp_scrollbar) |
| 175 return; |
| 176 } |
| 177 ScopedResourceId resource(this); |
| 178 ppp_scrollbar->ValueChanged( |
| 179 instance()->pp_instance(), resource.id, scrollbar_->value()); |
| 180 } |
| 181 |
| 182 void PPB_Scrollbar_Impl::overlayChanged(WebScrollbar* scrollbar) { |
| 183 const PPP_Scrollbar_Dev* ppp_scrollbar = |
| 184 static_cast<const PPP_Scrollbar_Dev*>(instance()->module()-> |
| 185 GetPluginInterface(PPP_SCROLLBAR_DEV_INTERFACE)); |
200 if (!ppp_scrollbar) | 186 if (!ppp_scrollbar) |
201 return; | 187 return; |
202 ScopedResourceId resource(this); | 188 ScopedResourceId resource(this); |
203 ppp_scrollbar->ValueChanged( | 189 ppp_scrollbar->OverlayChanged( |
204 instance()->pp_instance(), resource.id, scrollbar_->value()); | 190 instance()->pp_instance(), resource.id, |
| 191 PP_FromBool(IsOverlay())); |
205 } | 192 } |
206 | 193 |
207 void PPB_Scrollbar_Impl::invalidateScrollbarRect( | 194 void PPB_Scrollbar_Impl::invalidateScrollbarRect( |
208 WebKit::WebScrollbar* scrollbar, | 195 WebKit::WebScrollbar* scrollbar, |
209 const WebKit::WebRect& rect) { | 196 const WebKit::WebRect& rect) { |
210 gfx::Rect gfx_rect(rect.x, | 197 gfx::Rect gfx_rect(rect.x, |
211 rect.y, | 198 rect.y, |
212 rect.width, | 199 rect.width, |
213 rect.height); | 200 rect.height); |
214 dirty_ = dirty_.Union(gfx_rect); | 201 dirty_ = dirty_.Union(gfx_rect); |
(...skipping 24 matching lines...) Expand all Loading... |
239 pp_rect.point.y = dirty_.y(); | 226 pp_rect.point.y = dirty_.y(); |
240 pp_rect.size.width = dirty_.width(); | 227 pp_rect.size.width = dirty_.width(); |
241 pp_rect.size.height = dirty_.height(); | 228 pp_rect.size.height = dirty_.height(); |
242 dirty_ = gfx::Rect(); | 229 dirty_ = gfx::Rect(); |
243 Invalidate(&pp_rect); | 230 Invalidate(&pp_rect); |
244 } | 231 } |
245 | 232 |
246 } // namespace ppapi | 233 } // namespace ppapi |
247 } // namespace webkit | 234 } // namespace webkit |
248 | 235 |
OLD | NEW |