Chromium Code Reviews| 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 ((RenderWidgetHostViewGtk*)userdata)->GetAccessible(); | |
|
Evan Stade
2012/05/02 00:03:30
C++ casts (static_cast)
dmazzoni
2012/05/02 06:27:33
Done.
| |
| 117 } | |
| 118 | |
| 114 static GtkWidget* CreateNewWidget(RenderWidgetHostViewGtk* host_view) { | 119 static GtkWidget* CreateNewWidget(RenderWidgetHostViewGtk* host_view) { |
| 115 GtkWidget* widget = gtk_preserve_window_new(); | 120 GtkWidget* widget = gtk_preserve_window_new(); |
| 116 gtk_widget_set_name(widget, "chrome-render-widget-host-view"); | 121 gtk_widget_set_name(widget, "chrome-render-widget-host-view"); |
| 117 // We manually double-buffer in Paint() because Paint() may or may not be | 122 // We manually double-buffer in Paint() because Paint() may or may not be |
| 118 // called in repsonse to an "expose-event" signal. | 123 // called in repsonse to an "expose-event" signal. |
| 119 gtk_widget_set_double_buffered(widget, FALSE); | 124 gtk_widget_set_double_buffered(widget, FALSE); |
| 120 gtk_widget_set_redraw_on_allocate(widget, FALSE); | 125 gtk_widget_set_redraw_on_allocate(widget, FALSE); |
| 121 gtk_widget_modify_bg(widget, GTK_STATE_NORMAL, &kBGColor); | 126 gtk_widget_modify_bg(widget, GTK_STATE_NORMAL, &kBGColor); |
| 122 // Allow the browser window to be resized freely. | 127 // Allow the browser window to be resized freely. |
| 123 gtk_widget_set_size_request(widget, 0, 0); | 128 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); | 167 G_CALLBACK(OnCrossingEvent), host_view); |
| 163 g_signal_connect(widget, "client-event", | 168 g_signal_connect(widget, "client-event", |
| 164 G_CALLBACK(OnClientEvent), host_view); | 169 G_CALLBACK(OnClientEvent), host_view); |
| 165 | 170 |
| 166 | 171 |
| 167 // Connect after so that we are called after the handler installed by the | 172 // Connect after so that we are called after the handler installed by the |
| 168 // WebContentsView which handles zoom events. | 173 // WebContentsView which handles zoom events. |
| 169 g_signal_connect_after(widget, "scroll-event", | 174 g_signal_connect_after(widget, "scroll-event", |
| 170 G_CALLBACK(OnMouseScrollEvent), host_view); | 175 G_CALLBACK(OnMouseScrollEvent), host_view); |
| 171 | 176 |
| 177 // Route calls to get_accessible to the view. | |
| 178 gtk_preserve_window_set_accessible_factory( | |
| 179 GTK_PRESERVE_WINDOW(widget), GetAccessible, (void *)host_view); | |
|
Evan Stade
2012/05/02 00:03:30
C++ casts or GTK casts. I'm surprised that this ca
dmazzoni
2012/05/02 06:27:33
You're right, it wasn't necessary.
| |
| 180 | |
| 172 return widget; | 181 return widget; |
| 173 } | 182 } |
| 174 | 183 |
| 175 private: | 184 private: |
| 176 static gboolean OnExposeEvent(GtkWidget* widget, | 185 static gboolean OnExposeEvent(GtkWidget* widget, |
| 177 GdkEventExpose* expose, | 186 GdkEventExpose* expose, |
| 178 RenderWidgetHostViewGtk* host_view) { | 187 RenderWidgetHostViewGtk* host_view) { |
| 179 if (host_view->is_hidden_) | 188 if (host_view->is_hidden_) |
| 180 return FALSE; | 189 return FALSE; |
| 181 const gfx::Rect damage_rect(expose->area); | 190 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); | 1406 return new RenderWidgetHostViewGtk(widget); |
| 1398 } | 1407 } |
| 1399 | 1408 |
| 1400 // static | 1409 // static |
| 1401 void content::RenderWidgetHostViewPort::GetDefaultScreenInfo( | 1410 void content::RenderWidgetHostViewPort::GetDefaultScreenInfo( |
| 1402 WebKit::WebScreenInfo* results) { | 1411 WebKit::WebScreenInfo* results) { |
| 1403 GdkWindow* gdk_window = | 1412 GdkWindow* gdk_window = |
| 1404 gdk_display_get_default_group(gdk_display_get_default()); | 1413 gdk_display_get_default_group(gdk_display_get_default()); |
| 1405 content::GetScreenInfoFromNativeWindow(gdk_window, results); | 1414 content::GetScreenInfoFromNativeWindow(gdk_window, results); |
| 1406 } | 1415 } |
| 1416 | |
| 1417 void RenderWidgetHostViewGtk::SetAccessibilityFocus(int acc_obj_id) { | |
| 1418 if (!host_) | |
| 1419 return; | |
| 1420 | |
| 1421 host_->AccessibilitySetFocus(acc_obj_id); | |
| 1422 } | |
| 1423 | |
| 1424 void RenderWidgetHostViewGtk::AccessibilityDoDefaultAction(int acc_obj_id) { | |
| 1425 if (!host_) | |
| 1426 return; | |
| 1427 | |
| 1428 host_->AccessibilityDoDefaultAction(acc_obj_id); | |
| 1429 } | |
| 1430 | |
| 1431 void RenderWidgetHostViewGtk::AccessibilityScrollToMakeVisible( | |
| 1432 int acc_obj_id, gfx::Rect subfocus) { | |
| 1433 if (!host_) | |
| 1434 return; | |
| 1435 | |
| 1436 host_->AccessibilityScrollToMakeVisible(acc_obj_id, subfocus); | |
| 1437 } | |
| 1438 | |
| 1439 void RenderWidgetHostViewGtk::AccessibilityScrollToPoint( | |
| 1440 int acc_obj_id, gfx::Point point) { | |
| 1441 if (!host_) | |
| 1442 return; | |
| 1443 | |
| 1444 host_->AccessibilityScrollToPoint(acc_obj_id, point); | |
| 1445 } | |
| 1446 | |
| 1447 void RenderWidgetHostViewGtk::AccessibilitySetTextSelection( | |
| 1448 int acc_obj_id, int start_offset, int end_offset) { | |
| 1449 if (!host_) | |
| 1450 return; | |
| 1451 | |
| 1452 host_->AccessibilitySetTextSelection(acc_obj_id, start_offset, end_offset); | |
| 1453 } | |
| 1454 | |
| 1455 void RenderWidgetHostViewGtk::OnAccessibilityNotifications( | |
| 1456 const std::vector<AccessibilityHostMsg_NotificationParams>& params) { | |
| 1457 if (!browser_accessibility_manager_.get()) { | |
| 1458 GtkWidget* parent = gtk_widget_get_parent(view_.get()); | |
| 1459 browser_accessibility_manager_.reset( | |
| 1460 BrowserAccessibilityManager::CreateEmptyDocument( | |
| 1461 parent, static_cast<WebAccessibility::State>(0), this)); | |
| 1462 } | |
| 1463 browser_accessibility_manager_->OnAccessibilityNotifications(params); | |
| 1464 } | |
| 1465 | |
| 1466 AtkObject* RenderWidgetHostViewGtk::GetAccessible() { | |
| 1467 RenderWidgetHostImpl::From(GetRenderWidgetHost()) | |
| 1468 ->SetAccessibilityMode(AccessibilityModeComplete); | |
|
Evan Stade
2012/05/02 00:03:30
-> on previous line
dmazzoni
2012/05/02 06:27:33
Done.
| |
| 1469 | |
| 1470 if (!browser_accessibility_manager_.get()) { | |
| 1471 GtkWidget* parent = gtk_widget_get_parent(view_.get()); | |
| 1472 browser_accessibility_manager_.reset( | |
| 1473 BrowserAccessibilityManager::CreateEmptyDocument( | |
| 1474 parent, static_cast<WebAccessibility::State>(0), this)); | |
| 1475 } | |
| 1476 BrowserAccessibilityGtk* root = | |
| 1477 browser_accessibility_manager_->GetRoot()->toBrowserAccessibilityGtk(); | |
| 1478 | |
| 1479 atk_object_set_role(root->GetAtkObject(), ATK_ROLE_HTML_CONTAINER); | |
| 1480 return root->GetAtkObject(); | |
| 1481 } | |
| OLD | NEW |