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" |
30 #include "content/browser/renderer_host/backing_store_gtk.h" | 31 #include "content/browser/renderer_host/backing_store_gtk.h" |
31 #include "content/browser/renderer_host/gtk_im_context_wrapper.h" | 32 #include "content/browser/renderer_host/gtk_im_context_wrapper.h" |
32 #include "content/browser/renderer_host/gtk_key_bindings_handler.h" | 33 #include "content/browser/renderer_host/gtk_key_bindings_handler.h" |
33 #include "content/browser/renderer_host/gtk_window_utils.h" | 34 #include "content/browser/renderer_host/gtk_window_utils.h" |
34 #include "content/browser/renderer_host/render_view_host_impl.h" | 35 #include "content/browser/renderer_host/render_view_host_impl.h" |
35 #include "content/common/gpu/gpu_messages.h" | 36 #include "content/common/gpu/gpu_messages.h" |
36 #include "content/public/browser/native_web_keyboard_event.h" | 37 #include "content/public/browser/native_web_keyboard_event.h" |
37 #include "content/public/browser/render_view_host_delegate.h" | 38 #include "content/public/browser/render_view_host_delegate.h" |
38 #include "content/public/common/content_switches.h" | 39 #include "content/public/common/content_switches.h" |
39 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" | 40 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 using content::RenderWidgetHostImpl; | 105 using content::RenderWidgetHostImpl; |
105 using content::RenderWidgetHostView; | 106 using content::RenderWidgetHostView; |
106 using content::RenderWidgetHostViewPort; | 107 using content::RenderWidgetHostViewPort; |
107 using WebKit::WebInputEventFactory; | 108 using WebKit::WebInputEventFactory; |
108 using WebKit::WebMouseWheelEvent; | 109 using WebKit::WebMouseWheelEvent; |
109 | 110 |
110 // This class is a simple convenience wrapper for Gtk functions. It has only | 111 // This class is a simple convenience wrapper for Gtk functions. It has only |
111 // static methods. | 112 // static methods. |
112 class RenderWidgetHostViewGtkWidget { | 113 class RenderWidgetHostViewGtkWidget { |
113 public: | 114 public: |
| 115 static AtkObject* GetAccessible(void* userdata) { |
| 116 return (static_cast<RenderWidgetHostViewGtk*>(userdata))-> |
| 117 GetAccessible(); |
| 118 } |
| 119 |
114 static GtkWidget* CreateNewWidget(RenderWidgetHostViewGtk* host_view) { | 120 static GtkWidget* CreateNewWidget(RenderWidgetHostViewGtk* host_view) { |
115 GtkWidget* widget = gtk_preserve_window_new(); | 121 GtkWidget* widget = gtk_preserve_window_new(); |
116 gtk_widget_set_name(widget, "chrome-render-widget-host-view"); | 122 gtk_widget_set_name(widget, "chrome-render-widget-host-view"); |
117 // We manually double-buffer in Paint() because Paint() may or may not be | 123 // We manually double-buffer in Paint() because Paint() may or may not be |
118 // called in repsonse to an "expose-event" signal. | 124 // called in repsonse to an "expose-event" signal. |
119 gtk_widget_set_double_buffered(widget, FALSE); | 125 gtk_widget_set_double_buffered(widget, FALSE); |
120 gtk_widget_set_redraw_on_allocate(widget, FALSE); | 126 gtk_widget_set_redraw_on_allocate(widget, FALSE); |
121 gtk_widget_modify_bg(widget, GTK_STATE_NORMAL, &kBGColor); | 127 gtk_widget_modify_bg(widget, GTK_STATE_NORMAL, &kBGColor); |
122 // Allow the browser window to be resized freely. | 128 // Allow the browser window to be resized freely. |
123 gtk_widget_set_size_request(widget, 0, 0); | 129 gtk_widget_set_size_request(widget, 0, 0); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 G_CALLBACK(OnCrossingEvent), host_view); | 168 G_CALLBACK(OnCrossingEvent), host_view); |
163 g_signal_connect(widget, "client-event", | 169 g_signal_connect(widget, "client-event", |
164 G_CALLBACK(OnClientEvent), host_view); | 170 G_CALLBACK(OnClientEvent), host_view); |
165 | 171 |
166 | 172 |
167 // Connect after so that we are called after the handler installed by the | 173 // Connect after so that we are called after the handler installed by the |
168 // WebContentsView which handles zoom events. | 174 // WebContentsView which handles zoom events. |
169 g_signal_connect_after(widget, "scroll-event", | 175 g_signal_connect_after(widget, "scroll-event", |
170 G_CALLBACK(OnMouseScrollEvent), host_view); | 176 G_CALLBACK(OnMouseScrollEvent), host_view); |
171 | 177 |
| 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 |
172 return widget; | 182 return widget; |
173 } | 183 } |
174 | 184 |
175 private: | 185 private: |
176 static gboolean OnExposeEvent(GtkWidget* widget, | 186 static gboolean OnExposeEvent(GtkWidget* widget, |
177 GdkEventExpose* expose, | 187 GdkEventExpose* expose, |
178 RenderWidgetHostViewGtk* host_view) { | 188 RenderWidgetHostViewGtk* host_view) { |
179 if (host_view->is_hidden_) | 189 if (host_view->is_hidden_) |
180 return FALSE; | 190 return FALSE; |
181 const gfx::Rect damage_rect(expose->area); | 191 const gfx::Rect damage_rect(expose->area); |
(...skipping 1215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1397 return new RenderWidgetHostViewGtk(widget); | 1407 return new RenderWidgetHostViewGtk(widget); |
1398 } | 1408 } |
1399 | 1409 |
1400 // static | 1410 // static |
1401 void content::RenderWidgetHostViewPort::GetDefaultScreenInfo( | 1411 void content::RenderWidgetHostViewPort::GetDefaultScreenInfo( |
1402 WebKit::WebScreenInfo* results) { | 1412 WebKit::WebScreenInfo* results) { |
1403 GdkWindow* gdk_window = | 1413 GdkWindow* gdk_window = |
1404 gdk_display_get_default_group(gdk_display_get_default()); | 1414 gdk_display_get_default_group(gdk_display_get_default()); |
1405 content::GetScreenInfoFromNativeWindow(gdk_window, results); | 1415 content::GetScreenInfoFromNativeWindow(gdk_window, results); |
1406 } | 1416 } |
| 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 |