patch: force layout (overriding FOUC protection) for layout-required properties

Maciej Stachowiak mjs at apple.com
Mon Nov 3 23:57:23 CET 2003


Here's the patch:

-------------- next part --------------
Index: ChangeLog
===================================================================
RCS file: /local/home/cvs/Labyrinth/WebCore/ChangeLog,v
retrieving revision 1.2143
diff -u -p -r1.2143 ChangeLog
--- ChangeLog	2003/10/29 06:31:11	1.2143
+++ ChangeLog	2003/10/29 07:20:10
@@ -1,3 +1,22 @@
+2003-10-28  Maciej Stachowiak  <mjs at apple.com>
+
+        Reviewed by Darin.
+
+	- fixed 3163842 - Citibank cardmember central DHTML menus not working right in Safari
+	
+        * khtml/ecma/kjs_html.cpp:
+        (KJS::HTMLElement::getValueProperty): update layout before fetching image properties
+	that need it.
+        * khtml/xml/dom_docimpl.cpp:
+        (DocumentImpl::DocumentImpl): Initialize m_ignorePendingStylesheets to false.
+        (DocumentImpl::updateLayout): Ignore pending stylesheets - when JS demands a
+	layout, it wants a real one now.
+        (DocumentImpl::updateStyleSelector): Go ahead with the update if we're ignoring
+	pending stylesheets.
+        * khtml/xml/dom_docimpl.h:
+        (DOM::DocumentImpl::haveStylesheetsLoaded): Pretend stylesheets have loaded if
+	we're temporarily ignoring pending stylesheets.
+
 2003-10-28  Darin Adler  <darin at apple.com>
 
         Reviewed by Maciej.
Index: khtml/ecma/kjs_html.cpp
===================================================================
RCS file: /local/home/cvs/Labyrinth/WebCore/khtml/ecma/kjs_html.cpp,v
retrieving revision 1.41
diff -u -p -r1.41 khtml/ecma/kjs_html.cpp
--- khtml/ecma/kjs_html.cpp	2003/10/14 15:36:10	1.41
+++ khtml/ecma/kjs_html.cpp	2003/10/29 07:20:15
@@ -1529,16 +1529,24 @@ Value KJS::HTMLElement::getValueProperty
     case ImageAlign:           return String(image.align());
     case ImageAlt:             return String(image.alt());
     case ImageBorder:          return Number(image.border());
-    case ImageHeight:          return Number(image.height());
     case ImageHspace:          return Number(image.hspace());
     case ImageIsMap:           return Boolean(image.isMap());
     case ImageLongDesc:        return String(image.longDesc());
     case ImageSrc:             return String(image.src());
     case ImageUseMap:          return String(image.useMap());
     case ImageVspace:          return Number(image.vspace());
-    case ImageWidth:           return Number(image.width());
-    case ImageX:               return Number(image.x());
-    case ImageY:               return Number(image.y());
+    default:
+      // these attributes need layout
+      DOM::DocumentImpl* docimpl = node.handle()->getDocument();
+      if (docimpl) {
+        docimpl->updateLayout();
+      }
+      switch (token) {
+      case ImageHeight:          return Number(image.height());
+      case ImageWidth:           return Number(image.width());
+      case ImageX:               return Number(image.x());
+      case ImageY:               return Number(image.y());
+      }
     }
   }
   break;
Index: khtml/xml/dom_docimpl.cpp
===================================================================
RCS file: /local/home/cvs/Labyrinth/WebCore/khtml/xml/dom_docimpl.cpp,v
retrieving revision 1.83
diff -u -p -r1.83 khtml/xml/dom_docimpl.cpp
--- khtml/xml/dom_docimpl.cpp	2003/10/20 17:28:10	1.83
+++ khtml/xml/dom_docimpl.cpp	2003/10/29 07:20:17
@@ -307,6 +307,7 @@ DocumentImpl::DocumentImpl(DOMImplementa
                                             !inCompatMode() );
     m_windowEventListeners.setAutoDelete(true);
     m_pendingStylesheets = 0;
+    m_ignorePendingStylesheets = false;
 
     m_cssTarget = 0;
 }
@@ -1034,11 +1035,21 @@ void DocumentImpl::updateDocumentsRender
 
 void DocumentImpl::updateLayout()
 {
+    bool oldIgnore = m_ignorePendingStylesheets;
+
+    m_ignorePendingStylesheets = true;
+    
+    if (!oldIgnore) {
+	updateStyleSelector();    
+    }
+
     updateRendering();
 
     // Only do a layout if changes have occurred that make it necessary.      
     if (m_view && renderer() && renderer()->needsLayout())
 	m_view->layout();
+
+    m_ignorePendingStylesheets = oldIgnore;
 }
 
 void DocumentImpl::attach()
@@ -1912,7 +1923,7 @@ void DocumentImpl::stylesheetLoaded()
 void DocumentImpl::updateStyleSelector()
 {
     // Don't bother updating, since we haven't loaded all our style info yet.
-    if (m_pendingStylesheets > 0)
+    if (m_pendingStylesheets > 0 && !m_ignorePendingStylesheets)
         return;
 
     recalcStyleSelector();
Index: khtml/xml/dom_docimpl.h
===================================================================
RCS file: /local/home/cvs/Labyrinth/WebCore/khtml/xml/dom_docimpl.h,v
retrieving revision 1.41
diff -u -p -r1.41 khtml/xml/dom_docimpl.h
--- khtml/xml/dom_docimpl.h	2003/10/01 20:58:56	1.41
+++ khtml/xml/dom_docimpl.h	2003/10/29 07:20:19
@@ -184,7 +184,7 @@ public:
      * This method returns true if all top-level stylesheets have loaded (including
      * any @imports that they may be loading).
      */
-    bool haveStylesheetsLoaded() { return m_pendingStylesheets <= 0; }
+    bool haveStylesheetsLoaded() { return m_pendingStylesheets <= 0 || m_ignorePendingStylesheets; }
 
     /**
      * Increments the number of pending sheets.  The <link> elements
@@ -487,6 +487,10 @@ protected:
     // We use this count of pending sheets to detect when we can begin attaching
     // elements.
     int m_pendingStylesheets;
+
+    // but sometimes you need to ignore pending stylesheet count to
+    // force an immediate layout when requested by JS.
+    bool m_ignorePendingStylesheets;
 
     CSSStyleSheetImpl *m_elemSheet;
 
-------------- next part --------------


And here's a tweak to make it avoid FOUC-ing on Dave's blog:

-------------- next part --------------
Index: ChangeLog
===================================================================
RCS file: /local/home/cvs/Labyrinth/WebCore/ChangeLog,v
retrieving revision 1.2154
diff -u -p -r1.2154 ChangeLog
--- ChangeLog	2003/10/30 22:00:36	1.2154
+++ ChangeLog	2003/10/30 22:03:39
@@ -1,3 +1,13 @@
+2003-10-30  Maciej Stachowiak  <mjs at apple.com>
+
+        Reviewed by Dave.
+
+	- fixed 3468129 - REGRESSION: FOUC occurs on Surfin' Safari
+	
+        * khtml/ecma/kjs_html.cpp:
+        (KJS::HTMLElement::getValueProperty): Don't force layout for image
+	width/height if you can determine it statically from the attribute.
+
 2003-10-30  Ken Kocienda  <kocienda at apple.com>
 
         Reviewed by me
Index: khtml/ecma/kjs_html.cpp
===================================================================
RCS file: /local/home/cvs/Labyrinth/WebCore/khtml/ecma/kjs_html.cpp,v
retrieving revision 1.42
diff -u -p -r1.42 khtml/ecma/kjs_html.cpp
--- khtml/ecma/kjs_html.cpp	2003/10/29 20:08:15	1.42
+++ khtml/ecma/kjs_html.cpp	2003/10/30 22:03:39
@@ -1535,17 +1535,57 @@ Value KJS::HTMLElement::getValueProperty
     case ImageSrc:             return String(image.src());
     case ImageUseMap:          return String(image.useMap());
     case ImageVspace:          return Number(image.vspace());
-    default:
-      // these attributes need layout
-      DOM::DocumentImpl* docimpl = node.handle()->getDocument();
-      if (docimpl) {
-        docimpl->updateLayout();
+    case ImageHeight:
+      {
+	// check the attribute first for an explicit pixel value
+	DOM::DOMString attrHeight = image.getAttribute("height");
+	bool ok;
+	int height = attrHeight.string().toInt(&ok);
+	if (ok) {
+	  return Number(height);
+	}
+	
+	// not found, gotta force a layout
+	DOM::DocumentImpl* docimpl = node.handle()->getDocument();
+	if (docimpl) {
+	  docimpl->updateLayout();
+	}
+      
+	return Number(image.height());
       }
-      switch (token) {
-      case ImageHeight:          return Number(image.height());
-      case ImageWidth:           return Number(image.width());
-      case ImageX:               return Number(image.x());
-      case ImageY:               return Number(image.y());
+    case ImageWidth:
+      {
+	// check the attribute first for an explicit pixel value
+	DOM::DOMString attrWidth = image.getAttribute("width");
+	bool ok;
+	int width = attrWidth.string().toInt(&ok);
+	if (ok) {
+	  return Number(width);
+	}
+	
+	// not found, gotta force a layout
+	DOM::DocumentImpl* docimpl = node.handle()->getDocument();
+	if (docimpl) {
+	  docimpl->updateLayout();
+	}
+	
+	return Number(image.width());
+      }
+    case ImageX:
+      {
+	DOM::DocumentImpl* docimpl = node.handle()->getDocument();
+	if (docimpl) {
+	  docimpl->updateLayout();
+	}
+	return Number(image.x());
+      }
+    case ImageY:
+      {
+	DOM::DocumentImpl* docimpl = node.handle()->getDocument();
+	if (docimpl) {
+	  docimpl->updateLayout();
+	}
+	return Number(image.y());
       }
     }
   }


More information about the Khtml-devel mailing list