Chromium Code Reviews| 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 "views/examples/native_widget_views_example.h" | 5 #include "views/examples/native_widget_views_example.h" |
| 6 | 6 |
| 7 #include "ui/gfx/canvas.h" | |
| 8 #include "views/controls/button/text_button.h" | |
| 7 #include "views/examples/example_base.h" | 9 #include "views/examples/example_base.h" |
| 8 #include "views/view.h" | 10 #include "views/view.h" |
| 9 #include "views/widget/widget.h" | 11 #include "views/widget/widget.h" |
| 10 #include "views/widget/native_widget_views.h" | 12 #include "views/widget/native_widget_views.h" |
| 11 | 13 |
| 12 namespace examples { | 14 namespace examples { |
| 13 | 15 |
| 16 // A ContentView for our example widget. Contains a variety of controls for | |
| 17 // testing NativeWidgetViews event handling. If any part of the Widget's bounds | |
| 18 // are rendered red, something went wrong. | |
| 19 class TestContentView : public views::View, | |
| 20 public views::ButtonListener { | |
| 21 public: | |
| 22 TestContentView() | |
| 23 : click_count_(0), | |
| 24 button_(new views::TextButton(this, L"Click me!")) { | |
|
sky
2011/05/24 22:32:15
ALLOW_THIS_IN_INITIALIAZER_LIST
| |
| 25 AddChildView(button_); | |
| 26 } | |
| 27 virtual ~TestContentView() { | |
| 28 } | |
| 29 | |
| 30 // Overridden from views::View: | |
| 31 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { | |
| 32 SkColor color = click_count_ % 2 == 0 ? SK_ColorGREEN : SK_ColorBLUE; | |
| 33 canvas->FillRectInt(color, 0, 0, width(), height()); | |
| 34 } | |
| 35 virtual void Layout() OVERRIDE { | |
| 36 button_->SetBounds(10, 10, width() - 20, height() - 20); | |
| 37 } | |
| 38 | |
| 39 // Overridden from views::ButtonListener: | |
| 40 virtual void ButtonPressed(views::Button* sender, | |
| 41 const views::Event& event) OVERRIDE { | |
| 42 if (sender == button_) { | |
| 43 ++click_count_; | |
| 44 SchedulePaint(); | |
| 45 } | |
| 46 } | |
| 47 | |
| 48 private: | |
| 49 int click_count_; | |
| 50 views::TextButton* button_; | |
| 51 | |
| 52 DISALLOW_COPY_AND_ASSIGN(TestContentView); | |
| 53 }; | |
| 54 | |
| 14 NativeWidgetViewsExample::NativeWidgetViewsExample(ExamplesMain* main) | 55 NativeWidgetViewsExample::NativeWidgetViewsExample(ExamplesMain* main) |
| 15 : ExampleBase(main) { | 56 : ExampleBase(main) { |
| 16 } | 57 } |
| 17 | 58 |
| 18 NativeWidgetViewsExample::~NativeWidgetViewsExample() { | 59 NativeWidgetViewsExample::~NativeWidgetViewsExample() { |
| 19 } | 60 } |
| 20 | 61 |
| 21 std::wstring NativeWidgetViewsExample::GetExampleTitle() { | 62 std::wstring NativeWidgetViewsExample::GetExampleTitle() { |
| 22 return L"NativeWidgetViews"; | 63 return L"NativeWidgetViews"; |
| 23 } | 64 } |
| 24 | 65 |
| 25 void NativeWidgetViewsExample::CreateExampleView(views::View* container) { | 66 void NativeWidgetViewsExample::CreateExampleView(views::View* container) { |
| 26 views::Widget* widget = new views::Widget; | 67 views::Widget* widget = new views::Widget; |
| 27 views::NativeWidgetViews* nwv = new views::NativeWidgetViews(widget); | 68 views::NativeWidgetViews* nwv = |
| 69 new views::NativeWidgetViews(container, widget); | |
| 28 views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL); | 70 views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL); |
| 29 params.native_widget = nwv; | 71 params.native_widget = nwv; |
| 30 widget->Init(params); | 72 widget->Init(params); |
| 31 container->AddChildView(nwv->GetView()); | 73 widget->SetContentsView(new TestContentView); |
| 32 widget->SetBounds(gfx::Rect(10, 10, 50, 50)); | 74 widget->SetBounds(gfx::Rect(10, 10, 300, 150)); |
| 33 } | 75 } |
| 34 | 76 |
| 35 } // namespace examples | 77 } // namespace examples |
| OLD | NEW |