From: Simon Montagu Add some more logical getters to nsIFrame.h. Bug 735577 diff --git a/layout/generic/WritingModes.h b/layout/generic/WritingModes.h --- a/layout/generic/WritingModes.h +++ b/layout/generic/WritingModes.h @@ -834,16 +834,34 @@ public: } bool IsEmpty() const { return (mMargin.left == 0 && mMargin.top == 0 && mMargin.right == 0 && mMargin.bottom == 0); } + LogicalMargin operator+(const LogicalMargin& aMargin) { + CHECK_WRITING_MODE(aMargin.GetWritingMode()); + return LogicalMargin(GetWritingMode(), + BStart() + aMargin.BStart(), + IEnd() + aMargin.IEnd(), + BEnd() + aMargin.BEnd(), + IStart() + aMargin.IStart()); + } + + LogicalMargin operator-(const LogicalMargin& aMargin) { + CHECK_WRITING_MODE(aMargin.GetWritingMode()); + return LogicalMargin(GetWritingMode(), + BStart() - aMargin.BStart(), + IEnd() - aMargin.IEnd(), + BEnd() - aMargin.BEnd(), + IStart() - aMargin.IStart()); + } + private: friend class LogicalRect; LogicalMargin() MOZ_DELETE; #ifdef DEBUG WritingMode GetWritingMode() const { return mWritingMode; } #else diff --git a/layout/generic/nsIFrame.h b/layout/generic/nsIFrame.h --- a/layout/generic/nsIFrame.h +++ b/layout/generic/nsIFrame.h @@ -803,16 +803,27 @@ public: * simply be adjusted directly (e.g., using SetPosition()). */ void MovePositionBy(const nsPoint& aTranslation); /** * Return frame's position without relative positioning */ nsPoint GetNormalPosition() const; + mozilla::LogicalPoint + GetLogicalNormalPosition(nscoord aContainerWidth) const { + return GetLogicalNormalPosition(GetWritingMode(), aContainerWidth); + } + mozilla::LogicalPoint + GetLogicalNormalPosition(mozilla::WritingMode aWritingMode, + nscoord aContainerWidth) const + { + return mozilla::LogicalPoint(aWritingMode, + GetNormalPosition(), aContainerWidth); + } virtual nsPoint GetPositionOfChildIgnoringScrolling(nsIFrame* aChild) { return aChild->GetPosition(); } nsPoint GetPositionIgnoringScrolling() { return mParent ? mParent->GetPositionOfChildIgnoringScrolling(this) : GetPosition(); } @@ -900,39 +911,68 @@ public: * * This doesn't include any margin collapsing that may have occurred. * * It also treats 'auto' margins as zero, and treats any margins that * should have been turned into 'auto' because of overconstraint as * having their original values. */ virtual nsMargin GetUsedMargin() const; + virtual mozilla::LogicalMargin GetLogicalUsedMargin() const { + return GetLogicalUsedMargin(GetWritingMode()); + } + virtual mozilla::LogicalMargin + GetLogicalUsedMargin(mozilla::WritingMode aWritingMode) const { + return mozilla::LogicalMargin(aWritingMode, GetUsedMargin()); + } /** * Return the distance between the border edge of the frame (which is * its rect) and the padding edge of the frame. Like GetRect(), returns * the dimensions as of the most recent reflow. * * Note that this differs from StyleBorder()->GetBorder() in that * this describes region of the frame's box, and * StyleBorder()->GetBorder() describes a border. They differ only * for tables, particularly border-collapse tables. */ virtual nsMargin GetUsedBorder() const; + virtual mozilla::LogicalMargin GetLogicalUsedBorder() const { + return GetLogicalUsedBorder(GetWritingMode()); + } + virtual mozilla::LogicalMargin + GetLogicalUsedBorder(mozilla::WritingMode aWritingMode) const { + return mozilla::LogicalMargin(aWritingMode, GetUsedBorder()); + } /** * Return the distance between the padding edge of the frame and the * content edge of the frame. Like GetRect(), returns the dimensions * as of the most recent reflow. */ virtual nsMargin GetUsedPadding() const; + virtual mozilla::LogicalMargin GetLogicalUsedPadding() const { + return GetLogicalUsedPadding(GetWritingMode()); + } + virtual mozilla::LogicalMargin + GetLogicalUsedPadding(mozilla::WritingMode aWritingMode) const { + return mozilla::LogicalMargin(aWritingMode, GetUsedPadding()); + } nsMargin GetUsedBorderAndPadding() const { return GetUsedBorder() + GetUsedPadding(); } + mozilla::LogicalMargin GetLogicalUsedBorderAndPadding() const { + return GetLogicalUsedBorder() + GetLogicalUsedPadding(); + } + mozilla::LogicalMargin + GetLogicalUsedBorderAndPadding(mozilla::WritingMode aWritingMode) const { + return GetLogicalUsedBorder(aWritingMode) + + GetLogicalUsedPadding(aWritingMode); + } /** * Apply the result of GetSkipSides() on this frame to an nsMargin by * setting to zero any sides that are skipped. * * @param aMargin The margin to apply the result of GetSkipSides() to. * @param aReflowState An optional reflow state parameter, which is used if * ApplySkipSides() is being called in the middle of reflow.