OLD | NEW |
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/gfx/color_utils.h" |
10 #include "ui/views/background.h" | 11 #include "ui/views/background.h" |
11 #include "ui/views/controls/button/label_button.h" | 12 #include "ui/views/controls/button/label_button.h" |
12 #include "ui/views/controls/button/radio_button.h" | 13 #include "ui/views/controls/button/radio_button.h" |
13 #include "ui/views/layout/grid_layout.h" | 14 #include "ui/views/layout/grid_layout.h" |
| 15 #include "ui/views/painter.h" |
14 #include "ui/views/view.h" | 16 #include "ui/views/view.h" |
15 | 17 |
16 using base::ASCIIToUTF16; | 18 using base::ASCIIToUTF16; |
17 | 19 |
18 namespace views { | 20 namespace views { |
19 namespace examples { | 21 namespace examples { |
20 | 22 |
21 // ScrollView's content, which draws gradient color on background. | 23 // ScrollView's content, which draws gradient color on background. |
22 // TODO(oshima): add child views as well. | 24 // TODO(oshima): add child views as well. |
23 class ScrollViewExample::ScrollableView : public View { | 25 class ScrollViewExample::ScrollableView : public View { |
24 public: | 26 public: |
25 ScrollableView() { | 27 ScrollableView() { |
26 SetColor(SK_ColorRED, SK_ColorCYAN); | 28 SetColor(SK_ColorRED, SK_ColorCYAN); |
27 AddChildView(new LabelButton(NULL, ASCIIToUTF16("Button"))); | 29 AddChildView(new LabelButton(NULL, ASCIIToUTF16("Button"))); |
28 AddChildView(new RadioButton(ASCIIToUTF16("Radio Button"), 0)); | 30 AddChildView(new RadioButton(ASCIIToUTF16("Radio Button"), 0)); |
29 } | 31 } |
30 | 32 |
31 gfx::Size GetPreferredSize() const override { | 33 gfx::Size GetPreferredSize() const override { |
32 return gfx::Size(width(), height()); | 34 return gfx::Size(width(), height()); |
33 } | 35 } |
34 | 36 |
35 void SetColor(SkColor from, SkColor to) { | 37 void SetColor(SkColor from, SkColor to) { |
36 set_background(Background::CreateVerticalGradientBackground(from, to)); | 38 Background* background = Background::CreateBackgroundPainter( |
| 39 Painter::CreateVerticalGradient(from, to)); |
| 40 background->SetNativeControlColor( |
| 41 color_utils::AlphaBlend(from, to, 128)); |
| 42 set_background(background); |
37 } | 43 } |
38 | 44 |
39 void PlaceChildY(int index, int y) { | 45 void PlaceChildY(int index, int y) { |
40 View* view = child_at(index); | 46 View* view = child_at(index); |
41 gfx::Size size = view->GetPreferredSize(); | 47 gfx::Size size = view->GetPreferredSize(); |
42 view->SetBounds(0, y, size.width(), size.height()); | 48 view->SetBounds(0, y, size.width(), size.height()); |
43 } | 49 } |
44 | 50 |
45 void Layout() override { | 51 void Layout() override { |
46 PlaceChildY(0, 0); | 52 PlaceChildY(0, 0); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 scrollable_->SetColor(SK_ColorYELLOW, SK_ColorGREEN); | 115 scrollable_->SetColor(SK_ColorYELLOW, SK_ColorGREEN); |
110 } else if (sender == scroll_to_) { | 116 } else if (sender == scroll_to_) { |
111 scroll_view_->contents()->ScrollRectToVisible( | 117 scroll_view_->contents()->ScrollRectToVisible( |
112 gfx::Rect(20, 500, 1000, 500)); | 118 gfx::Rect(20, 500, 1000, 500)); |
113 } | 119 } |
114 scroll_view_->Layout(); | 120 scroll_view_->Layout(); |
115 } | 121 } |
116 | 122 |
117 } // namespace examples | 123 } // namespace examples |
118 } // namespace views | 124 } // namespace views |
OLD | NEW |