| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 #ifndef VIEWS_EXAMPLES_SCROLL_BAR_EXAMPLE_H_ | 5 #ifndef VIEWS_EXAMPLES_SCROLL_BAR_EXAMPLE_H_ |
| 6 #define VIEWS_EXAMPLES_SCROLL_BAR_EXAMPLE_H_ | 6 #define VIEWS_EXAMPLES_SCROLL_BAR_EXAMPLE_H_ |
| 7 | 7 |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "views/controls/button/text_button.h" | 10 #include "views/controls/button/text_button.h" |
| 11 #include "views/controls/scroll_view.h" | 11 #include "views/controls/scroll_view.h" |
| 12 #include "views/examples/example_base.h" | 12 #include "views/examples/example_base.h" |
| 13 | 13 |
| 14 namespace examples { | 14 namespace examples { |
| 15 | 15 |
| 16 class ScrollViewExample : protected ExampleBase, private views::ButtonListener { | 16 class ScrollViewExample : public ExampleBase, |
| 17 public views::ButtonListener { |
| 17 public: | 18 public: |
| 18 explicit ScrollViewExample(ExamplesMain* main) : ExampleBase(main) { | 19 explicit ScrollViewExample(ExamplesMain* main): ExampleBase(main) {} |
| 20 |
| 21 virtual ~ScrollViewExample() {} |
| 22 |
| 23 virtual std::wstring GetExampleTitle() { |
| 24 return L"Scroll View"; |
| 25 } |
| 26 |
| 27 virtual void CreateExampleView(views::View* container) { |
| 19 wide_ = new views::TextButton(this, L"Wide"); | 28 wide_ = new views::TextButton(this, L"Wide"); |
| 20 tall_ = new views::TextButton(this, L"Tall"); | 29 tall_ = new views::TextButton(this, L"Tall"); |
| 21 big_square_ = new views::TextButton(this, L"Big Square"); | 30 big_square_ = new views::TextButton(this, L"Big Square"); |
| 22 small_square_ = new views::TextButton(this, L"Small Square"); | 31 small_square_ = new views::TextButton(this, L"Small Square"); |
| 23 scroll_to_ = new views::TextButton(this, L"Scroll to"); | 32 scroll_to_ = new views::TextButton(this, L"Scroll to"); |
| 24 scrollable_ = new ScrollableView(); | 33 scrollable_ = new ScrollableView(); |
| 25 scroll_view_ = new views::ScrollView(); | 34 scroll_view_ = new views::ScrollView(); |
| 26 scroll_view_->SetContents(scrollable_); | 35 scroll_view_->SetContents(scrollable_); |
| 27 scrollable_->SetBounds(0, 0, 1000, 100); | 36 scrollable_->SetBounds(0, 0, 1000, 100); |
| 28 scrollable_->SetColor(SK_ColorYELLOW, SK_ColorCYAN); | 37 scrollable_->SetColor(SK_ColorYELLOW, SK_ColorCYAN); |
| 29 | 38 |
| 30 container_ = new views::View(); | 39 views::GridLayout* layout = new views::GridLayout(container); |
| 31 views::GridLayout* layout = new views::GridLayout(container_); | 40 container->SetLayoutManager(layout); |
| 32 container_->SetLayoutManager(layout); | |
| 33 | 41 |
| 34 // Add scroll view. | 42 // Add scroll view. |
| 35 views::ColumnSet* column_set = layout->AddColumnSet(0); | 43 views::ColumnSet* column_set = layout->AddColumnSet(0); |
| 36 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, | 44 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, |
| 37 views::GridLayout::USE_PREF, 0, 0); | 45 views::GridLayout::USE_PREF, 0, 0); |
| 38 layout->StartRow(1, 0); | 46 layout->StartRow(1, 0); |
| 39 layout->AddView(scroll_view_); | 47 layout->AddView(scroll_view_); |
| 40 | 48 |
| 41 // Add control buttons. | 49 // Add control buttons. |
| 42 column_set = layout->AddColumnSet(1); | 50 column_set = layout->AddColumnSet(1); |
| 43 for (int i = 0; i < 5; i++) { | 51 for (int i = 0; i < 5; i++) { |
| 44 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, | 52 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, |
| 45 views::GridLayout::USE_PREF, 0, 0); | 53 views::GridLayout::USE_PREF, 0, 0); |
| 46 } | 54 } |
| 47 layout->StartRow(0, 1); | 55 layout->StartRow(0, 1); |
| 48 layout->AddView(wide_); | 56 layout->AddView(wide_); |
| 49 layout->AddView(tall_); | 57 layout->AddView(tall_); |
| 50 layout->AddView(big_square_); | 58 layout->AddView(big_square_); |
| 51 layout->AddView(small_square_); | 59 layout->AddView(small_square_); |
| 52 layout->AddView(scroll_to_); | 60 layout->AddView(scroll_to_); |
| 53 } | 61 } |
| 54 | 62 |
| 55 virtual ~ScrollViewExample() {} | |
| 56 | |
| 57 virtual std::wstring GetExampleTitle() { | |
| 58 return L"Scroll View"; | |
| 59 } | |
| 60 | |
| 61 virtual views::View* GetExampleView() { | |
| 62 return container_; | |
| 63 } | |
| 64 | |
| 65 private: | 63 private: |
| 66 // ScrollView's content, which draws gradient color on background. | 64 // ScrollView's content, which draws gradient color on background. |
| 67 // TODO(oshima): add child views as well. | 65 // TODO(oshima): add child views as well. |
| 68 class ScrollableView : public views::View { | 66 class ScrollableView : public views::View { |
| 69 public: | 67 public: |
| 70 ScrollableView() { | 68 ScrollableView() { |
| 71 SetColor(SK_ColorRED, SK_ColorCYAN); | 69 SetColor(SK_ColorRED, SK_ColorCYAN); |
| 72 } | 70 } |
| 73 | 71 |
| 74 gfx::Size GetPreferredSize() { | 72 gfx::Size GetPreferredSize() { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 101 scrollable_->SetColor(SK_ColorRED, SK_ColorGREEN); | 99 scrollable_->SetColor(SK_ColorRED, SK_ColorGREEN); |
| 102 } else if (sender == small_square_) { | 100 } else if (sender == small_square_) { |
| 103 scrollable_->SetBounds(0, 0, 100, 100); | 101 scrollable_->SetBounds(0, 0, 100, 100); |
| 104 scrollable_->SetColor(SK_ColorYELLOW, SK_ColorGREEN); | 102 scrollable_->SetColor(SK_ColorYELLOW, SK_ColorGREEN); |
| 105 } else if (sender == scroll_to_) { | 103 } else if (sender == scroll_to_) { |
| 106 scroll_view_->ScrollContentsRegionToBeVisible(20, 500, 1000, 500); | 104 scroll_view_->ScrollContentsRegionToBeVisible(20, 500, 1000, 500); |
| 107 } | 105 } |
| 108 scroll_view_->Layout(); | 106 scroll_view_->Layout(); |
| 109 } | 107 } |
| 110 | 108 |
| 111 // The view containing this test's controls. | |
| 112 views::View* container_; | |
| 113 | |
| 114 // Control buttons to change the size of scrollable and jump to | 109 // Control buttons to change the size of scrollable and jump to |
| 115 // predefined position. | 110 // predefined position. |
| 116 views::TextButton* wide_, *tall_, *big_square_, *small_square_, *scroll_to_; | 111 views::TextButton* wide_, *tall_, *big_square_, *small_square_, *scroll_to_; |
| 117 | 112 |
| 118 // The content of the scroll view. | 113 // The content of the scroll view. |
| 119 ScrollableView* scrollable_; | 114 ScrollableView* scrollable_; |
| 120 | 115 |
| 121 // The scroll view to test. | 116 // The scroll view to test. |
| 122 views::ScrollView* scroll_view_; | 117 views::ScrollView* scroll_view_; |
| 123 | 118 |
| 124 DISALLOW_COPY_AND_ASSIGN(ScrollViewExample); | 119 DISALLOW_COPY_AND_ASSIGN(ScrollViewExample); |
| 125 }; | 120 }; |
| 126 | 121 |
| 127 } // namespace examples | 122 } // namespace examples |
| 128 | 123 |
| 129 #endif // VIEWS_EXAMPLES_SCROLL_BAR_EXAMPLE_H_ | 124 #endif // VIEWS_EXAMPLES_SCROLL_BAR_EXAMPLE_H_ |
| 130 | 125 |
| OLD | NEW |