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

Side by Side Diff: ui/base/gtk/focus_store_gtk.cc

Issue 8490029: GTK: Move code shared by future content/ classes and chrome/ to ui/. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Remove platform_util method. Created 9 years, 1 month 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
« no previous file with comments | « ui/base/gtk/focus_store_gtk.h ('k') | ui/ui.gyp » ('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 "chrome/browser/ui/gtk/focus_store_gtk.h" 5 #include "ui/base/gtk/focus_store_gtk.h"
6 6
7 #include <gtk/gtk.h> 7 #include <gtk/gtk.h>
8 8
9 #include "chrome/browser/platform_util.h" 9 namespace ui {
10 10
11 FocusStoreGtk::FocusStoreGtk() 11 FocusStoreGtk::FocusStoreGtk()
12 : widget_(NULL), 12 : widget_(NULL),
13 destroy_handler_id_(0) { 13 destroy_handler_id_(0) {
14 } 14 }
15 15
16 FocusStoreGtk::~FocusStoreGtk() { 16 FocusStoreGtk::~FocusStoreGtk() {
17 DisconnectDestroyHandler(); 17 DisconnectDestroyHandler();
18 } 18 }
19 19
20 void FocusStoreGtk::Store(GtkWidget* widget) { 20 void FocusStoreGtk::Store(GtkWidget* widget) {
21 GtkWidget* focus_widget = NULL; 21 GtkWidget* focus_widget = NULL;
22 if (widget) { 22 if (widget) {
23 GtkWindow* window = platform_util::GetTopLevel(widget); 23 // A detached widget won't have a toplevel window as an ancestor, so we
24 // can't assume that the query for toplevel will return a window.
25 GtkWidget* toplevel = gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW);
26 GtkWindow* window = GTK_IS_WINDOW(toplevel) ? GTK_WINDOW(toplevel) : NULL;
24 if (window) 27 if (window)
25 focus_widget = window->focus_widget; 28 focus_widget = window->focus_widget;
26 } 29 }
27 30
28 SetWidget(focus_widget); 31 SetWidget(focus_widget);
29 } 32 }
30 33
31 void FocusStoreGtk::SetWidget(GtkWidget* widget) { 34 void FocusStoreGtk::SetWidget(GtkWidget* widget) {
32 DisconnectDestroyHandler(); 35 DisconnectDestroyHandler();
33 36
34 // We don't add a ref. The signal handler below effectively gives us a weak 37 // We don't add a ref. The signal handler below effectively gives us a weak
35 // reference. 38 // reference.
36 widget_ = widget; 39 widget_ = widget;
37 if (widget_) { 40 if (widget_) {
38 // When invoked, |gtk_widget_destroyed| will set |widget_| to NULL. 41 // When invoked, |gtk_widget_destroyed| will set |widget_| to NULL.
39 destroy_handler_id_ = g_signal_connect(widget_, "destroy", 42 destroy_handler_id_ = g_signal_connect(widget_, "destroy",
40 G_CALLBACK(gtk_widget_destroyed), 43 G_CALLBACK(gtk_widget_destroyed),
41 &widget_); 44 &widget_);
42 } 45 }
43 } 46 }
44 47
45 void FocusStoreGtk::DisconnectDestroyHandler() { 48 void FocusStoreGtk::DisconnectDestroyHandler() {
46 if (widget_) { 49 if (widget_) {
47 g_signal_handler_disconnect(widget_, destroy_handler_id_); 50 g_signal_handler_disconnect(widget_, destroy_handler_id_);
48 widget_ = NULL; 51 widget_ = NULL;
49 } 52 }
50 } 53 }
54
55 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/gtk/focus_store_gtk.h ('k') | ui/ui.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698