#include "cc/animation/layer_animation_controller.h"
#include "cc/layers/layer_client.h"
#include "cc/layers/layer_impl.h"
+#include "cc/layers/scrollbar_layer_interface.h"
#include "cc/output/copy_output_request.h"
#include "cc/output/copy_output_result.h"
#include "cc/trees/layer_tree_host.h"
#include "cc/trees/layer_tree_impl.h"
#include "third_party/skia/include/core/SkImageFilter.h"
+#include "ui/gfx/geometry/vector2d_conversions.h"
#include "ui/gfx/rect_conversions.h"
namespace cc {
ignore_set_needs_commit_(false),
parent_(NULL),
layer_tree_host_(NULL),
- scrollable_(false),
+ scroll_clip_layer_id_(INVALID_ID),
should_scroll_on_main_thread_(false),
have_wheel_event_handlers_(false),
user_scrollable_horizontal_(true),
masks_to_bounds_(false),
contents_opaque_(false),
double_sided_(true),
- preserves_3d_(false),
+ should_flatten_transform_(true),
use_parent_backface_visibility_(false),
draw_checkerboard_for_missing_tiles_(false),
force_render_surface_(false),
+ is_3d_sorted_(false),
anchor_point_(0.5f, 0.5f),
background_color_(0),
opacity_(1.f),
return -1;
}
-void Layer::SetBounds(gfx::Size size) {
+void Layer::SetBounds(const gfx::Size& size) {
DCHECK(IsPropertyChangeAllowed());
if (bounds() == size)
return;
bool Layer::IsContainerForFixedPositionLayers() const {
if (!transform_.IsIdentityOrTranslation())
return true;
- if (parent_ && !parent_->sublayer_transform_.IsIdentityOrTranslation())
+ if (parent_ && !parent_->transform_.IsIdentityOrTranslation())
return true;
return is_container_for_fixed_position_layers_;
}
-void Layer::SetSublayerTransform(const gfx::Transform& sublayer_transform) {
- DCHECK(IsPropertyChangeAllowed());
- if (sublayer_transform_ == sublayer_transform)
- return;
- sublayer_transform_ = sublayer_transform;
- SetNeedsCommit();
-}
-
void Layer::SetTransform(const gfx::Transform& transform) {
DCHECK(IsPropertyChangeAllowed());
if (transform_ == transform)
void Layer::SetScrollOffset(gfx::Vector2d scroll_offset) {
DCHECK(IsPropertyChangeAllowed());
+
+ if (layer_tree_host()) {
+ scroll_offset = layer_tree_host()->DistributeScrollOffsetToViewports(
+ scroll_offset, this);
+ }
+
if (scroll_offset_ == scroll_offset)
return;
scroll_offset_ = scroll_offset;
SetNeedsCommit();
}
-void Layer::SetScrollOffsetFromImplSide(gfx::Vector2d scroll_offset) {
+void Layer::SetScrollOffsetFromImplSide(const gfx::Vector2d& scroll_offset) {
DCHECK(IsPropertyChangeAllowed());
// This function only gets called during a BeginMainFrame, so there
// is no need to call SetNeedsUpdate here.
// "this" may have been destroyed during the process.
}
-void Layer::SetMaxScrollOffset(gfx::Vector2d max_scroll_offset) {
- DCHECK(IsPropertyChangeAllowed());
- if (max_scroll_offset_ == max_scroll_offset)
- return;
- max_scroll_offset_ = max_scroll_offset;
- SetNeedsCommit();
+// TODO(wjmaclean) We should template this and put it into LayerTreeHostCommon
+// so that both Layer and LayerImpl are using the same code. In order
+// to template it we should avoid calling layer_tree_host() by giving
+// Layer/LayerImpl local accessors for page_scale_layer() and
+// page_scale_factor().
+gfx::Vector2d Layer::MaxScrollOffset() const {
+ if (scroll_clip_layer_id_ == INVALID_ID)
+ return gfx::Vector2d();
+
+ gfx::Size scaled_scroll_bounds(bounds());
+ Layer const* current_layer = this;
+ Layer const* page_scale_layer = layer_tree_host()->page_scale_layer();
+ float scale_factor = 1.f;
+ do {
+ if (current_layer == page_scale_layer) {
+ scale_factor = layer_tree_host()->page_scale_factor();
+ scaled_scroll_bounds.SetSize(
+ scale_factor * scaled_scroll_bounds.width(),
+ scale_factor * scaled_scroll_bounds.height());
+ }
+ current_layer = current_layer->parent();
+ } while (current_layer && current_layer->id() != scroll_clip_layer_id_);
+ DCHECK(current_layer);
+ DCHECK(current_layer->id() == scroll_clip_layer_id_);
+
+ gfx::Vector2dF max_offset(
+ scaled_scroll_bounds.width() - current_layer->bounds().width(),
+ scaled_scroll_bounds.height() - current_layer->bounds().height());
+ // We need the final scroll offset to be in CSS coords.
+ max_offset.Scale(1.f / scale_factor);
+ max_offset.SetToMax(gfx::Vector2dF());
+ return gfx::ToFlooredVector2d(max_offset);
}
-void Layer::SetScrollable(bool scrollable) {
+void Layer::SetScrollClipLayerId(int clip_layer_id) {
DCHECK(IsPropertyChangeAllowed());
- if (scrollable_ == scrollable)
+ if (scroll_clip_layer_id_ == clip_layer_id)
return;
- scrollable_ = scrollable;
+ scroll_clip_layer_id_ = clip_layer_id;
SetNeedsCommit();
}
SetNeedsCommit();
}
+void Layer::SetIs3dSorted(bool sorted) {
+ DCHECK(IsPropertyChangeAllowed());
+ if (is_3d_sorted_ == sorted)
+ return;
+ is_3d_sorted_ = sorted;
+ SetNeedsCommit();
+}
+
+void Layer::SetShouldFlattenTransform(bool should_flatten) {
+ DCHECK(IsPropertyChangeAllowed());
+ if (should_flatten_transform_ == should_flatten)
+ return;
+ should_flatten_transform_ = should_flatten;
+ SetNeedsCommit();
+}
+
void Layer::SetIsDrawable(bool is_drawable) {
DCHECK(IsPropertyChangeAllowed());
if (is_drawable_ == is_drawable)
layer->SetPosition(position_);
layer->SetIsContainerForFixedPositionLayers(
IsContainerForFixedPositionLayers());
- layer->SetFixedContainerSizeDelta(gfx::Vector2dF());
layer->SetPositionConstraint(position_constraint_);
- layer->SetPreserves3d(preserves_3d());
+ layer->SetShouldFlattenTransform(should_flatten_transform_);
+ layer->SetIs3dSorted(is_3d_sorted_);
layer->SetUseParentBackfaceVisibility(use_parent_backface_visibility_);
- layer->SetSublayerTransform(sublayer_transform_);
if (!layer->TransformIsAnimatingOnImplOnly() && !TransformIsAnimating())
layer->SetTransform(transform_);
DCHECK(!(TransformIsAnimating() && layer->TransformIsAnimatingOnImplOnly()));
- layer->SetScrollable(scrollable_);
+ layer->SetScrollClipLayer(scroll_clip_layer_id_);
layer->set_user_scrollable_horizontal(user_scrollable_horizontal_);
layer->set_user_scrollable_vertical(user_scrollable_vertical_);
- layer->SetMaxScrollOffset(max_scroll_offset_);
LayerImpl* scroll_parent = NULL;
if (scroll_parent_)
void Layer::RunMicroBenchmark(MicroBenchmark* benchmark) {
benchmark->RunOnLayer(this);
}
-
} // namespace cc