summaryrefslogtreecommitdiffstats
path: root/views
diff options
context:
space:
mode:
authorben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-16 17:21:23 +0000
committerben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-16 17:21:23 +0000
commit2f2b57b7e32777e656d4dbbbc04cd914d5b94472 (patch)
tree9e925e8063d39c06c4edb068d2f3a371ff395589 /views
parent4e8655deaccc49465a6c18055887d1e0e2501a55 (diff)
downloadchromium_src-2f2b57b7e32777e656d4dbbbc04cd914d5b94472.zip
chromium_src-2f2b57b7e32777e656d4dbbbc04cd914d5b94472.tar.gz
chromium_src-2f2b57b7e32777e656d4dbbbc04cd914d5b94472.tar.bz2
Re-land:
Move private NativeWidget methods to new internal interface NativeWidgetPrivate. This should make it harder to abuse accidentally. BUG=72040 TEST=none Review URL: http://codereview.chromium.org/7170019 Review URL: http://codereview.chromium.org/7189012 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@89357 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
-rw-r--r--views/controls/combobox/native_combobox_views_unittest.cc4
-rw-r--r--views/controls/menu/menu_host.cc6
-rw-r--r--views/controls/native/native_view_host.cc8
-rw-r--r--views/controls/native/native_view_host_win.cc4
-rw-r--r--views/controls/tabbed_pane/native_tabbed_pane_gtk.cc6
-rw-r--r--views/controls/textfield/native_textfield_views_unittest.cc4
-rw-r--r--views/focus/accelerator_handler_touch.cc4
-rw-r--r--views/focus/focus_manager_gtk.cc4
-rw-r--r--views/focus/focus_manager_win.cc5
-rw-r--r--views/view.cc12
-rw-r--r--views/view_unittest.cc8
-rw-r--r--views/views.gyp1
-rw-r--r--views/widget/native_widget.h192
-rw-r--r--views/widget/native_widget_gtk.cc90
-rw-r--r--views/widget/native_widget_gtk.h6
-rw-r--r--views/widget/native_widget_private.h206
-rw-r--r--views/widget/native_widget_test_utils.h8
-rw-r--r--views/widget/native_widget_test_utils_gtk.cc12
-rw-r--r--views/widget/native_widget_test_utils_win.cc12
-rw-r--r--views/widget/native_widget_unittest.cc16
-rw-r--r--views/widget/native_widget_views.cc11
-rw-r--r--views/widget/native_widget_views.h10
-rw-r--r--views/widget/native_widget_win.cc69
-rw-r--r--views/widget/native_widget_win.h6
-rw-r--r--views/widget/widget.cc78
-rw-r--r--views/widget/widget.h40
26 files changed, 468 insertions, 354 deletions
diff --git a/views/controls/combobox/native_combobox_views_unittest.cc b/views/controls/combobox/native_combobox_views_unittest.cc
index cb18b31..eec8c54 100644
--- a/views/controls/combobox/native_combobox_views_unittest.cc
+++ b/views/controls/combobox/native_combobox_views_unittest.cc
@@ -9,7 +9,7 @@
#include "views/controls/combobox/native_combobox_views.h"
#include "views/ime/mock_input_method.h"
#include "views/test/views_test_base.h"
-#include "views/widget/native_widget.h"
+#include "views/widget/native_widget_private.h"
#include "views/widget/widget.h"
namespace {
@@ -114,7 +114,7 @@ class NativeComboboxViewsTest : public ViewsTestBase {
ASSERT_TRUE(combobox_view_);
input_method_ = new MockInputMethod();
- widget_->native_widget()->ReplaceInputMethod(input_method_);
+ widget_->native_widget_private()->ReplaceInputMethod(input_method_);
// Assumes the Widget is always focused.
input_method_->OnFocus();
diff --git a/views/controls/menu/menu_host.cc b/views/controls/menu/menu_host.cc
index 82fd186..57f7707 100644
--- a/views/controls/menu/menu_host.cc
+++ b/views/controls/menu/menu_host.cc
@@ -9,7 +9,7 @@
#include "views/controls/menu/menu_item_view.h"
#include "views/controls/menu/native_menu_host.h"
#include "views/controls/menu/submenu_view.h"
-#include "views/widget/native_widget.h"
+#include "views/widget/native_widget_private.h"
#include "views/widget/widget.h"
namespace views {
@@ -72,8 +72,8 @@ void MenuHost::SetMenuHostBounds(const gfx::Rect& bounds) {
}
void MenuHost::ReleaseMenuHostCapture() {
- if (native_widget()->HasMouseCapture())
- native_widget()->ReleaseMouseCapture();
+ if (native_widget_private()->HasMouseCapture())
+ native_widget_private()->ReleaseMouseCapture();
}
////////////////////////////////////////////////////////////////////////////////
diff --git a/views/controls/native/native_view_host.cc b/views/controls/native/native_view_host.cc
index 1b9d74e..1a304a6 100644
--- a/views/controls/native/native_view_host.cc
+++ b/views/controls/native/native_view_host.cc
@@ -8,7 +8,6 @@
#include "ui/gfx/canvas.h"
#include "views/controls/native/native_view_host_wrapper.h"
#include "views/controls/native/native_view_host_views.h"
-#include "views/widget/native_widget.h"
#include "views/widget/widget.h"
namespace views {
@@ -190,12 +189,9 @@ bool NativeViewHost::ContainsNativeView(gfx::NativeView native_view) const {
if (!native_view_)
return false;
- views::NativeWidget* native_widget =
- views::NativeWidget::GetNativeWidgetForNativeView(native_view_);
- if (native_widget &&
- native_widget->GetWidget()->ContainsNativeView(native_view)) {
+ views::Widget* widget = views::Widget::GetWidgetForNativeView(native_view);
+ if (widget && widget->ContainsNativeView(native_view))
return true;
- }
return View::ContainsNativeView(native_view);
}
diff --git a/views/controls/native/native_view_host_win.cc b/views/controls/native/native_view_host_win.cc
index b7fa074..52f9373 100644
--- a/views/controls/native/native_view_host_win.cc
+++ b/views/controls/native/native_view_host_win.cc
@@ -37,8 +37,8 @@ void NativeViewHostWin::NativeViewAttached() {
// borders), when we change the parent below.
ShowWindow(host_->native_view(), SW_HIDE);
- NativeWidget::ReparentNativeView(host_->native_view(),
- host_->GetWidget()->GetNativeView());
+ Widget::ReparentNativeView(host_->native_view(),
+ host_->GetWidget()->GetNativeView());
host_->Layout();
}
diff --git a/views/controls/tabbed_pane/native_tabbed_pane_gtk.cc b/views/controls/tabbed_pane/native_tabbed_pane_gtk.cc
index 360ad6e..ac3ff19 100644
--- a/views/controls/tabbed_pane/native_tabbed_pane_gtk.cc
+++ b/views/controls/tabbed_pane/native_tabbed_pane_gtk.cc
@@ -77,8 +77,7 @@ View* NativeTabbedPaneGtk::RemoveTabAtIndex(int index) {
GtkWidget* page =
gtk_notebook_get_nth_page(GTK_NOTEBOOK(native_view()), index);
- Widget* widget =
- NativeWidget::GetNativeWidgetForNativeView(page)->GetWidget();
+ Widget* widget = Widget::GetWidgetForNativeView(page);
// detach the content view from widget so that we can delete widget
// without destroying the content view.
@@ -197,8 +196,7 @@ Widget* NativeTabbedPaneGtk::GetWidgetAt(int index) {
DCHECK(index <= GetTabCount());
GtkWidget* page = gtk_notebook_get_nth_page(GTK_NOTEBOOK(native_view()),
index);
- Widget* widget =
- NativeWidget::GetNativeWidgetForNativeView(page)->GetWidget();
+ Widget* widget = Widget::GetWidgetForNativeView(page);
DCHECK(widget);
return widget;
}
diff --git a/views/controls/textfield/native_textfield_views_unittest.cc b/views/controls/textfield/native_textfield_views_unittest.cc
index 0c9fd05..190aaae 100644
--- a/views/controls/textfield/native_textfield_views_unittest.cc
+++ b/views/controls/textfield/native_textfield_views_unittest.cc
@@ -27,7 +27,7 @@
#include "views/test/test_views_delegate.h"
#include "views/test/views_test_base.h"
#include "views/views_delegate.h"
-#include "views/widget/native_widget.h"
+#include "views/widget/native_widget_private.h"
#include "views/widget/widget.h"
namespace {
@@ -181,7 +181,7 @@ class NativeTextfieldViewsTest : public ViewsTestBase,
model_->ClearEditHistory();
input_method_ = new MockInputMethod();
- widget_->native_widget()->ReplaceInputMethod(input_method_);
+ widget_->native_widget_private()->ReplaceInputMethod(input_method_);
// Assumes the Widget is always focused.
input_method_->OnFocus();
diff --git a/views/focus/accelerator_handler_touch.cc b/views/focus/accelerator_handler_touch.cc
index 9edf516..3ffbd6a 100644
--- a/views/focus/accelerator_handler_touch.cc
+++ b/views/focus/accelerator_handler_touch.cc
@@ -32,13 +32,13 @@ Widget* FindWidgetForGdkWindow(GdkWindow* gdk_window) {
DLOG(WARNING) << "no GtkWidget found for that GdkWindow";
return NULL;
}
- NativeWidget* widget = NativeWidget::GetNativeWidgetForNativeView(gtk_widget);
+ Widget* widget = Widget::GetWidgetForNativeView(gtk_widget);
if (!widget) {
DLOG(WARNING) << "no NativeWidgetGtk found for that GtkWidget";
return NULL;
}
- return widget->GetWidget();
+ return widget;
}
} // namespace
diff --git a/views/focus/focus_manager_gtk.cc b/views/focus/focus_manager_gtk.cc
index 399ddc4..f6128681 100644
--- a/views/focus/focus_manager_gtk.cc
+++ b/views/focus/focus_manager_gtk.cc
@@ -27,7 +27,7 @@ FocusManager* FocusManager::GetFocusManagerForNativeView(
if (!root || !GTK_WIDGET_TOPLEVEL(root))
return NULL;
- NativeWidget* widget = NativeWidget::GetNativeWidgetForNativeView(root);
+ Widget* widget = Widget::GetWidgetForNativeView(root);
if (!widget) {
// TODO(jcampan): http://crbug.com/21378 Reenable this NOTREACHED() when the
// options page is only based on views.
@@ -35,7 +35,7 @@ FocusManager* FocusManager::GetFocusManagerForNativeView(
NOTIMPLEMENTED();
return NULL;
}
- FocusManager* focus_manager = widget->GetWidget()->GetFocusManager();
+ FocusManager* focus_manager = widget->GetFocusManager();
DCHECK(focus_manager) << "no FocusManager for top level Widget";
return focus_manager;
}
diff --git a/views/focus/focus_manager_win.cc b/views/focus/focus_manager_win.cc
index 79d0b59..a358fc8 100644
--- a/views/focus/focus_manager_win.cc
+++ b/views/focus/focus_manager_win.cc
@@ -25,9 +25,8 @@ void FocusManager::FocusNativeView(gfx::NativeView native_view) {
FocusManager* FocusManager::GetFocusManagerForNativeView(
gfx::NativeView native_view) {
// TODO(beng): This method probably isn't necessary.
- views::NativeWidget* native_widget =
- views::NativeWidget::GetTopLevelNativeWidget(native_view);
- return native_widget ? native_widget->GetWidget()->GetFocusManager() : NULL;
+ Widget* widget = Widget::GetTopLevelWidgetForNativeView(native_view);
+ return widget ? widget->GetFocusManager() : NULL;
}
// static
diff --git a/views/view.cc b/views/view.cc
index 35a0ccf..c411621 100644
--- a/views/view.cc
+++ b/views/view.cc
@@ -20,7 +20,7 @@
#include "views/background.h"
#include "views/layout/layout_manager.h"
#include "views/views_delegate.h"
-#include "views/widget/native_widget.h"
+#include "views/widget/native_widget_private.h"
#include "views/widget/root_view.h"
#include "views/widget/tooltip_manager.h"
#include "views/widget/widget.h"
@@ -1240,8 +1240,10 @@ void View::Blur() {
void View::TooltipTextChanged() {
Widget* widget = GetWidget();
// TooltipManager may be null if there is a problem creating it.
- if (widget && widget->native_widget()->GetTooltipManager())
- widget->native_widget()->GetTooltipManager()->TooltipTextChanged(this);
+ if (widget && widget->native_widget_private()->GetTooltipManager()) {
+ widget->native_widget_private()->GetTooltipManager()->
+ TooltipTextChanged(this);
+ }
}
// Context menus ---------------------------------------------------------------
@@ -1758,8 +1760,8 @@ void View::UpdateTooltip() {
// TODO(beng): The TooltipManager NULL check can be removed when we
// consolidate Init() methods and make views_unittests Init() all
// Widgets that it uses.
- if (widget && widget->native_widget()->GetTooltipManager())
- widget->native_widget()->GetTooltipManager()->UpdateTooltip();
+ if (widget && widget->native_widget_private()->GetTooltipManager())
+ widget->native_widget_private()->GetTooltipManager()->UpdateTooltip();
}
// Drag and drop ---------------------------------------------------------------
diff --git a/views/view_unittest.cc b/views/view_unittest.cc
index 3ffd2f5..65c704c 100644
--- a/views/view_unittest.cc
+++ b/views/view_unittest.cc
@@ -1510,14 +1510,14 @@ class TestChangeNativeViewHierarchy {
void CheckEnumeratingNativeWidgets() {
if (!host_->GetTopLevelWidget())
return;
- NativeWidget::NativeWidgets widgets;
- NativeWidget::GetAllNativeWidgets(host_->GetNativeView(), &widgets);
+ Widget::Widgets widgets;
+ Widget::GetAllChildWidgets(host_->GetNativeView(), &widgets);
EXPECT_EQ(TestNativeViewHierarchy::kTotalViews + 1, widgets.size());
// Unfortunately there is no guarantee the sequence of views here so always
// go through all of them.
- for (NativeWidget::NativeWidgets::iterator i = widgets.begin();
+ for (Widget::Widgets::iterator i = widgets.begin();
i != widgets.end(); ++i) {
- View* root_view = (*i)->GetWidget()->GetRootView();
+ View* root_view = (*i)->GetRootView();
if (host_->GetRootView() == root_view)
continue;
size_t j;
diff --git a/views/views.gyp b/views/views.gyp
index c3f8d18..a148431 100644
--- a/views/views.gyp
+++ b/views/views.gyp
@@ -365,6 +365,7 @@
'widget/monitor_win.h',
'widget/native_widget.h',
'widget/native_widget_delegate.h',
+ 'widget/native_widget_private.h',
'widget/native_widget_gtk.cc',
'widget/native_widget_gtk.h',
'widget/native_widget_view.cc',
diff --git a/views/widget/native_widget.h b/views/widget/native_widget.h
index 1e5b2df..9ed37e7 100644
--- a/views/widget/native_widget.h
+++ b/views/widget/native_widget.h
@@ -6,199 +6,31 @@
#define VIEWS_WIDGET_NATIVE_WIDGET_H_
#pragma once
-#include <set>
-
-#include "ui/gfx/native_widget_types.h"
#include "views/widget/widget.h"
-namespace gfx {
-class Rect;
-}
-
-namespace ui {
-class OSExchangeData;
-}
-
namespace views {
-
-class InputMethod;
-class TooltipManager;
+namespace internal {
+class NativeWidgetPrivate;
+}
////////////////////////////////////////////////////////////////////////////////
// NativeWidget interface
//
-// An interface implemented by an object that encapsulates rendering, event
-// handling and widget management provided by an underlying native toolkit.
+// An interface that serves as the public API base for the
+// internal::NativeWidget interface that Widget uses to communicate with a
+// backend-specific native widget implementation. This is the only component of
+// this interface that is publicly visible, and exists solely for exposure via
+// Widget's native_widget() accessor, which code occasionally static_casts to
+// a known implementation in platform-specific code.
//
class NativeWidget {
public:
- typedef std::set<NativeWidget*> NativeWidgets;
-
virtual ~NativeWidget() {}
- // Creates an appropriate default NativeWidget implementation for the current
- // OS/circumstance.
- static NativeWidget* CreateNativeWidget(
- internal::NativeWidgetDelegate* delegate);
-
- // Retrieves the NativeWidget implementation associated with the given
- // NativeView or Window, or NULL if the supplied handle has no associated
- // NativeView.
- static NativeWidget* GetNativeWidgetForNativeView(
- gfx::NativeView native_view);
- static NativeWidget* GetNativeWidgetForNativeWindow(
- gfx::NativeWindow native_window);
-
- // Retrieves the top NativeWidget in the hierarchy containing the given
- // NativeView, or NULL if there is no NativeWidget that contains it.
- static NativeWidget* GetTopLevelNativeWidget(gfx::NativeView native_view);
-
- // Returns all NativeWidgets in |native_view|'s hierarchy, including itself if
- // it is one.
- static void GetAllNativeWidgets(gfx::NativeView native_view,
- NativeWidgets* children);
-
- // Reparent a NativeView and notify all NativeWidgets in
- // |native_view|'s hierarchy of the change.
- static void ReparentNativeView(gfx::NativeView native_view,
- gfx::NativeView new_parent);
-
- // Initializes the NativeWidget.
- virtual void InitNativeWidget(const Widget::InitParams& params) = 0;
-
- // Returns a NonClientFrameView for the widget's NonClientView, or NULL if
- // the NativeWidget wants no special NonClientFrameView.
- virtual NonClientFrameView* CreateNonClientFrameView() = 0;
-
- virtual void UpdateFrameAfterFrameChange() = 0;
- virtual bool ShouldUseNativeFrame() const = 0;
- virtual void FrameTypeChanged() = 0;
-
- // Returns the Widget associated with this NativeWidget. This function is
- // guaranteed to return non-NULL for the lifetime of the NativeWidget.
- virtual Widget* GetWidget() = 0;
- virtual const Widget* GetWidget() const = 0;
-
- // Returns the NativeView/Window associated with this NativeWidget.
- virtual gfx::NativeView GetNativeView() const = 0;
- virtual gfx::NativeWindow GetNativeWindow() const = 0;
-
- // Notifies the NativeWidget that a view was removed from the Widget's view
- // hierarchy.
- virtual void ViewRemoved(View* view) = 0;
-
- // Sets/Gets a native window property on the underlying native window object.
- // Returns NULL if the property does not exist. Setting the property value to
- // NULL removes the property.
- virtual void SetNativeWindowProperty(const char* name, void* value) = 0;
- virtual void* GetNativeWindowProperty(const char* name) const = 0;
-
- // Returns the native widget's tooltip manager. Called from the View hierarchy
- // to update tooltips.
- virtual TooltipManager* GetTooltipManager() const = 0;
-
- // Returns true if a system screen reader is active for the NativeWidget.
- virtual bool IsScreenReaderActive() const = 0;
-
- // Notify native Accessibility clients of an event.
- virtual void SendNativeAccessibilityEvent(
- View* view,
- ui::AccessibilityTypes::Event event_type) = 0;
-
- // Sets or releases event capturing for this native widget.
- virtual void SetMouseCapture() = 0;
- virtual void ReleaseMouseCapture() = 0;
-
- // Returns true if this native widget is capturing all events.
- virtual bool HasMouseCapture() const = 0;
-
- // Returns true if any mouse button is currently pressed.
- virtual bool IsMouseButtonDown() const = 0;
-
- // Returns the InputMethod for this native widget.
- // Note that all widgets in a widget hierarchy share the same input method.
- // TODO(suzhe): rename to GetInputMethod() when NativeWidget implementation
- // class doesn't inherit Widget anymore.
- virtual InputMethod* GetInputMethodNative() = 0;
-
- // Sets a different InputMethod instance to this native widget. The instance
- // must not be initialized, the ownership will be assumed by the native
- // widget. It's only for testing purpose.
- virtual void ReplaceInputMethod(InputMethod* input_method) = 0;
-
- // Centers the window and sizes it to the specified size.
- virtual void CenterWindow(const gfx::Size& size) = 0;
-
- // Retrieves the window's current restored bounds and maximized state, for
- // persisting.
- virtual void GetWindowBoundsAndMaximizedState(gfx::Rect* bounds,
- bool* maximized) const = 0;
-
- // Sets the NativeWindow title.
- virtual void SetWindowTitle(const std::wstring& title) = 0;
-
- // Sets the Window icons. |window_icon| is a 16x16 icon suitable for use in
- // a title bar. |app_icon| is a larger size for use in the host environment
- // app switching UI.
- virtual void SetWindowIcons(const SkBitmap& window_icon,
- const SkBitmap& app_icon) = 0;
-
- // Update native accessibility properties on the native window.
- virtual void SetAccessibleName(const std::wstring& name) = 0;
- virtual void SetAccessibleRole(ui::AccessibilityTypes::Role role) = 0;
- virtual void SetAccessibleState(ui::AccessibilityTypes::State state) = 0;
-
- enum ShowState {
- SHOW_RESTORED,
- SHOW_MAXIMIZED,
- SHOW_INACTIVE
- };
-
- // Returns a handle for the underlying native widget that can be used for
- // accelerated drawing.
- virtual gfx::AcceleratedWidget GetAcceleratedWidget() = 0;
-
- // Makes the NativeWindow modal.
- virtual void BecomeModal() = 0;
+ private:
+ friend class Widget;
- // Widget pass-thrus, private to Views. --------------------------------------
- // See method documentation in Widget.
- virtual gfx::Rect GetWindowScreenBounds() const = 0;
- virtual gfx::Rect GetClientAreaScreenBounds() const = 0;
- virtual gfx::Rect GetRestoredBounds() const = 0;
- virtual void SetBounds(const gfx::Rect& bounds) = 0;
- virtual void SetSize(const gfx::Size& size) = 0;
- virtual void SetBoundsConstrained(const gfx::Rect& bounds,
- Widget* other_widget) = 0;
- virtual void MoveAbove(gfx::NativeView native_view) = 0;
- virtual void SetShape(gfx::NativeRegion shape) = 0;
- virtual void Close() = 0;
- virtual void CloseNow() = 0;
- virtual void EnableClose(bool enable) = 0;
- virtual void Show() = 0;
- virtual void Hide() = 0;
- virtual void ShowNativeWidget(ShowState state) = 0;
- virtual bool IsVisible() const = 0;
- virtual void Activate() = 0;
- virtual void Deactivate() = 0;
- virtual bool IsActive() const = 0;
- virtual void SetAlwaysOnTop(bool always_on_top) = 0;
- virtual void Maximize() = 0;
- virtual void Minimize() = 0;
- virtual bool IsMaximized() const = 0;
- virtual bool IsMinimized() const = 0;
- virtual void Restore() = 0;
- virtual void SetFullscreen(bool fullscreen) = 0;
- virtual bool IsFullscreen() const = 0;
- virtual void SetOpacity(unsigned char opacity) = 0;
- virtual void SetUseDragFrame(bool use_drag_frame) = 0;
- virtual bool IsAccessibleWidget() const = 0;
- virtual bool ContainsNativeView(gfx::NativeView native_view) const = 0;
- virtual void RunShellDrag(View* view,
- const ui::OSExchangeData& data,
- int operation) = 0;
- virtual void SchedulePaintInRect(const gfx::Rect& rect) = 0;
- virtual void SetCursor(gfx::NativeCursor cursor) = 0;
+ virtual internal::NativeWidgetPrivate* AsNativeWidgetPrivate() = 0;
};
} // namespace views
diff --git a/views/widget/native_widget_gtk.cc b/views/widget/native_widget_gtk.cc
index ea7dc50..8ca9870 100644
--- a/views/widget/native_widget_gtk.cc
+++ b/views/widget/native_widget_gtk.cc
@@ -163,12 +163,10 @@ void EnumerateChildWidgetsForNativeWidgets(GtkWidget* child_widget,
param);
}
- NativeWidget* native_widget =
- NativeWidget::GetNativeWidgetForNativeView(child_widget);
- if (native_widget) {
- NativeWidget::NativeWidgets* widgets =
- reinterpret_cast<NativeWidget::NativeWidgets*>(param);
- widgets->insert(native_widget);
+ Widget* widget = Widget::GetWidgetForNativeView(child_widget);
+ if (widget) {
+ Widget::Widgets* widgets = reinterpret_cast<Widget::Widgets*>(param);
+ widgets->insert(widget);
}
}
@@ -280,7 +278,8 @@ class NativeWidgetGtk::DropObserver : public MessageLoopForUI::Observer {
return NULL;
return static_cast<NativeWidgetGtk*>(
- NativeWidget::GetNativeWidgetForNativeView(gtk_widget));
+ internal::NativeWidgetPrivate::GetNativeWidgetForNativeView(
+ gtk_widget));
}
DISALLOW_COPY_AND_ASSIGN(DropObserver);
@@ -1001,7 +1000,7 @@ void NativeWidgetGtk::SetBounds(const gfx::Rect& bounds) {
GtkWidget* parent = gtk_widget_get_parent(widget_);
if (GTK_IS_VIEWS_FIXED(parent)) {
NativeWidgetGtk* parent_widget = static_cast<NativeWidgetGtk*>(
- NativeWidget::GetNativeWidgetForNativeView(parent));
+ internal::NativeWidgetPrivate::GetNativeWidgetForNativeView(parent));
parent_widget->PositionChild(widget_, bounds.x(), bounds.y(),
bounds.width(), bounds.height());
} else {
@@ -1111,7 +1110,7 @@ void NativeWidgetGtk::Hide() {
void NativeWidgetGtk::ShowNativeWidget(ShowState state) {
// No concept of maximization (yet) on ChromeOS.
- if (state == NativeWidget::SHOW_INACTIVE)
+ if (state == internal::NativeWidgetPrivate::SHOW_INACTIVE)
gtk_window_set_focus_on_map(GetNativeWindow(), false);
gtk_widget_show(GetNativeView());
}
@@ -1755,10 +1754,10 @@ gboolean NativeWidgetGtk::ChildExposeHandler(GtkWidget* widget,
GdkEventExpose* event) {
GtkWidget* toplevel = gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW);
CHECK(toplevel);
- NativeWidget* native_widget =
- NativeWidget::GetNativeWidgetForNativeView(toplevel);
- CHECK(native_widget);
- NativeWidgetGtk* widget_gtk = static_cast<NativeWidgetGtk*>(native_widget);
+ Widget* views_widget = Widget::GetWidgetForNativeView(toplevel);
+ CHECK(views_widget);
+ NativeWidgetGtk* widget_gtk =
+ static_cast<NativeWidgetGtk*>(views_widget->native_widget());
widget_gtk->OnChildExpose(widget);
return false;
}
@@ -1953,10 +1952,10 @@ void NativeWidgetGtk::SaveWindowPosition() {
void Widget::NotifyLocaleChanged() {
GList *window_list = gtk_window_list_toplevels();
for (GList* element = window_list; element; element = g_list_next(element)) {
- NativeWidget* native_widget =
- NativeWidget::GetNativeWidgetForNativeWindow(GTK_WINDOW(element->data));
- if (native_widget)
- native_widget->GetWidget()->LocaleChanged();
+ Widget* widget =
+ Widget::GetWidgetForNativeWindow(GTK_WINDOW(element->data));
+ if (widget)
+ widget->LocaleChanged();
}
g_list_free(window_list);
}
@@ -1966,13 +1965,9 @@ void Widget::CloseAllSecondaryWidgets() {
GList* windows = gtk_window_list_toplevels();
for (GList* window = windows; window;
window = g_list_next(window)) {
- NativeWidget* native_widget = NativeWidget::GetNativeWidgetForNativeView(
- GTK_WIDGET(window->data));
- if (native_widget) {
- Widget* widget = native_widget->GetWidget();
- if (widget->is_secondary_widget())
- widget->Close();
- }
+ Widget* widget = Widget::GetWidgetForNativeView(GTK_WIDGET(window->data));
+ if (widget && widget->is_secondary_widget())
+ widget->Close();
}
g_list_free(windows);
}
@@ -2003,17 +1998,19 @@ bool Widget::ConvertRect(const Widget* source,
return false;
}
+namespace internal {
+
////////////////////////////////////////////////////////////////////////////////
-// NativeWidget, public:
+// NativeWidgetPrivate, public:
// static
-NativeWidget* NativeWidget::CreateNativeWidget(
- internal::NativeWidgetDelegate* delegate) {
+NativeWidgetPrivate* NativeWidgetPrivate::CreateNativeWidget(
+ NativeWidgetDelegate* delegate) {
return new NativeWidgetGtk(delegate);
}
// static
-NativeWidget* NativeWidget::GetNativeWidgetForNativeView(
+NativeWidgetPrivate* NativeWidgetPrivate::GetNativeWidgetForNativeView(
gfx::NativeView native_view) {
if (!native_view)
return NULL;
@@ -2022,7 +2019,7 @@ NativeWidget* NativeWidget::GetNativeWidgetForNativeView(
}
// static
-NativeWidget* NativeWidget::GetNativeWidgetForNativeWindow(
+NativeWidgetPrivate* NativeWidgetPrivate::GetNativeWidgetForNativeWindow(
gfx::NativeWindow native_window) {
if (!native_window)
return NULL;
@@ -2031,15 +2028,15 @@ NativeWidget* NativeWidget::GetNativeWidgetForNativeWindow(
}
// static
-NativeWidget* NativeWidget::GetTopLevelNativeWidget(
+NativeWidgetPrivate* NativeWidgetPrivate::GetTopLevelNativeWidget(
gfx::NativeView native_view) {
if (!native_view)
return NULL;
- NativeWidget* widget = NULL;
+ NativeWidgetPrivate* widget = NULL;
GtkWidget* parent_gtkwidget = native_view;
- NativeWidget* parent_widget;
+ NativeWidgetPrivate* parent_widget;
do {
parent_widget = GetNativeWidgetForNativeView(parent_gtkwidget);
if (parent_widget)
@@ -2051,22 +2048,22 @@ NativeWidget* NativeWidget::GetTopLevelNativeWidget(
}
// static
-void NativeWidget::GetAllNativeWidgets(gfx::NativeView native_view,
- NativeWidgets* children) {
+void NativeWidgetPrivate::GetAllChildWidgets(gfx::NativeView native_view,
+ Widget::Widgets* children) {
if (!native_view)
return;
- NativeWidget* native_widget = GetNativeWidgetForNativeView(native_view);
- if (native_widget)
- children->insert(native_widget);
+ Widget* widget = Widget::GetWidgetForNativeView(native_view);
+ if (widget)
+ children->insert(widget);
gtk_container_foreach(GTK_CONTAINER(native_view),
EnumerateChildWidgetsForNativeWidgets,
reinterpret_cast<gpointer>(children));
}
// static
-void NativeWidget::ReparentNativeView(gfx::NativeView native_view,
- gfx::NativeView new_parent) {
+void NativeWidgetPrivate::ReparentNativeView(gfx::NativeView native_view,
+ gfx::NativeView new_parent) {
if (!native_view)
return;
@@ -2074,17 +2071,16 @@ void NativeWidget::ReparentNativeView(gfx::NativeView native_view,
if (previous_parent == new_parent)
return;
- NativeWidgets widgets;
- GetAllNativeWidgets(native_view, &widgets);
+ Widget::Widgets widgets;
+ GetAllChildWidgets(native_view, &widgets);
// First notify all the widgets that they are being disassociated
// from their previous parent.
- for (NativeWidgets::iterator it = widgets.begin();
+ for (Widget::Widgets::iterator it = widgets.begin();
it != widgets.end(); ++it) {
// TODO(beng): Rename this notification to NotifyNativeViewChanging()
// and eliminate the bool parameter.
- (*it)->GetWidget()->NotifyNativeViewHierarchyChanged(false,
- previous_parent);
+ (*it)->NotifyNativeViewHierarchyChanged(false, previous_parent);
}
if (gtk_widget_get_parent(native_view))
@@ -2093,11 +2089,11 @@ void NativeWidget::ReparentNativeView(gfx::NativeView native_view,
gtk_container_add(GTK_CONTAINER(new_parent), native_view);
// And now, notify them that they have a brand new parent.
- for (NativeWidgets::iterator it = widgets.begin();
+ for (Widget::Widgets::iterator it = widgets.begin();
it != widgets.end(); ++it) {
- (*it)->GetWidget()->NotifyNativeViewHierarchyChanged(true,
- new_parent);
+ (*it)->NotifyNativeViewHierarchyChanged(true, new_parent);
}
}
+} // namespace internal
} // namespace views
diff --git a/views/widget/native_widget_gtk.h b/views/widget/native_widget_gtk.h
index 559d98c..4565b39 100644
--- a/views/widget/native_widget_gtk.h
+++ b/views/widget/native_widget_gtk.h
@@ -14,7 +14,7 @@
#include "ui/gfx/size.h"
#include "views/focus/focus_manager.h"
#include "views/ime/input_method_delegate.h"
-#include "views/widget/native_widget.h"
+#include "views/widget/native_widget_private.h"
#include "views/widget/widget.h"
namespace gfx {
@@ -40,7 +40,7 @@ class NativeWidgetDelegate;
}
// Widget implementation for GTK.
-class NativeWidgetGtk : public NativeWidget,
+class NativeWidgetGtk : public internal::NativeWidgetPrivate,
public ui::ActiveWindowWatcherX::Observer,
public internal::InputMethodDelegate {
public:
@@ -153,7 +153,7 @@ class NativeWidgetGtk : public NativeWidget,
focus_on_creation_ = focus_on_creation;
}
- // Overridden from NativeWidget:
+ // Overridden from internal::NativeWidgetPrivate:
virtual void InitNativeWidget(const Widget::InitParams& params) OVERRIDE;
virtual NonClientFrameView* CreateNonClientFrameView() OVERRIDE;
virtual void UpdateFrameAfterFrameChange() OVERRIDE;
diff --git a/views/widget/native_widget_private.h b/views/widget/native_widget_private.h
new file mode 100644
index 0000000..1e08184
--- /dev/null
+++ b/views/widget/native_widget_private.h
@@ -0,0 +1,206 @@
+// 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_PRIVATE_H_
+#define VIEWS_WIDGET_NATIVE_WIDGET_PRIVATE_H_
+#pragma once
+
+#include "ui/gfx/native_widget_types.h"
+#include "views/widget/native_widget.h"
+
+namespace gfx {
+class Rect;
+}
+
+namespace ui {
+class OSExchangeData;
+}
+
+namespace views {
+class InputMethod;
+class TooltipManager;
+namespace internal {
+
+////////////////////////////////////////////////////////////////////////////////
+// NativeWidgetPrivate interface
+//
+// A NativeWidget subclass internal to views that provides Widget a conduit for
+// communication with a backend-specific native widget implementation.
+//
+// Many of the methods here are pass-thrus for Widget, and as such there is no
+// documentation for them here. In that case, see methods of the same name in
+// widget.h.
+//
+// IMPORTANT: This type is intended for use only by the views system and for
+// NativeWidget implementations. This file should not be included
+// in code that does not fall into one of these use cases.
+//
+class NativeWidgetPrivate : public NativeWidget {
+ public:
+ virtual ~NativeWidgetPrivate() {}
+
+ // Creates an appropriate default NativeWidgetPrivate implementation for the
+ // current OS/circumstance.
+ static NativeWidgetPrivate* CreateNativeWidget(
+ internal::NativeWidgetDelegate* delegate);
+
+ static NativeWidgetPrivate* GetNativeWidgetForNativeView(
+ gfx::NativeView native_view);
+ static NativeWidgetPrivate* GetNativeWidgetForNativeWindow(
+ gfx::NativeWindow native_window);
+
+ // Retrieves the top NativeWidgetPrivate in the hierarchy containing the given
+ // NativeView, or NULL if there is no NativeWidgetPrivate that contains it.
+ static NativeWidgetPrivate* GetTopLevelNativeWidget(
+ gfx::NativeView native_view);
+
+ static void GetAllChildWidgets(gfx::NativeView native_view,
+ Widget::Widgets* children);
+ static void ReparentNativeView(gfx::NativeView native_view,
+ gfx::NativeView new_parent);
+
+ // Initializes the NativeWidget.
+ virtual void InitNativeWidget(const Widget::InitParams& params) = 0;
+
+ // Returns a NonClientFrameView for the widget's NonClientView, or NULL if
+ // the NativeWidget wants no special NonClientFrameView.
+ virtual NonClientFrameView* CreateNonClientFrameView() = 0;
+
+ virtual void UpdateFrameAfterFrameChange() = 0;
+ virtual bool ShouldUseNativeFrame() const = 0;
+ virtual void FrameTypeChanged() = 0;
+
+ // Returns the Widget associated with this NativeWidget. This function is
+ // guaranteed to return non-NULL for the lifetime of the NativeWidget.
+ virtual Widget* GetWidget() = 0;
+ virtual const Widget* GetWidget() const = 0;
+
+ // Returns the NativeView/Window associated with this NativeWidget.
+ virtual gfx::NativeView GetNativeView() const = 0;
+ virtual gfx::NativeWindow GetNativeWindow() const = 0;
+
+ // Notifies the NativeWidget that a view was removed from the Widget's view
+ // hierarchy.
+ virtual void ViewRemoved(View* view) = 0;
+
+ // Sets/Gets a native window property on the underlying native window object.
+ // Returns NULL if the property does not exist. Setting the property value to
+ // NULL removes the property.
+ virtual void SetNativeWindowProperty(const char* name, void* value) = 0;
+ virtual void* GetNativeWindowProperty(const char* name) const = 0;
+
+ // Returns the native widget's tooltip manager. Called from the View hierarchy
+ // to update tooltips.
+ virtual TooltipManager* GetTooltipManager() const = 0;
+
+ // Returns true if a system screen reader is active for the NativeWidget.
+ virtual bool IsScreenReaderActive() const = 0;
+
+ // Notify native Accessibility clients of an event.
+ virtual void SendNativeAccessibilityEvent(
+ View* view,
+ ui::AccessibilityTypes::Event event_type) = 0;
+
+ // Sets or releases event capturing for this native widget.
+ virtual void SetMouseCapture() = 0;
+ virtual void ReleaseMouseCapture() = 0;
+
+ // Returns true if this native widget is capturing all events.
+ virtual bool HasMouseCapture() const = 0;
+
+ // Returns true if any mouse button is currently pressed.
+ virtual bool IsMouseButtonDown() const = 0;
+
+ // Returns the InputMethod for this native widget.
+ // Note that all widgets in a widget hierarchy share the same input method.
+ // TODO(suzhe): rename to GetInputMethod() when NativeWidget implementation
+ // class doesn't inherit Widget anymore.
+ virtual InputMethod* GetInputMethodNative() = 0;
+
+ // Sets a different InputMethod instance to this native widget. The instance
+ // must not be initialized, the ownership will be assumed by the native
+ // widget. It's only for testing purpose.
+ virtual void ReplaceInputMethod(InputMethod* input_method) = 0;
+
+ // Centers the window and sizes it to the specified size.
+ virtual void CenterWindow(const gfx::Size& size) = 0;
+
+ // Retrieves the window's current restored bounds and maximized state, for
+ // persisting.
+ virtual void GetWindowBoundsAndMaximizedState(gfx::Rect* bounds,
+ bool* maximized) const = 0;
+
+ // Sets the NativeWindow title.
+ virtual void SetWindowTitle(const std::wstring& title) = 0;
+
+ // Sets the Window icons. |window_icon| is a 16x16 icon suitable for use in
+ // a title bar. |app_icon| is a larger size for use in the host environment
+ // app switching UI.
+ virtual void SetWindowIcons(const SkBitmap& window_icon,
+ const SkBitmap& app_icon) = 0;
+
+ // Update native accessibility properties on the native window.
+ virtual void SetAccessibleName(const std::wstring& name) = 0;
+ virtual void SetAccessibleRole(ui::AccessibilityTypes::Role role) = 0;
+ virtual void SetAccessibleState(ui::AccessibilityTypes::State state) = 0;
+
+ enum ShowState {
+ SHOW_RESTORED,
+ SHOW_MAXIMIZED,
+ SHOW_INACTIVE
+ };
+
+ // Returns a handle for the underlying native widget that can be used for
+ // accelerated drawing.
+ virtual gfx::AcceleratedWidget GetAcceleratedWidget() = 0;
+
+ // Makes the NativeWindow modal.
+ virtual void BecomeModal() = 0;
+
+ // See method documentation in Widget.
+ virtual gfx::Rect GetWindowScreenBounds() const = 0;
+ virtual gfx::Rect GetClientAreaScreenBounds() const = 0;
+ virtual gfx::Rect GetRestoredBounds() const = 0;
+ virtual void SetBounds(const gfx::Rect& bounds) = 0;
+ virtual void SetSize(const gfx::Size& size) = 0;
+ virtual void SetBoundsConstrained(const gfx::Rect& bounds,
+ Widget* other_widget) = 0;
+ virtual void MoveAbove(gfx::NativeView native_view) = 0;
+ virtual void SetShape(gfx::NativeRegion shape) = 0;
+ virtual void Close() = 0;
+ virtual void CloseNow() = 0;
+ virtual void EnableClose(bool enable) = 0;
+ virtual void Show() = 0;
+ virtual void Hide() = 0;
+ virtual void ShowNativeWidget(ShowState state) = 0;
+ virtual bool IsVisible() const = 0;
+ virtual void Activate() = 0;
+ virtual void Deactivate() = 0;
+ virtual bool IsActive() const = 0;
+ virtual void SetAlwaysOnTop(bool always_on_top) = 0;
+ virtual void Maximize() = 0;
+ virtual void Minimize() = 0;
+ virtual bool IsMaximized() const = 0;
+ virtual bool IsMinimized() const = 0;
+ virtual void Restore() = 0;
+ virtual void SetFullscreen(bool fullscreen) = 0;
+ virtual bool IsFullscreen() const = 0;
+ virtual void SetOpacity(unsigned char opacity) = 0;
+ virtual void SetUseDragFrame(bool use_drag_frame) = 0;
+ virtual bool IsAccessibleWidget() const = 0;
+ virtual bool ContainsNativeView(gfx::NativeView native_view) const = 0;
+ virtual void RunShellDrag(View* view,
+ const ui::OSExchangeData& data,
+ int operation) = 0;
+ virtual void SchedulePaintInRect(const gfx::Rect& rect) = 0;
+ virtual void SetCursor(gfx::NativeCursor cursor) = 0;
+
+ // Overridden from NativeWidget:
+ virtual internal::NativeWidgetPrivate* AsNativeWidgetPrivate() OVERRIDE;
+};
+
+} // namespace internal
+} // namespace views
+
+#endif // VIEWS_WIDGET_NATIVE_WIDGET_PRIVATE_H_
diff --git a/views/widget/native_widget_test_utils.h b/views/widget/native_widget_test_utils.h
index ac3e5b4..2499a76 100644
--- a/views/widget/native_widget_test_utils.h
+++ b/views/widget/native_widget_test_utils.h
@@ -8,13 +8,13 @@
namespace views {
class View;
-class NativeWidget;
namespace internal {
+class NativeWidgetPrivate;
// Create dummy Widgets for use in testing.
-NativeWidget* CreateNativeWidget();
-NativeWidget* CreateNativeWidgetWithContents(View* contents_view);
-NativeWidget* CreateNativeWidgetWithParent(NativeWidget* parent);
+NativeWidgetPrivate* CreateNativeWidget();
+NativeWidgetPrivate* CreateNativeWidgetWithContents(View* contents_view);
+NativeWidgetPrivate* CreateNativeWidgetWithParent(NativeWidgetPrivate* parent);
} // namespace internal
} // namespace views
diff --git a/views/widget/native_widget_test_utils_gtk.cc b/views/widget/native_widget_test_utils_gtk.cc
index cd84b56..dbb1529 100644
--- a/views/widget/native_widget_test_utils_gtk.cc
+++ b/views/widget/native_widget_test_utils_gtk.cc
@@ -5,33 +5,33 @@
#include "views/widget/native_widget_test_utils.h"
#include "views/view.h"
-#include "views/widget/native_widget.h"
+#include "views/widget/native_widget_private.h"
#include "views/widget/widget.h"
namespace views {
namespace internal {
-NativeWidget* CreateNativeWidget() {
+NativeWidgetPrivate* CreateNativeWidget() {
return CreateNativeWidgetWithContents(new View);
}
-NativeWidget* CreateNativeWidgetWithContents(View* contents_view) {
+NativeWidgetPrivate* CreateNativeWidgetWithContents(View* contents_view) {
Widget* widget = new Widget;
Widget::InitParams params(Widget::InitParams::TYPE_POPUP);
params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
params.bounds = gfx::Rect(10, 10, 200, 200);
widget->Init(params);
- return widget->native_widget();
+ return widget->native_widget_private();
}
-NativeWidget* CreateNativeWidgetWithParent(NativeWidget* parent) {
+NativeWidgetPrivate* CreateNativeWidgetWithParent(NativeWidgetPrivate* parent) {
Widget* widget = new Widget;
Widget::InitParams params(Widget::InitParams::TYPE_CONTROL);
params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
params.parent = parent ? parent->GetWidget()->GetNativeView() : NULL;
params.bounds = gfx::Rect(10, 10, 200, 200);
widget->Init(params);
- return widget->native_widget();
+ return widget->native_widget_private();
}
} // namespace internal
diff --git a/views/widget/native_widget_test_utils_win.cc b/views/widget/native_widget_test_utils_win.cc
index 49cd063..b6a4184 100644
--- a/views/widget/native_widget_test_utils_win.cc
+++ b/views/widget/native_widget_test_utils_win.cc
@@ -5,26 +5,26 @@
#include "views/widget/native_widget_test_utils.h"
#include "views/view.h"
-#include "views/widget/native_widget.h"
+#include "views/widget/native_widget_private.h"
#include "views/widget/widget.h"
namespace views {
namespace internal {
-NativeWidget* CreateNativeWidget() {
+NativeWidgetPrivate* CreateNativeWidget() {
return CreateNativeWidgetWithContents(new View);
}
-NativeWidget* CreateNativeWidgetWithContents(View* contents_view) {
+NativeWidgetPrivate* CreateNativeWidgetWithContents(View* contents_view) {
Widget* widget = new Widget;
Widget::InitParams params(Widget::InitParams::TYPE_POPUP);
params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
params.bounds = gfx::Rect(10, 10, 200, 200);
widget->Init(params);
- return widget->native_widget();
+ return widget->native_widget_private();
}
-NativeWidget* CreateNativeWidgetWithParent(NativeWidget* parent) {
+NativeWidgetPrivate* CreateNativeWidgetWithParent(NativeWidgetPrivate* parent) {
Widget* widget = new Widget;
Widget::InitParams params(Widget::InitParams::TYPE_CONTROL);
params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
@@ -32,7 +32,7 @@ NativeWidget* CreateNativeWidgetWithParent(NativeWidget* parent) {
params.parent = parent ? parent->GetWidget()->GetNativeView() : NULL;
params.bounds = gfx::Rect(10, 10, 200, 200);
widget->Init(params);
- return widget->native_widget();
+ return widget->native_widget_private();
}
} // namespace internal
diff --git a/views/widget/native_widget_unittest.cc b/views/widget/native_widget_unittest.cc
index 7370840..158f7c6 100644
--- a/views/widget/native_widget_unittest.cc
+++ b/views/widget/native_widget_unittest.cc
@@ -6,7 +6,7 @@
#include "views/test/views_test_base.h"
#include "views/view.h"
#include "views/controls/native/native_view_host.h"
-#include "views/widget/native_widget.h"
+#include "views/widget/native_widget_private.h"
#include "views/widget/widget.h"
#include "views/widget/native_widget_test_utils.h"
@@ -14,20 +14,20 @@ namespace views {
class ScopedTestWidget {
public:
- ScopedTestWidget(NativeWidget* native_widget)
+ ScopedTestWidget(internal::NativeWidgetPrivate* native_widget)
: native_widget_(native_widget) {
}
~ScopedTestWidget() {
native_widget_->GetWidget()->CloseNow();
}
- NativeWidget* operator->() const {
+ internal::NativeWidgetPrivate* operator->() const {
return native_widget_.get();
}
- NativeWidget* get() const { return native_widget_.get(); }
+ internal::NativeWidgetPrivate* get() const { return native_widget_.get(); }
private:
- scoped_ptr<NativeWidget> native_widget_;
+ scoped_ptr<internal::NativeWidgetPrivate> native_widget_;
DISALLOW_COPY_AND_ASSIGN(ScopedTestWidget);
};
@@ -48,7 +48,7 @@ TEST_F(NativeWidgetTest, CreateNativeWidget) {
TEST_F(NativeWidgetTest, GetNativeWidgetForNativeView) {
ScopedTestWidget widget(internal::CreateNativeWidget());
EXPECT_EQ(widget.get(),
- NativeWidget::GetNativeWidgetForNativeView(
+ internal::NativeWidgetPrivate::GetNativeWidgetForNativeView(
widget->GetWidget()->GetNativeView()));
}
@@ -56,7 +56,7 @@ TEST_F(NativeWidgetTest, GetNativeWidgetForNativeView) {
TEST_F(NativeWidgetTest, GetTopLevelNativeWidget1) {
ScopedTestWidget widget(internal::CreateNativeWidget());
EXPECT_EQ(widget.get(),
- NativeWidget::GetTopLevelNativeWidget(
+ internal::NativeWidgetPrivate::GetTopLevelNativeWidget(
widget->GetWidget()->GetNativeView()));
}
@@ -70,7 +70,7 @@ TEST_F(NativeWidgetTest, GetTopLevelNativeWidget2) {
child_host->Attach(child_widget->GetWidget()->GetNativeView());
EXPECT_EQ(toplevel_widget.get(),
- NativeWidget::GetTopLevelNativeWidget(
+ internal::NativeWidgetPrivate::GetTopLevelNativeWidget(
child_widget->GetWidget()->GetNativeView()));
}
diff --git a/views/widget/native_widget_views.cc b/views/widget/native_widget_views.cc
index 3f400c4..438b755 100644
--- a/views/widget/native_widget_views.cc
+++ b/views/widget/native_widget_views.cc
@@ -319,12 +319,15 @@ void NativeWidgetViews::SetCursor(gfx::NativeCursor cursor) {
////////////////////////////////////////////////////////////////////////////////
// NativeWidgetViews, private:
-NativeWidget* NativeWidgetViews::GetParentNativeWidget() {
- return view_->GetWidget()->native_widget();
+internal::NativeWidgetPrivate* NativeWidgetViews::GetParentNativeWidget() {
+ return static_cast<internal::NativeWidgetPrivate*>(
+ view_->GetWidget()->native_widget());
}
-const NativeWidget* NativeWidgetViews::GetParentNativeWidget() const {
- return view_->GetWidget()->native_widget();
+const internal::NativeWidgetPrivate*
+ NativeWidgetViews::GetParentNativeWidget() const {
+ return static_cast<const internal::NativeWidgetPrivate*>(
+ view_->GetWidget()->native_widget());
}
} // namespace views
diff --git a/views/widget/native_widget_views.h b/views/widget/native_widget_views.h
index 1b0a47f..db6e097 100644
--- a/views/widget/native_widget_views.h
+++ b/views/widget/native_widget_views.h
@@ -7,7 +7,7 @@
#pragma once
#include "base/message_loop.h"
-#include "views/widget/native_widget.h"
+#include "views/widget/native_widget_private.h"
namespace views {
namespace internal {
@@ -19,7 +19,7 @@ class NativeWidgetView;
//
// A NativeWidget implementation that uses another View as its native widget.
//
-class NativeWidgetViews : public NativeWidget {
+class NativeWidgetViews : public internal::NativeWidgetPrivate {
public:
NativeWidgetViews(View* host, internal::NativeWidgetDelegate* delegate);
virtual ~NativeWidgetViews();
@@ -33,7 +33,7 @@ class NativeWidgetViews : public NativeWidget {
internal::NativeWidgetDelegate* delegate() { return delegate_; }
protected:
- // Overridden from NativeWidget:
+ // Overridden from internal::NativeWidgetPrivate:
virtual void InitNativeWidget(const Widget::InitParams& params) OVERRIDE;
virtual NonClientFrameView* CreateNonClientFrameView() OVERRIDE;
virtual void UpdateFrameAfterFrameChange() OVERRIDE;
@@ -106,8 +106,8 @@ class NativeWidgetViews : public NativeWidget {
virtual void SetCursor(gfx::NativeCursor cursor) OVERRIDE;
private:
- NativeWidget* GetParentNativeWidget();
- const NativeWidget* GetParentNativeWidget() const;
+ internal::NativeWidgetPrivate* GetParentNativeWidget();
+ const internal::NativeWidgetPrivate* GetParentNativeWidget() const;
internal::NativeWidgetDelegate* delegate_;
diff --git a/views/widget/native_widget_win.cc b/views/widget/native_widget_win.cc
index dce389b..cb1482d 100644
--- a/views/widget/native_widget_win.cc
+++ b/views/widget/native_widget_win.cc
@@ -143,15 +143,13 @@ bool ProcessChildWindowMessage(UINT message,
return false;
}
-// Enumeration callback for NativeWidget::GetAllNativeWidgets(). Called for each
+// Enumeration callback for NativeWidget::GetAllChildWidgets(). Called for each
// child HWND beneath the original HWND.
BOOL CALLBACK EnumerateChildWindowsForNativeWidgets(HWND hwnd, LPARAM l_param) {
- NativeWidget* native_widget =
- NativeWidget::GetNativeWidgetForNativeView(hwnd);
- if (native_widget) {
- NativeWidget::NativeWidgets* native_widgets =
- reinterpret_cast<NativeWidget::NativeWidgets*>(l_param);
- native_widgets->insert(native_widget);
+ Widget* widget = Widget::GetWidgetForNativeView(hwnd);
+ if (widget) {
+ Widget::Widgets* widgets = reinterpret_cast<Widget::Widgets*>(l_param);
+ widgets->insert(widget);
}
return TRUE;
}
@@ -2376,13 +2374,9 @@ void Widget::NotifyLocaleChanged() {
namespace {
BOOL CALLBACK WindowCallbackProc(HWND hwnd, LPARAM lParam) {
- NativeWidget* native_widget =
- NativeWidget::GetNativeWidgetForNativeView(hwnd);
- if (native_widget) {
- Widget* widget = native_widget->GetWidget();
- if (widget->is_secondary_widget())
- widget->Close();
- }
+ Widget* widget = Widget::GetWidgetForNativeView(hwnd);
+ if (widget && widget->is_secondary_widget())
+ widget->Close();
return TRUE;
}
} // namespace
@@ -2414,30 +2408,32 @@ bool Widget::ConvertRect(const Widget* source,
return false;
}
+namespace internal {
+
////////////////////////////////////////////////////////////////////////////////
-// NativeWidget, public:
+// internal::NativeWidgetPrivate, public:
// static
-NativeWidget* NativeWidget::CreateNativeWidget(
+NativeWidgetPrivate* NativeWidgetPrivate::CreateNativeWidget(
internal::NativeWidgetDelegate* delegate) {
return new NativeWidgetWin(delegate);
}
// static
-NativeWidget* NativeWidget::GetNativeWidgetForNativeView(
+NativeWidgetPrivate* NativeWidgetPrivate::GetNativeWidgetForNativeView(
gfx::NativeView native_view) {
return reinterpret_cast<NativeWidgetWin*>(
ViewProp::GetValue(native_view, kNativeWidgetKey));
}
// static
-NativeWidget* NativeWidget::GetNativeWidgetForNativeWindow(
+NativeWidgetPrivate* NativeWidgetPrivate::GetNativeWidgetForNativeWindow(
gfx::NativeWindow native_window) {
return GetNativeWidgetForNativeView(native_window);
}
// static
-NativeWidget* NativeWidget::GetTopLevelNativeWidget(
+NativeWidgetPrivate* NativeWidgetPrivate::GetTopLevelNativeWidget(
gfx::NativeView native_view) {
if (!native_view)
return NULL;
@@ -2447,13 +2443,13 @@ NativeWidget* NativeWidget::GetTopLevelNativeWidget(
if (!root)
return NULL;
- NativeWidget* widget = GetNativeWidgetForNativeView(root);
+ NativeWidgetPrivate* widget = GetNativeWidgetForNativeView(root);
if (widget)
return widget;
// Second, try to locate the last Widget window in the parent hierarchy.
HWND parent_hwnd = native_view;
- NativeWidget* parent_widget;
+ NativeWidgetPrivate* parent_widget;
do {
parent_widget = GetNativeWidgetForNativeView(parent_hwnd);
if (parent_widget) {
@@ -2466,21 +2462,21 @@ NativeWidget* NativeWidget::GetTopLevelNativeWidget(
}
// static
-void NativeWidget::GetAllNativeWidgets(gfx::NativeView native_view,
- NativeWidgets* children) {
+void NativeWidgetPrivate::GetAllChildWidgets(gfx::NativeView native_view,
+ Widget::Widgets* children) {
if (!native_view)
return;
- NativeWidget* native_widget = GetNativeWidgetForNativeView(native_view);
- if (native_widget)
- children->insert(native_widget);
+ Widget* widget = Widget::GetWidgetForNativeView(native_view);
+ if (widget)
+ children->insert(widget);
EnumChildWindows(native_view, EnumerateChildWindowsForNativeWidgets,
- reinterpret_cast<LPARAM>(children));
+ reinterpret_cast<LPARAM>(children));
}
// static
-void NativeWidget::ReparentNativeView(gfx::NativeView native_view,
- gfx::NativeView new_parent) {
+void NativeWidgetPrivate::ReparentNativeView(gfx::NativeView native_view,
+ gfx::NativeView new_parent) {
if (!native_view)
return;
@@ -2488,27 +2484,26 @@ void NativeWidget::ReparentNativeView(gfx::NativeView native_view,
if (previous_parent == new_parent)
return;
- NativeWidgets widgets;
- GetAllNativeWidgets(native_view, &widgets);
+ Widget::Widgets widgets;
+ GetAllChildWidgets(native_view, &widgets);
// First notify all the widgets that they are being disassociated
// from their previous parent.
- for (NativeWidgets::iterator it = widgets.begin();
+ for (Widget::Widgets::iterator it = widgets.begin();
it != widgets.end(); ++it) {
// TODO(beng): Rename this notification to NotifyNativeViewChanging()
// and eliminate the bool parameter.
- (*it)->GetWidget()->NotifyNativeViewHierarchyChanged(false,
- previous_parent);
+ (*it)->NotifyNativeViewHierarchyChanged(false, previous_parent);
}
::SetParent(native_view, new_parent);
// And now, notify them that they have a brand new parent.
- for (NativeWidgets::iterator it = widgets.begin();
+ for (Widget::Widgets::iterator it = widgets.begin();
it != widgets.end(); ++it) {
- (*it)->GetWidget()->NotifyNativeViewHierarchyChanged(true,
- new_parent);
+ (*it)->NotifyNativeViewHierarchyChanged(true, new_parent);
}
}
+} // namespace internal
} // namespace views
diff --git a/views/widget/native_widget_win.h b/views/widget/native_widget_win.h
index 5162988..dadbc38 100644
--- a/views/widget/native_widget_win.h
+++ b/views/widget/native_widget_win.h
@@ -22,7 +22,7 @@
#include "views/focus/focus_manager.h"
#include "views/ime/input_method_delegate.h"
#include "views/layout/layout_manager.h"
-#include "views/widget/native_widget.h"
+#include "views/widget/native_widget_private.h"
namespace ui {
class ViewProp;
@@ -84,7 +84,7 @@ const int WM_NCUAHDRAWFRAME = 0xAF;
//
///////////////////////////////////////////////////////////////////////////////
class NativeWidgetWin : public ui::WindowImpl,
- public NativeWidget,
+ public internal::NativeWidgetPrivate,
public MessageLoopForUI::Observer,
public internal::InputMethodDelegate {
public:
@@ -187,7 +187,7 @@ class NativeWidgetWin : public ui::WindowImpl,
return ::GetClientRect(GetNativeView(), rect);
}
- // Overridden from NativeWidget:
+ // Overridden from internal::NativeWidgetPrivate:
virtual void InitNativeWidget(const Widget::InitParams& params) OVERRIDE;
virtual NonClientFrameView* CreateNonClientFrameView() OVERRIDE;
virtual void UpdateFrameAfterFrameChange() OVERRIDE;
diff --git a/views/widget/widget.cc b/views/widget/widget.cc
index 5000156..8b19ce2 100644
--- a/views/widget/widget.cc
+++ b/views/widget/widget.cc
@@ -15,7 +15,7 @@
#include "views/views_delegate.h"
#include "views/widget/default_theme_provider.h"
#include "views/widget/root_view.h"
-#include "views/widget/native_widget.h"
+#include "views/widget/native_widget_private.h"
#include "views/widget/widget_delegate.h"
#include "views/window/custom_frame_view.h"
@@ -192,12 +192,40 @@ bool Widget::IsPureViews() {
// static
Widget* Widget::GetWidgetForNativeView(gfx::NativeView native_view) {
- NativeWidget* native_widget =
- NativeWidget::GetNativeWidgetForNativeView(native_view);
+ internal::NativeWidgetPrivate* native_widget =
+ internal::NativeWidgetPrivate::GetNativeWidgetForNativeView(native_view);
return native_widget ? native_widget->GetWidget() : NULL;
}
// static
+Widget* Widget::GetWidgetForNativeWindow(gfx::NativeWindow native_window) {
+ internal::NativeWidgetPrivate* native_widget =
+ internal::NativeWidgetPrivate::GetNativeWidgetForNativeWindow(
+ native_window);
+ return native_widget ? native_widget->GetWidget() : NULL;
+}
+
+// static
+Widget* Widget::GetTopLevelWidgetForNativeView(gfx::NativeView native_view) {
+ internal::NativeWidgetPrivate* native_widget =
+ internal::NativeWidgetPrivate::GetTopLevelNativeWidget(native_view);
+ return native_widget ? native_widget->GetWidget() : NULL;
+}
+
+
+// static
+void Widget::GetAllChildWidgets(gfx::NativeView native_view,
+ Widgets* children) {
+ internal::NativeWidgetPrivate::GetAllChildWidgets(native_view, children);
+}
+
+// static
+void Widget::ReparentNativeView(gfx::NativeView native_view,
+ gfx::NativeView new_parent) {
+ internal::NativeWidgetPrivate::ReparentNativeView(native_view, new_parent);
+}
+
+// static
int Widget::GetLocalizedContentsWidth(int col_resource_id) {
return ui::GetLocalizedContentsWidthForFont(col_resource_id,
ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::BaseFont));
@@ -220,9 +248,9 @@ void Widget::Init(const InitParams& params) {
widget_delegate_ =
params.delegate ? params.delegate : new DefaultWidgetDelegate;
ownership_ = params.ownership;
- native_widget_ =
- params.native_widget ? params.native_widget
- : NativeWidget::CreateNativeWidget(this);
+ native_widget_ = params.native_widget ?
+ params.native_widget->AsNativeWidgetPrivate() :
+ internal::NativeWidgetPrivate::CreateNativeWidget(this);
GetRootView();
default_theme_provider_.reset(new DefaultThemeProvider);
if (params.type == InitParams::TYPE_MENU)
@@ -287,8 +315,8 @@ Widget* Widget::GetTopLevelWidget() {
}
const Widget* Widget::GetTopLevelWidget() const {
- NativeWidget* native_widget =
- NativeWidget::GetTopLevelNativeWidget(GetNativeView());
+ internal::NativeWidgetPrivate* native_widget =
+ internal::NativeWidgetPrivate::GetTopLevelNativeWidget(GetNativeView());
return native_widget ? native_widget->GetWidget() : NULL;
}
@@ -363,8 +391,8 @@ void Widget::EnableClose(bool enable) {
void Widget::Show() {
if (non_client_view_) {
native_widget_->ShowNativeWidget(
- saved_maximized_state_ ? NativeWidget::SHOW_MAXIMIZED
- : NativeWidget::SHOW_RESTORED);
+ saved_maximized_state_ ? internal::NativeWidgetPrivate::SHOW_MAXIMIZED
+ : internal::NativeWidgetPrivate::SHOW_RESTORED);
// |saved_maximized_state_| only applies the first time the window is shown.
// If we don't reset the value the window will be shown maximized every time
// it is subsequently shown after being hidden.
@@ -379,7 +407,8 @@ void Widget::Hide() {
}
void Widget::ShowInactive() {
- native_widget_->ShowNativeWidget(NativeWidget::SHOW_INACTIVE);
+ native_widget_->ShowNativeWidget(
+ internal::NativeWidgetPrivate::SHOW_INACTIVE);
}
void Widget::Activate() {
@@ -482,7 +511,7 @@ FocusManager* Widget::GetFocusManager() {
InputMethod* Widget::GetInputMethod() {
Widget* toplevel_widget = GetTopLevelWidget();
return toplevel_widget ?
- toplevel_widget->native_widget()->GetInputMethodNative() : NULL;
+ toplevel_widget->native_widget_->GetInputMethodNative() : NULL;
}
bool Widget::ContainsNativeView(gfx::NativeView native_view) {
@@ -519,6 +548,14 @@ void Widget::ResetLastMouseMoveFlag() {
last_mouse_event_was_move_ = false;
}
+void Widget::SetNativeWindowProperty(const char* name, void* value) {
+ native_widget_->SetNativeWindowProperty(name, value);
+}
+
+void* Widget::GetNativeWindowProperty(const char* name) const {
+ return native_widget_->GetNativeWindowProperty(name);
+}
+
void Widget::UpdateWindowTitle() {
if (!non_client_view_)
return;
@@ -609,6 +646,14 @@ void Widget::NotifyAccessibilityEvent(
native_widget_->SendNativeAccessibilityEvent(view, event_type);
}
+const NativeWidget* Widget::native_widget() const {
+ return native_widget_;
+}
+
+NativeWidget* Widget::native_widget() {
+ return native_widget_;
+}
+
const Event* Widget::GetCurrentEvent() {
return event_stack_.empty() ? NULL : event_stack_.top()->event();
}
@@ -931,5 +976,14 @@ void Widget::SetInitialBounds(const gfx::Rect& bounds) {
}
}
+namespace internal {
+
+////////////////////////////////////////////////////////////////////////////////
+// internal::NativeWidgetPrivate, NativeWidget implementation:
+
+internal::NativeWidgetPrivate* NativeWidgetPrivate::AsNativeWidgetPrivate() {
+ return this;
+}
+} // namespace internal
} // namespace views
diff --git a/views/widget/widget.h b/views/widget/widget.h
index 4220cc6..1e1b6f8 100644
--- a/views/widget/widget.h
+++ b/views/widget/widget.h
@@ -60,6 +60,7 @@ class TooltipManager;
class View;
class WidgetDelegate;
namespace internal {
+class NativeWidgetPrivate;
class RootView;
}
@@ -91,6 +92,8 @@ class RootView;
class Widget : public internal::NativeWidgetDelegate,
public FocusTraversable {
public:
+ typedef std::set<Widget*> Widgets;
+
enum FrameType {
FRAME_TYPE_DEFAULT, // Use whatever the default would be.
FRAME_TYPE_FORCE_CUSTOM, // Force the custom frame.
@@ -180,9 +183,25 @@ class Widget : public internal::NativeWidgetDelegate,
static void SetPureViews(bool pure);
static bool IsPureViews();
- // Passes through to NativeWidget::GetWidgetForNativeView().
+ // Retrieves the Widget implementation associated with the given
+ // NativeView or Window, or NULL if the supplied handle has no associated
+ // Widget.
static Widget* GetWidgetForNativeView(gfx::NativeView native_view);
+ static Widget* GetWidgetForNativeWindow(gfx::NativeWindow native_window);
+
+ // Retrieves the highest Widget in a native view hierarchy starting at
+ // |native_view|, which may or may not be a Widget itself.
+ static Widget* GetTopLevelWidgetForNativeView(gfx::NativeView native_view);
+
+ // Returns all Widgets in |native_view|'s hierarchy, including itself if
+ // it is one.
+ static void GetAllChildWidgets(gfx::NativeView native_view,
+ Widgets* children);
+ // Re-parent a NativeView and notify all Widgets in |native_view|'s hierarchy
+ // of the change.
+ static void ReparentNativeView(gfx::NativeView native_view,
+ gfx::NativeView new_parent);
// Returns the preferred size of the contents view of this window based on
// its localized size data. The width in cols is held in a localized string
@@ -390,6 +409,12 @@ class Widget : public internal::NativeWidgetDelegate,
// to cause the close button to highlight.
void ResetLastMouseMoveFlag();
+ // Sets/Gets a native window property on the underlying native window object.
+ // Returns NULL if the property does not exist. Setting the property value to
+ // NULL removes the property.
+ void SetNativeWindowProperty(const char* name, void* value);
+ void* GetNativeWindowProperty(const char* name) const;
+
// Tell the window to update its title from the delegate.
void UpdateWindowTitle();
@@ -462,8 +487,15 @@ class Widget : public internal::NativeWidgetDelegate,
ui::AccessibilityTypes::Event event_type,
bool send_native_event);
- const NativeWidget* native_widget() const { return native_widget_; }
- NativeWidget* native_widget() { return native_widget_; }
+ const NativeWidget* native_widget() const;
+ NativeWidget* native_widget();
+
+ internal::NativeWidgetPrivate* native_widget_private() {
+ return native_widget_;
+ }
+ const internal::NativeWidgetPrivate* native_widget_private() const {
+ return native_widget_;
+ }
// Returns the current event being processed. If there are multiple events
// being processed at the same time (e.g. one event triggers another event),
@@ -553,7 +585,7 @@ class Widget : public internal::NativeWidgetDelegate,
// Sizes and positions the window just after it is created.
void SetInitialBounds(const gfx::Rect& bounds);
- NativeWidget* native_widget_;
+ internal::NativeWidgetPrivate* native_widget_;
// Non-owned pointer to the Widget's delegate. May be NULL if no delegate is
// being used.