diff options
author | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-24 21:02:28 +0000 |
---|---|---|
committer | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-24 21:02:28 +0000 |
commit | 244f6db2673d9bee139a2f1738ade5a0e729b208 (patch) | |
tree | 85ef99866735ff67091d8ab3651d1fd0e31c3a49 /views/widget | |
parent | 35e251d043bf98206b75b3065841bf25c21d7fcc (diff) | |
download | chromium_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/widget')
-rw-r--r-- | views/widget/native_widget.h | 1 | ||||
-rw-r--r-- | views/widget/native_widget_views.cc | 236 | ||||
-rw-r--r-- | views/widget/native_widget_views.h | 86 |
3 files changed, 323 insertions, 0 deletions
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_ |