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 | 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/focus/focus_manager.h" |
11 #include "views/widget/widget_gtk.h" | 12 #include "views/widget/widget_gtk.h" |
12 | 13 |
13 namespace views { | 14 namespace views { |
14 | 15 |
15 //////////////////////////////////////////////////////////////////////////////// | 16 //////////////////////////////////////////////////////////////////////////////// |
16 // NativeViewHostGtk, public: | 17 // NativeViewHostGtk, public: |
17 | 18 |
18 NativeViewHostGtk::NativeViewHostGtk(NativeViewHost* host) | 19 NativeViewHostGtk::NativeViewHostGtk(NativeViewHost* host) |
19 : host_(host), | 20 : host_(host), |
20 installed_clip_(false), | 21 installed_clip_(false), |
21 destroy_signal_id_(0), | 22 destroy_signal_id_(0), |
| 23 focus_signal_id_(0), |
22 fixed_(NULL) { | 24 fixed_(NULL) { |
23 CreateFixed(false); | 25 CreateFixed(false); |
24 } | 26 } |
25 | 27 |
26 NativeViewHostGtk::~NativeViewHostGtk() { | 28 NativeViewHostGtk::~NativeViewHostGtk() { |
27 if (fixed_) | 29 if (fixed_) |
28 gtk_widget_destroy(fixed_); | 30 gtk_widget_destroy(fixed_); |
29 } | 31 } |
30 | 32 |
31 //////////////////////////////////////////////////////////////////////////////// | 33 //////////////////////////////////////////////////////////////////////////////// |
32 // NativeViewHostGtk, NativeViewHostWrapper implementation: | 34 // NativeViewHostGtk, NativeViewHostWrapper implementation: |
33 | 35 |
34 void NativeViewHostGtk::NativeViewAttached() { | 36 void NativeViewHostGtk::NativeViewAttached() { |
35 DCHECK(host_->native_view()); | 37 DCHECK(host_->native_view()); |
36 if (gtk_widget_get_parent(host_->native_view())) | 38 if (gtk_widget_get_parent(host_->native_view())) |
37 gtk_widget_reparent(host_->native_view(), fixed_); | 39 gtk_widget_reparent(host_->native_view(), fixed_); |
38 else | 40 else |
39 gtk_container_add(GTK_CONTAINER(fixed_), host_->native_view()); | 41 gtk_container_add(GTK_CONTAINER(fixed_), host_->native_view()); |
40 | 42 |
41 if (!destroy_signal_id_) { | 43 if (!destroy_signal_id_) { |
42 destroy_signal_id_ = g_signal_connect(G_OBJECT(host_->native_view()), | 44 destroy_signal_id_ = g_signal_connect(G_OBJECT(host_->native_view()), |
43 "destroy", G_CALLBACK(CallDestroy), | 45 "destroy", G_CALLBACK(CallDestroy), |
44 this); | 46 this); |
45 } | 47 } |
46 | 48 |
| 49 if (!focus_signal_id_) { |
| 50 focus_signal_id_ = g_signal_connect(G_OBJECT(host_->native_view()), |
| 51 "focus-in-event", |
| 52 G_CALLBACK(CallFocusIn), this); |
| 53 } |
| 54 |
47 // Always layout though. | 55 // Always layout though. |
48 host_->Layout(); | 56 host_->Layout(); |
49 | 57 |
50 // We own the native view as long as it's attached, so that we can safely | 58 // We own the native view as long as it's attached, so that we can safely |
51 // reparent it in multiple passes. | 59 // reparent it in multiple passes. |
52 gtk_widget_ref(host_->native_view()); | 60 gtk_widget_ref(host_->native_view()); |
53 | 61 |
54 // TODO(port): figure out focus. | 62 // TODO(port): figure out focus. |
55 } | 63 } |
56 | 64 |
57 void NativeViewHostGtk::NativeViewDetaching() { | 65 void NativeViewHostGtk::NativeViewDetaching() { |
58 DCHECK(host_->native_view()); | 66 DCHECK(host_->native_view()); |
59 | 67 |
60 g_signal_handler_disconnect(G_OBJECT(host_->native_view()), | 68 g_signal_handler_disconnect(G_OBJECT(host_->native_view()), |
61 destroy_signal_id_); | 69 destroy_signal_id_); |
62 destroy_signal_id_ = 0; | 70 destroy_signal_id_ = 0; |
63 | 71 |
64 // TODO(port): focus. | 72 g_signal_handler_disconnect(G_OBJECT(host_->native_view()), |
65 // FocusManager::UninstallFocusSubclass(native_view()); | 73 focus_signal_id_); |
| 74 focus_signal_id_ = 0; |
| 75 |
66 installed_clip_ = false; | 76 installed_clip_ = false; |
67 | 77 |
68 // Release ownership back to the caller. | 78 // Release ownership back to the caller. |
69 gtk_widget_unref(host_->native_view()); | 79 gtk_widget_unref(host_->native_view()); |
70 } | 80 } |
71 | 81 |
72 void NativeViewHostGtk::AddedToWidget() { | 82 void NativeViewHostGtk::AddedToWidget() { |
73 if (gtk_widget_get_parent(fixed_)) | 83 if (gtk_widget_get_parent(fixed_)) |
74 GetHostWidget()->ReparentChild(fixed_); | 84 GetHostWidget()->ReparentChild(fixed_); |
75 else | 85 else |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 | 157 |
148 gtk_widget_show(fixed_); | 158 gtk_widget_show(fixed_); |
149 gtk_widget_show(host_->native_view()); | 159 gtk_widget_show(host_->native_view()); |
150 } | 160 } |
151 | 161 |
152 void NativeViewHostGtk::HideWidget() { | 162 void NativeViewHostGtk::HideWidget() { |
153 gtk_widget_hide(fixed_); | 163 gtk_widget_hide(fixed_); |
154 } | 164 } |
155 | 165 |
156 void NativeViewHostGtk::SetFocus() { | 166 void NativeViewHostGtk::SetFocus() { |
157 NOTIMPLEMENTED(); | 167 DCHECK(host_->native_view()); |
| 168 gtk_widget_grab_focus(host_->native_view()); |
158 } | 169 } |
159 | 170 |
160 //////////////////////////////////////////////////////////////////////////////// | 171 //////////////////////////////////////////////////////////////////////////////// |
161 // NativeViewHostGtk, private: | 172 // NativeViewHostGtk, private: |
162 | 173 |
163 void NativeViewHostGtk::CreateFixed(bool needs_window) { | 174 void NativeViewHostGtk::CreateFixed(bool needs_window) { |
164 DestroyFixed(); | 175 DestroyFixed(); |
165 | 176 |
166 fixed_ = gtk_fixed_new(); | 177 fixed_ = gtk_fixed_new(); |
167 gtk_fixed_set_has_window(GTK_FIXED(fixed_), needs_window); | 178 gtk_fixed_set_has_window(GTK_FIXED(fixed_), needs_window); |
(...skipping 24 matching lines...) Expand all Loading... |
192 fixed_ = NULL; | 203 fixed_ = NULL; |
193 } | 204 } |
194 | 205 |
195 WidgetGtk* NativeViewHostGtk::GetHostWidget() const { | 206 WidgetGtk* NativeViewHostGtk::GetHostWidget() const { |
196 return static_cast<WidgetGtk*>(host_->GetWidget()); | 207 return static_cast<WidgetGtk*>(host_->GetWidget()); |
197 } | 208 } |
198 | 209 |
199 // static | 210 // static |
200 void NativeViewHostGtk::CallDestroy(GtkObject* object, | 211 void NativeViewHostGtk::CallDestroy(GtkObject* object, |
201 NativeViewHostGtk* host) { | 212 NativeViewHostGtk* host) { |
202 return host->host_->NativeViewDestroyed(); | 213 host->host_->NativeViewDestroyed(); |
| 214 } |
| 215 |
| 216 // static |
| 217 void NativeViewHostGtk::CallFocusIn(GtkWidget* widget, |
| 218 » » » » GdkEventFocus* event, |
| 219 NativeViewHostGtk* host) { |
| 220 FocusManager* focus_manager = |
| 221 FocusManager::GetFocusManagerForNativeView(widget); |
| 222 if (!focus_manager) { |
| 223 NOTREACHED(); |
| 224 return; |
| 225 } |
| 226 focus_manager->SetFocusedView(host->host_->focus_view()); |
203 } | 227 } |
204 | 228 |
205 //////////////////////////////////////////////////////////////////////////////// | 229 //////////////////////////////////////////////////////////////////////////////// |
206 // NativeViewHostWrapper, public: | 230 // NativeViewHostWrapper, public: |
207 | 231 |
208 // static | 232 // static |
209 NativeViewHostWrapper* NativeViewHostWrapper::CreateWrapper( | 233 NativeViewHostWrapper* NativeViewHostWrapper::CreateWrapper( |
210 NativeViewHost* host) { | 234 NativeViewHost* host) { |
211 return new NativeViewHostGtk(host); | 235 return new NativeViewHostGtk(host); |
212 } | 236 } |
213 | 237 |
214 } // namespace views | 238 } // namespace views |
OLD | NEW |