OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "content/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 net::URLRequestStatus::Status. | 9 // badly with net::URLRequestStatus::Status. |
10 #include "chrome/common/render_messages.h" | |
11 #include "content/common/view_messages.h" | 10 #include "content/common/view_messages.h" |
12 | 11 |
13 #include <cairo/cairo.h> | 12 #include <cairo/cairo.h> |
14 #include <gdk/gdk.h> | 13 #include <gdk/gdk.h> |
15 #include <gdk/gdkkeysyms.h> | 14 #include <gdk/gdkkeysyms.h> |
16 #include <gdk/gdkx.h> | 15 #include <gdk/gdkx.h> |
17 #include <gtk/gtk.h> | 16 #include <gtk/gtk.h> |
18 | 17 |
19 #include <algorithm> | 18 #include <algorithm> |
20 #include <string> | 19 #include <string> |
21 | 20 |
22 #include "base/command_line.h" | 21 #include "base/command_line.h" |
23 #include "base/logging.h" | 22 #include "base/logging.h" |
24 #include "base/message_loop.h" | 23 #include "base/message_loop.h" |
25 #include "base/metrics/histogram.h" | 24 #include "base/metrics/histogram.h" |
26 #include "base/string_number_conversions.h" | 25 #include "base/string_number_conversions.h" |
27 #include "base/time.h" | 26 #include "base/time.h" |
28 #include "base/utf_string_conversions.h" | 27 #include "base/utf_string_conversions.h" |
29 #include "chrome/browser/renderer_host/gtk_im_context_wrapper.h" | |
30 #include "chrome/browser/ui/gtk/gtk_util.h" | |
31 #include "chrome/common/chrome_switches.h" | |
32 #include "content/browser/renderer_host/backing_store_x.h" | 28 #include "content/browser/renderer_host/backing_store_x.h" |
| 29 #include "content/browser/renderer_host/gtk_im_context_wrapper.h" |
33 #include "content/browser/renderer_host/render_view_host.h" | 30 #include "content/browser/renderer_host/render_view_host.h" |
34 #include "content/browser/renderer_host/render_view_host_delegate.h" | 31 #include "content/browser/renderer_host/render_view_host_delegate.h" |
35 #include "content/browser/renderer_host/render_widget_host.h" | 32 #include "content/browser/renderer_host/render_widget_host.h" |
| 33 #include "content/common/content_switches.h" |
36 #include "content/common/native_web_keyboard_event.h" | 34 #include "content/common/native_web_keyboard_event.h" |
37 #include "third_party/WebKit/Source/WebKit/chromium/public/gtk/WebInputEventFact
ory.h" | 35 #include "third_party/WebKit/Source/WebKit/chromium/public/gtk/WebInputEventFact
ory.h" |
38 #include "ui/base/l10n/l10n_util.h" | 36 #include "ui/base/text/text_elider.h" |
39 #include "ui/base/x/x11_util.h" | 37 #include "ui/base/x/x11_util.h" |
| 38 #include "ui/gfx/gtk_native_view_id_manager.h" |
40 #include "ui/gfx/gtk_preserve_window.h" | 39 #include "ui/gfx/gtk_preserve_window.h" |
41 #include "ui/gfx/gtk_native_view_id_manager.h" | |
42 #include "webkit/glue/webaccessibility.h" | 40 #include "webkit/glue/webaccessibility.h" |
43 #include "webkit/glue/webcursor_gtk_data.h" | 41 #include "webkit/glue/webcursor_gtk_data.h" |
44 #include "webkit/plugins/npapi/webplugin.h" | 42 #include "webkit/plugins/npapi/webplugin.h" |
45 | 43 |
46 #if defined(OS_CHROMEOS) | 44 #if defined(OS_CHROMEOS) |
47 #include "views/widget/tooltip_window_gtk.h" | 45 #include "views/widget/tooltip_window_gtk.h" |
48 #else | 46 #else |
49 #include "chrome/browser/renderer_host/gtk_key_bindings_handler.h" | 47 #include "content/browser/renderer_host/gtk_key_bindings_handler.h" |
50 #endif // defined(OS_CHROMEOS) | 48 #endif // defined(OS_CHROMEOS) |
51 | 49 |
52 namespace { | 50 namespace { |
53 | 51 |
54 const int kMaxWindowWidth = 4000; | 52 const int kMaxWindowWidth = 4000; |
55 const int kMaxWindowHeight = 4000; | 53 const int kMaxWindowHeight = 4000; |
56 const char* kRenderWidgetHostViewKey = "__RENDER_WIDGET_HOST_VIEW__"; | 54 const char* kRenderWidgetHostViewKey = "__RENDER_WIDGET_HOST_VIEW__"; |
57 | 55 |
58 // The duration of the fade-out animation. See |overlay_animation_|. | 56 // The duration of the fade-out animation. See |overlay_animation_|. |
59 const int kFadeEffectDuration = 300; | 57 const int kFadeEffectDuration = 300; |
60 | 58 |
61 #if defined(OS_CHROMEOS) | 59 #if defined(OS_CHROMEOS) |
62 // TODO(davemoore) Under Chromeos we are increasing the rate that the trackpad | 60 // TODO(davemoore) Under Chromeos we are increasing the rate that the trackpad |
63 // generates events to get better precisions. Eventually we will coordinate the | 61 // generates events to get better precisions. Eventually we will coordinate the |
64 // driver and this setting to ensure they match. | 62 // driver and this setting to ensure they match. |
65 const float kDefaultScrollPixelsPerTick = 20; | 63 const float kDefaultScrollPixelsPerTick = 20; |
66 #else | 64 #else |
67 // See WebInputEventFactor.cpp for a reason for this being the default | 65 // See WebInputEventFactor.cpp for a reason for this being the default |
68 // scroll size for linux. | 66 // scroll size for linux. |
69 const float kDefaultScrollPixelsPerTick = 160.0f / 3.0f; | 67 const float kDefaultScrollPixelsPerTick = 160.0f / 3.0f; |
70 #endif | 68 #endif |
71 | 69 |
| 70 const GdkColor kBGColor = |
| 71 #if defined(NDEBUG) |
| 72 { 0, 0xff * 257, 0xff * 257, 0xff * 257 }; |
| 73 #else |
| 74 { 0, 0x00 * 257, 0xff * 257, 0x00 * 257 }; |
| 75 #endif |
| 76 |
72 // Returns the spinning cursor used for loading state. | 77 // Returns the spinning cursor used for loading state. |
73 GdkCursor* GetMozSpinningCursor() { | 78 GdkCursor* GetMozSpinningCursor() { |
74 static GdkCursor* moz_spinning_cursor = NULL; | 79 static GdkCursor* moz_spinning_cursor = NULL; |
75 if (!moz_spinning_cursor) { | 80 if (!moz_spinning_cursor) { |
76 const GdkColor fg = { 0, 0, 0, 0 }; | 81 const GdkColor fg = { 0, 0, 0, 0 }; |
77 const GdkColor bg = { 65535, 65535, 65535, 65535 }; | 82 const GdkColor bg = { 65535, 65535, 65535, 65535 }; |
78 GdkPixmap* source = | 83 GdkPixmap* source = |
79 gdk_bitmap_create_from_data(NULL, moz_spinning_bits, 32, 32); | 84 gdk_bitmap_create_from_data(NULL, moz_spinning_bits, 32, 32); |
80 GdkPixmap* mask = | 85 GdkPixmap* mask = |
81 gdk_bitmap_create_from_data(NULL, moz_spinning_mask_bits, 32, 32); | 86 gdk_bitmap_create_from_data(NULL, moz_spinning_mask_bits, 32, 32); |
(...skipping 14 matching lines...) Expand all Loading... |
96 // static methods. | 101 // static methods. |
97 class RenderWidgetHostViewGtkWidget { | 102 class RenderWidgetHostViewGtkWidget { |
98 public: | 103 public: |
99 static GtkWidget* CreateNewWidget(RenderWidgetHostViewGtk* host_view) { | 104 static GtkWidget* CreateNewWidget(RenderWidgetHostViewGtk* host_view) { |
100 GtkWidget* widget = gtk_preserve_window_new(); | 105 GtkWidget* widget = gtk_preserve_window_new(); |
101 gtk_widget_set_name(widget, "chrome-render-widget-host-view"); | 106 gtk_widget_set_name(widget, "chrome-render-widget-host-view"); |
102 // We manually double-buffer in Paint() because Paint() may or may not be | 107 // We manually double-buffer in Paint() because Paint() may or may not be |
103 // called in repsonse to an "expose-event" signal. | 108 // called in repsonse to an "expose-event" signal. |
104 gtk_widget_set_double_buffered(widget, FALSE); | 109 gtk_widget_set_double_buffered(widget, FALSE); |
105 gtk_widget_set_redraw_on_allocate(widget, FALSE); | 110 gtk_widget_set_redraw_on_allocate(widget, FALSE); |
106 #if defined(NDEBUG) | 111 gtk_widget_modify_bg(widget, GTK_STATE_NORMAL, &kBGColor); |
107 gtk_widget_modify_bg(widget, GTK_STATE_NORMAL, >k_util::kGdkWhite); | |
108 #else | |
109 gtk_widget_modify_bg(widget, GTK_STATE_NORMAL, >k_util::kGdkGreen); | |
110 #endif | |
111 // Allow the browser window to be resized freely. | 112 // Allow the browser window to be resized freely. |
112 gtk_widget_set_size_request(widget, 0, 0); | 113 gtk_widget_set_size_request(widget, 0, 0); |
113 | 114 |
114 gtk_widget_add_events(widget, GDK_EXPOSURE_MASK | | 115 gtk_widget_add_events(widget, GDK_EXPOSURE_MASK | |
115 GDK_POINTER_MOTION_MASK | | 116 GDK_POINTER_MOTION_MASK | |
116 GDK_BUTTON_PRESS_MASK | | 117 GDK_BUTTON_PRESS_MASK | |
117 GDK_BUTTON_RELEASE_MASK | | 118 GDK_BUTTON_RELEASE_MASK | |
118 GDK_KEY_PRESS_MASK | | 119 GDK_KEY_PRESS_MASK | |
119 GDK_KEY_RELEASE_MASK | | 120 GDK_KEY_RELEASE_MASK | |
120 GDK_FOCUS_CHANGE_MASK | | 121 GDK_FOCUS_CHANGE_MASK | |
(...skipping 692 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
813 } | 814 } |
814 | 815 |
815 void RenderWidgetHostViewGtk::SetTooltipText(const std::wstring& tooltip_text) { | 816 void RenderWidgetHostViewGtk::SetTooltipText(const std::wstring& tooltip_text) { |
816 // Maximum number of characters we allow in a tooltip. | 817 // Maximum number of characters we allow in a tooltip. |
817 const int kMaxTooltipLength = 8 << 10; | 818 const int kMaxTooltipLength = 8 << 10; |
818 // Clamp the tooltip length to kMaxTooltipLength so that we don't | 819 // Clamp the tooltip length to kMaxTooltipLength so that we don't |
819 // accidentally DOS the user with a mega tooltip (since GTK doesn't do | 820 // accidentally DOS the user with a mega tooltip (since GTK doesn't do |
820 // this itself). | 821 // this itself). |
821 // I filed https://bugzilla.gnome.org/show_bug.cgi?id=604641 upstream. | 822 // I filed https://bugzilla.gnome.org/show_bug.cgi?id=604641 upstream. |
822 const string16 clamped_tooltip = | 823 const string16 clamped_tooltip = |
823 l10n_util::TruncateString(WideToUTF16Hack(tooltip_text), | 824 ui::TruncateString(WideToUTF16Hack(tooltip_text), |
824 kMaxTooltipLength); | 825 kMaxTooltipLength); |
825 | 826 |
826 if (clamped_tooltip.empty()) { | 827 if (clamped_tooltip.empty()) { |
827 gtk_widget_set_has_tooltip(view_.get(), FALSE); | 828 gtk_widget_set_has_tooltip(view_.get(), FALSE); |
828 } else { | 829 } else { |
829 gtk_widget_set_tooltip_text(view_.get(), | 830 gtk_widget_set_tooltip_text(view_.get(), |
830 UTF16ToUTF8(clamped_tooltip).c_str()); | 831 UTF16ToUTF8(clamped_tooltip).c_str()); |
831 #if defined(OS_CHROMEOS) | 832 #if defined(OS_CHROMEOS) |
832 tooltip_window_->SetTooltipText(UTF16ToWideHack(clamped_tooltip)); | 833 tooltip_window_->SetTooltipText(UTF16ToWideHack(clamped_tooltip)); |
833 #endif // defined(OS_CHROMEOS) | 834 #endif // defined(OS_CHROMEOS) |
834 } | 835 } |
835 } | 836 } |
836 | 837 |
837 void RenderWidgetHostViewGtk::SelectionChanged(const std::string& text, | 838 void RenderWidgetHostViewGtk::SelectionChanged(const std::string& text, |
838 const ui::Range& range, | 839 const ui::Range& range, |
839 const gfx::Point& start, | 840 const gfx::Point& start, |
840 const gfx::Point& end) { | 841 const gfx::Point& end) { |
841 if (!text.empty()) { | 842 if (!text.empty()) { |
842 GtkClipboard* x_clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY); | 843 GtkClipboard* x_clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY); |
843 gtk_clipboard_set_text(x_clipboard, text.c_str(), text.length()); | 844 gtk_clipboard_set_text(x_clipboard, text.c_str(), text.length()); |
844 } | 845 } |
845 } | 846 } |
846 | 847 |
847 void RenderWidgetHostViewGtk::ShowingContextMenu(bool showing) { | 848 void RenderWidgetHostViewGtk::ShowingContextMenu(bool showing) { |
848 is_showing_context_menu_ = showing; | 849 is_showing_context_menu_ = showing; |
849 } | 850 } |
850 | 851 |
851 #if !defined(TOOLKIT_VIEWS) | 852 #if !defined(TOOLKIT_VIEWS) |
852 void RenderWidgetHostViewGtk::AppendInputMethodsContextMenu(MenuGtk* menu) { | 853 GtkWidget* RenderWidgetHostViewGtk::BuildInputMethodsGtkMenu() { |
853 im_context_->AppendInputMethodsContextMenu(menu); | 854 return im_context_->BuildInputMethodsGtkMenu(); |
854 } | 855 } |
855 #endif | 856 #endif |
856 | 857 |
857 gboolean RenderWidgetHostViewGtk::OnWindowStateEvent( | 858 gboolean RenderWidgetHostViewGtk::OnWindowStateEvent( |
858 GtkWidget* widget, | 859 GtkWidget* widget, |
859 GdkEventWindowState* event) { | 860 GdkEventWindowState* event) { |
860 if (is_fullscreen_) { | 861 if (is_fullscreen_) { |
861 // If a fullscreen widget got unfullscreened (e.g. by the window manager), | 862 // If a fullscreen widget got unfullscreened (e.g. by the window manager), |
862 // close it. | 863 // close it. |
863 bool unfullscreened = | 864 bool unfullscreened = |
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1200 } | 1201 } |
1201 | 1202 |
1202 // static | 1203 // static |
1203 RenderWidgetHostView* | 1204 RenderWidgetHostView* |
1204 RenderWidgetHostView::GetRenderWidgetHostViewFromNativeView( | 1205 RenderWidgetHostView::GetRenderWidgetHostViewFromNativeView( |
1205 gfx::NativeView widget) { | 1206 gfx::NativeView widget) { |
1206 gpointer user_data = g_object_get_data(G_OBJECT(widget), | 1207 gpointer user_data = g_object_get_data(G_OBJECT(widget), |
1207 kRenderWidgetHostViewKey); | 1208 kRenderWidgetHostViewKey); |
1208 return reinterpret_cast<RenderWidgetHostView*>(user_data); | 1209 return reinterpret_cast<RenderWidgetHostView*>(user_data); |
1209 } | 1210 } |
OLD | NEW |