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

Side by Side Diff: views/controls/native/native_view_host_gtk.cc

Issue 126107: Creates a new TabContentsViewGtk for views based FE. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 6 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
OLDNEW
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 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "views/controls/native/native_view_host.h" 10 #include "views/controls/native/native_view_host.h"
11 #include "views/widget/widget_gtk.h" 11 #include "views/widget/widget_gtk.h"
12 12
13 namespace views { 13 namespace views {
14 14
15 //////////////////////////////////////////////////////////////////////////////// 15 ////////////////////////////////////////////////////////////////////////////////
16 // NativeViewHostGtk, public: 16 // NativeViewHostGtk, public:
17 17
18 NativeViewHostGtk::NativeViewHostGtk(NativeViewHost* host) 18 NativeViewHostGtk::NativeViewHostGtk(NativeViewHost* host)
19 : host_(host), 19 : host_(host),
20 installed_clip_(false), 20 installed_clip_(false),
21 destroy_signal_id_(0) { 21 destroy_signal_id_(0) {
22 } 22 }
23 23
24 NativeViewHostGtk::~NativeViewHostGtk() { 24 NativeViewHostGtk::~NativeViewHostGtk() {
25 } 25 }
26 26
27 // static
28 View* NativeViewHostGtk::GetViewForNative(GtkWidget* widget) {
29 gpointer user_data = g_object_get_data(G_OBJECT(widget), "chrome-view");
30 return static_cast<View*>(user_data);
31 }
32
33 // static
34 void NativeViewHostGtk::SetViewForNative(GtkWidget* widget, View* view) {
35 g_object_set_data(G_OBJECT(widget), "chrome-view", view);
36 }
37
38 //////////////////////////////////////////////////////////////////////////////// 27 ////////////////////////////////////////////////////////////////////////////////
39 // NativeViewHostGtk, NativeViewHostWrapper implementation: 28 // NativeViewHostGtk, NativeViewHostWrapper implementation:
40 29
41 void NativeViewHostGtk::NativeViewAttached() { 30 void NativeViewHostGtk::NativeViewAttached() {
42 DCHECK(host_->native_view()); 31 DCHECK(host_->native_view());
43 32
44 GtkWidget* current_parent = gtk_widget_get_parent(host_->native_view()); 33 if (gtk_widget_get_parent(host_->native_view())) {
sky 2009/06/16 16:01:45 NOTE: rather than invoking ReparentChild you could
45 GtkWidget* new_parent = host_->GetWidget()->GetNativeView(); 34 static_cast<WidgetGtk*>(host_->GetWidget())->ReparentChild(
46 // Only adjust the parent if the parent actually changed. 35 host_->native_view());
47 if (current_parent != new_parent) { 36 } else {
48 // First hide the new window. We don't want anything to draw (like sub-hwnd 37 static_cast<WidgetGtk*>(host_->GetWidget())->AddChild(
49 // borders), when we change the parent below. 38 host_->native_view());
50 gtk_widget_hide(host_->native_view()); 39 }
51 40
52 if (current_parent) { 41 if (!destroy_signal_id_) {
53 gtk_container_remove(GTK_CONTAINER(current_parent), 42 destroy_signal_id_ = g_signal_connect(G_OBJECT(host_->native_view()),
54 host_->native_view()); 43 "destroy", G_CALLBACK(CallDestroy),
55 } 44 this);
56
57 // Adds a mapping between the GtkWidget and us.
58 SetViewForNative(host_->native_view(), host_);
59
60 if (!destroy_signal_id_) {
61 destroy_signal_id_ = g_signal_connect(G_OBJECT(host_->native_view()),
62 "destroy", G_CALLBACK(CallDestroy),
63 NULL);
64 }
65
66 // Set the parent.
67 static_cast<WidgetGtk*>(host_->GetWidget())->AddChild(host_->native_view());
68 } 45 }
69 46
70 // Always layout though. 47 // Always layout though.
71 host_->Layout(); 48 host_->Layout();
72 49
73 // TODO(port): figure out focus. 50 // TODO(port): figure out focus.
74 } 51 }
75 52
76 void NativeViewHostGtk::NativeViewDetaching() { 53 void NativeViewHostGtk::NativeViewDetaching() {
77 DCHECK(host_->native_view()); 54 DCHECK(host_->native_view());
78 55
79 g_signal_handler_disconnect(G_OBJECT(host_->native_view()), 56 g_signal_handler_disconnect(G_OBJECT(host_->native_view()),
80 destroy_signal_id_); 57 destroy_signal_id_);
81 destroy_signal_id_ = 0; 58 destroy_signal_id_ = 0;
82 59
83 // TODO(port): focus. 60 // TODO(port): focus.
84 // FocusManager::UninstallFocusSubclass(native_view()); 61 // FocusManager::UninstallFocusSubclass(native_view());
85 installed_clip_ = false; 62 installed_clip_ = false;
86 } 63 }
87 64
88 void NativeViewHostGtk::AddedToWidget() { 65 void NativeViewHostGtk::AddedToWidget() {
89 if (!host_->native_view()) 66 if (!host_->native_view())
90 return; 67 return;
91 WidgetGtk* parent_widget = static_cast<WidgetGtk*>(host_->GetWidget()); 68 WidgetGtk* parent_widget = static_cast<WidgetGtk*>(host_->GetWidget());
92 GtkWidget* widget_parent = gtk_widget_get_parent(host_->native_view()); 69 GtkWidget* widget_parent = gtk_widget_get_parent(host_->native_view());
93 GtkWidget* parent_widget_widget = parent_widget->child_widget_parent(); 70 GtkWidget* parent_widget_widget = parent_widget->window_contents();
94 if (widget_parent != parent_widget_widget) { 71 if (widget_parent != parent_widget_widget) {
95 g_object_ref(host_->native_view()); 72 g_object_ref(host_->native_view());
96 if (widget_parent) 73 if (widget_parent)
97 gtk_container_remove(GTK_CONTAINER(widget_parent), host_->native_view()); 74 gtk_container_remove(GTK_CONTAINER(widget_parent), host_->native_view());
98 gtk_container_add(GTK_CONTAINER(parent_widget_widget), 75 gtk_container_add(GTK_CONTAINER(parent_widget_widget),
99 host_->native_view()); 76 host_->native_view());
100 g_object_unref(host_->native_view()); 77 g_object_unref(host_->native_view());
101 } 78 }
102 if (host_->IsVisibleInRootView()) 79 if (host_->IsVisibleInRootView())
103 gtk_widget_show(host_->native_view()); 80 gtk_widget_show(host_->native_view());
104 else 81 else
105 gtk_widget_hide(host_->native_view()); 82 gtk_widget_hide(host_->native_view());
106 host_->Layout(); 83 host_->Layout();
107 } 84 }
108 85
109 void NativeViewHostGtk::RemovedFromWidget() { 86 void NativeViewHostGtk::RemovedFromWidget() {
110 if (!host_->native_view()) 87 if (!host_->native_view())
111 return; 88 return;
112 89
113 WidgetGtk* parent_widget = static_cast<WidgetGtk*>(host_->GetWidget()); 90 WidgetGtk* parent_widget = static_cast<WidgetGtk*>(host_->GetWidget());
114 gtk_widget_hide(host_->native_view()); 91 gtk_widget_hide(host_->native_view());
115 if (parent_widget) { 92 if (parent_widget) {
116 gtk_container_remove(GTK_CONTAINER(parent_widget->child_widget_parent()), 93 gtk_container_remove(GTK_CONTAINER(parent_widget->window_contents()),
117 host_->native_view()); 94 host_->native_view());
118 } 95 }
119 } 96 }
120 97
121 void NativeViewHostGtk::InstallClip(int x, int y, int w, int h) { 98 void NativeViewHostGtk::InstallClip(int x, int y, int w, int h) {
122 DCHECK(w > 0 && h > 0); 99 DCHECK(w > 0 && h > 0);
123 100
124 bool has_window = 101 bool has_window =
125 (GTK_WIDGET_FLAGS(host_->native_view()) & GTK_NO_WINDOW) == 0; 102 (GTK_WIDGET_FLAGS(host_->native_view()) & GTK_NO_WINDOW) == 0;
126 if (!has_window) { 103 if (!has_window) {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 } 144 }
168 145
169 void NativeViewHostGtk::SetFocus() { 146 void NativeViewHostGtk::SetFocus() {
170 NOTIMPLEMENTED(); 147 NOTIMPLEMENTED();
171 } 148 }
172 149
173 //////////////////////////////////////////////////////////////////////////////// 150 ////////////////////////////////////////////////////////////////////////////////
174 // NativeViewHostGtk, private: 151 // NativeViewHostGtk, private:
175 152
176 // static 153 // static
177 void NativeViewHostGtk::CallDestroy(GtkObject* object) { 154 void NativeViewHostGtk::CallDestroy(GtkObject* object,
178 View* view = GetViewForNative(GTK_WIDGET(object)); 155 NativeViewHostGtk* host) {
179 if (!view) 156 return host->host_->NativeViewDestroyed();
180 return;
181
182 return static_cast<NativeViewHost*>(view)->NativeViewDestroyed();
183 } 157 }
184 158
185 //////////////////////////////////////////////////////////////////////////////// 159 ////////////////////////////////////////////////////////////////////////////////
186 // NativeViewHostWrapper, public: 160 // NativeViewHostWrapper, public:
187 161
188 // static 162 // static
189 NativeViewHostWrapper* NativeViewHostWrapper::CreateWrapper( 163 NativeViewHostWrapper* NativeViewHostWrapper::CreateWrapper(
190 NativeViewHost* host) { 164 NativeViewHost* host) {
191 return new NativeViewHostGtk(host); 165 return new NativeViewHostGtk(host);
192 } 166 }
193 167
194 } // namespace views 168 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698