This source file includes following definitions.
- next_id_
- HandleWebAccessibilityEvent
- GetType
- FocusedNodeChanged
- DidFinishLoad
- HandleFocusedNodeChanged
#include "content/renderer/accessibility/renderer_accessibility_focus_only.h"
#include "content/renderer/render_view_impl.h"
#include "third_party/WebKit/public/web/WebDocument.h"
#include "third_party/WebKit/public/web/WebElement.h"
#include "third_party/WebKit/public/web/WebFrame.h"
#include "third_party/WebKit/public/web/WebNode.h"
#include "third_party/WebKit/public/web/WebView.h"
#include "ui/accessibility/ax_node_data.h"
using blink::WebDocument;
using blink::WebElement;
using blink::WebFrame;
using blink::WebNode;
using blink::WebView;
namespace {
const int kInitialId = 2;
}
namespace content {
RendererAccessibilityFocusOnly::RendererAccessibilityFocusOnly(
RenderViewImpl* render_view)
: RendererAccessibility(render_view),
next_id_(kInitialId) {
}
RendererAccessibilityFocusOnly::~RendererAccessibilityFocusOnly() {
}
void RendererAccessibilityFocusOnly::HandleWebAccessibilityEvent(
const blink::WebAXObject& obj, blink::WebAXEvent event) {
}
RendererAccessibilityType RendererAccessibilityFocusOnly::GetType() {
return RendererAccessibilityTypeFocusOnly;
}
void RendererAccessibilityFocusOnly::FocusedNodeChanged(const WebNode& node) {
HandleFocusedNodeChanged(node, true);
}
void RendererAccessibilityFocusOnly::DidFinishLoad(
blink::WebLocalFrame* frame) {
WebView* view = render_view()->GetWebView();
if (view->focusedFrame() != frame)
return;
WebDocument document = frame->document();
HandleFocusedNodeChanged(document.focusedElement(), false);
}
void RendererAccessibilityFocusOnly::HandleFocusedNodeChanged(
const WebNode& node,
bool send_focus_event) {
const WebDocument& document = GetMainDocument();
if (document.isNull())
return;
bool node_has_focus;
bool node_is_editable_text;
if (render_view_->HasIMETextFocus()) {
node_has_focus = true;
node_is_editable_text = true;
} else {
node_has_focus = !node.isNull();
node_is_editable_text =
node_has_focus && render_view_->IsEditableNode(node);
}
std::vector<AccessibilityHostMsg_EventParams> events;
events.push_back(AccessibilityHostMsg_EventParams());
AccessibilityHostMsg_EventParams& event = events[0];
event.event_type =
send_focus_event ? ui::AX_EVENT_FOCUS : ui::AX_EVENT_LAYOUT_COMPLETE;
event.id = node_has_focus ? next_id_ : 1;
event.update.nodes.resize(2);
ui::AXNodeData& root = event.update.nodes[0];
ui::AXNodeData& child = event.update.nodes[1];
root.id = 1;
root.role = ui::AX_ROLE_ROOT_WEB_AREA;
root.state =
(1 << ui::AX_STATE_READ_ONLY) |
(1 << ui::AX_STATE_FOCUSABLE);
if (!node_has_focus)
root.state |= (1 << ui::AX_STATE_FOCUSED);
root.location = gfx::Rect(render_view_->size());
root.child_ids.push_back(next_id_);
child.id = next_id_;
child.role = ui::AX_ROLE_GROUP;
if (!node.isNull() && node.isElementNode()) {
child.location = gfx::Rect(
const_cast<WebNode&>(node).to<WebElement>().boundsInViewportSpace());
} else if (render_view_->HasIMETextFocus()) {
child.location = root.location;
} else {
child.location = gfx::Rect();
}
if (node_has_focus) {
child.state =
(1 << ui::AX_STATE_FOCUSABLE) |
(1 << ui::AX_STATE_FOCUSED);
if (!node_is_editable_text)
child.state |= (1 << ui::AX_STATE_READ_ONLY);
}
#ifndef NDEBUG
#endif
Send(new AccessibilityHostMsg_Events(routing_id(), events));
next_id_++;
if (next_id_ > 1000000)
next_id_ = kInitialId;
}
}