| 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 "chrome/browser/renderer_host/render_widget_host_view_gtk.h" | 5 #include "chrome/browser/renderer_host/render_widget_host_view_gtk.h" |
| 6 | 6 |
| 7 // If this gets included after the gtk headers, then a bunch of compiler | 7 // If this gets included after the gtk headers, then a bunch of compiler |
| 8 // errors happen because of a "#define Status int" in Xlib.h, which interacts | 8 // errors happen because of a "#define Status int" in Xlib.h, which interacts |
| 9 // badly with URLRequestStatus::Status. | 9 // badly with URLRequestStatus::Status. |
| 10 #include "chrome/common/render_messages.h" | 10 #include "chrome/common/render_messages.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 #include "chrome/browser/renderer_host/gtk_im_context_wrapper.h" | 32 #include "chrome/browser/renderer_host/gtk_im_context_wrapper.h" |
| 33 #include "chrome/browser/renderer_host/gtk_key_bindings_handler.h" | 33 #include "chrome/browser/renderer_host/gtk_key_bindings_handler.h" |
| 34 #include "chrome/browser/renderer_host/render_widget_host.h" | 34 #include "chrome/browser/renderer_host/render_widget_host.h" |
| 35 #include "chrome/browser/renderer_host/video_layer_x.h" | 35 #include "chrome/browser/renderer_host/video_layer_x.h" |
| 36 #include "chrome/common/chrome_switches.h" | 36 #include "chrome/common/chrome_switches.h" |
| 37 #include "chrome/common/native_web_keyboard_event.h" | 37 #include "chrome/common/native_web_keyboard_event.h" |
| 38 #include "gfx/gtk_util.h" | 38 #include "gfx/gtk_util.h" |
| 39 #include "third_party/WebKit/WebKit/chromium/public/gtk/WebInputEventFactory.h" | 39 #include "third_party/WebKit/WebKit/chromium/public/gtk/WebInputEventFactory.h" |
| 40 #include "webkit/glue/webcursor_gtk_data.h" | 40 #include "webkit/glue/webcursor_gtk_data.h" |
| 41 | 41 |
| 42 #if defined(OS_CHROMEOS) |
| 43 #include "views/widget/tooltip_window_gtk.h" |
| 44 #endif // defined(OS_CHROMEOS) |
| 45 |
| 42 static const int kMaxWindowWidth = 4000; | 46 static const int kMaxWindowWidth = 4000; |
| 43 static const int kMaxWindowHeight = 4000; | 47 static const int kMaxWindowHeight = 4000; |
| 44 | 48 |
| 45 static const char* kRenderWidgetHostViewKey = "__RENDER_WIDGET_HOST_VIEW__"; | 49 static const char* kRenderWidgetHostViewKey = "__RENDER_WIDGET_HOST_VIEW__"; |
| 46 | 50 |
| 47 using WebKit::WebInputEventFactory; | 51 using WebKit::WebInputEventFactory; |
| 48 | 52 |
| 49 // This class is a simple convenience wrapper for Gtk functions. It has only | 53 // This class is a simple convenience wrapper for Gtk functions. It has only |
| 50 // static methods. | 54 // static methods. |
| 51 class RenderWidgetHostViewGtkWidget { | 55 class RenderWidgetHostViewGtkWidget { |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 view_.Destroy(); | 346 view_.Destroy(); |
| 343 } | 347 } |
| 344 | 348 |
| 345 void RenderWidgetHostViewGtk::InitAsChild() { | 349 void RenderWidgetHostViewGtk::InitAsChild() { |
| 346 view_.Own(RenderWidgetHostViewGtkWidget::CreateNewWidget(this)); | 350 view_.Own(RenderWidgetHostViewGtkWidget::CreateNewWidget(this)); |
| 347 // |im_context_| must be created after creating |view_| widget. | 351 // |im_context_| must be created after creating |view_| widget. |
| 348 im_context_.reset(new GtkIMContextWrapper(this)); | 352 im_context_.reset(new GtkIMContextWrapper(this)); |
| 349 // |key_bindings_handler_| must be created after creating |view_| widget. | 353 // |key_bindings_handler_| must be created after creating |view_| widget. |
| 350 key_bindings_handler_.reset(new GtkKeyBindingsHandler(view_.get())); | 354 key_bindings_handler_.reset(new GtkKeyBindingsHandler(view_.get())); |
| 351 plugin_container_manager_.set_host_widget(view_.get()); | 355 plugin_container_manager_.set_host_widget(view_.get()); |
| 356 |
| 357 #if defined(OS_CHROMEOS) |
| 358 tooltip_window_.reset(new views::TooltipWindowGtk(view_.get())); |
| 359 #endif // defined(OS_CHROMEOS) |
| 360 |
| 352 gtk_widget_show(view_.get()); | 361 gtk_widget_show(view_.get()); |
| 353 } | 362 } |
| 354 | 363 |
| 355 void RenderWidgetHostViewGtk::InitAsPopup( | 364 void RenderWidgetHostViewGtk::InitAsPopup( |
| 356 RenderWidgetHostView* parent_host_view, const gfx::Rect& pos) { | 365 RenderWidgetHostView* parent_host_view, const gfx::Rect& pos) { |
| 357 parent_host_view_ = parent_host_view; | 366 parent_host_view_ = parent_host_view; |
| 358 parent_ = parent_host_view->GetNativeView(); | 367 parent_ = parent_host_view->GetNativeView(); |
| 359 GtkWidget* popup = gtk_window_new(GTK_WINDOW_POPUP); | 368 GtkWidget* popup = gtk_window_new(GTK_WINDOW_POPUP); |
| 360 view_.Own(RenderWidgetHostViewGtkWidget::CreateNewWidget(this)); | 369 view_.Own(RenderWidgetHostViewGtkWidget::CreateNewWidget(this)); |
| 361 // |im_context_| must be created after creating |view_| widget. | 370 // |im_context_| must be created after creating |view_| widget. |
| 362 im_context_.reset(new GtkIMContextWrapper(this)); | 371 im_context_.reset(new GtkIMContextWrapper(this)); |
| 363 // |key_bindings_handler_| must be created after creating |view_| widget. | 372 // |key_bindings_handler_| must be created after creating |view_| widget. |
| 364 key_bindings_handler_.reset(new GtkKeyBindingsHandler(view_.get())); | 373 key_bindings_handler_.reset(new GtkKeyBindingsHandler(view_.get())); |
| 365 plugin_container_manager_.set_host_widget(view_.get()); | 374 plugin_container_manager_.set_host_widget(view_.get()); |
| 375 |
| 376 #if defined(OS_CHROMEOS) |
| 377 tooltip_window_.reset(new views::TooltipWindowGtk(view_.get())); |
| 378 #endif // defined(OS_CHROMEOS) |
| 379 |
| 366 gtk_container_add(GTK_CONTAINER(popup), view_.get()); | 380 gtk_container_add(GTK_CONTAINER(popup), view_.get()); |
| 367 | 381 |
| 368 // If we are not activatable, we don't want to grab keyboard input, | 382 // If we are not activatable, we don't want to grab keyboard input, |
| 369 // and webkit will manage our destruction. | 383 // and webkit will manage our destruction. |
| 370 if (NeedsInputGrab()) { | 384 if (NeedsInputGrab()) { |
| 371 // Grab all input for the app. If a click lands outside the bounds of the | 385 // Grab all input for the app. If a click lands outside the bounds of the |
| 372 // popup, WebKit will notice and destroy us. Before doing this we need | 386 // popup, WebKit will notice and destroy us. Before doing this we need |
| 373 // to ensure that the the popup is added to the browser's window group, | 387 // to ensure that the the popup is added to the browser's window group, |
| 374 // to allow for the grabs to work correctly. | 388 // to allow for the grabs to work correctly. |
| 375 gtk_window_group_add_window(gtk_window_get_group( | 389 gtk_window_group_add_window(gtk_window_get_group( |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 601 // this itself). | 615 // this itself). |
| 602 // I filed https://bugzilla.gnome.org/show_bug.cgi?id=604641 upstream. | 616 // I filed https://bugzilla.gnome.org/show_bug.cgi?id=604641 upstream. |
| 603 const std::wstring& clamped_tooltip = | 617 const std::wstring& clamped_tooltip = |
| 604 l10n_util::TruncateString(tooltip_text, kMaxTooltipLength); | 618 l10n_util::TruncateString(tooltip_text, kMaxTooltipLength); |
| 605 | 619 |
| 606 if (clamped_tooltip.empty()) { | 620 if (clamped_tooltip.empty()) { |
| 607 gtk_widget_set_has_tooltip(view_.get(), FALSE); | 621 gtk_widget_set_has_tooltip(view_.get(), FALSE); |
| 608 } else { | 622 } else { |
| 609 gtk_widget_set_tooltip_text(view_.get(), | 623 gtk_widget_set_tooltip_text(view_.get(), |
| 610 WideToUTF8(clamped_tooltip).c_str()); | 624 WideToUTF8(clamped_tooltip).c_str()); |
| 625 #if defined(OS_CHROMEOS) |
| 626 tooltip_window_->SetTooltipText(clamped_tooltip); |
| 627 #endif // defined(OS_CHROMEOS) |
| 611 } | 628 } |
| 612 } | 629 } |
| 613 | 630 |
| 614 void RenderWidgetHostViewGtk::SelectionChanged(const std::string& text) { | 631 void RenderWidgetHostViewGtk::SelectionChanged(const std::string& text) { |
| 615 GtkClipboard* x_clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY); | 632 GtkClipboard* x_clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY); |
| 616 gtk_clipboard_set_text(x_clipboard, text.c_str(), text.length()); | 633 gtk_clipboard_set_text(x_clipboard, text.c_str(), text.length()); |
| 617 } | 634 } |
| 618 | 635 |
| 619 void RenderWidgetHostViewGtk::ShowingContextMenu(bool showing) { | 636 void RenderWidgetHostViewGtk::ShowingContextMenu(bool showing) { |
| 620 is_showing_context_menu_ = showing; | 637 is_showing_context_menu_ = showing; |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 842 } | 859 } |
| 843 | 860 |
| 844 // static | 861 // static |
| 845 RenderWidgetHostView* | 862 RenderWidgetHostView* |
| 846 RenderWidgetHostView::GetRenderWidgetHostViewFromNativeView( | 863 RenderWidgetHostView::GetRenderWidgetHostViewFromNativeView( |
| 847 gfx::NativeView widget) { | 864 gfx::NativeView widget) { |
| 848 gpointer user_data = g_object_get_data(G_OBJECT(widget), | 865 gpointer user_data = g_object_get_data(G_OBJECT(widget), |
| 849 kRenderWidgetHostViewKey); | 866 kRenderWidgetHostViewKey); |
| 850 return reinterpret_cast<RenderWidgetHostView*>(user_data); | 867 return reinterpret_cast<RenderWidgetHostView*>(user_data); |
| 851 } | 868 } |
| OLD | NEW |