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