Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(260)

Side by Side Diff: content/browser/renderer_host/render_widget_host_view_gtk.cc

Issue 10382051: Add initial GTK web accessibility framework (third attempt). (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 <atk/atk.h>
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/debug/trace_event.h" 22 #include "base/debug/trace_event.h"
24 #include "base/logging.h" 23 #include "base/logging.h"
25 #include "base/message_loop.h" 24 #include "base/message_loop.h"
26 #include "base/metrics/histogram.h" 25 #include "base/metrics/histogram.h"
27 #include "base/string_number_conversions.h" 26 #include "base/string_number_conversions.h"
28 #include "base/time.h" 27 #include "base/time.h"
29 #include "base/utf_offset_string_conversions.h" 28 #include "base/utf_offset_string_conversions.h"
30 #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" 31 #include "content/browser/renderer_host/backing_store_gtk.h"
32 #include "content/browser/renderer_host/gtk_im_context_wrapper.h" 32 #include "content/browser/renderer_host/gtk_im_context_wrapper.h"
33 #include "content/browser/renderer_host/gtk_key_bindings_handler.h" 33 #include "content/browser/renderer_host/gtk_key_bindings_handler.h"
34 #include "content/browser/renderer_host/gtk_window_utils.h" 34 #include "content/browser/renderer_host/gtk_window_utils.h"
35 #include "content/browser/renderer_host/render_view_host_impl.h" 35 #include "content/browser/renderer_host/render_view_host_impl.h"
36 #include "content/common/gpu/gpu_messages.h" 36 #include "content/common/gpu/gpu_messages.h"
37 #include "content/public/browser/native_web_keyboard_event.h" 37 #include "content/public/browser/native_web_keyboard_event.h"
38 #include "content/public/browser/render_view_host_delegate.h" 38 #include "content/public/browser/render_view_host_delegate.h"
39 #include "content/public/common/content_switches.h" 39 #include "content/public/common/content_switches.h"
40 #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
105 using content::RenderWidgetHostImpl; 105 using content::RenderWidgetHostImpl;
106 using content::RenderWidgetHostView; 106 using content::RenderWidgetHostView;
107 using content::RenderWidgetHostViewPort; 107 using content::RenderWidgetHostViewPort;
108 using WebKit::WebInputEventFactory; 108 using WebKit::WebInputEventFactory;
109 using WebKit::WebMouseWheelEvent; 109 using WebKit::WebMouseWheelEvent;
110 110
111 // 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
112 // static methods. 112 // static methods.
113 class RenderWidgetHostViewGtkWidget { 113 class RenderWidgetHostViewGtkWidget {
114 public: 114 public:
115 static AtkObject* GetAccessible(void* userdata) {
116 return (static_cast<RenderWidgetHostViewGtk*>(userdata))->
117 GetAccessible();
118 }
119
115 static GtkWidget* CreateNewWidget(RenderWidgetHostViewGtk* host_view) { 120 static GtkWidget* CreateNewWidget(RenderWidgetHostViewGtk* host_view) {
116 GtkWidget* widget = gtk_preserve_window_new(); 121 GtkWidget* widget = gtk_preserve_window_new();
117 gtk_widget_set_name(widget, "chrome-render-widget-host-view"); 122 gtk_widget_set_name(widget, "chrome-render-widget-host-view");
118 // 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
119 // called in repsonse to an "expose-event" signal. 124 // called in repsonse to an "expose-event" signal.
120 gtk_widget_set_double_buffered(widget, FALSE); 125 gtk_widget_set_double_buffered(widget, FALSE);
121 gtk_widget_set_redraw_on_allocate(widget, FALSE); 126 gtk_widget_set_redraw_on_allocate(widget, FALSE);
122 gtk_widget_modify_bg(widget, GTK_STATE_NORMAL, &kBGColor); 127 gtk_widget_modify_bg(widget, GTK_STATE_NORMAL, &kBGColor);
123 // Allow the browser window to be resized freely. 128 // Allow the browser window to be resized freely.
124 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
163 G_CALLBACK(OnCrossingEvent), host_view); 168 G_CALLBACK(OnCrossingEvent), host_view);
164 g_signal_connect(widget, "client-event", 169 g_signal_connect(widget, "client-event",
165 G_CALLBACK(OnClientEvent), host_view); 170 G_CALLBACK(OnClientEvent), host_view);
166 171
167 172
168 // 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
169 // WebContentsView which handles zoom events. 174 // WebContentsView which handles zoom events.
170 g_signal_connect_after(widget, "scroll-event", 175 g_signal_connect_after(widget, "scroll-event",
171 G_CALLBACK(OnMouseScrollEvent), host_view); 176 G_CALLBACK(OnMouseScrollEvent), host_view);
172 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
173 return widget; 182 return widget;
174 } 183 }
175 184
176 private: 185 private:
177 static gboolean OnExposeEvent(GtkWidget* widget, 186 static gboolean OnExposeEvent(GtkWidget* widget,
178 GdkEventExpose* expose, 187 GdkEventExpose* expose,
179 RenderWidgetHostViewGtk* host_view) { 188 RenderWidgetHostViewGtk* host_view) {
180 if (host_view->is_hidden_) 189 if (host_view->is_hidden_)
181 return FALSE; 190 return FALSE;
182 const gfx::Rect damage_rect(expose->area); 191 const gfx::Rect damage_rect(expose->area);
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 is_popup_first_mouse_release_(true), 564 is_popup_first_mouse_release_(true),
556 was_imcontext_focused_before_grab_(false), 565 was_imcontext_focused_before_grab_(false),
557 do_x_grab_(false), 566 do_x_grab_(false),
558 is_fullscreen_(false), 567 is_fullscreen_(false),
559 destroy_handler_id_(0), 568 destroy_handler_id_(0),
560 dragged_at_horizontal_edge_(0), 569 dragged_at_horizontal_edge_(0),
561 dragged_at_vertical_edge_(0), 570 dragged_at_vertical_edge_(0),
562 compositing_surface_(gfx::kNullPluginWindow), 571 compositing_surface_(gfx::kNullPluginWindow),
563 last_mouse_down_(NULL) { 572 last_mouse_down_(NULL) {
564 host_->SetView(this); 573 host_->SetView(this);
565
566 // TODO(dmazzoni): This conditional intentionally never evaluates to true.
567 // Introduce a dependency on libatk with a trivial change so that the
568 // Linux packaging scripts can be updated simultaneously to allow it.
569 // Once this change is in, a real patch to enable ATK support will be
570 // added and these two lines will be removed: http://crbug.com/24585
571 if (!host_)
572 atk_object_set_role(NULL, ATK_ROLE_HTML_CONTAINER);
573 } 574 }
574 575
575 RenderWidgetHostViewGtk::~RenderWidgetHostViewGtk() { 576 RenderWidgetHostViewGtk::~RenderWidgetHostViewGtk() {
576 UnlockMouse(); 577 UnlockMouse();
577 set_last_mouse_down(NULL); 578 set_last_mouse_down(NULL);
578 view_.Destroy(); 579 view_.Destroy();
579 } 580 }
580 581
581 void RenderWidgetHostViewGtk::InitAsChild( 582 void RenderWidgetHostViewGtk::InitAsChild(
582 gfx::NativeView parent_view) { 583 gfx::NativeView parent_view) {
(...skipping 823 matching lines...) Expand 10 before | Expand all | Expand 10 after
1406 return new RenderWidgetHostViewGtk(widget); 1407 return new RenderWidgetHostViewGtk(widget);
1407 } 1408 }
1408 1409
1409 // static 1410 // static
1410 void content::RenderWidgetHostViewPort::GetDefaultScreenInfo( 1411 void content::RenderWidgetHostViewPort::GetDefaultScreenInfo(
1411 WebKit::WebScreenInfo* results) { 1412 WebKit::WebScreenInfo* results) {
1412 GdkWindow* gdk_window = 1413 GdkWindow* gdk_window =
1413 gdk_display_get_default_group(gdk_display_get_default()); 1414 gdk_display_get_default_group(gdk_display_get_default());
1414 content::GetScreenInfoFromNativeWindow(gdk_window, results); 1415 content::GetScreenInfoFromNativeWindow(gdk_window, results);
1415 } 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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698