summaryrefslogtreecommitdiffstats
path: root/views/widget
diff options
context:
space:
mode:
authorben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-01 22:28:44 +0000
committerben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-01 22:28:44 +0000
commit449a1685341fb38c088bb664c88b536a48c2066d (patch)
tree84df488c8c789f67ff2827aef339b4926025f5ef /views/widget
parent14d4f99f31f9365a20d5726b44bcb3e53b5b65f9 (diff)
downloadchromium_src-449a1685341fb38c088bb664c88b536a48c2066d.zip
chromium_src-449a1685341fb38c088bb664c88b536a48c2066d.tar.gz
chromium_src-449a1685341fb38c088bb664c88b536a48c2066d.tar.bz2
Consolidate cross platform logic into MenuHost.
BUG=72040 TEST=none Review URL: http://codereview.chromium.org/6690054 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@80232 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/widget')
-rw-r--r--views/widget/native_widget.h5
-rw-r--r--views/widget/widget.cc4
-rw-r--r--views/widget/widget.h3
-rw-r--r--views/widget/widget_gtk.cc42
-rw-r--r--views/widget/widget_gtk.h4
-rw-r--r--views/widget/widget_win.cc108
-rw-r--r--views/widget/widget_win.h4
7 files changed, 90 insertions, 80 deletions
diff --git a/views/widget/native_widget.h b/views/widget/native_widget.h
index d9a1184..c46aff3 100644
--- a/views/widget/native_widget.h
+++ b/views/widget/native_widget.h
@@ -9,6 +9,7 @@
#include <set>
#include "ui/gfx/native_widget_types.h"
+#include "views/widget/widget.h"
namespace gfx {
class Rect;
@@ -22,7 +23,6 @@ namespace views {
class InputMethod;
class TooltipManager;
-class Widget;
////////////////////////////////////////////////////////////////////////////////
// NativeWidget interface
@@ -58,6 +58,9 @@ class NativeWidget {
static void ReparentNativeView(gfx::NativeView native_view,
gfx::NativeView new_parent);
+ // Sets the create params for the NativeWidget.
+ virtual void SetCreateParams(const Widget::CreateParams& params) = 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;
diff --git a/views/widget/widget.cc b/views/widget/widget.cc
index 320f69f..e707a2b 100644
--- a/views/widget/widget.cc
+++ b/views/widget/widget.cc
@@ -58,6 +58,10 @@ Widget::Widget()
Widget::~Widget() {
}
+void Widget::SetCreateParams(const CreateParams& params) {
+ native_widget_->SetCreateParams(params);
+}
+
// Unconverted methods (see header) --------------------------------------------
void Widget::Init(gfx::NativeView parent, const gfx::Rect& bounds) {
diff --git a/views/widget/widget.h b/views/widget/widget.h
index 8bf3ec0..e4c1035 100644
--- a/views/widget/widget.h
+++ b/views/widget/widget.h
@@ -104,6 +104,9 @@ class Widget : public internal::NativeWidgetDelegate,
const Widget* target,
gfx::Rect* rect);
+ // Sets the creation params for the Widget.
+ void SetCreateParams(const CreateParams& params);
+
// Unconverted methods -------------------------------------------------------
// TODO(beng):
diff --git a/views/widget/widget_gtk.cc b/views/widget/widget_gtk.cc
index 00824f5..da998b4 100644
--- a/views/widget/widget_gtk.cc
+++ b/views/widget/widget_gtk.cc
@@ -304,26 +304,6 @@ WidgetGtk::~WidgetGtk() {
ActiveWindowWatcherX::RemoveObserver(this);
}
-void WidgetGtk::SetCreateParams(const CreateParams& params) {
- // Set non-style attributes.
- set_delete_on_destroy(params.delete_on_destroy);
-
- if (params.transparent)
- MakeTransparent();
- if (!params.accept_events)
- MakeIgnoreEvents();
-
- if (params.type == CreateParams::TYPE_MENU) {
- GdkEvent* event = gtk_get_current_event();
- if (event) {
- is_mouse_button_pressed_ = event->type == GDK_BUTTON_PRESS ||
- event->type == GDK_2BUTTON_PRESS ||
- event->type == GDK_3BUTTON_PRESS;
- gdk_event_free(event);
- }
- }
-}
-
GtkWindow* WidgetGtk::GetTransientParent() const {
return (type_ != TYPE_CHILD && widget_) ?
gtk_window_get_transient_for(GTK_WINDOW(widget_)) : NULL;
@@ -749,6 +729,28 @@ void WidgetGtk::UpdateFreezeUpdatesProperty(GtkWindow* window, bool enable) {
////////////////////////////////////////////////////////////////////////////////
// WidgetGtk, NativeWidget implementation:
+void WidgetGtk::SetCreateParams(const CreateParams& params) {
+ DCHECK(!GetNativeView());
+
+ // Set non-style attributes.
+ set_delete_on_destroy(params.delete_on_destroy);
+
+ if (params.transparent)
+ MakeTransparent();
+ if (!params.accept_events)
+ MakeIgnoreEvents();
+
+ if (params.type == CreateParams::TYPE_MENU) {
+ GdkEvent* event = gtk_get_current_event();
+ if (event) {
+ is_mouse_button_pressed_ = event->type == GDK_BUTTON_PRESS ||
+ event->type == GDK_2BUTTON_PRESS ||
+ event->type == GDK_3BUTTON_PRESS;
+ gdk_event_free(event);
+ }
+ }
+}
+
Widget* WidgetGtk::GetWidget() {
return this;
}
diff --git a/views/widget/widget_gtk.h b/views/widget/widget_gtk.h
index 323f886..4028997 100644
--- a/views/widget/widget_gtk.h
+++ b/views/widget/widget_gtk.h
@@ -67,9 +67,6 @@ class WidgetGtk : public Widget,
explicit WidgetGtk(Type type);
virtual ~WidgetGtk();
- // Initializes native widget properties based on |params|.
- void SetCreateParams(const CreateParams& params);
-
// Marks this window as transient to its parent. A window that is transient
// to its parent results in the parent rendering active when the child is
// active.
@@ -191,6 +188,7 @@ class WidgetGtk : public Widget,
static void UpdateFreezeUpdatesProperty(GtkWindow* window, bool enable);
// Overridden from NativeWidget:
+ virtual void SetCreateParams(const CreateParams& params) OVERRIDE;
virtual Widget* GetWidget() OVERRIDE;
virtual void SetNativeWindowProperty(const char* name, void* value) OVERRIDE;
virtual void* GetNativeWindowProperty(const char* name) OVERRIDE;
diff --git a/views/widget/widget_win.cc b/views/widget/widget_win.cc
index 1cadfb1..3c526b6 100644
--- a/views/widget/widget_win.cc
+++ b/views/widget/widget_win.cc
@@ -157,59 +157,6 @@ WidgetWin::~WidgetWin() {
DestroyRootView();
}
-void WidgetWin::SetCreateParams(const CreateParams& params) {
- // Set non-style attributes.
- set_delete_on_destroy(params.delete_on_destroy);
-
- DWORD style = WS_CLIPCHILDREN | WS_CLIPSIBLINGS;
- DWORD ex_style = 0;
- DWORD class_style = CS_DBLCLKS;
-
- // Set type-independent style attributes.
- if (params.child)
- style |= WS_CHILD | WS_VISIBLE;
- if (!params.accept_events)
- ex_style |= WS_EX_TRANSPARENT;
- if (!params.can_activate)
- ex_style |= WS_EX_NOACTIVATE;
- if (params.keep_on_top)
- ex_style |= WS_EX_TOPMOST;
- if (params.mirror_origin_in_rtl)
- ex_style |= l10n_util::GetExtendedTooltipStyles();
- if (params.transparent)
- ex_style |= WS_EX_LAYERED;
- if (params.has_dropshadow) {
- class_style |= (base::win::GetVersion() < base::win::VERSION_XP) ?
- 0 : CS_DROPSHADOW;
- }
-
- // Set type-dependent style attributes.
- switch (params.type) {
- case CreateParams::TYPE_WINDOW:
- case CreateParams::TYPE_CONTROL:
- break;
- case CreateParams::TYPE_POPUP:
- style |= WS_POPUP;
- ex_style |= WS_EX_TOOLWINDOW;
- break;
- case CreateParams::TYPE_MENU:
- style |= WS_POPUP;
- is_mouse_button_pressed_ =
- ((GetKeyState(VK_LBUTTON) & 0x80) ||
- (GetKeyState(VK_RBUTTON) & 0x80) ||
- (GetKeyState(VK_MBUTTON) & 0x80) ||
- (GetKeyState(VK_XBUTTON1) & 0x80) ||
- (GetKeyState(VK_XBUTTON2) & 0x80));
- break;
- default:
- NOTREACHED();
- }
-
- set_initial_class_style(class_style);
- set_window_style(style);
- set_window_ex_style(ex_style);
-}
-
// static
WidgetWin* WidgetWin::GetWidget(HWND hwnd) {
// TODO(jcivelli): http://crbug.com/44499 We need a way to test that hwnd is
@@ -297,6 +244,61 @@ void WidgetWin::ViewHierarchyChanged(bool is_add, View* parent,
////////////////////////////////////////////////////////////////////////////////
// WidgetWin, NativeWidget implementation:
+void WidgetWin::SetCreateParams(const CreateParams& params) {
+ DCHECK(!GetNativeView());
+
+ // Set non-style attributes.
+ set_delete_on_destroy(params.delete_on_destroy);
+
+ DWORD style = WS_CLIPCHILDREN | WS_CLIPSIBLINGS;
+ DWORD ex_style = 0;
+ DWORD class_style = CS_DBLCLKS;
+
+ // Set type-independent style attributes.
+ if (params.child)
+ style |= WS_CHILD | WS_VISIBLE;
+ if (!params.accept_events)
+ ex_style |= WS_EX_TRANSPARENT;
+ if (!params.can_activate)
+ ex_style |= WS_EX_NOACTIVATE;
+ if (params.keep_on_top)
+ ex_style |= WS_EX_TOPMOST;
+ if (params.mirror_origin_in_rtl)
+ ex_style |= l10n_util::GetExtendedTooltipStyles();
+ if (params.transparent)
+ ex_style |= WS_EX_LAYERED;
+ if (params.has_dropshadow) {
+ class_style |= (base::win::GetVersion() < base::win::VERSION_XP) ?
+ 0 : CS_DROPSHADOW;
+ }
+
+ // Set type-dependent style attributes.
+ switch (params.type) {
+ case CreateParams::TYPE_WINDOW:
+ case CreateParams::TYPE_CONTROL:
+ break;
+ case CreateParams::TYPE_POPUP:
+ style |= WS_POPUP;
+ ex_style |= WS_EX_TOOLWINDOW;
+ break;
+ case CreateParams::TYPE_MENU:
+ style |= WS_POPUP;
+ is_mouse_button_pressed_ =
+ ((GetKeyState(VK_LBUTTON) & 0x80) ||
+ (GetKeyState(VK_RBUTTON) & 0x80) ||
+ (GetKeyState(VK_MBUTTON) & 0x80) ||
+ (GetKeyState(VK_XBUTTON1) & 0x80) ||
+ (GetKeyState(VK_XBUTTON2) & 0x80));
+ break;
+ default:
+ NOTREACHED();
+ }
+
+ set_initial_class_style(class_style);
+ set_window_style(style);
+ set_window_ex_style(ex_style);
+}
+
Widget* WidgetWin::GetWidget() {
return this;
}
diff --git a/views/widget/widget_win.h b/views/widget/widget_win.h
index 6c72a22..c7b83e8 100644
--- a/views/widget/widget_win.h
+++ b/views/widget/widget_win.h
@@ -88,9 +88,6 @@ class WidgetWin : public ui::WindowImpl,
WidgetWin();
virtual ~WidgetWin();
- // Initializes native widget properties based on |params|.
- void SetCreateParams(const CreateParams& params);
-
// Returns the Widget associated with the specified HWND (if any).
static WidgetWin* GetWidget(HWND hwnd);
@@ -203,6 +200,7 @@ class WidgetWin : public ui::WindowImpl,
}
// Overridden from NativeWidget:
+ virtual void SetCreateParams(const Widget::CreateParams& params) OVERRIDE;
virtual Widget* GetWidget() OVERRIDE;
virtual void SetNativeWindowProperty(const char* name, void* value) OVERRIDE;
virtual void* GetNativeWindowProperty(const char* name) OVERRIDE;