OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/renderer/pepper/ppb_scrollbar_impl.h" | 5 #include "content/renderer/pepper/ppb_scrollbar_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "content/renderer/pepper/common.h" | 10 #include "content/renderer/pepper/common.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 | 28 |
29 using ppapi::thunk::PPB_Scrollbar_API; | 29 using ppapi::thunk::PPB_Scrollbar_API; |
30 using blink::WebInputEvent; | 30 using blink::WebInputEvent; |
31 using blink::WebRect; | 31 using blink::WebRect; |
32 using blink::WebScrollbar; | 32 using blink::WebScrollbar; |
33 using blink::WebPluginScrollbar; | 33 using blink::WebPluginScrollbar; |
34 | 34 |
35 namespace content { | 35 namespace content { |
36 | 36 |
37 // static | 37 // static |
38 PP_Resource PPB_Scrollbar_Impl::Create(PP_Instance instance, | 38 PP_Resource PPB_Scrollbar_Impl::Create(PP_Instance instance, bool vertical) { |
39 bool vertical) { | 39 scoped_refptr<PPB_Scrollbar_Impl> scrollbar(new PPB_Scrollbar_Impl(instance)); |
40 scoped_refptr<PPB_Scrollbar_Impl> scrollbar( | |
41 new PPB_Scrollbar_Impl(instance)); | |
42 scrollbar->Init(vertical); | 40 scrollbar->Init(vertical); |
43 return scrollbar->GetReference(); | 41 return scrollbar->GetReference(); |
44 } | 42 } |
45 | 43 |
46 PPB_Scrollbar_Impl::PPB_Scrollbar_Impl(PP_Instance instance) | 44 PPB_Scrollbar_Impl::PPB_Scrollbar_Impl(PP_Instance instance) |
47 : PPB_Widget_Impl(instance), | 45 : PPB_Widget_Impl(instance), weak_ptr_factory_(this) {} |
48 weak_ptr_factory_(this) { | |
49 } | |
50 | 46 |
51 PPB_Scrollbar_Impl::~PPB_Scrollbar_Impl() { | 47 PPB_Scrollbar_Impl::~PPB_Scrollbar_Impl() {} |
52 } | |
53 | 48 |
54 void PPB_Scrollbar_Impl::Init(bool vertical) { | 49 void PPB_Scrollbar_Impl::Init(bool vertical) { |
55 PepperPluginInstanceImpl* plugin_instance = | 50 PepperPluginInstanceImpl* plugin_instance = |
56 HostGlobals::Get()->GetInstance(pp_instance()); | 51 HostGlobals::Get()->GetInstance(pp_instance()); |
57 if (!plugin_instance) | 52 if (!plugin_instance) |
58 return; | 53 return; |
59 scrollbar_.reset(WebPluginScrollbar::createForPlugin( | 54 scrollbar_.reset(WebPluginScrollbar::createForPlugin( |
60 vertical ? WebScrollbar::Vertical : WebScrollbar::Horizontal, | 55 vertical ? WebScrollbar::Vertical : WebScrollbar::Horizontal, |
61 plugin_instance->container(), | 56 plugin_instance->container(), |
62 static_cast<blink::WebPluginScrollbarClient*>(this))); | 57 static_cast<blink::WebPluginScrollbarClient*>(this))); |
63 } | 58 } |
64 | 59 |
65 PPB_Scrollbar_API* PPB_Scrollbar_Impl::AsPPB_Scrollbar_API() { | 60 PPB_Scrollbar_API* PPB_Scrollbar_Impl::AsPPB_Scrollbar_API() { return this; } |
66 return this; | |
67 } | |
68 | 61 |
69 void PPB_Scrollbar_Impl::InstanceWasDeleted() { | 62 void PPB_Scrollbar_Impl::InstanceWasDeleted() { scrollbar_.reset(); } |
70 scrollbar_.reset(); | |
71 } | |
72 | 63 |
73 uint32_t PPB_Scrollbar_Impl::GetThickness() { | 64 uint32_t PPB_Scrollbar_Impl::GetThickness() { |
74 return WebPluginScrollbar::defaultThickness(); | 65 return WebPluginScrollbar::defaultThickness(); |
75 } | 66 } |
76 | 67 |
77 bool PPB_Scrollbar_Impl::IsOverlay() { | 68 bool PPB_Scrollbar_Impl::IsOverlay() { return scrollbar_->isOverlay(); } |
78 return scrollbar_->isOverlay(); | |
79 } | |
80 | 69 |
81 uint32_t PPB_Scrollbar_Impl::GetValue() { | 70 uint32_t PPB_Scrollbar_Impl::GetValue() { return scrollbar_->value(); } |
82 return scrollbar_->value(); | |
83 } | |
84 | 71 |
85 void PPB_Scrollbar_Impl::SetValue(uint32_t value) { | 72 void PPB_Scrollbar_Impl::SetValue(uint32_t value) { |
86 if (scrollbar_) | 73 if (scrollbar_) |
87 scrollbar_->setValue(value); | 74 scrollbar_->setValue(value); |
88 } | 75 } |
89 | 76 |
90 void PPB_Scrollbar_Impl::SetDocumentSize(uint32_t size) { | 77 void PPB_Scrollbar_Impl::SetDocumentSize(uint32_t size) { |
91 if (scrollbar_) | 78 if (scrollbar_) |
92 scrollbar_->setDocumentSize(size); | 79 scrollbar_->setDocumentSize(size); |
93 } | 80 } |
94 | 81 |
95 void PPB_Scrollbar_Impl::SetTickMarks(const PP_Rect* tick_marks, | 82 void PPB_Scrollbar_Impl::SetTickMarks(const PP_Rect* tick_marks, |
96 uint32_t count) { | 83 uint32_t count) { |
97 if (!scrollbar_) | 84 if (!scrollbar_) |
98 return; | 85 return; |
99 tickmarks_.resize(count); | 86 tickmarks_.resize(count); |
100 for (uint32 i = 0; i < count; ++i) { | 87 for (uint32 i = 0; i < count; ++i) { |
101 tickmarks_[i] = WebRect(tick_marks[i].point.x, | 88 tickmarks_[i] = WebRect(tick_marks[i].point.x, |
102 tick_marks[i].point.y, | 89 tick_marks[i].point.y, |
103 tick_marks[i].size.width, | 90 tick_marks[i].size.width, |
104 tick_marks[i].size.height);; | 91 tick_marks[i].size.height); |
| 92 ; |
105 } | 93 } |
106 PP_Rect rect = location(); | 94 PP_Rect rect = location(); |
107 Invalidate(&rect); | 95 Invalidate(&rect); |
108 } | 96 } |
109 | 97 |
110 void PPB_Scrollbar_Impl::ScrollBy(PP_ScrollBy_Dev unit, int32_t multiplier) { | 98 void PPB_Scrollbar_Impl::ScrollBy(PP_ScrollBy_Dev unit, int32_t multiplier) { |
111 if (!scrollbar_) | 99 if (!scrollbar_) |
112 return; | 100 return; |
113 | 101 |
114 WebScrollbar::ScrollDirection direction = multiplier >= 0 ? | 102 WebScrollbar::ScrollDirection direction = multiplier >= 0 |
115 WebScrollbar::ScrollForward : WebScrollbar::ScrollBackward; | 103 ? WebScrollbar::ScrollForward |
| 104 : WebScrollbar::ScrollBackward; |
116 float fmultiplier = 1.0; | 105 float fmultiplier = 1.0; |
117 | 106 |
118 WebScrollbar::ScrollGranularity granularity; | 107 WebScrollbar::ScrollGranularity granularity; |
119 if (unit == PP_SCROLLBY_LINE) { | 108 if (unit == PP_SCROLLBY_LINE) { |
120 granularity = WebScrollbar::ScrollByLine; | 109 granularity = WebScrollbar::ScrollByLine; |
121 } else if (unit == PP_SCROLLBY_PAGE) { | 110 } else if (unit == PP_SCROLLBY_PAGE) { |
122 granularity = WebScrollbar::ScrollByPage; | 111 granularity = WebScrollbar::ScrollByPage; |
123 } else if (unit == PP_SCROLLBY_DOCUMENT) { | 112 } else if (unit == PP_SCROLLBY_DOCUMENT) { |
124 granularity = WebScrollbar::ScrollByDocument; | 113 granularity = WebScrollbar::ScrollByDocument; |
125 } else { | 114 } else { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 location->size.height)); | 157 location->size.height)); |
169 } | 158 } |
170 | 159 |
171 void PPB_Scrollbar_Impl::valueChanged(blink::WebPluginScrollbar* scrollbar) { | 160 void PPB_Scrollbar_Impl::valueChanged(blink::WebPluginScrollbar* scrollbar) { |
172 PluginModule* plugin_module = | 161 PluginModule* plugin_module = |
173 HostGlobals::Get()->GetInstance(pp_instance())->module(); | 162 HostGlobals::Get()->GetInstance(pp_instance())->module(); |
174 if (!plugin_module) | 163 if (!plugin_module) |
175 return; | 164 return; |
176 | 165 |
177 const PPP_Scrollbar_Dev* ppp_scrollbar = | 166 const PPP_Scrollbar_Dev* ppp_scrollbar = |
178 static_cast<const PPP_Scrollbar_Dev*>(plugin_module->GetPluginInterface( | 167 static_cast<const PPP_Scrollbar_Dev*>( |
179 PPP_SCROLLBAR_DEV_INTERFACE)); | 168 plugin_module->GetPluginInterface(PPP_SCROLLBAR_DEV_INTERFACE)); |
180 if (!ppp_scrollbar) { | 169 if (!ppp_scrollbar) { |
181 // Try the old version. This is ok because the old interface is a subset of | 170 // Try the old version. This is ok because the old interface is a subset of |
182 // the new one, and ValueChanged didn't change. | 171 // the new one, and ValueChanged didn't change. |
183 ppp_scrollbar = | 172 ppp_scrollbar = static_cast<const PPP_Scrollbar_Dev*>( |
184 static_cast<const PPP_Scrollbar_Dev*>(plugin_module->GetPluginInterface( | 173 plugin_module->GetPluginInterface(PPP_SCROLLBAR_DEV_INTERFACE_0_2)); |
185 PPP_SCROLLBAR_DEV_INTERFACE_0_2)); | |
186 if (!ppp_scrollbar) | 174 if (!ppp_scrollbar) |
187 return; | 175 return; |
188 } | 176 } |
189 ppp_scrollbar->ValueChanged(pp_instance(), pp_resource(), | 177 ppp_scrollbar->ValueChanged( |
190 scrollbar_->value()); | 178 pp_instance(), pp_resource(), scrollbar_->value()); |
191 } | 179 } |
192 | 180 |
193 void PPB_Scrollbar_Impl::overlayChanged(WebPluginScrollbar* scrollbar) { | 181 void PPB_Scrollbar_Impl::overlayChanged(WebPluginScrollbar* scrollbar) { |
194 PluginModule* plugin_module = | 182 PluginModule* plugin_module = |
195 HostGlobals::Get()->GetInstance(pp_instance())->module(); | 183 HostGlobals::Get()->GetInstance(pp_instance())->module(); |
196 if (!plugin_module) | 184 if (!plugin_module) |
197 return; | 185 return; |
198 | 186 |
199 const PPP_Scrollbar_Dev* ppp_scrollbar = | 187 const PPP_Scrollbar_Dev* ppp_scrollbar = |
200 static_cast<const PPP_Scrollbar_Dev*>(plugin_module->GetPluginInterface( | 188 static_cast<const PPP_Scrollbar_Dev*>( |
201 PPP_SCROLLBAR_DEV_INTERFACE)); | 189 plugin_module->GetPluginInterface(PPP_SCROLLBAR_DEV_INTERFACE)); |
202 if (!ppp_scrollbar) | 190 if (!ppp_scrollbar) |
203 return; | 191 return; |
204 ppp_scrollbar->OverlayChanged(pp_instance(), pp_resource(), | 192 ppp_scrollbar->OverlayChanged( |
205 PP_FromBool(IsOverlay())); | 193 pp_instance(), pp_resource(), PP_FromBool(IsOverlay())); |
206 } | 194 } |
207 | 195 |
208 void PPB_Scrollbar_Impl::invalidateScrollbarRect( | 196 void PPB_Scrollbar_Impl::invalidateScrollbarRect( |
209 blink::WebPluginScrollbar* scrollbar, | 197 blink::WebPluginScrollbar* scrollbar, |
210 const blink::WebRect& rect) { | 198 const blink::WebRect& rect) { |
211 gfx::Rect gfx_rect(rect.x, | 199 gfx::Rect gfx_rect(rect.x, rect.y, rect.width, rect.height); |
212 rect.y, | |
213 rect.width, | |
214 rect.height); | |
215 dirty_.Union(gfx_rect); | 200 dirty_.Union(gfx_rect); |
216 // Can't call into the client to tell them about the invalidate right away, | 201 // Can't call into the client to tell them about the invalidate right away, |
217 // since the PPB_Scrollbar_Impl code is still in the middle of updating its | 202 // since the PPB_Scrollbar_Impl code is still in the middle of updating its |
218 // internal state. | 203 // internal state. |
219 // Note: we use a WeakPtrFactory here so that a lingering callback can not | 204 // Note: we use a WeakPtrFactory here so that a lingering callback can not |
220 // modify the lifetime of this object. Otherwise, blink::WebPluginScrollbar | 205 // modify the lifetime of this object. Otherwise, blink::WebPluginScrollbar |
221 // could outlive blink::WebPluginContainer, which is against its contract. | 206 // could outlive blink::WebPluginContainer, which is against its contract. |
222 base::MessageLoop::current()->PostTask( | 207 base::MessageLoop::current()->PostTask( |
223 FROM_HERE, | 208 FROM_HERE, |
224 base::Bind(&PPB_Scrollbar_Impl::NotifyInvalidate, | 209 base::Bind(&PPB_Scrollbar_Impl::NotifyInvalidate, |
(...skipping 17 matching lines...) Expand all Loading... |
242 PP_Rect pp_rect; | 227 PP_Rect pp_rect; |
243 pp_rect.point.x = dirty_.x(); | 228 pp_rect.point.x = dirty_.x(); |
244 pp_rect.point.y = dirty_.y(); | 229 pp_rect.point.y = dirty_.y(); |
245 pp_rect.size.width = dirty_.width(); | 230 pp_rect.size.width = dirty_.width(); |
246 pp_rect.size.height = dirty_.height(); | 231 pp_rect.size.height = dirty_.height(); |
247 dirty_ = gfx::Rect(); | 232 dirty_ = gfx::Rect(); |
248 Invalidate(&pp_rect); | 233 Invalidate(&pp_rect); |
249 } | 234 } |
250 | 235 |
251 } // namespace content | 236 } // namespace content |
OLD | NEW |