| 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();
|
| }
|
|
|