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