| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "views/controls/native/native_view_host_gtk.h" | 5 #include "views/controls/native/native_view_host_gtk.h" |
| 6 | 6 |
| 7 #include <gtk/gtk.h> | 7 #include <gtk/gtk.h> |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 // Always layout though. | 56 // Always layout though. |
| 57 host_->Layout(); | 57 host_->Layout(); |
| 58 | 58 |
| 59 // We own the native view as long as it's attached, so that we can safely | 59 // We own the native view as long as it's attached, so that we can safely |
| 60 // reparent it in multiple passes. | 60 // reparent it in multiple passes. |
| 61 gtk_widget_ref(host_->native_view()); | 61 gtk_widget_ref(host_->native_view()); |
| 62 | 62 |
| 63 // TODO(port): figure out focus. | 63 // TODO(port): figure out focus. |
| 64 } | 64 } |
| 65 | 65 |
| 66 void NativeViewHostGtk::NativeViewDetaching() { | 66 void NativeViewHostGtk::NativeViewDetaching(bool destroyed) { |
| 67 DCHECK(host_->native_view()); | 67 DCHECK(host_->native_view()); |
| 68 | 68 |
| 69 g_signal_handler_disconnect(G_OBJECT(host_->native_view()), | 69 g_signal_handler_disconnect(G_OBJECT(host_->native_view()), |
| 70 destroy_signal_id_); | 70 destroy_signal_id_); |
| 71 destroy_signal_id_ = 0; | 71 destroy_signal_id_ = 0; |
| 72 | 72 |
| 73 g_signal_handler_disconnect(G_OBJECT(host_->native_view()), | 73 g_signal_handler_disconnect(G_OBJECT(host_->native_view()), |
| 74 focus_signal_id_); | 74 focus_signal_id_); |
| 75 focus_signal_id_ = 0; | 75 focus_signal_id_ = 0; |
| 76 | 76 |
| 77 installed_clip_ = false; | 77 installed_clip_ = false; |
| 78 | 78 |
| 79 if (fixed_ && !destroyed) { |
| 80 DCHECK_NE(static_cast<gfx::NativeView>(NULL), |
| 81 gtk_widget_get_parent(host_->native_view())); |
| 82 gtk_container_remove(GTK_CONTAINER(fixed_), host_->native_view()); |
| 83 DCHECK_EQ( |
| 84 0U, g_list_length(gtk_container_get_children(GTK_CONTAINER(fixed_)))); |
| 85 } |
| 86 |
| 79 g_object_unref(G_OBJECT(host_->native_view())); | 87 g_object_unref(G_OBJECT(host_->native_view())); |
| 80 } | 88 } |
| 81 | 89 |
| 82 void NativeViewHostGtk::AddedToWidget() { | 90 void NativeViewHostGtk::AddedToWidget() { |
| 83 if (!fixed_) | 91 if (!fixed_) |
| 84 CreateFixed(false); | 92 CreateFixed(false); |
| 85 if (gtk_widget_get_parent(fixed_)) | 93 if (gtk_widget_get_parent(fixed_)) |
| 86 GetHostWidget()->ReparentChild(fixed_); | 94 GetHostWidget()->ReparentChild(fixed_); |
| 87 else | 95 else |
| 88 GetHostWidget()->AddChild(fixed_); | 96 GetHostWidget()->AddChild(fixed_); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 return; | 201 return; |
| 194 | 202 |
| 195 gtk_widget_hide(fixed_); | 203 gtk_widget_hide(fixed_); |
| 196 GetHostWidget()->RemoveChild(fixed_); | 204 GetHostWidget()->RemoveChild(fixed_); |
| 197 | 205 |
| 198 if (host_->native_view()) { | 206 if (host_->native_view()) { |
| 199 // We can safely remove the widget from its container since we own the | 207 // We can safely remove the widget from its container since we own the |
| 200 // widget from the moment it is attached. | 208 // widget from the moment it is attached. |
| 201 gtk_container_remove(GTK_CONTAINER(fixed_), host_->native_view()); | 209 gtk_container_remove(GTK_CONTAINER(fixed_), host_->native_view()); |
| 202 } | 210 } |
| 203 | 211 // fixed_ should not have any children this point. |
| 212 DCHECK_EQ(0U, |
| 213 g_list_length(gtk_container_get_children(GTK_CONTAINER(fixed_)))); |
| 204 gtk_widget_destroy(fixed_); | 214 gtk_widget_destroy(fixed_); |
| 205 fixed_ = NULL; | 215 fixed_ = NULL; |
| 206 } | 216 } |
| 207 | 217 |
| 208 WidgetGtk* NativeViewHostGtk::GetHostWidget() const { | 218 WidgetGtk* NativeViewHostGtk::GetHostWidget() const { |
| 209 return static_cast<WidgetGtk*>(host_->GetWidget()); | 219 return static_cast<WidgetGtk*>(host_->GetWidget()); |
| 210 } | 220 } |
| 211 | 221 |
| 212 // static | 222 // static |
| 213 void NativeViewHostGtk::CallDestroy(GtkObject* object, | 223 void NativeViewHostGtk::CallDestroy(GtkObject* object, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 234 //////////////////////////////////////////////////////////////////////////////// | 244 //////////////////////////////////////////////////////////////////////////////// |
| 235 // NativeViewHostWrapper, public: | 245 // NativeViewHostWrapper, public: |
| 236 | 246 |
| 237 // static | 247 // static |
| 238 NativeViewHostWrapper* NativeViewHostWrapper::CreateWrapper( | 248 NativeViewHostWrapper* NativeViewHostWrapper::CreateWrapper( |
| 239 NativeViewHost* host) { | 249 NativeViewHost* host) { |
| 240 return new NativeViewHostGtk(host); | 250 return new NativeViewHostGtk(host); |
| 241 } | 251 } |
| 242 | 252 |
| 243 } // namespace views | 253 } // namespace views |
| OLD | NEW |