OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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" |
11 #include "views/controls/native/native_view_host.h" | 11 #include "views/controls/native/native_view_host.h" |
12 #include "views/focus/focus_manager.h" | 12 #include "views/focus/focus_manager.h" |
| 13 #include "views/widget/gtk_views_fixed.h" |
13 #include "views/widget/widget_gtk.h" | 14 #include "views/widget/widget_gtk.h" |
14 | 15 |
15 namespace views { | 16 namespace views { |
16 | 17 |
17 namespace { | 18 namespace { |
18 static bool signal_id_initialized_ = false; | 19 static bool signal_id_initialized_ = false; |
19 static guint focus_in_event_signal_id_; | 20 static guint focus_in_event_signal_id_; |
20 static guint focus_out_event_signal_id_; | 21 static guint focus_out_event_signal_id_; |
21 | 22 |
22 //////////////////////////////////////////////////////////////////////////////// | 23 //////////////////////////////////////////////////////////////////////////////// |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 int child_h = h; | 222 int child_h = h; |
222 if (installed_clip_) { | 223 if (installed_clip_) { |
223 child_x = -installed_clip_bounds_.x(); | 224 child_x = -installed_clip_bounds_.x(); |
224 child_y = -installed_clip_bounds_.y(); | 225 child_y = -installed_clip_bounds_.y(); |
225 fixed_x += -child_x; | 226 fixed_x += -child_x; |
226 fixed_y += -child_y; | 227 fixed_y += -child_y; |
227 fixed_w = std::min(installed_clip_bounds_.width(), w); | 228 fixed_w = std::min(installed_clip_bounds_.width(), w); |
228 fixed_h = std::min(installed_clip_bounds_.height(), h); | 229 fixed_h = std::min(installed_clip_bounds_.height(), h); |
229 } | 230 } |
230 | 231 |
| 232 // Don't call gtk_widget_size_allocate now, as we're possibly in the |
| 233 // middle of a re-size, and it kicks off another re-size, and you |
| 234 // get flashing. Instead, we'll set the desired size as properties |
| 235 // on the widget and queue the re-size. |
| 236 gtk_views_fixed_set_widget_size(host_->native_view(), child_w, child_h); |
| 237 gtk_fixed_move(GTK_FIXED(fixed_), host_->native_view(), child_x, child_y); |
| 238 |
231 // Size and place the fixed_. | 239 // Size and place the fixed_. |
232 GetHostWidget()->PositionChild(fixed_, fixed_x, fixed_y, fixed_w, fixed_h); | 240 GetHostWidget()->PositionChild(fixed_, fixed_x, fixed_y, fixed_w, fixed_h); |
233 | 241 |
234 // Size and place the hosted NativeView. | |
235 gtk_widget_set_size_request(host_->native_view(), child_w, child_h); | |
236 gtk_fixed_move(GTK_FIXED(fixed_), host_->native_view(), child_x, child_y); | |
237 | |
238 gtk_widget_show(fixed_); | 242 gtk_widget_show(fixed_); |
239 gtk_widget_show(host_->native_view()); | 243 gtk_widget_show(host_->native_view()); |
240 } | 244 } |
241 | 245 |
242 void NativeViewHostGtk::HideWidget() { | 246 void NativeViewHostGtk::HideWidget() { |
243 gtk_widget_hide(fixed_); | 247 gtk_widget_hide(fixed_); |
244 } | 248 } |
245 | 249 |
246 void NativeViewHostGtk::SetFocus() { | 250 void NativeViewHostGtk::SetFocus() { |
247 DCHECK(host_->native_view()); | 251 DCHECK(host_->native_view()); |
(...skipping 17 matching lines...) Expand all Loading... |
265 if (focused_widget) { | 269 if (focused_widget) { |
266 // A descendant of our fixed has focus. When we destroy the fixed focus is | 270 // A descendant of our fixed has focus. When we destroy the fixed focus is |
267 // automatically moved. Temporarily move focus to our host widget, then | 271 // automatically moved. Temporarily move focus to our host widget, then |
268 // restore focus after we create the new fixed_. This way focus hasn't | 272 // restore focus after we create the new fixed_. This way focus hasn't |
269 // really moved. | 273 // really moved. |
270 gtk_widget_grab_focus(GetHostWidget()->GetNativeView()); | 274 gtk_widget_grab_focus(GetHostWidget()->GetNativeView()); |
271 } | 275 } |
272 | 276 |
273 DestroyFixed(); | 277 DestroyFixed(); |
274 | 278 |
275 fixed_ = gtk_fixed_new(); | 279 fixed_ = gtk_views_fixed_new(); |
276 gtk_widget_set_name(fixed_, "views-native-view-host-fixed"); | 280 gtk_widget_set_name(fixed_, "views-native-view-host-fixed"); |
277 gtk_fixed_set_has_window(GTK_FIXED(fixed_), needs_window); | 281 gtk_fixed_set_has_window(GTK_FIXED(fixed_), needs_window); |
278 // Defeat refcounting. We need to own the fixed. | 282 // Defeat refcounting. We need to own the fixed. |
279 gtk_widget_ref(fixed_); | 283 gtk_widget_ref(fixed_); |
280 | 284 |
281 WidgetGtk* widget_gtk = GetHostWidget(); | 285 WidgetGtk* widget_gtk = GetHostWidget(); |
282 if (widget_gtk) | 286 if (widget_gtk) |
283 widget_gtk->AddChild(fixed_); | 287 widget_gtk->AddChild(fixed_); |
284 | 288 |
285 if (host_->native_view()) | 289 if (host_->native_view()) |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 //////////////////////////////////////////////////////////////////////////////// | 364 //////////////////////////////////////////////////////////////////////////////// |
361 // NativeViewHostWrapper, public: | 365 // NativeViewHostWrapper, public: |
362 | 366 |
363 // static | 367 // static |
364 NativeViewHostWrapper* NativeViewHostWrapper::CreateWrapper( | 368 NativeViewHostWrapper* NativeViewHostWrapper::CreateWrapper( |
365 NativeViewHost* host) { | 369 NativeViewHost* host) { |
366 return new NativeViewHostGtk(host); | 370 return new NativeViewHostGtk(host); |
367 } | 371 } |
368 | 372 |
369 } // namespace views | 373 } // namespace views |
OLD | NEW |