From 2ce8edd0afae45b008c23b720c55644eb837c5e5 Mon Sep 17 00:00:00 2001 From: Jaehun Lim Date: Tue, 23 Apr 2013 20:02:12 +0900 Subject: [PATCH] [Cherry-pick] Remove dependency on RenderStyle from FractionalLayoutBoxExtent and LayoutBox 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. Change-Id: I71dc5d99bad23ba14f774e01a9f004d4914ace0d --- Source/WebCore/css/CSSPrimitiveValueMappings.h | 1 + Source/WebCore/css/CSSProperty.h | 1 + Source/WebCore/css/CSSToStyleMap.h | 1 + Source/WebCore/platform/LengthBox.cpp | 34 ++++----- Source/WebCore/platform/LengthBox.h | 14 ++-- .../graphics/FractionalLayoutBoxExtent.cpp | 86 +++++++++++----------- .../platform/graphics/FractionalLayoutBoxExtent.h | 36 ++++----- Source/WebCore/platform/text/TextDirection.h | 4 +- Source/WebCore/platform/text/WritingMode.h | 60 +++++++++++++++ Source/WebCore/rendering/InlineFlowBox.cpp | 8 +- Source/WebCore/rendering/RenderBox.cpp | 16 ++-- Source/WebCore/rendering/RenderBox.h | 36 ++++++--- Source/WebCore/rendering/style/RenderStyle.h | 32 ++++---- .../WebCore/rendering/style/RenderStyleConstants.h | 5 -- 14 files changed, 204 insertions(+), 130 deletions(-) create mode 100644 Source/WebCore/platform/text/WritingMode.h diff --git a/Source/WebCore/css/CSSPrimitiveValueMappings.h b/Source/WebCore/css/CSSPrimitiveValueMappings.h index f54fdaa..3380b91 100644 --- a/Source/WebCore/css/CSSPrimitiveValueMappings.h +++ b/Source/WebCore/css/CSSPrimitiveValueMappings.h @@ -50,6 +50,7 @@ #include "TextRenderingMode.h" #include "ThemeTypes.h" #include "UnicodeBidi.h" +#include "WritingMode.h" #if ENABLE(CSS_SHADERS) #include "CustomFilterOperation.h" diff --git a/Source/WebCore/css/CSSProperty.h b/Source/WebCore/css/CSSProperty.h index 7124146..0a02d98 100644 --- a/Source/WebCore/css/CSSProperty.h +++ b/Source/WebCore/css/CSSProperty.h @@ -25,6 +25,7 @@ #include "CSSValue.h" #include "RenderStyleConstants.h" #include "TextDirection.h" +#include "WritingMode.h" #include #include diff --git a/Source/WebCore/css/CSSToStyleMap.h b/Source/WebCore/css/CSSToStyleMap.h index 8e0fc95..6bab40b 100644 --- a/Source/WebCore/css/CSSToStyleMap.h +++ b/Source/WebCore/css/CSSToStyleMap.h @@ -30,6 +30,7 @@ namespace WebCore { class FillLayer; class CSSValue; class Animation; +class RenderStyle; class StyleImage; class StyleResolver; class NinePieceImage; diff --git a/Source/WebCore/platform/LengthBox.cpp b/Source/WebCore/platform/LengthBox.cpp index 4aa7451..a5205f2 100644 --- a/Source/WebCore/platform/LengthBox.cpp +++ b/Source/WebCore/platform/LengthBox.cpp @@ -31,23 +31,21 @@ #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 diff --git a/Source/WebCore/platform/LengthBox.h b/Source/WebCore/platform/LengthBox.h index 389cb66..d5dfc13 100644 --- a/Source/WebCore/platform/LengthBox.h +++ b/Source/WebCore/platform/LengthBox.h @@ -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 { diff --git a/Source/WebCore/platform/graphics/FractionalLayoutBoxExtent.cpp b/Source/WebCore/platform/graphics/FractionalLayoutBoxExtent.cpp index e4e545a..f1c4e5b 100644 --- a/Source/WebCore/platform/graphics/FractionalLayoutBoxExtent.cpp +++ b/Source/WebCore/platform/graphics/FractionalLayoutBoxExtent.cpp @@ -31,33 +31,31 @@ #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 diff --git a/Source/WebCore/platform/graphics/FractionalLayoutBoxExtent.h b/Source/WebCore/platform/graphics/FractionalLayoutBoxExtent.h index 921c84b..28bdb9c 100644 --- a/Source/WebCore/platform/graphics/FractionalLayoutBoxExtent.h +++ b/Source/WebCore/platform/graphics/FractionalLayoutBoxExtent.h @@ -32,11 +32,11 @@ #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; diff --git a/Source/WebCore/platform/text/TextDirection.h b/Source/WebCore/platform/text/TextDirection.h index 5be416e..9a074c8 100644 --- a/Source/WebCore/platform/text/TextDirection.h +++ b/Source/WebCore/platform/text/TextDirection.h @@ -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 index 0000000..9e5d28c --- /dev/null +++ b/Source/WebCore/platform/text/WritingMode.h @@ -0,0 +1,60 @@ +/* + * 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 +}; + +// Lines have horizontal orientation; modes horizontal-tb or horizontal-bt. +inline bool isHorizontalWritingMode(WritingMode writingMode) +{ + return writingMode == TopToBottomWritingMode || writingMode == BottomToTopWritingMode; +} + +// 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; +} + +// 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; +} + +} // namespace WebCore + +#endif // WritingMode_h diff --git a/Source/WebCore/rendering/InlineFlowBox.cpp b/Source/WebCore/rendering/InlineFlowBox.cpp index a96f612..4dceca5 100644 --- a/Source/WebCore/rendering/InlineFlowBox.cpp +++ b/Source/WebCore/rendering/InlineFlowBox.cpp @@ -791,10 +791,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. diff --git a/Source/WebCore/rendering/RenderBox.cpp b/Source/WebCore/rendering/RenderBox.cpp index fa27b46..6c516aa 100644 --- a/Source/WebCore/rendering/RenderBox.cpp +++ b/Source/WebCore/rendering/RenderBox.cpp @@ -2543,8 +2543,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(); @@ -2883,8 +2883,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(); @@ -3150,8 +3150,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 @@ -3311,8 +3311,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(); diff --git a/Source/WebCore/rendering/RenderBox.h b/Source/WebCore/rendering/RenderBox.h index 1c4aaa6..bf7b7b4 100644 --- a/Source/WebCore/rendering/RenderBox.h +++ b/Source/WebCore/rendering/RenderBox.h @@ -233,17 +233,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 diff --git a/Source/WebCore/rendering/style/RenderStyle.h b/Source/WebCore/rendering/style/RenderStyle.h index 48778a3..82b4417 100644 --- a/Source/WebCore/rendering/style/RenderStyle.h +++ b/Source/WebCore/rendering/style/RenderStyle.h @@ -492,10 +492,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. @@ -727,24 +727,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(inherited_flags._cursor_style); } diff --git a/Source/WebCore/rendering/style/RenderStyleConstants.h b/Source/WebCore/rendering/style/RenderStyleConstants.h index 6847f9f..6e04a14 100644 --- a/Source/WebCore/rendering/style/RenderStyleConstants.h +++ b/Source/WebCore/rendering/style/RenderStyleConstants.h @@ -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 }; -- 2.7.4