Fix style sharing so that it doesn't share when it shouldn't. Partially fixes 36715...
authorhyatt <hyatt@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 27 Sep 2004 17:52:18 +0000 (17:52 +0000)
committerhyatt <hyatt@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 27 Sep 2004 17:52:18 +0000 (17:52 +0000)
their color on macosx.apple.com.

Fix 3521639, iframe mispositioned on bidi page.  Make sure that when the width of a line exceeds the available line
width that the spillage out of the block is determined by the direction of the block and not by the text-align value.

Partial fix for 3762962, make sure the image cells with specified widths but percentage heights don't just get a minwidth
of 0.

Fix for 3533878, framesets that use percentages that add up to a value > 100% should normalize those percentages.

        Reviewed by john

        * khtml/css/cssstyleselector.cpp:
        (khtml::CSSStyleSelector::locateCousinList):
        (khtml::CSSStyleSelector::elementsCanShareStyle):
        (khtml::CSSStyleSelector::locateSharedStyle):
        * khtml/css/cssstyleselector.h:
        * khtml/html/html_elementimpl.h:
        (DOM::HTMLNamedAttrMapImpl::hasMappedAttributes):
        (DOM::HTMLElementImpl::inlineStyleDecl):
        * khtml/rendering/bidi.cpp:
        (khtml::RenderBlock::computeHorizontalPositionsForLine):
        * khtml/rendering/render_frames.cpp:
        (RenderFrameSet::layout):
        * khtml/rendering/render_replaced.cpp:
        (RenderReplaced::calcMinMaxWidth):
        * khtml/xml/dom_elementimpl.h:
        (DOM::ElementImpl::inlineStyleDecl):
        (DOM::ElementImpl::hasMappedAttributes):

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

WebCore/ChangeLog-2005-08-23
WebCore/khtml/css/cssstyleselector.cpp
WebCore/khtml/css/cssstyleselector.h
WebCore/khtml/html/html_elementimpl.h
WebCore/khtml/rendering/bidi.cpp
WebCore/khtml/rendering/render_frames.cpp
WebCore/khtml/rendering/render_replaced.cpp
WebCore/khtml/xml/dom_elementimpl.h

index 07590fb..3fc86e4 100644 (file)
@@ -1,3 +1,36 @@
+2004-09-27  David Hyatt  <hyatt@apple.com>
+
+       Fix style sharing so that it doesn't share when it shouldn't.  Partially fixes 3671516, table cells don't update
+       their color on macosx.apple.com.
+
+       Fix 3521639, iframe mispositioned on bidi page.  Make sure that when the width of a line exceeds the available line
+       width that the spillage out of the block is determined by the direction of the block and not by the text-align value.
+
+       Partial fix for 3762962, make sure the image cells with specified widths but percentage heights don't just get a minwidth
+       of 0.
+
+       Fix for 3533878, framesets that use percentages that add up to a value > 100% should normalize those percentages.
+       
+        Reviewed by john
+
+        * khtml/css/cssstyleselector.cpp:
+        (khtml::CSSStyleSelector::locateCousinList):
+        (khtml::CSSStyleSelector::elementsCanShareStyle):
+        (khtml::CSSStyleSelector::locateSharedStyle):
+        * khtml/css/cssstyleselector.h:
+        * khtml/html/html_elementimpl.h:
+        (DOM::HTMLNamedAttrMapImpl::hasMappedAttributes):
+        (DOM::HTMLElementImpl::inlineStyleDecl):
+        * khtml/rendering/bidi.cpp:
+        (khtml::RenderBlock::computeHorizontalPositionsForLine):
+        * khtml/rendering/render_frames.cpp:
+        (RenderFrameSet::layout):
+        * khtml/rendering/render_replaced.cpp:
+        (RenderReplaced::calcMinMaxWidth):
+        * khtml/xml/dom_elementimpl.h:
+        (DOM::ElementImpl::inlineStyleDecl):
+        (DOM::ElementImpl::hasMappedAttributes):
+
 2004-09-27  Ken Kocienda  <kocienda@apple.com>
 
         Reviewed by John
index 76647b8..09c77bc 100644 (file)
@@ -529,76 +529,70 @@ const int siblingThreshold = 10;
 
 NodeImpl* CSSStyleSelector::locateCousinList(ElementImpl* parent)
 {
-    if (parent && parent->isHTMLElement()) {
-        HTMLElementImpl* p = static_cast<HTMLElementImpl*>(parent);
-        if (p->renderer() && !p->inlineStyleDecl() && !p->hasID()) {
-            DOM::NodeImpl* r = p->previousSibling();
-            int subcount = 0;
-            RenderStyle* st = p->renderer()->style();
-            while (r) {
-                if (r->renderer() && r->renderer()->style() == st)
-                    return r->lastChild();
-                if (subcount++ == siblingThreshold)
-                    return 0;
-                r = r->previousSibling();
-            }
-            if (!r)
-                r = locateCousinList(static_cast<ElementImpl*>(parent->parentNode()));
-            while (r) {
-                if (r->renderer() && r->renderer()->style() == st)
-                    return r->lastChild();
-                if (subcount++ == siblingThreshold)
-                    return 0;
-                r = r->previousSibling();
-            }
+    if (parent && parent->renderer() && !parent->inlineStyleDecl() && !parent->hasID()) {
+        DOM::NodeImpl* n;
+        for (n = parent->previousSibling(); n && !n->isElementNode(); n = n->previousSibling());
+        int subcount = 0;
+        while (n) {
+            if (elementsCanShareStyle(static_cast<ElementImpl*>(n), parent))
+                return n->lastChild();
+            if (subcount++ == siblingThreshold)
+                return 0;
+            for (n = n->previousSibling(); n && !n->isElementNode(); n = n->previousSibling());
+        }
+        if (!n && parent->parentNode() && parent->parentNode()->isElementNode())
+            n = locateCousinList(static_cast<ElementImpl*>(parent->parentNode()));
+        while (n) {
+            if (elementsCanShareStyle(static_cast<ElementImpl*>(n), parent))
+                return n->lastChild();
+            if (subcount++ == siblingThreshold)
+                return 0;
+            for (n = parent->previousSibling(); n && !n->isElementNode(); n = n->previousSibling());
         }
     }
     return 0;
 }
 
-bool CSSStyleSelector::canShareStyleWithElement(NodeImpl* n)
+bool CSSStyleSelector::elementsCanShareStyle(ElementImpl* e1, ElementImpl* e2)
 {
-    if (n->isHTMLElement()) {
-        bool mouseInside = element->renderer() ? element->renderer()->mouseInside() : false;
-        HTMLElementImpl* s = static_cast<HTMLElementImpl*>(n);
-        if (s->renderer() && (s->id() == element->id()) && !s->hasID() &&
-            (s->hasClass() == element->hasClass()) && !s->inlineStyleDecl() &&
-            (s->hasMappedAttributes() == htmlElement->hasMappedAttributes()) &&
-            (s->hasAnchor() == element->hasAnchor()) && 
-            !s->renderer()->style()->affectedByAttributeSelectors() &&
-            (s->renderer()->mouseInside() == mouseInside) &&
-            (s->active() == element->active()) &&
-            (s->focused() == element->focused())) {
-            bool classesMatch = true;
-            if (s->hasClass()) {
-                const AtomicString& class1 = element->getAttribute(ATTR_CLASS);
-                const AtomicString& class2 = s->getAttribute(ATTR_CLASS);
-                classesMatch = (class1 == class2);
-            }
-            
-            if (classesMatch) {
-                bool mappedAttrsMatch = true;
-                if (s->hasMappedAttributes())
-                    mappedAttrsMatch = s->htmlAttributes()->mapsEquivalent(htmlElement->htmlAttributes());
-                if (mappedAttrsMatch) {
-                    bool anchorsMatch = true;
-                    if (s->hasAnchor()) {
-                        // We need to check to see if the visited state matches.
-                        QColor linkColor = element->getDocument()->linkColor();
-                        QColor visitedColor = element->getDocument()->visitedLinkColor();
-                        if (pseudoState == PseudoUnknown)
-                            checkPseudoState(element, s->renderer()->style()->pseudoState() != PseudoAnyLink ||
-                                             linkColor != visitedColor);
-                        anchorsMatch = (pseudoState == s->renderer()->style()->pseudoState());
-                    }
-                    
-                    if (anchorsMatch) {
+    bool mouseInside = e2->renderer() ? e2->renderer()->mouseInside() : false;
+    if (e1->renderer() && (e1->id() == e2->id()) && !e1->hasID() &&
+        (e1->hasClass() == e2->hasClass()) && !e1->inlineStyleDecl() &&
+        (e1->hasMappedAttributes() == e2->hasMappedAttributes()) &&
+        (e1->hasAnchor() == e2->hasAnchor()) && 
+        !e1->renderer()->style()->affectedByAttributeSelectors() &&
+        (e1->renderer()->mouseInside() == mouseInside) &&
+        (e1->active() == e2->active()) &&
+        (e1->focused() == e2->focused())) {
+        bool classesMatch = true;
+        if (e1->hasClass()) {
+            const AtomicString& class1 = e2->getAttribute(ATTR_CLASS);
+            const AtomicString& class2 = e1->getAttribute(ATTR_CLASS);
+            classesMatch = (class1 == class2);
+        }
+        
+        if (classesMatch) {
+            bool mappedAttrsMatch = true;
+            if (e1->hasMappedAttributes()) 
+                mappedAttrsMatch = static_cast<HTMLElementImpl*>(e1)->htmlAttributes()->mapsEquivalent(static_cast<HTMLElementImpl*>(e2)->htmlAttributes());
+            if (mappedAttrsMatch) {
+                bool anchorsMatch = true;
+                if (e1->hasAnchor()) {
+                    // We need to check to see if the visited state matches.
+                    QColor linkColor = e2->getDocument()->linkColor();
+                    QColor visitedColor = e2->getDocument()->visitedLinkColor();
+                    if (pseudoState == PseudoUnknown)
+                        checkPseudoState(element, e1->renderer()->style()->pseudoState() != PseudoAnyLink ||
+                                         linkColor != visitedColor);
+                    anchorsMatch = (pseudoState == e1->renderer()->style()->pseudoState());
+                }
+                
+                if (anchorsMatch) {
 #ifdef STYLE_SHARING_STATS
-                        fraction++; total++;
-                        printf("Sharing %d out of %d\n", fraction, total);
+                    fraction++; total++;
+                    printf("Sharing %d out of %d\n", fraction, total);
 #endif
-                        return true;
-                    }
+                    return true;
                 }
             }
         }
@@ -608,24 +602,22 @@ bool CSSStyleSelector::canShareStyleWithElement(NodeImpl* n)
 
 RenderStyle* CSSStyleSelector::locateSharedStyle()
 {
-    //total++;
-    if (htmlElement && !htmlElement->inlineStyleDecl() && !htmlElement->hasID() &&
-        !htmlElement->getDocument()->usesSiblingRules()) {
+    if (!element->inlineStyleDecl() && !element->hasID() && !element->getDocument()->usesSiblingRules()) {
         // Check previous siblings.
         int count = 0;
         DOM::NodeImpl* n;
         for (n = element->previousSibling(); n && !n->isElementNode(); n = n->previousSibling());
         while (n) {
-            if (canShareStyleWithElement(n))
+            if (elementsCanShareStyle(static_cast<ElementImpl*>(n), element))
                 return n->renderer()->style();
             if (count++ == siblingThreshold)
                 return 0;
             for (n = n->previousSibling(); n && !n->isElementNode(); n = n->previousSibling());
         }
-        if (!n) 
+        if (!n && element->parentNode() && element->parentNode()->isElementNode()
             n = locateCousinList(static_cast<ElementImpl*>(element->parentNode()));
         while (n) {
-            if (canShareStyleWithElement(n))
+            if (elementsCanShareStyle(static_cast<ElementImpl*>(n), element))
                 return n->renderer()->style();
             if (count++ == siblingThreshold)
                 return 0;
index 90245f7..64136e0 100644 (file)
@@ -112,7 +112,7 @@ namespace khtml
 
         RenderStyle* locateSharedStyle();
         DOM::NodeImpl* locateCousinList(DOM::ElementImpl* parent);
-        bool canShareStyleWithElement(DOM::NodeImpl* e);
+        bool elementsCanShareStyle(DOM::ElementImpl* e1, DOM::ElementImpl* e2);
         
        bool strictParsing;
        
index a490206..6bf1e9f 100644 (file)
@@ -99,7 +99,7 @@ public:
     virtual void parseClassAttribute(const DOMString& classAttr);
     const AtomicStringList* getClassList() const { return &m_classList; }
     
-    bool hasMappedAttributes() const { return m_mappedAttributeCount > 0; }
+    virtual bool hasMappedAttributes() const { return m_mappedAttributeCount > 0; }
     void declRemoved() { m_mappedAttributeCount--; }
     void declAdded() { m_mappedAttributeCount++; }
     
@@ -168,7 +168,7 @@ public:
 
     virtual void click();
     
-    CSSStyleDeclarationImpl* inlineStyleDecl() const { return m_inlineStyleDecl; }
+    virtual CSSStyleDeclarationImpl* inlineStyleDecl() const { return m_inlineStyleDecl; }
     virtual CSSStyleDeclarationImpl* additionalAttributeStyleDecl();
     CSSStyleDeclarationImpl* getInlineStyleDecl();
     void createInlineStyleDecl();
index 10a2712..af3a897 100644 (file)
@@ -741,6 +741,10 @@ void RenderBlock::computeHorizontalPositionsForLine(RootInlineBox* lineBox, Bidi
     switch(style()->textAlign()) {
         case LEFT:
         case KHTML_LEFT:
+            // The direction of the block should determine what happens with wide lines.  In
+            // particular with RTL blocks, wide lines should still spill out to the left.
+            if (style()->direction() == RTL && totWidth > availableWidth)
+                x -= (totWidth - availableWidth);
             numSpaces = 0;
             break;
         case JUSTIFY:
@@ -754,7 +758,11 @@ void RenderBlock::computeHorizontalPositionsForLine(RootInlineBox* lineBox, Bidi
                 break;
         case RIGHT:
         case KHTML_RIGHT:
-            x += availableWidth - totWidth;
+            // Wide lines spill out of the block based off direction.
+            // So even if text-align is right, if direction is LTR, wide lines should overflow out of the right
+            // side of the block.
+            if (style()->direction() == RTL || totWidth < availableWidth)
+                x += availableWidth - totWidth;
             numSpaces = 0;
             break;
         case CENTER:
index 80844e2..24329c6 100644 (file)
@@ -155,7 +155,7 @@ void RenderFrameSet::layout( )
         if (grid) {
             // first distribute the available width for fixed rows, then handle the
             // percentage ones and distribute remaining over relative
-            for(int i = 0; i< gridLen; ++i)
+            for(int i = 0; i< gridLen; ++i) {
                 if (grid[i].isFixed()) {
                     gridLayout[i] = kMin(grid[i].value > 0 ? grid[i].value : 0, remainingLen[k]);
                     remainingLen[k] -= gridLayout[i];
@@ -165,13 +165,18 @@ void RenderFrameSet::layout( )
                     totalRelative += grid[i].value > 1 ? grid[i].value : 1;
                     countRelative++;
                 }
+                else if (grid[i].isPercent()) {
+                    totalPercent += grid[i].value >= 0 ? grid[i].value : 0;
+                    countPercent++;
+                }
+            }
 
+            int currPercent = totalPercent;
             for(int i = 0; i < gridLen; i++)
-                if(grid[i].isPercent()) {
-                    gridLayout[i] = kMin(kMax(grid[i].width(availableLen[k]), 0), remainingLen[k]);
+                if (grid[i].isPercent() && grid[i].value >= 0 && currPercent) {
+                    gridLayout[i] = grid[i].value * remainingLen[k] / currPercent;
                     remainingLen[k] -= gridLayout[i];
-                    totalPercent += grid[i].value;
-                    countPercent++;
+                    currPercent -= grid[i].value;
                 }
 
             assert(remainingLen[k] >= 0);
index 308523e..ea23d13 100644 (file)
@@ -88,7 +88,7 @@ void RenderReplaced::calcMinMaxWidth()
 #endif
 
     int width = calcReplacedWidth() + paddingLeft() + paddingRight() + borderLeft() + borderRight();
-    if ( style()->width().isPercent() || style()->height().isPercent() ) {
+    if (style()->width().isPercent() || (style()->width().isVariable() && style()->height().isPercent())) {
         m_minWidth = 0;
         m_maxWidth = width;
     }
index dbb55dd..e015940 100644 (file)
@@ -196,6 +196,9 @@ public:
     // State of the element.
     virtual QString state() { return QString::null; }
 
+    virtual CSSStyleDeclarationImpl* inlineStyleDecl() const { return 0; }
+    virtual bool hasMappedAttributes() const { return false; }
+
     virtual void attach();
     virtual void detach();
     virtual khtml::RenderStyle *styleForRenderer(khtml::RenderObject *parent);