| 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" | |
| 14 #include "views/widget/widget_gtk.h" | 13 #include "views/widget/widget_gtk.h" |
| 15 | 14 |
| 16 namespace views { | 15 namespace views { |
| 17 | 16 |
| 18 namespace { | 17 namespace { |
| 19 static bool signal_id_initialized_ = false; | 18 static bool signal_id_initialized_ = false; |
| 20 static guint focus_in_event_signal_id_; | 19 static guint focus_in_event_signal_id_; |
| 21 static guint focus_out_event_signal_id_; | 20 static guint focus_out_event_signal_id_; |
| 22 | 21 |
| 23 //////////////////////////////////////////////////////////////////////////////// | 22 //////////////////////////////////////////////////////////////////////////////// |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 int child_h = h; | 221 int child_h = h; |
| 223 if (installed_clip_) { | 222 if (installed_clip_) { |
| 224 child_x = -installed_clip_bounds_.x(); | 223 child_x = -installed_clip_bounds_.x(); |
| 225 child_y = -installed_clip_bounds_.y(); | 224 child_y = -installed_clip_bounds_.y(); |
| 226 fixed_x += -child_x; | 225 fixed_x += -child_x; |
| 227 fixed_y += -child_y; | 226 fixed_y += -child_y; |
| 228 fixed_w = std::min(installed_clip_bounds_.width(), w); | 227 fixed_w = std::min(installed_clip_bounds_.width(), w); |
| 229 fixed_h = std::min(installed_clip_bounds_.height(), h); | 228 fixed_h = std::min(installed_clip_bounds_.height(), h); |
| 230 } | 229 } |
| 231 | 230 |
| 232 // Size and place the hosted NativeView. It should be done BEFORE placing | |
| 233 // fixed_ itself, otherwise controls will initially appear at 0,0 of fixed_ | |
| 234 // parent. | |
| 235 GtkAllocation alloc = { child_x, child_y, child_w, child_h }; | |
| 236 gtk_widget_size_allocate(host_->native_view(), &alloc); | |
| 237 gtk_views_fixed_set_use_allocated_size(host_->native_view(), true); | |
| 238 gtk_fixed_move(GTK_FIXED(fixed_), host_->native_view(), child_x, child_y); | |
| 239 | |
| 240 // Size and place the fixed_. | 231 // Size and place the fixed_. |
| 241 GetHostWidget()->PositionChild(fixed_, fixed_x, fixed_y, fixed_w, fixed_h); | 232 GetHostWidget()->PositionChild(fixed_, fixed_x, fixed_y, fixed_w, fixed_h); |
| 242 | 233 |
| 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 |
| 243 gtk_widget_show(fixed_); | 238 gtk_widget_show(fixed_); |
| 244 gtk_widget_show(host_->native_view()); | 239 gtk_widget_show(host_->native_view()); |
| 245 } | 240 } |
| 246 | 241 |
| 247 void NativeViewHostGtk::HideWidget() { | 242 void NativeViewHostGtk::HideWidget() { |
| 248 gtk_widget_hide(fixed_); | 243 gtk_widget_hide(fixed_); |
| 249 } | 244 } |
| 250 | 245 |
| 251 void NativeViewHostGtk::SetFocus() { | 246 void NativeViewHostGtk::SetFocus() { |
| 252 DCHECK(host_->native_view()); | 247 DCHECK(host_->native_view()); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 270 if (focused_widget) { | 265 if (focused_widget) { |
| 271 // A descendant of our fixed has focus. When we destroy the fixed focus is | 266 // A descendant of our fixed has focus. When we destroy the fixed focus is |
| 272 // automatically moved. Temporarily move focus to our host widget, then | 267 // automatically moved. Temporarily move focus to our host widget, then |
| 273 // restore focus after we create the new fixed_. This way focus hasn't | 268 // restore focus after we create the new fixed_. This way focus hasn't |
| 274 // really moved. | 269 // really moved. |
| 275 gtk_widget_grab_focus(GetHostWidget()->GetNativeView()); | 270 gtk_widget_grab_focus(GetHostWidget()->GetNativeView()); |
| 276 } | 271 } |
| 277 | 272 |
| 278 DestroyFixed(); | 273 DestroyFixed(); |
| 279 | 274 |
| 280 fixed_ = gtk_views_fixed_new(); | 275 fixed_ = gtk_fixed_new(); |
| 281 gtk_widget_set_name(fixed_, "views-native-view-host-fixed"); | 276 gtk_widget_set_name(fixed_, "views-native-view-host-fixed"); |
| 282 gtk_fixed_set_has_window(GTK_FIXED(fixed_), needs_window); | 277 gtk_fixed_set_has_window(GTK_FIXED(fixed_), needs_window); |
| 283 // Defeat refcounting. We need to own the fixed. | 278 // Defeat refcounting. We need to own the fixed. |
| 284 gtk_widget_ref(fixed_); | 279 gtk_widget_ref(fixed_); |
| 285 | 280 |
| 286 WidgetGtk* widget_gtk = GetHostWidget(); | 281 WidgetGtk* widget_gtk = GetHostWidget(); |
| 287 if (widget_gtk) | 282 if (widget_gtk) |
| 288 widget_gtk->AddChild(fixed_); | 283 widget_gtk->AddChild(fixed_); |
| 289 | 284 |
| 290 if (host_->native_view()) | 285 if (host_->native_view()) |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 //////////////////////////////////////////////////////////////////////////////// | 360 //////////////////////////////////////////////////////////////////////////////// |
| 366 // NativeViewHostWrapper, public: | 361 // NativeViewHostWrapper, public: |
| 367 | 362 |
| 368 // static | 363 // static |
| 369 NativeViewHostWrapper* NativeViewHostWrapper::CreateWrapper( | 364 NativeViewHostWrapper* NativeViewHostWrapper::CreateWrapper( |
| 370 NativeViewHost* host) { | 365 NativeViewHost* host) { |
| 371 return new NativeViewHostGtk(host); | 366 return new NativeViewHostGtk(host); |
| 372 } | 367 } |
| 373 | 368 |
| 374 } // namespace views | 369 } // namespace views |
| OLD | NEW |