XML Patch For FOUC
Alexander Kellett
lypanov@kde.org
Wed, 15 Jan 2003 10:21:59 +0100
hiya david!
quick question to cvs khtml people, why is parentNode()->renderer()
asserted in some attach() methods but not in others?, bugs?
the attached patch merges in the below dom_xmlimpl.cpp
changes (didn't have time to look into the <link> element logic)
and does a s/_style/style/ in html/html_baseimpl.cpp to make the
code slightly cleaner. adds some parentNode()->renderer() checks
and removes some asserts, and a few other things that i noticed
in the WebCore diffs. questions about those few things follow...
david, one thing i wondered was why HTMLFrameSetElementImpl::attach
uses isStyleAvailable rather than a parentNode()->renderer() like
most of the other code. problem is that i'm really unsure of
the "assert(parentNode()->renderer());" removal that i made.
i'll have time on sunday to get a grasp on the entire attach/addChild
situation in khtml, but before then i'm just looking through a
magnifying glass at the WebCore diff code sections only :)
one more thing, is the HTMLFrameElementImpl::contentDocument change
purely to remove the use of renderer() and thus to stop possible
crashes due to FOUC?
btw, current version of stylesheet support does have
alternate and disabled (not sure about title)
well, assuming that the html/html_headimpl.h (isDisabled for example)
changes that were merged by antti during the fouc merge?
i'm reallyl unsure as to whether these are all the changes
needed. for example i'm not sure that m_media and m_type
are being set at all in fact. i'll do some more checks on this.
thanks,
Alex
On Tue, Jan 14, 2003 at 04:58:39PM -0800, David Hyatt wrote:
> This patch makes FOUC work for XML PIs. I am making the assumption
> that you guys haven't added support for alternates, title, or disabled
> sheets yet in your version of XML (since 3.0.2). If you have, then
> this logic will have to be improved to more closely copy the code on
> the <link> element.
>
> Index: khtml/xml/dom_xmlimpl.cpp
> ===================================================================
> RCS file: /local/home/cvs/Labyrinth/WebCore/khtml/xml/dom_xmlimpl.cpp,v
> retrieving revision 1.2
> diff -u -r1.2 dom_xmlimpl.cpp
> --- dom_xmlimpl.cpp 2002/03/22 00:31:19 1.2
> +++ dom_xmlimpl.cpp 2003/01/15 00:21:21
> @@ -257,6 +257,7 @@
> m_localHref = 0;
> m_sheet = 0;
> m_cachedSheet = 0;
> + m_loading = false;
> }
>
> ProcessingInstructionImpl::ProcessingInstructionImpl(DocumentPtr *doc,
> DOMString _target, DOMString _data) : NodeBaseImpl(doc)
> @@ -378,6 +379,8 @@
> {
> // ### some validation on the URL?
> // ### FIXME charset
> + m_loading = true;
> + getDocument()->addPendingSheet();
> if (m_cachedSheet) m_cachedSheet->deref(this);
> m_cachedSheet =
> getDocument()->docLoader()->requestStyleSheet(getDocument()-
> >completeURL(href.string()), QString::null);
> if (m_cachedSheet)
> @@ -393,6 +396,19 @@
> return m_sheet;
> }
>
> +bool ProcessingInstructionImpl::isLoading() const
> +{
> + if(m_loading) return true;
> + if(!m_sheet) return false;
> + return static_cast<CSSStyleSheetImpl *>(m_sheet)->isLoading();
> +}
> +
> +void ProcessingInstructionImpl::sheetLoaded()
> +{
> + if (!isLoading())
> + getDocument()->stylesheetLoaded();
> +}
> +
> void ProcessingInstructionImpl::setStyleSheet(const DOM::DOMString
> &url, const DOM::DOMString &sheet)
> {
> if (m_sheet)
> @@ -403,8 +419,12 @@
> if (m_cachedSheet)
> m_cachedSheet->deref(this);
> m_cachedSheet = 0;
> +
> + m_loading = false;
>
> - getDocument()->updateStyleSelector();
> + // Tell the doc about the sheet.
> + if (!isLoading() && m_sheet)
> + getDocument()->stylesheetLoaded();
> }
>
> void ProcessingInstructionImpl::setStyleSheet(CSSStyleSheetImpl* sheet)
> Index: khtml/xml/dom_xmlimpl.h
> ===================================================================
> RCS file: /local/home/cvs/Labyrinth/WebCore/khtml/xml/dom_xmlimpl.h,v
> retrieving revision 1.5
> diff -u -r1.5 dom_xmlimpl.h
> --- dom_xmlimpl.h 2002/10/26 23:21:43 1.5
> +++ dom_xmlimpl.h 2003/01/15 00:21:21
> @@ -152,7 +152,9 @@
> void checkStyleSheet();
> virtual void setStyleSheet(const DOM::DOMString &url, const
> DOM::DOMString &sheet);
> virtual void setStyleSheet(CSSStyleSheetImpl* sheet);
> -
> + bool isLoading() const;
> + void sheetLoaded();
> +
> #if APPLE_CHANGES
> static ProcessingInstruction
> createInstance(ProcessingInstructionImpl *impl);
> #endif
> @@ -163,6 +165,7 @@
> DOMStringImpl *m_localHref;
> khtml::CachedCSSStyleSheet *m_cachedSheet;
> CSSStyleSheetImpl *m_sheet;
> + bool m_loading;
> };
>
> class XMLAttributeReader : public QXmlDefaultHandler
> Index: khtml/html/html_baseimpl.cpp
> ===================================================================
> RCS file:
> /local/home/cvs/Labyrinth/WebCore/khtml/html/html_baseimpl.cpp,v
> retrieving revision 1.20
> diff -u -r1.20 html_baseimpl.cpp
> --- html_baseimpl.cpp 2003/01/09 07:07:26 1.20
> +++ html_baseimpl.cpp 2003/01/15 00:21:21
> @@ -185,17 +185,18 @@
> {
> assert(!m_render);
> assert(parentNode());
> - assert(parentNode()->renderer());
> -
> - RenderStyle* style =
> getDocument()->styleSelector()->styleForElement(this);
> - style->ref();
> - if (style->display() != NONE) {
> - m_render = new (getDocument()->renderArena()) RenderBody(this);
> - m_render->setStyle(style);
> - parentNode()->renderer()->addChild(m_render, nextRenderer());
> +
> + if (parentNode()->renderer()) {
> + RenderStyle* style =
> getDocument()->styleSelector()->styleForElement(this);
> + style->ref();
> + if (style->display() != NONE) {
> + m_render = new (getDocument()->renderArena())
> RenderBody(this);
> + m_render->setStyle(style);
> + parentNode()->renderer()->addChild(m_render,
> nextRenderer());
> + }
> + style->deref();
> }
> - style->deref();
> -
> +
> NodeBaseImpl::attach();
> }
>
> _______________________________________________
> Khtml-devel@mail.kde.org
> http://mail.kde.org/mailman/listinfo/khtml-devel
>
mvg,
Alex
--
"[...] Konqueror open source project. Weighing in at less than
one tenth the size of another open source renderer"
Apple, Jan 2003 (http://www.apple.com/safari/)