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

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

Issue 8762012: Removing example code related to deprecated NativeWidgetViews. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years 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 | Annotate | Revision Log
« no previous file with comments | « ui/views/examples/native_widget_views_example.h ('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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ui/views/examples/native_widget_views_example.h"
6
7 #include "base/utf_string_conversions.h"
8 #include "ui/gfx/canvas.h"
9 #include "ui/views/controls/button/text_button.h"
10 #include "ui/views/examples/example_base.h"
11 #include "ui/views/test/test_views_delegate.h"
12 #include "ui/views/view.h"
13 #include "ui/views/widget/native_widget_views.h"
14 #include "ui/views/widget/widget.h"
15
16 namespace examples {
17
18 // A ContentView for our example widget. Contains a variety of controls for
19 // testing NativeWidgetViews event handling. If any part of the Widget's bounds
20 // are rendered red, something went wrong.
21 class TestContentView : public views::View,
22 public views::ButtonListener {
23 public:
24 TestContentView()
25 : click_count_(0),
26 ALLOW_THIS_IN_INITIALIZER_LIST(
27 button_(new views::TextButton(this, ASCIIToUTF16("Click me!")))) {
28 AddChildView(button_);
29 }
30 virtual ~TestContentView() {
31 }
32
33 // Overridden from views::View:
34 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {
35 SkColor color = click_count_ % 2 == 0 ? SK_ColorGREEN : SK_ColorBLUE;
36 canvas->FillRect(color, GetLocalBounds());
37 }
38 virtual void Layout() OVERRIDE {
39 button_->SetBounds(10, 10, width() - 20, height() - 20);
40 }
41
42 // Overridden from views::ButtonListener:
43 virtual void ButtonPressed(views::Button* sender,
44 const views::Event& event) OVERRIDE {
45 if (sender == button_) {
46 ++click_count_;
47 SchedulePaint();
48 }
49 }
50
51 private:
52 int click_count_;
53 views::TextButton* button_;
54
55 DISALLOW_COPY_AND_ASSIGN(TestContentView);
56 };
57
58 NativeWidgetViewsExample::NativeWidgetViewsExample(ExamplesMain* main)
59 : ExampleBase(main, "Native Widget Views") {
60 }
61
62 NativeWidgetViewsExample::~NativeWidgetViewsExample() {
63 }
64
65 void NativeWidgetViewsExample::CreateExampleView(views::View* container) {
66 views::Widget* widget = new views::Widget;
67 views::NativeWidgetViews* nwv = new views::NativeWidgetViews(widget);
68 views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL);
69
70 // Set parent View for widget. Real code should use params.parent_widget
71 // but since tabs are implemented with Views instead of Widgets on Windows
72 // we have to hack the parenting.
73 #if defined(OS_WIN)
74 views::TestViewsDelegate* test_views_delegate =
75 static_cast<views::TestViewsDelegate*>(
76 views::ViewsDelegate::views_delegate);
77 views::View* old_default_parent_view =
78 test_views_delegate->GetDefaultParentView();
79 test_views_delegate->set_default_parent_view(container);
80 #else
81 params.parent_widget = container->GetWidget();
82 #endif
83
84 params.native_widget = nwv;
85 widget->Init(params);
86
87 #if defined(OS_WIN)
88 test_views_delegate->set_default_parent_view(old_default_parent_view);
89 #endif
90
91 widget->SetContentsView(new TestContentView);
92 widget->SetBounds(gfx::Rect(10, 10, 300, 150));
93 }
94
95 } // namespace examples
OLDNEW
« no previous file with comments | « ui/views/examples/native_widget_views_example.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698