Closed Bug 91450 Opened 23 years ago Closed 23 years ago

complete loss of style when executing a certain javascript

Categories

(Core :: DOM: CSS Object Model, defect, P2)

x86
Other
defect

Tracking

()

RESOLVED FIXED
mozilla0.9.4

People

(Reporter: wo, Assigned: peterv)

References

()

Details

(Keywords: regression, Whiteboard: [Hixie-P3])

Attachments

(1 file)

On http://www.umsu.de/tests/zdvlopmozbug.html, if you click the link "Element
Labels", all style rules for the entire document will be lost. This is what that
link does:

<a class="b" href="javascript:
function z7T0(par){
  for(var i=0; i<par.childNodes.length;	i++){
    var z=par.childNodes[i];
    if(z.nodeType!=1)continue;
    z.title='tagName: '+z.tagName+'\nid: '+(z.id || '[none]')
    +'\nparentNode: '+(z.parentNode.tagName || '[none]')
    +'\nchildren: '+z.childNodes.length;
    z7T0(z);
  }
};
z7T0(document.documentElement);
">

If I find some time I'll try to isolate that problem further.

Tested with NB 2001-07-18-03 and M0.91 on win98.
OK.  Here is the problem.  document.documentElement is <html>, not <body>.

So you end up resetting the "title" attribute of the <style> element.

Looks like we're deapplying the stylesheet when that happens, because which
stylesheet is applied depends on the title, of course. Thing is, title seems to
be only magical for <link> styles, not <style> styles.

setting status to NEW and over to style system to decide whether this is
actually a bug.

Wolfgang, if you getElementById to get the <style> element and change its title
in IE, does the style get lost?  Does document.documentElement return <html> or
<body> in IE?
Assignee: jst → pierre
Status: UNCONFIRMED → NEW
Component: DOM Style → Style System
Ever confirmed: true
document.documentElement is <html> in IE as well, but changing the <style>'s 
title does never affect the layout, no matter how I access it (tested with 
getElementById, getElementsByTagName and document...childNodes[...]).
This is a regression added by peterv on May 18 2001 while working on bug 7515.

When the <style>'s title is changed we call nsHTMLStyleElement::SetAttribute() 
and then nsStyleLinkElement::UpdateStyleSheet() which has for function to remove 
a stylesheet and load it all over again.  Problem: to reload the stylesheet, 
UpdateStyleSheet() needs an URL, which it doesn't have in this particular case 
because the styles comes from a <style> element, not from a linked stylesheet. It 
means that the <style> element's stylesheet is removed and nothing is re-
inserted: all the style disappears.

1) What kind of attributes can change on the <style> element?  Is there any that 
require an update of the stylesheet?  If so, nsHTMLStyleElement may need to 
implement its own version of UpdateStyleSheet() instead of reusing the one from 
nsStyleLinkElement.

2) In the case of a linked stylesheet, should all the attributes cause an update 
of the stylesheet?  Can't we do an update for just a small list of attributes?

Reassigned to DOM Style.
Assignee: pierre → jst
Component: Style System → DOM Style
Keywords: regression
> 1) What kind of attributes can change on the <style> element?

type, media, title

When the type is changed, we probably want to reload the stylesheet (in case it
is no longer CSS), right?  When media is changed do we need to reload the
stylesheet?  And for title changing we don't need to.

2) In the case of a linked stylesheet, should all the attributes cause an update 
of the stylesheet?

Well..  we need to update for title, href, type, and rel.  The other attributes
of a <LINK> element should not cause updates, being inapplicable to stylesheets.
reassigned to peterv, like bug 83981 which is also related to bug 7515
Assignee: jst → peterv
Depends on: 7515
my apologies: bug 83981 is a different problem
Mozilla should consider the title attribute of <style> elements to be equivalent
to the title attribute of <link> elements. (IE doesn't support this.)
Keywords: qawanted
Whiteboard: [Hixie-P3]
Attaching a patch. Internally, inline stylesheets have the document URL as their
URL, so we need to compare with that if the href is empty. I think the updating
of the stylesheets when any of the other attributes change should be filed as a
separate RFE.
Status: NEW → ASSIGNED
r=pierre
Priority: -- → P2
Target Milestone: --- → mozilla0.9.4
Documents don't always have base url's, you should check for a null base url and
ask for the document url if there's no base url. With that, sr=jst
Jst, but then the loader would use a null url, no? See
http://lxr.mozilla.org/seamonkey/source/content/html/style/src/nsCSSLoader.cpp#1288.
 I don't see how I could handle that at all.
Ignore my comments about documents not always having a base URI.
Checked in.
Status: ASSIGNED → RESOLVED
Closed: 23 years ago
Resolution: --- → FIXED
Keywords: qawanted
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: