Add CefDOMNode::GetElementBounds() method
This commit is contained in:
parent
1679632000
commit
a312974ad9
|
@ -331,6 +331,11 @@ typedef struct _cef_domnode_t {
|
|||
// The resulting string must be freed by calling cef_string_userfree_free().
|
||||
cef_string_userfree_t (CEF_CALLBACK *get_element_inner_text)(
|
||||
struct _cef_domnode_t* self);
|
||||
|
||||
///
|
||||
// Returns the bounds of the element.
|
||||
///
|
||||
cef_rect_t (CEF_CALLBACK *get_element_bounds)(struct _cef_domnode_t* self);
|
||||
} cef_domnode_t;
|
||||
|
||||
|
||||
|
|
|
@ -323,6 +323,12 @@ class CefDOMNode : public virtual CefBase {
|
|||
///
|
||||
/*--cef()--*/
|
||||
virtual CefString GetElementInnerText() =0;
|
||||
|
||||
///
|
||||
// Returns the bounds of the element.
|
||||
///
|
||||
/*--cef()--*/
|
||||
virtual CefRect GetElementBounds() =0;
|
||||
};
|
||||
|
||||
#endif // CEF_INCLUDE_CEF_DOM_H_
|
||||
|
|
|
@ -378,6 +378,23 @@ CefString CefDOMNodeImpl::GetElementInnerText() {
|
|||
return str;
|
||||
}
|
||||
|
||||
CefRect CefDOMNodeImpl::GetElementBounds() {
|
||||
CefRect rect;
|
||||
if (!VerifyContext())
|
||||
return rect;
|
||||
|
||||
if (!node_.isElementNode()) {
|
||||
NOTREACHED();
|
||||
return rect;
|
||||
}
|
||||
|
||||
WebElement element = node_.to<blink::WebElement>();
|
||||
blink::WebRect rc = element.boundsInViewport();
|
||||
rect.Set(rc.x, rc.y, rc.width, rc.height);
|
||||
|
||||
return rect;
|
||||
}
|
||||
|
||||
void CefDOMNodeImpl::Detach() {
|
||||
document_ = NULL;
|
||||
node_.assign(WebNode());
|
||||
|
|
|
@ -44,6 +44,7 @@ class CefDOMNodeImpl : public CefDOMNode {
|
|||
bool SetElementAttribute(const CefString& attrName,
|
||||
const CefString& value) override;
|
||||
CefString GetElementInnerText() override;
|
||||
CefRect GetElementBounds() override;
|
||||
|
||||
// Will be called from CefDOMDocumentImpl::Detach().
|
||||
void Detach();
|
||||
|
|
|
@ -429,6 +429,21 @@ cef_string_userfree_t CEF_CALLBACK domnode_get_element_inner_text(
|
|||
return _retval.DetachToUserFree();
|
||||
}
|
||||
|
||||
cef_rect_t CEF_CALLBACK domnode_get_element_bounds(
|
||||
struct _cef_domnode_t* self) {
|
||||
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
|
||||
|
||||
DCHECK(self);
|
||||
if (!self)
|
||||
return CefRect();
|
||||
|
||||
// Execute
|
||||
cef_rect_t _retval = CefDOMNodeCppToC::Get(self)->GetElementBounds();
|
||||
|
||||
// Return type: simple
|
||||
return _retval;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
|
||||
|
@ -461,6 +476,7 @@ CefDOMNodeCppToC::CefDOMNodeCppToC() {
|
|||
GetStruct()->get_element_attributes = domnode_get_element_attributes;
|
||||
GetStruct()->set_element_attribute = domnode_set_element_attribute;
|
||||
GetStruct()->get_element_inner_text = domnode_get_element_inner_text;
|
||||
GetStruct()->get_element_bounds = domnode_get_element_bounds;
|
||||
}
|
||||
|
||||
template<> CefRefPtr<CefDOMNode> CefCppToC<CefDOMNodeCppToC, CefDOMNode,
|
||||
|
|
|
@ -429,6 +429,20 @@ CefString CefDOMNodeCToCpp::GetElementInnerText() {
|
|||
return _retvalStr;
|
||||
}
|
||||
|
||||
CefRect CefDOMNodeCToCpp::GetElementBounds() {
|
||||
cef_domnode_t* _struct = GetStruct();
|
||||
if (CEF_MEMBER_MISSING(_struct, get_element_bounds))
|
||||
return CefRect();
|
||||
|
||||
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
|
||||
|
||||
// Execute
|
||||
cef_rect_t _retval = _struct->get_element_bounds(_struct);
|
||||
|
||||
// Return type: simple
|
||||
return _retval;
|
||||
}
|
||||
|
||||
|
||||
// CONSTRUCTOR - Do not edit by hand.
|
||||
|
||||
|
|
|
@ -56,6 +56,7 @@ class CefDOMNodeCToCpp
|
|||
bool SetElementAttribute(const CefString& attrName,
|
||||
const CefString& value) OVERRIDE;
|
||||
CefString GetElementInnerText() OVERRIDE;
|
||||
CefRect GetElementBounds() OVERRIDE;
|
||||
};
|
||||
|
||||
#endif // USING_CEF_SHARED
|
||||
|
|
|
@ -78,7 +78,7 @@ class TestDOMVisitor : public CefDOMVisitor {
|
|||
EXPECT_EQ(h1Node->GetName(), "H1");
|
||||
EXPECT_EQ(h1Node->GetElementTagName(), "H1");
|
||||
|
||||
EXPECT_FALSE(h1Node->GetNextSibling().get());
|
||||
EXPECT_TRUE(h1Node->GetNextSibling().get());
|
||||
EXPECT_FALSE(h1Node->GetPreviousSibling().get());
|
||||
EXPECT_TRUE(h1Node->HasChildren());
|
||||
EXPECT_FALSE(h1Node->HasElementAttributes());
|
||||
|
@ -130,6 +130,17 @@ class TestDOMVisitor : public CefDOMVisitor {
|
|||
|
||||
EXPECT_FALSE(textNode->GetNextSibling().get());
|
||||
EXPECT_FALSE(textNode->HasChildren());
|
||||
|
||||
CefRefPtr<CefDOMNode> divNode = h1Node->GetNextSibling();
|
||||
EXPECT_TRUE(divNode.get());
|
||||
EXPECT_TRUE(divNode->IsElement());
|
||||
EXPECT_FALSE(divNode->IsText());
|
||||
CefRect divRect = divNode->GetElementBounds();
|
||||
EXPECT_EQ(divRect.width, 50);
|
||||
EXPECT_EQ(divRect.height, 25);
|
||||
EXPECT_EQ(divRect.x, 150);
|
||||
EXPECT_EQ(divRect.y, 100);
|
||||
EXPECT_FALSE(divNode->GetNextSibling().get());
|
||||
}
|
||||
|
||||
// Test document structure by iterating through the DOM tree.
|
||||
|
@ -264,6 +275,7 @@ class TestDOMHandler : public TestHandler {
|
|||
"<body>"
|
||||
"<h1>Hello From<br class=\"some_class\"/ id=\"some_id\"/>"
|
||||
"Main Frame</h1>"
|
||||
"<div id=\"sized_element\" style=\"width: 50px; height: 25px; position: fixed; top: 100px; left: 150px;\"/>"
|
||||
"</body>"
|
||||
"</html>";
|
||||
|
||||
|
|
Loading…
Reference in New Issue