Move padding/margin/offset writing mode logic from RenderStyle to LengthBox
authoreae@chromium.org <eae@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 21 May 2012 23:42:54 +0000 (23:42 +0000)
committereae@chromium.org <eae@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 21 May 2012 23:42:54 +0000 (23:42 +0000)
https://bugs.webkit.org/show_bug.cgi?id=86970

Reviewed by Eric Seidel.

Move writing mode and bidi logic for paddings, margins and offsets from
RenderStyle to LengthBox. This way the same logic can be used for all
three removing unnecessary code duplication.

No new tests, no change in functionality.

* CMakeLists.txt:
* GNUmakefile.list.am:
* Target.pri:
* WebCore.gypi:
* WebCore.vcproj/WebCore.vcproj:
* WebCore.xcodeproj/project.pbxproj:
* platform/LengthBox.cpp: Added.
* platform/LengthBox.h:
* rendering/style/RenderStyle.cpp:
* rendering/style/RenderStyle.h:

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

Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/GNUmakefile.list.am
Source/WebCore/Target.pri
Source/WebCore/WebCore.gypi
Source/WebCore/WebCore.vcproj/WebCore.vcproj
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/platform/LengthBox.cpp [new file with mode: 0644]
Source/WebCore/platform/LengthBox.h
Source/WebCore/rendering/style/RenderStyle.cpp
Source/WebCore/rendering/style/RenderStyle.h

index 69cda01..1750165 100644 (file)
@@ -1113,6 +1113,7 @@ SET(WebCore_SOURCES
     platform/KillRingNone.cpp
     platform/Language.cpp
     platform/Length.cpp
+    platform/LengthBox.cpp
     platform/LinkHash.cpp
     platform/Logging.cpp
     platform/MemoryUsageSupport.cpp
index 87f3e77..0f9b1c9 100644 (file)
@@ -1,3 +1,27 @@
+2012-05-21  Emil A Eklund  <eae@chromium.org>
+
+        Move padding/margin/offset writing mode logic from RenderStyle to LengthBox
+        https://bugs.webkit.org/show_bug.cgi?id=86970
+
+        Reviewed by Eric Seidel.
+
+        Move writing mode and bidi logic for paddings, margins and offsets from
+        RenderStyle to LengthBox. This way the same logic can be used for all
+        three removing unnecessary code duplication.
+
+        No new tests, no change in functionality.
+
+        * CMakeLists.txt:
+        * GNUmakefile.list.am:
+        * Target.pri:
+        * WebCore.gypi:
+        * WebCore.vcproj/WebCore.vcproj:
+        * WebCore.xcodeproj/project.pbxproj:
+        * platform/LengthBox.cpp: Added.
+        * platform/LengthBox.h:
+        * rendering/style/RenderStyle.cpp:
+        * rendering/style/RenderStyle.h:
+
 2012-05-21  Mike West  <mkwst@chromium.org>
 
         Improving console error for CSP-blocked  `setTimeout` and `setInterval` evaluation.
index d71db59..2594323 100644 (file)
@@ -3383,6 +3383,7 @@ webcore_sources += \
        Source/WebCore/platform/KURLWTFURLImpl.h \
        Source/WebCore/platform/Language.cpp \
        Source/WebCore/platform/Language.h \
+       Source/WebCore/platform/LengthBox.cpp \
        Source/WebCore/platform/LengthBox.h \
        Source/WebCore/platform/Length.cpp \
        Source/WebCore/platform/Length.h \
index c278b6b..3c9b60a 100644 (file)
@@ -1143,6 +1143,7 @@ SOURCES += \
     platform/KURL.cpp \
     platform/Language.cpp \
     platform/Length.cpp \
+    platform/LengthBox.cpp \
     platform/text/LineEnding.cpp \
     platform/leveldb/LevelDBDatabase.cpp \
     platform/leveldb/LevelDBTransaction.cpp \
index cbe5194..eda6bc3 100644 (file)
             'platform/KillRingNone.cpp',
             'platform/Language.cpp',
             'platform/Length.cpp',
+            'platform/LengthBox.cpp',
             'platform/LinkHash.cpp',
             'platform/Logging.cpp',
             'platform/MemoryPressureHandler.cpp',
index 1a4ae67..b1add15 100755 (executable)
                                >
                        </File>
                        <File
+                               RelativePath="..\platform\LengthBox.cpp"
+                               >
+                       </File>
+                       <File
                                RelativePath="..\platform\LengthBox.h"
                                >
                        </File>
index 2d346f2..372183a 100644 (file)
                144FCFE014EF2509000D17A3 /* FractionalLayoutRect.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 144FCFDE14EF2509000D17A3 /* FractionalLayoutRect.cpp */; };
                144FCFE114EF2509000D17A3 /* FractionalLayoutRect.h in Headers */ = {isa = PBXBuildFile; fileRef = 144FCFDF14EF2509000D17A3 /* FractionalLayoutRect.h */; settings = {ATTRIBUTES = (Private, ); }; };
                1464E06C135EC10600FDB00A /* JSMediaListCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1464E06B135EC10600FDB00A /* JSMediaListCustom.cpp */; };
+               146CC115156988E400109E37 /* LengthBox.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 146CC113156988BD00109E37 /* LengthBox.cpp */; };
                1477E7760BF4134A00152872 /* PageCache.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1477E7740BF4134A00152872 /* PageCache.cpp */; };
                1477E7770BF4134A00152872 /* PageCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 1477E7750BF4134A00152872 /* PageCache.h */; settings = {ATTRIBUTES = (Private, ); }; };
                1479FAED109AE37500DED655 /* RenderRuby.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1479FAE5109AE37500DED655 /* RenderRuby.cpp */; };
                144FCFDE14EF2509000D17A3 /* FractionalLayoutRect.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FractionalLayoutRect.cpp; sourceTree = "<group>"; };
                144FCFDF14EF2509000D17A3 /* FractionalLayoutRect.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FractionalLayoutRect.h; sourceTree = "<group>"; };
                1464E06B135EC10600FDB00A /* JSMediaListCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSMediaListCustom.cpp; sourceTree = "<group>"; };
+               146CC113156988BD00109E37 /* LengthBox.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LengthBox.cpp; sourceTree = "<group>"; };
                1477E7740BF4134A00152872 /* PageCache.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = PageCache.cpp; sourceTree = "<group>"; };
                1477E7750BF4134A00152872 /* PageCache.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = PageCache.h; sourceTree = "<group>"; };
                1479FAE5109AE37500DED655 /* RenderRuby.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RenderRuby.cpp; sourceTree = "<group>"; };
                                85EC9AF90A71A2C600EEEAED /* Language.h */,
                                BCE65BE80EACDF16007E4533 /* Length.cpp */,
                                BCE65BE90EACDF16007E4533 /* Length.h */,
+                               146CC113156988BD00109E37 /* LengthBox.cpp */,
                                BCFF648F0EAD15C200C1D6F7 /* LengthBox.h */,
                                BCFF64900EAD15C200C1D6F7 /* LengthSize.h */,
                                A7AD2F850EC89D07008AB002 /* LinkHash.cpp */,
                                29A309B01561CAC400BBD8E5 /* VisitedLinks.cpp in Sources */,
                                FDB052DF1561A42C00B500D6 /* AudioSummingJunction.cpp in Sources */,
                                371941961566B37200A276D8 /* WebCoreNSCellExtras.m in Sources */,
+                               146CC115156988E400109E37 /* LengthBox.cpp in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
diff --git a/Source/WebCore/platform/LengthBox.cpp b/Source/WebCore/platform/LengthBox.cpp
new file mode 100644 (file)
index 0000000..4aa7451
--- /dev/null
@@ -0,0 +1,94 @@
+/*
+ * Copyright (c) 2012, Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "LengthBox.h"
+
+#include "RenderStyle.h"
+
+namespace WebCore {
+
+Length LengthBox::logicalLeft(const RenderStyle* style) const
+{
+    return style->isHorizontalWritingMode() ? m_left : m_top;
+}
+
+Length LengthBox::logicalRight(const RenderStyle* style) const
+{
+    return style->isHorizontalWritingMode() ? m_right : m_bottom;
+}
+
+Length LengthBox::before(const RenderStyle* style) const
+{
+    switch (style->writingMode()) {
+    case TopToBottomWritingMode:
+        return m_top;
+    case BottomToTopWritingMode:
+        return m_bottom;
+    case LeftToRightWritingMode:
+        return m_left;
+    case RightToLeftWritingMode:
+        return m_right;
+    }
+    ASSERT_NOT_REACHED();
+    return m_top;
+}
+
+Length LengthBox::after(const RenderStyle* style) const
+{
+    switch (style->writingMode()) {
+    case TopToBottomWritingMode:
+        return m_bottom;
+    case BottomToTopWritingMode:
+        return m_top;
+    case LeftToRightWritingMode:
+        return m_right;
+    case RightToLeftWritingMode:
+        return m_left;
+    }
+    ASSERT_NOT_REACHED();
+    return m_bottom;
+}
+
+Length LengthBox::start(const RenderStyle* style) const
+{
+    if (style->isHorizontalWritingMode())
+        return style->isLeftToRightDirection() ? m_left : m_right;
+    return style->isLeftToRightDirection() ? m_top : m_bottom;
+}
+
+Length LengthBox::end(const RenderStyle* style) const
+{
+    if (style->isHorizontalWritingMode())
+        return style->isLeftToRightDirection() ? m_right : m_left;
+    return style->isLeftToRightDirection() ? m_bottom : m_top;
+}
+
+} // namespace WebCore
index cf56389..389cb66 100644 (file)
@@ -1,6 +1,7 @@
 /*
     Copyright (C) 1999 Lars Knoll (knoll@kde.org)
     Copyright (C) 2006, 2008 Apple Inc. All rights reserved.
+    Copyright (c) 2012, Google Inc. All rights reserved.
 
     This library is free software; you can redistribute it and/or
     modify it under the terms of the GNU Library General Public
@@ -25,6 +26,8 @@
 
 namespace WebCore {
 
+class RenderStyle;
+
 struct LengthBox {
     LengthBox()
     {
@@ -67,6 +70,14 @@ struct LengthBox {
     Length top() const { return m_top; }
     Length bottom() const { return m_bottom; }
 
+    Length logicalLeft(const RenderStyle*) const;
+    Length logicalRight(const RenderStyle*) const;
+
+    Length before(const RenderStyle*) const;
+    Length after(const RenderStyle*) const;
+    Length start(const RenderStyle*) const;
+    Length end(const RenderStyle*) const;
+
     bool operator==(const LengthBox& o) const
     {
         return m_left == o.m_left && m_right == o.m_right && m_top == o.m_top && m_bottom == o.m_bottom;
index 9c07f8e..af67367 100644 (file)
@@ -1412,98 +1412,6 @@ unsigned short RenderStyle::borderEndWidth() const
         return isLeftToRightDirection() ? borderRightWidth() : borderLeftWidth();
     return isLeftToRightDirection() ? borderBottomWidth() : borderTopWidth();
 }
-    
-Length RenderStyle::marginBefore() const
-{
-    switch (writingMode()) {
-    case TopToBottomWritingMode:
-        return marginTop();
-    case BottomToTopWritingMode:
-        return marginBottom();
-    case LeftToRightWritingMode:
-        return marginLeft();
-    case RightToLeftWritingMode:
-        return marginRight();
-    }
-    ASSERT_NOT_REACHED();
-    return marginTop();
-}
-
-Length RenderStyle::marginAfter() const
-{
-    switch (writingMode()) {
-    case TopToBottomWritingMode:
-        return marginBottom();
-    case BottomToTopWritingMode:
-        return marginTop();
-    case LeftToRightWritingMode:
-        return marginRight();
-    case RightToLeftWritingMode:
-        return marginLeft();
-    }
-    ASSERT_NOT_REACHED();
-    return marginBottom();
-}
-
-Length RenderStyle::marginBeforeUsing(const RenderStyle* otherStyle) const
-{
-    switch (otherStyle->writingMode()) {
-    case TopToBottomWritingMode:
-        return marginTop();
-    case BottomToTopWritingMode:
-        return marginBottom();
-    case LeftToRightWritingMode:
-        return marginLeft();
-    case RightToLeftWritingMode:
-        return marginRight();
-    }
-    ASSERT_NOT_REACHED();
-    return marginTop();
-}
-
-Length RenderStyle::marginAfterUsing(const RenderStyle* otherStyle) const
-{
-    switch (otherStyle->writingMode()) {
-    case TopToBottomWritingMode:
-        return marginBottom();
-    case BottomToTopWritingMode:
-        return marginTop();
-    case LeftToRightWritingMode:
-        return marginRight();
-    case RightToLeftWritingMode:
-        return marginLeft();
-    }
-    ASSERT_NOT_REACHED();
-    return marginBottom();
-}
-
-Length RenderStyle::marginStart() const
-{
-    if (isHorizontalWritingMode())
-        return isLeftToRightDirection() ? marginLeft() : marginRight();
-    return isLeftToRightDirection() ? marginTop() : marginBottom();
-}
-
-Length RenderStyle::marginEnd() const
-{
-    if (isHorizontalWritingMode())
-        return isLeftToRightDirection() ? marginRight() : marginLeft();
-    return isLeftToRightDirection() ? marginBottom() : marginTop();
-}
-    
-Length RenderStyle::marginStartUsing(const RenderStyle* otherStyle) const
-{
-    if (otherStyle->isHorizontalWritingMode())
-        return otherStyle->isLeftToRightDirection() ? marginLeft() : marginRight();
-    return otherStyle->isLeftToRightDirection() ? marginTop() : marginBottom();
-}
-
-Length RenderStyle::marginEndUsing(const RenderStyle* otherStyle) const
-{
-    if (otherStyle->isHorizontalWritingMode())
-        return otherStyle->isLeftToRightDirection() ? marginRight() : marginLeft();
-    return otherStyle->isLeftToRightDirection() ? marginBottom() : marginTop();
-}
 
 void RenderStyle::setMarginStart(Length margin)
 {
@@ -1535,52 +1443,6 @@ void RenderStyle::setMarginEnd(Length margin)
     }
 }
 
-Length RenderStyle::paddingBefore() const
-{
-    switch (writingMode()) {
-    case TopToBottomWritingMode:
-        return paddingTop();
-    case BottomToTopWritingMode:
-        return paddingBottom();
-    case LeftToRightWritingMode:
-        return paddingLeft();
-    case RightToLeftWritingMode:
-        return paddingRight();
-    }
-    ASSERT_NOT_REACHED();
-    return paddingTop();
-}
-
-Length RenderStyle::paddingAfter() const
-{
-    switch (writingMode()) {
-    case TopToBottomWritingMode:
-        return paddingBottom();
-    case BottomToTopWritingMode:
-        return paddingTop();
-    case LeftToRightWritingMode:
-        return paddingRight();
-    case RightToLeftWritingMode:
-        return paddingLeft();
-    }
-    ASSERT_NOT_REACHED();
-    return paddingBottom();
-}
-
-Length RenderStyle::paddingStart() const
-{
-    if (isHorizontalWritingMode())
-        return isLeftToRightDirection() ? paddingLeft() : paddingRight();
-    return isLeftToRightDirection() ? paddingTop() : paddingBottom();
-}
-
-Length RenderStyle::paddingEnd() const
-{
-    if (isHorizontalWritingMode())
-        return isLeftToRightDirection() ? paddingRight() : paddingLeft();
-    return isLeftToRightDirection() ? paddingBottom() : paddingTop();
-}
-
 TextEmphasisMark RenderStyle::textEmphasisMark() const
 {
     TextEmphasisMark mark = static_cast<TextEmphasisMark>(rareInheritedData->textEmphasisMark);
index dc5ece0..be79144 100644 (file)
@@ -498,10 +498,10 @@ public:
     Length bottom() const { return surround->offset.bottom(); }
 
     // Accessors for positioned object edges that take into account writing mode.
-    Length logicalLeft() const { return isHorizontalWritingMode() ? left() : top(); }
-    Length logicalRight() const { return isHorizontalWritingMode() ? right() : bottom(); }
-    Length logicalTop() const { return isHorizontalWritingMode() ? (isFlippedBlocksWritingMode() ? bottom() : top()) : (isFlippedBlocksWritingMode() ? right() : left()); }
-    Length logicalBottom() const { return isHorizontalWritingMode() ? (isFlippedBlocksWritingMode() ? top() : bottom()) : (isFlippedBlocksWritingMode() ? left() : right()); }
+    Length logicalLeft() const { return surround->offset.logicalLeft(this); }
+    Length logicalRight() const { return surround->offset.logicalRight(this); }
+    Length logicalTop() const { return surround->offset.before(this); }
+    Length logicalBottom() const { return surround->offset.after(this); }
 
     // Whether or not a positioned element requires normal flow x/y to be computed
     // to determine its position.
@@ -738,24 +738,24 @@ public:
     Length marginBottom() const { return surround->margin.bottom(); }
     Length marginLeft() const { return surround->margin.left(); }
     Length marginRight() const { return surround->margin.right(); }
-    Length marginBefore() const;
-    Length marginAfter() const;
-    Length marginStart() const;
-    Length marginEnd() const;
-    Length marginStartUsing(const RenderStyle* otherStyle) const;
-    Length marginEndUsing(const RenderStyle* otherStyle) const;
-    Length marginBeforeUsing(const RenderStyle* otherStyle) const;
-    Length marginAfterUsing(const RenderStyle* otherStyle) const;
+    Length marginBefore() const { return surround->margin.before(this); }
+    Length marginAfter() const { return surround->margin.after(this); }
+    Length marginStart() const { return surround->margin.start(this); }
+    Length marginEnd() const { return surround->margin.end(this); }
+    Length marginStartUsing(const RenderStyle* otherStyle) const { return surround->margin.start(otherStyle); }
+    Length marginEndUsing(const RenderStyle* otherStyle) const { return surround->margin.end(otherStyle); }
+    Length marginBeforeUsing(const RenderStyle* otherStyle) const { return surround->margin.before(otherStyle); }
+    Length marginAfterUsing(const RenderStyle* otherStyle) const { return surround->margin.after(otherStyle); }
 
     LengthBox paddingBox() const { return surround->padding; }
     Length paddingTop() const { return surround->padding.top(); }
     Length paddingBottom() const { return surround->padding.bottom(); }
     Length paddingLeft() const { return surround->padding.left(); }
     Length paddingRight() const { return surround->padding.right(); }
-    Length paddingBefore() const;
-    Length paddingAfter() const;
-    Length paddingStart() const;
-    Length paddingEnd() const;
+    Length paddingBefore() const { return surround->padding.before(this); }
+    Length paddingAfter() const { return surround->padding.after(this); }
+    Length paddingStart() const { return surround->padding.start(this); }
+    Length paddingEnd() const { return surround->padding.end(this); }
 
     ECursor cursor() const { return static_cast<ECursor>(inherited_flags._cursor_style); }