| 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" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 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::HandleWebAccessibilityNotification( | 38 void RendererAccessibilityFocusOnly::HandleWebAccessibilityEvent( |
| 39 const WebKit::WebAccessibilityObject& obj, | 39 const WebKit::WebAXObject& obj, WebKit::WebAXEvent event) { |
| 40 WebKit::WebAccessibilityNotification notification) { | |
| 41 // Do nothing. | 40 // Do nothing. |
| 42 } | 41 } |
| 43 | 42 |
| 44 void RendererAccessibilityFocusOnly::FocusedNodeChanged(const WebNode& node) { | 43 void RendererAccessibilityFocusOnly::FocusedNodeChanged(const WebNode& node) { |
| 45 // Send the new accessible tree and post a native focus event. | 44 // Send the new accessible tree and post a native focus event. |
| 46 HandleFocusedNodeChanged(node, true); | 45 HandleFocusedNodeChanged(node, true); |
| 47 } | 46 } |
| 48 | 47 |
| 49 void RendererAccessibilityFocusOnly::DidFinishLoad(WebKit::WebFrame* frame) { | 48 void RendererAccessibilityFocusOnly::DidFinishLoad(WebKit::WebFrame* frame) { |
| 50 WebView* view = render_view()->GetWebView(); | 49 WebView* view = render_view()->GetWebView(); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 73 // checking the focused node in WebKit. | 72 // checking the focused node in WebKit. |
| 74 if (render_view_->HasIMETextFocus()) { | 73 if (render_view_->HasIMETextFocus()) { |
| 75 node_has_focus = true; | 74 node_has_focus = true; |
| 76 node_is_editable_text = true; | 75 node_is_editable_text = true; |
| 77 } else { | 76 } else { |
| 78 node_has_focus = !node.isNull(); | 77 node_has_focus = !node.isNull(); |
| 79 node_is_editable_text = | 78 node_is_editable_text = |
| 80 node_has_focus && render_view_->IsEditableNode(node); | 79 node_has_focus && render_view_->IsEditableNode(node); |
| 81 } | 80 } |
| 82 | 81 |
| 83 std::vector<AccessibilityHostMsg_NotificationParams> notifications; | 82 std::vector<AccessibilityHostMsg_EventParams> events; |
| 84 notifications.push_back(AccessibilityHostMsg_NotificationParams()); | 83 events.push_back(AccessibilityHostMsg_EventParams()); |
| 85 AccessibilityHostMsg_NotificationParams& notification = notifications[0]; | 84 AccessibilityHostMsg_EventParams& event = events[0]; |
| 86 | 85 |
| 87 // 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 |
| 88 // native focus changed notification, we can send a LayoutComplete | 87 // native focus changed event, we can send a LayoutComplete |
| 89 // notification, which doesn't post a native event on Windows. | 88 // event, which doesn't post a native event on Windows. |
| 90 notification.notification_type = | 89 event.event_type = |
| 91 send_focus_event ? | 90 send_focus_event ? |
| 92 AccessibilityNotificationFocusChanged : | 91 WebKit::WebAXEventFocus : |
| 93 AccessibilityNotificationLayoutComplete; | 92 WebKit::WebAXEventLayoutComplete; |
| 94 | 93 |
| 95 // Set the id that the notification applies to: the root node if nothing | 94 // Set the id that the event applies to: the root node if nothing |
| 96 // has focus, otherwise the focused node. | 95 // has focus, otherwise the focused node. |
| 97 notification.id = node_has_focus ? next_id_ : 1; | 96 event.id = node_has_focus ? next_id_ : 1; |
| 98 | 97 |
| 99 notification.nodes.resize(2); | 98 event.nodes.resize(2); |
| 100 AccessibilityNodeData& root = notification.nodes[0]; | 99 AccessibilityNodeData& root = event.nodes[0]; |
| 101 AccessibilityNodeData& child = notification.nodes[1]; | 100 AccessibilityNodeData& child = event.nodes[1]; |
| 102 | 101 |
| 103 // 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. |
| 104 root.id = 1; | 103 root.id = 1; |
| 105 root.role = AccessibilityNodeData::ROLE_ROOT_WEB_AREA; | 104 root.role = WebKit::WebAXRoleRootWebArea; |
| 106 root.state = | 105 root.state = |
| 107 (1 << AccessibilityNodeData::STATE_READONLY) | | 106 (1 << WebKit::WebAXStateReadonly) | |
| 108 (1 << AccessibilityNodeData::STATE_FOCUSABLE); | 107 (1 << WebKit::WebAXStateFocusable); |
| 109 if (!node_has_focus) | 108 if (!node_has_focus) |
| 110 root.state |= (1 << AccessibilityNodeData::STATE_FOCUSED); | 109 root.state |= (1 << WebKit::WebAXStateFocused); |
| 111 root.location = gfx::Rect(render_view_->size()); | 110 root.location = gfx::Rect(render_view_->size()); |
| 112 root.child_ids.push_back(next_id_); | 111 root.child_ids.push_back(next_id_); |
| 113 | 112 |
| 114 child.id = next_id_; | 113 child.id = next_id_; |
| 115 child.role = AccessibilityNodeData::ROLE_GROUP; | 114 child.role = WebKit::WebAXRoleGroup; |
| 116 | 115 |
| 117 if (!node.isNull() && node.isElementNode()) { | 116 if (!node.isNull() && node.isElementNode()) { |
| 118 child.location = gfx::Rect( | 117 child.location = gfx::Rect( |
| 119 const_cast<WebNode&>(node).to<WebElement>().boundsInViewportSpace()); | 118 const_cast<WebNode&>(node).to<WebElement>().boundsInViewportSpace()); |
| 120 } else if (render_view_->HasIMETextFocus()) { | 119 } else if (render_view_->HasIMETextFocus()) { |
| 121 child.location = root.location; | 120 child.location = root.location; |
| 122 } else { | 121 } else { |
| 123 child.location = gfx::Rect(); | 122 child.location = gfx::Rect(); |
| 124 } | 123 } |
| 125 | 124 |
| 126 if (node_has_focus) { | 125 if (node_has_focus) { |
| 127 child.state = | 126 child.state = |
| 128 (1 << AccessibilityNodeData::STATE_FOCUSABLE) | | 127 (1 << WebKit::WebAXStateFocusable) | |
| 129 (1 << AccessibilityNodeData::STATE_FOCUSED); | 128 (1 << WebKit::WebAXStateFocused); |
| 130 if (!node_is_editable_text) | 129 if (!node_is_editable_text) |
| 131 child.state |= (1 << AccessibilityNodeData::STATE_READONLY); | 130 child.state |= (1 << WebKit::WebAXStateReadonly); |
| 132 } | 131 } |
| 133 | 132 |
| 134 #ifndef NDEBUG | 133 #ifndef NDEBUG |
| 135 if (logging_) { | 134 if (logging_) { |
| 136 LOG(INFO) << "Accessibility update: \n" | 135 LOG(INFO) << "Accessibility update: \n" |
| 137 << "routing id=" << routing_id() | 136 << "routing id=" << routing_id() |
| 138 << " notification=" | 137 << " event=" |
| 139 << AccessibilityNotificationToString(notification.notification_type) | 138 << AccessibilityEventToString(event.event_type) |
| 140 << "\n" << notification.nodes[0].DebugString(true); | 139 << "\n" << event.nodes[0].DebugString(true); |
| 141 } | 140 } |
| 142 #endif | 141 #endif |
| 143 | 142 |
| 144 Send(new AccessibilityHostMsg_Notifications(routing_id(), notifications)); | 143 Send(new AccessibilityHostMsg_Events(routing_id(), events)); |
| 145 | 144 |
| 146 // Increment the id, wrap back when we get past a million. | 145 // Increment the id, wrap back when we get past a million. |
| 147 next_id_++; | 146 next_id_++; |
| 148 if (next_id_ > 1000000) | 147 if (next_id_ > 1000000) |
| 149 next_id_ = kInitialId; | 148 next_id_ = kInitialId; |
| 150 } | 149 } |
| 151 | 150 |
| 152 } // namespace content | 151 } // namespace content |
| OLD | NEW |