b10b5e88e2e9060d3cc88a7086b78d2ae5f549ca
[platform/framework/web/crosswalk.git] / src / content / shell / renderer / test_runner / web_ax_object_proxy.h
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.
4
5 #ifndef CONTENT_SHELL_RENDERER_TEST_RUNNER_WEB_AX_OBJECT_PROXY_H_
6 #define CONTENT_SHELL_RENDERER_TEST_RUNNER_WEB_AX_OBJECT_PROXY_H_
7
8 #include <string>
9 #include <vector>
10
11 #include "base/basictypes.h"
12 #include "content/shell/renderer/test_runner/unsafe_persistent.h"
13 #include "gin/object_template_builder.h"
14 #include "gin/wrappable.h"
15 #include "third_party/WebKit/public/web/WebAXObject.h"
16 #include "v8/include/v8.h"
17
18 namespace blink {
19 class WebFrame;
20 }
21
22 namespace content {
23
24 class WebAXObjectProxy : public gin::Wrappable<WebAXObjectProxy> {
25  public:
26   class Factory {
27    public:
28     virtual ~Factory() { }
29     virtual v8::Handle<v8::Object> GetOrCreate(
30         const blink::WebAXObject& object) = 0;
31   };
32
33   static gin::WrapperInfo kWrapperInfo;
34
35   WebAXObjectProxy(const blink::WebAXObject& object, Factory* factory);
36   virtual ~WebAXObjectProxy();
37
38   // gin::Wrappable:
39   virtual gin::ObjectTemplateBuilder GetObjectTemplateBuilder(
40       v8::Isolate* isolate) OVERRIDE;
41
42   virtual v8::Handle<v8::Object> GetChildAtIndex(unsigned index);
43   virtual bool IsRoot() const;
44   bool IsEqualToObject(const blink::WebAXObject& object);
45
46   void NotificationReceived(blink::WebFrame* frame,
47                             const std::string& notification_name);
48
49  protected:
50   const blink::WebAXObject& accessibility_object() const {
51     return accessibility_object_;
52   }
53
54   Factory* factory() const { return factory_; }
55
56  private:
57   friend class WebAXObjectProxyBindings;
58
59   // Bound properties.
60   std::string Role();
61   std::string Title();
62   std::string Description();
63   std::string HelpText();
64   std::string StringValue();
65   int X();
66   int Y();
67   int Width();
68   int Height();
69   int IntValue();
70   int MinValue();
71   int MaxValue();
72   std::string ValueDescription();
73   int ChildrenCount();
74   int InsertionPointLineNumber();
75   std::string SelectedTextRange();
76   bool IsEnabled();
77   bool IsRequired();
78   bool IsFocused();
79   bool IsFocusable();
80   bool IsSelected();
81   bool IsSelectable();
82   bool IsMultiSelectable();
83   bool IsSelectedOptionActive();
84   bool IsExpanded();
85   bool IsChecked();
86   bool IsVisible();
87   bool IsOffScreen();
88   bool IsCollapsed();
89   bool HasPopup();
90   bool IsValid();
91   bool IsReadOnly();
92   std::string Orientation();
93   int ClickPointX();
94   int ClickPointY();
95   int32_t RowCount();
96   int32_t ColumnCount();
97   bool IsClickable();
98
99   // Bound methods.
100   std::string AllAttributes();
101   std::string AttributesOfChildren();
102   int LineForIndex(int index);
103   std::string BoundsForRange(int start, int end);
104   v8::Handle<v8::Object> ChildAtIndex(int index);
105   v8::Handle<v8::Object> ElementAtPoint(int x, int y);
106   v8::Handle<v8::Object> TableHeader();
107   std::string RowIndexRange();
108   std::string ColumnIndexRange();
109   v8::Handle<v8::Object> CellForColumnAndRow(int column, int row);
110   v8::Handle<v8::Object> TitleUIElement();
111   void SetSelectedTextRange(int selection_start, int length);
112   bool IsAttributeSettable(const std::string& attribute);
113   bool IsPressActionSupported();
114   bool IsIncrementActionSupported();
115   bool IsDecrementActionSupported();
116   v8::Handle<v8::Object> ParentElement();
117   void Increment();
118   void Decrement();
119   void ShowMenu();
120   void Press();
121   bool IsEqual(v8::Handle<v8::Object> proxy);
122   void SetNotificationListener(v8::Handle<v8::Function> callback);
123   void UnsetNotificationListener();
124   void TakeFocus();
125   void ScrollToMakeVisible();
126   void ScrollToMakeVisibleWithSubFocus(int x, int y, int width, int height);
127   void ScrollToGlobalPoint(int x, int y);
128   int WordStart(int character_index);
129   int WordEnd(int character_index);
130
131   blink::WebAXObject accessibility_object_;
132   Factory* factory_;
133
134   v8::Persistent<v8::Function> notification_callback_;
135
136   DISALLOW_COPY_AND_ASSIGN(WebAXObjectProxy);
137 };
138
139 class RootWebAXObjectProxy : public WebAXObjectProxy {
140  public:
141   RootWebAXObjectProxy(const blink::WebAXObject&, Factory*);
142
143   virtual v8::Handle<v8::Object> GetChildAtIndex(unsigned index) OVERRIDE;
144   virtual bool IsRoot() const OVERRIDE;
145 };
146
147
148 // Provides simple lifetime management of the WebAXObjectProxy instances: all
149 // WebAXObjectProxys ever created from the controller are stored in a list and
150 // cleared explicitly.
151 class WebAXObjectProxyList : public WebAXObjectProxy::Factory {
152  public:
153   WebAXObjectProxyList();
154   virtual ~WebAXObjectProxyList();
155
156   void Clear();
157   virtual v8::Handle<v8::Object> GetOrCreate(
158       const blink::WebAXObject&) OVERRIDE;
159   v8::Handle<v8::Object> CreateRoot(const blink::WebAXObject&);
160
161  private:
162   typedef std::vector<UnsafePersistent<v8::Object> > ElementList;
163   ElementList elements_;
164 };
165
166 }  // namespace content
167
168 #endif  // CONTENT_SHELL_RENDERER_TEST_RUNNER_WEB_AX_OBJECT_PROXY_H_