Calculate Position of CefFrame

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

Calculate Position of CefFrame

Postby grigory » Sat Aug 18, 2018 1:54 pm

Hi community!
I hope you are all doing well.

I want to calculate positions of 'child frames' inside the 'main frame'.
I did the following.

Code: Select all
CefRefPtr<CefFrame> mainframe = m_cefBrowser->GetMainFrame();
CString js;
js.Format(
   L"var i, iframes = document.getElementsByTagName('iframe')"
   L"for(i = 0; i < iframes.length; i++){"
   L"   console.log(JSON.stringify(iframes[i].getBoundingClientRect()));"
   L"}"
);
mainframe->ExecuteJavaScript(js.GetString(), frame->GetURL(), 0);

Then I needed to identify which iframe element is assigned to which CefFrame.
I tried to compare iframe's src and name attribute values with CefFrame::GetURL and CefFrame::GetName.

In this way, I could calculate the position, width, and height of each CefFrame.

My problem is when the iframe element hasn't got src or name attribute, how can I get the position of the corresponding CefFrame?

Is there any direct way of doing this?
CefFrame class can't return attribute values except src and name?
Maybe CefFrame::GetIdentifier() increases in order of element array document.getElementsByTagName('iframe') ?

Thanks for your attention.
grigory
Newbie
 
Posts: 3
Joined: Mon Jul 23, 2018 6:19 am

Re: Calculate Position of CefFrame

Postby Czarek » Fri Aug 31, 2018 4:24 am

Does the frame without src and name attributes have any content?
Maintainer of the CEF Python, PHP Desktop and CEF C API projects. My LinkedIn.
User avatar
Czarek
Virtuoso
 
Posts: 1927
Joined: Sun Nov 06, 2011 2:12 am

Re: Calculate Position of CefFrame

Postby Czarek » Fri Aug 31, 2018 4:27 am

You can execute custom js in a frame and such js code can access "window.frameElement", thus can identify the frame, see:
https://developer.mozilla.org/en-US/doc ... ameElement
Maintainer of the CEF Python, PHP Desktop and CEF C API projects. My LinkedIn.
User avatar
Czarek
Virtuoso
 
Posts: 1927
Joined: Sun Nov 06, 2011 2:12 am


Return to Support Forum

Who is online

Users browsing this forum: No registered users and 33 guests