Closed Bug 125710 Opened 24 years ago Closed 24 years ago

Can't dynamically create stylesheets (style, text/css, createCSSstyleSheet)

Categories

(Core :: DOM: Core & HTML, defect, P3)

defect

Tracking

()

VERIFIED FIXED
mozilla1.0.1

People

(Reporter: robert, Assigned: peterv)

References

Details

(Keywords: helpwanted, Whiteboard: DIGBug)

Attachments

(1 file)

Build 2002020406 Dynamic creation of style sheets doesn't seem to work. I've been trying to to do this with no success. The W3C spec specifies two ways of doing this, neither of which work: 1.) Sect. 2.2.2 of http://www.w3.org/TR/2000/REC-DOM-Level-2-Style-20001113/css.html talks about the createCSSStyleSheet() method, but this doesn't appear to be implemented in Mozilla. 2.) Sect. 1.4 of http://www.w3.org/TR/2000/REC-DOM-Level-2-Style-20001113/stylesheets.html#StyleSheets-Association says explicitely that style sheets can be created by creating a STYLE element and setting it's type to 'text/css'. There is an existing bug about method #1 (http://bugzilla.mozilla.org/show_bug.cgi?id=63850) that, correctly, makes the point that there is no spec'ed way of attaching the sheet to a document. However, method #2 *should* work. I've attached a test case that tries this approach, but no matter what I do, the 'sheet' property of the element is always null. The test case writes out the properties of a static STYLE element (which I can add rules to) and the dynamic element (which I can't because of the missing sheet), and everything looks pretty good between the two, except for the null 'sheet' property. The workaround is to create an empty STYLE block in your HTML and just use that to insertRule()'s into. (There are cases where this may not work for us here at DIG, but I'll discuss prioritization of this offline with bcleary). §
Whiteboard: DIGBug
I've been poking at this code.... We'd ideally like to create the sheet at inserting-into-document time as the spec says. At that point we'd just take an empty string, parse it into stylesheet data, and Unfortunately, we insert normal <style> elements into the doc _before_ parsing their contents. Even worse, if the <style> element has a title (hence the sheet is alternate) the stylesheet parsing/creation is asynchronous with the parsing of the HTML document... So we can't just "parse first, insert later". The issue is confused by the fact that we seem to support either <style href="..."> or <style src="..."> or some mix depending on how you read the comments and the code.... Do we _ever_ have <style> elements loading non-inline sheets?? Peterv? Any ideas? You did this dynamic stuff for <link>, right?
OS: Windows 2000 → All
Hardware: PC → All
Another thought.... We could add a method on nsIStyleSheetLinkingElement that will basically say "data coming up". Then the content sink will call that method before appending to the doc. If said method has been called the <style> element will hold off on creating an inline sheet because the CSSLoader is handling it. If the method has not been called, the element will create the sheet upon being appended to the document. That seem reasonable?
OK. More investigation shows: 1) we call SetEnableUpdates(FALSE) in the content sink. So in fact updating dynamically in SetDocument or SetType is OK. 2) The content sink increments mStyleSheetCount twice per inline sheet. This seems wrong, but correct me now if I'm missing something. 3) The best solution seems to be to make nsStyleLinkElement::UpdateStyleSheet aware of inline stylesheets and then move the inline sheet stuff out of the content sink and into UpdateStyleSheet.
Boris, there's already a patch to fix this in bug 34849, I believe.
Fabian, nice catch! Boris, how does your analysis reflect the state of bug 34849? Should we just dupe against that bug? If so, please carry over the DIGBug status.
well, the patch in bug 34839 would fix this. :) Dupping to that one. *** This bug has been marked as a duplicate of 34849 ***
Status: NEW → RESOLVED
Closed: 24 years ago
Resolution: --- → DUPLICATE
Re-opening and marking as dependent on bug 34849. This is not quite a duplicate. It addresses a DOM spec issue that's not discussed in bug 34849 - namely that adding a style sheet element (and, specifically, setting the type to 'text/css') is a recommended way of adding style sheets to a document. Given that the fix for 34849 should fix this, it might make sense to assign it to glazman@netscape.com (but I don't seem to have permission to do that).
Status: RESOLVED → REOPENED
Depends on: 34849
Resolution: DUPLICATE → ---
bz's favourite subject, reassigning! :-) bz, feel free to hand this back to me if you don't want it.
Assignee: jst → bzbarsky
Status: REOPENED → NEW
I'll take this. :) I'm gonna try to make glazou fix this as part of 34849; if that fails at least he's making the arch changes that should make this an easy fix. :)
Status: NEW → ASSIGNED
Priority: -- → P3
Target Milestone: --- → mozilla1.0
nominating nsbeta1 . Turns out this is asked for by developers to our feedback alias.
Keywords: nsbeta1
I'm going out of town in two days and not getting back till after 1.0 freeze. Setting realistic milestones for all 1.0 bugs that depend on other bugs or on possible interface work. Any help on getting these fixed would be much appreciated...
Keywords: helpwanted
Target Milestone: mozilla1.0 → mozilla1.1alpha
This will be fixed by my upcoming patch for bug 34849 (I just tried it and the testcase works in my tree).
Assignee: bzbarsky → peterv
Status: ASSIGNED → NEW
As a note, please test the same script but with inserting the <style> element into the document first, _then_ setting the type attr.
adding to cc list
There is one milestone before 1.1alpha, let's try to get this in 1.0.1
Target Milestone: mozilla1.1alpha → mozilla1.0.1
i think this is important for MachV and according to comment 13, if the patch for bug 34849 will fix this, i think this should be a nsbeta1+
Fixed by patch for bug 34849.
Status: NEW → RESOLVED
Closed: 24 years ago → 24 years ago
Resolution: --- → FIXED
Verified on 2002-05-23-08-trunk.
Status: RESOLVED → VERIFIED
Component: DOM: HTML → DOM: Core & HTML
QA Contact: stummala → general
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: