summaryrefslogtreecommitdiffstats
path: root/views
diff options
context:
space:
mode:
authorben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-24 21:02:28 +0000
committerben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-24 21:02:28 +0000
commit244f6db2673d9bee139a2f1738ade5a0e729b208 (patch)
tree85ef99866735ff67091d8ab3651d1fd0e31c3a49 /views
parent35e251d043bf98206b75b3065841bf25c21d7fcc (diff)
downloadchromium_src-244f6db2673d9bee139a2f1738ade5a0e729b208.zip
chromium_src-244f6db2673d9bee139a2f1738ade5a0e729b208.tar.gz
chromium_src-244f6db2673d9bee139a2f1738ade5a0e729b208.tar.bz2
Add NativeWidgetViews. This is a stub implementation that mostly just defers to its parent NativeWidget.
http://crbug.com/83663 TEST=none Review URL: http://codereview.chromium.org/6990048 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@86488 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
-rw-r--r--views/examples/examples_main.cc5
-rw-r--r--views/examples/native_widget_views_example.cc35
-rw-r--r--views/examples/native_widget_views_example.h32
-rw-r--r--views/views.gyp4
-rw-r--r--views/widget/native_widget.h1
-rw-r--r--views/widget/native_widget_views.cc236
-rw-r--r--views/widget/native_widget_views.h86
7 files changed, 399 insertions, 0 deletions
diff --git a/views/examples/examples_main.cc b/views/examples/examples_main.cc
index 1c28b42..be25458 100644
--- a/views/examples/examples_main.cc
+++ b/views/examples/examples_main.cc
@@ -21,6 +21,7 @@
#include "views/examples/message_box_example.h"
#include "views/examples/native_theme_button_example.h"
#include "views/examples/native_theme_checkbox_example.h"
+#include "views/examples/native_widget_views_example.h"
#include "views/examples/radio_button_example.h"
#include "views/examples/scroll_view_example.h"
#include "views/examples/single_split_view_example.h"
@@ -110,6 +111,10 @@ void ExamplesMain::Run() {
tabbed_pane->AddTab(native_theme_button_example.GetExampleTitle(),
native_theme_button_example.GetExampleView());
+ examples::NativeWidgetViewsExample native_widget_views_example(this);
+ tabbed_pane->AddTab(native_widget_views_example.GetExampleTitle(),
+ native_widget_views_example.GetExampleView());
+
examples::TextfieldExample textfield_example(this);
tabbed_pane->AddTab(textfield_example.GetExampleTitle(),
textfield_example.GetExampleView());
diff --git a/views/examples/native_widget_views_example.cc b/views/examples/native_widget_views_example.cc
new file mode 100644
index 0000000..f02b3e1
--- /dev/null
+++ b/views/examples/native_widget_views_example.cc
@@ -0,0 +1,35 @@
+// 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/examples/native_widget_views_example.h"
+
+#include "views/examples/example_base.h"
+#include "views/view.h"
+#include "views/widget/widget.h"
+#include "views/widget/native_widget_views.h"
+
+namespace examples {
+
+NativeWidgetViewsExample::NativeWidgetViewsExample(ExamplesMain* main)
+ : ExampleBase(main) {
+}
+
+NativeWidgetViewsExample::~NativeWidgetViewsExample() {
+}
+
+std::wstring NativeWidgetViewsExample::GetExampleTitle() {
+ return L"NativeWidgetViews";
+}
+
+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);
+ params.native_widget = nwv;
+ widget->Init(params);
+ container->AddChildView(nwv->GetView());
+ widget->SetBounds(gfx::Rect(10, 10, 50, 50));
+}
+
+} // namespace examples
diff --git a/views/examples/native_widget_views_example.h b/views/examples/native_widget_views_example.h
new file mode 100644
index 0000000..b3d8b96
--- /dev/null
+++ b/views/examples/native_widget_views_example.h
@@ -0,0 +1,32 @@
+// 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_EXAMPLES_NATIVE_WIDGET_VIEWS_EXAMPLE_H_
+#define VIEWS_EXAMPLES_NATIVE_WIDGET_VIEWS_EXAMPLE_H_
+#pragma once
+
+#include <string>
+
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "views/examples/example_base.h"
+
+namespace examples {
+
+class NativeWidgetViewsExample : public ExampleBase {
+ public:
+ explicit NativeWidgetViewsExample(ExamplesMain* main);
+ virtual ~NativeWidgetViewsExample();
+
+ // Overridden from ExampleBase:
+ virtual std::wstring GetExampleTitle() OVERRIDE;
+ virtual void CreateExampleView(views::View* container) OVERRIDE;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(NativeWidgetViewsExample);
+};
+
+} // namespace examples
+
+#endif // VIEWS_EXAMPLES_NATIVE_WIDGET_VIEWS_EXAMPLE_H_
diff --git a/views/views.gyp b/views/views.gyp
index 2176bb2..d3f4272 100644
--- a/views/views.gyp
+++ b/views/views.gyp
@@ -362,6 +362,8 @@
'widget/native_widget_delegate.h',
'widget/native_widget_gtk.cc',
'widget/native_widget_gtk.h',
+ 'widget/native_widget_views.cc',
+ 'widget/native_widget_views.h',
'widget/native_widget_win.cc',
'widget/native_widget_win.h',
'widget/widget.cc',
@@ -576,6 +578,8 @@
'examples/native_theme_button_example.h',
'examples/native_theme_checkbox_example.cc',
'examples/native_theme_checkbox_example.h',
+ 'examples/native_widget_views_example.cc',
+ 'examples/native_widget_views_example.h',
'examples/radio_button_example.cc',
'examples/radio_button_example.h',
'examples/scroll_view_example.cc',
diff --git a/views/widget/native_widget.h b/views/widget/native_widget.h
index c672044..2f12fbd 100644
--- a/views/widget/native_widget.h
+++ b/views/widget/native_widget.h
@@ -124,6 +124,7 @@ class NativeWidget {
protected:
friend class Widget;
+ friend class NativeWidgetViews;
// Returns a handle for the underlying native widget that can be used for
// accelerated drawing.
diff --git a/views/widget/native_widget_views.cc b/views/widget/native_widget_views.cc
new file mode 100644
index 0000000..5928f36
--- /dev/null
+++ b/views/widget/native_widget_views.cc
@@ -0,0 +1,236 @@
+// 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_views.h"
+
+#include "ui/gfx/canvas.h"
+#include "views/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)
+ : delegate_(delegate),
+ view_(NULL),
+ ALLOW_THIS_IN_INITIALIZER_LIST(close_widget_factory_(this)) {
+}
+
+NativeWidgetViews::~NativeWidgetViews() {
+}
+
+View* NativeWidgetViews::GetView() {
+ return view_;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// NativeWidgetViews, NativeWidget implementation:
+
+void NativeWidgetViews::InitNativeWidget(const Widget::InitParams& params) {
+ view_ = new NativeWidgetView;
+
+ // TODO(beng): handle parenting.
+ // TODO(beng): SetInitParams().
+}
+
+Widget* NativeWidgetViews::GetWidget() {
+ return delegate_->AsWidget();
+}
+
+const Widget* NativeWidgetViews::GetWidget() const {
+ return delegate_->AsWidget();
+}
+
+gfx::NativeView NativeWidgetViews::GetNativeView() const {
+ return GetParentNativeWidget()->GetNativeView();
+}
+
+gfx::NativeWindow NativeWidgetViews::GetNativeWindow() const {
+ return GetParentNativeWidget()->GetNativeWindow();
+}
+
+Window* NativeWidgetViews::GetContainingWindow() {
+ return view_->GetWindow();
+}
+
+const Window* NativeWidgetViews::GetContainingWindow() const {
+ return view_->GetWindow();
+}
+
+void NativeWidgetViews::ViewRemoved(View* view) {
+ return GetParentNativeWidget()->ViewRemoved(view);
+}
+
+void NativeWidgetViews::SetNativeWindowProperty(const char* name, void* value) {
+ NOTIMPLEMENTED();
+}
+
+void* NativeWidgetViews::GetNativeWindowProperty(const char* name) {
+ NOTIMPLEMENTED();
+ return NULL;
+}
+
+TooltipManager* NativeWidgetViews::GetTooltipManager() const {
+ return GetParentNativeWidget()->GetTooltipManager();
+}
+
+bool NativeWidgetViews::IsScreenReaderActive() const {
+ return GetParentNativeWidget()->IsScreenReaderActive();
+}
+
+void NativeWidgetViews::SendNativeAccessibilityEvent(
+ View* view,
+ ui::AccessibilityTypes::Event event_type) {
+ return GetParentNativeWidget()->SendNativeAccessibilityEvent(view,
+ event_type);
+}
+
+void NativeWidgetViews::SetMouseCapture() {
+ GetParentNativeWidget()->SetMouseCapture();
+}
+
+void NativeWidgetViews::ReleaseMouseCapture() {
+ GetParentNativeWidget()->ReleaseMouseCapture();
+}
+
+bool NativeWidgetViews::HasMouseCapture() const {
+ return GetParentNativeWidget()->HasMouseCapture();
+}
+
+bool NativeWidgetViews::IsMouseButtonDown() const {
+ return GetParentNativeWidget()->IsMouseButtonDown();
+}
+
+InputMethod* NativeWidgetViews::GetInputMethodNative() {
+ return GetParentNativeWidget()->GetInputMethodNative();
+}
+
+void NativeWidgetViews::ReplaceInputMethod(InputMethod* input_method) {
+ GetParentNativeWidget()->ReplaceInputMethod(input_method);
+}
+
+gfx::AcceleratedWidget NativeWidgetViews::GetAcceleratedWidget() {
+ // TODO(sky):
+ return gfx::kNullAcceleratedWidget;
+}
+
+gfx::Rect NativeWidgetViews::GetWindowScreenBounds() const {
+ gfx::Point origin = view_->bounds().origin();
+ View::ConvertPointToScreen(view_->parent(), &origin);
+ return gfx::Rect(origin.x(), origin.y(), view_->width(), view_->height());
+}
+
+gfx::Rect NativeWidgetViews::GetClientAreaScreenBounds() const {
+ return GetWindowScreenBounds();
+}
+
+void NativeWidgetViews::SetBounds(const gfx::Rect& bounds) {
+ // |bounds| are supplied in the coordinates of the parent.
+ view_->SetBoundsRect(bounds);
+}
+
+void NativeWidgetViews::SetSize(const gfx::Size& size) {
+ view_->SetSize(size);
+}
+
+void NativeWidgetViews::MoveAbove(gfx::NativeView native_view) {
+ NOTIMPLEMENTED();
+}
+
+void NativeWidgetViews::SetShape(gfx::NativeRegion region) {
+ NOTIMPLEMENTED();
+}
+
+void NativeWidgetViews::Close() {
+ Hide();
+ if (close_widget_factory_.empty()) {
+ MessageLoop::current()->PostTask(FROM_HERE,
+ close_widget_factory_.NewRunnableMethod(&NativeWidgetViews::CloseNow));
+ }
+}
+
+void NativeWidgetViews::CloseNow() {
+ view_->parent()->RemoveChildView(view_);
+ delete view_;
+}
+
+void NativeWidgetViews::Show() {
+ view_->SetVisible(true);
+}
+
+void NativeWidgetViews::Hide() {
+ view_->SetVisible(false);
+}
+
+void NativeWidgetViews::SetOpacity(unsigned char opacity) {
+ NOTIMPLEMENTED();
+}
+
+void NativeWidgetViews::SetAlwaysOnTop(bool on_top) {
+ NOTIMPLEMENTED();
+}
+
+bool NativeWidgetViews::IsVisible() const {
+ return view_->IsVisible();
+}
+
+bool NativeWidgetViews::IsActive() const {
+ return view_->HasFocus();
+}
+
+bool NativeWidgetViews::IsAccessibleWidget() const {
+ NOTIMPLEMENTED();
+ return false;
+}
+
+bool NativeWidgetViews::ContainsNativeView(gfx::NativeView native_view) const {
+ NOTIMPLEMENTED();
+ return GetParentNativeWidget()->ContainsNativeView(native_view);
+}
+
+void NativeWidgetViews::RunShellDrag(View* view,
+ const ui::OSExchangeData& data,
+ int operation) {
+ GetParentNativeWidget()->RunShellDrag(view, data, operation);
+}
+
+void NativeWidgetViews::SchedulePaintInRect(const gfx::Rect& rect) {
+ view_->SchedulePaintInRect(rect);
+}
+
+void NativeWidgetViews::SetCursor(gfx::NativeCursor cursor) {
+ GetParentNativeWidget()->SetCursor(cursor);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// NativeWidgetViews, private:
+
+NativeWidget* NativeWidgetViews::GetParentNativeWidget() {
+ return view_->GetWidget()->native_widget();
+}
+
+const NativeWidget* NativeWidgetViews::GetParentNativeWidget() const {
+ return view_->GetWidget()->native_widget();
+}
+
+} // namespace views
+
diff --git a/views/widget/native_widget_views.h b/views/widget/native_widget_views.h
new file mode 100644
index 0000000..dbd0a57
--- /dev/null
+++ b/views/widget/native_widget_views.h
@@ -0,0 +1,86 @@
+// 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_WIN_H_
+#define VIEWS_WIDGET_NATIVE_WIDGET_WIN_H_
+#pragma once
+
+#include "base/message_loop.h"
+#include "views/widget/native_widget.h"
+
+namespace views {
+
+class NativeWidgetViews : public NativeWidget {
+ public:
+ explicit NativeWidgetViews(internal::NativeWidgetDelegate* delegate);
+ virtual ~NativeWidgetViews();
+
+ // TODO(beng): remove.
+ View* GetView();
+
+ private:
+ class NativeWidgetView;
+
+ // Overridden from NativeWidget:
+ virtual void InitNativeWidget(const Widget::InitParams& params) OVERRIDE;
+ virtual Widget* GetWidget() OVERRIDE;
+ virtual const Widget* GetWidget() const OVERRIDE;
+ virtual gfx::NativeView GetNativeView() const OVERRIDE;
+ virtual gfx::NativeWindow GetNativeWindow() const OVERRIDE;
+ virtual Window* GetContainingWindow() OVERRIDE;
+ virtual const Window* GetContainingWindow() const OVERRIDE;
+ virtual void ViewRemoved(View* view) OVERRIDE;
+ virtual void SetNativeWindowProperty(const char* name, void* value) OVERRIDE;
+ virtual void* GetNativeWindowProperty(const char* name) OVERRIDE;
+ virtual TooltipManager* GetTooltipManager() const OVERRIDE;
+ virtual bool IsScreenReaderActive() const OVERRIDE;
+ virtual void SendNativeAccessibilityEvent(
+ View* view,
+ ui::AccessibilityTypes::Event event_type) OVERRIDE;
+ virtual void SetMouseCapture() OVERRIDE;
+ virtual void ReleaseMouseCapture() OVERRIDE;
+ virtual bool HasMouseCapture() const OVERRIDE;
+ virtual bool IsMouseButtonDown() const OVERRIDE;
+ virtual InputMethod* GetInputMethodNative() OVERRIDE;
+ virtual void ReplaceInputMethod(InputMethod* input_method) OVERRIDE;
+ virtual gfx::AcceleratedWidget GetAcceleratedWidget() OVERRIDE;
+ virtual gfx::Rect GetWindowScreenBounds() const OVERRIDE;
+ virtual gfx::Rect GetClientAreaScreenBounds() const OVERRIDE;
+ virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE;
+ virtual void SetSize(const gfx::Size& size) OVERRIDE;
+ virtual void MoveAbove(gfx::NativeView native_view) OVERRIDE;
+ virtual void SetShape(gfx::NativeRegion shape) OVERRIDE;
+ virtual void Close() OVERRIDE;
+ virtual void CloseNow() OVERRIDE;
+ virtual void Show() OVERRIDE;
+ virtual void Hide() OVERRIDE;
+ virtual void SetOpacity(unsigned char opacity) OVERRIDE;
+ virtual void SetAlwaysOnTop(bool on_top) OVERRIDE;
+ virtual bool IsVisible() const OVERRIDE;
+ virtual bool IsActive() const OVERRIDE;
+ virtual bool IsAccessibleWidget() const OVERRIDE;
+ virtual bool ContainsNativeView(gfx::NativeView native_view) const OVERRIDE;
+ virtual void RunShellDrag(View* view,
+ const ui::OSExchangeData& data,
+ int operation) OVERRIDE;
+ virtual void SchedulePaintInRect(const gfx::Rect& rect) OVERRIDE;
+ virtual void SetCursor(gfx::NativeCursor cursor) OVERRIDE;
+
+ NativeWidget* GetParentNativeWidget();
+ const NativeWidget* GetParentNativeWidget() const;
+
+ internal::NativeWidgetDelegate* delegate_;
+
+ NativeWidgetView* view_;
+
+ // The following factory is used for calls to close the NativeWidgetViews
+ // instance.
+ ScopedRunnableMethodFactory<NativeWidgetViews> close_widget_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(NativeWidgetViews);
+};
+
+}
+
+#endif // VIEWS_WIDGET_NATIVE_WIDGET_WIN_H_