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
3 // found in the LICENSE file.
5 #ifndef CONTENT_RENDERER_ACCESSIBILITY_RENDERER_ACCESSIBILITY_FOCUS_ONLY_H_
6 #define CONTENT_RENDERER_ACCESSIBILITY_RENDERER_ACCESSIBILITY_FOCUS_ONLY_H_
8 #include "content/renderer/accessibility/renderer_accessibility.h"
12 // This is an accessibility implementation that only handles whatever
13 // node has focus, ignoring everything else. It's here because on Windows 8,
14 // we need to use accessibility APIs to tell the operating system when a
15 // touch should pop up the on-screen keyboard, but it's not worth the
16 // performance overhead to enable full accessibility support.
18 // Here's how the on-screen keyboard works in Windows 8 "Metro-style" apps:
20 // 1. The user touches a control.
21 // 2. If the application determines focus moves to an editable text control,
22 // it sends a native focus event, pointing to a native accessibility object
23 // with information about the control that was just focused.
24 // 3. If the operating system sees that a focus event closely follows a
25 // touch event, AND the bounding rectangle of the newly-focused control
26 // contains the touch point, AND the focused object is a text control,
27 // then Windows pops up the on-screen keyboard. In all other cases,
28 // changing focus closes the on-screen keyboard.
31 // 1. The user touches a text control that already has focus.
32 // 2. The operating system uses accessibility APIs to query for the
33 // currently focused object. If the touch falls within the bounds of
34 // the focused object, the on-screen keyboard opens.
36 // In order to implement the accessibility APIs with minimal overhead, this
37 // class builds a "fake" accessibility tree consisting of only a single root
38 // node and optionally a single child node, representing the current focused
39 // element in the page (if any). Every time focus changes, this fake tree is
40 // sent from the renderer to the browser, along with a focus event - either
41 // on the child, or on the root of the tree if nothing is focused.
43 // Sometimes, touching an element other than a text box will result in a
44 // text box getting focus. We want the on-screen keyboard to pop up in those
45 // cases, so we "cheat" more and always send the dimensions of the whole
46 // window as the bounds of the child object. That way, a touch that leads
47 // to a text box getting focus will always open the on-screen keyboard,
48 // regardless of the relation between the touch location and the text box
50 class RendererAccessibilityFocusOnly
: public RendererAccessibility
{
52 explicit RendererAccessibilityFocusOnly(RenderFrameImpl
* render_frame
);
53 virtual ~RendererAccessibilityFocusOnly();
55 // RendererAccessibility implementation.
56 virtual void HandleWebAccessibilityEvent(
57 const blink::WebAXObject
& obj
, blink::WebAXEvent event
) override
;
58 virtual RendererAccessibilityType
GetType() override
;
59 virtual void FocusedNodeChanged(const blink::WebNode
& node
) override
;
61 // RenderFrameObserver implementation.
62 virtual void DidFinishLoad() override
;
65 void HandleFocusedNodeChanged(const blink::WebNode
& node
,
66 bool send_focus_event
);
70 DISALLOW_COPY_AND_ASSIGN(RendererAccessibilityFocusOnly
);
73 } // namespace content
75 #endif // CONTENT_RENDERER_ACCESSIBILITY_RENDERER_ACCESSIBILITY_FOCUS_ONLY_H_