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

Side by Side Diff: content/renderer/accessibility/renderer_accessibility_focus_only.cc

Issue 407493002: Revert of Migrate accessibility from RenderView to RenderFrame. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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/renderer/accessibility/renderer_accessibility_focus_only.h" 5 #include "content/renderer/accessibility/renderer_accessibility_focus_only.h"
6 6
7 #include "content/renderer/render_frame_impl.h"
8 #include "content/renderer/render_view_impl.h" 7 #include "content/renderer/render_view_impl.h"
9 #include "third_party/WebKit/public/web/WebDocument.h" 8 #include "third_party/WebKit/public/web/WebDocument.h"
10 #include "third_party/WebKit/public/web/WebElement.h" 9 #include "third_party/WebKit/public/web/WebElement.h"
11 #include "third_party/WebKit/public/web/WebLocalFrame.h" 10 #include "third_party/WebKit/public/web/WebLocalFrame.h"
12 #include "third_party/WebKit/public/web/WebNode.h" 11 #include "third_party/WebKit/public/web/WebNode.h"
13 #include "third_party/WebKit/public/web/WebView.h" 12 #include "third_party/WebKit/public/web/WebView.h"
14 #include "ui/accessibility/ax_node_data.h" 13 #include "ui/accessibility/ax_node_data.h"
15 14
16 using blink::WebDocument; 15 using blink::WebDocument;
17 using blink::WebElement; 16 using blink::WebElement;
18 using blink::WebNode; 17 using blink::WebNode;
19 using blink::WebView; 18 using blink::WebView;
20 19
21 namespace { 20 namespace {
22 // The root node will always have id 1. Let each child node have a new 21 // The root node will always have id 1. Let each child node have a new
23 // id starting with 2. 22 // id starting with 2.
24 const int kInitialId = 2; 23 const int kInitialId = 2;
25 } 24 }
26 25
27 namespace content { 26 namespace content {
28 27
29 RendererAccessibilityFocusOnly::RendererAccessibilityFocusOnly( 28 RendererAccessibilityFocusOnly::RendererAccessibilityFocusOnly(
30 RenderFrameImpl* render_frame) 29 RenderViewImpl* render_view)
31 : RendererAccessibility(render_frame), 30 : RendererAccessibility(render_view),
32 next_id_(kInitialId) { 31 next_id_(kInitialId) {
33 } 32 }
34 33
35 RendererAccessibilityFocusOnly::~RendererAccessibilityFocusOnly() { 34 RendererAccessibilityFocusOnly::~RendererAccessibilityFocusOnly() {
36 } 35 }
37 36
38 void RendererAccessibilityFocusOnly::HandleWebAccessibilityEvent( 37 void RendererAccessibilityFocusOnly::HandleWebAccessibilityEvent(
39 const blink::WebAXObject& obj, blink::WebAXEvent event) { 38 const blink::WebAXObject& obj, blink::WebAXEvent event) {
40 // Do nothing. 39 // Do nothing.
41 } 40 }
42 41
43 RendererAccessibilityType RendererAccessibilityFocusOnly::GetType() { 42 RendererAccessibilityType RendererAccessibilityFocusOnly::GetType() {
44 return RendererAccessibilityTypeFocusOnly; 43 return RendererAccessibilityTypeFocusOnly;
45 } 44 }
46 45
47 void RendererAccessibilityFocusOnly::FocusedNodeChanged(const WebNode& node) { 46 void RendererAccessibilityFocusOnly::FocusedNodeChanged(const WebNode& node) {
48 // Send the new accessible tree and post a native focus event. 47 // Send the new accessible tree and post a native focus event.
49 HandleFocusedNodeChanged(node, true); 48 HandleFocusedNodeChanged(node, true);
50 } 49 }
51 50
52 void RendererAccessibilityFocusOnly::DidFinishLoad() { 51 void RendererAccessibilityFocusOnly::DidFinishLoad(
52 blink::WebLocalFrame* frame) {
53 WebView* view = render_view()->GetWebView();
54 if (view->focusedFrame() != frame)
55 return;
56
57 WebDocument document = frame->document();
53 // Send an accessible tree to the browser, but do not post a native 58 // Send an accessible tree to the browser, but do not post a native
54 // focus event. This is important so that if focus is initially in an 59 // focus event. This is important so that if focus is initially in an
55 // editable text field, Windows will know to pop up the keyboard if the 60 // editable text field, Windows will know to pop up the keyboard if the
56 // user touches it and focus doesn't change. 61 // user touches it and focus doesn't change.
57 const WebDocument& document = GetMainDocument();
58 HandleFocusedNodeChanged(document.focusedElement(), false); 62 HandleFocusedNodeChanged(document.focusedElement(), false);
59 } 63 }
60 64
61 void RendererAccessibilityFocusOnly::HandleFocusedNodeChanged( 65 void RendererAccessibilityFocusOnly::HandleFocusedNodeChanged(
62 const WebNode& node, 66 const WebNode& node,
63 bool send_focus_event) { 67 bool send_focus_event) {
64 const WebDocument& document = GetMainDocument(); 68 const WebDocument& document = GetMainDocument();
65 if (document.isNull()) 69 if (document.isNull())
66 return; 70 return;
67 71
68 bool node_has_focus; 72 bool node_has_focus;
69 bool node_is_editable_text; 73 bool node_is_editable_text;
70 // Check HasIMETextFocus first, because it will correctly handle 74 // Check HasIMETextFocus first, because it will correctly handle
71 // focus in a text box inside a ppapi plug-in. Otherwise fall back on 75 // focus in a text box inside a ppapi plug-in. Otherwise fall back on
72 // checking the focused node in Blink. 76 // checking the focused node in Blink.
73 if (render_frame_->render_view()->HasIMETextFocus()) { 77 if (render_view_->HasIMETextFocus()) {
74 node_has_focus = true; 78 node_has_focus = true;
75 node_is_editable_text = true; 79 node_is_editable_text = true;
76 } else { 80 } else {
77 node_has_focus = !node.isNull(); 81 node_has_focus = !node.isNull();
78 node_is_editable_text = 82 node_is_editable_text =
79 node_has_focus && render_frame_->render_view()->IsEditableNode(node); 83 node_has_focus && render_view_->IsEditableNode(node);
80 } 84 }
81 85
82 std::vector<AccessibilityHostMsg_EventParams> events; 86 std::vector<AccessibilityHostMsg_EventParams> events;
83 events.push_back(AccessibilityHostMsg_EventParams()); 87 events.push_back(AccessibilityHostMsg_EventParams());
84 AccessibilityHostMsg_EventParams& event = events[0]; 88 AccessibilityHostMsg_EventParams& event = events[0];
85 89
86 // If we want to update the browser's accessibility tree but not send a 90 // If we want to update the browser's accessibility tree but not send a
87 // native focus changed event, we can send a LayoutComplete 91 // native focus changed event, we can send a LayoutComplete
88 // event, which doesn't post a native event on Windows. 92 // event, which doesn't post a native event on Windows.
89 event.event_type = 93 event.event_type =
90 send_focus_event ? ui::AX_EVENT_FOCUS : ui::AX_EVENT_LAYOUT_COMPLETE; 94 send_focus_event ? ui::AX_EVENT_FOCUS : ui::AX_EVENT_LAYOUT_COMPLETE;
91 95
92 // Set the id that the event applies to: the root node if nothing 96 // Set the id that the event applies to: the root node if nothing
93 // has focus, otherwise the focused node. 97 // has focus, otherwise the focused node.
94 event.id = node_has_focus ? next_id_ : 1; 98 event.id = node_has_focus ? next_id_ : 1;
95 99
96 event.update.nodes.resize(2); 100 event.update.nodes.resize(2);
97 ui::AXNodeData& root = event.update.nodes[0]; 101 ui::AXNodeData& root = event.update.nodes[0];
98 ui::AXNodeData& child = event.update.nodes[1]; 102 ui::AXNodeData& child = event.update.nodes[1];
99 103
100 // Always include the root of the tree, the document. It always has id 1. 104 // Always include the root of the tree, the document. It always has id 1.
101 root.id = 1; 105 root.id = 1;
102 root.role = ui::AX_ROLE_ROOT_WEB_AREA; 106 root.role = ui::AX_ROLE_ROOT_WEB_AREA;
103 root.state = 107 root.state =
104 (1 << ui::AX_STATE_READ_ONLY) | 108 (1 << ui::AX_STATE_READ_ONLY) |
105 (1 << ui::AX_STATE_FOCUSABLE); 109 (1 << ui::AX_STATE_FOCUSABLE);
106 if (!node_has_focus) 110 if (!node_has_focus)
107 root.state |= (1 << ui::AX_STATE_FOCUSED); 111 root.state |= (1 << ui::AX_STATE_FOCUSED);
108 root.location = gfx::Rect(render_frame_->render_view()->size()); 112 root.location = gfx::Rect(render_view_->size());
109 root.child_ids.push_back(next_id_); 113 root.child_ids.push_back(next_id_);
110 114
111 child.id = next_id_; 115 child.id = next_id_;
112 child.role = ui::AX_ROLE_GROUP; 116 child.role = ui::AX_ROLE_GROUP;
113 117
114 if (!node.isNull() && node.isElementNode()) { 118 if (!node.isNull() && node.isElementNode()) {
115 child.location = gfx::Rect( 119 child.location = gfx::Rect(
116 const_cast<WebNode&>(node).to<WebElement>().boundsInViewportSpace()); 120 const_cast<WebNode&>(node).to<WebElement>().boundsInViewportSpace());
117 } else if (render_frame_->render_view()->HasIMETextFocus()) { 121 } else if (render_view_->HasIMETextFocus()) {
118 child.location = root.location; 122 child.location = root.location;
119 } else { 123 } else {
120 child.location = gfx::Rect(); 124 child.location = gfx::Rect();
121 } 125 }
122 126
123 if (node_has_focus) { 127 if (node_has_focus) {
124 child.state = 128 child.state =
125 (1 << ui::AX_STATE_FOCUSABLE) | 129 (1 << ui::AX_STATE_FOCUSABLE) |
126 (1 << ui::AX_STATE_FOCUSED); 130 (1 << ui::AX_STATE_FOCUSED);
127 if (!node_is_editable_text) 131 if (!node_is_editable_text)
(...skipping 14 matching lines...) Expand all
142 146
143 Send(new AccessibilityHostMsg_Events(routing_id(), events)); 147 Send(new AccessibilityHostMsg_Events(routing_id(), events));
144 148
145 // Increment the id, wrap back when we get past a million. 149 // Increment the id, wrap back when we get past a million.
146 next_id_++; 150 next_id_++;
147 if (next_id_ > 1000000) 151 if (next_id_ > 1000000)
148 next_id_ = kInitialId; 152 next_id_ = kInitialId;
149 } 153 }
150 154
151 } // namespace content 155 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/accessibility/renderer_accessibility_focus_only.h ('k') | content/renderer/render_frame_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698