summaryrefslogtreecommitdiffstats
path: root/views/widget
diff options
context:
space:
mode:
authorben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-01 00:07:00 +0000
committerben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-01 00:07:00 +0000
commita2920638f52df5d5e0e3ea86c1802d4a7416abe5 (patch)
tree635245f5d524df6ce6a10ec75db72f81639a4156 /views/widget
parentfb3ef9384cc76c4237f98e5aa38d2689cc7b60cd (diff)
downloadchromium_src-a2920638f52df5d5e0e3ea86c1802d4a7416abe5.zip
chromium_src-a2920638f52df5d5e0e3ea86c1802d4a7416abe5.tar.gz
chromium_src-a2920638f52df5d5e0e3ea86c1802d4a7416abe5.tar.bz2
Status bubble limping in TOOLKIT_VIEWS.
Add CreateTransparentFloatingWidget method to Widget and add Init/SetContentsView methods. BUG=none TEST=none Review URL: http://codereview.chromium.org/160474 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@22229 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/widget')
-rw-r--r--views/widget/root_view.cc27
-rw-r--r--views/widget/root_view.h4
-rw-r--r--views/widget/widget.h19
-rw-r--r--views/widget/widget_gtk.cc124
-rw-r--r--views/widget/widget_gtk.h8
-rw-r--r--views/widget/widget_win.cc40
-rw-r--r--views/widget/widget_win.h17
7 files changed, 131 insertions, 108 deletions
diff --git a/views/widget/root_view.cc b/views/widget/root_view.cc
index 34de509..145de92 100644
--- a/views/widget/root_view.cc
+++ b/views/widget/root_view.cc
@@ -8,17 +8,17 @@
#include "app/drag_drop_types.h"
#include "app/gfx/canvas.h"
-#if defined(OS_WIN)
-#include "base/base_drag_source.h"
-#endif
#include "base/logging.h"
#include "base/message_loop.h"
+#include "views/fill_layout.h"
#include "views/focus/view_storage.h"
+#include "views/widget/widget.h"
+#include "views/window/window.h"
+
#if defined(OS_WIN)
+#include "base/base_drag_source.h"
#include "views/widget/root_view_drop_target.h"
#endif
-#include "views/widget/widget.h"
-#include "views/window/window.h"
namespace views {
@@ -92,6 +92,23 @@ RootView::~RootView() {
pending_paint_task_->Cancel(); // Ensure we're not called any more.
}
+void RootView::SetContentsView(View* contents_view) {
+ DCHECK(contents_view && GetWidget()->GetNativeView()) <<
+ "Can't be called until after the native view is created!";
+ // The ContentsView must be set up _after_ the window is created so that its
+ // Widget pointer is valid.
+ SetLayoutManager(new FillLayout);
+ if (GetChildViewCount() != 0)
+ RemoveAllChildViews(true);
+ AddChildView(contents_view);
+
+ // Force a layout now, since the attached hierarchy won't be ready for the
+ // containing window's bounds. Note that we call Layout directly rather than
+ // calling the widget's size changed handler, since the RootView's bounds may
+ // not have changed, which will cause the Layout not to be done otherwise.
+ Layout();
+}
+
/////////////////////////////////////////////////////////////////////////////
//
// RootView - layout, painting
diff --git a/views/widget/root_view.h b/views/widget/root_view.h
index 6488de5..8e8d467 100644
--- a/views/widget/root_view.h
+++ b/views/widget/root_view.h
@@ -42,6 +42,10 @@ class RootView : public View,
virtual ~RootView();
+ // Sets the "contents view" of the RootView. This is the single child view
+ // that is responsible for laying out the contents of the widget.
+ void SetContentsView(View* contents_view);
+
// Layout and Painting functions
// Overridden from View to implement paint scheduling.
diff --git a/views/widget/widget.h b/views/widget/widget.h
index f7170da..f3a8613 100644
--- a/views/widget/widget.h
+++ b/views/widget/widget.h
@@ -43,6 +43,25 @@ class Widget {
public:
virtual ~Widget() { }
+ // Creates a transparent popup widget specific to the current platform useful
+ // for transient status notifications.
+ static Widget* CreateTransparentPopupWidget(bool delete_on_destroy);
+
+ // Initialize the Widget with a parent and an initial desired size.
+ // |contents_view| is the view that will be the single child of RootView
+ // within this Widget. As contents_view is inserted into RootView's tree,
+ // RootView assumes ownership of this view and cleaning it up. If you remove
+ // this view, you are responsible for its destruction. If this value is NULL,
+ // the caller is responsible for populating the RootView, and sizing its
+ // contents as the window is sized.
+ virtual void Init(gfx::NativeView parent, const gfx::Rect& bounds) = 0;
+
+ // Sets the specified view as the contents of this Widget. There can only
+ // be one contnets view child of this Widget's RootView. This view is sized to
+ // fit the entire size of the RootView. The RootView takes ownership of this
+ // View, unless it is set as not being parent-owned.
+ virtual void SetContentsView(View* view) = 0;
+
// Returns the bounds of this Widget in the screen coordinate system.
// If the receiving Widget is a frame which is larger than its client area,
// this method returns the client area if including_frame is false and the
diff --git a/views/widget/widget_gtk.cc b/views/widget/widget_gtk.cc
index 677e58c..76abe93 100644
--- a/views/widget/widget_gtk.cc
+++ b/views/widget/widget_gtk.cc
@@ -6,7 +6,6 @@
#include "app/gfx/path.h"
#include "base/compiler_specific.h"
-#include "views/fill_layout.h"
#include "views/widget/default_theme_provider.h"
#include "views/widget/root_view.h"
#include "views/widget/tooltip_manager_gtk.h"
@@ -78,6 +77,53 @@ WidgetGtk::~WidgetGtk() {
MessageLoopForUI::current()->RemoveObserver(this);
}
+bool WidgetGtk::MakeTransparent() {
+ // Transparency can only be enabled for windows/popups and only if we haven't
+ // realized the widget.
+ DCHECK(!widget_ && type_ != TYPE_CHILD);
+
+ if (!gdk_screen_is_composited(gdk_screen_get_default())) {
+ // Transparency is only supported for compositing window managers.
+ DLOG(WARNING) << "compsiting not supported";
+ return false;
+ }
+
+ if (!gdk_screen_get_rgba_colormap(gdk_screen_get_default())) {
+ // We need rgba to make the window transparent.
+ return false;
+ }
+
+ transparent_ = true;
+ return true;
+}
+
+void WidgetGtk::AddChild(GtkWidget* child) {
+ gtk_container_add(GTK_CONTAINER(window_contents_), child);
+}
+
+void WidgetGtk::RemoveChild(GtkWidget* child) {
+ // We can be called after the contents widget has been destroyed, e.g. any
+ // NativeViewHost not removed from the view hierarchy before the window is
+ // closed.
+ if (GTK_IS_CONTAINER(window_contents_))
+ gtk_container_remove(GTK_CONTAINER(window_contents_), child);
+}
+
+void WidgetGtk::ReparentChild(GtkWidget* child) {
+ gtk_widget_reparent(child, window_contents_);
+}
+
+void WidgetGtk::PositionChild(GtkWidget* child, int x, int y, int w, int h) {
+ GtkAllocation alloc = { x, y, w, h };
+ // For some reason we need to do both of these to size a widget.
+ gtk_widget_size_allocate(child, &alloc);
+ gtk_widget_set_size_request(child, w, h);
+ gtk_fixed_move(GTK_FIXED(window_contents_), child, x, y);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// WidgetGtk, Widget implementation:
+
void WidgetGtk::Init(GtkWidget* parent,
const gfx::Rect& bounds) {
// Force creation of the RootView if it hasn't been created yet.
@@ -183,72 +229,10 @@ void WidgetGtk::Init(GtkWidget* parent,
}
}
-bool WidgetGtk::MakeTransparent() {
- // Transparency can only be enabled for windows/popups and only if we haven't
- // realized the widget.
- DCHECK(!widget_ && type_ != TYPE_CHILD);
-
- if (!gdk_screen_is_composited(gdk_screen_get_default())) {
- // Transparency is only supported for compositing window managers.
- DLOG(WARNING) << "compsiting not supported";
- return false;
- }
-
- if (!gdk_screen_get_rgba_colormap(gdk_screen_get_default())) {
- // We need rgba to make the window transparent.
- return false;
- }
-
- transparent_ = true;
- return true;
-}
-
-void WidgetGtk::AddChild(GtkWidget* child) {
- gtk_container_add(GTK_CONTAINER(window_contents_), child);
-}
-
-void WidgetGtk::RemoveChild(GtkWidget* child) {
- // We can be called after the contents widget has been destroyed, e.g. any
- // NativeViewHost not removed from the view hierarchy before the window is
- // closed.
- if (GTK_IS_CONTAINER(window_contents_))
- gtk_container_remove(GTK_CONTAINER(window_contents_), child);
-}
-
-void WidgetGtk::ReparentChild(GtkWidget* child) {
- gtk_widget_reparent(child, window_contents_);
-}
-
-void WidgetGtk::PositionChild(GtkWidget* child, int x, int y, int w, int h) {
- GtkAllocation alloc = { x, y, w, h };
- // For some reason we need to do both of these to size a widget.
- gtk_widget_size_allocate(child, &alloc);
- gtk_widget_set_size_request(child, w, h);
- gtk_fixed_move(GTK_FIXED(window_contents_), child, x, y);
-}
-
void WidgetGtk::SetContentsView(View* view) {
- DCHECK(view && widget_)
- << "Can't be called until after the HWND is created!";
- // The ContentsView must be set up _after_ the window is created so that its
- // Widget pointer is valid.
- root_view_->SetLayoutManager(new FillLayout);
- if (root_view_->GetChildViewCount() != 0)
- root_view_->RemoveAllChildViews(true);
- root_view_->AddChildView(view);
-
- DCHECK(widget_); // Widget must have been created by now.
-
- // Force a layout now, since the attached hierarchy won't be ready for the
- // containing window's bounds. Note that we call Layout directly rather than
- // calling OnSizeAllocate, since the RootView's bounds may not have changed,
- // which will cause the Layout not to be done otherwise.
- root_view_->Layout();
+ root_view_->SetContentsView(view);
}
-////////////////////////////////////////////////////////////////////////////////
-// WidgetGtk, Widget implementation:
-
void WidgetGtk::GetBounds(gfx::Rect* out, bool including_frame) const {
DCHECK(widget_);
@@ -841,4 +825,16 @@ void WidgetGtk::HandleGrabBroke() {
}
}
+
+////////////////////////////////////////////////////////////////////////////////
+// Widget, public:
+
+// static
+Widget* Widget::CreateTransparentPopupWidget(bool delete_on_destroy) {
+ WidgetGtk* popup = new WidgetGtk(WidgetGtk::TYPE_POPUP);
+ popup->set_delete_on_destroy(delete_on_destroy);
+ popup->MakeTransparent();
+ return popup;
+}
+
} // namespace views
diff --git a/views/widget/widget_gtk.h b/views/widget/widget_gtk.h
index fbb6c0e..42ea283 100644
--- a/views/widget/widget_gtk.h
+++ b/views/widget/widget_gtk.h
@@ -38,10 +38,6 @@ class WidgetGtk : public Widget, public MessageLoopForUI::Observer {
explicit WidgetGtk(Type type);
virtual ~WidgetGtk();
- // Initializes this widget.
- void Init(GtkWidget* parent,
- const gfx::Rect& bounds);
-
// Makes the background of the window totally transparent. This must be
// invoked before Init. This does a couple of checks and returns true if
// the window can be made transparent. The actual work of making the window
@@ -75,9 +71,9 @@ class WidgetGtk : public Widget, public MessageLoopForUI::Observer {
// |widget_|.
GtkWidget* window_contents() const { return window_contents_; }
- virtual void SetContentsView(View* view);
-
// Overridden from Widget:
+ virtual void Init(gfx::NativeView parent, const gfx::Rect& bounds);
+ virtual void SetContentsView(View* view);
virtual void GetBounds(gfx::Rect* out, bool including_frame) const;
virtual void SetBounds(const gfx::Rect& bounds);
virtual void SetShape(const gfx::Path& shape);
diff --git a/views/widget/widget_win.cc b/views/widget/widget_win.cc
index ed58ae9..1f49d1d 100644
--- a/views/widget/widget_win.cc
+++ b/views/widget/widget_win.cc
@@ -6,13 +6,13 @@
#include "app/gfx/canvas.h"
#include "app/gfx/path.h"
+#include "app/l10n_util_win.h"
#include "app/win_util.h"
#include "base/gfx/native_theme.h"
#include "base/string_util.h"
#include "base/win_util.h"
#include "views/accessibility/view_accessibility.h"
#include "views/controls/native_control_win.h"
-#include "views/fill_layout.h"
#include "views/focus/focus_util_win.h"
#include "views/views_delegate.h"
#include "views/widget/aero_tooltip_manager.h"
@@ -154,7 +154,10 @@ WidgetWin::~WidgetWin() {
MessageLoopForUI::current()->RemoveObserver(this);
}
-void WidgetWin::Init(HWND parent, const gfx::Rect& bounds) {
+///////////////////////////////////////////////////////////////////////////////
+// Widget implementation:
+
+void WidgetWin::Init(gfx::NativeView parent, const gfx::Rect& bounds) {
if (window_style_ == 0)
window_style_ = parent ? kWindowDefaultChildStyle : kWindowDefaultStyle;
@@ -218,24 +221,9 @@ void WidgetWin::Init(HWND parent, const gfx::Rect& bounds) {
}
void WidgetWin::SetContentsView(View* view) {
- DCHECK(view && hwnd_) << "Can't be called until after the HWND is created!";
- // The ContentsView must be set up _after_ the window is created so that its
- // Widget pointer is valid.
- root_view_->SetLayoutManager(new FillLayout);
- if (root_view_->GetChildViewCount() != 0)
- root_view_->RemoveAllChildViews(true);
- root_view_->AddChildView(view);
-
- // Force a layout now, since the attached hierarchy won't be ready for the
- // containing window's bounds. Note that we call Layout directly rather than
- // calling ChangeSize, since the RootView's bounds may not have changed, which
- // will cause the Layout not to be done otherwise.
- root_view_->Layout();
+ root_view_->SetContentsView(view);
}
-///////////////////////////////////////////////////////////////////////////////
-// Widget implementation:
-
void WidgetWin::GetBounds(gfx::Rect* out, bool including_frame) const {
CRect crect;
if (including_frame) {
@@ -1088,4 +1076,20 @@ void WidgetWin::PostProcessActivateMessage(WidgetWin* widget,
widget->focus_manager_->RestoreFocusedView();
}
}
+
+////////////////////////////////////////////////////////////////////////////////
+// Widget, public:
+
+// static
+Widget* Widget::CreateTransparentPopupWidget(bool delete_on_destroy) {
+ WidgetWin* popup = new WidgetWin;
+ popup->set_window_style(WS_POPUP);
+ popup->set_window_ex_style(WS_EX_LAYERED | WS_EX_TOOLWINDOW |
+ WS_EX_TRANSPARENT |
+ l10n_util::GetExtendedTooltipStyles());
+ popup->set_delete_on_destroy(delete_on_destroy);
+ return popup;
+}
+
} // namespace views
+
diff --git a/views/widget/widget_win.h b/views/widget/widget_win.h
index 9018c64..b15b682 100644
--- a/views/widget/widget_win.h
+++ b/views/widget/widget_win.h
@@ -71,21 +71,6 @@ class WidgetWin : public Widget,
WidgetWin();
virtual ~WidgetWin();
- // Initialize the Widget with a parent and an initial desired size.
- // |contents_view| is the view that will be the single child of RootView
- // within this Widget. As contents_view is inserted into RootView's tree,
- // RootView assumes ownership of this view and cleaning it up. If you remove
- // this view, you are responsible for its destruction. If this value is NULL,
- // the caller is responsible for populating the RootView, and sizing its
- // contents as the window is sized.
- void Init(HWND parent, const gfx::Rect& bounds);
-
- // Sets the specified view as the contents of this Widget. There can only
- // be one contnets view child of this Widget's RootView. This view is sized to
- // fit the entire size of the RootView. The RootView takes ownership of this
- // View, unless it is set as not being parent-owned.
- virtual void SetContentsView(View* view);
-
// Sets the window styles. This is ONLY used when the window is created.
// In other words, if you invoke this after invoking Init, nothing happens.
void set_window_style(DWORD style) { window_style_ = style; }
@@ -211,6 +196,8 @@ class WidgetWin : public Widget,
END_MSG_MAP()
// Overridden from Widget:
+ virtual void Init(gfx::NativeView parent, const gfx::Rect& bounds);
+ virtual void SetContentsView(View* view);
virtual void GetBounds(gfx::Rect* out, bool including_frame) const;
virtual void SetBounds(const gfx::Rect& bounds);
virtual void SetShape(const gfx::Path& shape);