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