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 30 matching lines...) Expand all Loading... |
41 else | 41 else |
42 gtk_container_add(GTK_CONTAINER(fixed_), host_->native_view()); | 42 gtk_container_add(GTK_CONTAINER(fixed_), host_->native_view()); |
43 | 43 |
44 if (!destroy_signal_id_) { | 44 if (!destroy_signal_id_) { |
45 destroy_signal_id_ = g_signal_connect(G_OBJECT(host_->native_view()), | 45 destroy_signal_id_ = g_signal_connect(G_OBJECT(host_->native_view()), |
46 "destroy", G_CALLBACK(CallDestroy), | 46 "destroy", G_CALLBACK(CallDestroy), |
47 this); | 47 this); |
48 } | 48 } |
49 | 49 |
50 if (!focus_signal_id_) { | 50 if (!focus_signal_id_) { |
51 focus_signal_id_ = g_signal_connect(G_OBJECT(host_->native_view()), | 51 focus_signal_id_ = g_signal_connect(G_OBJECT(host_->focus_native_view()), |
52 "focus-in-event", | 52 "focus-in-event", |
53 G_CALLBACK(CallFocusIn), this); | 53 G_CALLBACK(CallFocusIn), this); |
54 } | 54 } |
55 | 55 |
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() { |
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_->focus_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 // Release ownership back to the caller. | 79 // Release ownership back to the caller. |
80 gtk_widget_unref(host_->native_view()); | 80 gtk_widget_unref(host_->native_view()); |
81 } | 81 } |
82 | 82 |
83 void NativeViewHostGtk::AddedToWidget() { | 83 void NativeViewHostGtk::AddedToWidget() { |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 gtk_fixed_move(GTK_FIXED(fixed_), host_->native_view(), child_x, child_y); | 157 gtk_fixed_move(GTK_FIXED(fixed_), host_->native_view(), child_x, child_y); |
158 | 158 |
159 gtk_widget_show(fixed_); | 159 gtk_widget_show(fixed_); |
160 gtk_widget_show(host_->native_view()); | 160 gtk_widget_show(host_->native_view()); |
161 } | 161 } |
162 | 162 |
163 void NativeViewHostGtk::HideWidget() { | 163 void NativeViewHostGtk::HideWidget() { |
164 gtk_widget_hide(fixed_); | 164 gtk_widget_hide(fixed_); |
165 } | 165 } |
166 | 166 |
167 void NativeViewHostGtk::SetFocus() { | |
168 DCHECK(host_->native_view()); | |
169 gtk_widget_grab_focus(host_->native_view()); | |
170 } | |
171 | |
172 //////////////////////////////////////////////////////////////////////////////// | 167 //////////////////////////////////////////////////////////////////////////////// |
173 // NativeViewHostGtk, private: | 168 // NativeViewHostGtk, private: |
174 | 169 |
175 void NativeViewHostGtk::CreateFixed(bool needs_window) { | 170 void NativeViewHostGtk::CreateFixed(bool needs_window) { |
176 DestroyFixed(); | 171 DestroyFixed(); |
177 | 172 |
178 fixed_ = gtk_fixed_new(); | 173 fixed_ = gtk_fixed_new(); |
179 gtk_fixed_set_has_window(GTK_FIXED(fixed_), needs_window); | 174 gtk_fixed_set_has_window(GTK_FIXED(fixed_), needs_window); |
180 // Defeat refcounting. We need to own the fixed. | 175 // Defeat refcounting. We need to own the fixed. |
181 gtk_widget_ref(fixed_); | 176 gtk_widget_ref(fixed_); |
(...skipping 26 matching lines...) Expand all Loading... |
208 return static_cast<WidgetGtk*>(host_->GetWidget()); | 203 return static_cast<WidgetGtk*>(host_->GetWidget()); |
209 } | 204 } |
210 | 205 |
211 // static | 206 // static |
212 void NativeViewHostGtk::CallDestroy(GtkObject* object, | 207 void NativeViewHostGtk::CallDestroy(GtkObject* object, |
213 NativeViewHostGtk* host) { | 208 NativeViewHostGtk* host) { |
214 host->host_->NativeViewDestroyed(); | 209 host->host_->NativeViewDestroyed(); |
215 } | 210 } |
216 | 211 |
217 // static | 212 // static |
218 void NativeViewHostGtk::CallFocusIn(GtkWidget* widget, | 213 gboolean NativeViewHostGtk::CallFocusIn(GtkWidget* widget, |
219 GdkEventFocus* event, | 214 GdkEventFocus* event, |
220 NativeViewHostGtk* host) { | 215 NativeViewHostGtk* host) { |
221 FocusManager* focus_manager = | 216 host->host_->GotNativeFocus(); |
222 FocusManager::GetFocusManagerForNativeView(widget); | 217 return false; |
223 if (!focus_manager) { | |
224 // TODO(jcampan): http://crbug.com/21378 Reenable this NOTREACHED() when the | |
225 // options page is only based on views. | |
226 // NOTREACHED(); | |
227 NOTIMPLEMENTED(); | |
228 return; | |
229 } | |
230 focus_manager->SetFocusedView(host->host_->focus_view()); | |
231 } | 218 } |
232 | 219 |
233 //////////////////////////////////////////////////////////////////////////////// | 220 //////////////////////////////////////////////////////////////////////////////// |
234 // NativeViewHostWrapper, public: | 221 // NativeViewHostWrapper, public: |
235 | 222 |
236 // static | 223 // static |
237 NativeViewHostWrapper* NativeViewHostWrapper::CreateWrapper( | 224 NativeViewHostWrapper* NativeViewHostWrapper::CreateWrapper( |
238 NativeViewHost* host) { | 225 NativeViewHost* host) { |
239 return new NativeViewHostGtk(host); | 226 return new NativeViewHostGtk(host); |
240 } | 227 } |
241 | 228 |
242 } // namespace views | 229 } // namespace views |
OLD | NEW |