blob: 62cffb5c1fa78b1852a4d7265da4c64b974630db [file] [log] [blame]
[email protected]c5c2a672010-10-01 23:28:041// Copyright (c) 2010 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 CHROME_BROWSER_ACCESSIBILITY_BROWSER_ACCESSIBILITY_H_
6#define CHROME_BROWSER_ACCESSIBILITY_BROWSER_ACCESSIBILITY_H_
7#pragma once
8
[email protected]f27e81c2010-10-07 05:20:239#include <map>
10#include <utility>
11#include <vector>
12
[email protected]c5c2a672010-10-01 23:28:0413#include "base/basictypes.h"
[email protected]f27e81c2010-10-07 05:20:2314#include "build/build_config.h"
15#include "webkit/glue/webaccessibility.h"
16
17class BrowserAccessibilityManager;
[email protected]1dbadbd2010-10-13 18:50:1018#if defined(OS_MACOSX)
19class BrowserAccessibilityMac;
20#elif defined(OS_WIN)
[email protected]f27e81c2010-10-07 05:20:2321class BrowserAccessibilityWin;
22#endif
23
24using webkit_glue::WebAccessibility;
[email protected]c5c2a672010-10-01 23:28:0425
26////////////////////////////////////////////////////////////////////////////////
27//
28// BrowserAccessibility
29//
30// Class implementing the cross platform interface for the Browser-Renderer
31// communication of accessibility information, providing accessibility
32// to be used by screen readers and other assistive technology (AT).
33//
34// An implementation for each platform handles platform specific accessibility
35// APIs.
36//
37////////////////////////////////////////////////////////////////////////////////
38class BrowserAccessibility {
39 public:
[email protected]f27e81c2010-10-07 05:20:2340 // Creates a platform specific BrowserAccessibility. Ownership passes to the
[email protected]c5c2a672010-10-01 23:28:0441 // caller.
[email protected]f27e81c2010-10-07 05:20:2342 static BrowserAccessibility* Create();
43
[email protected]c5c2a672010-10-01 23:28:0444 virtual ~BrowserAccessibility();
45
[email protected]f27e81c2010-10-07 05:20:2346 // Perform platform specific initialization. This can be called multiple times
47 // during the lifetime of this instance after the members of this base object
48 // have been reset with new values from the renderer process.
49 virtual void Initialize() = 0;
50
51 // Remove references to all children and delete them if possible.
52 virtual void ReleaseTree();
53
54 // Release a reference to this node. This may be a no-op on platforms other
55 // than windows.
56 virtual void ReleaseReference() = 0;
57
58 // Initialize this object
59 void Initialize(BrowserAccessibilityManager* manager,
60 BrowserAccessibility* parent,
61 int32 child_id,
62 int32 index_in_parent,
63 const WebAccessibility& src);
64
65 // Add a child of this object.
66 void AddChild(BrowserAccessibility* child);
67
68 // Return true if this object is equal to or a descendant of |ancestor|.
69 bool IsDescendantOf(BrowserAccessibility* ancestor);
70
71 // Returns the parent of this object, or NULL if it's the root.
72 BrowserAccessibility* GetParent();
73
74 // Returns the number of children of this object.
75 uint32 GetChildCount();
76
77 // Return a pointer to the child with the given index.
78 BrowserAccessibility* GetChild(uint32 child_index);
79
80 // Return the previous sibling of this object, or NULL if it's the first
81 // child of its parent.
82 BrowserAccessibility* GetPreviousSibling();
83
84 // Return the next sibling of this object, or NULL if it's the last child
85 // of its parent.
86 BrowserAccessibility* GetNextSibling();
87
88 // Replace a child object. Used when updating the accessibility tree.
89 void ReplaceChild(
90 const BrowserAccessibility* old_acc,
91 BrowserAccessibility* new_acc);
92
93 // Accessors
94 int32 child_id() const { return child_id_; }
95 const std::vector<BrowserAccessibility*>& children() const {
96 return children_;
97 }
98 int32 renderer_id() const { return renderer_id_; }
99 int32 index_in_parent() const { return index_in_parent_; }
100 WebKit::WebRect location() const { return location_; }
101
[email protected]1dbadbd2010-10-13 18:50:10102#if defined(OS_MACOSX)
103 BrowserAccessibilityMac* toBrowserAccessibilityMac();
104#elif defined(OS_WIN)
[email protected]f27e81c2010-10-07 05:20:23105 BrowserAccessibilityWin* toBrowserAccessibilityWin();
106#endif
107
[email protected]c5c2a672010-10-01 23:28:04108 protected:
109 BrowserAccessibility();
110
[email protected]f27e81c2010-10-07 05:20:23111 // The manager of this tree of accessibility objects; needed for
112 // global operations like focus tracking.
113 BrowserAccessibilityManager* manager_;
114
115 // The parent of this object, may be NULL if we're the root object.
116 BrowserAccessibility* parent_;
117
118 // The ID of this object; globally unique within the browser process.
119 int32 child_id_;
120
121 // The index of this within its parent object.
122 int32 index_in_parent_;
123
124 // The ID of this object in the renderer process.
125 int32 renderer_id_;
126
127 // The children of this object.
128 std::vector<BrowserAccessibility*> children_;
129
130 // Accessibility metadata from the renderer
131 string16 name_;
132 string16 value_;
133 std::map<int32, string16> attributes_;
134 std::vector<std::pair<string16, string16> > html_attributes_;
135 int32 role_;
136 int32 state_;
137 string16 role_name_;
138 WebKit::WebRect location_;
139
[email protected]c5c2a672010-10-01 23:28:04140 private:
141 DISALLOW_COPY_AND_ASSIGN(BrowserAccessibility);
142};
143
144#endif // CHROME_BROWSER_ACCESSIBILITY_BROWSER_ACCESSIBILITY_H_