diff options
-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: |