diff options
author | sungmann.cho <sungmann.cho@navercorp.com> | 2014-10-21 07:05:23 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-10-21 14:05:41 +0000 |
commit | cbaf69539f099899555220b092ba3a501634bab3 (patch) | |
tree | 3c15de6247bac26831e0822fecdd969ac69f240e /content/renderer/accessibility | |
parent | 39be52ebbd6681c7d79ad63e2a0ab028075af0c2 (diff) | |
download | chromium_src-cbaf69539f099899555220b092ba3a501634bab3.zip chromium_src-cbaf69539f099899555220b092ba3a501634bab3.tar.gz chromium_src-cbaf69539f099899555220b092ba3a501634bab3.tar.bz2 |
Remove RendererAccessibilityFocusOnly.
After landing of https://codereview.chromium.org/600263002,
RendererAccessibilityFocusOnly class is no longer necessary.
So we can remove it and related codes.
BUG=417758
Review URL: https://codereview.chromium.org/651593002
Cr-Commit-Position: refs/heads/master@{#300482}
Diffstat (limited to 'content/renderer/accessibility')
5 files changed, 3 insertions, 386 deletions
diff --git a/content/renderer/accessibility/renderer_accessibility.h b/content/renderer/accessibility/renderer_accessibility.h index 2c016d7..426c1a7 100644 --- a/content/renderer/accessibility/renderer_accessibility.h +++ b/content/renderer/accessibility/renderer_accessibility.h @@ -19,13 +19,7 @@ class RenderFrameImpl; enum RendererAccessibilityType { // Turns on Blink accessibility and provides a full accessibility // implementation for when assistive technology is running. - RendererAccessibilityTypeComplete, - - // Does not turn on Blink accessibility. Only sends a minimal accessible tree - // to the browser whenever focus changes. This mode is currently used to - // support opening the on-screen keyboard in response to touch events on - // Windows 8 in Metro mode. - RendererAccessibilityTypeFocusOnly + RendererAccessibilityTypeComplete }; // The browser process implement native accessibility APIs, allowing @@ -46,18 +40,12 @@ enum RendererAccessibilityType { // from other processes. // // This base class just contains common code and will not do anything by itself. -// The two subclasses are: +// The subclass is: // // RendererAccessibilityComplete - turns on Blink accessibility and // provides a full accessibility implementation for when // assistive technology is running. // -// RendererAccessibilityFocusOnly - does not turn on Blink -// accessibility. Only sends a minimal accessible tree to the -// browser whenever focus changes. This mode is currently used -// to support opening the on-screen keyboard in response to -// touch events on Windows 8 in Metro mode. -// class CONTENT_EXPORT RendererAccessibility : public RenderFrameObserver { public: explicit RendererAccessibility(RenderFrameImpl* render_frame); diff --git a/content/renderer/accessibility/renderer_accessibility_browsertest.cc b/content/renderer/accessibility/renderer_accessibility_browsertest.cc index a197b9f..18e7366 100644 --- a/content/renderer/accessibility/renderer_accessibility_browsertest.cc +++ b/content/renderer/accessibility/renderer_accessibility_browsertest.cc @@ -78,150 +78,6 @@ class RendererAccessibilityTest : public RenderViewTest { }; -TEST_F(RendererAccessibilityTest, EditableTextModeFocusEvents) { - // This is not a test of true web accessibility, it's a test of - // a mode used on Windows 8 in Metro mode where an extremely simplified - // accessibility tree containing only the current focused node is - // generated. - SetMode(AccessibilityModeEditableTextOnly); - - // Set a minimum size and give focus so simulated events work. - view()->webwidget()->resize(blink::WebSize(500, 500)); - view()->webwidget()->setFocus(true); - - std::string html = - "<body>" - " <input>" - " <textarea></textarea>" - " <p contentEditable>Editable</p>" - " <div tabindex=0 role=textbox>Textbox</div>" - " <button>Button</button>" - " <a href=#>Link</a>" - "</body>"; - - // Load the test page. - LoadHTML(html.c_str()); - - // We should have sent a message to the browser with the initial focus - // on the document. - { - SCOPED_TRACE("Initial focus on document"); - AccessibilityHostMsg_EventParams event; - GetLastAccEvent(&event); - EXPECT_EQ(event.event_type, - ui::AX_EVENT_LAYOUT_COMPLETE); - EXPECT_EQ(event.id, 1); - EXPECT_EQ(event.update.nodes.size(), 2U); - EXPECT_EQ(event.update.nodes[0].id, 1); - EXPECT_EQ(event.update.nodes[0].role, - ui::AX_ROLE_ROOT_WEB_AREA); - EXPECT_EQ(event.update.nodes[0].state, - (1U << ui::AX_STATE_READ_ONLY) | - (1U << ui::AX_STATE_FOCUSABLE) | - (1U << ui::AX_STATE_FOCUSED)); - EXPECT_EQ(event.update.nodes[0].child_ids.size(), 1U); - } - - // Now focus the input element, and check everything again. - { - SCOPED_TRACE("input"); - sink_->ClearMessages(); - ExecuteJavaScript("document.querySelector('input').focus();"); - AccessibilityHostMsg_EventParams event; - GetLastAccEvent(&event); - EXPECT_EQ(event.event_type, - ui::AX_EVENT_FOCUS); - EXPECT_EQ(event.id, 3); - EXPECT_EQ(event.update.nodes[0].id, 1); - EXPECT_EQ(event.update.nodes[0].role, - ui::AX_ROLE_ROOT_WEB_AREA); - EXPECT_EQ(event.update.nodes[0].state, - (1U << ui::AX_STATE_READ_ONLY) | - (1U << ui::AX_STATE_FOCUSABLE)); - EXPECT_EQ(event.update.nodes[0].child_ids.size(), 1U); - EXPECT_EQ(event.update.nodes[1].id, 3); - EXPECT_EQ(event.update.nodes[1].role, - ui::AX_ROLE_GROUP); - EXPECT_EQ(event.update.nodes[1].state, - (1U << ui::AX_STATE_FOCUSABLE) | - (1U << ui::AX_STATE_FOCUSED)); - } - - // Check other editable text nodes. - { - SCOPED_TRACE("textarea"); - sink_->ClearMessages(); - ExecuteJavaScript("document.querySelector('textarea').focus();"); - AccessibilityHostMsg_EventParams event; - GetLastAccEvent(&event); - EXPECT_EQ(event.id, 4); - EXPECT_EQ(event.update.nodes[1].state, - (1U << ui::AX_STATE_FOCUSABLE) | - (1U << ui::AX_STATE_FOCUSED)); - } - - { - SCOPED_TRACE("contentEditable"); - sink_->ClearMessages(); - ExecuteJavaScript("document.querySelector('p').focus();"); - AccessibilityHostMsg_EventParams event; - GetLastAccEvent(&event); - EXPECT_EQ(event.id, 5); - EXPECT_EQ(event.update.nodes[1].state, - (1U << ui::AX_STATE_FOCUSABLE) | - (1U << ui::AX_STATE_FOCUSED)); - } - - { - SCOPED_TRACE("role=textarea"); - sink_->ClearMessages(); - ExecuteJavaScript("document.querySelector('div').focus();"); - AccessibilityHostMsg_EventParams event; - GetLastAccEvent(&event); - EXPECT_EQ(event.id, 6); - EXPECT_EQ(event.update.nodes[1].state, - (1U << ui::AX_STATE_FOCUSABLE) | - (1U << ui::AX_STATE_FOCUSED)); - } - - // Try focusing things that aren't editable text. - { - SCOPED_TRACE("button"); - sink_->ClearMessages(); - ExecuteJavaScript("document.querySelector('button').focus();"); - AccessibilityHostMsg_EventParams event; - GetLastAccEvent(&event); - EXPECT_EQ(event.id, 7); - EXPECT_EQ(event.update.nodes[1].state, - (1U << ui::AX_STATE_FOCUSABLE) | - (1U << ui::AX_STATE_FOCUSED) | - (1U << ui::AX_STATE_READ_ONLY)); - } - - { - SCOPED_TRACE("link"); - sink_->ClearMessages(); - ExecuteJavaScript("document.querySelector('a').focus();"); - AccessibilityHostMsg_EventParams event; - GetLastAccEvent(&event); - EXPECT_EQ(event.id, 8); - EXPECT_EQ(event.update.nodes[1].state, - (1U << ui::AX_STATE_FOCUSABLE) | - (1U << ui::AX_STATE_FOCUSED) | - (1U << ui::AX_STATE_READ_ONLY)); - } - - // Clear focus. - { - SCOPED_TRACE("Back to document."); - sink_->ClearMessages(); - ExecuteJavaScript("document.activeElement.blur()"); - AccessibilityHostMsg_EventParams event; - GetLastAccEvent(&event); - EXPECT_EQ(event.id, 1); - } -} - TEST_F(RendererAccessibilityTest, SendFullAccessibilityTreeOnReload) { // The job of RendererAccessibilityComplete is to serialize the // accessibility tree built by WebKit and send it to the browser. diff --git a/content/renderer/accessibility/renderer_accessibility_complete.h b/content/renderer/accessibility/renderer_accessibility_complete.h index 095b062..96d1c6f 100644 --- a/content/renderer/accessibility/renderer_accessibility_complete.h +++ b/content/renderer/accessibility/renderer_accessibility_complete.h @@ -27,8 +27,7 @@ namespace content { class RenderViewImpl; // This is the subclass of RendererAccessibility that implements -// complete accessibility support for assistive technology (as opposed to -// partial support - see RendererAccessibilityFocusOnly). +// complete accessibility support for assistive technology. // // This version turns on Blink's accessibility code and sends // a serialized representation of that tree whenever it changes. It also diff --git a/content/renderer/accessibility/renderer_accessibility_focus_only.cc b/content/renderer/accessibility/renderer_accessibility_focus_only.cc deleted file mode 100644 index 4391412..0000000 --- a/content/renderer/accessibility/renderer_accessibility_focus_only.cc +++ /dev/null @@ -1,151 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "content/renderer/accessibility/renderer_accessibility_focus_only.h" - -#include "content/renderer/render_frame_impl.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/WebLocalFrame.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::WebNode; -using blink::WebView; - -namespace { -// The root node will always have id 1. Let each child node have a new -// id starting with 2. -const int kInitialId = 2; -} - -namespace content { - -RendererAccessibilityFocusOnly::RendererAccessibilityFocusOnly( - RenderFrameImpl* render_frame) - : RendererAccessibility(render_frame), - next_id_(kInitialId) { -} - -RendererAccessibilityFocusOnly::~RendererAccessibilityFocusOnly() { -} - -void RendererAccessibilityFocusOnly::HandleWebAccessibilityEvent( - const blink::WebAXObject& obj, blink::WebAXEvent event) { - // Do nothing. -} - -RendererAccessibilityType RendererAccessibilityFocusOnly::GetType() { - return RendererAccessibilityTypeFocusOnly; -} - -void RendererAccessibilityFocusOnly::FocusedNodeChanged(const WebNode& node) { - // Send the new accessible tree and post a native focus event. - HandleFocusedNodeChanged(node, true); -} - -void RendererAccessibilityFocusOnly::DidFinishLoad() { - // Send an accessible tree to the browser, but do not post a native - // focus event. This is important so that if focus is initially in an - // editable text field, Windows will know to pop up the keyboard if the - // user touches it and focus doesn't change. - const WebDocument& document = GetMainDocument(); - 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; - // Check HasIMETextFocus first, because it will correctly handle - // focus in a text box inside a ppapi plug-in. Otherwise fall back on - // checking the focused node in Blink. - if (render_frame_->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_frame_->render_view()->IsEditableNode(node); - } - - std::vector<AccessibilityHostMsg_EventParams> events; - events.push_back(AccessibilityHostMsg_EventParams()); - AccessibilityHostMsg_EventParams& event = events[0]; - - // If we want to update the browser's accessibility tree but not send a - // native focus changed event, we can send a LayoutComplete - // event, which doesn't post a native event on Windows. - event.event_type = - send_focus_event ? ui::AX_EVENT_FOCUS : ui::AX_EVENT_LAYOUT_COMPLETE; - - // Set the id that the event applies to: the root node if nothing - // has focus, otherwise the focused node. - 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]; - - // Always include the root of the tree, the document. It always has id 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_frame_->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_frame_->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 - /** - if (logging_) { - VLOG(0) << "Accessibility update: \n" - << "routing id=" << routing_id() - << " event=" - << AccessibilityEventToString(event.event_type) - << "\n" << event.nodes[0].DebugString(true); - } - **/ -#endif - - Send(new AccessibilityHostMsg_Events(routing_id(), events)); - - // Increment the id, wrap back when we get past a million. - next_id_++; - if (next_id_ > 1000000) - next_id_ = kInitialId; -} - -} // namespace content diff --git a/content/renderer/accessibility/renderer_accessibility_focus_only.h b/content/renderer/accessibility/renderer_accessibility_focus_only.h deleted file mode 100644 index 19a1520..0000000 --- a/content/renderer/accessibility/renderer_accessibility_focus_only.h +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CONTENT_RENDERER_ACCESSIBILITY_RENDERER_ACCESSIBILITY_FOCUS_ONLY_H_ -#define CONTENT_RENDERER_ACCESSIBILITY_RENDERER_ACCESSIBILITY_FOCUS_ONLY_H_ - -#include "content/renderer/accessibility/renderer_accessibility.h" - -namespace content { - -// This is an accessibility implementation that only handles whatever -// node has focus, ignoring everything else. It's here because on Windows 8, -// we need to use accessibility APIs to tell the operating system when a -// touch should pop up the on-screen keyboard, but it's not worth the -// performance overhead to enable full accessibility support. -// -// Here's how the on-screen keyboard works in Windows 8 "Metro-style" apps: -// -// 1. The user touches a control. -// 2. If the application determines focus moves to an editable text control, -// it sends a native focus event, pointing to a native accessibility object -// with information about the control that was just focused. -// 3. If the operating system sees that a focus event closely follows a -// touch event, AND the bounding rectangle of the newly-focused control -// contains the touch point, AND the focused object is a text control, -// then Windows pops up the on-screen keyboard. In all other cases, -// changing focus closes the on-screen keyboard. -// -// Alternatively: -// 1. The user touches a text control that already has focus. -// 2. The operating system uses accessibility APIs to query for the -// currently focused object. If the touch falls within the bounds of -// the focused object, the on-screen keyboard opens. -// -// In order to implement the accessibility APIs with minimal overhead, this -// class builds a "fake" accessibility tree consisting of only a single root -// node and optionally a single child node, representing the current focused -// element in the page (if any). Every time focus changes, this fake tree is -// sent from the renderer to the browser, along with a focus event - either -// on the child, or on the root of the tree if nothing is focused. -// -// Sometimes, touching an element other than a text box will result in a -// text box getting focus. We want the on-screen keyboard to pop up in those -// cases, so we "cheat" more and always send the dimensions of the whole -// window as the bounds of the child object. That way, a touch that leads -// to a text box getting focus will always open the on-screen keyboard, -// regardless of the relation between the touch location and the text box -// bounds. -class RendererAccessibilityFocusOnly : public RendererAccessibility { - public: - explicit RendererAccessibilityFocusOnly(RenderFrameImpl* render_frame); - ~RendererAccessibilityFocusOnly() override; - - // RendererAccessibility implementation. - void HandleWebAccessibilityEvent(const blink::WebAXObject& obj, - blink::WebAXEvent event) override; - RendererAccessibilityType GetType() override; - void FocusedNodeChanged(const blink::WebNode& node) override; - - // RenderFrameObserver implementation. - void DidFinishLoad() override; - - private: - void HandleFocusedNodeChanged(const blink::WebNode& node, - bool send_focus_event); - - int next_id_; - - DISALLOW_COPY_AND_ASSIGN(RendererAccessibilityFocusOnly); -}; - -} // namespace content - -#endif // CONTENT_RENDERER_ACCESSIBILITY_RENDERER_ACCESSIBILITY_FOCUS_ONLY_H_ |