mirror of
				https://bitbucket.org/chromiumembedded/cef
				synced 2025-06-05 21:39:12 +02:00 
			
		
		
		
	Add CefDOMNode::GetElementBounds() method
This commit is contained in:
		| @@ -331,6 +331,11 @@ typedef struct _cef_domnode_t { | |||||||
|   // The resulting string must be freed by calling cef_string_userfree_free(). |   // The resulting string must be freed by calling cef_string_userfree_free(). | ||||||
|   cef_string_userfree_t (CEF_CALLBACK *get_element_inner_text)( |   cef_string_userfree_t (CEF_CALLBACK *get_element_inner_text)( | ||||||
|       struct _cef_domnode_t* self); |       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; | } cef_domnode_t; | ||||||
|  |  | ||||||
|  |  | ||||||
|   | |||||||
| @@ -323,6 +323,12 @@ class CefDOMNode : public virtual CefBase { | |||||||
|   /// |   /// | ||||||
|   /*--cef()--*/ |   /*--cef()--*/ | ||||||
|   virtual CefString GetElementInnerText() =0; |   virtual CefString GetElementInnerText() =0; | ||||||
|  |  | ||||||
|  |   /// | ||||||
|  |   // Returns the bounds of the element. | ||||||
|  |   /// | ||||||
|  |   /*--cef()--*/ | ||||||
|  |   virtual CefRect GetElementBounds() =0; | ||||||
| }; | }; | ||||||
|  |  | ||||||
| #endif  // CEF_INCLUDE_CEF_DOM_H_ | #endif  // CEF_INCLUDE_CEF_DOM_H_ | ||||||
|   | |||||||
| @@ -378,6 +378,23 @@ CefString CefDOMNodeImpl::GetElementInnerText() { | |||||||
|   return str; |   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() { | void CefDOMNodeImpl::Detach() { | ||||||
|   document_ = NULL; |   document_ = NULL; | ||||||
|   node_.assign(WebNode()); |   node_.assign(WebNode()); | ||||||
|   | |||||||
| @@ -44,6 +44,7 @@ class CefDOMNodeImpl : public CefDOMNode { | |||||||
|   bool SetElementAttribute(const CefString& attrName, |   bool SetElementAttribute(const CefString& attrName, | ||||||
|                            const CefString& value) override; |                            const CefString& value) override; | ||||||
|   CefString GetElementInnerText() override; |   CefString GetElementInnerText() override; | ||||||
|  |   CefRect GetElementBounds() override; | ||||||
|  |  | ||||||
|   // Will be called from CefDOMDocumentImpl::Detach(). |   // Will be called from CefDOMDocumentImpl::Detach(). | ||||||
|   void Detach(); |   void Detach(); | ||||||
|   | |||||||
| @@ -429,6 +429,21 @@ cef_string_userfree_t CEF_CALLBACK domnode_get_element_inner_text( | |||||||
|   return _retval.DetachToUserFree(); |   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 | }  // namespace | ||||||
|  |  | ||||||
|  |  | ||||||
| @@ -461,6 +476,7 @@ CefDOMNodeCppToC::CefDOMNodeCppToC() { | |||||||
|   GetStruct()->get_element_attributes = domnode_get_element_attributes; |   GetStruct()->get_element_attributes = domnode_get_element_attributes; | ||||||
|   GetStruct()->set_element_attribute = domnode_set_element_attribute; |   GetStruct()->set_element_attribute = domnode_set_element_attribute; | ||||||
|   GetStruct()->get_element_inner_text = domnode_get_element_inner_text; |   GetStruct()->get_element_inner_text = domnode_get_element_inner_text; | ||||||
|  |   GetStruct()->get_element_bounds = domnode_get_element_bounds; | ||||||
| } | } | ||||||
|  |  | ||||||
| template<> CefRefPtr<CefDOMNode> CefCppToC<CefDOMNodeCppToC, CefDOMNode, | template<> CefRefPtr<CefDOMNode> CefCppToC<CefDOMNodeCppToC, CefDOMNode, | ||||||
|   | |||||||
| @@ -429,6 +429,20 @@ CefString CefDOMNodeCToCpp::GetElementInnerText() { | |||||||
|   return _retvalStr; |   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. | // CONSTRUCTOR - Do not edit by hand. | ||||||
|  |  | ||||||
|   | |||||||
| @@ -56,6 +56,7 @@ class CefDOMNodeCToCpp | |||||||
|   bool SetElementAttribute(const CefString& attrName, |   bool SetElementAttribute(const CefString& attrName, | ||||||
|       const CefString& value) OVERRIDE; |       const CefString& value) OVERRIDE; | ||||||
|   CefString GetElementInnerText() OVERRIDE; |   CefString GetElementInnerText() OVERRIDE; | ||||||
|  |   CefRect GetElementBounds() OVERRIDE; | ||||||
| }; | }; | ||||||
|  |  | ||||||
| #endif  // USING_CEF_SHARED | #endif  // USING_CEF_SHARED | ||||||
|   | |||||||
| @@ -78,7 +78,7 @@ class TestDOMVisitor : public CefDOMVisitor { | |||||||
|     EXPECT_EQ(h1Node->GetName(), "H1"); |     EXPECT_EQ(h1Node->GetName(), "H1"); | ||||||
|     EXPECT_EQ(h1Node->GetElementTagName(), "H1"); |     EXPECT_EQ(h1Node->GetElementTagName(), "H1"); | ||||||
|  |  | ||||||
|     EXPECT_FALSE(h1Node->GetNextSibling().get()); |     EXPECT_TRUE(h1Node->GetNextSibling().get()); | ||||||
|     EXPECT_FALSE(h1Node->GetPreviousSibling().get()); |     EXPECT_FALSE(h1Node->GetPreviousSibling().get()); | ||||||
|     EXPECT_TRUE(h1Node->HasChildren()); |     EXPECT_TRUE(h1Node->HasChildren()); | ||||||
|     EXPECT_FALSE(h1Node->HasElementAttributes()); |     EXPECT_FALSE(h1Node->HasElementAttributes()); | ||||||
| @@ -130,6 +130,17 @@ class TestDOMVisitor : public CefDOMVisitor { | |||||||
|  |  | ||||||
|     EXPECT_FALSE(textNode->GetNextSibling().get()); |     EXPECT_FALSE(textNode->GetNextSibling().get()); | ||||||
|     EXPECT_FALSE(textNode->HasChildren()); |     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. |   // Test document structure by iterating through the DOM tree. | ||||||
| @@ -264,6 +275,7 @@ class TestDOMHandler : public TestHandler { | |||||||
|         "<body>" |         "<body>" | ||||||
|         "<h1>Hello From<br class=\"some_class\"/ id=\"some_id\"/>" |         "<h1>Hello From<br class=\"some_class\"/ id=\"some_id\"/>" | ||||||
|         "Main Frame</h1>" |         "Main Frame</h1>" | ||||||
|  |         "<div id=\"sized_element\" style=\"width: 50px; height: 25px; position: fixed; top: 100px; left: 150px;\"/>" | ||||||
|         "</body>" |         "</body>" | ||||||
|         "</html>"; |         "</html>"; | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user