1 // Copyright 2014 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 COMPONENTS_TEST_RUNNER_WEB_AX_OBJECT_PROXY_H_
6 #define COMPONENTS_TEST_RUNNER_WEB_AX_OBJECT_PROXY_H_
10 #include "base/basictypes.h"
11 #include "gin/object_template_builder.h"
12 #include "gin/wrappable.h"
13 #include "third_party/WebKit/public/web/WebAXObject.h"
14 #include "v8/include/v8-util.h"
15 #include "v8/include/v8.h"
21 namespace test_runner
{
23 class WebAXObjectProxy
: public gin::Wrappable
<WebAXObjectProxy
> {
27 virtual ~Factory() { }
28 virtual v8::Local
<v8::Object
> GetOrCreate(
29 const blink::WebAXObject
& object
) = 0;
32 static gin::WrapperInfo kWrapperInfo
;
34 WebAXObjectProxy(const blink::WebAXObject
& object
, Factory
* factory
);
35 ~WebAXObjectProxy() override
;
38 gin::ObjectTemplateBuilder
GetObjectTemplateBuilder(
39 v8::Isolate
* isolate
) override
;
41 virtual v8::Local
<v8::Object
> GetChildAtIndex(unsigned index
);
42 virtual bool IsRoot() const;
43 bool IsEqualToObject(const blink::WebAXObject
& object
);
45 void NotificationReceived(blink::WebFrame
* frame
,
46 const std::string
& notification_name
);
50 const blink::WebAXObject
& accessibility_object() const {
51 return accessibility_object_
;
54 Factory
* factory() const { return factory_
; }
57 friend class WebAXObjectProxyBindings
;
61 std::string
StringValue();
62 std::string
Language();
70 std::string
ValueDescription();
73 // The following selection functions return global information about the
74 // current selection and can be called on any object in the tree.
75 v8::Local
<v8::Value
> SelectionAnchorObject();
76 int SelectionAnchorOffset();
77 v8::Local
<v8::Value
> SelectionFocusObject();
78 int SelectionFocusOffset();
80 // The following selection functions return text offsets calculated starting
81 // at this object. They only report on a selection that is placed on the
82 // current object or on any of its descendants.
83 // For example, they can be used to retrieve the selection in an input or
87 int SelectionStartLineNumber();
88 int SelectionEndLineNumber();
93 bool IsRichlyEditable();
98 bool IsMultiSelectable();
99 bool IsSelectedOptionActive();
108 unsigned int BackgroundColor();
109 unsigned int Color();
110 // For input elements of type color.
111 unsigned int ColorValue();
113 std::string
Orientation();
119 int32_t RowHeadersCount();
120 int32_t ColumnCount();
121 int32_t ColumnHeadersCount();
123 bool IsButtonStateMixed();
126 v8::Local
<v8::Object
> AriaControlsElementAtIndex(unsigned index
);
127 v8::Local
<v8::Object
> AriaFlowToElementAtIndex(unsigned index
);
128 v8::Local
<v8::Object
> AriaOwnsElementAtIndex(unsigned index
);
129 std::string
AllAttributes();
130 std::string
AttributesOfChildren();
131 int LineForIndex(int index
);
132 std::string
BoundsForRange(int start
, int end
);
133 v8::Local
<v8::Object
> ChildAtIndex(int index
);
134 v8::Local
<v8::Object
> ElementAtPoint(int x
, int y
);
135 v8::Local
<v8::Object
> TableHeader();
136 v8::Local
<v8::Object
> RowHeaderAtIndex(unsigned index
);
137 v8::Local
<v8::Object
> ColumnHeaderAtIndex(unsigned index
);
138 std::string
RowIndexRange();
139 std::string
ColumnIndexRange();
140 v8::Local
<v8::Object
> CellForColumnAndRow(int column
, int row
);
141 void SetSelectedTextRange(int selection_start
, int length
);
142 void SetSelection(v8::Local
<v8::Value
> anchor_object
, int anchor_offset
,
143 v8::Local
<v8::Value
> focus_object
, int focus_offset
);
144 bool IsAttributeSettable(const std::string
& attribute
);
145 bool IsPressActionSupported();
146 bool IsIncrementActionSupported();
147 bool IsDecrementActionSupported();
148 v8::Local
<v8::Object
> ParentElement();
153 bool SetValue(const std::string
& value
);
154 bool IsEqual(v8::Local
<v8::Object
> proxy
);
155 void SetNotificationListener(v8::Local
<v8::Function
> callback
);
156 void UnsetNotificationListener();
158 void ScrollToMakeVisible();
159 void ScrollToMakeVisibleWithSubFocus(int x
, int y
, int width
, int height
);
160 void ScrollToGlobalPoint(int x
, int y
);
161 int WordStart(int character_index
);
162 int WordEnd(int character_index
);
163 v8::Local
<v8::Object
> NextOnLine();
164 v8::Local
<v8::Object
> PreviousOnLine();
166 // DEPRECATED accessible name and description accessors
167 std::string
DeprecatedTitle();
168 std::string
DeprecatedDescription();
169 std::string
DeprecatedHelpText();
170 v8::Local
<v8::Object
> DeprecatedTitleUIElement();
172 // NEW accessible name and description accessors
174 std::string
NameFrom();
175 int NameElementCount();
176 v8::Local
<v8::Object
> NameElementAtIndex(unsigned index
);
178 blink::WebAXObject accessibility_object_
;
181 v8::Persistent
<v8::Function
> notification_callback_
;
183 DISALLOW_COPY_AND_ASSIGN(WebAXObjectProxy
);
186 class RootWebAXObjectProxy
: public WebAXObjectProxy
{
188 RootWebAXObjectProxy(const blink::WebAXObject
&, Factory
*);
190 v8::Local
<v8::Object
> GetChildAtIndex(unsigned index
) override
;
191 bool IsRoot() const override
;
195 // Provides simple lifetime management of the WebAXObjectProxy instances: all
196 // WebAXObjectProxys ever created from the controller are stored in a list and
197 // cleared explicitly.
198 class WebAXObjectProxyList
: public WebAXObjectProxy::Factory
{
200 WebAXObjectProxyList();
201 ~WebAXObjectProxyList() override
;
204 v8::Local
<v8::Object
> GetOrCreate(const blink::WebAXObject
&) override
;
207 typedef v8::PersistentValueVector
<v8::Object
> ElementList
;
208 ElementList elements_
;
211 } // namespace test_runner
213 #endif // COMPONENTS_TEST_RUNNER_WEB_AX_OBJECT_PROXY_H_