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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « ui/views/examples/scroll_view_example.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/views/examples/scroll_view_example.h" 5 #include "ui/views/examples/scroll_view_example.h"
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/strings/stringprintf.h" 8 #include "base/strings/stringprintf.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "ui/views/background.h" 10 #include "ui/views/background.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 57
58 ScrollViewExample::~ScrollViewExample() { 58 ScrollViewExample::~ScrollViewExample() {
59 } 59 }
60 60
61 void ScrollViewExample::CreateExampleView(View* container) { 61 void ScrollViewExample::CreateExampleView(View* container) {
62 wide_ = new LabelButton(this, ASCIIToUTF16("Wide")); 62 wide_ = new LabelButton(this, ASCIIToUTF16("Wide"));
63 tall_ = new LabelButton(this, ASCIIToUTF16("Tall")); 63 tall_ = new LabelButton(this, ASCIIToUTF16("Tall"));
64 big_square_ = new LabelButton(this, ASCIIToUTF16("Big Square")); 64 big_square_ = new LabelButton(this, ASCIIToUTF16("Big Square"));
65 small_square_ = new LabelButton(this, ASCIIToUTF16("Small Square")); 65 small_square_ = new LabelButton(this, ASCIIToUTF16("Small Square"));
66 scroll_to_ = new LabelButton(this, ASCIIToUTF16("Scroll to")); 66 scroll_to_ = new LabelButton(this, ASCIIToUTF16("Scroll to"));
67 scrollable_ = new ScrollableView(); 67 nested_ = new LabelButton(this, ASCIIToUTF16("Nested"));
68 scroll_view_ = new ScrollView(); 68 scroll_view_ = new ScrollView();
69 CreateScrollable();
69 scroll_view_->SetContents(scrollable_); 70 scroll_view_->SetContents(scrollable_);
70 scrollable_->SetBounds(0, 0, 1000, 100); 71 nested_scrolls_ = nullptr;
71 scrollable_->SetColor(SK_ColorYELLOW, SK_ColorCYAN);
72 72
73 GridLayout* layout = new GridLayout(container); 73 GridLayout* layout = new GridLayout(container);
74 container->SetLayoutManager(layout); 74 container->SetLayoutManager(layout);
75 75
76 // Add scroll view. 76 // Add scroll view.
77 ColumnSet* column_set = layout->AddColumnSet(0); 77 ColumnSet* column_set = layout->AddColumnSet(0);
78 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, 78 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1,
79 GridLayout::USE_PREF, 0, 0); 79 GridLayout::USE_PREF, 0, 0);
80 layout->StartRow(1, 0); 80 layout->StartRow(1, 0);
81 layout->AddView(scroll_view_); 81 layout->AddView(scroll_view_);
82 82
83 // Add control buttons. 83 // Add control buttons.
84 column_set = layout->AddColumnSet(1); 84 column_set = layout->AddColumnSet(1);
85 for (int i = 0; i < 5; i++) { 85 for (int i = 0; i < 6; i++) {
86 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, 86 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1,
87 GridLayout::USE_PREF, 0, 0); 87 GridLayout::USE_PREF, 0, 0);
88 } 88 }
89 layout->StartRow(0, 1); 89 layout->StartRow(0, 1);
90 layout->AddView(wide_); 90 layout->AddView(wide_);
91 layout->AddView(tall_); 91 layout->AddView(tall_);
92 layout->AddView(big_square_); 92 layout->AddView(big_square_);
93 layout->AddView(small_square_); 93 layout->AddView(small_square_);
94 layout->AddView(scroll_to_); 94 layout->AddView(scroll_to_);
95 layout->AddView(nested_);
96 }
97
98 void ScrollViewExample::CreateScrollable() {
99 scrollable_ = new ScrollableView();
100 scrollable_->SetBounds(0, 0, 1000, 100);
101 scrollable_->SetColor(SK_ColorYELLOW, SK_ColorCYAN);
102 }
103
104 void ScrollViewExample::CreateNestedScrolls() {
105 const int kNestedHeight = 500;
106 nested_scrolls_ = new View();
107 nested_scrolls_->SetBounds(0, 0, 1000, kNestedHeight);
108 // Add two scroll views.
109 ScrollView* left = new ScrollView();
110 ScrollView* right = new ScrollView();
111 left->SetBounds(0, 0, 500, kNestedHeight);
112 right->SetBounds(500, 0, 500, kNestedHeight);
113
114 // The left scrollable is tall. Scrolling vertically inside it should scroll
115 // the inner ScrollView first, then the outer ScrollView when reaching the
116 // bounds. Scrolling horizontally should affect the outer scroll view, but
117 // elasticity should affect only the inner ScrollView (both directions).
118 CreateScrollable();
119 scrollable_->SetBounds(0, 0, 400, 1000);
120 left->SetContents(scrollable_);
121
122 // The right scrollable is too small to scroll. The outer scroll view should
123 // always scroll, and it should get all the elasticity.
124 CreateScrollable();
125 scrollable_->SetBounds(0, 0, 100, 100);
126 right->SetContents(scrollable_);
127
128 nested_scrolls_->AddChildView(left);
129 nested_scrolls_->AddChildView(right);
95 } 130 }
96 131
97 void ScrollViewExample::ButtonPressed(Button* sender, const ui::Event& event) { 132 void ScrollViewExample::ButtonPressed(Button* sender, const ui::Event& event) {
133 if (nested_scrolls_ && sender != nested_) {
134 CreateScrollable();
135 scroll_view_->SetContents(scrollable_);
136 nested_scrolls_ = nullptr;
137 }
138
98 if (sender == wide_) { 139 if (sender == wide_) {
99 scrollable_->SetBounds(0, 0, 1000, 100); 140 scrollable_->SetBounds(0, 0, 1000, 100);
100 scrollable_->SetColor(SK_ColorYELLOW, SK_ColorCYAN); 141 scrollable_->SetColor(SK_ColorYELLOW, SK_ColorCYAN);
101 } else if (sender == tall_) { 142 } else if (sender == tall_) {
102 scrollable_->SetBounds(0, 0, 100, 1000); 143 scrollable_->SetBounds(0, 0, 100, 1000);
103 scrollable_->SetColor(SK_ColorRED, SK_ColorCYAN); 144 scrollable_->SetColor(SK_ColorRED, SK_ColorCYAN);
104 } else if (sender == big_square_) { 145 } else if (sender == big_square_) {
105 scrollable_->SetBounds(0, 0, 1000, 1000); 146 scrollable_->SetBounds(0, 0, 1000, 1000);
106 scrollable_->SetColor(SK_ColorRED, SK_ColorGREEN); 147 scrollable_->SetColor(SK_ColorRED, SK_ColorGREEN);
107 } else if (sender == small_square_) { 148 } else if (sender == small_square_) {
108 scrollable_->SetBounds(0, 0, 100, 100); 149 scrollable_->SetBounds(0, 0, 100, 100);
109 scrollable_->SetColor(SK_ColorYELLOW, SK_ColorGREEN); 150 scrollable_->SetColor(SK_ColorYELLOW, SK_ColorGREEN);
110 } else if (sender == scroll_to_) { 151 } else if (sender == scroll_to_) {
111 scroll_view_->contents()->ScrollRectToVisible( 152 scroll_view_->contents()->ScrollRectToVisible(
112 gfx::Rect(20, 500, 1000, 500)); 153 gfx::Rect(20, 500, 1000, 500));
154 } else if (sender == nested_) {
155 if (!nested_scrolls_)
156 CreateNestedScrolls();
157 scroll_view_->SetContents(nested_scrolls_);
113 } 158 }
114 scroll_view_->Layout(); 159 scroll_view_->Layout();
115 } 160 }
116 161
117 } // namespace examples 162 } // namespace examples
118 } // namespace views 163 } // namespace views
OLDNEW
« 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