Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: views/widget/native_widget_gtk.cc

Issue 7031053: Make Widget ownership a little clearer by expressing it in terms of an enum. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « views/widget/native_widget_gtk.h ('k') | views/widget/native_widget_test_utils_gtk.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/widget/native_widget_gtk.h" 5 #include "views/widget/native_widget_gtk.h"
6 6
7 #include <gdk/gdk.h> 7 #include <gdk/gdk.h>
8 #include <gdk/gdkx.h> 8 #include <gdk/gdkx.h>
9 #include <X11/extensions/shape.h> 9 #include <X11/extensions/shape.h>
10 #include <X11/Xatom.h> 10 #include <X11/Xatom.h>
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 //////////////////////////////////////////////////////////////////////////////// 282 ////////////////////////////////////////////////////////////////////////////////
283 // NativeWidgetGtk, public: 283 // NativeWidgetGtk, public:
284 284
285 NativeWidgetGtk::NativeWidgetGtk(internal::NativeWidgetDelegate* delegate) 285 NativeWidgetGtk::NativeWidgetGtk(internal::NativeWidgetDelegate* delegate)
286 : is_window_(false), 286 : is_window_(false),
287 delegate_(delegate), 287 delegate_(delegate),
288 widget_(NULL), 288 widget_(NULL),
289 window_contents_(NULL), 289 window_contents_(NULL),
290 child_(false), 290 child_(false),
291 ALLOW_THIS_IN_INITIALIZER_LIST(close_widget_factory_(this)), 291 ALLOW_THIS_IN_INITIALIZER_LIST(close_widget_factory_(this)),
292 delete_on_destroy_(true), 292 ownership_(Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET),
293 transparent_(false), 293 transparent_(false),
294 ignore_events_(false), 294 ignore_events_(false),
295 ignore_drag_leave_(false), 295 ignore_drag_leave_(false),
296 opacity_(255), 296 opacity_(255),
297 drag_data_(NULL), 297 drag_data_(NULL),
298 is_active_(false), 298 is_active_(false),
299 transient_to_parent_(false), 299 transient_to_parent_(false),
300 got_initial_focus_in_(false), 300 got_initial_focus_in_(false),
301 has_focus_(false), 301 has_focus_(false),
302 focus_on_creation_(true), 302 focus_on_creation_(true),
(...skipping 13 matching lines...) Expand all
316 MessageLoopForUI* loop = MessageLoopForUI::current(); 316 MessageLoopForUI* loop = MessageLoopForUI::current();
317 if (loop) 317 if (loop)
318 loop->AddObserver(DropObserver::GetInstance()); 318 loop->AddObserver(DropObserver::GetInstance());
319 } 319 }
320 } 320 }
321 321
322 NativeWidgetGtk::~NativeWidgetGtk() { 322 NativeWidgetGtk::~NativeWidgetGtk() {
323 // We need to delete the input method before calling DestroyRootView(), 323 // We need to delete the input method before calling DestroyRootView(),
324 // because it'll set focus_manager_ to NULL. 324 // because it'll set focus_manager_ to NULL.
325 input_method_.reset(); 325 input_method_.reset();
326 DCHECK(delete_on_destroy_ || widget_ == NULL); 326 DCHECK(ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET ||
327 if (delete_on_destroy_) 327 widget_ == NULL);
328 if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET)
328 delete delegate_; 329 delete delegate_;
329 // TODO(altimofeev): investigate why OnDestroy could not be called. 330 // TODO(altimofeev): investigate why OnDestroy could not be called.
330 if (!child_) 331 if (!child_)
331 ActiveWindowWatcherX::RemoveObserver(this); 332 ActiveWindowWatcherX::RemoveObserver(this);
332 } 333 }
333 334
334 GtkWindow* NativeWidgetGtk::GetTransientParent() const { 335 GtkWindow* NativeWidgetGtk::GetTransientParent() const {
335 return (!child_ && widget_) ? 336 return (!child_ && widget_) ?
336 gtk_window_get_transient_for(GTK_WINDOW(widget_)) : NULL; 337 gtk_window_get_transient_for(GTK_WINDOW(widget_)) : NULL;
337 } 338 }
(...skipping 989 matching lines...) Expand 10 before | Expand all | Expand 10 after
1327 HandleGtkGrabBroke(); 1328 HandleGtkGrabBroke();
1328 } 1329 }
1329 1330
1330 void NativeWidgetGtk::OnDestroy(GtkWidget* object) { 1331 void NativeWidgetGtk::OnDestroy(GtkWidget* object) {
1331 if (!child_) 1332 if (!child_)
1332 ActiveWindowWatcherX::RemoveObserver(this); 1333 ActiveWindowWatcherX::RemoveObserver(this);
1333 // Note that this handler is hooked to GtkObject::destroy. 1334 // Note that this handler is hooked to GtkObject::destroy.
1334 // NULL out pointers here since we might still be in an observer list 1335 // NULL out pointers here since we might still be in an observer list
1335 // until delstion happens. 1336 // until delstion happens.
1336 widget_ = window_contents_ = NULL; 1337 widget_ = window_contents_ = NULL;
1337 if (delete_on_destroy_) { 1338 if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET) {
1338 // Delays the deletion of this NativeWidgetGtk as we want its children to 1339 // Delays the deletion of this NativeWidgetGtk as we want its children to
1339 // have access to it when destroyed. 1340 // have access to it when destroyed.
1340 MessageLoop::current()->DeleteSoon(FROM_HERE, this); 1341 MessageLoop::current()->DeleteSoon(FROM_HERE, this);
1341 } 1342 }
1342 } 1343 }
1343 1344
1344 void NativeWidgetGtk::OnShow(GtkWidget* widget) { 1345 void NativeWidgetGtk::OnShow(GtkWidget* widget) {
1345 } 1346 }
1346 1347
1347 void NativeWidgetGtk::OnMap(GtkWidget* widget) { 1348 void NativeWidgetGtk::OnMap(GtkWidget* widget) {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
1408 handled = HandleKeyboardEvent(key); 1409 handled = HandleKeyboardEvent(key);
1409 1410
1410 // Dispatch the key event for bindings processing. 1411 // Dispatch the key event for bindings processing.
1411 if (!handled && event && GTK_IS_WINDOW(widget_)) 1412 if (!handled && event && GTK_IS_WINDOW(widget_))
1412 gtk_bindings_activate_event(GTK_OBJECT(widget_), event); 1413 gtk_bindings_activate_event(GTK_OBJECT(widget_), event);
1413 } 1414 }
1414 1415
1415 void NativeWidgetGtk::SetInitParams(const Widget::InitParams& params) { 1416 void NativeWidgetGtk::SetInitParams(const Widget::InitParams& params) {
1416 DCHECK(!GetNativeView()); 1417 DCHECK(!GetNativeView());
1417 1418
1418 delete_on_destroy_ = params.delete_on_destroy; 1419 ownership_ = params.ownership;
1419 child_ = params.child; 1420 child_ = params.child;
1420 1421
1421 // TODO(beng): The secondary checks here actually obviate the need for 1422 // TODO(beng): The secondary checks here actually obviate the need for
1422 // params.transient but that's only because NativeWidgetGtk 1423 // params.transient but that's only because NativeWidgetGtk
1423 // considers any top-level widget to be a transient widget. We 1424 // considers any top-level widget to be a transient widget. We
1424 // will probably want to ammend this assumption at some point. 1425 // will probably want to ammend this assumption at some point.
1425 if (params.transient || params.parent || params.parent_widget) 1426 if (params.transient || params.parent || params.parent_widget)
1426 transient_to_parent_ = true; 1427 transient_to_parent_ = true;
1427 if (params.transparent) 1428 if (params.transparent)
1428 MakeTransparent(); 1429 MakeTransparent();
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
1805 1806
1806 // And now, notify them that they have a brand new parent. 1807 // And now, notify them that they have a brand new parent.
1807 for (NativeWidgets::iterator it = widgets.begin(); 1808 for (NativeWidgets::iterator it = widgets.begin();
1808 it != widgets.end(); ++it) { 1809 it != widgets.end(); ++it) {
1809 (*it)->GetWidget()->NotifyNativeViewHierarchyChanged(true, 1810 (*it)->GetWidget()->NotifyNativeViewHierarchyChanged(true,
1810 new_parent); 1811 new_parent);
1811 } 1812 }
1812 } 1813 }
1813 1814
1814 } // namespace views 1815 } // namespace views
OLDNEW
« no previous file with comments | « views/widget/native_widget_gtk.h ('k') | views/widget/native_widget_test_utils_gtk.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698