Fix for bugs 9000 and 10606. Add code to suppress painting when
authorhyatt <hyatt@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 30 Aug 2006 21:46:29 +0000 (21:46 +0000)
committerhyatt <hyatt@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 30 Aug 2006 21:46:29 +0000 (21:46 +0000)
        a FOUC situation would otherwise occur.  There will still typically be
        a flash to white, but at least the wrong content won't show.

        Reviewed by darin

        * dom/Document.cpp:
        (WebCore::Document::Document):
        (WebCore::Document::updateLayoutIgnorePendingStylesheets):
        (WebCore::Document::preferredStylesheetSet):
        (WebCore::Document::selectedStylesheetSet):
        (WebCore::Document::setSelectedStylesheetSet):
        (WebCore::Document::stylesheetLoaded):
        (WebCore::Document::updateStyleSelector):
        * dom/Document.h:
        (WebCore::Document::haveStylesheetsLoaded):
        * rendering/RenderBlock.cpp:
        (WebCore::RenderBlock::paintChildren):
        * rendering/RenderLayer.cpp:
        (WebCore::RenderLayer::paintLayer):
        (WebCore::isSubframe):
        (WebCore::RenderLayer::hitTest):
        * rendering/RenderView.cpp:
        (WebCore::RenderView::repaintViewRectangle):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@16129 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebCore/ChangeLog
WebCore/dom/Document.cpp
WebCore/dom/Document.h
WebCore/rendering/RenderBlock.cpp
WebCore/rendering/RenderLayer.cpp
WebCore/rendering/RenderView.cpp

index c4130944f7ab1ddd205e4486d1a5b69383a2ecb2..14c4cc6092782dc30fa4560206c6a1f3da6c54a1 100644 (file)
@@ -1,3 +1,30 @@
+2006-08-30  David Hyatt  <hyatt@apple.com>
+
+        Fix for bugs 9000 and 10606.  Add code to suppress painting when
+        a FOUC situation would otherwise occur.  There will still typically be
+        a flash to white, but at least the wrong content won't show.
+
+        Reviewed by darin
+
+        * dom/Document.cpp:
+        (WebCore::Document::Document):
+        (WebCore::Document::updateLayoutIgnorePendingStylesheets):
+        (WebCore::Document::preferredStylesheetSet):
+        (WebCore::Document::selectedStylesheetSet):
+        (WebCore::Document::setSelectedStylesheetSet):
+        (WebCore::Document::stylesheetLoaded):
+        (WebCore::Document::updateStyleSelector):
+        * dom/Document.h:
+        (WebCore::Document::haveStylesheetsLoaded):
+        * rendering/RenderBlock.cpp:
+        (WebCore::RenderBlock::paintChildren):
+        * rendering/RenderLayer.cpp:
+        (WebCore::RenderLayer::paintLayer):
+        (WebCore::isSubframe):
+        (WebCore::RenderLayer::hitTest):
+        * rendering/RenderView.cpp:
+        (WebCore::RenderView::repaintViewRectangle):
+
 2006-08-31  Nikolas Zimmermann  <zimmermann@kde.org>
  
          Reviewed by Eric. Landed by rwlbuis.
index 88ea6592c35ee2915ed523e2f3ab47082ea2149c..e8865f8c98e8ae102c5331cb6160f6514bdeb7d2 100644 (file)
@@ -265,6 +265,7 @@ Document::Document(DOMImplementation* impl, FrameView *v)
     m_styleSelector = new CSSStyleSelector(this, m_usersheet, m_styleSheets.get(), !inCompatMode());
     m_pendingStylesheets = 0;
     m_ignorePendingStylesheets = false;
+    m_didLayoutWithPendingStylesheets = false;
 
     m_cssTarget = 0;
 
@@ -929,6 +930,7 @@ void Document::updateLayoutIgnorePendingStylesheets()
     
     if (!haveStylesheetsLoaded()) {
         m_ignorePendingStylesheets = true;
+        m_didLayoutWithPendingStylesheets = true;
         updateStyleSelector();    
     }
 
@@ -1735,36 +1737,36 @@ StyleSheetList* Document::styleSheets()
 
 String Document::preferredStylesheetSet() const
 {
-  return m_preferredStylesheetSet;
+    return m_preferredStylesheetSet;
 }
 
 String Document::selectedStylesheetSet() const
 {
-  return m_selectedStylesheetSet;
+    return m_selectedStylesheetSet;
 }
 
 void Document::setSelectedStylesheetSet(const String& aString)
 {
-  m_selectedStylesheetSet = aString;
-  updateStyleSelector();
-  if (renderer())
-    renderer()->repaint();
+    m_selectedStylesheetSet = aString;
+    updateStyleSelector();
+    if (renderer())
+        renderer()->repaint();
 }
 
 // This method is called whenever a top-level stylesheet has finished loading.
 void Document::stylesheetLoaded()
 {
-  // Make sure we knew this sheet was pending, and that our count isn't out of sync.
-  assert(m_pendingStylesheets > 0);
+    // Make sure we knew this sheet was pending, and that our count isn't out of sync.
+    assert(m_pendingStylesheets > 0);
 
-  m_pendingStylesheets--;
-  
+    m_pendingStylesheets--;
+    
 #ifdef INSTRUMENT_LAYOUT_SCHEDULING
-  if (!ownerElement())
-      printf("Stylesheet loaded at time %d. %d stylesheets still remain.\n", elapsedTime(), m_pendingStylesheets);
+    if (!ownerElement())
+        printf("Stylesheet loaded at time %d. %d stylesheets still remain.\n", elapsedTime(), m_pendingStylesheets);
 #endif
 
-  updateStyleSelector();    
+    updateStyleSelector();    
 }
 
 void Document::updateStyleSelector()
@@ -1773,6 +1775,12 @@ void Document::updateStyleSelector()
     if (!haveStylesheetsLoaded())
         return;
 
+    if (m_didLayoutWithPendingStylesheets) {
+        m_didLayoutWithPendingStylesheets = false;
+        if (renderer())
+            renderer()->repaint();
+    }
+
 #ifdef INSTRUMENT_LAYOUT_SCHEDULING
     if (!ownerElement())
         printf("Beginning update of style selector at time %d.\n", elapsedTime());
index 74f4ca315433e1b641b50d173e456da34868e936..9adced8871217e480e02b3cb901858a8a6f12949 100644 (file)
@@ -240,7 +240,7 @@ public:
      * This method returns true if all top-level stylesheets have loaded (including
      * any @imports that they may be loading).
      */
-    bool haveStylesheetsLoaded() const { return m_pendingStylesheets <= 0 || m_ignorePendingStylesheets; }
+    bool haveStylesheetsLoaded(bool checkIgnoreFlag = true) const { return m_pendingStylesheets <= 0 || (checkIgnoreFlag && m_ignorePendingStylesheets); }
 
     /**
      * Increments the number of pending sheets.  The <link> elements
@@ -625,6 +625,11 @@ protected:
     // force an immediate layout when requested by JS.
     bool m_ignorePendingStylesheets;
 
+    // If we do ignore the pending stylesheet count, then we need to add a boolean
+    // to track that this happened so that we can do a full repaint when the stylesheets
+    // do eventually load.
+    bool m_didLayoutWithPendingStylesheets;
+
     RefPtr<CSSStyleSheet> m_elemSheet;
 
     bool m_printing;
index ef46b24832c8c895df88dcdfc338f3b9db1b34f1..377b729e08865be4167a479ab4030239fcf7e831 100644 (file)
@@ -1255,6 +1255,12 @@ void RenderBlock::paint(PaintInfo& i, int _tx, int _ty)
 
 void RenderBlock::paintChildren(PaintInfo& i, int _tx, int _ty)
 {
+    // Avoid painting descendants of the root element when stylesheets haven't loaded.  This eliminates FOUC.
+    // It's ok not to draw, because later on, when all the stylesheets do load, updateStyleSelector on the Document
+    // will do a full repaint().
+    if (!document()->haveStylesheetsLoaded(false))
+        return;
+    
     PaintPhase newPhase = (i.phase == PaintPhaseChildOutlines) ? PaintPhaseOutline : i.phase;
     newPhase = (newPhase == PaintPhaseChildBlockBackgrounds) ? PaintPhaseChildBlockBackground : newPhase;
     
index 5ba819f8effc49f1ba4aae1e248a41b7571802f4..33c730e153815484f9bc32bbba985f089dcc64ee 100644 (file)
@@ -1270,6 +1270,12 @@ RenderLayer::paintLayer(RenderLayer* rootLayer, GraphicsContext* p,
                         const IntRect& paintDirtyRect, bool haveTransparency, PaintRestriction paintRestriction,
                         RenderObject *paintingRoot)
 {
+    // Avoid painting layers when stylesheets haven't loaded.  This eliminates FOUC.
+    // It's ok not to draw, because later on, when all the stylesheets do load, updateStyleSelector on the Document
+    // will do a full repaint().
+    if (!renderer()->document()->haveStylesheetsLoaded(false) && !renderer()->isRenderView() && !renderer()->isRoot())
+        return;
+    
     // Calculate the clip rects we should use.
     IntRect layerBounds, damageRect, clipRectToApply, outlineRect;
     calculateRects(rootLayer, paintDirtyRect, layerBounds, damageRect, clipRectToApply, outlineRect);
@@ -1282,7 +1288,7 @@ RenderLayer::paintLayer(RenderLayer* rootLayer, GraphicsContext* p,
     updateZOrderLists();
     updateOverflowList();
 
-    // If this layer is totally invisible, then return as there is nothing to paint
+    // If this layer is totally invisible then there is nothing to paint.
     if (!m_object->opacity())
         return;
         
@@ -1381,7 +1387,7 @@ RenderLayer::paintLayer(RenderLayer* rootLayer, GraphicsContext* p,
     }
 }
 
-static inline bool isSubframeCanvas(RenderObject* renderer)
+static inline bool isSubframe(RenderObject* renderer)
 {
     return renderer->isRenderView() && renderer->node()->document()->frame()->tree()->parent();
 }
@@ -1399,7 +1405,7 @@ RenderLayer::hitTest(RenderObject::NodeInfo& info, const IntPoint& point)
     renderer()->document()->updateLayout();
     
     IntRect boundsRect(m_x, m_y, width(), height());
-    if (isSubframeCanvas(renderer()))
+    if (isSubframe(renderer()))
         boundsRect.intersect(frameVisibleRect(renderer()));
 
     RenderLayer* insideLayer = hitTestLayer(this, info, point, boundsRect);
index a9ff06cee04520e97fec2442ecbad25e194f58fa..8b080f1964a42f8c76c423810c352a7adf70bac2 100644 (file)
@@ -213,7 +213,8 @@ void RenderView::paintBoxDecorations(PaintInfo& i, int _tx, int _ty)
 
 void RenderView::repaintViewRectangle(const IntRect& ur, bool immediate)
 {
-    if (m_printingMode || ur.width() == 0 || ur.height() == 0) return;
+    if (m_printingMode || ur.width() == 0 || ur.height() == 0)
+        return;
     
     IntRect vr = viewRect();
     if (m_frameView && ur.intersects(vr)) {