[content shell] implement testRunner.overridePreference
[chromium-blink-merge.git] / content / renderer / renderer_accessibility_focus_only.h
blob6b2eb9f4454b652a98a93dccb40518d3e3fe672c
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_RENDERER_ACCESSIBILITY_FOCUS_ONLY_H_
6 #define CONTENT_RENDERER_RENDERER_ACCESSIBILITY_FOCUS_ONLY_H_
8 #include "content/renderer/renderer_accessibility.h"
10 namespace content {
12 // This is an accsessibility 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.
30 // Alternatively:
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
49 // bounds.
50 class RendererAccessibilityFocusOnly : public RendererAccessibility {
51 public:
52 explicit RendererAccessibilityFocusOnly(RenderViewImpl* render_view);
53 virtual ~RendererAccessibilityFocusOnly();
55 // RendererAccessibility implementation.
56 virtual void HandleWebAccessibilityNotification(
57 const WebKit::WebAccessibilityObject& obj,
58 WebKit::WebAccessibilityNotification notification) OVERRIDE;
60 // RenderView::Observer implementation.
61 virtual void FocusedNodeChanged(const WebKit::WebNode& node) OVERRIDE;
62 virtual void DidFinishLoad(WebKit::WebFrame* frame) OVERRIDE;
64 private:
65 void HandleFocusedNodeChanged(const WebKit::WebNode& node,
66 bool send_focus_event);
68 int next_id_;
70 DISALLOW_COPY_AND_ASSIGN(RendererAccessibilityFocusOnly);
73 } // namespace content
75 #endif // CONTENT_RENDERER_RENDERER_ACCESSIBILITY_FOCUS_ONLY_H_