summaryrefslogtreecommitdiffstats
path: root/views
diff options
context:
space:
mode:
Diffstat (limited to 'views')
-rw-r--r--views/controls/menu/menu_host_gtk.cc4
-rw-r--r--views/controls/menu/menu_host_win.cc16
-rw-r--r--views/controls/textfield/native_textfield_views_unittest.cc8
-rw-r--r--views/examples/widget_example.cc36
-rw-r--r--views/examples/widget_example.h9
-rw-r--r--views/widget/widget.cc23
-rw-r--r--views/widget/widget.h51
-rw-r--r--views/widget/widget_gtk.cc21
-rw-r--r--views/widget/widget_gtk.h3
-rw-r--r--views/widget/widget_win.cc66
-rw-r--r--views/widget/widget_win.h3
-rw-r--r--views/window/window.cc9
-rw-r--r--views/window/window.h4
-rw-r--r--views/window/window_gtk.cc2
-rw-r--r--views/window/window_win.cc2
15 files changed, 155 insertions, 102 deletions
diff --git a/views/controls/menu/menu_host_gtk.cc b/views/controls/menu/menu_host_gtk.cc
index 8679490..5552fbe 100644
--- a/views/controls/menu/menu_host_gtk.cc
+++ b/views/controls/menu/menu_host_gtk.cc
@@ -40,6 +40,10 @@ MenuHostGtk::MenuHostGtk(SubmenuView* submenu)
}
gdk_event_free(event);
}
+ CreateParams params;
+ params.type = CreateParams::TYPE_MENU;
+ params.has_dropshadow = true;
+ SetCreateParams(params);
}
MenuHostGtk::~MenuHostGtk() {
diff --git a/views/controls/menu/menu_host_win.cc b/views/controls/menu/menu_host_win.cc
index 1beda38..3e77287 100644
--- a/views/controls/menu/menu_host_win.cc
+++ b/views/controls/menu/menu_host_win.cc
@@ -21,18 +21,10 @@ MenuHostWin::MenuHostWin(SubmenuView* submenu)
: destroying_(false),
submenu_(submenu),
owns_capture_(false) {
- set_window_style(WS_POPUP);
- set_initial_class_style(
- (base::win::GetVersion() < base::win::VERSION_XP) ?
- 0 : CS_DROPSHADOW);
- is_mouse_down_ =
- ((GetKeyState(VK_LBUTTON) & 0x80) ||
- (GetKeyState(VK_RBUTTON) & 0x80) ||
- (GetKeyState(VK_MBUTTON) & 0x80) ||
- (GetKeyState(VK_XBUTTON1) & 0x80) ||
- (GetKeyState(VK_XBUTTON2) & 0x80));
- // Mouse clicks shouldn't give us focus.
- set_window_ex_style(WS_EX_TOPMOST | WS_EX_NOACTIVATE);
+ CreateParams params;
+ params.type = CreateParams::TYPE_MENU;
+ params.has_dropshadow = true;
+ SetCreateParams(params);
}
MenuHostWin::~MenuHostWin() {
diff --git a/views/controls/textfield/native_textfield_views_unittest.cc b/views/controls/textfield/native_textfield_views_unittest.cc
index b284e6e..417a4b9 100644
--- a/views/controls/textfield/native_textfield_views_unittest.cc
+++ b/views/controls/textfield/native_textfield_views_unittest.cc
@@ -76,11 +76,9 @@ class NativeTextfieldViewsTest : public ViewsTestBase,
ASSERT_FALSE(textfield_);
textfield_ = new Textfield(style);
textfield_->SetController(this);
- widget_ = Widget::CreatePopupWidget(
- Widget::NotTransparent,
- Widget::AcceptEvents,
- Widget::DeleteOnDestroy,
- Widget::DontMirrorOriginInRTL);
+ Widget::CreateParams params(Widget::CreateParams::TYPE_POPUP);
+ params.mirror_origin_in_rtl = false;
+ widget_ = Widget::CreatePopupWidget(params);
widget_->Init(NULL, gfx::Rect(100, 100, 100, 100));
View* container = new View();
widget_->SetContentsView(container);
diff --git a/views/examples/widget_example.cc b/views/examples/widget_example.cc
index 65de2a3..7b53a69 100644
--- a/views/examples/widget_example.cc
+++ b/views/examples/widget_example.cc
@@ -79,9 +79,7 @@ void WidgetExample::BuildButton(views::View* container,
container->AddChildView(button);
}
-void WidgetExample::InitWidget(
- views::Widget* widget,
- const views::Widget::TransparencyParam transparency) {
+void WidgetExample::InitWidget(views::Widget* widget, bool transparent) {
// Add view/native buttons to close the popup widget.
views::TextButton* close_button = new views::TextButton(this, L"Close");
close_button->set_tag(CLOSE_WIDGET);
@@ -102,7 +100,7 @@ void WidgetExample::InitWidget(
widget->SetContentsView(widget_container);
- if (transparency != views::Widget::Transparent) {
+ if (!transparent) {
widget_container->set_background(
views::Background::CreateStandardPanelBackground());
}
@@ -112,12 +110,10 @@ void WidgetExample::InitWidget(
}
#if defined(OS_LINUX)
-void WidgetExample::CreateChild(
- views::View* parent,
- const views::Widget::TransparencyParam transparency) {
+void WidgetExample::CreateChild(views::View* parent, bool transparent) {
views::WidgetGtk* widget =
new views::WidgetGtk(views::WidgetGtk::TYPE_CHILD);
- if (transparency == views::Widget::Transparent)
+ if (transparent)
widget->MakeTransparent();
// Compute where to place the child widget.
// We'll place it at the center of the root widget.
@@ -128,18 +124,14 @@ void WidgetExample::CreateChild(
200, 200);
// Initialize the child widget with the computed bounds.
widget->InitWithWidget(parent_widget, bounds);
- InitWidget(widget, transparency);
+ InitWidget(widget, transparent);
}
#endif
-void WidgetExample::CreatePopup(
- views::View* parent,
- const views::Widget::TransparencyParam transparency) {
- views::Widget* widget = views::Widget::CreatePopupWidget(
- transparency,
- views::Widget::AcceptEvents,
- views::Widget::DeleteOnDestroy,
- views::Widget::MirrorOriginInRTL);
+void WidgetExample::CreatePopup(views::View* parent, bool transparent) {
+ views::Widget::CreateParams params(views::Widget::CreateParams::TYPE_POPUP);
+ params.transparent = transparent;
+ views::Widget* widget = views::Widget::CreatePopupWidget(params);
// Compute where to place the popup widget.
// We'll place it right below the create button.
@@ -151,24 +143,24 @@ void WidgetExample::CreatePopup(
gfx::Rect bounds(point.x(), point.y(), 200, 300);
// Initialize the popup widget with the computed bounds.
widget->InitWithWidget(parent->GetWidget(), bounds);
- InitWidget(widget, transparency);
+ InitWidget(widget, transparent);
}
void WidgetExample::ButtonPressed(views::Button* sender,
const views::Event& event) {
switch (sender->tag()) {
case POPUP:
- CreatePopup(sender, views::Widget::NotTransparent);
+ CreatePopup(sender, false);
break;
case TRANSPARENT_POPUP:
- CreatePopup(sender, views::Widget::Transparent);
+ CreatePopup(sender, true);
break;
#if defined(OS_LINUX)
case CHILD:
- CreateChild(sender, views::Widget::NotTransparent);
+ CreateChild(sender, false);
break;
case TRANSPARENT_CHILD:
- CreateChild(sender, views::Widget::Transparent);
+ CreateChild(sender, true);
break;
#endif
case CLOSE_WIDGET:
diff --git a/views/examples/widget_example.h b/views/examples/widget_example.h
index b6d143a..14ddb65 100644
--- a/views/examples/widget_example.h
+++ b/views/examples/widget_example.h
@@ -37,16 +37,13 @@ class WidgetExample : public ExampleBase, public views::ButtonListener {
void BuildButton(views::View* container, const std::wstring& label, int tag);
- void InitWidget(views::Widget* widget,
- const views::Widget::TransparencyParam transparency);
+ void InitWidget(views::Widget* widget, bool transparent);
#if defined(OS_LINUX)
- void CreateChild(views::View* parent,
- const views::Widget::TransparencyParam transparency);
+ void CreateChild(views::View* parent, bool transparent);
#endif
- void CreatePopup(views::View* parent,
- const views::Widget::TransparencyParam transparency);
+ void CreatePopup(views::View* parent, bool transparent);
// Overridden from views::ButtonListener:
virtual void ButtonPressed(views::Button* sender,
diff --git a/views/widget/widget.cc b/views/widget/widget.cc
index 8944ff9..65b9f916 100644
--- a/views/widget/widget.cc
+++ b/views/widget/widget.cc
@@ -15,6 +15,29 @@
namespace views {
////////////////////////////////////////////////////////////////////////////////
+// Widget, CreateParams:
+
+Widget::CreateParams::CreateParams()
+ : type(TYPE_TOPLEVEL),
+ transparent(false),
+ accept_events(true),
+ delete_on_destroy(true),
+ mirror_origin_in_rtl(true),
+ has_dropshadow(false),
+ native_widget(NULL) {
+}
+
+Widget::CreateParams::CreateParams(Type type)
+ : type(type),
+ transparent(false),
+ accept_events(true),
+ delete_on_destroy(true),
+ mirror_origin_in_rtl(true),
+ has_dropshadow(false),
+ native_widget(NULL) {
+}
+
+////////////////////////////////////////////////////////////////////////////////
// Widget, public:
Widget::Widget()
diff --git a/views/widget/widget.h b/views/widget/widget.h
index b094932..c164c16 100644
--- a/views/widget/widget.h
+++ b/views/widget/widget.h
@@ -60,44 +60,37 @@ class Window;
class Widget : public internal::NativeWidgetDelegate,
public FocusTraversable {
public:
- enum TransparencyParam {
- Transparent,
- NotTransparent
- };
-
- enum EventsParam {
- AcceptEvents,
- NotAcceptEvents
- };
-
- enum DeleteParam {
- DeleteOnDestroy,
- NotDeleteOnDestroy
- };
-
- enum MirroringParam {
- MirrorOriginInRTL,
- DontMirrorOriginInRTL
+ struct CreateParams {
+ enum Type {
+ TYPE_TOPLEVEL,
+ TYPE_CHILD,
+ TYPE_POPUP,
+ TYPE_MENU
+ };
+
+ CreateParams();
+ explicit CreateParams(Type type);
+
+ Type type;
+
+ bool transparent;
+ bool accept_events;
+ bool delete_on_destroy;
+ bool mirror_origin_in_rtl;
+ bool has_dropshadow;
+ NativeWidget* native_widget;
};
+ Widget();
virtual ~Widget();
- // Creates a transient popup widget specific to the current platform.
- // If |mirror_in_rtl| is set to MirrorOriginInRTL, the contents of the
- // popup will be mirrored if the current locale is RTL. You should use
- // DontMirrorOriginInRTL if you are aleady handling the RTL layout within
- // the widget.
- static Widget* CreatePopupWidget(TransparencyParam transparent,
- EventsParam accept_events,
- DeleteParam delete_on_destroy,
- MirroringParam mirror_in_rtl);
+ // Creates a Widget instance suitable for use as a transient popup.
+ static Widget* CreatePopupWidget(const CreateParams& params);
// Enumerates all windows pertaining to us and notifies their
// view hierarchies that the locale has changed.
static void NotifyLocaleChanged();
- Widget();
-
// Unconverted methods -------------------------------------------------------
// TODO(beng):
diff --git a/views/widget/widget_gtk.cc b/views/widget/widget_gtk.cc
index 1c3d541..5f470c5 100644
--- a/views/widget/widget_gtk.cc
+++ b/views/widget/widget_gtk.cc
@@ -298,6 +298,16 @@ 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();
+}
+
GtkWindow* WidgetGtk::GetTransientParent() const {
return (type_ != TYPE_CHILD && widget_) ?
gtk_window_get_transient_for(GTK_WINDOW(widget_)) : NULL;
@@ -1540,16 +1550,9 @@ void WidgetGtk::DrawTransparentBackground(GtkWidget* widget,
// Widget, public:
// static
-Widget* Widget::CreatePopupWidget(TransparencyParam transparent,
- EventsParam accept_events,
- DeleteParam delete_on_destroy,
- MirroringParam mirror_in_rtl) {
+Widget* Widget::CreatePopupWidget(const CreateParams& params) {
WidgetGtk* popup = new WidgetGtk(WidgetGtk::TYPE_POPUP);
- popup->set_delete_on_destroy(delete_on_destroy == DeleteOnDestroy);
- if (transparent == Transparent)
- popup->MakeTransparent();
- if (accept_events == NotAcceptEvents)
- popup->MakeIgnoreEvents();
+ popup->SetCreateParams(params);
return popup;
}
diff --git a/views/widget/widget_gtk.h b/views/widget/widget_gtk.h
index 39f6de5..ed9e9fb 100644
--- a/views/widget/widget_gtk.h
+++ b/views/widget/widget_gtk.h
@@ -64,6 +64,9 @@ 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.
diff --git a/views/widget/widget_win.cc b/views/widget/widget_win.cc
index 2c247fd..c97d8e0 100644
--- a/views/widget/widget_win.cc
+++ b/views/widget/widget_win.cc
@@ -153,6 +153,56 @@ WidgetWin::~WidgetWin() {
DestroyRootView();
}
+void WidgetWin::SetCreateParams(const CreateParams& params) {
+ // Set non-style attributes.
+ set_delete_on_destroy(params.delete_on_destroy);
+
+ DWORD style = 0;
+ DWORD ex_style = 0;
+ DWORD class_style = CS_DBLCLKS;
+
+ // Set type-independent style attributes.
+ if (params.accept_events)
+ ex_style |= WS_EX_TRANSPARENT;
+ 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_TOPLEVEL:
+ break;
+ case CreateParams::TYPE_CHILD:
+ style |= WS_CHILD;
+ break;
+ case CreateParams::TYPE_POPUP:
+ style |= WS_POPUP;
+ ex_style |= WS_EX_TOOLWINDOW | WS_EX_NOACTIVATE;
+ break;
+ case CreateParams::TYPE_MENU:
+ style |= WS_POPUP;
+ ex_style |= WS_EX_TOPMOST | WS_EX_NOACTIVATE;
+ is_mouse_down_ =
+ ((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
@@ -1147,21 +1197,9 @@ gfx::AcceleratedWidget WidgetWin::GetAcceleratedWidget() {
// Widget, public:
// static
-Widget* Widget::CreatePopupWidget(TransparencyParam transparent,
- EventsParam accept_events,
- DeleteParam delete_on_destroy,
- MirroringParam mirror_in_rtl) {
+Widget* Widget::CreatePopupWidget(const CreateParams& params) {
WidgetWin* popup = new WidgetWin;
- DWORD ex_style = WS_EX_TOOLWINDOW | WS_EX_NOACTIVATE;
- if (mirror_in_rtl == MirrorOriginInRTL)
- ex_style |= l10n_util::GetExtendedTooltipStyles();
- if (transparent == Transparent)
- ex_style |= WS_EX_LAYERED;
- if (accept_events != AcceptEvents)
- ex_style |= WS_EX_TRANSPARENT;
- popup->set_window_style(WS_POPUP);
- popup->set_window_ex_style(ex_style);
- popup->set_delete_on_destroy(delete_on_destroy == DeleteOnDestroy);
+ popup->SetCreateParams(params);
return popup;
}
diff --git a/views/widget/widget_win.h b/views/widget/widget_win.h
index 2428a3e8..41e24f9 100644
--- a/views/widget/widget_win.h
+++ b/views/widget/widget_win.h
@@ -86,6 +86,9 @@ 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);
diff --git a/views/window/window.cc b/views/window/window.cc
index ba7d055..16d4170 100644
--- a/views/window/window.cc
+++ b/views/window/window.cc
@@ -236,6 +236,15 @@ const Widget* Window::AsWidget() const {
}
////////////////////////////////////////////////////////////////////////////////
+// Window, protected:
+
+void Window::SetNativeWindow(NativeWindow* native_window) {
+ native_window_ = native_window;
+ native_window->AsNativeWidget()->GetWidget()->set_widget_delegate(
+ window_delegate_);
+}
+
+////////////////////////////////////////////////////////////////////////////////
// Window, internal::NativeWindowDelegate implementation:
bool Window::CanActivate() const {
diff --git a/views/window/window.h b/views/window/window.h
index f18f4bb..d043dc1 100644
--- a/views/window/window.h
+++ b/views/window/window.h
@@ -197,9 +197,7 @@ class Window : public internal::NativeWindowDelegate {
protected:
// TODO(beng): Temporarily provided as a way to associate the subclass'
// implementation of NativeWidget with this.
- void set_native_window(NativeWindow* native_window) {
- native_window_ = native_window;
- }
+ void SetNativeWindow(NativeWindow* native_window);
// Overridden from NativeWindowDelegate:
virtual bool CanActivate() const OVERRIDE;
diff --git a/views/window/window_gtk.cc b/views/window/window_gtk.cc
index 46af221..2257f07 100644
--- a/views/window/window_gtk.cc
+++ b/views/window/window_gtk.cc
@@ -418,7 +418,7 @@ WindowGtk::WindowGtk(WindowDelegate* window_delegate)
ALLOW_THIS_IN_INITIALIZER_LIST(delegate_(this)),
window_state_(GDK_WINDOW_STATE_WITHDRAWN),
window_closed_(false) {
- set_native_window(this);
+ SetNativeWindow(this);
is_window_ = true;
}
diff --git a/views/window/window_win.cc b/views/window/window_win.cc
index 9ba6056..cc0c6dd 100644
--- a/views/window/window_win.cc
+++ b/views/window/window_win.cc
@@ -311,7 +311,7 @@ WindowWin::WindowWin(WindowDelegate* window_delegate)
force_hidden_count_(0),
is_right_mouse_pressed_on_caption_(false),
last_monitor_(NULL) {
- set_native_window(this);
+ SetNativeWindow(this);
is_window_ = true;
InitClass();
// Initialize these values to 0 so that subclasses can override the default