Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / components / test_runner / web_ax_object_proxy.h
blobfc636a1660b9d55eb046268d8277f6bc3601596e
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_
8 #include <string>
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"
17 namespace blink {
18 class WebFrame;
21 namespace test_runner {
23 class WebAXObjectProxy : public gin::Wrappable<WebAXObjectProxy> {
24 public:
25 class Factory {
26 public:
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;
37 // gin::Wrappable:
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);
47 void Reset();
49 protected:
50 const blink::WebAXObject& accessibility_object() const {
51 return accessibility_object_;
54 Factory* factory() const { return factory_; }
56 private:
57 friend class WebAXObjectProxyBindings;
59 // Bound properties.
60 std::string Role();
61 std::string StringValue();
62 std::string Language();
63 int X();
64 int Y();
65 int Width();
66 int Height();
67 int IntValue();
68 int MinValue();
69 int MaxValue();
70 std::string ValueDescription();
71 int ChildrenCount();
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
84 // a textarea.
85 int SelectionStart();
86 int SelectionEnd();
87 int SelectionStartLineNumber();
88 int SelectionEndLineNumber();
90 bool IsEnabled();
91 bool IsRequired();
92 bool IsEditable();
93 bool IsRichlyEditable();
94 bool IsFocused();
95 bool IsFocusable();
96 bool IsSelected();
97 bool IsSelectable();
98 bool IsMultiSelectable();
99 bool IsSelectedOptionActive();
100 bool IsExpanded();
101 bool IsChecked();
102 bool IsVisible();
103 bool IsOffScreen();
104 bool IsCollapsed();
105 bool HasPopup();
106 bool IsValid();
107 bool IsReadOnly();
108 unsigned int BackgroundColor();
109 unsigned int Color();
110 // For input elements of type color.
111 unsigned int ColorValue();
112 float FontSize();
113 std::string Orientation();
114 int PosInSet();
115 int SetSize();
116 int ClickPointX();
117 int ClickPointY();
118 int32_t RowCount();
119 int32_t RowHeadersCount();
120 int32_t ColumnCount();
121 int32_t ColumnHeadersCount();
122 bool IsClickable();
123 bool IsButtonStateMixed();
125 // Bound methods.
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();
149 void Increment();
150 void Decrement();
151 void ShowMenu();
152 void Press();
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();
157 void TakeFocus();
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
173 std::string Name();
174 std::string NameFrom();
175 int NameElementCount();
176 v8::Local<v8::Object> NameElementAtIndex(unsigned index);
178 blink::WebAXObject accessibility_object_;
179 Factory* factory_;
181 v8::Persistent<v8::Function> notification_callback_;
183 DISALLOW_COPY_AND_ASSIGN(WebAXObjectProxy);
186 class RootWebAXObjectProxy : public WebAXObjectProxy {
187 public:
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 {
199 public:
200 WebAXObjectProxyList();
201 ~WebAXObjectProxyList() override;
203 void Clear();
204 v8::Local<v8::Object> GetOrCreate(const blink::WebAXObject&) override;
206 private:
207 typedef v8::PersistentValueVector<v8::Object> ElementList;
208 ElementList elements_;
211 } // namespace test_runner
213 #endif // COMPONENTS_TEST_RUNNER_WEB_AX_OBJECT_PROXY_H_