diff options
author | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-25 23:09:39 +0000 |
---|---|---|
committer | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-25 23:09:39 +0000 |
commit | 154a9820511c94bdcc8a69a3f7cc69b56ea75cd1 (patch) | |
tree | 41404665474d256283ab285ca688c5913d3eb22c /views | |
parent | 2186fec4df1dde813a12011eb1ea650ce8470ea2 (diff) | |
download | chromium_src-154a9820511c94bdcc8a69a3f7cc69b56ea75cd1.zip chromium_src-154a9820511c94bdcc8a69a3f7cc69b56ea75cd1.tar.gz chromium_src-154a9820511c94bdcc8a69a3f7cc69b56ea75cd1.tar.bz2 |
Fixed a few bugs in view/gtk framework
NativeControlGtk
* Layout if the visibility is changed after the native view is created.
(I also added DCHECK(GetWidget()) to make sure Wiget is available at this point)
NativeViewHostGtk
* decrement the native_view's ref count only if it still has a parent.
* create fixed in AddedToWidget if fixed_ does not exist. This can happen when
a view is removed, then added.
BUG=none
TEST=unit test for last 2 bugs is added to view_unittest.cc (ChangeVisibility).
Review URL: http://codereview.chromium.org/219035
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@27282 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
-rw-r--r-- | views/controls/native/native_view_host_gtk.cc | 5 | ||||
-rw-r--r-- | views/controls/native_control_gtk.cc | 28 | ||||
-rw-r--r-- | views/view_unittest.cc | 28 |
3 files changed, 50 insertions, 11 deletions
diff --git a/views/controls/native/native_view_host_gtk.cc b/views/controls/native/native_view_host_gtk.cc index ea9bd62..581f08d 100644 --- a/views/controls/native/native_view_host_gtk.cc +++ b/views/controls/native/native_view_host_gtk.cc @@ -76,11 +76,12 @@ void NativeViewHostGtk::NativeViewDetaching() { installed_clip_ = false; - // Release ownership back to the caller. - gtk_widget_unref(host_->native_view()); + g_object_unref(G_OBJECT(host_->native_view())); } void NativeViewHostGtk::AddedToWidget() { + if (!fixed_) + CreateFixed(false); if (gtk_widget_get_parent(fixed_)) GetHostWidget()->ReparentChild(fixed_); else diff --git a/views/controls/native_control_gtk.cc b/views/controls/native_control_gtk.cc index 082e610..49453ef 100644 --- a/views/controls/native_control_gtk.cc +++ b/views/controls/native_control_gtk.cc @@ -35,21 +35,31 @@ void NativeControlGtk::ViewHierarchyChanged(bool is_add, View* parent, // Call the base class to hide the view if we're being removed. NativeViewHost::ViewHierarchyChanged(is_add, parent, child); - // Create the widget when we're added to a valid Widget. Many controls need a - // parent widget to function properly. - if (is_add && GetWidget() && !native_view()) + if (!is_add && child == this && native_view()) { + Detach(); + } else if (is_add && GetWidget() && !native_view()) { + // Create the widget when we're added to a valid Widget. Many + // controls need a parent widget to function properly. CreateNativeControl(); + } } void NativeControlGtk::VisibilityChanged(View* starting_from, bool is_visible) { if (!is_visible) { - // We destroy the child widget when we become invisible because of the - // performance cost of maintaining widgets that aren't currently needed. - GtkWidget* widget = native_view(); - Detach(); - gtk_widget_destroy(widget); + if (native_view()) { + // We destroy the child widget when we become invisible because of the + // performance cost of maintaining widgets that aren't currently needed. + GtkWidget* widget = native_view(); + Detach(); + gtk_widget_destroy(widget); + } } else if (!native_view()) { - CreateNativeControl(); + if (GetWidget()) + CreateNativeControl(); + } else { + // The view becomes visible after native control is created. + // Layout now. + Layout(); } } diff --git a/views/view_unittest.cc b/views/view_unittest.cc index 613c522..bad592b 100644 --- a/views/view_unittest.cc +++ b/views/view_unittest.cc @@ -1186,6 +1186,34 @@ TEST_F(DefaultButtonTest, DialogDefaultButtonTest) { } #endif +//////////////////////////////////////////////////////////////////////////////// +// View hierachy / Visibility changes +//////////////////////////////////////////////////////////////////////////////// +/* +TEST_F(ViewTest, ChangeVisibility) { +#if defined(OS_LINUX) + // Make CRITICAL messages fatal + // TODO(oshima): we probably should enable this for entire tests on linux. + g_log_set_always_fatal(G_LOG_LEVEL_CRITICAL); +#endif + scoped_ptr<views::Widget> window(CreateWidget()); + window->Init(NULL, gfx::Rect(0, 0, 500, 300)); + views::RootView* root_view = window->GetRootView(); + NativeButton* native = new NativeButton(NULL, L"Native"); + + root_view->SetContentsView(native); + native->SetVisible(true); + + root_view->RemoveChildView(native); + native->SetVisible(false); + // Change visibility to true with no widget. + native->SetVisible(true); + + root_view->SetContentsView(native); + native->SetVisible(true); +} +*/ + #if defined(OS_LINUX) class TestViewWithControls : public View { public: |