Chromium Code Reviews| 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/thunk.h" | 10 #include "ppapi/thunk/thunk.h" |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 41 // the GetThickness call which has no parameters. | 41 // the GetThickness call which has no parameters. |
| 42 | 42 |
| 43 PP_Resource Create(PP_Instance instance, PP_Bool vertical) { | 43 PP_Resource Create(PP_Instance instance, PP_Bool vertical) { |
| 44 return ::ppapi::thunk::GetPPB_Scrollbar_Thunk()->Create(instance, vertical); | 44 return ::ppapi::thunk::GetPPB_Scrollbar_Thunk()->Create(instance, vertical); |
| 45 } | 45 } |
| 46 | 46 |
| 47 PP_Bool IsScrollbar(PP_Resource resource) { | 47 PP_Bool IsScrollbar(PP_Resource resource) { |
| 48 return ::ppapi::thunk::GetPPB_Scrollbar_Thunk()->IsScrollbar(resource); | 48 return ::ppapi::thunk::GetPPB_Scrollbar_Thunk()->IsScrollbar(resource); |
| 49 } | 49 } |
| 50 | 50 |
| 51 uint32_t GetThickness() { | 51 uint32_t GetThickness3() { |
| 52 return WebScrollbar::defaultThickness(); | 52 return WebScrollbar::defaultThickness(); |
| 53 } | 53 } |
| 54 | 54 |
| 55 uint32_t GetThickness4(PP_Resource resource) { | |
| 56 return ::ppapi::thunk::GetPPB_Scrollbar_Thunk()->GetThickness(resource); | |
| 57 } | |
| 58 | |
| 55 uint32_t GetValue(PP_Resource resource) { | 59 uint32_t GetValue(PP_Resource resource) { |
| 56 return ::ppapi::thunk::GetPPB_Scrollbar_Thunk()->GetValue(resource); | 60 return ::ppapi::thunk::GetPPB_Scrollbar_Thunk()->GetValue(resource); |
| 57 } | 61 } |
| 58 | 62 |
| 59 void SetValue(PP_Resource resource, uint32_t value) { | 63 void SetValue(PP_Resource resource, uint32_t value) { |
| 60 return ::ppapi::thunk::GetPPB_Scrollbar_Thunk()->SetValue(resource, value); | 64 return ::ppapi::thunk::GetPPB_Scrollbar_Thunk()->SetValue(resource, value); |
| 61 } | 65 } |
| 62 | 66 |
| 63 void SetDocumentSize(PP_Resource resource, uint32_t size) { | 67 void SetDocumentSize(PP_Resource resource, uint32_t size) { |
| 64 return ::ppapi::thunk::GetPPB_Scrollbar_Thunk()->SetDocumentSize(resource, | 68 return ::ppapi::thunk::GetPPB_Scrollbar_Thunk()->SetDocumentSize(resource, |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 75 | 79 |
| 76 void ScrollBy(PP_Resource resource, PP_ScrollBy_Dev unit, int32_t multiplier) { | 80 void ScrollBy(PP_Resource resource, PP_ScrollBy_Dev unit, int32_t multiplier) { |
| 77 return ::ppapi::thunk::GetPPB_Scrollbar_Thunk()->ScrollBy(resource, | 81 return ::ppapi::thunk::GetPPB_Scrollbar_Thunk()->ScrollBy(resource, |
| 78 unit, | 82 unit, |
| 79 multiplier); | 83 multiplier); |
| 80 } | 84 } |
| 81 | 85 |
| 82 const PPB_Scrollbar_0_3_Dev ppb_scrollbar_0_3 = { | 86 const PPB_Scrollbar_0_3_Dev ppb_scrollbar_0_3 = { |
| 83 &Create, | 87 &Create, |
| 84 &IsScrollbar, | 88 &IsScrollbar, |
| 85 &GetThickness, | 89 &GetThickness3, |
| 86 &GetValue, | 90 &GetValue, |
| 87 &SetValue, | 91 &SetValue, |
| 88 &SetDocumentSize, | 92 &SetDocumentSize, |
| 89 &SetTickMarks, | 93 &SetTickMarks, |
| 90 &ScrollBy | 94 &ScrollBy |
| 91 }; | 95 }; |
| 92 | 96 |
| 97 const PPB_Scrollbar_0_4_Dev ppb_scrollbar_0_4 = { | |
| 98 &Create, | |
| 99 &IsScrollbar, | |
| 100 &GetThickness4, | |
| 101 &GetValue, | |
| 102 &SetValue, | |
| 103 &SetDocumentSize, | |
| 104 &SetTickMarks, | |
| 105 &ScrollBy | |
| 106 }; | |
| 107 | |
| 93 } // namespace | 108 } // namespace |
| 94 | 109 |
| 95 PPB_Scrollbar_Impl::PPB_Scrollbar_Impl(PluginInstance* instance, bool vertical) | 110 // static |
| 111 PP_Resource PPB_Scrollbar_Impl::Create(PluginInstance* instance, | |
| 112 bool vertical) { | |
| 113 scoped_refptr<PPB_Scrollbar_Impl> scrollbar(new PPB_Scrollbar_Impl(instance)); | |
| 114 scrollbar->Init(vertical); | |
| 115 return scrollbar->GetReference(); | |
| 116 } | |
| 117 | |
| 118 PPB_Scrollbar_Impl::PPB_Scrollbar_Impl(PluginInstance* instance) | |
| 96 : PPB_Widget_Impl(instance) { | 119 : PPB_Widget_Impl(instance) { |
| 120 } | |
| 121 | |
| 122 PPB_Scrollbar_Impl::~PPB_Scrollbar_Impl() { | |
| 123 } | |
| 124 | |
| 125 void PPB_Scrollbar_Impl::Init(bool vertical) { | |
| 97 scrollbar_.reset(WebScrollbar::create( | 126 scrollbar_.reset(WebScrollbar::create( |
| 98 static_cast<WebKit::WebScrollbarClient*>(this), | 127 static_cast<WebKit::WebScrollbarClient*>(this), |
| 99 vertical ? WebScrollbar::Vertical : WebScrollbar::Horizontal)); | 128 vertical ? WebScrollbar::Vertical : WebScrollbar::Horizontal)); |
| 100 } | 129 } |
| 101 | 130 |
| 102 PPB_Scrollbar_Impl::~PPB_Scrollbar_Impl() { | |
| 103 } | |
| 104 | |
| 105 PPB_Scrollbar_API* PPB_Scrollbar_Impl::AsPPB_Scrollbar_API() { | 131 PPB_Scrollbar_API* PPB_Scrollbar_Impl::AsPPB_Scrollbar_API() { |
| 106 return this; | 132 return this; |
| 107 } | 133 } |
| 108 | 134 |
| 109 // static | 135 // static |
| 110 const PPB_Scrollbar_0_3_Dev* PPB_Scrollbar_Impl::Get0_3Interface() { | 136 const PPB_Scrollbar_0_3_Dev* PPB_Scrollbar_Impl::Get0_3Interface() { |
| 111 return &ppb_scrollbar_0_3; | 137 return &ppb_scrollbar_0_3; |
| 112 } | 138 } |
| 113 | 139 |
| 140 // static | |
| 141 const PPB_Scrollbar_0_4_Dev* PPB_Scrollbar_Impl::Get0_4Interface() { | |
| 142 return &ppb_scrollbar_0_4; | |
| 143 } | |
| 144 | |
| 114 uint32_t PPB_Scrollbar_Impl::GetThickness() { | 145 uint32_t PPB_Scrollbar_Impl::GetThickness() { |
| 115 return WebScrollbar::defaultThickness(); | 146 return WebScrollbar::defaultThickness(); |
| 116 } | 147 } |
| 117 | 148 |
| 149 bool PPB_Scrollbar_Impl::IsOverlay() { | |
| 150 // TODO(jam): take this out once WebKit is rolled. | |
| 151 #if defined(WEBSCROLLBAR_SUPPORTS_OVERLAY) | |
| 152 return scrollbar_->isOverlay(); | |
| 153 #else | |
| 154 return false; | |
| 155 #endif | |
| 156 } | |
| 157 | |
| 118 uint32_t PPB_Scrollbar_Impl::GetValue() { | 158 uint32_t PPB_Scrollbar_Impl::GetValue() { |
| 119 return scrollbar_->value(); | 159 return scrollbar_->value(); |
| 120 } | 160 } |
| 121 | 161 |
| 122 void PPB_Scrollbar_Impl::SetValue(uint32_t value) { | 162 void PPB_Scrollbar_Impl::SetValue(uint32_t value) { |
| 123 scrollbar_->setValue(value); | 163 scrollbar_->setValue(value); |
| 124 } | 164 } |
| 125 | 165 |
| 126 void PPB_Scrollbar_Impl::SetDocumentSize(uint32_t size) { | 166 void PPB_Scrollbar_Impl::SetDocumentSize(uint32_t size) { |
| 127 scrollbar_->setDocumentSize(size); | 167 scrollbar_->setDocumentSize(size); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 190 scrollbar_->setLocation(WebRect(location->point.x, | 230 scrollbar_->setLocation(WebRect(location->point.x, |
| 191 location->point.y, | 231 location->point.y, |
| 192 location->size.width, | 232 location->size.width, |
| 193 location->size.height)); | 233 location->size.height)); |
| 194 } | 234 } |
| 195 | 235 |
| 196 void PPB_Scrollbar_Impl::valueChanged(WebKit::WebScrollbar* scrollbar) { | 236 void PPB_Scrollbar_Impl::valueChanged(WebKit::WebScrollbar* scrollbar) { |
| 197 const PPP_Scrollbar_Dev* ppp_scrollbar = | 237 const PPP_Scrollbar_Dev* ppp_scrollbar = |
| 198 static_cast<const PPP_Scrollbar_Dev*>(instance()->module()-> | 238 static_cast<const PPP_Scrollbar_Dev*>(instance()->module()-> |
| 199 GetPluginInterface(PPP_SCROLLBAR_DEV_INTERFACE)); | 239 GetPluginInterface(PPP_SCROLLBAR_DEV_INTERFACE)); |
| 240 if (!ppp_scrollbar) { | |
| 241 // Try the old version. | |
|
brettw
2011/08/03 17:13:58
Can you add here that this is OK to do because the
| |
| 242 ppp_scrollbar = | |
| 243 static_cast<const PPP_Scrollbar_Dev*>(instance()->module()-> | |
| 244 GetPluginInterface(PPP_SCROLLBAR_DEV_INTERFACE_0_2)); | |
| 245 if (!ppp_scrollbar) | |
| 246 return; | |
| 247 } | |
| 248 ScopedResourceId resource(this); | |
| 249 ppp_scrollbar->ValueChanged( | |
| 250 instance()->pp_instance(), resource.id, scrollbar_->value()); | |
| 251 } | |
| 252 | |
| 253 void PPB_Scrollbar_Impl::overlayChanged(WebScrollbar* scrollbar) { | |
| 254 const PPP_Scrollbar_Dev* ppp_scrollbar = | |
| 255 static_cast<const PPP_Scrollbar_Dev*>(instance()->module()-> | |
| 256 GetPluginInterface(PPP_SCROLLBAR_DEV_INTERFACE)); | |
| 200 if (!ppp_scrollbar) | 257 if (!ppp_scrollbar) |
| 201 return; | 258 return; |
| 202 ScopedResourceId resource(this); | 259 ScopedResourceId resource(this); |
| 203 ppp_scrollbar->ValueChanged( | 260 ppp_scrollbar->OverlayChanged( |
| 204 instance()->pp_instance(), resource.id, scrollbar_->value()); | 261 instance()->pp_instance(), resource.id, |
| 262 PP_FromBool(IsOverlay())); | |
| 205 } | 263 } |
| 206 | 264 |
| 207 void PPB_Scrollbar_Impl::invalidateScrollbarRect( | 265 void PPB_Scrollbar_Impl::invalidateScrollbarRect( |
| 208 WebKit::WebScrollbar* scrollbar, | 266 WebKit::WebScrollbar* scrollbar, |
| 209 const WebKit::WebRect& rect) { | 267 const WebKit::WebRect& rect) { |
| 210 gfx::Rect gfx_rect(rect.x, | 268 gfx::Rect gfx_rect(rect.x, |
| 211 rect.y, | 269 rect.y, |
| 212 rect.width, | 270 rect.width, |
| 213 rect.height); | 271 rect.height); |
| 214 dirty_ = dirty_.Union(gfx_rect); | 272 dirty_ = dirty_.Union(gfx_rect); |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 239 pp_rect.point.y = dirty_.y(); | 297 pp_rect.point.y = dirty_.y(); |
| 240 pp_rect.size.width = dirty_.width(); | 298 pp_rect.size.width = dirty_.width(); |
| 241 pp_rect.size.height = dirty_.height(); | 299 pp_rect.size.height = dirty_.height(); |
| 242 dirty_ = gfx::Rect(); | 300 dirty_ = gfx::Rect(); |
| 243 Invalidate(&pp_rect); | 301 Invalidate(&pp_rect); |
| 244 } | 302 } |
| 245 | 303 |
| 246 } // namespace ppapi | 304 } // namespace ppapi |
| 247 } // namespace webkit | 305 } // namespace webkit |
| 248 | 306 |
| OLD | NEW |