Index: headless/lib/web_element.cc |
diff --git a/headless/lib/web_element.cc b/headless/lib/web_element.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..848e354b50db6421fd5f5aff0054badedd90edfc |
--- /dev/null |
+++ b/headless/lib/web_element.cc |
@@ -0,0 +1,48 @@ |
+// Copyright 2015 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 "headless/public/web_element.h" |
+ |
+#include "third_party/WebKit/public/platform/WebRect.h" |
+#include "third_party/WebKit/public/web/WebElement.h" |
+ |
+namespace headless { |
+ |
+WebElement::WebElement(const blink::WebElement& web_element) |
+ : WebNode(web_element), attributes_(nullptr) {} |
+ |
+WebElement::WebElement(const WebElement& web_element) |
+ : WebNode(web_element.web_node_), attributes_(nullptr) {} |
+ |
+WebElement::~WebElement() {} |
+ |
+std::string WebElement::TagName() const { |
+ return web_element().tagName().utf8(); |
+} |
+ |
+gfx::Rect WebElement::BoundingBox() const { |
+ blink::WebElement& element = const_cast<blink::WebElement&>(web_element()); |
+ return element.boundsInViewportSpace(); |
+} |
+ |
+const std::map<std::string, std::string>& WebElement::Attributes() const { |
+ if (!attributes_) { |
+ attributes_.reset(new std::map<std::string, std::string>()); |
+ for (size_t i = 0; i < web_element().attributeCount(); ++i) { |
+ (*attributes_)[web_element().attributeLocalName(i).utf8()] = |
+ web_element().attributeValue(i).utf8(); |
+ } |
+ } |
+ return *attributes_; |
+} |
+ |
+blink::WebElement& WebElement::web_element() { |
+ return static_cast<blink::WebElement&>(web_node_); |
+} |
+ |
+const blink::WebElement& WebElement::web_element() const { |
+ return static_cast<const blink::WebElement&>(web_node_); |
+} |
+ |
+} // namespace headless |