Remove dependency on RenderStyle from FractionalLayoutBoxExtent and LayoutBox
authoreae@chromium.org <eae@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 23 Aug 2012 16:21:57 +0000 (16:21 +0000)
committereae@chromium.org <eae@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 23 Aug 2012 16:21:57 +0000 (16:21 +0000)
https://bugs.webkit.org/show_bug.cgi?id=94146

Reviewed by Eric Seidel.

FractionalLayoutBoxExtent and LayoutBox currently have a dependency on
RenderStyle to resolve writing mode and text direction.
This is undesirable and breaks encapsulation.

Change FractionalLayoutBoxExtent and LengthBox to take a writing mode
parameter, and text direction as needed, instead of a pointer to a
RenderStyle object.

No new tests, no change in functionality.

* WebCore.gypi:
* WebCore.vcproj/WebCore.vcproj:
* WebCore.xcodeproj/project.pbxproj:
Add new WritingMode.h file.

* css/CSSPrimitiveValueMappings.h:
* css/CSSProperty.h:
* css/CSSToStyleMap.h:
Change includes as needed.

* platform/LengthBox.h:
* platform/LengthBox.cpp:
(WebCore::LengthBox::logicalLeft):
(WebCore::LengthBox::logicalRight):
(WebCore::LengthBox::before):
(WebCore::LengthBox::after):
Change methods to take a WirtingMode parameter instead of a RenderStyle pointer.

(WebCore::LengthBox::start):
(WebCore::LengthBox::end):
Change methods to take WritingMode and TextDirection parameters instead of a RenderStyle pointer.

* platform/graphics/FractionalLayoutBoxExtent.h:
* platform/graphics/FractionalLayoutBoxExtent.cpp:
(WebCore::FractionalLayoutBoxExtent::logicalTop):
(WebCore::FractionalLayoutBoxExtent::logicalBottom):
(WebCore::FractionalLayoutBoxExtent::logicalLeft):
(WebCore::FractionalLayoutBoxExtent::logicalRight):
(WebCore::FractionalLayoutBoxExtent::before):
(WebCore::FractionalLayoutBoxExtent::after):
(WebCore::FractionalLayoutBoxExtent::setBefore):
(WebCore::FractionalLayoutBoxExtent::setAfter):
(WebCore::FractionalLayoutBoxExtent::mutableLogicalLeft):
(WebCore::FractionalLayoutBoxExtent::mutableLogicalRight):
(WebCore::FractionalLayoutBoxExtent::mutableBefore):
(WebCore::FractionalLayoutBoxExtent::mutableAfter):
Change methods to take a WritingMode parameter instead of a RenderStyle pointer.

(WebCore::FractionalLayoutBoxExtent::start):
(WebCore::FractionalLayoutBoxExtent::end):
(WebCore::FractionalLayoutBoxExtent::setStart):
(WebCore::FractionalLayoutBoxExtent::setEnd):
Change methods to take WritingMode and TextDirection parameters instead of a RenderStyle pointer.

* platform/text/TextDirection.h:
(WebCore::isLeftToRightDirection):
Add convenience method.

* platform/text/WritingMode.h: Added.
Move WritingMode enum from RenderStyleConstants to new file.

(WebCore::isHorizontalWritingMode):
(WebCore::isFlippedLinesWritingMode):
(WebCore::isFlippedBlocksWritingMode):
Add convenience methods for working with writing modes.

* rendering/InlineFlowBox.cpp:
* rendering/RenderBox.cpp:
* rendering/RenderBox.h:
* rendering/style/RenderStyle.h:
Update calls to FractionalLayoutBoxExtent/LengthBox to pass WritingMode/
TextDirection as needed.

* rendering/style/RenderStyleConstants.h:
Remove WritingMode enum as it is now in a dedicated file.

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

18 files changed:
Source/WebCore/ChangeLog
Source/WebCore/WebCore.gypi
Source/WebCore/WebCore.vcproj/WebCore.vcproj
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/css/CSSPrimitiveValueMappings.h
Source/WebCore/css/CSSProperty.h
Source/WebCore/css/CSSToStyleMap.h
Source/WebCore/platform/LengthBox.cpp
Source/WebCore/platform/LengthBox.h
Source/WebCore/platform/graphics/FractionalLayoutBoxExtent.cpp
Source/WebCore/platform/graphics/FractionalLayoutBoxExtent.h
Source/WebCore/platform/text/TextDirection.h
Source/WebCore/platform/text/WritingMode.h [new file with mode: 0644]
Source/WebCore/rendering/InlineFlowBox.cpp
Source/WebCore/rendering/RenderBox.cpp
Source/WebCore/rendering/RenderBox.h
Source/WebCore/rendering/style/RenderStyle.h
Source/WebCore/rendering/style/RenderStyleConstants.h

index df4df03..2966949 100644 (file)
@@ -1,3 +1,86 @@
+2012-08-23  Emil A Eklund  <eae@chromium.org>
+
+        Remove dependency on RenderStyle from FractionalLayoutBoxExtent and LayoutBox
+        https://bugs.webkit.org/show_bug.cgi?id=94146
+
+        Reviewed by Eric Seidel.
+
+        FractionalLayoutBoxExtent and LayoutBox currently have a dependency on
+        RenderStyle to resolve writing mode and text direction.
+        This is undesirable and breaks encapsulation.
+
+        Change FractionalLayoutBoxExtent and LengthBox to take a writing mode
+        parameter, and text direction as needed, instead of a pointer to a
+        RenderStyle object.
+
+        No new tests, no change in functionality.
+
+        * WebCore.gypi:
+        * WebCore.vcproj/WebCore.vcproj:
+        * WebCore.xcodeproj/project.pbxproj:
+        Add new WritingMode.h file.
+        
+        * css/CSSPrimitiveValueMappings.h:
+        * css/CSSProperty.h:
+        * css/CSSToStyleMap.h:
+        Change includes as needed.
+
+        * platform/LengthBox.h:
+        * platform/LengthBox.cpp:
+        (WebCore::LengthBox::logicalLeft):
+        (WebCore::LengthBox::logicalRight):
+        (WebCore::LengthBox::before):
+        (WebCore::LengthBox::after):
+        Change methods to take a WirtingMode parameter instead of a RenderStyle pointer.
+        
+        (WebCore::LengthBox::start):
+        (WebCore::LengthBox::end):
+        Change methods to take WritingMode and TextDirection parameters instead of a RenderStyle pointer.
+        
+        * platform/graphics/FractionalLayoutBoxExtent.h:
+        * platform/graphics/FractionalLayoutBoxExtent.cpp:
+        (WebCore::FractionalLayoutBoxExtent::logicalTop):
+        (WebCore::FractionalLayoutBoxExtent::logicalBottom):
+        (WebCore::FractionalLayoutBoxExtent::logicalLeft):
+        (WebCore::FractionalLayoutBoxExtent::logicalRight):
+        (WebCore::FractionalLayoutBoxExtent::before):
+        (WebCore::FractionalLayoutBoxExtent::after):
+        (WebCore::FractionalLayoutBoxExtent::setBefore):
+        (WebCore::FractionalLayoutBoxExtent::setAfter):
+        (WebCore::FractionalLayoutBoxExtent::mutableLogicalLeft):
+        (WebCore::FractionalLayoutBoxExtent::mutableLogicalRight):
+        (WebCore::FractionalLayoutBoxExtent::mutableBefore):
+        (WebCore::FractionalLayoutBoxExtent::mutableAfter):
+        Change methods to take a WritingMode parameter instead of a RenderStyle pointer.
+
+        (WebCore::FractionalLayoutBoxExtent::start):
+        (WebCore::FractionalLayoutBoxExtent::end):
+        (WebCore::FractionalLayoutBoxExtent::setStart):
+        (WebCore::FractionalLayoutBoxExtent::setEnd):
+        Change methods to take WritingMode and TextDirection parameters instead of a RenderStyle pointer.
+
+        * platform/text/TextDirection.h:
+        (WebCore::isLeftToRightDirection):
+        Add convenience method.
+        
+        * platform/text/WritingMode.h: Added.
+        Move WritingMode enum from RenderStyleConstants to new file.
+        
+        (WebCore::isHorizontalWritingMode):
+        (WebCore::isFlippedLinesWritingMode):
+        (WebCore::isFlippedBlocksWritingMode):
+        Add convenience methods for working with writing modes.
+        
+        * rendering/InlineFlowBox.cpp:
+        * rendering/RenderBox.cpp:
+        * rendering/RenderBox.h:
+        * rendering/style/RenderStyle.h:
+        Update calls to FractionalLayoutBoxExtent/LengthBox to pass WritingMode/
+        TextDirection as needed.
+
+        * rendering/style/RenderStyleConstants.h:
+        Remove WritingMode enum as it is now in a dedicated file.
+
 2012-08-23  Pavel Feldman  <pfeldman@chromium.org>
 
         Web Inspector: introduce canFilter on panel (otherwise we check for function existence).
index a6e62ca..0e954d7 100644 (file)
             'platform/text/TextStream.h',
             'platform/text/UnicodeBidi.h',
             'platform/text/UnicodeRange.h',
+            'platform/text/WritingMode.h',
             'platform/text/mac/CharsetData.h',
             'plugins/PluginData.h',
             'plugins/PluginMainThreadScheduler.h',
index 88752e2..8758fce 100755 (executable)
                                        >
                                </File>
                                <File
+                                       RelativePath="..\platform\text\WritingMode.h"
+                                       >
+                               </File>
+                               <File
                                        RelativePath="..\platform\graphics\WidthIterator.cpp"
                                        >
                                </File>
index d95f658..95bc870 100644 (file)
                142B97CA13138943008BEF4B /* TextControlInnerElements.h in Headers */ = {isa = PBXBuildFile; fileRef = 142B97C813138943008BEF4B /* TextControlInnerElements.h */; };
                1432E8470C51493800B1500F /* GCController.h in Headers */ = {isa = PBXBuildFile; fileRef = 1432E8460C51493800B1500F /* GCController.h */; settings = {ATTRIBUTES = (Private, ); }; };
                1432E8490C51493F00B1500F /* GCController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1432E8480C51493F00B1500F /* GCController.cpp */; };
+               14476AA815DC4BB100305DB2 /* WritingMode.h in Headers */ = {isa = PBXBuildFile; fileRef = 14476AA715DC4BB100305DB2 /* WritingMode.h */; settings = {ATTRIBUTES = (Private, ); }; };
                1449E24C107D4A8400B5793F /* JSCallbackData.h in Headers */ = {isa = PBXBuildFile; fileRef = 1449E24A107D4A8400B5793F /* JSCallbackData.h */; };
                1449E287107D4DB400B5793F /* JSCallbackData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1449E286107D4DB400B5793F /* JSCallbackData.cpp */; };
                144FCE5214EC79BC000D17A3 /* FractionalLayoutUnit.h in Headers */ = {isa = PBXBuildFile; fileRef = 144FCE5114EC79BC000D17A3 /* FractionalLayoutUnit.h */; settings = {ATTRIBUTES = (Private, ); }; };
                142B97C813138943008BEF4B /* TextControlInnerElements.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TextControlInnerElements.h; sourceTree = "<group>"; };
                1432E8460C51493800B1500F /* GCController.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = GCController.h; sourceTree = "<group>"; };
                1432E8480C51493F00B1500F /* GCController.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = GCController.cpp; sourceTree = "<group>"; };
+               14476AA715DC4BB100305DB2 /* WritingMode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WritingMode.h; sourceTree = "<group>"; };
                1449E24A107D4A8400B5793F /* JSCallbackData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSCallbackData.h; sourceTree = "<group>"; };
                1449E286107D4DB400B5793F /* JSCallbackData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSCallbackData.cpp; sourceTree = "<group>"; };
                144FCE5114EC79BC000D17A3 /* FractionalLayoutUnit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FractionalLayoutUnit.h; sourceTree = "<group>"; };
                                A863E2001343412000274926 /* UnicodeBidi.h */,
                                B2C3DA1C0D006C1D00EF6F26 /* UnicodeRange.cpp */,
                                B2C3DA1D0D006C1D00EF6F26 /* UnicodeRange.h */,
+                               14476AA715DC4BB100305DB2 /* WritingMode.h */,
                        );
                        path = text;
                        sourceTree = "<group>";
                                977E2E0F12F0FC9C00C13379 /* XSSAuditor.h in Headers */,
                                FD537353137B651800008DCE /* ZeroPole.h in Headers */,
                                9377ABA015DEFEEF0031FD04 /* Pagination.h in Headers */,
+                               14476AA815DC4BB100305DB2 /* WritingMode.h in Headers */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
index c39a9c0..806605f 100644 (file)
@@ -50,6 +50,7 @@
 #include "TextRenderingMode.h"
 #include "ThemeTypes.h"
 #include "UnicodeBidi.h"
+#include "WritingMode.h"
 
 #if ENABLE(CSS_SHADERS)
 #include "CustomFilterOperation.h"
index 57a3012..7afaa75 100644 (file)
@@ -25,6 +25,7 @@
 #include "CSSValue.h"
 #include "RenderStyleConstants.h"
 #include "TextDirection.h"
+#include "WritingMode.h"
 #include <wtf/PassRefPtr.h>
 #include <wtf/RefPtr.h>
 
index 8e0fc95..6bab40b 100644 (file)
@@ -30,6 +30,7 @@ namespace WebCore {
 class FillLayer;
 class CSSValue;
 class Animation;
+class RenderStyle;
 class StyleImage;
 class StyleResolver;
 class NinePieceImage;
index 4aa7451..a5205f2 100644 (file)
 #include "config.h"
 #include "LengthBox.h"
 
-#include "RenderStyle.h"
-
 namespace WebCore {
 
-Length LengthBox::logicalLeft(const RenderStyle* style) const
+Length LengthBox::logicalLeft(WritingMode writingMode) const
 {
-    return style->isHorizontalWritingMode() ? m_left : m_top;
+    return isHorizontalWritingMode(writingMode) ? m_left : m_top;
 }
 
-Length LengthBox::logicalRight(const RenderStyle* style) const
+Length LengthBox::logicalRight(WritingMode writingMode) const
 {
-    return style->isHorizontalWritingMode() ? m_right : m_bottom;
+    return isHorizontalWritingMode(writingMode) ? m_right : m_bottom;
 }
 
-Length LengthBox::before(const RenderStyle* style) const
+Length LengthBox::before(WritingMode writingMode) const
 {
-    switch (style->writingMode()) {
+    switch (writingMode) {
     case TopToBottomWritingMode:
         return m_top;
     case BottomToTopWritingMode:
@@ -61,9 +59,9 @@ Length LengthBox::before(const RenderStyle* style) const
     return m_top;
 }
 
-Length LengthBox::after(const RenderStyle* style) const
+Length LengthBox::after(WritingMode writingMode) const
 {
-    switch (style->writingMode()) {
+    switch (writingMode) {
     case TopToBottomWritingMode:
         return m_bottom;
     case BottomToTopWritingMode:
@@ -77,18 +75,18 @@ Length LengthBox::after(const RenderStyle* style) const
     return m_bottom;
 }
 
-Length LengthBox::start(const RenderStyle* style) const
+Length LengthBox::start(WritingMode writingMode, TextDirection direction) const
 {
-    if (style->isHorizontalWritingMode())
-        return style->isLeftToRightDirection() ? m_left : m_right;
-    return style->isLeftToRightDirection() ? m_top : m_bottom;
+    if (isHorizontalWritingMode(writingMode))
+        return isLeftToRightDirection(direction) ? m_left : m_right;
+    return isLeftToRightDirection(direction) ? m_top : m_bottom;
 }
 
-Length LengthBox::end(const RenderStyle* style) const
+Length LengthBox::end(WritingMode writingMode, TextDirection direction) const
 {
-    if (style->isHorizontalWritingMode())
-        return style->isLeftToRightDirection() ? m_right : m_left;
-    return style->isLeftToRightDirection() ? m_bottom : m_top;
+    if (isHorizontalWritingMode(writingMode))
+        return isLeftToRightDirection(direction) ? m_right : m_left;
+    return isLeftToRightDirection(direction) ? m_bottom : m_top;
 }
 
 } // namespace WebCore
index 389cb66..d5dfc13 100644 (file)
@@ -23,6 +23,8 @@
 #define LengthBox_h
 
 #include "Length.h"
+#include "TextDirection.h"
+#include "WritingMode.h"
 
 namespace WebCore {
 
@@ -70,13 +72,13 @@ 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 logicalLeft(WritingMode) const;
+    Length logicalRight(WritingMode) const;
 
-    Length before(const RenderStyle*) const;
-    Length after(const RenderStyle*) const;
-    Length start(const RenderStyle*) const;
-    Length end(const RenderStyle*) const;
+    Length before(WritingMode) const;
+    Length after(WritingMode) const;
+    Length start(WritingMode, TextDirection) const;
+    Length end(WritingMode, TextDirection) const;
 
     bool operator==(const LengthBox& o) const
     {
index e4e545a..f1c4e5b 100644 (file)
 #include "config.h"
 #include "FractionalLayoutBoxExtent.h"
 
-#include "RenderStyle.h"
-
 namespace WebCore {
 
-FractionalLayoutUnit FractionalLayoutBoxExtent::logicalTop(const RenderStyle* style) const
+FractionalLayoutUnit FractionalLayoutBoxExtent::logicalTop(WritingMode writingMode) const
 {
-    return style->isHorizontalWritingMode() ? m_top : m_left;
+    return isHorizontalWritingMode(writingMode) ? m_top : m_left;
 }
 
-FractionalLayoutUnit FractionalLayoutBoxExtent::logicalBottom(const RenderStyle* style) const
+FractionalLayoutUnit FractionalLayoutBoxExtent::logicalBottom(WritingMode writingMode) const
 {
-    return style->isHorizontalWritingMode() ? m_bottom : m_right;
+    return isHorizontalWritingMode(writingMode) ? m_bottom : m_right;
 }
 
-FractionalLayoutUnit FractionalLayoutBoxExtent::logicalLeft(const RenderStyle* style) const
+FractionalLayoutUnit FractionalLayoutBoxExtent::logicalLeft(WritingMode writingMode) const
 {
-    return style->isHorizontalWritingMode() ? m_left : m_top;
+    return isHorizontalWritingMode(writingMode) ? m_left : m_top;
 }
 
-FractionalLayoutUnit FractionalLayoutBoxExtent::logicalRight(const RenderStyle* style) const
+FractionalLayoutUnit FractionalLayoutBoxExtent::logicalRight(WritingMode writingMode) const
 {
-    return style->isHorizontalWritingMode() ? m_right : m_bottom;
+    return isHorizontalWritingMode(writingMode) ? m_right : m_bottom;
 }
 
-FractionalLayoutUnit FractionalLayoutBoxExtent::before(const RenderStyle* style) const
+FractionalLayoutUnit FractionalLayoutBoxExtent::before(WritingMode writingMode) const
 {
-    switch (style->writingMode()) {
+    switch (writingMode) {
     case TopToBottomWritingMode:
         return m_top;
     case BottomToTopWritingMode:
@@ -71,9 +69,9 @@ FractionalLayoutUnit FractionalLayoutBoxExtent::before(const RenderStyle* style)
     return m_top;
 }
 
-FractionalLayoutUnit FractionalLayoutBoxExtent::after(const RenderStyle* style) const
+FractionalLayoutUnit FractionalLayoutBoxExtent::after(WritingMode writingMode) const
 {
-    switch (style->writingMode()) {
+    switch (writingMode) {
     case TopToBottomWritingMode:
         return m_bottom;
     case BottomToTopWritingMode:
@@ -87,23 +85,23 @@ FractionalLayoutUnit FractionalLayoutBoxExtent::after(const RenderStyle* style)
     return m_bottom;
 }
 
-FractionalLayoutUnit FractionalLayoutBoxExtent::start(const RenderStyle* style) const
+FractionalLayoutUnit FractionalLayoutBoxExtent::start(WritingMode writingMode, TextDirection direction) const
 {
-    if (style->isHorizontalWritingMode())
-        return style->isLeftToRightDirection() ? m_left : m_right;
-    return style->isLeftToRightDirection() ? m_top : m_bottom;
+    if (isHorizontalWritingMode(writingMode))
+        return isLeftToRightDirection(direction) ? m_left : m_right;
+    return isLeftToRightDirection(direction) ? m_top : m_bottom;
 }
 
-FractionalLayoutUnit FractionalLayoutBoxExtent::end(const RenderStyle* style) const
+FractionalLayoutUnit FractionalLayoutBoxExtent::end(WritingMode writingMode, TextDirection direction) const
 {
-    if (style->isHorizontalWritingMode())
-        return style->isLeftToRightDirection() ? m_right : m_left;
-    return style->isLeftToRightDirection() ? m_bottom : m_top;
+    if (isHorizontalWritingMode(writingMode))
+        return isLeftToRightDirection(direction) ? m_right : m_left;
+    return isLeftToRightDirection(direction) ? m_bottom : m_top;
 }
 
-void FractionalLayoutBoxExtent::setBefore(const RenderStyle* style, FractionalLayoutUnit value)
+void FractionalLayoutBoxExtent::setBefore(WritingMode writingMode, FractionalLayoutUnit value)
 {
-    switch (style->writingMode()) {
+    switch (writingMode) {
     case TopToBottomWritingMode:
         m_top = value;
         break;
@@ -122,9 +120,9 @@ void FractionalLayoutBoxExtent::setBefore(const RenderStyle* style, FractionalLa
     }
 }
 
-void FractionalLayoutBoxExtent::setAfter(const RenderStyle* style, FractionalLayoutUnit value)
+void FractionalLayoutBoxExtent::setAfter(WritingMode writingMode, FractionalLayoutUnit value)
 {
-    switch (style->writingMode()) {
+    switch (writingMode) {
     case TopToBottomWritingMode:
         m_bottom = value;
         break;
@@ -143,56 +141,56 @@ void FractionalLayoutBoxExtent::setAfter(const RenderStyle* style, FractionalLay
     }
 }
 
-void FractionalLayoutBoxExtent::setStart(const RenderStyle* style, FractionalLayoutUnit value)
+void FractionalLayoutBoxExtent::setStart(WritingMode writingMode, TextDirection direction, FractionalLayoutUnit value)
 {
-    if (style->isHorizontalWritingMode()) {
-        if (style->isLeftToRightDirection())
+    if (isHorizontalWritingMode(writingMode)) {
+        if (isLeftToRightDirection(direction))
             m_left = value;
         else
             m_right = value;
     } else {
-        if (style->isLeftToRightDirection())
+        if (isLeftToRightDirection(direction))
             m_top = value;
         else
             m_bottom = value;
     }
 }
 
-void FractionalLayoutBoxExtent::setEnd(const RenderStyle* style, FractionalLayoutUnit value)
+void FractionalLayoutBoxExtent::setEnd(WritingMode writingMode, TextDirection direction, FractionalLayoutUnit value)
 {
-    if (style->isHorizontalWritingMode()) {
-        if (style->isLeftToRightDirection())
+    if (isHorizontalWritingMode(writingMode)) {
+        if (isLeftToRightDirection(direction))
             m_right = value;
         else
             m_left = value;
     } else {
-        if (style->isLeftToRightDirection())
+        if (isLeftToRightDirection(direction))
             m_bottom = value;
         else
             m_top = value;
     }
 }
 
-FractionalLayoutUnit& FractionalLayoutBoxExtent::mutableLogicalLeft(const RenderStyle* style)
+FractionalLayoutUnit& FractionalLayoutBoxExtent::mutableLogicalLeft(WritingMode writingMode)
 {
-    return style->isHorizontalWritingMode() ? m_left : m_top;
+    return isHorizontalWritingMode(writingMode) ? m_left : m_top;
 }
 
-FractionalLayoutUnit& FractionalLayoutBoxExtent::mutableLogicalRight(const RenderStyle* style)
+FractionalLayoutUnit& FractionalLayoutBoxExtent::mutableLogicalRight(WritingMode writingMode)
 {
-    return style->isHorizontalWritingMode() ? m_right : m_bottom;
+    return isHorizontalWritingMode(writingMode) ? m_right : m_bottom;
 }
 
-FractionalLayoutUnit& FractionalLayoutBoxExtent::mutableBefore(const RenderStyle* style)
+FractionalLayoutUnit& FractionalLayoutBoxExtent::mutableBefore(WritingMode writingMode)
 {
-    return style->isHorizontalWritingMode() ? (style->isFlippedBlocksWritingMode() ? m_bottom : m_top) :
-                                              (style->isFlippedBlocksWritingMode() ? m_right: m_left);
+    return isHorizontalWritingMode(writingMode) ? (isFlippedBlocksWritingMode(writingMode) ? m_bottom : m_top) :
+                                                  (isFlippedBlocksWritingMode(writingMode) ? m_right: m_left);
 }
 
-FractionalLayoutUnit& FractionalLayoutBoxExtent::mutableAfter(const RenderStyle* style)
+FractionalLayoutUnit& FractionalLayoutBoxExtent::mutableAfter(WritingMode writingMode)
 {
-    return style->isHorizontalWritingMode() ? (style->isFlippedBlocksWritingMode() ? m_top : m_bottom) :
-                                              (style->isFlippedBlocksWritingMode() ? m_left: m_right);
+    return isHorizontalWritingMode(writingMode) ? (isFlippedBlocksWritingMode(writingMode) ? m_top : m_bottom) :
+                                                  (isFlippedBlocksWritingMode(writingMode) ? m_left: m_right);
 }
 
 } // namespace WebCore
index 921c84b..28bdb9c 100644 (file)
 #define FractionalLayoutBoxExtent_h
 
 #include "FractionalLayoutUnit.h"
+#include "TextDirection.h"
+#include "WritingMode.h"
 
 namespace WebCore {
 
-class RenderStyle;
-
 class FractionalLayoutBoxExtent {
 public:
     FractionalLayoutBoxExtent() : m_top(0), m_right(0), m_bottom(0), m_left(0) { }
@@ -53,26 +53,26 @@ public:
     inline void setBottom(FractionalLayoutUnit value) { m_bottom = value; }
     inline void setLeft(FractionalLayoutUnit value) { m_left = value; }
 
-    FractionalLayoutUnit logicalTop(const RenderStyle*) const;
-    FractionalLayoutUnit logicalBottom(const RenderStyle*) const;
-    FractionalLayoutUnit logicalLeft(const RenderStyle*) const;
-    FractionalLayoutUnit logicalRight(const RenderStyle*) const;
+    FractionalLayoutUnit logicalTop(WritingMode) const;
+    FractionalLayoutUnit logicalBottom(WritingMode) const;
+    FractionalLayoutUnit logicalLeft(WritingMode) const;
+    FractionalLayoutUnit logicalRight(WritingMode) const;
 
-    FractionalLayoutUnit before(const RenderStyle*) const;
-    FractionalLayoutUnit after(const RenderStyle*) const;
-    FractionalLayoutUnit start(const RenderStyle*) const;
-    FractionalLayoutUnit end(const RenderStyle*) const;
+    FractionalLayoutUnit before(WritingMode) const;
+    FractionalLayoutUnit after(WritingMode) const;
+    FractionalLayoutUnit start(WritingMode, TextDirection) const;
+    FractionalLayoutUnit end(WritingMode, TextDirection) const;
 
-    void setBefore(const RenderStyle*, FractionalLayoutUnit);
-    void setAfter(const RenderStyle*, FractionalLayoutUnit);
-    void setStart(const RenderStyle*, FractionalLayoutUnit);
-    void setEnd(const RenderStyle*, FractionalLayoutUnit);
+    void setBefore(WritingMode, FractionalLayoutUnit);
+    void setAfter(WritingMode, FractionalLayoutUnit);
+    void setStart(WritingMode, TextDirection, FractionalLayoutUnit);
+    void setEnd(WritingMode, TextDirection, FractionalLayoutUnit);
 
-    FractionalLayoutUnit& mutableLogicalLeft(const RenderStyle*);
-    FractionalLayoutUnit& mutableLogicalRight(const RenderStyle*);
+    FractionalLayoutUnit& mutableLogicalLeft(WritingMode);
+    FractionalLayoutUnit& mutableLogicalRight(WritingMode);
 
-    FractionalLayoutUnit& mutableBefore(const RenderStyle*);
-    FractionalLayoutUnit& mutableAfter(const RenderStyle*);
+    FractionalLayoutUnit& mutableBefore(WritingMode);
+    FractionalLayoutUnit& mutableAfter(WritingMode);
 
 private:
     FractionalLayoutUnit m_top;
index 5be416e..9a074c8 100644 (file)
@@ -28,7 +28,9 @@
 
 namespace WebCore {
 
-    enum TextDirection { RTL, LTR };
+enum TextDirection { RTL, LTR };
+
+inline bool isLeftToRightDirection(TextDirection direction) { return direction == LTR; }
 
 }
 
diff --git a/Source/WebCore/platform/text/WritingMode.h b/Source/WebCore/platform/text/WritingMode.h
new file mode 100644 (file)
index 0000000..9a4a206
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * 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.
+ */
+
+#ifndef WritingMode_h
+#define WritingMode_h
+
+namespace WebCore {
+
+enum WritingMode {
+    TopToBottomWritingMode, RightToLeftWritingMode, LeftToRightWritingMode, BottomToTopWritingMode
+};
+
+inline bool isHorizontalWritingMode(WritingMode writingMode)
+{
+    return writingMode == TopToBottomWritingMode || writingMode == BottomToTopWritingMode;
+}
+
+inline bool isFlippedLinesWritingMode(WritingMode writingMode)
+{
+    return writingMode == LeftToRightWritingMode || writingMode == BottomToTopWritingMode;
+}
+
+inline bool isFlippedBlocksWritingMode(WritingMode writingMode)
+{
+    return writingMode == RightToLeftWritingMode || writingMode == BottomToTopWritingMode;
+}
+
+} // namespace WebCore
+
+#endif // WritingMode_h
index c3da100..126db27 100644 (file)
@@ -792,10 +792,10 @@ inline void InlineFlowBox::addBorderOutsetVisualOverflow(LayoutRect& logicalVisu
 
     FractionalLayoutBoxExtent borderOutsets = style->borderImageOutsets();
 
-    LayoutUnit borderOutsetLogicalTop = borderOutsets.logicalTop(style);
-    LayoutUnit borderOutsetLogicalBottom = borderOutsets.logicalBottom(style);
-    LayoutUnit borderOutsetLogicalLeft = borderOutsets.logicalLeft(style);
-    LayoutUnit borderOutsetLogicalRight = borderOutsets.logicalRight(style);
+    LayoutUnit borderOutsetLogicalTop = borderOutsets.logicalTop(style->writingMode());
+    LayoutUnit borderOutsetLogicalBottom = borderOutsets.logicalBottom(style->writingMode());
+    LayoutUnit borderOutsetLogicalLeft = borderOutsets.logicalLeft(style->writingMode());
+    LayoutUnit borderOutsetLogicalRight = borderOutsets.logicalRight(style->writingMode());
 
     // Similar to how glyph overflow works, if our lines are flipped, then it's actually the opposite border that applies, since
     // the line is "upside down" in terms of block coordinates. vertical-rl and horizontal-bt are the flipped line modes.
index a0056e0..361a5c9 100644 (file)
@@ -2538,8 +2538,8 @@ void RenderBox::computePositionedLogicalWidth(RenderRegion* region, LayoutUnit o
     const LayoutUnit bordersPlusPadding = borderAndPaddingLogicalWidth();
     const Length marginLogicalLeft = isHorizontal ? style()->marginLeft() : style()->marginTop();
     const Length marginLogicalRight = isHorizontal ? style()->marginRight() : style()->marginBottom();
-    LayoutUnit& marginLogicalLeftAlias = m_marginBox.mutableLogicalLeft(style());
-    LayoutUnit& marginLogicalRightAlias = m_marginBox.mutableLogicalRight(style());
+    LayoutUnit& marginLogicalLeftAlias = m_marginBox.mutableLogicalLeft(style()->writingMode());
+    LayoutUnit& marginLogicalRightAlias = m_marginBox.mutableLogicalRight(style()->writingMode());
 
     Length logicalLeftLength = style()->logicalLeft();
     Length logicalRightLength = style()->logicalRight();
@@ -2878,8 +2878,8 @@ void RenderBox::computePositionedLogicalHeight()
     const LayoutUnit bordersPlusPadding = borderAndPaddingLogicalHeight();
     const Length marginBefore = styleToUse->marginBefore();
     const Length marginAfter = styleToUse->marginAfter();
-    LayoutUnit& marginBeforeAlias = m_marginBox.mutableBefore(styleToUse);
-    LayoutUnit& marginAfterAlias = m_marginBox.mutableAfter(styleToUse);
+    LayoutUnit& marginBeforeAlias = m_marginBox.mutableBefore(styleToUse->writingMode());
+    LayoutUnit& marginAfterAlias = m_marginBox.mutableAfter(styleToUse->writingMode());
 
     Length logicalTopLength = styleToUse->logicalTop();
     Length logicalBottomLength = styleToUse->logicalBottom();
@@ -3145,8 +3145,8 @@ void RenderBox::computePositionedLogicalWidthReplaced()
     Length logicalRight = style()->logicalRight();
     Length marginLogicalLeft = isHorizontal ? style()->marginLeft() : style()->marginTop();
     Length marginLogicalRight = isHorizontal ? style()->marginRight() : style()->marginBottom();
-    LayoutUnit& marginLogicalLeftAlias = m_marginBox.mutableLogicalLeft(style());
-    LayoutUnit& marginLogicalRightAlias = m_marginBox.mutableLogicalRight(style());
+    LayoutUnit& marginLogicalLeftAlias = m_marginBox.mutableLogicalLeft(style()->writingMode());
+    LayoutUnit& marginLogicalRightAlias = m_marginBox.mutableLogicalRight(style()->writingMode());
 
     /*-----------------------------------------------------------------------*\
      * 1. The used value of 'width' is determined as for inline replaced
@@ -3306,8 +3306,8 @@ void RenderBox::computePositionedLogicalHeightReplaced()
     // Variables to solve.
     Length marginBefore = style()->marginBefore();
     Length marginAfter = style()->marginAfter();
-    LayoutUnit& marginBeforeAlias = m_marginBox.mutableBefore(style());
-    LayoutUnit& marginAfterAlias = m_marginBox.mutableAfter(style());
+    LayoutUnit& marginBeforeAlias = m_marginBox.mutableBefore(style()->writingMode());
+    LayoutUnit& marginAfterAlias = m_marginBox.mutableAfter(style()->writingMode());
 
     Length logicalTop = style()->logicalTop();
     Length logicalBottom = style()->logicalBottom();
index 00b05f4..0bd773f 100644 (file)
@@ -234,17 +234,33 @@ public:
     void setMarginLeft(LayoutUnit margin) { m_marginBox.setLeft(margin); }
     void setMarginRight(LayoutUnit margin) { m_marginBox.setRight(margin); }
 
-    virtual LayoutUnit marginLogicalLeft() const { return m_marginBox.logicalLeft(style()); }
-    virtual LayoutUnit marginLogicalRight() const { return m_marginBox.logicalRight(style()); }
+    virtual LayoutUnit marginLogicalLeft() const { return m_marginBox.logicalLeft(style()->writingMode()); }
+    virtual LayoutUnit marginLogicalRight() const { return m_marginBox.logicalRight(style()->writingMode()); }
     
-    virtual LayoutUnit marginBefore(const RenderStyle* overrideStyle = 0) const OVERRIDE { return m_marginBox.before(overrideStyle ? overrideStyle : style()); }
-    virtual LayoutUnit marginAfter(const RenderStyle* overrideStyle = 0) const OVERRIDE { return m_marginBox.after(overrideStyle ? overrideStyle : style()); }
-    virtual LayoutUnit marginStart(const RenderStyle* overrideStyle = 0) const OVERRIDE { return m_marginBox.start(overrideStyle ? overrideStyle : style()); }
-    virtual LayoutUnit marginEnd(const RenderStyle* overrideStyle = 0) const OVERRIDE { return m_marginBox.end(overrideStyle ? overrideStyle : style()); }
-    void setMarginBefore(LayoutUnit value, const RenderStyle* overrideStyle = 0) { m_marginBox.setBefore(overrideStyle ? overrideStyle : style(), value); }
-    void setMarginAfter(LayoutUnit value, const RenderStyle* overrideStyle = 0) { m_marginBox.setAfter(overrideStyle ? overrideStyle : style(), value); }
-    void setMarginStart(LayoutUnit value, const RenderStyle* overrideStyle = 0) { m_marginBox.setStart(overrideStyle ? overrideStyle : style(), value); }
-    void setMarginEnd(LayoutUnit value, const RenderStyle* overrideStyle = 0) { m_marginBox.setEnd(overrideStyle ? overrideStyle : style(), value); }
+    virtual LayoutUnit marginBefore(const RenderStyle* overrideStyle = 0) const OVERRIDE { return m_marginBox.before((overrideStyle ? overrideStyle : style())->writingMode()); }
+    virtual LayoutUnit marginAfter(const RenderStyle* overrideStyle = 0) const OVERRIDE { return m_marginBox.after((overrideStyle ? overrideStyle : style())->writingMode()); }
+    virtual LayoutUnit marginStart(const RenderStyle* overrideStyle = 0) const OVERRIDE
+    {
+        const RenderStyle* styleToUse = overrideStyle ? overrideStyle : style();
+        return m_marginBox.start(styleToUse->writingMode(), styleToUse->direction());
+    }
+    virtual LayoutUnit marginEnd(const RenderStyle* overrideStyle = 0) const OVERRIDE
+    {
+        const RenderStyle* styleToUse = overrideStyle ? overrideStyle : style();
+        return m_marginBox.end(styleToUse->writingMode(), styleToUse->direction());
+    }
+    void setMarginBefore(LayoutUnit value, const RenderStyle* overrideStyle = 0) { m_marginBox.setBefore((overrideStyle ? overrideStyle : style())->writingMode(), value); }
+    void setMarginAfter(LayoutUnit value, const RenderStyle* overrideStyle = 0) { m_marginBox.setAfter((overrideStyle ? overrideStyle : style())->writingMode(), value); }
+    void setMarginStart(LayoutUnit value, const RenderStyle* overrideStyle = 0)
+    {
+        const RenderStyle* styleToUse = overrideStyle ? overrideStyle : style();
+        m_marginBox.setStart(styleToUse->writingMode(), styleToUse->direction(), value);
+    }
+    void setMarginEnd(LayoutUnit value, const RenderStyle* overrideStyle = 0)
+    {
+        const RenderStyle* styleToUse = overrideStyle ? overrideStyle : style();
+        m_marginBox.setEnd(styleToUse->writingMode(), styleToUse->direction(), value);
+    }
 
     // The following five functions are used to implement collapsing margins.
     // All objects know their maximal positive and negative margins.  The
index 011950c..b647828 100644 (file)
@@ -496,10 +496,10 @@ public:
     Length bottom() const { return surround->offset.bottom(); }
 
     // Accessors for positioned object edges that take into account writing mode.
-    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); }
+    Length logicalLeft() const { return surround->offset.logicalLeft(writingMode()); }
+    Length logicalRight() const { return surround->offset.logicalRight(writingMode()); }
+    Length logicalTop() const { return surround->offset.before(writingMode()); }
+    Length logicalBottom() const { return surround->offset.after(writingMode()); }
 
     // Whether or not a positioned element requires normal flow x/y to be computed
     // to determine its position.
@@ -728,24 +728,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 { 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); }
+    Length marginBefore() const { return surround->margin.before(writingMode()); }
+    Length marginAfter() const { return surround->margin.after(writingMode()); }
+    Length marginStart() const { return surround->margin.start(writingMode(), direction()); }
+    Length marginEnd() const { return surround->margin.end(writingMode(), direction()); }
+    Length marginStartUsing(const RenderStyle* otherStyle) const { return surround->margin.start(otherStyle->writingMode(), otherStyle->direction()); }
+    Length marginEndUsing(const RenderStyle* otherStyle) const { return surround->margin.end(otherStyle->writingMode(), otherStyle->direction()); }
+    Length marginBeforeUsing(const RenderStyle* otherStyle) const { return surround->margin.before(otherStyle->writingMode()); }
+    Length marginAfterUsing(const RenderStyle* otherStyle) const { return surround->margin.after(otherStyle->writingMode()); }
 
     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 { 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); }
+    Length paddingBefore() const { return surround->padding.before(writingMode()); }
+    Length paddingAfter() const { return surround->padding.after(writingMode()); }
+    Length paddingStart() const { return surround->padding.start(writingMode(), direction()); }
+    Length paddingEnd() const { return surround->padding.end(writingMode(), direction()); }
 
     ECursor cursor() const { return static_cast<ECursor>(inherited_flags._cursor_style); }
 
index 880b622..6d967cb 100644 (file)
@@ -130,11 +130,6 @@ enum ETableLayout {
     TAUTO, TFIXED
 };
 
-// CSS Text Layout Module Level 3: Vertical writing support
-enum WritingMode {
-    TopToBottomWritingMode, RightToLeftWritingMode, LeftToRightWritingMode, BottomToTopWritingMode
-};
-
 enum TextCombine {
     TextCombineNone, TextCombineHorizontal
 };