Get Document Height and Remove Scrollbars

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.

Get Document Height and Remove Scrollbars

Postby matthewj » Mon Jun 06, 2011 5:09 pm

It might be obvious, but I'm not seeing an easy way to determine the full height of a document after it has been rendered.

Additionally, is there a way to turn off scrollbars on the browser control?

Thanks,
Matt
matthewj
Techie
 
Posts: 13
Joined: Mon Jun 06, 2011 5:05 pm

Re: Get Document Height and Remove Scrollbars

Postby magreenblatt » Mon Jun 06, 2011 7:44 pm

matthewj wrote:It might be obvious, but I'm not seeing an easy way to determine the full height of a document after it has been rendered.
Additionally, is there a way to turn off scrollbars on the browser control?

Both of these can be done using JavaScript/CSS:

http://stackoverflow.com/questions/1145 ... javascript
http://www.w3schools.com/css/pr_pos_overflow.asp
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: Get Document Height and Remove Scrollbars

Postby matthewj » Tue Jun 07, 2011 8:55 am

JS is not ideal to get the height, but I should be able to execute it via CefFrame::ExecuteJavaScript. However, I don't see a good way to pass the result back to the caller.

Do I have to use the JS to update the DOM and then use the other APIs to look in the DOM to get the data?
matthewj
Techie
 
Posts: 13
Joined: Mon Jun 06, 2011 5:05 pm

Re: Get Document Height and Remove Scrollbars

Postby cagret » Tue Jun 07, 2011 9:06 am

You want to pass the height from javascript to c++?
You could use javascript handler binding, see cefclient.cpp: HandleJSBinding, binding_test.h, binding_test.cpp.
Last edited by cagret on Tue Jun 07, 2011 9:19 am, edited 1 time in total.
User avatar
cagret
Techie
 
Posts: 41
Joined: Fri Mar 11, 2011 11:42 am
Location: Poland

Re: Get Document Height and Remove Scrollbars

Postby magreenblatt » Tue Jun 07, 2011 9:07 am

matthewj wrote:JS is not ideal to get the height, but I should be able to execute it via CefFrame::ExecuteJavaScript. However, I don't see a good way to pass the result back to the caller.

See viewtopic.php?f=6&t=328

matthewj wrote:Do I have to use the JS to update the DOM and then use the other APIs to look in the DOM to get the data?

You can use the CefDOM* classes to access the DOM from C/C++ but the interface is mostly read-only. To modify the DOM you should use JavaScript.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: Get Document Height and Remove Scrollbars

Postby cagret » Tue Jun 07, 2011 9:16 am

Marshall,

Would it be a problem to add a similar function to ExecuteJavascript() but with arguments like in ExecuteFunction()?
So I can call: frame->ExecuteFunction("alert", args, retval, exception);
Alert is not the best example, but when I want to pass data that I already have in some kind of format, using ExecuteJavascript is problematic cause I would need to stringify that data to json or something.
User avatar
cagret
Techie
 
Posts: 41
Joined: Fri Mar 11, 2011 11:42 am
Location: Poland

Re: Get Document Height and Remove Scrollbars

Postby magreenblatt » Tue Jun 07, 2011 9:24 am

cagret wrote:Marshall,

Would it be a problem to add a similar function to ExecuteJavascript() but with arguments like in ExecuteFunction()?
So I can call: frame->ExecuteFunction("alert", args, retval, exception);
Alert is not the best example, but when I want to pass data that I already have in some kind of format, using ExecuteJavascript is problematic cause I would need to stringify that data to json or something.

You can register JavaScript callbacks with your native code and execute them asynchronously using CefV8Context. See issues #188 and #203.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: Get Document Height and Remove Scrollbars

Postby cagret » Tue Jun 07, 2011 10:05 am

Okay so I need to do this steps:

1. First, on my html page I need to send function callbacks to c++, so I do this:
Code: Select all
<head>
window.sendCallback("myfunc1", myfunc1);
window.sendCallback("myfunc2", myfunc2");
</head>

And I need to do this for all the javascript functions that I would like to be able to call from c++ code?

2. In CefV8Handler::Execute() I implement "sendCallback" function in which I save the callbacks somewhere in the code along with current context? So that I have an array like this to use later:
Code: Select all
context = CefV8Context::GetCurrentContext();
jsfuncs = array(
    "myfunc1" => (callback, context),
    "myfunc2" => (callback, context)
)
// myfunc1 = arguments[0], callback = arguments[1]


3. Later in my c++ code if I want to call js function called "myfunc1" I do this:
Code: Select all
callback = jsfuncs["myfunc1"][0]
context = jsfuncs["myfunc2"][1]
context.Enter()
callback->ExecuteFunctionWithContext(context, callback, someArguments, retval, exception);
SomeWork_1();
context.Exit()
SomeWork_2();


And that code between .Enter() and .Exit() is executed asynchronously, so that if myfunc1() executes for 5 secs, then SomeWork_2() will be executed before SomeWork_1() ?
Is it also possible to execute myfunc1() synchronously? Or do I always need to call .Enter and .Exit?
I read more and seems like calling context.Enter and .Exit is required when creating V8 Objects, Arrays or Functions - and I can create them only asynchronously, is that right?
User avatar
cagret
Techie
 
Posts: 41
Joined: Fri Mar 11, 2011 11:42 am
Location: Poland

Re: Get Document Height and Remove Scrollbars

Postby magreenblatt » Tue Jun 07, 2011 10:22 am

cagret wrote:And that code between .Enter() and .Exit() is executed asynchronously, so that if myfunc1() executes for 5 secs, then SomeWork_2() will be executed before SomeWork_1() ?
Is it also possible to execute myfunc1() synchronously? Or do I always need to call .Enter and .Exit?
I read more and seems like calling context.Enter and .Exit is required when creating V8 Objects, Arrays or Functions - and I can create them only asynchronously, is that right?

You should be calling Enter(), ExecuteFunctionWithContext() and Exit() on the UI thread. Execution of your JS callback will be synchronous with and block other JavaScript (and WebKit) execution.

If your JS callback will take a long time you should break it into separate smaller code blocks and execute them asynchronously using CEF tasks or JS timers.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: Get Document Height and Remove Scrollbars

Postby matthewj » Wed Jun 08, 2011 3:28 pm

cagret wrote:You want to pass the height from javascript to c++?
You could use javascript handler binding, see cefclient.cpp: HandleJSBinding, binding_test.h, binding_test.cpp.


Thanks, I have this method working now. Though it's a little too much power for what I need right now, but I'm seeing many possible uses of it in the future.
matthewj
Techie
 
Posts: 13
Joined: Mon Jun 06, 2011 5:05 pm


Return to Support Forum

Who is online

Users browsing this forum: No registered users and 199 guests