diff options
author | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-01 00:07:00 +0000 |
---|---|---|
committer | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-01 00:07:00 +0000 |
commit | a2920638f52df5d5e0e3ea86c1802d4a7416abe5 (patch) | |
tree | 635245f5d524df6ce6a10ec75db72f81639a4156 /views/widget/widget_gtk.cc | |
parent | fb3ef9384cc76c4237f98e5aa38d2689cc7b60cd (diff) | |
download | chromium_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/widget_gtk.cc')
-rw-r--r-- | views/widget/widget_gtk.cc | 124 |
1 files changed, 60 insertions, 64 deletions
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 |