summaryrefslogtreecommitdiffstats
path: root/ui/views/examples/native_widget_views_example.cc
diff options
context:
space:
mode:
authortfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-15 02:56:30 +0000
committertfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-15 02:56:30 +0000
commit75b985094ca3603b5d566227a3dc2d0b62fcf51c (patch)
tree23e30d8df3b4527c80a56fc9eb61cd67c43e5677 /ui/views/examples/native_widget_views_example.cc
parente5c49f5cb6e52f3d3f23f6f514421d3247d4c01b (diff)
downloadchromium_src-75b985094ca3603b5d566227a3dc2d0b62fcf51c.zip
chromium_src-75b985094ca3603b5d566227a3dc2d0b62fcf51c.tar.gz
chromium_src-75b985094ca3603b5d566227a3dc2d0b62fcf51c.tar.bz2
views: Move examples/ directory to ui/views/.
BUG=104039 R=ben@chromium.org Review URL: http://codereview.chromium.org/8555013 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@110023 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/views/examples/native_widget_views_example.cc')
-rw-r--r--ui/views/examples/native_widget_views_example.cc95
1 files changed, 95 insertions, 0 deletions
diff --git a/ui/views/examples/native_widget_views_example.cc b/ui/views/examples/native_widget_views_example.cc
new file mode 100644
index 0000000..0e00035
--- /dev/null
+++ b/ui/views/examples/native_widget_views_example.cc
@@ -0,0 +1,95 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ui/views/examples/native_widget_views_example.h"
+
+#include "base/utf_string_conversions.h"
+#include "ui/gfx/canvas.h"
+#include "ui/views/examples/example_base.h"
+#include "views/controls/button/text_button.h"
+#include "views/test/test_views_delegate.h"
+#include "views/view.h"
+#include "views/widget/native_widget_views.h"
+#include "views/widget/widget.h"
+
+namespace examples {
+
+// A ContentView for our example widget. Contains a variety of controls for
+// testing NativeWidgetViews event handling. If any part of the Widget's bounds
+// are rendered red, something went wrong.
+class TestContentView : public views::View,
+ public views::ButtonListener {
+ public:
+ TestContentView()
+ : click_count_(0),
+ ALLOW_THIS_IN_INITIALIZER_LIST(
+ button_(new views::TextButton(this, ASCIIToUTF16("Click me!")))) {
+ AddChildView(button_);
+ }
+ virtual ~TestContentView() {
+ }
+
+ // Overridden from views::View:
+ virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {
+ SkColor color = click_count_ % 2 == 0 ? SK_ColorGREEN : SK_ColorBLUE;
+ canvas->FillRect(color, GetLocalBounds());
+ }
+ virtual void Layout() OVERRIDE {
+ button_->SetBounds(10, 10, width() - 20, height() - 20);
+ }
+
+ // Overridden from views::ButtonListener:
+ virtual void ButtonPressed(views::Button* sender,
+ const views::Event& event) OVERRIDE {
+ if (sender == button_) {
+ ++click_count_;
+ SchedulePaint();
+ }
+ }
+
+ private:
+ int click_count_;
+ views::TextButton* button_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestContentView);
+};
+
+NativeWidgetViewsExample::NativeWidgetViewsExample(ExamplesMain* main)
+ : ExampleBase(main, "Native Widget Views") {
+}
+
+NativeWidgetViewsExample::~NativeWidgetViewsExample() {
+}
+
+void NativeWidgetViewsExample::CreateExampleView(views::View* container) {
+ views::Widget* widget = new views::Widget;
+ views::NativeWidgetViews* nwv = new views::NativeWidgetViews(widget);
+ views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL);
+
+ // Set parent View for widget. Real code should use params.parent_widget
+ // but since tabs are implemented with Views instead of Widgets on Windows
+ // we have to hack the parenting.
+#if defined(OS_WIN)
+ views::TestViewsDelegate* test_views_delegate =
+ static_cast<views::TestViewsDelegate*>(
+ views::ViewsDelegate::views_delegate);
+ views::View* old_default_parent_view =
+ test_views_delegate->GetDefaultParentView();
+ test_views_delegate->set_default_parent_view(container);
+#else
+ params.parent_widget = container->GetWidget();
+#endif
+
+ params.native_widget = nwv;
+ widget->Init(params);
+
+#if defined(OS_WIN)
+ test_views_delegate->set_default_parent_view(old_default_parent_view);
+#endif
+
+ widget->SetContentsView(new TestContentView);
+ widget->SetBounds(gfx::Rect(10, 10, 300, 150));
+}
+
+} // namespace examples