summaryrefslogtreecommitdiffstats
path: root/cc/layers
diff options
context:
space:
mode:
authorsadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-22 03:36:43 +0000
committersadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-22 03:36:43 +0000
commit59a7d55a7116325891f2a25329041d9e657d2a6a (patch)
tree5bff7b5fc26c17ba98b6069584244d97dd35461c /cc/layers
parentf02ebd33700c53251c0e86662a91390170950477 (diff)
downloadchromium_src-59a7d55a7116325891f2a25329041d9e657d2a6a.zip
chromium_src-59a7d55a7116325891f2a25329041d9e657d2a6a.tar.gz
chromium_src-59a7d55a7116325891f2a25329041d9e657d2a6a.tar.bz2
cc: Do not allow gesture-scrolling 'overflow[-{x|y}]:hidden' layers.
BUG=175502 R=jamesr@chromium.org Review URL: https://codereview.chromium.org/30793002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@230032 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc/layers')
-rw-r--r--cc/layers/layer.cc14
-rw-r--r--cc/layers/layer.h8
-rw-r--r--cc/layers/layer_impl.cc23
-rw-r--r--cc/layers/layer_impl.h9
-rw-r--r--cc/layers/layer_impl_unittest.cc14
-rw-r--r--cc/layers/layer_unittest.cc1
6 files changed, 68 insertions, 1 deletions
diff --git a/cc/layers/layer.cc b/cc/layers/layer.cc
index 15de223..80fad6a 100644
--- a/cc/layers/layer.cc
+++ b/cc/layers/layer.cc
@@ -41,6 +41,8 @@ Layer::Layer()
scrollable_(false),
should_scroll_on_main_thread_(false),
have_wheel_event_handlers_(false),
+ user_scrollable_horizontal_(true),
+ user_scrollable_vertical_(true),
anchor_point_(0.5f, 0.5f),
background_color_(0),
compositing_reasons_(kCompositingReasonUnknown),
@@ -646,6 +648,16 @@ void Layer::SetScrollable(bool scrollable) {
SetNeedsCommit();
}
+void Layer::SetUserScrollable(bool horizontal, bool vertical) {
+ DCHECK(IsPropertyChangeAllowed());
+ if (user_scrollable_horizontal_ == horizontal &&
+ user_scrollable_vertical_ == vertical)
+ return;
+ user_scrollable_horizontal_ = horizontal;
+ user_scrollable_vertical_ = vertical;
+ SetNeedsCommit();
+}
+
void Layer::SetShouldScrollOnMainThread(bool should_scroll_on_main_thread) {
DCHECK(IsPropertyChangeAllowed());
if (should_scroll_on_main_thread_ == should_scroll_on_main_thread)
@@ -833,6 +845,8 @@ void Layer::PushPropertiesTo(LayerImpl* layer) {
DCHECK(!(TransformIsAnimating() && layer->TransformIsAnimatingOnImplOnly()));
layer->SetScrollable(scrollable_);
+ 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;
diff --git a/cc/layers/layer.h b/cc/layers/layer.h
index e1bed9b..1328b07 100644
--- a/cc/layers/layer.h
+++ b/cc/layers/layer.h
@@ -251,6 +251,12 @@ class CC_EXPORT Layer : public base::RefCounted<Layer>,
void SetScrollable(bool scrollable);
bool scrollable() const { return scrollable_; }
+ void SetUserScrollable(bool horizontal, bool vertical);
+ bool user_scrollable_horizontal() const {
+ return user_scrollable_horizontal_;
+ }
+ bool user_scrollable_vertical() const { return user_scrollable_vertical_; }
+
void SetShouldScrollOnMainThread(bool should_scroll_on_main_thread);
bool should_scroll_on_main_thread() const {
return should_scroll_on_main_thread_;
@@ -539,6 +545,8 @@ class CC_EXPORT Layer : public base::RefCounted<Layer>,
bool scrollable_;
bool should_scroll_on_main_thread_;
bool have_wheel_event_handlers_;
+ bool user_scrollable_horizontal_;
+ bool user_scrollable_vertical_;
Region non_fast_scrollable_region_;
Region touch_event_handler_region_;
gfx::PointF position_;
diff --git a/cc/layers/layer_impl.cc b/cc/layers/layer_impl.cc
index d42ec31..14f3e2a 100644
--- a/cc/layers/layer_impl.cc
+++ b/cc/layers/layer_impl.cc
@@ -42,6 +42,8 @@ LayerImpl::LayerImpl(LayerTreeImpl* tree_impl, int id)
scrollable_(false),
should_scroll_on_main_thread_(false),
have_wheel_event_handlers_(false),
+ user_scrollable_horizontal_(true),
+ user_scrollable_vertical_(true),
background_color_(0),
stacking_order_changed_(false),
double_sided_(true),
@@ -341,6 +343,15 @@ void LayerImpl::SetSentScrollDelta(gfx::Vector2d sent_scroll_delta) {
gfx::Vector2dF LayerImpl::ScrollBy(gfx::Vector2dF scroll) {
DCHECK(scrollable());
+ gfx::Vector2dF scroll_hidden;
+ if (!user_scrollable_horizontal_) {
+ scroll_hidden.set_x(scroll.x());
+ scroll.set_x(0.f);
+ }
+ if (!user_scrollable_vertical_) {
+ scroll_hidden.set_y(scroll.y());
+ scroll.set_y(0.f);
+ }
gfx::Vector2dF min_delta = -scroll_offset_;
gfx::Vector2dF max_delta = max_scroll_offset_ - scroll_offset_;
@@ -348,7 +359,8 @@ gfx::Vector2dF LayerImpl::ScrollBy(gfx::Vector2dF scroll) {
gfx::Vector2dF new_delta = (ScrollDelta() + scroll);
new_delta.SetToMax(min_delta);
new_delta.SetToMin(max_delta);
- gfx::Vector2dF unscrolled = ScrollDelta() + scroll - new_delta;
+ gfx::Vector2dF unscrolled =
+ ScrollDelta() + scroll + scroll_hidden - new_delta;
SetScrollDelta(new_delta);
return unscrolled;
}
@@ -449,6 +461,13 @@ InputHandler::ScrollStatus LayerImpl::TryScroll(
return InputHandler::ScrollIgnored;
}
+ if (!user_scrollable_horizontal_ && !user_scrollable_vertical_) {
+ TRACE_EVENT0("cc",
+ "LayerImpl::TryScroll: Ignored. User gesture is not allowed"
+ " to scroll this layer.");
+ return InputHandler::ScrollIgnored;
+ }
+
return InputHandler::ScrollStarted;
}
@@ -514,6 +533,8 @@ void LayerImpl::PushPropertiesTo(LayerImpl* layer) {
layer->SetTransform(transform_);
layer->SetScrollable(scrollable_);
+ layer->set_user_scrollable_horizontal(user_scrollable_horizontal_);
+ layer->set_user_scrollable_vertical(user_scrollable_vertical_);
layer->SetScrollOffsetAndDelta(
scroll_offset_, layer->ScrollDelta() - layer->sent_scroll_delta());
layer->SetSentScrollDelta(gfx::Vector2d());
diff --git a/cc/layers/layer_impl.h b/cc/layers/layer_impl.h
index 2048840..4bd91da 100644
--- a/cc/layers/layer_impl.h
+++ b/cc/layers/layer_impl.h
@@ -374,6 +374,13 @@ class CC_EXPORT LayerImpl : LayerAnimationValueObserver {
void SetScrollable(bool scrollable) { scrollable_ = scrollable; }
bool scrollable() const { return scrollable_; }
+ void set_user_scrollable_horizontal(bool scrollable) {
+ user_scrollable_horizontal_ = scrollable;
+ }
+ void set_user_scrollable_vertical(bool scrollable) {
+ user_scrollable_vertical_ = scrollable;
+ }
+
void ApplySentScrollDeltasFromAbortedCommit();
void ApplyScrollDeltasSinceBeginFrame();
@@ -544,6 +551,8 @@ class CC_EXPORT LayerImpl : LayerAnimationValueObserver {
bool scrollable_;
bool should_scroll_on_main_thread_;
bool have_wheel_event_handlers_;
+ bool user_scrollable_horizontal_;
+ bool user_scrollable_vertical_;
Region non_fast_scrollable_region_;
Region touch_event_handler_region_;
SkColor background_color_;
diff --git a/cc/layers/layer_impl_unittest.cc b/cc/layers/layer_impl_unittest.cc
index 83cd346..2d3305c 100644
--- a/cc/layers/layer_impl_unittest.cc
+++ b/cc/layers/layer_impl_unittest.cc
@@ -547,5 +547,19 @@ TEST_F(LayerImplScrollTest, ApplySentScrollsWithAcceptingDelegate) {
EXPECT_VECTOR_EQ(gfx::Vector2d(), layer()->sent_scroll_delta());
}
+TEST_F(LayerImplScrollTest, ScrollUserUnscrollableLayer) {
+ gfx::Vector2d max_scroll_offset(50, 80);
+ gfx::Vector2d scroll_offset(10, 5);
+ gfx::Vector2dF scroll_delta(20.5f, 8.5f);
+
+ layer()->set_user_scrollable_vertical(false);
+ layer()->SetMaxScrollOffset(max_scroll_offset);
+ layer()->SetScrollOffset(scroll_offset);
+ gfx::Vector2dF unscrolled = layer()->ScrollBy(scroll_delta);
+
+ EXPECT_VECTOR_EQ(gfx::Vector2dF(0, 8.5f), unscrolled);
+ EXPECT_VECTOR_EQ(gfx::Vector2dF(30.5f, 5), layer()->TotalScrollOffset());
+}
+
} // namespace
} // namespace cc
diff --git a/cc/layers/layer_unittest.cc b/cc/layers/layer_unittest.cc
index 3bbff6b..3a7a1c1 100644
--- a/cc/layers/layer_unittest.cc
+++ b/cc/layers/layer_unittest.cc
@@ -550,6 +550,7 @@ TEST_F(LayerTest, CheckPropertyChangeCausesCorrectBehavior) {
EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetSublayerTransform(
gfx::Transform(0.0, 0.0, 0.0, 0.0, 0.0, 0.0)));
EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetScrollable(true));
+ EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetUserScrollable(true, false));
EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetScrollOffset(
gfx::Vector2d(10, 10)));
EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetShouldScrollOnMainThread(true));