OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/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 "content/common/view_messages.h" | 10 #include "content/common/view_messages.h" |
11 | 11 |
12 #include <cairo/cairo.h> | 12 #include <cairo/cairo.h> |
13 #include <gdk/gdk.h> | 13 #include <gdk/gdk.h> |
14 #include <gdk/gdkkeysyms.h> | 14 #include <gdk/gdkkeysyms.h> |
15 #include <gdk/gdkx.h> | 15 #include <gdk/gdkx.h> |
16 #include <gtk/gtk.h> | 16 #include <gtk/gtk.h> |
17 | 17 |
18 #include <algorithm> | 18 #include <algorithm> |
19 #include <string> | 19 #include <string> |
20 | 20 |
21 #include "base/command_line.h" | 21 #include "base/command_line.h" |
22 #include "base/debug/trace_event.h" | 22 #include "base/debug/trace_event.h" |
23 #include "base/logging.h" | 23 #include "base/logging.h" |
24 #include "base/message_loop.h" | 24 #include "base/message_loop.h" |
25 #include "base/metrics/histogram.h" | 25 #include "base/metrics/histogram.h" |
26 #include "base/string_number_conversions.h" | 26 #include "base/string_number_conversions.h" |
27 #include "base/time.h" | 27 #include "base/time.h" |
28 #include "base/utf_offset_string_conversions.h" | 28 #include "base/utf_offset_string_conversions.h" |
29 #include "base/utf_string_conversions.h" | 29 #include "base/utf_string_conversions.h" |
30 #include "content/browser/accessibility/browser_accessibility_gtk.h" | |
31 #include "content/browser/renderer_host/backing_store_gtk.h" | 30 #include "content/browser/renderer_host/backing_store_gtk.h" |
32 #include "content/browser/renderer_host/gtk_im_context_wrapper.h" | 31 #include "content/browser/renderer_host/gtk_im_context_wrapper.h" |
33 #include "content/browser/renderer_host/gtk_key_bindings_handler.h" | 32 #include "content/browser/renderer_host/gtk_key_bindings_handler.h" |
34 #include "content/browser/renderer_host/gtk_window_utils.h" | 33 #include "content/browser/renderer_host/gtk_window_utils.h" |
35 #include "content/browser/renderer_host/render_view_host_impl.h" | 34 #include "content/browser/renderer_host/render_view_host_impl.h" |
36 #include "content/common/gpu/gpu_messages.h" | 35 #include "content/common/gpu/gpu_messages.h" |
37 #include "content/public/browser/native_web_keyboard_event.h" | 36 #include "content/public/browser/native_web_keyboard_event.h" |
38 #include "content/public/browser/render_view_host_delegate.h" | 37 #include "content/public/browser/render_view_host_delegate.h" |
39 #include "content/public/common/content_switches.h" | 38 #include "content/public/common/content_switches.h" |
40 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" | 39 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 using content::RenderWidgetHostImpl; | 104 using content::RenderWidgetHostImpl; |
106 using content::RenderWidgetHostView; | 105 using content::RenderWidgetHostView; |
107 using content::RenderWidgetHostViewPort; | 106 using content::RenderWidgetHostViewPort; |
108 using WebKit::WebInputEventFactory; | 107 using WebKit::WebInputEventFactory; |
109 using WebKit::WebMouseWheelEvent; | 108 using WebKit::WebMouseWheelEvent; |
110 | 109 |
111 // This class is a simple convenience wrapper for Gtk functions. It has only | 110 // This class is a simple convenience wrapper for Gtk functions. It has only |
112 // static methods. | 111 // static methods. |
113 class RenderWidgetHostViewGtkWidget { | 112 class RenderWidgetHostViewGtkWidget { |
114 public: | 113 public: |
115 static AtkObject* GetAccessible(void* userdata) { | |
116 return (static_cast<RenderWidgetHostViewGtk*>(userdata))-> | |
117 GetAccessible(); | |
118 } | |
119 | |
120 static GtkWidget* CreateNewWidget(RenderWidgetHostViewGtk* host_view) { | 114 static GtkWidget* CreateNewWidget(RenderWidgetHostViewGtk* host_view) { |
121 GtkWidget* widget = gtk_preserve_window_new(); | 115 GtkWidget* widget = gtk_preserve_window_new(); |
122 gtk_widget_set_name(widget, "chrome-render-widget-host-view"); | 116 gtk_widget_set_name(widget, "chrome-render-widget-host-view"); |
123 // We manually double-buffer in Paint() because Paint() may or may not be | 117 // We manually double-buffer in Paint() because Paint() may or may not be |
124 // called in repsonse to an "expose-event" signal. | 118 // called in repsonse to an "expose-event" signal. |
125 gtk_widget_set_double_buffered(widget, FALSE); | 119 gtk_widget_set_double_buffered(widget, FALSE); |
126 gtk_widget_set_redraw_on_allocate(widget, FALSE); | 120 gtk_widget_set_redraw_on_allocate(widget, FALSE); |
127 gtk_widget_modify_bg(widget, GTK_STATE_NORMAL, &kBGColor); | 121 gtk_widget_modify_bg(widget, GTK_STATE_NORMAL, &kBGColor); |
128 // Allow the browser window to be resized freely. | 122 // Allow the browser window to be resized freely. |
129 gtk_widget_set_size_request(widget, 0, 0); | 123 gtk_widget_set_size_request(widget, 0, 0); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 G_CALLBACK(OnCrossingEvent), host_view); | 162 G_CALLBACK(OnCrossingEvent), host_view); |
169 g_signal_connect(widget, "client-event", | 163 g_signal_connect(widget, "client-event", |
170 G_CALLBACK(OnClientEvent), host_view); | 164 G_CALLBACK(OnClientEvent), host_view); |
171 | 165 |
172 | 166 |
173 // Connect after so that we are called after the handler installed by the | 167 // Connect after so that we are called after the handler installed by the |
174 // WebContentsView which handles zoom events. | 168 // WebContentsView which handles zoom events. |
175 g_signal_connect_after(widget, "scroll-event", | 169 g_signal_connect_after(widget, "scroll-event", |
176 G_CALLBACK(OnMouseScrollEvent), host_view); | 170 G_CALLBACK(OnMouseScrollEvent), host_view); |
177 | 171 |
178 // Route calls to get_accessible to the view. | |
179 gtk_preserve_window_set_accessible_factory( | |
180 GTK_PRESERVE_WINDOW(widget), GetAccessible, host_view); | |
181 | |
182 return widget; | 172 return widget; |
183 } | 173 } |
184 | 174 |
185 private: | 175 private: |
186 static gboolean OnExposeEvent(GtkWidget* widget, | 176 static gboolean OnExposeEvent(GtkWidget* widget, |
187 GdkEventExpose* expose, | 177 GdkEventExpose* expose, |
188 RenderWidgetHostViewGtk* host_view) { | 178 RenderWidgetHostViewGtk* host_view) { |
189 if (host_view->is_hidden_) | 179 if (host_view->is_hidden_) |
190 return FALSE; | 180 return FALSE; |
191 const gfx::Rect damage_rect(expose->area); | 181 const gfx::Rect damage_rect(expose->area); |
(...skipping 1215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1407 return new RenderWidgetHostViewGtk(widget); | 1397 return new RenderWidgetHostViewGtk(widget); |
1408 } | 1398 } |
1409 | 1399 |
1410 // static | 1400 // static |
1411 void content::RenderWidgetHostViewPort::GetDefaultScreenInfo( | 1401 void content::RenderWidgetHostViewPort::GetDefaultScreenInfo( |
1412 WebKit::WebScreenInfo* results) { | 1402 WebKit::WebScreenInfo* results) { |
1413 GdkWindow* gdk_window = | 1403 GdkWindow* gdk_window = |
1414 gdk_display_get_default_group(gdk_display_get_default()); | 1404 gdk_display_get_default_group(gdk_display_get_default()); |
1415 content::GetScreenInfoFromNativeWindow(gdk_window, results); | 1405 content::GetScreenInfoFromNativeWindow(gdk_window, results); |
1416 } | 1406 } |
1417 | |
1418 void RenderWidgetHostViewGtk::SetAccessibilityFocus(int acc_obj_id) { | |
1419 if (!host_) | |
1420 return; | |
1421 | |
1422 host_->AccessibilitySetFocus(acc_obj_id); | |
1423 } | |
1424 | |
1425 void RenderWidgetHostViewGtk::AccessibilityDoDefaultAction(int acc_obj_id) { | |
1426 if (!host_) | |
1427 return; | |
1428 | |
1429 host_->AccessibilityDoDefaultAction(acc_obj_id); | |
1430 } | |
1431 | |
1432 void RenderWidgetHostViewGtk::AccessibilityScrollToMakeVisible( | |
1433 int acc_obj_id, gfx::Rect subfocus) { | |
1434 if (!host_) | |
1435 return; | |
1436 | |
1437 host_->AccessibilityScrollToMakeVisible(acc_obj_id, subfocus); | |
1438 } | |
1439 | |
1440 void RenderWidgetHostViewGtk::AccessibilityScrollToPoint( | |
1441 int acc_obj_id, gfx::Point point) { | |
1442 if (!host_) | |
1443 return; | |
1444 | |
1445 host_->AccessibilityScrollToPoint(acc_obj_id, point); | |
1446 } | |
1447 | |
1448 void RenderWidgetHostViewGtk::AccessibilitySetTextSelection( | |
1449 int acc_obj_id, int start_offset, int end_offset) { | |
1450 if (!host_) | |
1451 return; | |
1452 | |
1453 host_->AccessibilitySetTextSelection(acc_obj_id, start_offset, end_offset); | |
1454 } | |
1455 | |
1456 void RenderWidgetHostViewGtk::OnAccessibilityNotifications( | |
1457 const std::vector<AccessibilityHostMsg_NotificationParams>& params) { | |
1458 if (!browser_accessibility_manager_.get()) { | |
1459 GtkWidget* parent = gtk_widget_get_parent(view_.get()); | |
1460 browser_accessibility_manager_.reset( | |
1461 BrowserAccessibilityManager::CreateEmptyDocument( | |
1462 parent, static_cast<WebAccessibility::State>(0), this)); | |
1463 } | |
1464 browser_accessibility_manager_->OnAccessibilityNotifications(params); | |
1465 } | |
1466 | |
1467 AtkObject* RenderWidgetHostViewGtk::GetAccessible() { | |
1468 RenderWidgetHostImpl::From(GetRenderWidgetHost())-> | |
1469 SetAccessibilityMode(AccessibilityModeComplete); | |
1470 | |
1471 if (!browser_accessibility_manager_.get()) { | |
1472 GtkWidget* parent = gtk_widget_get_parent(view_.get()); | |
1473 browser_accessibility_manager_.reset( | |
1474 BrowserAccessibilityManager::CreateEmptyDocument( | |
1475 parent, static_cast<WebAccessibility::State>(0), this)); | |
1476 } | |
1477 BrowserAccessibilityGtk* root = | |
1478 browser_accessibility_manager_->GetRoot()->ToBrowserAccessibilityGtk(); | |
1479 | |
1480 atk_object_set_role(root->GetAtkObject(), ATK_ROLE_HTML_CONTAINER); | |
1481 return root->GetAtkObject(); | |
1482 } | |
OLD | NEW |