Code clean up for extracting information from the mix of WritingMode and TextDirection
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 28 May 2015 21:55:32 +0000 (21:55 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 28 May 2015 21:55:32 +0000 (21:55 +0000)
https://bugs.webkit.org/show_bug.cgi?id=143399

Patch by Said Abou-Hallawa <sabouhallawa@apple.com> on 2015-05-28
Reviewed by Darin Adler.
Source/WebCore:

There should be eight TextFlows. A TextFlow consists of two directions.
The first one controls the inline growing direction and the second one
controls the block growing direction. We are going to use the cardinal
directions to define these combinations.

We need to extract the following information easily from the TextFlow

-- isTextFlowReversed() // RTL
-- isTextFlowFlipped()  // the opposite direction to normal
-- isTextFlowVertical() // The line grows vertically

Mixing WritingMode and TextDirection into TextFlow and choosing their values
carefully to ease implementing the above functions can make things clearer.

* Modules/notifications/Notification.h:
* platform/graphics/TextRun.h:
* platform/ios/SelectionRect.h:
* platform/text/BidiResolver.h:
* platform/text/StringWithDirection.h:
* platform/text/TextFlags.h:
(WebCore::isLeftToRightDirection): Deleted.
enum TextDirection is moved from TextFlags.h to WritingMode.h. So include
WritingMode.h instead of including TextFlags.h.

* css/CSSProperty.cpp:
(WebCore::resolveToPhysicalProperty): Instead of handling the eight possible
cases of the text flows one by one, we can map from a LogicalSide to a
PhysicalSide using the TextFlow value.

* platform/LengthBox.h:
(WebCore::BoxExtent::before):
(WebCore::BoxExtent::after):
(WebCore::BoxExtent::start):
(WebCore::BoxExtent::end):
Use mapLogicalSideToPhysicalSide() to convert from a LogicalSide to a PhysicalSide.

* platform/text/WritingMode.h:
(WebCore::isLeftToRightDirection): Usually the default enum is defined
first. And usually the default value is equal to zero. Since LTR is the
default for the text direction, it should be defined before RTL.

(WebCore::makeTextFlow): Returns a TextFlow given a WritingMode and a
TextDirection.

(WebCore::isReversedTextFlow): Returns true if the text direction is RTL.

(WebCore::isFlippedTextFlow):
(WebCore::isFlippedWritingMode): Returns true if the block growing direction
is in the opposite direction of normal.

(WebCore::isVerticalTextFlow):
(WebCore::isVerticalWritingMode): Returns true if the line grows vertically.

(WebCore::isHorizontalWritingMode):
(WebCore::isFlippedLinesWritingMode): Use isVerticalWritingMode() and
isFlippedWritingMode() to answer these questions.

(WebCore::isHorizontalPhysicalSide):
(WebCore::mirrorPhysicalSide): top <-> bottom and left <-> right conversion.
(WebCore::rotatePhysicalSide): top <-> left and right <-> bottom conversion.

(WebCore::mapLogicalSideToPhysicalSide): Maps a LogicalSide to a PhysicalSide
using either the TextFlow or the WritingMode.

(WebCore::isFlippedBlocksWritingMode): Deleted.
* rendering/RenderMultiColumnSet.cpp:
(WebCore::RenderMultiColumnSet::collectLayerFragments):
(WebCore::RenderMultiColumnSet::columnTranslationForOffset):
* rendering/shapes/Shape.cpp:
(WebCore::physicalRectToLogical):
(WebCore::physicalPointToLogical):
* rendering/style/RenderStyle.h:
Rename isFlippedBlocksWritingMode() to be isFlippedWritingMode() so we can
be consistent with other WritingMode query functions.

Source/WebKit2:

* Shared/WebPopupItem.h:
* UIProcess/API/C/efl/WKAPICastEfl.h:
* UIProcess/WebPopupMenuProxy.h:
enum TextDirection is moved from TextFlags.h to WritingMode.h. So include
WritingMode.h instead of including TextFlags.h.

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

18 files changed:
Source/WebCore/ChangeLog
Source/WebCore/Modules/notifications/Notification.h
Source/WebCore/css/CSSProperty.cpp
Source/WebCore/css/CSSProperty.h
Source/WebCore/platform/LengthBox.h
Source/WebCore/platform/graphics/TextRun.h
Source/WebCore/platform/ios/SelectionRect.h
Source/WebCore/platform/text/BidiResolver.h
Source/WebCore/platform/text/StringWithDirection.h
Source/WebCore/platform/text/TextFlags.h
Source/WebCore/platform/text/WritingMode.h
Source/WebCore/rendering/RenderMultiColumnSet.cpp
Source/WebCore/rendering/shapes/Shape.cpp
Source/WebCore/rendering/style/RenderStyle.h
Source/WebKit2/ChangeLog
Source/WebKit2/Shared/WebPopupItem.h
Source/WebKit2/UIProcess/API/C/efl/WKAPICastEfl.h
Source/WebKit2/UIProcess/WebPopupMenuProxy.h

index 349cce0..6eae58a 100644 (file)
@@ -1,3 +1,85 @@
+2015-05-28  Said Abou-Hallawa  <sabouhallawa@apple.com>
+
+        Code clean up for extracting information from the mix of WritingMode and TextDirection
+        https://bugs.webkit.org/show_bug.cgi?id=143399
+
+        Reviewed by Darin Adler.
+        
+        There should be eight TextFlows. A TextFlow consists of two directions.
+        The first one controls the inline growing direction and the second one
+        controls the block growing direction. We are going to use the cardinal
+        directions to define these combinations.
+
+        We need to extract the following information easily from the TextFlow
+
+        -- isTextFlowReversed() // RTL
+        -- isTextFlowFlipped()  // the opposite direction to normal
+        -- isTextFlowVertical() // The line grows vertically
+        
+        Mixing WritingMode and TextDirection into TextFlow and choosing their values
+        carefully to ease implementing the above functions can make things clearer.
+
+        * Modules/notifications/Notification.h:
+        * platform/graphics/TextRun.h:
+        * platform/ios/SelectionRect.h:
+        * platform/text/BidiResolver.h:
+        * platform/text/StringWithDirection.h:
+        * platform/text/TextFlags.h:
+        (WebCore::isLeftToRightDirection): Deleted.
+        enum TextDirection is moved from TextFlags.h to WritingMode.h. So include
+        WritingMode.h instead of including TextFlags.h.
+        
+        * css/CSSProperty.cpp:
+        (WebCore::resolveToPhysicalProperty): Instead of handling the eight possible
+        cases of the text flows one by one, we can map from a LogicalSide to a
+        PhysicalSide using the TextFlow value.
+        
+        * platform/LengthBox.h:
+        (WebCore::BoxExtent::before):
+        (WebCore::BoxExtent::after):
+        (WebCore::BoxExtent::start):
+        (WebCore::BoxExtent::end):
+        Use mapLogicalSideToPhysicalSide() to convert from a LogicalSide to a PhysicalSide.
+        
+        * platform/text/WritingMode.h:
+        (WebCore::isLeftToRightDirection): Usually the default enum is defined
+        first. And usually the default value is equal to zero. Since LTR is the
+        default for the text direction, it should be defined before RTL.
+        
+        (WebCore::makeTextFlow): Returns a TextFlow given a WritingMode and a
+        TextDirection.
+        
+        (WebCore::isReversedTextFlow): Returns true if the text direction is RTL.
+        
+        (WebCore::isFlippedTextFlow):
+        (WebCore::isFlippedWritingMode): Returns true if the block growing direction
+        is in the opposite direction of normal.
+        
+        (WebCore::isVerticalTextFlow):
+        (WebCore::isVerticalWritingMode): Returns true if the line grows vertically.
+               
+        (WebCore::isHorizontalWritingMode):
+        (WebCore::isFlippedLinesWritingMode): Use isVerticalWritingMode() and 
+        isFlippedWritingMode() to answer these questions.
+        
+        (WebCore::isHorizontalPhysicalSide): 
+        (WebCore::mirrorPhysicalSide): top <-> bottom and left <-> right conversion.
+        (WebCore::rotatePhysicalSide): top <-> left and right <-> bottom conversion.
+        
+        (WebCore::mapLogicalSideToPhysicalSide): Maps a LogicalSide to a PhysicalSide
+        using either the TextFlow or the WritingMode.
+        
+        (WebCore::isFlippedBlocksWritingMode): Deleted.
+        * rendering/RenderMultiColumnSet.cpp:
+        (WebCore::RenderMultiColumnSet::collectLayerFragments):
+        (WebCore::RenderMultiColumnSet::columnTranslationForOffset):
+        * rendering/shapes/Shape.cpp:
+        (WebCore::physicalRectToLogical):
+        (WebCore::physicalPointToLogical):
+        * rendering/style/RenderStyle.h:
+        Rename isFlippedBlocksWritingMode() to be isFlippedWritingMode() so we can
+        be consistent with other WritingMode query functions.
+
 2015-05-28  Matt Rajca  <mrajca@apple.com>
 
         Add ENABLE_MEDIA_SESSION feature flag (which is off by default).
index 1397adf..2792092 100644 (file)
 #include "ActiveDOMObject.h"
 #include "EventNames.h"
 #include "EventTarget.h"
-#include "URL.h"
 #include "NotificationClient.h"
-#include "TextFlags.h"
 #include "ThreadableLoaderClient.h"
+#include "URL.h"
+#include "WritingMode.h"
 #include <wtf/PassRefPtr.h>
 #include <wtf/RefCounted.h>
 #include <wtf/RefPtr.h>
index a62fbcc..aea8798 100644 (file)
@@ -56,107 +56,7 @@ void CSSProperty::wrapValueInCommaSeparatedList()
 
 static CSSPropertyID resolveToPhysicalProperty(TextDirection direction, WritingMode writingMode, LogicalBoxSide logicalSide, const StylePropertyShorthand& shorthand)
 {
-    if (direction == LTR) {
-        if (writingMode == TopToBottomWritingMode) {
-            // The common case. The logical and physical box sides match.
-            // Left = Start, Right = End, Before = Top, After = Bottom
-            return shorthand.properties()[logicalSide];
-        }
-
-        if (writingMode == BottomToTopWritingMode) {
-            // Start = Left, End = Right, Before = Bottom, After = Top.
-            switch (logicalSide) {
-            case StartSide:
-                return shorthand.properties()[LeftSide];
-            case EndSide:
-                return shorthand.properties()[RightSide];
-            case BeforeSide:
-                return shorthand.properties()[BottomSide];
-            default:
-                return shorthand.properties()[TopSide];
-            }
-        }
-
-        if (writingMode == LeftToRightWritingMode) {
-            // Start = Top, End = Bottom, Before = Left, After = Right.
-            switch (logicalSide) {
-            case StartSide:
-                return shorthand.properties()[TopSide];
-            case EndSide:
-                return shorthand.properties()[BottomSide];
-            case BeforeSide:
-                return shorthand.properties()[LeftSide];
-            default:
-                return shorthand.properties()[RightSide];
-            }
-        }
-
-        // Start = Top, End = Bottom, Before = Right, After = Left
-        switch (logicalSide) {
-        case StartSide:
-            return shorthand.properties()[TopSide];
-        case EndSide:
-            return shorthand.properties()[BottomSide];
-        case BeforeSide:
-            return shorthand.properties()[RightSide];
-        default:
-            return shorthand.properties()[LeftSide];
-        }
-    }
-
-    if (writingMode == TopToBottomWritingMode) {
-        // Start = Right, End = Left, Before = Top, After = Bottom
-        switch (logicalSide) {
-        case StartSide:
-            return shorthand.properties()[RightSide];
-        case EndSide:
-            return shorthand.properties()[LeftSide];
-        case BeforeSide:
-            return shorthand.properties()[TopSide];
-        default:
-            return shorthand.properties()[BottomSide];
-        }
-    }
-
-    if (writingMode == BottomToTopWritingMode) {
-        // Start = Right, End = Left, Before = Bottom, After = Top
-        switch (logicalSide) {
-        case StartSide:
-            return shorthand.properties()[RightSide];
-        case EndSide:
-            return shorthand.properties()[LeftSide];
-        case BeforeSide:
-            return shorthand.properties()[BottomSide];
-        default:
-            return shorthand.properties()[TopSide];
-        }
-    }
-
-    if (writingMode == LeftToRightWritingMode) {
-        // Start = Bottom, End = Top, Before = Left, After = Right
-        switch (logicalSide) {
-        case StartSide:
-            return shorthand.properties()[BottomSide];
-        case EndSide:
-            return shorthand.properties()[TopSide];
-        case BeforeSide:
-            return shorthand.properties()[LeftSide];
-        default:
-            return shorthand.properties()[RightSide];
-        }
-    }
-
-    // Start = Bottom, End = Top, Before = Right, After = Left
-    switch (logicalSide) {
-    case StartSide:
-        return shorthand.properties()[BottomSide];
-    case EndSide:
-        return shorthand.properties()[TopSide];
-    case BeforeSide:
-        return shorthand.properties()[RightSide];
-    default:
-        return shorthand.properties()[LeftSide];
-    }
+    return shorthand.properties()[mapLogicalSideToPhysicalSide(makeTextFlow(writingMode, direction), logicalSide)];
 }
 
 enum LogicalExtent { LogicalWidth, LogicalHeight };
index 0348eb2..d5c38a0 100644 (file)
@@ -25,7 +25,6 @@
 #include "CSSPropertyNames.h"
 #include "CSSValue.h"
 #include "RenderStyleConstants.h"
-#include "TextFlags.h"
 #include "WritingMode.h"
 #include <wtf/PassRefPtr.h>
 #include <wtf/RefPtr.h>
index 34195ee..2436a5c 100644 (file)
@@ -23,7 +23,6 @@
 #define LengthBox_h
 
 #include "Length.h"
-#include "TextFlags.h"
 #include "WritingMode.h"
 #include <array>
 
@@ -61,58 +60,42 @@ public:
 
     T& before(WritingMode writingMode)
     {
-        return isHorizontalWritingMode(writingMode) ?
-            (isFlippedBlocksWritingMode(writingMode) ? bottom() : top()) :
-            (isFlippedBlocksWritingMode(writingMode) ? right() : left());
+        return at(mapLogicalSideToPhysicalSide(writingMode, BeforeSide));
     }
 
     T& after(WritingMode writingMode)
     {
-        return isHorizontalWritingMode(writingMode) ?
-            (isFlippedBlocksWritingMode(writingMode) ? top() : bottom()) :
-            (isFlippedBlocksWritingMode(writingMode) ? left() : right());
+        return at(mapLogicalSideToPhysicalSide(writingMode, AfterSide));
     }
 
     T& start(WritingMode writingMode, TextDirection direction = LTR)
     {
-        return isHorizontalWritingMode(writingMode) ?
-            (isLeftToRightDirection(direction) ? left() : right()) :
-            (isLeftToRightDirection(direction) ? top() : bottom());
+        return at(mapLogicalSideToPhysicalSide(makeTextFlow(writingMode, direction), StartSide));
     }
 
     T& end(WritingMode writingMode, TextDirection direction = LTR)
     {
-        return isHorizontalWritingMode(writingMode) ?
-            (isLeftToRightDirection(direction) ? right() : left()) :
-            (isLeftToRightDirection(direction) ? bottom() : top());
+        return at(mapLogicalSideToPhysicalSide(makeTextFlow(writingMode, direction), EndSide));
     }
 
     const T& before(WritingMode writingMode) const
     {
-        return isHorizontalWritingMode(writingMode) ?
-            (isFlippedBlocksWritingMode(writingMode) ? bottom() : top()) :
-            (isFlippedBlocksWritingMode(writingMode) ? right() : left());
+        return at(mapLogicalSideToPhysicalSide(writingMode, BeforeSide));
     }
 
     const T& after(WritingMode writingMode) const
     {
-        return isHorizontalWritingMode(writingMode) ?
-            (isFlippedBlocksWritingMode(writingMode) ? top() : bottom()) :
-            (isFlippedBlocksWritingMode(writingMode) ? left() : right());
+        return at(mapLogicalSideToPhysicalSide(writingMode, AfterSide));
     }
 
     const T& start(WritingMode writingMode, TextDirection direction = LTR) const
     {
-        return isHorizontalWritingMode(writingMode) ?
-            (isLeftToRightDirection(direction) ? left() : right()) :
-            (isLeftToRightDirection(direction) ? top() : bottom());
+        return at(mapLogicalSideToPhysicalSide(makeTextFlow(writingMode, direction), StartSide));
     }
 
     const T& end(WritingMode writingMode, TextDirection direction = LTR) const
     {
-        return isHorizontalWritingMode(writingMode) ?
-            (isLeftToRightDirection(direction) ? right() : left()) :
-            (isLeftToRightDirection(direction) ? bottom() : top());
+        return at(mapLogicalSideToPhysicalSide(makeTextFlow(writingMode, direction), EndSide));
     }
 
     void setBefore(const T& before, WritingMode writingMode) { this->before(writingMode) = before; }
index 1f1ef1f..c4773d9 100644 (file)
@@ -25,6 +25,7 @@
 #define TextRun_h
 
 #include "TextFlags.h"
+#include "WritingMode.h"
 #include <wtf/RefCounted.h>
 #include <wtf/text/StringView.h>
 
index 2d98ef6..290717d 100644 (file)
@@ -27,7 +27,7 @@
 #define SelectionRect_h
 
 #include "IntRect.h"
-#include "TextFlags.h"
+#include "WritingMode.h"
 #include <wtf/FastMalloc.h>
 
 namespace WebCore {
index 3d35023..e3ce749 100644 (file)
@@ -24,7 +24,7 @@
 
 #include "BidiContext.h"
 #include "BidiRunList.h"
-#include "TextFlags.h"
+#include "WritingMode.h"
 #include <wtf/Noncopyable.h>
 #include <wtf/PassRefPtr.h>
 #include <wtf/Vector.h>
index 88f8b7a..4aeaa32 100644 (file)
@@ -31,7 +31,7 @@
 #ifndef StringWithDirection_h
 #define StringWithDirection_h
 
-#include "TextFlags.h"
+#include "WritingMode.h"
 #include <wtf/text/WTFString.h>
 
 namespace WebCore {
index 4aa57bf..f1b1f26 100644 (file)
@@ -28,8 +28,6 @@
 
 namespace WebCore {
 
-enum TextDirection { RTL, LTR };
-
 enum TextRenderingMode { AutoTextRendering, OptimizeSpeed, OptimizeLegibility, GeometricPrecision };
 
 enum FontSmoothingMode { AutoSmoothing, NoSmoothing, Antialiased, SubpixelAntialiased };
@@ -42,8 +40,6 @@ enum FontOrientation { Horizontal, Vertical };
 
 enum NonCJKGlyphOrientation { NonCJKGlyphOrientationVerticalRight, NonCJKGlyphOrientationUpright };
 
-inline bool isLeftToRightDirection(TextDirection direction) { return direction == LTR; }
-
 // Here, "Leading" and "Trailing" are relevant after the line has been rearranged for bidi.
 // ("Leading" means "left" and "Trailing" means "right.")
 enum ExpansionBehaviorFlags {
index d158bb2..2310b43 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright (c) 2012, Google Inc. All rights reserved.
+ * Copyright (C) 2015, Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
 
 namespace WebCore {
 
+enum TextDirection { LTR, RTL };
+
+inline bool isLeftToRightDirection(TextDirection direction)
+{
+    return direction == LTR;
+}
+
 enum WritingMode {
-    TopToBottomWritingMode, RightToLeftWritingMode, LeftToRightWritingMode, BottomToTopWritingMode
+    TopToBottomWritingMode = 0, // horizontal-tb
+    BottomToTopWritingMode = 1, // horizontal-bt
+    LeftToRightWritingMode = 2, // vertical-lr
+    RightToLeftWritingMode = 3, // vertical-rl
 };
 
-// Lines have horizontal orientation; modes horizontal-tb or horizontal-bt.
-inline bool isHorizontalWritingMode(WritingMode writingMode)
+#define MAKE_TEXT_FLOW(writingMode, direction)  ((writingMode) << 1 | (direction))
+
+// Define the text flow in terms of the writing mode and the text direction. The first
+// part is the line growing direction and the second part is the block growing direction.
+enum TextFlow {
+    InlineEastBlockSouth = MAKE_TEXT_FLOW(TopToBottomWritingMode, LTR),
+    InlineWestBlockSouth = MAKE_TEXT_FLOW(TopToBottomWritingMode, RTL),
+    InlineEastBlockNorth = MAKE_TEXT_FLOW(BottomToTopWritingMode, LTR),
+    InlineWestBlockNorth = MAKE_TEXT_FLOW(BottomToTopWritingMode, RTL),
+    InlineSouthBlockEast = MAKE_TEXT_FLOW(LeftToRightWritingMode, LTR),
+    InlineSouthBlockWest = MAKE_TEXT_FLOW(LeftToRightWritingMode, RTL),
+    InlineNorthBlockEast = MAKE_TEXT_FLOW(RightToLeftWritingMode, LTR),
+    InlineNorthBlockWest = MAKE_TEXT_FLOW(RightToLeftWritingMode, RTL)
+};
+
+inline TextFlow makeTextFlow(WritingMode writingMode, TextDirection direction)
 {
-    return writingMode == TopToBottomWritingMode || writingMode == BottomToTopWritingMode;
+    return static_cast<TextFlow>(MAKE_TEXT_FLOW(writingMode, direction));
 }
 
-// Bottom of the line occurs earlier in the block; modes vertical-lr or horizontal-bt.
-inline bool isFlippedLinesWritingMode(WritingMode writingMode)
+#undef MAKE_TEXT_FLOW
+
+const unsigned TextFlowReversedMask = 1;
+const unsigned TextFlowFlippedMask = 2;
+const unsigned TextFlowVerticalMask = 4;
+
+inline bool isReversedTextFlow(TextFlow textflow)
 {
-    return writingMode == LeftToRightWritingMode || writingMode == BottomToTopWritingMode;
+    return textflow & TextFlowReversedMask;
+}
+
+inline bool isFlippedTextFlow(TextFlow textflow)
+{
+    return textflow & TextFlowFlippedMask;
+}
+
+inline bool isVerticalTextFlow(TextFlow textflow)
+{
+    return textflow & TextFlowVerticalMask;
+}
+
+// Lines have vertical orientation; modes vertical-lr or vertical-rl.
+inline bool isVerticalWritingMode(WritingMode writingMode)
+{
+    return isVerticalTextFlow(makeTextFlow(writingMode, LTR));
 }
 
 // Block progression increases in the opposite direction to normal; modes vertical-rl or horizontal-bt.
-inline bool isFlippedBlocksWritingMode(WritingMode writingMode)
+inline bool isFlippedWritingMode(WritingMode writingMode)
+{
+    return isFlippedTextFlow(makeTextFlow(writingMode, LTR));
+}
+
+// Lines have horizontal orientation; modes horizontal-tb or horizontal-bt.
+inline bool isHorizontalWritingMode(WritingMode writingMode)
+{
+    return !isVerticalWritingMode(writingMode);
+}
+
+// Bottom of the line occurs earlier in the block; modes vertical-lr or horizontal-bt.
+inline bool isFlippedLinesWritingMode(WritingMode writingMode)
 {
-    return writingMode == RightToLeftWritingMode || writingMode == BottomToTopWritingMode;
+    return isVerticalWritingMode(writingMode) != isFlippedWritingMode(writingMode);
 }
 
 enum LogicalBoxSide {
@@ -70,6 +128,45 @@ enum PhysicalBoxSide {
     LeftSide
 };
 
+inline bool isHorizontalPhysicalSide(PhysicalBoxSide physicalSide)
+{
+    return physicalSide == LeftSide || physicalSide == RightSide;
+}
+
+inline PhysicalBoxSide mirrorPhysicalSide(PhysicalBoxSide physicalSide)
+{
+    // top <-> bottom and left <-> right conversion
+    return static_cast<PhysicalBoxSide>((static_cast<int>(physicalSide) + 2) % 4);
+}
+
+inline PhysicalBoxSide rotatePhysicalSide(PhysicalBoxSide physicalSide)
+{
+    // top <-> left and right <-> bottom conversion
+    bool horizontalSide = isHorizontalPhysicalSide(physicalSide);
+    return static_cast<PhysicalBoxSide>((static_cast<int>(physicalSide) + (horizontalSide ? 1 : 3)) % 4);
+}
+
+inline PhysicalBoxSide mapLogicalSideToPhysicalSide(TextFlow textflow, LogicalBoxSide logicalSide)
+{
+    PhysicalBoxSide physicalSide = static_cast<PhysicalBoxSide>(logicalSide);
+    bool horizontalSide = isHorizontalPhysicalSide(physicalSide);
+
+    if (isVerticalTextFlow(textflow))
+        physicalSide = rotatePhysicalSide(physicalSide);
+
+    if ((horizontalSide && isReversedTextFlow(textflow)) || (!horizontalSide && isFlippedTextFlow(textflow)))
+        physicalSide = mirrorPhysicalSide(physicalSide);
+
+    return physicalSide;
+}
+
+inline PhysicalBoxSide mapLogicalSideToPhysicalSide(WritingMode writingMode, LogicalBoxSide logicalSide)
+{
+    // Set the direction such that side is mirrored if isFlippedWritingMode() is true
+    TextDirection direction = isFlippedWritingMode(writingMode) ? RTL : LTR;
+    return mapLogicalSideToPhysicalSide(makeTextFlow(writingMode, direction), logicalSide);
+}
+
 } // namespace WebCore
 
 #endif // WritingMode_h
index 9412518..821e4b9 100644 (file)
@@ -799,7 +799,7 @@ void RenderMultiColumnSet::collectLayerFragments(LayerFragments& fragments, cons
             else
                 blockOffset -= i * (computedColumnHeight() + colGap);
         }
-        if (isFlippedBlocksWritingMode(style().writingMode()))
+        if (isFlippedWritingMode(style().writingMode()))
             blockOffset = -blockOffset;
         translationOffset.setHeight(blockOffset);
         if (!isHorizontalWritingMode())
@@ -851,7 +851,7 @@ LayoutPoint RenderMultiColumnSet::columnTranslationForOffset(const LayoutUnit& o
         else
             blockOffset -= startColumn * (computedColumnHeight() + colGap);
     }
-    if (isFlippedBlocksWritingMode(style().writingMode()))
+    if (isFlippedWritingMode(style().writingMode()))
         blockOffset = -blockOffset;
     translationOffset.setY(blockOffset);
     
index e5a9a75..58eb9e2 100644 (file)
@@ -69,7 +69,7 @@ static inline FloatRect physicalRectToLogical(const FloatRect& rect, float logic
 {
     if (isHorizontalWritingMode(writingMode))
         return rect;
-    if (isFlippedBlocksWritingMode(writingMode))
+    if (isFlippedWritingMode(writingMode))
         return FloatRect(rect.y(), logicalBoxHeight - rect.maxX(), rect.height(), rect.width());
     return rect.transposedRect();
 }
@@ -78,7 +78,7 @@ static inline FloatPoint physicalPointToLogical(const FloatPoint& point, float l
 {
     if (isHorizontalWritingMode(writingMode))
         return point;
-    if (isFlippedBlocksWritingMode(writingMode))
+    if (isFlippedWritingMode(writingMode))
         return FloatPoint(point.y(), logicalBoxHeight - point.x());
     return point.transposedPoint();
 }
index dfa5441..d92ab35 100644 (file)
@@ -1136,7 +1136,7 @@ public:
     WritingMode writingMode() const { return static_cast<WritingMode>(inherited_flags.m_writingMode); }
     bool isHorizontalWritingMode() const { return WebCore::isHorizontalWritingMode(writingMode()); }
     bool isFlippedLinesWritingMode() const { return WebCore::isFlippedLinesWritingMode(writingMode()); }
-    bool isFlippedBlocksWritingMode() const { return WebCore::isFlippedBlocksWritingMode(writingMode()); }
+    bool isFlippedBlocksWritingMode() const { return WebCore::isFlippedWritingMode(writingMode()); }
 
 #if ENABLE(CSS_IMAGE_ORIENTATION)
     ImageOrientationEnum imageOrientation() const { return static_cast<ImageOrientationEnum>(rareInheritedData->m_imageOrientation); }
index f54abe1..32095aa 100644 (file)
@@ -1,3 +1,16 @@
+2015-05-28  Said Abou-Hallawa  <sabouhallawa@apple.com>
+
+        Code clean up for extracting information from the mix of WritingMode and TextDirection
+        https://bugs.webkit.org/show_bug.cgi?id=143399
+
+        Reviewed by Darin Adler.
+
+        * Shared/WebPopupItem.h:
+        * UIProcess/API/C/efl/WKAPICastEfl.h:
+        * UIProcess/WebPopupMenuProxy.h:
+        enum TextDirection is moved from TextFlags.h to WritingMode.h. So include
+        WritingMode.h instead of including TextFlags.h.
+
 2015-05-28  Antti Koivisto  <antti@apple.com>
 
         Disable network cache for old clients
index f59b829..c10f76a 100644 (file)
@@ -26,7 +26,7 @@
 #ifndef WebPopupItem_h
 #define WebPopupItem_h
 
-#include <WebCore/TextFlags.h>
+#include <WebCore/WritingMode.h>
 #include <wtf/text/WTFString.h>
 
 namespace IPC {
index 07c3bef..3f7a98f 100644 (file)
@@ -24,7 +24,7 @@
 #error "Please #include \"WKAPICast.h\" instead of this file directly."
 #endif
 
-#include <WebCore/TextFlags.h>
+#include <WebCore/WritingMode.h>
 #include <WebKit/WKPopupItem.h>
 
 #if ENABLE(TOUCH_EVENTS)
index b9b7d2b..96a8098 100644 (file)
@@ -26,7 +26,7 @@
 #ifndef WebPopupMenuProxy_h
 #define WebPopupMenuProxy_h
 
-#include <WebCore/TextFlags.h>
+#include <WebCore/WritingMode.h>
 #include <wtf/PassRefPtr.h>
 #include <wtf/RefCounted.h>
 #include <wtf/Vector.h>