Title: [184962] trunk/Source
Revision
184962
Author
commit-qu...@webkit.org
Date
2015-05-28 14:55:32 -0700 (Thu, 28 May 2015)

Log Message

Code clean up for extracting information from the mix of WritingMode and TextDirection
https://bugs.webkit.org/show_bug.cgi?id=143399

Patch by Said Abou-Hallawa <sabouhall...@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.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (184961 => 184962)


--- trunk/Source/WebCore/ChangeLog	2015-05-28 21:05:26 UTC (rev 184961)
+++ trunk/Source/WebCore/ChangeLog	2015-05-28 21:55:32 UTC (rev 184962)
@@ -1,3 +1,85 @@
+2015-05-28  Said Abou-Hallawa  <sabouhall...@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  <mra...@apple.com>
 
         Add ENABLE_MEDIA_SESSION feature flag (which is off by default).

Modified: trunk/Source/WebCore/Modules/notifications/Notification.h (184961 => 184962)


--- trunk/Source/WebCore/Modules/notifications/Notification.h	2015-05-28 21:05:26 UTC (rev 184961)
+++ trunk/Source/WebCore/Modules/notifications/Notification.h	2015-05-28 21:55:32 UTC (rev 184962)
@@ -35,10 +35,10 @@
 #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>

Modified: trunk/Source/WebCore/css/CSSProperty.cpp (184961 => 184962)


--- trunk/Source/WebCore/css/CSSProperty.cpp	2015-05-28 21:05:26 UTC (rev 184961)
+++ trunk/Source/WebCore/css/CSSProperty.cpp	2015-05-28 21:55:32 UTC (rev 184962)
@@ -56,107 +56,7 @@
 
 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 };

Modified: trunk/Source/WebCore/css/CSSProperty.h (184961 => 184962)


--- trunk/Source/WebCore/css/CSSProperty.h	2015-05-28 21:05:26 UTC (rev 184961)
+++ trunk/Source/WebCore/css/CSSProperty.h	2015-05-28 21:55:32 UTC (rev 184962)
@@ -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>

Modified: trunk/Source/WebCore/platform/LengthBox.h (184961 => 184962)


--- trunk/Source/WebCore/platform/LengthBox.h	2015-05-28 21:05:26 UTC (rev 184961)
+++ trunk/Source/WebCore/platform/LengthBox.h	2015-05-28 21:55:32 UTC (rev 184962)
@@ -23,7 +23,6 @@
 #define LengthBox_h
 
 #include "Length.h"
-#include "TextFlags.h"
 #include "WritingMode.h"
 #include <array>
 
@@ -61,58 +60,42 @@
 
     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; }

Modified: trunk/Source/WebCore/platform/graphics/TextRun.h (184961 => 184962)


--- trunk/Source/WebCore/platform/graphics/TextRun.h	2015-05-28 21:05:26 UTC (rev 184961)
+++ trunk/Source/WebCore/platform/graphics/TextRun.h	2015-05-28 21:55:32 UTC (rev 184962)
@@ -25,6 +25,7 @@
 #define TextRun_h
 
 #include "TextFlags.h"
+#include "WritingMode.h"
 #include <wtf/RefCounted.h>
 #include <wtf/text/StringView.h>
 

Modified: trunk/Source/WebCore/platform/ios/SelectionRect.h (184961 => 184962)


--- trunk/Source/WebCore/platform/ios/SelectionRect.h	2015-05-28 21:05:26 UTC (rev 184961)
+++ trunk/Source/WebCore/platform/ios/SelectionRect.h	2015-05-28 21:55:32 UTC (rev 184962)
@@ -27,7 +27,7 @@
 #define SelectionRect_h
 
 #include "IntRect.h"
-#include "TextFlags.h"
+#include "WritingMode.h"
 #include <wtf/FastMalloc.h>
 
 namespace WebCore {

Modified: trunk/Source/WebCore/platform/text/BidiResolver.h (184961 => 184962)


--- trunk/Source/WebCore/platform/text/BidiResolver.h	2015-05-28 21:05:26 UTC (rev 184961)
+++ trunk/Source/WebCore/platform/text/BidiResolver.h	2015-05-28 21:55:32 UTC (rev 184962)
@@ -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>

Modified: trunk/Source/WebCore/platform/text/StringWithDirection.h (184961 => 184962)


--- trunk/Source/WebCore/platform/text/StringWithDirection.h	2015-05-28 21:05:26 UTC (rev 184961)
+++ trunk/Source/WebCore/platform/text/StringWithDirection.h	2015-05-28 21:55:32 UTC (rev 184962)
@@ -31,7 +31,7 @@
 #ifndef StringWithDirection_h
 #define StringWithDirection_h
 
-#include "TextFlags.h"
+#include "WritingMode.h"
 #include <wtf/text/WTFString.h>
 
 namespace WebCore {

Modified: trunk/Source/WebCore/platform/text/TextFlags.h (184961 => 184962)


--- trunk/Source/WebCore/platform/text/TextFlags.h	2015-05-28 21:05:26 UTC (rev 184961)
+++ trunk/Source/WebCore/platform/text/TextFlags.h	2015-05-28 21:55:32 UTC (rev 184962)
@@ -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 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 {

Modified: trunk/Source/WebCore/platform/text/WritingMode.h (184961 => 184962)


--- trunk/Source/WebCore/platform/text/WritingMode.h	2015-05-28 21:05:26 UTC (rev 184961)
+++ trunk/Source/WebCore/platform/text/WritingMode.h	2015-05-28 21:55:32 UTC (rev 184962)
@@ -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
@@ -33,28 +34,85 @@
 
 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
 };
 
+#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 static_cast<TextFlow>(MAKE_TEXT_FLOW(writingMode, direction));
+}
+
+#undef MAKE_TEXT_FLOW
+
+const unsigned TextFlowReversedMask = 1;
+const unsigned TextFlowFlippedMask = 2;
+const unsigned TextFlowVerticalMask = 4;
+
+inline bool isReversedTextFlow(TextFlow textflow)
+{
+    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 isFlippedWritingMode(WritingMode writingMode)
+{
+    return isFlippedTextFlow(makeTextFlow(writingMode, LTR));
+}
+
 // Lines have horizontal orientation; modes horizontal-tb or horizontal-bt.
 inline bool isHorizontalWritingMode(WritingMode writingMode)
 {
-    return writingMode == TopToBottomWritingMode || writingMode == BottomToTopWritingMode;
+    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 == LeftToRightWritingMode || writingMode == BottomToTopWritingMode;
+    return isVerticalWritingMode(writingMode) != isFlippedWritingMode(writingMode);
 }
 
-// Block progression increases in the opposite direction to normal; modes vertical-rl or horizontal-bt.
-inline bool isFlippedBlocksWritingMode(WritingMode writingMode)
-{
-    return writingMode == RightToLeftWritingMode || writingMode == BottomToTopWritingMode;
-}
-
 enum LogicalBoxSide {
     BeforeSide,
     EndSide,
@@ -70,6 +128,45 @@
     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

Modified: trunk/Source/WebCore/rendering/RenderMultiColumnSet.cpp (184961 => 184962)


--- trunk/Source/WebCore/rendering/RenderMultiColumnSet.cpp	2015-05-28 21:05:26 UTC (rev 184961)
+++ trunk/Source/WebCore/rendering/RenderMultiColumnSet.cpp	2015-05-28 21:55:32 UTC (rev 184962)
@@ -799,7 +799,7 @@
             else
                 blockOffset -= i * (computedColumnHeight() + colGap);
         }
-        if (isFlippedBlocksWritingMode(style().writingMode()))
+        if (isFlippedWritingMode(style().writingMode()))
             blockOffset = -blockOffset;
         translationOffset.setHeight(blockOffset);
         if (!isHorizontalWritingMode())
@@ -851,7 +851,7 @@
         else
             blockOffset -= startColumn * (computedColumnHeight() + colGap);
     }
-    if (isFlippedBlocksWritingMode(style().writingMode()))
+    if (isFlippedWritingMode(style().writingMode()))
         blockOffset = -blockOffset;
     translationOffset.setY(blockOffset);
     

Modified: trunk/Source/WebCore/rendering/shapes/Shape.cpp (184961 => 184962)


--- trunk/Source/WebCore/rendering/shapes/Shape.cpp	2015-05-28 21:05:26 UTC (rev 184961)
+++ trunk/Source/WebCore/rendering/shapes/Shape.cpp	2015-05-28 21:55:32 UTC (rev 184962)
@@ -69,7 +69,7 @@
 {
     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 @@
 {
     if (isHorizontalWritingMode(writingMode))
         return point;
-    if (isFlippedBlocksWritingMode(writingMode))
+    if (isFlippedWritingMode(writingMode))
         return FloatPoint(point.y(), logicalBoxHeight - point.x());
     return point.transposedPoint();
 }

Modified: trunk/Source/WebCore/rendering/style/RenderStyle.h (184961 => 184962)


--- trunk/Source/WebCore/rendering/style/RenderStyle.h	2015-05-28 21:05:26 UTC (rev 184961)
+++ trunk/Source/WebCore/rendering/style/RenderStyle.h	2015-05-28 21:55:32 UTC (rev 184962)
@@ -1136,7 +1136,7 @@
     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); }

Modified: trunk/Source/WebKit2/ChangeLog (184961 => 184962)


--- trunk/Source/WebKit2/ChangeLog	2015-05-28 21:05:26 UTC (rev 184961)
+++ trunk/Source/WebKit2/ChangeLog	2015-05-28 21:55:32 UTC (rev 184962)
@@ -1,3 +1,16 @@
+2015-05-28  Said Abou-Hallawa  <sabouhall...@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  <an...@apple.com>
 
         Disable network cache for old clients

Modified: trunk/Source/WebKit2/Shared/WebPopupItem.h (184961 => 184962)


--- trunk/Source/WebKit2/Shared/WebPopupItem.h	2015-05-28 21:05:26 UTC (rev 184961)
+++ trunk/Source/WebKit2/Shared/WebPopupItem.h	2015-05-28 21:55:32 UTC (rev 184962)
@@ -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 {

Modified: trunk/Source/WebKit2/UIProcess/API/C/efl/WKAPICastEfl.h (184961 => 184962)


--- trunk/Source/WebKit2/UIProcess/API/C/efl/WKAPICastEfl.h	2015-05-28 21:05:26 UTC (rev 184961)
+++ trunk/Source/WebKit2/UIProcess/API/C/efl/WKAPICastEfl.h	2015-05-28 21:55:32 UTC (rev 184962)
@@ -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)

Modified: trunk/Source/WebKit2/UIProcess/WebPopupMenuProxy.h (184961 => 184962)


--- trunk/Source/WebKit2/UIProcess/WebPopupMenuProxy.h	2015-05-28 21:05:26 UTC (rev 184961)
+++ trunk/Source/WebKit2/UIProcess/WebPopupMenuProxy.h	2015-05-28 21:55:32 UTC (rev 184962)
@@ -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>
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to