Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(997)

Unified Diff: ui/views/examples/scroll_view_example.cc

Issue 2194833002: Overscroll and Elasticity for views::ScrollView Base URL: https://chromium.googlesource.com/chromium/src.git@20160728-MacViews-RouteThroughInputHandler
Patch Set: Restore functionality and fix bugs \o/ Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/views/examples/scroll_view_example.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/examples/scroll_view_example.cc
diff --git a/ui/views/examples/scroll_view_example.cc b/ui/views/examples/scroll_view_example.cc
index 4fd1aaa2970948ed351eff7775a654532e9aa837..687056ce32bd3a5ce195c44cff60dd6fc62d6eca 100644
--- a/ui/views/examples/scroll_view_example.cc
+++ b/ui/views/examples/scroll_view_example.cc
@@ -64,11 +64,11 @@ void ScrollViewExample::CreateExampleView(View* container) {
big_square_ = new LabelButton(this, ASCIIToUTF16("Big Square"));
small_square_ = new LabelButton(this, ASCIIToUTF16("Small Square"));
scroll_to_ = new LabelButton(this, ASCIIToUTF16("Scroll to"));
- scrollable_ = new ScrollableView();
+ nested_ = new LabelButton(this, ASCIIToUTF16("Nested"));
scroll_view_ = new ScrollView();
+ CreateScrollable();
scroll_view_->SetContents(scrollable_);
- scrollable_->SetBounds(0, 0, 1000, 100);
- scrollable_->SetColor(SK_ColorYELLOW, SK_ColorCYAN);
+ nested_scrolls_ = nullptr;
GridLayout* layout = new GridLayout(container);
container->SetLayoutManager(layout);
@@ -82,7 +82,7 @@ void ScrollViewExample::CreateExampleView(View* container) {
// Add control buttons.
column_set = layout->AddColumnSet(1);
- for (int i = 0; i < 5; i++) {
+ for (int i = 0; i < 6; i++) {
column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1,
GridLayout::USE_PREF, 0, 0);
}
@@ -92,9 +92,50 @@ void ScrollViewExample::CreateExampleView(View* container) {
layout->AddView(big_square_);
layout->AddView(small_square_);
layout->AddView(scroll_to_);
+ layout->AddView(nested_);
+}
+
+void ScrollViewExample::CreateScrollable() {
+ scrollable_ = new ScrollableView();
+ scrollable_->SetBounds(0, 0, 1000, 100);
+ scrollable_->SetColor(SK_ColorYELLOW, SK_ColorCYAN);
+}
+
+void ScrollViewExample::CreateNestedScrolls() {
+ const int kNestedHeight = 500;
+ nested_scrolls_ = new View();
+ nested_scrolls_->SetBounds(0, 0, 1000, kNestedHeight);
+ // Add two scroll views.
+ ScrollView* left = new ScrollView();
+ ScrollView* right = new ScrollView();
+ left->SetBounds(0, 0, 500, kNestedHeight);
+ right->SetBounds(500, 0, 500, kNestedHeight);
+
+ // The left scrollable is tall. Scrolling vertically inside it should scroll
+ // the inner ScrollView first, then the outer ScrollView when reaching the
+ // bounds. Scrolling horizontally should affect the outer scroll view, but
+ // elasticity should affect only the inner ScrollView (both directions).
+ CreateScrollable();
+ scrollable_->SetBounds(0, 0, 400, 1000);
+ left->SetContents(scrollable_);
+
+ // The right scrollable is too small to scroll. The outer scroll view should
+ // always scroll, and it should get all the elasticity.
+ CreateScrollable();
+ scrollable_->SetBounds(0, 0, 100, 100);
+ right->SetContents(scrollable_);
+
+ nested_scrolls_->AddChildView(left);
+ nested_scrolls_->AddChildView(right);
}
void ScrollViewExample::ButtonPressed(Button* sender, const ui::Event& event) {
+ if (nested_scrolls_ && sender != nested_) {
+ CreateScrollable();
+ scroll_view_->SetContents(scrollable_);
+ nested_scrolls_ = nullptr;
+ }
+
if (sender == wide_) {
scrollable_->SetBounds(0, 0, 1000, 100);
scrollable_->SetColor(SK_ColorYELLOW, SK_ColorCYAN);
@@ -110,6 +151,10 @@ void ScrollViewExample::ButtonPressed(Button* sender, const ui::Event& event) {
} else if (sender == scroll_to_) {
scroll_view_->contents()->ScrollRectToVisible(
gfx::Rect(20, 500, 1000, 500));
+ } else if (sender == nested_) {
+ if (!nested_scrolls_)
+ CreateNestedScrolls();
+ scroll_view_->SetContents(nested_scrolls_);
}
scroll_view_->Layout();
}
« no previous file with comments | « ui/views/examples/scroll_view_example.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698