Home | History | Annotate | Download | only in accessibility
      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.
      4 
      5 #ifndef CONTENT_RENDERER_ACCESSIBILITY_RENDERER_ACCESSIBILITY_FOCUS_ONLY_H_
      6 #define CONTENT_RENDERER_ACCESSIBILITY_RENDERER_ACCESSIBILITY_FOCUS_ONLY_H_
      7 
      8 #include "content/renderer/accessibility/renderer_accessibility.h"
      9 
     10 namespace content {
     11 
     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.
     17 //
     18 // Here's how the on-screen keyboard works in Windows 8 "Metro-style" apps:
     19 //
     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.
     29 //
     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.
     35 //
     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.
     42 //
     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();
     54 
     55   // RendererAccessibility implementation.
     56   virtual void HandleWebAccessibilityEvent(
     57       const blink::WebAXObject& obj, blink::WebAXEvent event) OVERRIDE;
     58   virtual RendererAccessibilityType GetType() OVERRIDE;
     59 
     60   // RenderView::Observer implementation.
     61   virtual void FocusedNodeChanged(const blink::WebNode& node) OVERRIDE;
     62   virtual void DidFinishLoad(blink::WebLocalFrame* frame) OVERRIDE;
     63 
     64  private:
     65   void HandleFocusedNodeChanged(const blink::WebNode& node,
     66                                 bool send_focus_event);
     67 
     68   int next_id_;
     69 
     70   DISALLOW_COPY_AND_ASSIGN(RendererAccessibilityFocusOnly);
     71 };
     72 
     73 }  // namespace content
     74 
     75 #endif  // CONTENT_RENDERER_ACCESSIBILITY_RENDERER_ACCESSIBILITY_FOCUS_ONLY_H_
     76