Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Setting default stylesheets

2 views
Skip to first unread message

Ben Hutchings

unread,
Oct 24, 2005, 9:01:33 AM10/24/05
to
It's not clear to me how to override the default stylesheet(s) when
embedding Mozilla. It appears that I can use
nsIPresShell::SetAgentStyleSheets to change them, but I don't see how
to load a CSS stylesheet and obtain the interface pointer I would pass
into this function. How should I do that?

--
Ben Hutchings
For every complex problem
there is a solution that is simple, neat, and wrong.

Boris Zbarsky

unread,
Oct 24, 2005, 2:36:14 PM10/24/05
to
Ben Hutchings wrote:
> It's not clear to me how to override the default stylesheet(s) when
> embedding Mozilla.

You can use nsIStyleSheetService to load additional style sheets. If you want
to modify the existing ones, and you're shipping your own gecko, you can always
just edit ua.css...

-Boris

Ben Hutchings

unread,
Oct 24, 2005, 5:58:22 PM10/24/05
to
Boris Zbarsky <bzba...@mit.edu> wrote:
> Ben Hutchings wrote:
>> It's not clear to me how to override the default stylesheet(s) when
>> embedding Mozilla.
>
> You can use nsIStyleSheetService to load additional style sheets.

Oddly I can only find an IDL file for that, not a header file (LXR
denies all knowledge of the identifier). Should I attempt to generate
a header file, and how should I find a/the implementation of it at
run-time?

> If you want to modify the existing ones, and you're shipping your
> own gecko, you can always just edit ua.css...

I was hoping to get away with using an existing installation, at
least in my current environment (Debian).

Ben.

Boris Zbarsky

unread,
Oct 24, 2005, 6:20:06 PM10/24/05
to
Ben Hutchings wrote:
> Oddly I can only find an IDL file for that, not a header file

The nsIStyleSheetService.h header is generated via xpidl.

> (LXR denies all knowledge of the identifier).

Yeah, lxr kinda sucks like that.

> Should I attempt to generate
> a header file, and how should I find a/the implementation of it at
> run-time?

getService() the "@mozilla.org/content/style-sheet-service;1" contract.

-Boris

Ben Hutchings

unread,
Oct 24, 2005, 9:41:03 PM10/24/05
to
Boris, you've been very helpful, but I'm afraid I have more questions
for you.

Boris Zbarsky <bzba...@mit.edu> wrote:
> Ben Hutchings wrote:
>> Oddly I can only find an IDL file for that, not a header file
>
> The nsIStyleSheetService.h header is generated via xpidl.

I figured it was something like that, but didn't know what the tool
was - I've used COM previously but not XPCOM. Is it a frozen
interface? If not, do you have any suggestions for how to find the
relevant version of the interface definition? Debian's mozilla-dev
package doesn't include the IDL file. Could this be considered a
packaging bug?

>> (LXR denies all knowledge of the identifier).
>
> Yeah, lxr kinda sucks like that.

Can it not parse IDL files?

>> Should I attempt to generate
>> a header file, and how should I find a/the implementation of it at
>> run-time?
>
> getService() the "@mozilla.org/content/style-sheet-service;1" contract.

Great. Thanks.

Boris Zbarsky

unread,
Oct 24, 2005, 10:33:47 PM10/24/05
to
Ben Hutchings wrote:
> I figured it was something like that, but didn't know what the tool
> was - I've used COM previously but not XPCOM. Is it a frozen
> interface?

Not yet, no.

> Debian's mozilla-dev
> package doesn't include the IDL file. Could this be considered a
> packaging bug?

Hmm... Which version are they packaging? This interface did not exist in the
1.7 version of Gecko.

If you're working against 1.7, then things are harder. You may have to go back
to that nsIPresShell business.

>> Yeah, lxr kinda sucks like that.
>
> Can it not parse IDL files?

It can, and does. But it has a tendency to sometimes miss identifiers, in both
IDL and C++...

-Boris

Ben Hutchings

unread,
Oct 25, 2005, 7:51:54 AM10/25/05
to
Boris Zbarsky <bzba...@mit.edu> wrote:
> Ben Hutchings wrote:
<snip>

>> Debian's mozilla-dev
>> package doesn't include the IDL file. Could this be considered a
>> packaging bug?
>
> Hmm... Which version are they packaging? This interface did not exist in the
> 1.7 version of Gecko.
>
> If you're working against 1.7, then things are harder. You may have to go back
> to that nsIPresShell business.
<snip>

It's 1.7.8.

Ben.

--
Ben Hutchings
friends: People who know you well, but like you anyway.

Boris Zbarsky

unread,
Oct 25, 2005, 10:35:59 AM10/25/05
to
Ben Hutchings wrote:
> It's 1.7.8.

OK. Then there is no really clean way to do it... You can try creating a
CSSLoader (nsICSSLoader.h) and using it to load sheets, then using
SetAgentStyleSheets() on the presshell, I guess.

-Boris

Ben Hutchings

unread,
Oct 25, 2005, 10:25:53 PM10/25/05
to

That works for me, though it took me a while to work out that some of
my rules were being overridden by the default "preferences". I'm now
also calling EnablePrefStyleRules(false) to avoid this.

Something I don't understand is that I apparently have to do this for
each page. How do Seamonkey and Firefox set stylesheets to be applied
to all pages, and can I do the same?

Boris Zbarsky

unread,
Oct 26, 2005, 12:41:03 AM10/26/05
to
Ben Hutchings wrote:
> Something I don't understand is that I apparently have to do this for
> each page. How do Seamonkey and Firefox set stylesheets to be applied
> to all pages

There are hardcoded URIs to the sheets in the C++.

> and can I do the same?

Yes, if you change the C++ involved...

In 1.8-based builds, the stylesheet service does that work for you, but with
1.7, you have to do it for each page. :(

-Boris

Ben Hutchings

unread,
Oct 27, 2005, 5:29:35 AM10/27/05
to

I'll carry on doing that for now, then. Thanks; you've been very
helpful.

I don't suppose you can help with my other query about link extents?

--
Ben Hutchings
Never put off till tomorrow what you can avoid all together.

Boris Zbarsky

unread,
Oct 27, 2005, 10:09:18 AM10/27/05
to
Ben Hutchings wrote:
> I don't suppose you can help with my other query about link extents?

I'm not sure I saw this query.

-Boris

Ben Hutchings

unread,
Oct 27, 2005, 12:26:53 PM10/27/05
to

Then I'll post it again:

I'm working on an application that uses Mozilla to render pages for
inclusion on a DVD. DVDs can only include MPEG video and overlaid
bitmaps (subpictures) with a limited palette. So I convert the page
into an MPEG video, set each link into its hover and active states and
copy the changes in appearance into a subpicture. (I assume that
state changes don't cause reflow, though I know it isn't guaranteed.)

Currently I'm using nsIDOMNSDocument::GetBoxObjectFor to find the
extents of each link before scanning for changes, but this doesn't
always provide the correct extents for my purposes. In particular,
the extents for links that contain images appear to be limited to the
height of a line of a text. Is there a better way to do this, or
should I look for changes across the whole window?

Boris Zbarsky

unread,
Oct 27, 2005, 1:01:51 PM10/27/05
to
Ben Hutchings wrote:
> Currently I'm using nsIDOMNSDocument::GetBoxObjectFor to find the
> extents of each link before scanning for changes, but this doesn't
> always provide the correct extents for my purposes.

What do you mean by "extents of each link", exactly? Given positioned content,
etc, a state change on the link can affect arbitrary bits in the final rendered
bitmap.

-Boris

Ben Hutchings

unread,
Oct 27, 2005, 2:00:35 PM10/27/05
to

The extents of the content of the link. If the change of link state
causes the link content to change position or size, I would consider
that an error (and report it, if I can detect it).

Boris Zbarsky

unread,
Oct 27, 2005, 2:30:21 PM10/27/05
to
Ben Hutchings wrote:
> The extents of the content of the link.

You mean the smallest rectangle that contains all the layout objects
corresponding to descendants of the link DOM node in the DOM?

You can get that by getting the rectangles for all those nodes and taking the
minimal bounding rectangle... There's no one-stop place for this information.

Note, however, that change of state on a link can also affect rendering of the
link's siblings in the DOM, what with the CSS '+' and '~' combinators.

-Boris

Ben Hutchings

unread,
Oct 27, 2005, 10:40:30 PM10/27/05
to
On 2005-10-27, Boris Zbarsky <bzba...@mit.edu> wrote:
> Ben Hutchings wrote:
>> The extents of the content of the link.
>
> You mean the smallest rectangle that contains all the layout objects
> corresponding to descendants of the link DOM node in the DOM?

I suppose so, yes.

> You can get that by getting the rectangles for all those nodes and taking the
> minimal bounding rectangle... There's no one-stop place for this information.

OK, I can manage that.

> Note, however, that change of state on a link can also affect rendering of the
> link's siblings in the DOM, what with the CSS '+' and '~' combinators.

I realise there are things like this that I won't catch, but I think I
can live with documenting those as limitations. The idea is simply to
let people use a familiar format and tools, not to support arbitrary
existing web pages. For example, pages will have to fit on the screen
rather than being scrollable, and if I'm not mistaken there will be a
limit of 36 links per page.

Boris Zbarsky

unread,
Oct 27, 2005, 11:25:39 PM10/27/05
to
Ben Hutchings wrote:
> The idea is simply to let people use a familiar format and tools, not to support arbitrary
> existing web pages.

Ah, ok. That makes life simpler. ;)

-Boris

0 new messages