<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.kde.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.6"
          urlbase="https://bugs.kde.org/"
          
          maintainer="sysadmin@kde.org"
>

    <bug>
          <bug_id>102536</bug_id>
          
          <creation_ts>2005-03-26 15:41:46 +0000</creation_ts>
          <short_desc>[test case] Incorrect margin for tables</short_desc>
          <delta_ts>2006-10-14 16:32:08 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>2</classification_id>
          <classification>Applications</classification>
          <product>konqueror</product>
          <component>khtml renderer</component>
          <version>unspecified</version>
          <rep_platform>unspecified</rep_platform>
          <op_sys>Linux</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>NOR</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter>fleona</reporter>
          <assigned_to name="Konqueror Bugs">konqueror-bugs-null</assigned_to>
          
          
          <cf_commitlink></cf_commitlink>
          <cf_versionfixedin></cf_versionfixedin>
          <cf_sentryurl></cf_sentryurl>
          <votes>20</votes>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>328435</commentid>
    <comment_count>0</comment_count>
    <who name="">fleona</who>
    <bug_when>2005-03-26 15:41:47 +0000</bug_when>
    <thetext>Version:            (using KDE KDE 3.4.0)
Installed from:    Unlisted Binary Package
Compiler:          gcc 3.4.3 
OS:                Linux

Hey guys. I have a small site that shows the static pages of a project of mine.

http://mipagina.cantv.net/fleona/html

Mozilla and Safari render all those tables centered correctly, respecting the margins i set with CSS. Somehow, konqueror displays the tables left-aligned, as if it wasn&apos;t respecting the right margin

Here is some css code of a table:
ttp://mipagina.cantv.net/fleona/html/css/style.css

table#header {
	background: #345487;
	width:90%;
	text-align: center;
	border-collapse: collapse;
	margin-left:5%;
	margin-right:5%;
}

margin-left and margin-right are 5%, set to center the table. 

On konqueror the right margin seems to be triple (15%). I don&apos;t think i will need to provide a screenshot, but if somehow you can&apos;t reproduce this, tell me to attach a comparison between mozilla and konqueror. Like i said, safari also renders correctly.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>333737</commentid>
    <comment_count>1</comment_count>
    <who name="lexual">lex.lists</who>
    <bug_when>2005-04-12 10:17:05 +0000</bug_when>
    <thetext>The alignment looks correct to me and the same as firefox.

The right margin is too big though.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>333755</commentid>
    <comment_count>2</comment_count>
      <attachid>10589</attachid>
    <who name="Allan Sandfeld">kde</who>
    <bug_when>2005-04-12 10:55:26 +0000</bug_when>
    <thetext>Created attachment 10589
test case

A simple test case. It appears it doesn&apos;t happen if you replace the table with
a div.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>333756</commentid>
    <comment_count>3</comment_count>
      <attachid>10590</attachid>
    <who name="Allan Sandfeld">kde</who>
    <bug_when>2005-04-12 10:56:54 +0000</bug_when>
    <thetext>Created attachment 10590
Corrected test case

Sorry, the first test case was buggy</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>476817</commentid>
    <comment_count>4</comment_count>
    <who name="Allan Sandfeld">kde</who>
    <bug_when>2006-10-14 16:32:07 +0000</bug_when>
    <thetext>SVN commit 595493 by carewolf:

Don&apos;t subtract margin from available-width + fix various width bugs that 
revealed themselves up after fixing that.
BUG: 102536


 M  +15 -9     render_table.cpp  
 M  +4 -0      render_table.h  
 M  +6 -2      table_layout.cpp  


--- branches/KDE/3.5/kdelibs/khtml/rendering/render_table.cpp #595492:595493
@@ -233,27 +233,33 @@
     RenderBlock *cb = containingBlock();
     int availableWidth = cb-&gt;contentWidth();
 
-    // Subtract minimum margins
-    availableWidth -= style()-&gt;marginLeft().minWidth(cb-&gt;contentWidth());
-    availableWidth -= style()-&gt;marginRight().minWidth(cb-&gt;contentWidth());
-
     LengthType widthType = style()-&gt;width().type();
     if(widthType &gt; Relative &amp;&amp; style()-&gt;width().value() &gt; 0) {
 	// Percent or fixed table
-        m_width = style()-&gt;width().minWidth( availableWidth );
+        m_width = calcBoxWidth(style()-&gt;width().minWidth( availableWidth ));
         if(m_minWidth &gt; m_width) m_width = m_minWidth;
     } else {
-        m_width = KMIN(short( availableWidth ), short(m_maxWidth));
+        // Subtract out any fixed margins from our available width for auto width tables.
+        int marginTotal = 0;
+        if (!style()-&gt;marginLeft().isVariable())
+            marginTotal += style()-&gt;marginLeft().width(availableWidth);
+        if (!style()-&gt;marginRight().isVariable())
+            marginTotal += style()-&gt;marginRight().width(availableWidth);
+
+        // Subtract out our margins to get the available content width.
+        int availContentWidth = kMax(0, availableWidth - marginTotal);
+
+        // Ensure we aren&apos;t bigger than our max width or smaller than our min width.
+        m_width = kMin(availContentWidth, m_maxWidth);
     }
 
     // restrict width to what we really have
     // EXCEPT percent tables, which are still calculated as above
-
     availableWidth = cb-&gt;lineWidth( m_y );
     if ( widthType != Percent )
-        m_width = KMIN( short( availableWidth ), m_width );
+        m_width = kMin( short( availableWidth ), m_width );
 
-    m_width = KMAX (m_width, m_minWidth);
+    m_width = kMax (m_width, m_minWidth);
 
     // Finally, with our true width determined, compute our margins for real.
     m_marginRight=0;
--- branches/KDE/3.5/kdelibs/khtml/rendering/render_table.h #595492:595493
@@ -73,6 +73,10 @@
     int borderRight() const;
     int borderTop() const;
     int borderBottom() const;
+    int paddingLeft() const { return collapseBorders() ? 0 : RenderBlock::paddingLeft(); }
+    int paddingRight() const { return collapseBorders() ? 0 : RenderBlock::paddingRight(); }
+    int paddingTop() const { return collapseBorders() ? 0 : RenderBlock::paddingTop(); }
+    int paddingBottom() const { return collapseBorders() ? 0 : RenderBlock::paddingBottom(); }
 
     const QColor &amp;bgColor() const { return style()-&gt;backgroundColor(); }
 
--- branches/KDE/3.5/kdelibs/khtml/rendering/table_layout.cpp #595492:595493
@@ -233,7 +233,10 @@
     // unlimited.
 
     int bs = table-&gt;bordersPaddingAndSpacing();
-    int tableWidth = table-&gt;style()-&gt;width().isFixed() ? table-&gt;style()-&gt;width().value() - bs : 0;
+    int tableWidth = 0;
+    if (table-&gt;style()-&gt;width().isFixed()) {
+        tableWidth = table-&gt;calcBoxWidth(table-&gt;style()-&gt;width().value());
+    }
 
     int mw = calcWidthArray() + bs;
     table-&gt;m_minWidth = kMin( kMax( mw, tableWidth ), 0x7fff );
@@ -599,7 +602,8 @@
 
     Length tw = table-&gt;style()-&gt;width();
     if ( tw.isFixed() &amp;&amp; tw.value() &gt; 0 ) {
-	minWidth = kMax( minWidth, int( tw.value() ) );
+        int width = table-&gt;calcBoxWidth(tw.value());
+        minWidth = kMax( minWidth, width );
 	maxWidth = minWidth;
     }
 
</thetext>
  </long_desc>
      
          <attachment
              isobsolete="1"
              ispatch="0"
              isprivate="0"
          >
            <attachid>10589</attachid>
            <date>2005-04-12 10:55:26 +0000</date>
            <delta_ts>2005-04-12 10:56:54 +0000</delta_ts>
            <desc>test case</desc>
            <filename>102536.html</filename>
            <type>text/html</type>
            <size>297</size>
            <attacher name="Allan Sandfeld">kde</attacher>
            
              <data encoding="base64">PGh0bWw+CjxoZWFkPgo8c3R5bGUgdHlwZT0idGV4dC9jc3MiPgpkaXYgewoJYmFja2dyb3VuZDog
IzM0NTQ4NzsKCXdpZHRoOjkwJTsKCWhlaWdodDogMTAwcHg7Cgl0ZXh0LWFsaWduOiBjZW50ZXI7
Cglib3JkZXItY29sbGFwc2U6IGNvbGxhcHNlOwoJbWFyZ2luLWxlZnQ6NSU7CgltYXJnaW4tcmln
aHQ6NSU7Cn0KPC9zdHlsZT4KPC9oZWFkPgo8Ym9keT4KPHRhYmxlID4KICA8dGJvZHk+CiAgIDx0
cj4KICAgIDx0ZCA+CiAgICA8L3RkPgogICA8L3RyPgogIDwvdGJvZHk+CjwvdGFibGU+CgoKPC9i
b2R5Pgo8L2h0bWw+
</data>

          </attachment>
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>10590</attachid>
            <date>2005-04-12 10:56:54 +0000</date>
            <delta_ts>2005-04-12 10:56:54 +0000</delta_ts>
            <desc>Corrected test case</desc>
            <filename>102536.html</filename>
            <type>text/html</type>
            <size>299</size>
            <attacher name="Allan Sandfeld">kde</attacher>
            
              <data encoding="base64">PGh0bWw+CjxoZWFkPgo8c3R5bGUgdHlwZT0idGV4dC9jc3MiPgp0YWJsZSB7CgliYWNrZ3JvdW5k
OiAjMzQ1NDg3OwoJd2lkdGg6OTAlOwoJaGVpZ2h0OiAxMDBweDsKCXRleHQtYWxpZ246IGNlbnRl
cjsKCWJvcmRlci1jb2xsYXBzZTogY29sbGFwc2U7CgltYXJnaW4tbGVmdDo1JTsKCW1hcmdpbi1y
aWdodDo1JTsKfQo8L3N0eWxlPgo8L2hlYWQ+Cjxib2R5Pgo8dGFibGUgPgogIDx0Ym9keT4KICAg
PHRyPgogICAgPHRkID4KICAgIDwvdGQ+CiAgIDwvdHI+CiAgPC90Ym9keT4KPC90YWJsZT4KCgo8
L2JvZHk+CjwvaHRtbD4=
</data>

          </attachment>
      

    </bug>

</bugzilla>