| OLD | NEW |
| (Empty) |
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "webkit/compositor_bindings/web_layer_impl.h" | |
| 6 | |
| 7 #include "base/string_util.h" | |
| 8 #include "cc/animation/animation.h" | |
| 9 #include "cc/base/region.h" | |
| 10 #include "cc/layers/layer.h" | |
| 11 #include "cc/layers/layer_position_constraint.h" | |
| 12 #include "third_party/WebKit/Source/Platform/chromium/public/WebFloatPoint.h" | |
| 13 #include "third_party/WebKit/Source/Platform/chromium/public/WebFloatRect.h" | |
| 14 #include "third_party/WebKit/Source/Platform/chromium/public/WebLayerPositionCon
straint.h" | |
| 15 #include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h" | |
| 16 #include "third_party/skia/include/utils/SkMatrix44.h" | |
| 17 #include "webkit/compositor_bindings/web_animation_impl.h" | |
| 18 | |
| 19 using cc::Animation; | |
| 20 using cc::Layer; | |
| 21 using WebKit::WebLayer; | |
| 22 using WebKit::WebFloatPoint; | |
| 23 using WebKit::WebVector; | |
| 24 using WebKit::WebRect; | |
| 25 using WebKit::WebSize; | |
| 26 using WebKit::WebColor; | |
| 27 using WebKit::WebFilterOperations; | |
| 28 | |
| 29 namespace webkit { | |
| 30 | |
| 31 WebLayerImpl::WebLayerImpl() : layer_(Layer::Create()) {} | |
| 32 | |
| 33 WebLayerImpl::WebLayerImpl(scoped_refptr<Layer> layer) : layer_(layer) {} | |
| 34 | |
| 35 WebLayerImpl::~WebLayerImpl() { | |
| 36 layer_->ClearRenderSurface(); | |
| 37 layer_->set_layer_animation_delegate(NULL); | |
| 38 } | |
| 39 | |
| 40 int WebLayerImpl::id() const { return layer_->id(); } | |
| 41 | |
| 42 void WebLayerImpl::invalidateRect(const WebKit::WebFloatRect& rect) { | |
| 43 layer_->SetNeedsDisplayRect(rect); | |
| 44 } | |
| 45 | |
| 46 void WebLayerImpl::invalidate() { layer_->SetNeedsDisplay(); } | |
| 47 | |
| 48 void WebLayerImpl::addChild(WebLayer* child) { | |
| 49 layer_->AddChild(static_cast<WebLayerImpl*>(child)->layer()); | |
| 50 } | |
| 51 | |
| 52 void WebLayerImpl::insertChild(WebLayer* child, size_t index) { | |
| 53 layer_->InsertChild(static_cast<WebLayerImpl*>(child)->layer(), index); | |
| 54 } | |
| 55 | |
| 56 void WebLayerImpl::replaceChild(WebLayer* reference, WebLayer* new_layer) { | |
| 57 layer_->ReplaceChild(static_cast<WebLayerImpl*>(reference)->layer(), | |
| 58 static_cast<WebLayerImpl*>(new_layer)->layer()); | |
| 59 } | |
| 60 | |
| 61 void WebLayerImpl::removeFromParent() { layer_->RemoveFromParent(); } | |
| 62 | |
| 63 void WebLayerImpl::removeAllChildren() { layer_->RemoveAllChildren(); } | |
| 64 | |
| 65 void WebLayerImpl::setAnchorPoint(const WebFloatPoint& anchor_point) { | |
| 66 layer_->SetAnchorPoint(anchor_point); | |
| 67 } | |
| 68 | |
| 69 WebFloatPoint WebLayerImpl::anchorPoint() const { | |
| 70 return layer_->anchor_point(); | |
| 71 } | |
| 72 | |
| 73 void WebLayerImpl::setAnchorPointZ(float anchor_point_z) { | |
| 74 layer_->SetAnchorPointZ(anchor_point_z); | |
| 75 } | |
| 76 | |
| 77 float WebLayerImpl::anchorPointZ() const { return layer_->anchor_point_z(); } | |
| 78 | |
| 79 void WebLayerImpl::setBounds(const WebSize& size) { layer_->SetBounds(size); } | |
| 80 | |
| 81 WebSize WebLayerImpl::bounds() const { return layer_->bounds(); } | |
| 82 | |
| 83 void WebLayerImpl::setMasksToBounds(bool masks_to_bounds) { | |
| 84 layer_->SetMasksToBounds(masks_to_bounds); | |
| 85 } | |
| 86 | |
| 87 bool WebLayerImpl::masksToBounds() const { return layer_->masks_to_bounds(); } | |
| 88 | |
| 89 void WebLayerImpl::setMaskLayer(WebLayer* maskLayer) { | |
| 90 layer_->SetMaskLayer( | |
| 91 maskLayer ? static_cast<WebLayerImpl*>(maskLayer)->layer() : 0); | |
| 92 } | |
| 93 | |
| 94 void WebLayerImpl::setReplicaLayer(WebLayer* replica_layer) { | |
| 95 layer_->SetReplicaLayer( | |
| 96 replica_layer ? static_cast<WebLayerImpl*>(replica_layer)->layer() : 0); | |
| 97 } | |
| 98 | |
| 99 void WebLayerImpl::setOpacity(float opacity) { layer_->SetOpacity(opacity); } | |
| 100 | |
| 101 float WebLayerImpl::opacity() const { return layer_->opacity(); } | |
| 102 | |
| 103 void WebLayerImpl::setOpaque(bool opaque) { layer_->SetContentsOpaque(opaque); } | |
| 104 | |
| 105 bool WebLayerImpl::opaque() const { return layer_->contents_opaque(); } | |
| 106 | |
| 107 void WebLayerImpl::setPosition(const WebFloatPoint& position) { | |
| 108 layer_->SetPosition(position); | |
| 109 } | |
| 110 | |
| 111 WebFloatPoint WebLayerImpl::position() const { return layer_->position(); } | |
| 112 | |
| 113 void WebLayerImpl::setSublayerTransform(const SkMatrix44& matrix) { | |
| 114 gfx::Transform sub_layer_transform; | |
| 115 sub_layer_transform.matrix() = matrix; | |
| 116 layer_->SetSublayerTransform(sub_layer_transform); | |
| 117 } | |
| 118 | |
| 119 SkMatrix44 WebLayerImpl::sublayerTransform() const { | |
| 120 return layer_->sublayer_transform().matrix(); | |
| 121 } | |
| 122 | |
| 123 void WebLayerImpl::setTransform(const SkMatrix44& matrix) { | |
| 124 gfx::Transform transform; | |
| 125 transform.matrix() = matrix; | |
| 126 layer_->SetTransform(transform); | |
| 127 } | |
| 128 | |
| 129 SkMatrix44 WebLayerImpl::transform() const { | |
| 130 return layer_->transform().matrix(); | |
| 131 } | |
| 132 | |
| 133 void WebLayerImpl::setDrawsContent(bool draws_content) { | |
| 134 layer_->SetIsDrawable(draws_content); | |
| 135 } | |
| 136 | |
| 137 bool WebLayerImpl::drawsContent() const { return layer_->DrawsContent(); } | |
| 138 | |
| 139 void WebLayerImpl::setPreserves3D(bool preserve3D) { | |
| 140 layer_->SetPreserves3d(preserve3D); | |
| 141 } | |
| 142 | |
| 143 void WebLayerImpl::setUseParentBackfaceVisibility( | |
| 144 bool use_parent_backface_visibility) { | |
| 145 layer_->set_use_parent_backface_visibility(use_parent_backface_visibility); | |
| 146 } | |
| 147 | |
| 148 void WebLayerImpl::setBackgroundColor(WebColor color) { | |
| 149 layer_->SetBackgroundColor(color); | |
| 150 } | |
| 151 | |
| 152 WebColor WebLayerImpl::backgroundColor() const { | |
| 153 return layer_->background_color(); | |
| 154 } | |
| 155 | |
| 156 void WebLayerImpl::setFilters(const WebFilterOperations& filters) { | |
| 157 layer_->SetFilters(filters); | |
| 158 } | |
| 159 | |
| 160 void WebLayerImpl::setBackgroundFilters(const WebFilterOperations& filters) { | |
| 161 layer_->SetBackgroundFilters(filters); | |
| 162 } | |
| 163 | |
| 164 void WebLayerImpl::setFilter(SkImageFilter* filter) { | |
| 165 SkSafeRef(filter); // Claim a reference for the compositor. | |
| 166 layer_->SetFilter(skia::AdoptRef(filter)); | |
| 167 } | |
| 168 | |
| 169 void WebLayerImpl::setDebugName(WebKit::WebString name) { | |
| 170 layer_->SetDebugName( | |
| 171 UTF16ToASCII(base::string16(name.data(), name.length()))); | |
| 172 } | |
| 173 | |
| 174 void WebLayerImpl::setAnimationDelegate( | |
| 175 WebKit::WebAnimationDelegate* delegate) { | |
| 176 layer_->set_layer_animation_delegate(delegate); | |
| 177 } | |
| 178 | |
| 179 bool WebLayerImpl::addAnimation(WebKit::WebAnimation* animation) { | |
| 180 return layer_->AddAnimation( | |
| 181 static_cast<WebAnimationImpl*>(animation)->CloneToAnimation()); | |
| 182 } | |
| 183 | |
| 184 void WebLayerImpl::removeAnimation(int animation_id) { | |
| 185 layer_->RemoveAnimation(animation_id); | |
| 186 } | |
| 187 | |
| 188 void WebLayerImpl::removeAnimation( | |
| 189 int animation_id, | |
| 190 WebKit::WebAnimation::TargetProperty target_property) { | |
| 191 layer_->layer_animation_controller()->RemoveAnimation( | |
| 192 animation_id, | |
| 193 static_cast<Animation::TargetProperty>(target_property)); | |
| 194 } | |
| 195 | |
| 196 void WebLayerImpl::pauseAnimation(int animation_id, double time_offset) { | |
| 197 layer_->PauseAnimation(animation_id, time_offset); | |
| 198 } | |
| 199 | |
| 200 void WebLayerImpl::suspendAnimations(double monotonic_time) { | |
| 201 layer_->SuspendAnimations(monotonic_time); | |
| 202 } | |
| 203 | |
| 204 void WebLayerImpl::resumeAnimations(double monotonic_time) { | |
| 205 layer_->ResumeAnimations(monotonic_time); | |
| 206 } | |
| 207 | |
| 208 bool WebLayerImpl::hasActiveAnimation() { return layer_->HasActiveAnimation(); } | |
| 209 | |
| 210 void WebLayerImpl::transferAnimationsTo(WebLayer* other) { | |
| 211 DCHECK(other); | |
| 212 layer_->TransferAnimationsTo(static_cast<WebLayerImpl*>(other)->layer_); | |
| 213 } | |
| 214 | |
| 215 void WebLayerImpl::setForceRenderSurface(bool force_render_surface) { | |
| 216 layer_->SetForceRenderSurface(force_render_surface); | |
| 217 } | |
| 218 | |
| 219 void WebLayerImpl::setScrollPosition(WebKit::WebPoint position) { | |
| 220 layer_->SetScrollOffset(gfx::Point(position).OffsetFromOrigin()); | |
| 221 } | |
| 222 | |
| 223 WebKit::WebPoint WebLayerImpl::scrollPosition() const { | |
| 224 return gfx::PointAtOffsetFromOrigin(layer_->scroll_offset()); | |
| 225 } | |
| 226 | |
| 227 void WebLayerImpl::setMaxScrollPosition(WebSize max_scroll_position) { | |
| 228 layer_->SetMaxScrollOffset(max_scroll_position); | |
| 229 } | |
| 230 | |
| 231 WebSize WebLayerImpl::maxScrollPosition() const { | |
| 232 return layer_->max_scroll_offset(); | |
| 233 } | |
| 234 | |
| 235 void WebLayerImpl::setScrollable(bool scrollable) { | |
| 236 layer_->SetScrollable(scrollable); | |
| 237 } | |
| 238 | |
| 239 bool WebLayerImpl::scrollable() const { return layer_->scrollable(); } | |
| 240 | |
| 241 void WebLayerImpl::setHaveWheelEventHandlers(bool have_wheel_event_handlers) { | |
| 242 layer_->SetHaveWheelEventHandlers(have_wheel_event_handlers); | |
| 243 } | |
| 244 | |
| 245 bool WebLayerImpl::haveWheelEventHandlers() const { | |
| 246 return layer_->have_wheel_event_handlers(); | |
| 247 } | |
| 248 | |
| 249 void WebLayerImpl::setShouldScrollOnMainThread( | |
| 250 bool should_scroll_on_main_thread) { | |
| 251 layer_->SetShouldScrollOnMainThread(should_scroll_on_main_thread); | |
| 252 } | |
| 253 | |
| 254 bool WebLayerImpl::shouldScrollOnMainThread() const { | |
| 255 return layer_->should_scroll_on_main_thread(); | |
| 256 } | |
| 257 | |
| 258 void WebLayerImpl::setNonFastScrollableRegion(const WebVector<WebRect>& rects) { | |
| 259 cc::Region region; | |
| 260 for (size_t i = 0; i < rects.size(); ++i) | |
| 261 region.Union(rects[i]); | |
| 262 layer_->SetNonFastScrollableRegion(region); | |
| 263 } | |
| 264 | |
| 265 WebVector<WebRect> WebLayerImpl::nonFastScrollableRegion() const { | |
| 266 size_t num_rects = 0; | |
| 267 for (cc::Region::Iterator region_rects(layer_->non_fast_scrollable_region()); | |
| 268 region_rects.has_rect(); | |
| 269 region_rects.next()) | |
| 270 ++num_rects; | |
| 271 | |
| 272 WebVector<WebRect> result(num_rects); | |
| 273 size_t i = 0; | |
| 274 for (cc::Region::Iterator region_rects(layer_->non_fast_scrollable_region()); | |
| 275 region_rects.has_rect(); | |
| 276 region_rects.next()) { | |
| 277 result[i] = region_rects.rect(); | |
| 278 ++i; | |
| 279 } | |
| 280 return result; | |
| 281 } | |
| 282 | |
| 283 void WebLayerImpl::setTouchEventHandlerRegion(const WebVector<WebRect>& rects) { | |
| 284 cc::Region region; | |
| 285 for (size_t i = 0; i < rects.size(); ++i) | |
| 286 region.Union(rects[i]); | |
| 287 layer_->SetTouchEventHandlerRegion(region); | |
| 288 } | |
| 289 | |
| 290 WebVector<WebRect> WebLayerImpl::touchEventHandlerRegion() const { | |
| 291 size_t num_rects = 0; | |
| 292 for (cc::Region::Iterator region_rects(layer_->touch_event_handler_region()); | |
| 293 region_rects.has_rect(); | |
| 294 region_rects.next()) | |
| 295 ++num_rects; | |
| 296 | |
| 297 WebVector<WebRect> result(num_rects); | |
| 298 size_t i = 0; | |
| 299 for (cc::Region::Iterator region_rects(layer_->touch_event_handler_region()); | |
| 300 region_rects.has_rect(); | |
| 301 region_rects.next()) { | |
| 302 result[i] = region_rects.rect(); | |
| 303 ++i; | |
| 304 } | |
| 305 return result; | |
| 306 } | |
| 307 | |
| 308 void WebLayerImpl::setIsContainerForFixedPositionLayers(bool enable) { | |
| 309 layer_->SetIsContainerForFixedPositionLayers(enable); | |
| 310 } | |
| 311 | |
| 312 bool WebLayerImpl::isContainerForFixedPositionLayers() const { | |
| 313 return layer_->IsContainerForFixedPositionLayers(); | |
| 314 } | |
| 315 | |
| 316 static WebKit::WebLayerPositionConstraint ToWebLayerPositionConstraint( | |
| 317 const cc::LayerPositionConstraint& constraint) { | |
| 318 WebKit::WebLayerPositionConstraint web_constraint; | |
| 319 web_constraint.isFixedPosition = constraint.is_fixed_position(); | |
| 320 web_constraint.isFixedToRightEdge = constraint.is_fixed_to_right_edge(); | |
| 321 web_constraint.isFixedToBottomEdge = constraint.is_fixed_to_bottom_edge(); | |
| 322 return web_constraint; | |
| 323 } | |
| 324 | |
| 325 static cc::LayerPositionConstraint ToLayerPositionConstraint( | |
| 326 const WebKit::WebLayerPositionConstraint& web_constraint) { | |
| 327 cc::LayerPositionConstraint constraint; | |
| 328 constraint.set_is_fixed_position(web_constraint.isFixedPosition); | |
| 329 constraint.set_is_fixed_to_right_edge(web_constraint.isFixedToRightEdge); | |
| 330 constraint.set_is_fixed_to_bottom_edge(web_constraint.isFixedToBottomEdge); | |
| 331 return constraint; | |
| 332 } | |
| 333 | |
| 334 void WebLayerImpl::setPositionConstraint( | |
| 335 const WebKit::WebLayerPositionConstraint& constraint) { | |
| 336 layer_->SetPositionConstraint(ToLayerPositionConstraint(constraint)); | |
| 337 } | |
| 338 | |
| 339 WebKit::WebLayerPositionConstraint WebLayerImpl::positionConstraint() const { | |
| 340 return ToWebLayerPositionConstraint(layer_->position_constraint()); | |
| 341 } | |
| 342 | |
| 343 void WebLayerImpl::setScrollClient( | |
| 344 WebKit::WebLayerScrollClient* scroll_client) { | |
| 345 layer_->set_layer_scroll_client(scroll_client); | |
| 346 } | |
| 347 | |
| 348 bool WebLayerImpl::isOrphan() const { return !layer_->layer_tree_host(); } | |
| 349 | |
| 350 Layer* WebLayerImpl::layer() const { return layer_.get(); } | |
| 351 | |
| 352 } // namespace WebKit | |
| OLD | NEW |