OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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 #include "headless/public/web_element.h" |
| 6 |
| 7 #include "third_party/WebKit/public/platform/WebRect.h" |
| 8 #include "third_party/WebKit/public/web/WebElement.h" |
| 9 |
| 10 namespace headless { |
| 11 |
| 12 WebElement::WebElement(const blink::WebElement& web_element) |
| 13 : WebNode(web_element), attributes_(nullptr) {} |
| 14 |
| 15 WebElement::WebElement(const WebElement& web_element) |
| 16 : WebNode(web_element.web_node_), attributes_(nullptr) {} |
| 17 |
| 18 WebElement::~WebElement() {} |
| 19 |
| 20 std::string WebElement::TagName() const { |
| 21 return web_element().tagName().utf8(); |
| 22 } |
| 23 |
| 24 gfx::Rect WebElement::BoundingBox() const { |
| 25 blink::WebElement& element = const_cast<blink::WebElement&>(web_element()); |
| 26 return element.boundsInViewportSpace(); |
| 27 } |
| 28 |
| 29 const std::map<std::string, std::string>& WebElement::Attributes() const { |
| 30 if (!attributes_) { |
| 31 attributes_.reset(new std::map<std::string, std::string>()); |
| 32 for (size_t i = 0; i < web_element().attributeCount(); ++i) { |
| 33 (*attributes_)[web_element().attributeLocalName(i).utf8()] = |
| 34 web_element().attributeValue(i).utf8(); |
| 35 } |
| 36 } |
| 37 return *attributes_; |
| 38 } |
| 39 |
| 40 blink::WebElement& WebElement::web_element() { |
| 41 return static_cast<blink::WebElement&>(web_node_); |
| 42 } |
| 43 |
| 44 const blink::WebElement& WebElement::web_element() const { |
| 45 return static_cast<const blink::WebElement&>(web_node_); |
| 46 } |
| 47 |
| 48 } // namespace headless |
OLD | NEW |