kdelibs/khtml/html

Peter Kelly pmk at kde.org
Sat Aug 16 11:59:10 CEST 2003


After taking a closer look at this I'm not sure that we're handling 
alternate stylesheets the correct way.

>From what I understand from the HTML/DOM specs and experimenting with 
mozilla, it seems that the decision about whether or not to use a sheet 
should depend on whether or not it is enabled, rather than directly on 
it's title and whether or not it is alternate.

When a page gets loaded, a sheet can be in one of three states:

Persistent - <LINK REL="stylesheet"> with no TITLE attribute
Preferred - <LINK REL="stylesheet"> with TITLE attribute set
Alternate - <LINK REL="alternate stylesheet"> with TITLE attribute set

Persistent stylesheets are always displayed (which we do correctly). But 
when loading a page, mozilla sets the disabled property (of the link 
element) to false if the stylesheet is preferred (and is in the first 
group of preferred stylesheets), or true otherwise. It then decides 
which stylsheets to use based on the disabled property. If you set 
disabled to false on a link from javascript, it will then use the 
stylsheet. The "use stylesheet" menu is updated accordingly. Also, 
selecting a different sheet from the menu changes the disabled properties 
to reflect which ones are used.

KHTML treats the disabled property as meaning "this stylesheet _can_ be 
used" rather than "this stylesheet _is_ used". Thus, when you set disabled
to false on a sheet it becomes available for use but is not actually used 
until the user selects the sheet from the menu.

Have a look at the style switcher on zeldman.com. This uses the disabled 
property, but also works correctly with mozilla's "use style" menu.

I think the solution here is when a new sheet is selected from the "use 
stylesheet" menu, to change the disabled properties, and in 
DocumentImpl::recalcStylSelector() look at disabled instead of 
comparing the title against sheetUsed.

On Thu, 14 Aug 2003, Dirk Mueller wrote:

> On Don, 14 Aug 2003, Peter Kelly wrote:
> 
> > Could someone review this?
> 
> Hmpf. why do you commit it then?
> 
> Check the code in HTMLLinkElementImpl::process() :
> 
>          m_alternate = rel.contains("alternate");
>          if (!isAlternate())
>                getDocument()->addPendingSheet();
> 
> 
> > -            if (isLoading() && m_isDisabled && (!m_alternate || m_oldisDisabled))
> > +            if (isLoading() && m_isDisabled)
> >                  getDocument()->styleSheetLoaded();
> 
> 
> there is no point in notifying that a sheet was loaded when it was not 
> marked as pending in the first place. you're just hiding a refcount bug 
> elsewhere. 
> 
> 
> 

-- 
Peter Kelly
pmk at kde.org



More information about the Khtml-devel mailing list