Commit 244f6db2 authored by ben@chromium.org's avatar ben@chromium.org

Add NativeWidgetViews. This is a stub implementation that mostly just defers...

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
parent 35e251d0
......@@ -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());
......
// 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
// 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_
......@@ -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',
......
......@@ -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.
......
// 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
// 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_
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