Index: content/shell/renderer/test_runner/accessibility_controller.cc |
diff --git a/content/shell/renderer/test_runner/accessibility_controller.cc b/content/shell/renderer/test_runner/accessibility_controller.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..671e1a244d6c6b560bc5e26a93a3f91125010422 |
--- /dev/null |
+++ b/content/shell/renderer/test_runner/accessibility_controller.cc |
@@ -0,0 +1,187 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "content/shell/renderer/test_runner/accessibility_controller.h" |
+ |
+#include "gin/handle.h" |
+#include "gin/object_template_builder.h" |
+#include "gin/wrappable.h" |
+#include "third_party/WebKit/public/web/WebElement.h" |
+#include "third_party/WebKit/public/web/WebFrame.h" |
+#include "third_party/WebKit/public/web/WebKit.h" |
+#include "third_party/WebKit/public/web/WebView.h" |
+ |
+namespace content { |
+ |
+class AccessibilityControllerBindings |
+ : public gin::Wrappable<AccessibilityControllerBindings> { |
+ public: |
+ static gin::WrapperInfo kWrapperInfo; |
+ |
+ static void Install(base::WeakPtr<AccessibilityController> controller, |
+ blink::WebFrame* frame); |
+ private: |
+ explicit AccessibilityControllerBindings( |
+ base::WeakPtr<AccessibilityController> controller); |
+ virtual ~AccessibilityControllerBindings(); |
+ |
+ void LogAccessibilityEvents(); |
+ void AddNotificationListener(v8::Handle<v8::Function> callback); |
+ void RemoveNotificationListener(v8::Handle<v8::Function> callback); |
+ // FIXME |
+ void FocusedElement(); |
+ // FIXME |
+ void RootElement(); |
+ void AccessibleElementById(); |
+ void Fallback(); |
+ |
+ // gin::Wrappable: |
+ virtual gin::ObjectTemplateBuilder GetObjectTemplateBuilder( |
+ v8::Isolate* isolate) OVERRIDE; |
+ |
+ base::WeakPtr<AccessibilityController> controller_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(AccessibilityControllerBindings); |
+}; |
+ |
+// static |
+gin::WrapperInfo AccessibilityControllerBindings::kWrapperInfo = { |
+ gin::kEmbedderNativeGin, |
+}; |
+ |
+// static |
+void AccessibilityControllerBindings::Install( |
+ base::WeakPtr<AccessibilityController> controller, |
+ blink::WebFrame* frame) { |
+ v8::Isolate* isolate = blink::mainThreadIsolate(); |
+ v8::HandleScope handle_scope(isolate); |
+ v8::Handle<v8::Context> context = frame->mainWorldScriptContext(); |
+ if (context.IsEmpty()) |
+ return; |
+ |
+ v8::Context::Scope context_scope(context); |
+ |
+ gin::Handle<AccessibilityControllerBindings> bindings = |
+ gin::CreateHandle(isolate, |
+ new AccessibilityControllerBindings(controller)); |
+ v8::Handle<v8::Object> global = context->Global(); |
+ global->Set(gin::StringToV8(isolate, "accessibilityController"), |
+ bindings.ToV8()); |
+} |
+ |
+AccessibilityControllerBindings::AccessibilityControllerBindings( |
+ base::WeakPtr<AccessibilityController> controller) |
+ : controller_(controller) { |
+} |
+ |
+gin::ObjectTemplateBuilder |
+AccessibilityControllerBindings::GetObjectTemplateBuilder( |
+ v8::Isolate* isolate) { |
+ return gin::Wrappable<AccessibilityControllerBindings>:: |
+ GetObjectTemplateBuilder(isolate) |
+ .SetMethod("logAccessibilityEvents", |
+ &AccessibilityControllerBindings::LogAccessibilityEvents) |
+ .SetMethod("addNotificationListener", |
+ &AccessibilityControllerBindings::AddNotificationListener) |
+ .SetMethod("removeNotificationListener", |
+ &AccessibilityControllerBindings::RemoveNotificationListener) |
+ .SetMethod("focusedEelement", |
+ &AccessibilityControllerBindings::FocusedElement) |
+ .SetMethod("rootElement", |
+ &AccessibilityControllerBindings::RootElement) |
+ .SetMethod("accessibleElementById", |
+ &AccessibilityControllerBindings::AccessibleElementById); |
+ |
+ // fallback? |
+} |
+ |
+void AccessibilityControllerBindings::LogAccessibilityEvents() { |
+ if (controller_) |
+ controller_->LogAccessibilityEvents(); |
+} |
+ |
+void AccessibilityControllerBindings::AddNotificationListener( |
+ v8::Handle<v8::Function> callback) { |
+ if (controller_) |
+ controller_->AddNotificationListener(callback); |
+} |
+ |
+void AccessibilityControllerBindings::RemoveNotificationListener( |
+ v8::Handle<v8::Function> callback) { |
+ if (controller_) |
+ controller_->RemoveNotificationListener(callback); |
+} |
+ |
+void AccessibilityControllerBindings::FocusedElement() { |
+ // return controller_ ? controller_->FocusedElement() : NULL; |
+} |
+ |
+void AccessibilityControllerBindings::RootElement() { |
+ // return controller_ ? controller_->RootElement() : NULL; |
+} |
+ |
+void AccessibilityControllerBindings::AccessibleElementById() { |
+} |
+ |
+AccessibilityController::AccessibilityController() |
+ : log_accessibility_events_(false), |
+ weak_factory_(this) { |
+} |
+ |
+AccessibilityController::~AccessibilityController() { |
+} |
+ |
+WebTestRunner::WebAXObjectProxy* |
+AccessibilityController::FindAccessibleElementByIdRecursive( |
+ const blink::WebAXObject& obj, const blink::WebString& id) |
+{ |
+ if (obj.isNull() || obj.isDetached()) |
+ return NULL; |
+ |
+ blink::WebNode node = obj.node(); |
+ if (!node.isNull() && node.isElementNode()) { |
+ blink::WebElement element = node.to<blink::WebElement>(); |
+ element.getAttribute("id"); |
+ if (element.getAttribute("id") == id) |
+ return elements_.getOrCreate(obj); |
+ } |
+ |
+ unsigned childCount = obj.childCount(); |
+ for (unsigned i = 0; i < childCount; i++) { |
+ if (WebTestRunner::WebAXObjectProxy* result = |
+ FindAccessibleElementByIdRecursive(obj.childAt(i), id)) { |
+ return result; |
+ } |
+ } |
+ |
+ return NULL; |
+} |
+ |
+void AccessibilityController::LogAccessibilityEvents() { |
+ log_accessibility_events_ = true; |
+} |
+ |
+void AccessibilityController::AddNotificationListener( |
+ v8::Handle<v8::Function> callback) { |
+ notification_callbacks_.push_back(callback); |
+} |
+ |
+void AccessibilityController::RemoveNotificationListener( |
+ v8::Handle<v8::Function> callback) { |
+ // FIXME: Implement this |
+} |
+ |
+WebTestRunner::WebAXObjectProxy* AccessibilityController::FocusedElement() { |
+ if (focused_element_.isNull()) |
+ focused_element_ = web_view_->accessibilityObject(); |
+ return elements_.getOrCreate(focused_element_); |
+} |
+ |
+WebTestRunner::WebAXObjectProxy* AccessibilityController::RootElement() { |
+ if (root_element_.isNull()) |
+ root_element_ = web_view_->accessibilityObject(); |
+ return elements_.createRoot(root_element_); |
+} |
+ |
+} // namespace content |