safari patch splitup: fix FOUC problems
Alexander Kellett
lypanov at kde.org
Thu Jan 9 15:31:39 GMT 2003
(patch five)
fix FOUC (flash of unstyled content) problems
depends on not yet posted xml/ stylesheet changes
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/)
-------------- next part --------------
Index: html_baseimpl.cpp
===================================================================
RCS file: /home/kde/kdelibs/khtml/html/html_baseimpl.cpp,v
retrieving revision 1.174
diff -u -p -B -w -r1.174 html_baseimpl.cpp
--- html_baseimpl.cpp 9 Jan 2003 14:25:00 -0000 1.174
+++ html_baseimpl.cpp 9 Jan 2003 15:31:32 -0000
@@ -297,7 +297,6 @@ void HTMLFrameElementImpl::attach()
{
assert(!attached());
assert(parentNode());
- assert(parentNode()->renderer());
// we should first look up via id, then via name.
// this shortterm hack fixes the ugly case. ### rewrite needed for next release
@@ -322,7 +321,7 @@ void HTMLFrameElementImpl::attach()
// ignore display: none for this element!
KHTMLView* w = getDocument()->view();
- if (isURLAllowed()) {
+ if (isURLAllowed() && parentNode()->renderer()) {
m_render = new RenderFrame(this);
m_render->setStyle(getDocument()->styleSelector()->styleForElement(this));
parentNode()->renderer()->addChild(m_render, nextRenderer());
@@ -369,12 +368,14 @@ void HTMLFrameElementImpl::setFocus(bool
DocumentImpl* HTMLFrameElementImpl::contentDocument() const
{
- if ( !m_render ) return 0;
-
- RenderPart* render = static_cast<RenderPart*>( m_render );
+ KHTMLView* w = getDocument()->view();
- if(render->widget() && render->widget()->inherits("KHTMLView"))
- return static_cast<KHTMLView*>( render->widget() )->part()->xmlDocImpl();
+ if (w) {
+ KHTMLPart *part = w->part()->findFrame( name.string() );
+ if (part) {
+ return part->xmlDocImpl();
+ }
+ }
return 0;
}
@@ -476,10 +477,16 @@ void HTMLFrameSetElementImpl::attach()
node = static_cast<HTMLElementImpl*>(node->parentNode());
}
- // ignore display: none
+ // ignore display: none but do pay attention if a stylesheet has caused us to delay
+ // our loading.
+ RenderStyle* style = getDocument()->styleSelector()->styleForElement(this);
+ style->ref();
+ if (style->isStyleAvailable()) {
m_render = new RenderFrameSet(this);
- m_render->setStyle(getDocument()->styleSelector()->styleForElement(this));
+ m_render->setStyle(style);
parentNode()->renderer()->addChild(m_render, nextRenderer());
+ }
+ style->deref();
NodeBaseImpl::attach();
}
Index: html_documentimpl.cpp
===================================================================
RCS file: /home/kde/kdelibs/khtml/html/html_documentimpl.cpp,v
retrieving revision 1.144
diff -u -p -B -w -r1.144 html_documentimpl.cpp
--- html_documentimpl.cpp 8 Jan 2003 18:16:56 -0000 1.144
+++ html_documentimpl.cpp 9 Jan 2003 15:31:32 -0000
@@ -303,6 +303,13 @@ void HTMLDocumentImpl::close()
getDocument()->dispatchWindowEvent(EventImpl::LOAD_EVENT, false, false);
updateRendering();
+
+ // Always do a layout/repaint after loading.
+ if (renderer()) {
+ if (!renderer()->layouted())
+ renderer()->layout();
+ renderer()->repaint();
+ }
}
}
Index: html_formimpl.cpp
===================================================================
RCS file: /home/kde/kdelibs/khtml/html/html_formimpl.cpp,v
retrieving revision 1.307
diff -u -p -B -w -r1.307 html_formimpl.cpp
--- html_formimpl.cpp 7 Jan 2003 17:12:09 -0000 1.307
+++ html_formimpl.cpp 9 Jan 2003 15:31:32 -0000
@@ -583,10 +583,16 @@ void HTMLGenericFormElementImpl::attach(
if (m_render) {
assert(m_render->style());
parentNode()->renderer()->addChild(m_render, nextRenderer());
- m_render->updateFromElement();
}
NodeBaseImpl::attach();
+
+ // The call to updateFromElement() needs to go after the call through
+ // to the base class's attach() because that can sometimes do a close
+ // on the renderer.
+ if (m_render)
+ m_render->updateFromElement();
+
}
HTMLFormElementImpl *HTMLGenericFormElementImpl::getForm() const
Index: html_headimpl.cpp
===================================================================
RCS file: /home/kde/kdelibs/khtml/html/html_headimpl.cpp,v
retrieving revision 1.95
diff -u -p -B -w -r1.95 html_headimpl.cpp
--- html_headimpl.cpp 9 Dec 2002 07:21:44 -0000 1.95
+++ html_headimpl.cpp 9 Jan 2003 15:31:32 -0000
@@ -158,6 +158,13 @@ void HTMLLinkElementImpl::process()
// ### there may be in some situations e.g. for an editor or script to manipulate
if( m_media.isNull() || m_media.contains("screen") || m_media.contains("all") || m_media.contains("print") ) {
m_loading = true;
+
+ // Add ourselves as a pending sheet, but only if we aren't an alternate
+ // stylesheet. Alternate stylesheets don't hold up render tree construction.
+ m_alternate = rel.contains("alternate");
+ if (!isAlternate())
+ getDocument()->addPendingSheet();
+
QString chset = getAttribute( ATTR_CHARSET ).string();
if (m_cachedSheet)
m_cachedSheet->deref(this);
@@ -203,7 +210,9 @@ void HTMLLinkElementImpl::setStyleSheet(
m_loading = false;
- getDocument()->updateStyleSelector();
+ // Tell the doc about the sheet.
+ if (!isLoading() && m_sheet && !isAlternate())
+ getDocument()->stylesheetLoaded();
}
bool HTMLLinkElementImpl::isLoading() const
@@ -217,7 +226,8 @@ bool HTMLLinkElementImpl::isLoading() co
void HTMLLinkElementImpl::sheetLoaded()
{
- getDocument()->updateStyleSelector();
+ if (!isLoading() && !isAlternate())
+ getDocument()->stylesheetLoaded();
}
// -------------------------------------------------------------------------
@@ -315,12 +325,14 @@ void HTMLStyleElementImpl::parseAttribut
void HTMLStyleElementImpl::insertedIntoDocument()
{
HTMLElementImpl::insertedIntoDocument();
+ if (m_sheet)
getDocument()->updateStyleSelector();
}
void HTMLStyleElementImpl::removedFromDocument()
{
HTMLElementImpl::removedFromDocument();
+ if (m_sheet)
getDocument()->updateStyleSelector();
}
@@ -337,23 +349,36 @@ void HTMLStyleElementImpl::childrenChang
text += c->nodeValue();
}
- if(m_sheet)
+ if (m_sheet) {
m_sheet->deref();
+ m_sheet = 0;
+ }
+
+ m_loading = false;
+
+ getDocument()->addPendingSheet();
+ m_loading = true;
m_sheet = new CSSStyleSheetImpl(this);
m_sheet->ref();
m_sheet->parseString( text, (getDocument()->parseMode() == DocumentImpl::Strict) );
- getDocument()->updateStyleSelector();
+ m_loading = false;
+
+ if (!isLoading() && m_sheet)
+ getDocument()->stylesheetLoaded();
+
}
bool HTMLStyleElementImpl::isLoading() const
{
+ if(m_loading) return true;
if(!m_sheet) return false;
return static_cast<CSSStyleSheetImpl *>(m_sheet)->isLoading();
}
void HTMLStyleElementImpl::sheetLoaded()
{
- getDocument()->updateStyleSelector();
+ if (!isLoading())
+ getDocument()->stylesheetLoaded();
}
// -------------------------------------------------------------------------
Index: html_headimpl.h
===================================================================
RCS file: /home/kde/kdelibs/khtml/html/html_headimpl.h,v
retrieving revision 1.38
diff -u -p -B -w -r1.38 html_headimpl.h
--- html_headimpl.h 9 Dec 2002 07:21:44 -0000 1.38
+++ html_headimpl.h 9 Jan 2003 15:31:32 -0000
@@ -71,7 +71,7 @@ class HTMLLinkElementImpl : public khtml
{
public:
HTMLLinkElementImpl(DocumentPtr *doc)
- : HTMLElementImpl(doc), m_cachedSheet(0), m_sheet(0), m_loading(false) {}
+ : HTMLElementImpl(doc), m_cachedSheet(0), m_sheet(0), m_loading(false), m_alternate(false) {}
~HTMLLinkElementImpl();
@@ -92,6 +92,7 @@ public:
bool isLoading() const;
void sheetLoaded();
+ bool isAlternate() const { return m_alternate; }
protected:
khtml::CachedCSSStyleSheet *m_cachedSheet;
@@ -101,6 +102,8 @@ protected:
QString m_media;
DOMString m_rel;
bool m_loading;
+ bool m_alternate;
+
QString m_data; // needed for temporarily storing the loaded style sheet data
};
@@ -143,7 +146,7 @@ class HTMLStyleElementImpl : public HTML
{
public:
HTMLStyleElementImpl(DocumentPtr *doc)
- : HTMLElementImpl(doc), m_sheet(0) {}
+ : HTMLElementImpl(doc), m_sheet(0), m_loading(false) {}
~HTMLStyleElementImpl();
virtual Id id() const;
@@ -161,6 +164,7 @@ public:
protected:
StyleSheetImpl *m_sheet;
+ bool m_loading;
};
// -------------------------------------------------------------------------
Index: html_inlineimpl.cpp
===================================================================
RCS file: /home/kde/kdelibs/khtml/html/html_inlineimpl.cpp,v
retrieving revision 1.116
diff -u -p -B -w -r1.116 html_inlineimpl.cpp
--- html_inlineimpl.cpp 9 Jan 2003 06:16:58 -0000 1.116
+++ html_inlineimpl.cpp 9 Jan 2003 15:31:32 -0000
@@ -196,11 +196,18 @@ void HTMLBRElementImpl::attach()
assert(!m_render);
assert(parentNode());
- if (parentNode()->renderer()) {
+ RenderObject *parentRenderer = parentNode()->renderer();
+ if (parentRenderer) {
+ RenderStyle *style = getDocument()->styleSelector()->styleForElement(this);
+ style->ref();
+ if (style->display() != NONE) {
m_render = new RenderBR(this);
- m_render->setStyle(getDocument()->styleSelector()->styleForElement(this));
- parentNode()->renderer()->addChild(m_render, nextRenderer());
+ m_render->setStyle(style);
+ parentRenderer->addChild(m_render, nextRenderer());
}
+ style->deref();
+ }
+
NodeImpl::attach();
}
Index: html_objectimpl.cpp
===================================================================
RCS file: /home/kde/kdelibs/khtml/html/html_objectimpl.cpp,v
retrieving revision 1.95
diff -u -p -B -w -r1.95 html_objectimpl.cpp
--- html_objectimpl.cpp 23 Oct 2002 17:03:31 -0000 1.95
+++ html_objectimpl.cpp 9 Jan 2003 15:31:32 -0000
@@ -421,12 +421,13 @@ void HTMLObjectElementImpl::attach()
NodeBaseImpl::attach();
// ### do this when we are actually finished loading instead
+ if (m_render)
dispatchHTMLEvent(EventImpl::LOAD_EVENT,false,false);
}
void HTMLObjectElementImpl::detach()
{
- if (attached())
+ if (attached() && m_render)
// ### do this when we are actualy removed from document instead
dispatchHTMLEvent(EventImpl::UNLOAD_EVENT,false,false);
More information about the kfm-devel
mailing list