Auto detection of body element size change

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.

Auto detection of body element size change

Postby omeriko » Mon Dec 03, 2012 1:05 pm

Hi,

I'm using CEF1 (version 1.1180.832) on Windows7.

I want to resize my browser window according to it's body's height and width (DOM).
There are actually 2 parts for this question:

1 - Automatically detect body element size change
Whenever the DOM body size changes - I want to detect it immediately.
calling pDOMNode->AddEventListener("resize", ...) doesn't work for any DOM element (document\body\div...).
what I do right now, is visiting the DOM and checking the size of the body and see if it changed - every 250msec.
I don't like this way, but I can't think of any other method to do that.
suggestions?

2 - Query the page's document\body width and height
How can I query the size of the document (to resize the browser window accordingly)?
Right now I'm simply calling context->Eval with a script that returns the body size.
Here also there are a couple of problems. For example, when asking for document.body.offsetWidth - it doesn't include a vertical scrollbar.
Is there a better (and more efficient) way for querying the size without executing a script?

Thanks.
omeriko
Techie
 
Posts: 32
Joined: Wed Dec 07, 2011 8:32 am

Re: Auto detection of body element size change

Postby magreenblatt » Mon Dec 03, 2012 3:08 pm

CEF1 provides a CefDisplayHandler::OnContentsSizeChange callback that may work for your purposes. Also see viewtopic.php?f=6&t=832&start=0#p3339 for related conversation.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: Auto detection of body element size change

Postby omeriko » Tue Dec 04, 2012 5:39 am

Thanks for the quick reply!

CefDisplayHandler::OnContentsSizeChange would have been perfect, if it weren't for a couple of annoying issues (or maybe I'm doing something wrong):]

1 - Question - How can I limit the page's size using CSS.
For example, I have a 500X500 image in my body. The body's CSS is set to {width:300px; height:300px; overflow: hidden;}.
The content size is 500X500, and not 300X300 (despite using overflow hidden).
If I were to wrap the image with a div and set its CSS to "div {width:200px; height: 200px; overflow:hidden;}" then the content width would be limited.
Bottom line - Why is the "overflow hidden" behavior for DIV and BODY different?

2 - More important - When content size change to something smaller - I don't get notified.
Using the same example, when dynamically resizing the image to bigger size (700X700), I get notified via CefDisplayHandler::OnContentsSizeChange.
But when resizing to smaller size (200X200), I don't get any notification through CefDisplayHandler::OnContentsSizeChange

I saw a similar question: viewtopic.php?f=6&t=1448&p=4587
I tried to set different DOCTYPE declarations (strict and quirks mode) - but nothing happened.

Is this really a bug? or am I doing something wrong?
omeriko
Techie
 
Posts: 32
Joined: Wed Dec 07, 2011 8:32 am

Re: Auto detection of body element size change

Postby omeriko » Sun Dec 09, 2012 3:58 am

Didn't get any reply and I'd love to resolve it:
The event CefDisplayHandler::OnContentsSizeChange isn't called when body size is changed to smaller. It only works when I change it to a bigger size.

Please advise!

Thanks
omeriko
Techie
 
Posts: 32
Joined: Wed Dec 07, 2011 8:32 am

Re: Auto detection of body element size change

Postby omeriko » Thu Dec 13, 2012 3:27 am

*bump*

The event CefDisplayHandler::OnContentsSizeChange isn't called when body size is changed to smaller. It only works when I change it to a bigger size.


Any ideas? :?

Thanks!
omeriko
Techie
 
Posts: 32
Joined: Wed Dec 07, 2011 8:32 am

Re: Auto detection of body element size change

Postby emerick » Wed Jan 09, 2013 3:42 pm

Is your HTML page running in "quirks mode"? That was the problem I encountered in this thread:

viewtopic.php?f=6&t=1448&p=4587&hilit=oncontentssizechange#p4546

Emerick
emerick
Expert
 
Posts: 154
Joined: Sun Feb 21, 2010 7:57 pm
Location: Belmont, MA


Return to Support Forum

Who is online

Users browsing this forum: Google [Bot] and 223 guests