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

Side by Side Diff: ui/views/examples/scroll_view_example.cc

Issue 2616273002: Native Themes: Add table header colors (Closed)
Patch Set: estade@'s comments Created 3 years, 11 months 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/controls/table/table_header.cc ('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"
11 #include "ui/views/controls/button/label_button.h" 11 #include "ui/views/controls/button/label_button.h"
12 #include "ui/views/controls/button/radio_button.h" 12 #include "ui/views/controls/button/radio_button.h"
13 #include "ui/views/layout/grid_layout.h" 13 #include "ui/views/layout/grid_layout.h"
14 #include "ui/views/view.h" 14 #include "ui/views/view.h"
15 15
16 using base::ASCIIToUTF16; 16 using base::ASCIIToUTF16;
17 17
18 namespace views { 18 namespace views {
19 namespace examples { 19 namespace examples {
20 20
21 // ScrollView's content, which draws gradient color on background. 21 // ScrollView's content, which draws gradient color on background.
Evan Stade 2017/01/20 20:00:18 nit: this is no longer accurate. Is the example s
Tom (Use chromium acct) 2017/01/20 20:18:15 I've added the gradients back, so this should no l
22 // TODO(oshima): add child views as well. 22 // TODO(oshima): add child views as well.
23 class ScrollViewExample::ScrollableView : public View { 23 class ScrollViewExample::ScrollableView : public View {
24 public: 24 public:
25 ScrollableView() { 25 ScrollableView() {
26 SetColor(SK_ColorRED, SK_ColorCYAN); 26 SetColor(SK_ColorRED);
27 AddChildView(new LabelButton(NULL, ASCIIToUTF16("Button"))); 27 AddChildView(new LabelButton(NULL, ASCIIToUTF16("Button")));
28 AddChildView(new RadioButton(ASCIIToUTF16("Radio Button"), 0)); 28 AddChildView(new RadioButton(ASCIIToUTF16("Radio Button"), 0));
29 } 29 }
30 30
31 gfx::Size GetPreferredSize() const override { 31 gfx::Size GetPreferredSize() const override {
32 return gfx::Size(width(), height()); 32 return gfx::Size(width(), height());
33 } 33 }
34 34
35 void SetColor(SkColor from, SkColor to) { 35 void SetColor(SkColor color) {
36 set_background(Background::CreateVerticalGradientBackground(from, to)); 36 set_background(Background::CreateSolidBackground(color));
37 } 37 }
38 38
39 void PlaceChildY(int index, int y) { 39 void PlaceChildY(int index, int y) {
40 View* view = child_at(index); 40 View* view = child_at(index);
41 gfx::Size size = view->GetPreferredSize(); 41 gfx::Size size = view->GetPreferredSize();
42 view->SetBounds(0, y, size.width(), size.height()); 42 view->SetBounds(0, y, size.width(), size.height());
43 } 43 }
44 44
45 void Layout() override { 45 void Layout() override {
46 PlaceChildY(0, 0); 46 PlaceChildY(0, 0);
(...skipping 14 matching lines...) Expand all
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 scrollable_ = new ScrollableView();
68 scroll_view_ = new ScrollView(); 68 scroll_view_ = new ScrollView();
69 scroll_view_->SetContents(scrollable_); 69 scroll_view_->SetContents(scrollable_);
70 scrollable_->SetBounds(0, 0, 1000, 100); 70 scrollable_->SetBounds(0, 0, 1000, 100);
71 scrollable_->SetColor(SK_ColorYELLOW, SK_ColorCYAN); 71 scrollable_->SetColor(SK_ColorYELLOW);
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 < 5; 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 } 95 }
96 96
97 void ScrollViewExample::ButtonPressed(Button* sender, const ui::Event& event) { 97 void ScrollViewExample::ButtonPressed(Button* sender, const ui::Event& event) {
98 if (sender == wide_) { 98 if (sender == wide_) {
99 scrollable_->SetBounds(0, 0, 1000, 100); 99 scrollable_->SetBounds(0, 0, 1000, 100);
100 scrollable_->SetColor(SK_ColorYELLOW, SK_ColorCYAN); 100 scrollable_->SetColor(SK_ColorYELLOW);
101 } else if (sender == tall_) { 101 } else if (sender == tall_) {
102 scrollable_->SetBounds(0, 0, 100, 1000); 102 scrollable_->SetBounds(0, 0, 100, 1000);
103 scrollable_->SetColor(SK_ColorRED, SK_ColorCYAN); 103 scrollable_->SetColor(SK_ColorRED);
104 } else if (sender == big_square_) { 104 } else if (sender == big_square_) {
105 scrollable_->SetBounds(0, 0, 1000, 1000); 105 scrollable_->SetBounds(0, 0, 1000, 1000);
106 scrollable_->SetColor(SK_ColorRED, SK_ColorGREEN); 106 scrollable_->SetColor(SK_ColorCYAN);
107 } else if (sender == small_square_) { 107 } else if (sender == small_square_) {
108 scrollable_->SetBounds(0, 0, 100, 100); 108 scrollable_->SetBounds(0, 0, 100, 100);
109 scrollable_->SetColor(SK_ColorYELLOW, SK_ColorGREEN); 109 scrollable_->SetColor(SK_ColorGREEN);
110 } else if (sender == scroll_to_) { 110 } else if (sender == scroll_to_) {
111 scroll_view_->contents()->ScrollRectToVisible( 111 scroll_view_->contents()->ScrollRectToVisible(
112 gfx::Rect(20, 500, 1000, 500)); 112 gfx::Rect(20, 500, 1000, 500));
113 } 113 }
114 scroll_view_->Layout(); 114 scroll_view_->Layout();
115 } 115 }
116 116
117 } // namespace examples 117 } // namespace examples
118 } // namespace views 118 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/table/table_header.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698