Commit 65fffb56 authored by ben@chromium.org's avatar ben@chromium.org

Hook up more of the NativeWidgetViews.

- Move NativeWidgetView to its own file.
- Enhances the example to contain a button.

http://crbug.com/83663
TEST=none
Review URL: http://codereview.chromium.org/7065042

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@86527 0039d316-1c4b-4281-b951-d872f2087c98
parent 09733b45
......@@ -27,6 +27,7 @@ namespace views {
class View;
namespace internal {
class NativeWidgetView;
class RootView;
}
......@@ -234,6 +235,7 @@ class MouseEvent : public LocatedEvent {
}
private:
friend class internal::NativeWidgetView;
friend class internal::RootView;
DISALLOW_COPY_AND_ASSIGN(MouseEvent);
......@@ -377,6 +379,7 @@ class MouseWheelEvent : public MouseEvent {
private:
friend class internal::RootView;
friend class internal::NativeWidgetView;
MouseWheelEvent(const MouseWheelEvent& model, View* root)
: MouseEvent(model, root),
......
......@@ -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,46 @@
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, L"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->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 +66,13 @@ std::wstring NativeWidgetViewsExample::GetExampleTitle() {
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
......@@ -362,6 +362,8 @@
'widget/native_widget_delegate.h',
'widget/native_widget_gtk.cc',
'widget/native_widget_gtk.h',
'widget/native_widget_view.cc',
'widget/native_widget_view.h',
'widget/native_widget_views.cc',
'widget/native_widget_views.h',
'widget/native_widget_win.cc',
......
// 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 "views/widget/native_widget_view.h"
#include "ui/gfx/canvas.h"
namespace views {
namespace internal {
////////////////////////////////////////////////////////////////////////////////
// NativeWidgetView, public:
NativeWidgetView::NativeWidgetView(NativeWidgetViews* native_widget)
: native_widget_(native_widget) {
}
NativeWidgetView::~NativeWidgetView() {
}
////////////////////////////////////////////////////////////////////////////////
// NativeWidgetView, View overrides:
void NativeWidgetView::ViewHierarchyChanged(bool is_add, View* parent,
View* child) {
if (is_add && child == this)
delegate()->OnNativeWidgetCreated();
}
void NativeWidgetView::OnBoundsChanged(const gfx::Rect& previous_bounds) {
delegate()->OnSizeChanged(size());
}
void NativeWidgetView::OnPaint(gfx::Canvas* canvas) {
canvas->FillRectInt(SK_ColorRED, 0, 0, width(), height());
delegate()->OnNativeWidgetPaint(canvas);
}
bool NativeWidgetView::OnMousePressed(const MouseEvent& event) {
MouseEvent e(event, this);
return delegate()->OnMouseEvent(event);
}
bool NativeWidgetView::OnMouseDragged(const MouseEvent& event) {
MouseEvent e(event, this);
return delegate()->OnMouseEvent(event);
}
void NativeWidgetView::OnMouseReleased(const MouseEvent& event) {
MouseEvent e(event, this);
delegate()->OnMouseEvent(event);
}
void NativeWidgetView::OnMouseCaptureLost() {
delegate()->OnMouseCaptureLost();
}
void NativeWidgetView::OnMouseMoved(const MouseEvent& event) {
MouseEvent e(event, this);
delegate()->OnMouseEvent(event);
}
void NativeWidgetView::OnMouseEntered(const MouseEvent& event) {
MouseEvent e(event, this);
delegate()->OnMouseEvent(event);
}
void NativeWidgetView::OnMouseExited(const MouseEvent& event) {
MouseEvent e(event, this);
delegate()->OnMouseEvent(event);
}
#if defined(TOUCH_UI)
View::TouchStatus NativeWidgetView::OnTouchEvent(const TouchEvent& event) {
NOTIMPLEMENTED();
// TODO(beng): TouchEvents don't go through the Widget right now... so we
// can't just pass them to the delegate...
return TOUCH_STATUS_UNKNOWN;
}
#endif
bool NativeWidgetView::OnKeyPressed(const KeyEvent& event) {
return delegate()->OnKeyEvent(event);
}
bool NativeWidgetView::OnKeyReleased(const KeyEvent& event) {
return delegate()->OnKeyEvent(event);
}
bool NativeWidgetView::OnMouseWheel(const MouseWheelEvent& event) {
MouseWheelEvent e(event, this);
return delegate()->OnMouseEvent(event);
}
void NativeWidgetView::OnFocus() {
// TODO(beng): check if we have to do this.
//delegate()->OnNativeFocus(NULL);
}
void NativeWidgetView::OnBlur() {
// TODO(beng): check if we have to do this.
//delegate()->OnNativeBlur(NULL);
}
} // namespace internal
} // namespace views
// 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.
#ifndef VIEWS_WIDGET_NATIVE_WIDGET_VIEW_H_
#define VIEWS_WIDGET_NATIVE_WIDGET_VIEW_H_
#pragma once
#include "views/view.h"
#include "views/widget/native_widget_delegate.h"
#include "views/widget/native_widget_views.h"
namespace views {
class NativeWidgetViews;
namespace internal {
////////////////////////////////////////////////////////////////////////////////
// NativeWidgetView
//
// This class represents the View that is the "native view" for a
// NativeWidgetViews. It is the View that is a member of the parent Widget's
// View hierarchy. It is responsible for receiving relevant events from that
// hierarchy and forwarding them to its NativeWidgetViews' delegate's hierarchy.
//
class NativeWidgetView : public View {
public:
explicit NativeWidgetView(NativeWidgetViews* native_widget);
virtual ~NativeWidgetView();
private:
// Overridden from View:
virtual void ViewHierarchyChanged(bool is_add,
View* parent,
View* child) OVERRIDE;
virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE;
virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
virtual bool OnMousePressed(const MouseEvent& event) OVERRIDE;
virtual bool OnMouseDragged(const MouseEvent& event) OVERRIDE;
virtual void OnMouseReleased(const MouseEvent& event) OVERRIDE;
virtual void OnMouseCaptureLost() OVERRIDE;
virtual void OnMouseMoved(const MouseEvent& event) OVERRIDE;
virtual void OnMouseEntered(const MouseEvent& event) OVERRIDE;
virtual void OnMouseExited(const MouseEvent& event) OVERRIDE;
#if defined(TOUCH_UI)
virtual TouchStatus OnTouchEvent(const TouchEvent& event) OVERRIDE;
#endif
virtual bool OnKeyPressed(const KeyEvent& event) OVERRIDE;
virtual bool OnKeyReleased(const KeyEvent& event) OVERRIDE;
virtual bool OnMouseWheel(const MouseWheelEvent& event) OVERRIDE;
virtual void OnFocus() OVERRIDE;
virtual void OnBlur() OVERRIDE;
internal::NativeWidgetDelegate* delegate() {
return native_widget_->delegate();
}
NativeWidgetViews* native_widget_;
DISALLOW_COPY_AND_ASSIGN(NativeWidgetView);
};
} // namespace internal
} // namespace views
#endif // VIEWS_WIDGET_NATIVE_WIDGET_VIEW_H_
......@@ -4,34 +4,19 @@
#include "views/widget/native_widget_views.h"
#include "ui/gfx/canvas.h"
#include "views/view.h"
#include "views/widget/native_widget_view.h"
namespace views {
////////////////////////////////////////////////////////////////////////////////
// NativeWidgetViews::NativeWidgetView:
class NativeWidgetViews::NativeWidgetView : public View {
public:
NativeWidgetView() {}
virtual ~NativeWidgetView() {}
// Overridden from View:
virtual void OnPaint(gfx::Canvas* canvas) {
canvas->FillRectInt(SK_ColorRED, 0, 0, width(), height());
}
private:
DISALLOW_COPY_AND_ASSIGN(NativeWidgetView);
};
////////////////////////////////////////////////////////////////////////////////
// NativeWidgetViews, public:
NativeWidgetViews::NativeWidgetViews(internal::NativeWidgetDelegate* delegate)
NativeWidgetViews::NativeWidgetViews(View* host,
internal::NativeWidgetDelegate* delegate)
: delegate_(delegate),
view_(NULL),
host_view_(host),
ALLOW_THIS_IN_INITIALIZER_LIST(close_widget_factory_(this)) {
}
......@@ -46,7 +31,8 @@ View* NativeWidgetViews::GetView() {
// NativeWidgetViews, NativeWidget implementation:
void NativeWidgetViews::InitNativeWidget(const Widget::InitParams& params) {
view_ = new NativeWidgetView;
view_ = new internal::NativeWidgetView(this);
host_view_->AddChildView(view_);
// TODO(beng): handle parenting.
// TODO(beng): SetInitParams().
......
......@@ -2,26 +2,34 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef VIEWS_WIDGET_NATIVE_WIDGET_WIN_H_
#define VIEWS_WIDGET_NATIVE_WIDGET_WIN_H_
#ifndef VIEWS_WIDGET_NATIVE_WIDGET_VIEWS_H_
#define VIEWS_WIDGET_NATIVE_WIDGET_VIEWS_H_
#pragma once
#include "base/message_loop.h"
#include "views/widget/native_widget.h"
namespace views {
namespace internal {
class NativeWidgetView;
}
////////////////////////////////////////////////////////////////////////////////
// NativeWidgetViews
//
// A NativeWidget implementation that uses another View as its native widget.
//
class NativeWidgetViews : public NativeWidget {
public:
explicit NativeWidgetViews(internal::NativeWidgetDelegate* delegate);
NativeWidgetViews(View* host, internal::NativeWidgetDelegate* delegate);
virtual ~NativeWidgetViews();
// TODO(beng): remove.
View* GetView();
private:
class NativeWidgetView;
internal::NativeWidgetDelegate* delegate() { return delegate_; }
private:
// Overridden from NativeWidget:
virtual void InitNativeWidget(const Widget::InitParams& params) OVERRIDE;
virtual Widget* GetWidget() OVERRIDE;
......@@ -72,7 +80,9 @@ class NativeWidgetViews : public NativeWidget {
internal::NativeWidgetDelegate* delegate_;
NativeWidgetView* view_;
internal::NativeWidgetView* view_;
View* host_view_;
// The following factory is used for calls to close the NativeWidgetViews
// instance.
......@@ -83,4 +93,4 @@ class NativeWidgetViews : public NativeWidget {
}
#endif // VIEWS_WIDGET_NATIVE_WIDGET_WIN_H_
#endif // VIEWS_WIDGET_NATIVE_WIDGET_VIEWS_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment