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/renderer/accessibility/renderer_accessibility_focus_only.h" | 5 #include "content/renderer/accessibility/renderer_accessibility_focus_only.h" |
6 | 6 |
7 #include "content/common/accessibility_node_data.h" | 7 #include "content/common/accessibility_node_data.h" |
8 #include "content/renderer/render_view_impl.h" | 8 #include "content/renderer/render_view_impl.h" |
9 #include "third_party/WebKit/public/web/WebDocument.h" | 9 #include "third_party/WebKit/public/web/WebDocument.h" |
10 #include "third_party/WebKit/public/web/WebElement.h" | 10 #include "third_party/WebKit/public/web/WebElement.h" |
11 #include "third_party/WebKit/public/web/WebFrame.h" | 11 #include "third_party/WebKit/public/web/WebFrame.h" |
12 #include "third_party/WebKit/public/web/WebNode.h" | 12 #include "third_party/WebKit/public/web/WebNode.h" |
13 #include "third_party/WebKit/public/web/WebView.h" | 13 #include "third_party/WebKit/public/web/WebView.h" |
14 | 14 |
15 using WebKit::WebDocument; | 15 using blink::WebDocument; |
16 using WebKit::WebElement; | 16 using blink::WebElement; |
17 using WebKit::WebFrame; | 17 using blink::WebFrame; |
18 using WebKit::WebNode; | 18 using blink::WebNode; |
19 using WebKit::WebView; | 19 using blink::WebView; |
20 | 20 |
21 namespace { | 21 namespace { |
22 // The root node will always have id 1. Let each child node have a new | 22 // The root node will always have id 1. Let each child node have a new |
23 // id starting with 2. | 23 // id starting with 2. |
24 const int kInitialId = 2; | 24 const int kInitialId = 2; |
25 } | 25 } |
26 | 26 |
27 namespace content { | 27 namespace content { |
28 | 28 |
29 RendererAccessibilityFocusOnly::RendererAccessibilityFocusOnly( | 29 RendererAccessibilityFocusOnly::RendererAccessibilityFocusOnly( |
30 RenderViewImpl* render_view) | 30 RenderViewImpl* render_view) |
31 : RendererAccessibility(render_view), | 31 : RendererAccessibility(render_view), |
32 next_id_(kInitialId) { | 32 next_id_(kInitialId) { |
33 } | 33 } |
34 | 34 |
35 RendererAccessibilityFocusOnly::~RendererAccessibilityFocusOnly() { | 35 RendererAccessibilityFocusOnly::~RendererAccessibilityFocusOnly() { |
36 } | 36 } |
37 | 37 |
38 void RendererAccessibilityFocusOnly::HandleWebAccessibilityEvent( | 38 void RendererAccessibilityFocusOnly::HandleWebAccessibilityEvent( |
39 const WebKit::WebAXObject& obj, WebKit::WebAXEvent event) { | 39 const blink::WebAXObject& obj, blink::WebAXEvent event) { |
40 // Do nothing. | 40 // Do nothing. |
41 } | 41 } |
42 | 42 |
43 void RendererAccessibilityFocusOnly::FocusedNodeChanged(const WebNode& node) { | 43 void RendererAccessibilityFocusOnly::FocusedNodeChanged(const WebNode& node) { |
44 // Send the new accessible tree and post a native focus event. | 44 // Send the new accessible tree and post a native focus event. |
45 HandleFocusedNodeChanged(node, true); | 45 HandleFocusedNodeChanged(node, true); |
46 } | 46 } |
47 | 47 |
48 void RendererAccessibilityFocusOnly::DidFinishLoad(WebKit::WebFrame* frame) { | 48 void RendererAccessibilityFocusOnly::DidFinishLoad(blink::WebFrame* frame) { |
49 WebView* view = render_view()->GetWebView(); | 49 WebView* view = render_view()->GetWebView(); |
50 if (view->focusedFrame() != frame) | 50 if (view->focusedFrame() != frame) |
51 return; | 51 return; |
52 | 52 |
53 WebDocument document = frame->document(); | 53 WebDocument document = frame->document(); |
54 // Send an accessible tree to the browser, but do not post a native | 54 // Send an accessible tree to the browser, but do not post a native |
55 // focus event. This is important so that if focus is initially in an | 55 // focus event. This is important so that if focus is initially in an |
56 // editable text field, Windows will know to pop up the keyboard if the | 56 // editable text field, Windows will know to pop up the keyboard if the |
57 // user touches it and focus doesn't change. | 57 // user touches it and focus doesn't change. |
58 HandleFocusedNodeChanged(document.focusedNode(), false); | 58 HandleFocusedNodeChanged(document.focusedNode(), false); |
(...skipping 22 matching lines...) Expand all Loading... |
81 | 81 |
82 std::vector<AccessibilityHostMsg_EventParams> events; | 82 std::vector<AccessibilityHostMsg_EventParams> events; |
83 events.push_back(AccessibilityHostMsg_EventParams()); | 83 events.push_back(AccessibilityHostMsg_EventParams()); |
84 AccessibilityHostMsg_EventParams& event = events[0]; | 84 AccessibilityHostMsg_EventParams& event = events[0]; |
85 | 85 |
86 // If we want to update the browser's accessibility tree but not send a | 86 // If we want to update the browser's accessibility tree but not send a |
87 // native focus changed event, we can send a LayoutComplete | 87 // native focus changed event, we can send a LayoutComplete |
88 // event, which doesn't post a native event on Windows. | 88 // event, which doesn't post a native event on Windows. |
89 event.event_type = | 89 event.event_type = |
90 send_focus_event ? | 90 send_focus_event ? |
91 WebKit::WebAXEventFocus : | 91 blink::WebAXEventFocus : |
92 WebKit::WebAXEventLayoutComplete; | 92 blink::WebAXEventLayoutComplete; |
93 | 93 |
94 // Set the id that the event applies to: the root node if nothing | 94 // Set the id that the event applies to: the root node if nothing |
95 // has focus, otherwise the focused node. | 95 // has focus, otherwise the focused node. |
96 event.id = node_has_focus ? next_id_ : 1; | 96 event.id = node_has_focus ? next_id_ : 1; |
97 | 97 |
98 event.nodes.resize(2); | 98 event.nodes.resize(2); |
99 AccessibilityNodeData& root = event.nodes[0]; | 99 AccessibilityNodeData& root = event.nodes[0]; |
100 AccessibilityNodeData& child = event.nodes[1]; | 100 AccessibilityNodeData& child = event.nodes[1]; |
101 | 101 |
102 // Always include the root of the tree, the document. It always has id 1. | 102 // Always include the root of the tree, the document. It always has id 1. |
103 root.id = 1; | 103 root.id = 1; |
104 root.role = WebKit::WebAXRoleRootWebArea; | 104 root.role = blink::WebAXRoleRootWebArea; |
105 root.state = | 105 root.state = |
106 (1 << WebKit::WebAXStateReadonly) | | 106 (1 << blink::WebAXStateReadonly) | |
107 (1 << WebKit::WebAXStateFocusable); | 107 (1 << blink::WebAXStateFocusable); |
108 if (!node_has_focus) | 108 if (!node_has_focus) |
109 root.state |= (1 << WebKit::WebAXStateFocused); | 109 root.state |= (1 << blink::WebAXStateFocused); |
110 root.location = gfx::Rect(render_view_->size()); | 110 root.location = gfx::Rect(render_view_->size()); |
111 root.child_ids.push_back(next_id_); | 111 root.child_ids.push_back(next_id_); |
112 | 112 |
113 child.id = next_id_; | 113 child.id = next_id_; |
114 child.role = WebKit::WebAXRoleGroup; | 114 child.role = blink::WebAXRoleGroup; |
115 | 115 |
116 if (!node.isNull() && node.isElementNode()) { | 116 if (!node.isNull() && node.isElementNode()) { |
117 child.location = gfx::Rect( | 117 child.location = gfx::Rect( |
118 const_cast<WebNode&>(node).to<WebElement>().boundsInViewportSpace()); | 118 const_cast<WebNode&>(node).to<WebElement>().boundsInViewportSpace()); |
119 } else if (render_view_->HasIMETextFocus()) { | 119 } else if (render_view_->HasIMETextFocus()) { |
120 child.location = root.location; | 120 child.location = root.location; |
121 } else { | 121 } else { |
122 child.location = gfx::Rect(); | 122 child.location = gfx::Rect(); |
123 } | 123 } |
124 | 124 |
125 if (node_has_focus) { | 125 if (node_has_focus) { |
126 child.state = | 126 child.state = |
127 (1 << WebKit::WebAXStateFocusable) | | 127 (1 << blink::WebAXStateFocusable) | |
128 (1 << WebKit::WebAXStateFocused); | 128 (1 << blink::WebAXStateFocused); |
129 if (!node_is_editable_text) | 129 if (!node_is_editable_text) |
130 child.state |= (1 << WebKit::WebAXStateReadonly); | 130 child.state |= (1 << blink::WebAXStateReadonly); |
131 } | 131 } |
132 | 132 |
133 #ifndef NDEBUG | 133 #ifndef NDEBUG |
134 if (logging_) { | 134 if (logging_) { |
135 LOG(INFO) << "Accessibility update: \n" | 135 LOG(INFO) << "Accessibility update: \n" |
136 << "routing id=" << routing_id() | 136 << "routing id=" << routing_id() |
137 << " event=" | 137 << " event=" |
138 << AccessibilityEventToString(event.event_type) | 138 << AccessibilityEventToString(event.event_type) |
139 << "\n" << event.nodes[0].DebugString(true); | 139 << "\n" << event.nodes[0].DebugString(true); |
140 } | 140 } |
141 #endif | 141 #endif |
142 | 142 |
143 Send(new AccessibilityHostMsg_Events(routing_id(), events)); | 143 Send(new AccessibilityHostMsg_Events(routing_id(), events)); |
144 | 144 |
145 // Increment the id, wrap back when we get past a million. | 145 // Increment the id, wrap back when we get past a million. |
146 next_id_++; | 146 next_id_++; |
147 if (next_id_ > 1000000) | 147 if (next_id_ > 1000000) |
148 next_id_ = kInitialId; | 148 next_id_ = kInitialId; |
149 } | 149 } |
150 | 150 |
151 } // namespace content | 151 } // namespace content |
OLD | NEW |