How to change the style of scrollbar?

Do not post support requests, bug reports or feature requests. Discuss CEF here. Non-CEF related discussion goes in General Discussion!

How to change the style of scrollbar?

Postby shenhui » Sun Apr 17, 2011 1:33 am

Hello all,

I have embeded CEF in my application and want to change the window's scrollbar style on web page. I wrote a piece of javascript code and called ExecuteJavascript() api when web page started loading, but it seems not work well all the time, sometimes it works and somtimes not.

I have also tried another method by set user_style_sheet_enabled in CefBrowserSettings to true and initialize user_style_sheet_location when initialize CEF, but not worked as well.

Is there anyway we can do to change the scrollbar style of CEF webpage when we embeded CEF framwork?

Any advice will be much appreciated.

ShenHui.
shenhui
Techie
 
Posts: 31
Joined: Sat Apr 16, 2011 10:50 pm

Re: How to change the style of scrollbar?

Postby magreenblatt » Sun Apr 17, 2011 8:17 am

Can you provide more detail about the situations where what you've tried so far has not worked? For example, did they work on some websites but not others?

CEF will support custom drawing of scrollbars in the future where the client is completely responsible for drawing the scroll bar controls. Would that satisfy what you're looking for?
magreenblatt
Site Admin
 
Posts: 12408
Joined: Fri May 29, 2009 6:57 pm

Re: How to change the style of scrollbar?

Postby shenhui » Sun Apr 17, 2011 9:53 am

Hello magreenblatt,

Thanks very much for your reply.

I just want to modify the scrollbar style of CEF browser.
In my opinion, the best way is changing the custom style sheet file, I have found that there is a user_style_sheet_enabled and a user_style_sheet_location attribute in class CefBrowserSettings, then I think I can set the values of these two attributes and then pass CefBrowserSettings object into CefInitialize api. The code sample is followed below:
......
CefSettings settings;
CefBrowserSettings browserDefaults ;

browserDefaults.user_style_sheet_enabled = true ;
browserDefaults.user_style_sheet_location.str = new TCHAR[MAX_PATH] ;
_tcscpy(browserDefaults.user_style_sheet_location.str, _T("E:\\tmp\\cef_binary_r181_VS2005-VS2008\\build\\Debug\\obj2005\\custom.css")) ;

CefInitialize(settings, browserDefaults);
......
......

Then I wrote my own scrollbar style in custom.css, but it seems not work when I run the program.
shenhui
Techie
 
Posts: 31
Joined: Sat Apr 16, 2011 10:50 pm

Re: How to change the style of scrollbar?

Postby cagret » Sun Apr 17, 2011 11:48 am

You could provide more details.
1. When adding your custom CSS styles - did you try changing some other elements on a web page using this css? Only scroll bars don't work, or the CSS completely?
2. Did you test your custom css on a webpage in chrome? Also check javascript console for any errors.
User avatar
cagret
Techie
 
Posts: 41
Joined: Fri Mar 11, 2011 11:42 am
Location: Poland

Re: How to change the style of scrollbar?

Postby shenhui » Sun Apr 17, 2011 8:11 pm

Thanks for your reply.

1. When adding your custom CSS styles - did you try changing some other elements on a web page using this css? Only scroll bars don't work, or the CSS completely?
I add my custom CSS styles by calling CefInitalize(...) when my application starts up. And all of styles in CSS file did not work.
2. Did you test your custom css on a webpage in chrome? Also check javascript console for any errors.
I have tested my own custom css on a chrome webpage by replacing the chrome's default custom.css file, and it works well.

I also found that if I execute a piece of javescript code during a web page is loading, in order to change the style of scrollbar, sometime my self-defined scrollbar can be loaded, sometime not.

I have another question, how do I initialize the value of user_style_sheet_location in CefBrowserSettings, I initialized like this:
browserDefaults.user_style_sheet_location.str = new TCHAR[MAX_PATH] ;
_tcscpy(browserSettings.user_style_sheet_location.str, file:///H://20110411//cef_binary_r181_VS2005-VS2008//build//Release//scrollbar_style.css) ;
But it does not work.

Thanks!!
shenhui
Techie
 
Posts: 31
Joined: Sat Apr 16, 2011 10:50 pm

Re: How to change the style of scrollbar?

Postby custa1200 » Sun Apr 17, 2011 11:43 pm

We have used the Webkit CSS classes for scollbars perfectly with CEF.
custa1200
Techie
 
Posts: 32
Joined: Wed Oct 27, 2010 2:34 am

Re: How to change the style of scrollbar?

Postby shenhui » Mon Apr 18, 2011 12:28 am

Hello custa1200,

Could you please provide more detailed info about how to set scrollbar style?
shenhui
Techie
 
Posts: 31
Joined: Sat Apr 16, 2011 10:50 pm

Re: How to change the style of scrollbar?

Postby cagret » Mon Apr 18, 2011 7:47 am

User avatar
cagret
Techie
 
Posts: 41
Joined: Fri Mar 11, 2011 11:42 am
Location: Poland

Re: How to change the style of scrollbar?

Postby shenhui » Mon Apr 18, 2011 10:12 am

Hi cagret,

I have ever seen this article before and I know how to write my own style scrollbar code, what I care about is how to insert the style in CEF.

Thanks.
shenhui
Techie
 
Posts: 31
Joined: Sat Apr 16, 2011 10:50 pm

Re: How to change the style of scrollbar?

Postby cagret » Sun Jun 05, 2011 6:54 pm

I have the same problem as shenhui, can't set user stylesheet for web pages.

Code: Select all
browserDefaults.user_style_sheet_enabled = true;
CefString(&browserDefaults.user_style_sheet_location).FromASCII("file://D:/.../proto3/shared.css");
browserDefaults.universal_access_from_file_urls_allowed = true;
browserDefaults.file_access_from_file_urls_allowed = true;


I even set "universal_access_from_file_urls_allowed" and "file_access_from_file_urls_allowed" but it doesn't help.
Setting the path to "D:/.../proto3/shared.css" (no file://) also doesn't help.
The file exists - 100% tested.
The styles in CSS also work - 100% tested.
User avatar
cagret
Techie
 
Posts: 41
Joined: Fri Mar 11, 2011 11:42 am
Location: Poland

Next

Return to CEF Discussion

Who is online

Users browsing this forum: No registered users and 33 guests