web_element.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. * Copyright (C) 2009 Google Inc. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are
  6. * met:
  7. *
  8. * * Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * * Redistributions in binary form must reproduce the above
  11. * copyright notice, this list of conditions and the following disclaimer
  12. * in the documentation and/or other materials provided with the
  13. * distribution.
  14. * * Neither the name of Google Inc. nor the names of its
  15. * contributors may be used to endorse or promote products derived from
  16. * this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  22. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  24. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  25. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  26. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  28. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. #ifndef THIRD_PARTY_BLINK_PUBLIC_WEB_WEB_ELEMENT_H_
  31. #define THIRD_PARTY_BLINK_PUBLIC_WEB_WEB_ELEMENT_H_
  32. #include <vector>
  33. #include "third_party/blink/public/web/web_node.h"
  34. #include "third_party/skia/include/core/SkBitmap.h"
  35. #include "v8/include/v8.h"
  36. namespace gfx {
  37. class Size;
  38. }
  39. namespace blink {
  40. class Element;
  41. class Image;
  42. struct WebRect;
  43. // Provides access to some properties of a DOM element node.
  44. class BLINK_EXPORT WebElement : public WebNode {
  45. public:
  46. WebElement() : WebNode() {}
  47. WebElement(const WebElement& e) = default;
  48. // Returns the empty WebElement if the argument doesn't represent an Element.
  49. static WebElement FromV8Value(v8::Local<v8::Value>);
  50. WebElement& operator=(const WebElement& e) {
  51. WebNode::Assign(e);
  52. return *this;
  53. }
  54. void Assign(const WebElement& e) { WebNode::Assign(e); }
  55. bool IsFormControlElement() const;
  56. // If the element is editable, for example by being contenteditable or being
  57. // an <input> that isn't readonly or disabled.
  58. bool IsEditable() const;
  59. // Returns the qualified name, which may contain a prefix and a colon.
  60. WebString TagName() const;
  61. // Check if this element has the specified local tag name, and the HTML
  62. // namespace. Tag name matching is case-insensitive.
  63. bool HasHTMLTagName(const WebString&) const;
  64. bool HasAttribute(const WebString&) const;
  65. WebString GetAttribute(const WebString&) const;
  66. void SetAttribute(const WebString& name, const WebString& value);
  67. WebString TextContent() const;
  68. WebString InnerHTML() const;
  69. WebString AttributeLocalName(unsigned index) const;
  70. WebString AttributeValue(unsigned index) const;
  71. unsigned AttributeCount() const;
  72. // Returns true if this is an autonomous custom element, regardless of
  73. // Custom Elements V0 or V1.
  74. bool IsAutonomousCustomElement() const;
  75. // Returns an author ShadowRoot attached to this element, regardless
  76. // of V0, V1 open, or V1 closed. This returns null WebNode if this
  77. // element has no ShadowRoot or has a UA ShadowRoot.
  78. WebNode ShadowRoot() const;
  79. // Returns the open shadow root or the closed shadow root.
  80. WebNode OpenOrClosedShadowRoot();
  81. // Returns the bounds of the element in Visual Viewport. The bounds
  82. // have been adjusted to include any transformations, including page scale.
  83. // This function will update the layout if required.
  84. WebRect BoundsInViewport() const;
  85. // Returns the image contents of this element or a null SkBitmap
  86. // if there isn't any.
  87. SkBitmap ImageContents();
  88. // Returns a copy of original image data of this element or an empty vector
  89. // if there isn't any.
  90. std::vector<uint8_t> CopyOfImageData();
  91. // Returns the original image file extension.
  92. std::string ImageExtension();
  93. // Returns the original image size.
  94. gfx::Size GetImageSize();
  95. void RequestFullscreen();
  96. // ComputedStyle property values. The following exposure is of CSS property
  97. // values are part of the ComputedStyle set which is usually exposed through
  98. // the Window object in WebIDL as window.getComputedStyle(element). Exposing
  99. // ComputedStyle requires all of CSSComputedStyleDeclaration which is a pretty
  100. // large interfaces. For now the we are exposing computed property values as
  101. // strings directly to WebElement and enable public component usage through
  102. // /public/web interfaces.
  103. WebString GetComputedValue(const WebString& property_name);
  104. #if INSIDE_BLINK
  105. WebElement(Element*);
  106. WebElement& operator=(Element*);
  107. operator Element*() const;
  108. #endif
  109. private:
  110. Image* GetImage();
  111. };
  112. DECLARE_WEB_NODE_TYPE_CASTS(WebElement);
  113. } // namespace blink
  114. #endif