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

Unified Diff: views/examples/native_widget_views_example.cc

Issue 7065042: Hook up more of the NativeWidgetViews. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 7 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « views/events/event.h ('k') | views/views.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: views/examples/native_widget_views_example.cc
===================================================================
--- views/examples/native_widget_views_example.cc (revision 86488)
+++ views/examples/native_widget_views_example.cc (working copy)
@@ -4,6 +4,8 @@
#include "views/examples/native_widget_views_example.h"
+#include "ui/gfx/canvas.h"
+#include "views/controls/button/text_button.h"
#include "views/examples/example_base.h"
#include "views/view.h"
#include "views/widget/widget.h"
@@ -11,6 +13,45 @@
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),
+ button_(new views::TextButton(this, L"Click me!")) {
sky 2011/05/24 22:32:15 ALLOW_THIS_IN_INITIALIAZER_LIST
+ 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->FillRectInt(color, 0, 0, width(), height());
+ }
+ 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) {
}
@@ -24,12 +65,13 @@
void NativeWidgetViewsExample::CreateExampleView(views::View* container) {
views::Widget* widget = new views::Widget;
- views::NativeWidgetViews* nwv = new views::NativeWidgetViews(widget);
+ views::NativeWidgetViews* nwv =
+ new views::NativeWidgetViews(container, widget);
views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL);
params.native_widget = nwv;
widget->Init(params);
- container->AddChildView(nwv->GetView());
- widget->SetBounds(gfx::Rect(10, 10, 50, 50));
+ widget->SetContentsView(new TestContentView);
+ widget->SetBounds(gfx::Rect(10, 10, 300, 150));
}
} // namespace examples
« no previous file with comments | « views/events/event.h ('k') | views/views.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698