Bug 1281099 part 1 - Convert some macros to functions to help later change. r?jfkthame
MozReview-Commit-ID: 2OS5eIsNAYN
--- a/layout/base/nsBidi.h
+++ b/layout/base/nsBidi.h
@@ -657,24 +657,30 @@ public:
* @param aDestSize will receive the number of characters that were written to <code>aDest</code>.
*/
nsresult WriteReverse(const char16_t *aSrc, int32_t aSrcLength, char16_t *aDest, uint16_t aOptions, int32_t *aDestSize);
NS_DECLARE_FRAME_PROPERTY_SMALL_VALUE(BaseLevelProperty, nsBidiLevel)
NS_DECLARE_FRAME_PROPERTY_SMALL_VALUE(EmbeddingLevelProperty, nsBidiLevel)
NS_DECLARE_FRAME_PROPERTY_SMALL_VALUE(ParagraphDepthProperty, uint8_t)
-#define NS_GET_BASE_LEVEL(frame) \
- frame->Properties().Get(nsBidi::BaseLevelProperty())
+ static nsBidiLevel GetBaseLevel(nsIFrame* aFrame)
+ {
+ return aFrame->Properties().Get(BaseLevelProperty());
+ }
-#define NS_GET_EMBEDDING_LEVEL(frame) \
- frame->Properties().Get(nsBidi::EmbeddingLevelProperty())
+ static nsBidiLevel GetEmbeddingLevel(nsIFrame* aFrame)
+ {
+ return aFrame->Properties().Get(EmbeddingLevelProperty());
+ }
-#define NS_GET_PARAGRAPH_DEPTH(frame) \
- frame->Properties().Get(nsBidi::ParagraphDepthProperty())
+ static uint8_t GetParagraphDepth(nsIFrame* aFrame)
+ {
+ return aFrame->Properties().Get(ParagraphDepthProperty());
+ }
protected:
friend class nsBidiPresUtils;
class BracketData {
public:
explicit BracketData(const nsBidi* aBidi);
~BracketData();
--- a/layout/base/nsBidiPresUtils.cpp
+++ b/layout/base/nsBidiPresUtils.cpp
@@ -1288,34 +1288,34 @@ nsBidiPresUtils::GetFirstLeaf(nsIFrame*
realFrame : firstChild;
}
return firstLeaf;
}
nsBidiLevel
nsBidiPresUtils::GetFrameEmbeddingLevel(nsIFrame* aFrame)
{
- return NS_GET_EMBEDDING_LEVEL(nsBidiPresUtils::GetFirstLeaf(aFrame));
+ return nsBidi::GetEmbeddingLevel(GetFirstLeaf(aFrame));
}
uint8_t
nsBidiPresUtils::GetParagraphDepth(nsIFrame* aFrame)
{
- return NS_GET_PARAGRAPH_DEPTH(nsBidiPresUtils::GetFirstLeaf(aFrame));
+ return nsBidi::GetParagraphDepth(GetFirstLeaf(aFrame));
}
nsBidiLevel
nsBidiPresUtils::GetFrameBaseLevel(nsIFrame* aFrame)
{
nsIFrame* firstLeaf = aFrame;
while (!IsBidiLeaf(firstLeaf)) {
firstLeaf = firstLeaf->PrincipalChildList().FirstChild();
}
- return NS_GET_BASE_LEVEL(firstLeaf);
+ return nsBidi::GetBaseLevel(firstLeaf);
}
void
nsBidiPresUtils::IsFirstOrLast(nsIFrame* aFrame,
const nsContinuationStates* aContinuationStates,
bool aSpanDirMatchesLineDir,
bool& aIsFirst /* out */,
bool& aIsLast /* out */)
--- a/layout/base/nsCaret.cpp
+++ b/layout/base/nsCaret.cpp
@@ -664,18 +664,19 @@ nsCaret::GetCaretFrameForNodeOffset(nsFr
//
// Direction Style from visibility->mDirection
// ------------------
// NS_STYLE_DIRECTION_LTR : LTR or Default
// NS_STYLE_DIRECTION_RTL
if (theFrame->PresContext()->BidiEnabled())
{
// If there has been a reflow, take the caret Bidi level to be the level of the current frame
- if (aBidiLevel & BIDI_LEVEL_UNDEFINED)
- aBidiLevel = NS_GET_EMBEDDING_LEVEL(theFrame);
+ if (aBidiLevel & BIDI_LEVEL_UNDEFINED) {
+ aBidiLevel = nsBidi::GetEmbeddingLevel(theFrame);
+ }
int32_t start;
int32_t end;
nsIFrame* frameBefore;
nsIFrame* frameAfter;
nsBidiLevel levelBefore; // Bidi level of the character before the caret
nsBidiLevel levelAfter; // Bidi level of the character after the caret
@@ -712,17 +713,17 @@ nsCaret::GetCaretFrameForNodeOffset(nsFr
theFrameOffset = end;
}
else
{
// if there is no frameBefore, we must be at the beginning of the line
// so we stay with the current frame.
// Exception: when the first frame on the line has a different Bidi level from the paragraph level, there is no
// real frame for the caret to be in. We have to find the visually first frame on the line.
- nsBidiLevel baseLevel = NS_GET_BASE_LEVEL(frameAfter);
+ nsBidiLevel baseLevel = nsBidi::GetBaseLevel(frameAfter);
if (baseLevel != levelAfter)
{
nsPeekOffsetStruct pos(eSelectBeginLine, eDirPrevious, 0,
nsPoint(0, 0), false, true, false,
true, false);
if (NS_SUCCEEDED(frameAfter->PeekOffset(&pos))) {
theFrame = pos.mResultFrame;
theFrameOffset = pos.mContentOffset;
@@ -747,17 +748,17 @@ nsCaret::GetCaretFrameForNodeOffset(nsFr
theFrameOffset = start;
}
else
{
// if there is no frameAfter, we must be at the end of the line
// so we stay with the current frame.
// Exception: when the last frame on the line has a different Bidi level from the paragraph level, there is no
// real frame for the caret to be in. We have to find the visually last frame on the line.
- nsBidiLevel baseLevel = NS_GET_BASE_LEVEL(frameBefore);
+ nsBidiLevel baseLevel = nsBidi::GetBaseLevel(frameBefore);
if (baseLevel != levelBefore)
{
nsPeekOffsetStruct pos(eSelectEndLine, eDirNext, 0,
nsPoint(0, 0), false, true, false,
true, false);
if (NS_SUCCEEDED(frameBefore->PeekOffset(&pos))) {
theFrame = pos.mResultFrame;
theFrameOffset = pos.mContentOffset;
@@ -768,31 +769,31 @@ nsCaret::GetCaretFrameForNodeOffset(nsFr
}
else if (aBidiLevel > levelBefore && aBidiLevel < levelAfter // rule c7/8
&& IS_SAME_DIRECTION(levelBefore, levelAfter) // before and after have the same parity
&& !IS_SAME_DIRECTION(aBidiLevel, levelAfter)) // caret has different parity
{
if (NS_SUCCEEDED(aFrameSelection->GetFrameFromLevel(frameAfter, eDirNext, aBidiLevel, &theFrame)))
{
theFrame->GetOffsets(start, end);
- levelAfter = NS_GET_EMBEDDING_LEVEL(theFrame);
+ levelAfter = nsBidi::GetEmbeddingLevel(theFrame);
if (IS_LEVEL_RTL(aBidiLevel)) // c8: caret to the right of the rightmost character
theFrameOffset = IS_LEVEL_RTL(levelAfter) ? start : end;
else // c7: caret to the left of the leftmost character
theFrameOffset = IS_LEVEL_RTL(levelAfter) ? end : start;
}
}
else if (aBidiLevel < levelBefore && aBidiLevel > levelAfter // rule c11/12
&& IS_SAME_DIRECTION(levelBefore, levelAfter) // before and after have the same parity
&& !IS_SAME_DIRECTION(aBidiLevel, levelAfter)) // caret has different parity
{
if (NS_SUCCEEDED(aFrameSelection->GetFrameFromLevel(frameBefore, eDirPrevious, aBidiLevel, &theFrame)))
{
theFrame->GetOffsets(start, end);
- levelBefore = NS_GET_EMBEDDING_LEVEL(theFrame);
+ levelBefore = nsBidi::GetEmbeddingLevel(theFrame);
if (IS_LEVEL_RTL(aBidiLevel)) // c12: caret to the left of the leftmost character
theFrameOffset = IS_LEVEL_RTL(levelBefore) ? end : start;
else // c11: caret to the right of the rightmost character
theFrameOffset = IS_LEVEL_RTL(levelBefore) ? start : end;
}
}
}
}
--- a/layout/generic/nsFrame.cpp
+++ b/layout/generic/nsFrame.cpp
@@ -146,18 +146,22 @@ struct nsContentAndOffset
// Some Misc #defines
#define SELECTION_DEBUG 0
#define FORCE_SELECTION_UPDATE 1
#define CALC_DEBUG 0
// This is faster than nsBidiPresUtils::IsFrameInParagraphDirection,
// because it uses the frame pointer passed in without drilling down to
// the leaf frame.
-#define REVERSED_DIRECTION_FRAME(frame) \
- (!IS_SAME_DIRECTION(NS_GET_EMBEDDING_LEVEL(frame), NS_GET_BASE_LEVEL(frame)))
+static bool
+IsReversedDirectionFrame(nsIFrame* aFrame)
+{
+ return !IS_SAME_DIRECTION(nsBidi::GetEmbeddingLevel(aFrame),
+ nsBidi::GetBaseLevel(aFrame));
+}
#include "nsILineIterator.h"
//non Hack prototypes
#if 0
static void RefreshContentFrames(nsPresContext* aPresContext, nsIContent * aStartContent, nsIContent * aEndContent);
#endif
@@ -7036,17 +7040,17 @@ nsIFrame::PeekOffsetParagraph(nsPeekOffs
}
}
return NS_OK;
}
// Determine movement direction relative to frame
static bool IsMovingInFrameDirection(nsIFrame* frame, nsDirection aDirection, bool aVisual)
{
- bool isReverseDirection = aVisual && REVERSED_DIRECTION_FRAME(frame);
+ bool isReverseDirection = aVisual && IsReversedDirectionFrame(frame);
return aDirection == (isReverseDirection ? eDirPrevious : eDirNext);
}
nsresult
nsIFrame::PeekOffset(nsPeekOffsetStruct* aPos)
{
if (!aPos)
return NS_ERROR_NULL_POINTER;
@@ -7672,17 +7676,17 @@ nsIFrame::GetFrameFromDirection(nsDirect
traversedFrame->IsSelectable(&selectable, nullptr);
if (!selectable) {
*aOutMovedOverNonSelectableText = true;
}
} // while (!selectable)
*aOutOffset = (aDirection == eDirNext) ? 0 : -1;
- if (aVisual && REVERSED_DIRECTION_FRAME(traversedFrame)) {
+ if (aVisual && IsReversedDirectionFrame(traversedFrame)) {
// The new frame is reverse-direction, go to the other end
*aOutOffset = -1 - *aOutOffset;
}
*aOutFrame = traversedFrame;
return NS_OK;
}
nsView* nsIFrame::GetClosestView(nsPoint* aOffset) const
--- a/layout/generic/nsSelection.cpp
+++ b/layout/generic/nsSelection.cpp
@@ -1118,27 +1118,27 @@ nsFrameSelection::MoveCaret(nsDirection
switch (aAmount) {
case eSelectBeginLine:
case eSelectEndLine:
// In Bidi contexts, PeekOffset calculates pos.mContentOffset
// differently depending on whether the movement is visual or logical.
// For visual movement, pos.mContentOffset depends on the direction-
// ality of the first/last frame on the line (theFrame), and the caret
// directionality must correspond.
- SetCaretBidiLevel(visualMovement ? NS_GET_EMBEDDING_LEVEL(theFrame) :
- NS_GET_BASE_LEVEL(theFrame));
+ SetCaretBidiLevel(visualMovement ? nsBidi::GetEmbeddingLevel(theFrame)
+ : nsBidi::GetBaseLevel(theFrame));
break;
default:
// If the current position is not a frame boundary, it's enough just
// to take the Bidi level of the current frame
if ((pos.mContentOffset != frameStart &&
pos.mContentOffset != frameEnd) ||
eSelectLine == aAmount) {
- SetCaretBidiLevel(NS_GET_EMBEDDING_LEVEL(theFrame));
+ SetCaretBidiLevel(nsBidi::GetEmbeddingLevel(theFrame));
}
else {
BidiLevelFromMove(mShell, pos.mResultContent, pos.mContentOffset,
aAmount, tHint);
}
}
}
result = TakeFocus(pos.mResultContent, pos.mContentOffset, pos.mContentOffset,
@@ -1358,35 +1358,35 @@ nsFrameSelection::GetPrevNextBidiLevels(
if (0 == frameStart && 0 == frameEnd)
direction = eDirPrevious;
else if (frameStart == currentOffset)
direction = eDirPrevious;
else if (frameEnd == currentOffset)
direction = eDirNext;
else {
// we are neither at the beginning nor at the end of the frame, so we have no worries
- levels.SetData(currentFrame, currentFrame,
- NS_GET_EMBEDDING_LEVEL(currentFrame),
- NS_GET_EMBEDDING_LEVEL(currentFrame));
+ nsBidiLevel currentLevel = nsBidi::GetEmbeddingLevel(currentFrame);
+ levels.SetData(currentFrame, currentFrame, currentLevel, currentLevel);
return levels;
}
nsIFrame *newFrame;
int32_t offset;
bool jumpedLine, movedOverNonSelectableText;
nsresult rv = currentFrame->GetFrameFromDirection(direction, false,
aJumpLines, true,
&newFrame, &offset, &jumpedLine,
&movedOverNonSelectableText);
if (NS_FAILED(rv))
newFrame = nullptr;
- nsBidiLevel baseLevel = NS_GET_BASE_LEVEL(currentFrame);
- nsBidiLevel currentLevel = NS_GET_EMBEDDING_LEVEL(currentFrame);
- nsBidiLevel newLevel = newFrame ? NS_GET_EMBEDDING_LEVEL(newFrame) : baseLevel;
+ nsBidiLevel baseLevel = nsBidi::GetBaseLevel(currentFrame);
+ nsBidiLevel currentLevel = nsBidi::GetEmbeddingLevel(currentFrame);
+ nsBidiLevel newLevel = newFrame ? nsBidi::GetEmbeddingLevel(newFrame)
+ : baseLevel;
// If not jumping lines, disregard br frames, since they might be positioned incorrectly.
// XXX This could be removed once bug 339786 is fixed.
if (!aJumpLines) {
if (currentFrame->GetType() == nsGkAtoms::brFrame) {
currentFrame = nullptr;
currentLevel = baseLevel;
}
@@ -1436,17 +1436,17 @@ nsFrameSelection::GetFrameFromLevel(nsIF
if (aDirection == eDirNext)
frameTraversal->Next();
else
frameTraversal->Prev();
foundFrame = frameTraversal->CurrentItem();
if (!foundFrame)
return NS_ERROR_FAILURE;
- foundLevel = NS_GET_EMBEDDING_LEVEL(foundFrame);
+ foundLevel = nsBidi::GetEmbeddingLevel(foundFrame);
} while (foundLevel > aBidiLevel);
return NS_OK;
}
nsresult
@@ -1536,17 +1536,17 @@ void nsFrameSelection::BidiLevelFromClic
{
nsIFrame* clickInFrame=nullptr;
int32_t OffsetNotUsed;
clickInFrame = GetFrameForNodeOffset(aNode, aContentOffset, mHint, &OffsetNotUsed);
if (!clickInFrame)
return;
- SetCaretBidiLevel(NS_GET_EMBEDDING_LEVEL(clickInFrame));
+ SetCaretBidiLevel(nsBidi::GetEmbeddingLevel(clickInFrame));
}
bool
nsFrameSelection::AdjustForMaintainedSelection(nsIContent *aContent,
int32_t aOffset)
{
if (!mMaintainRange)
@@ -6361,17 +6361,17 @@ Selection::SelectionLanguageChange(bool
int32_t frameStart, frameEnd;
focusFrame->GetOffsets(frameStart, frameEnd);
RefPtr<nsPresContext> context = GetPresContext();
nsBidiLevel levelBefore, levelAfter;
if (!context) {
return NS_ERROR_FAILURE;
}
- nsBidiLevel level = NS_GET_EMBEDDING_LEVEL(focusFrame);
+ nsBidiLevel level = nsBidi::GetEmbeddingLevel(focusFrame);
int32_t focusOffset = static_cast<int32_t>(FocusOffset());
if ((focusOffset != frameStart) && (focusOffset != frameEnd))
// the cursor is not at a frame boundary, so the level of both the characters (logically) before and after the cursor
// is equal to the frame level
levelBefore = levelAfter = level;
else {
// the cursor is at a frame boundary, so use GetPrevNextBidiLevels to find the level of the characters
// before and after the cursor
--- a/layout/generic/nsTextFrame.cpp
+++ b/layout/generic/nsTextFrame.cpp
@@ -1602,18 +1602,20 @@ BuildTextRunsScanner::ContinueTextRunAcr
{
// We don't need to check font size inflation, since
// |FindLineContainer| above (via |nsIFrame::CanContinueTextRun|)
// ensures that text runs never cross block boundaries. This means
// that the font size inflation on all text frames in the text run is
// already guaranteed to be the same as each other (and for the line
// container).
if (mBidiEnabled &&
- (NS_GET_EMBEDDING_LEVEL(aFrame1) != NS_GET_EMBEDDING_LEVEL(aFrame2) ||
- NS_GET_PARAGRAPH_DEPTH(aFrame1) != NS_GET_PARAGRAPH_DEPTH(aFrame2)))
+ (nsBidi::GetEmbeddingLevel(aFrame1) !=
+ nsBidi::GetEmbeddingLevel(aFrame2) ||
+ nsBidi::GetParagraphDepth(aFrame1) !=
+ nsBidi::GetParagraphDepth(aFrame2)))
return false;
nsStyleContext* sc1 = aFrame1->StyleContext();
const nsStyleText* textStyle1 = sc1->StyleText();
// If the first frame ends in a preformatted newline, then we end the textrun
// here. This avoids creating giant textruns for an entire plain text file.
// Note that we create a single text frame for a preformatted text node,
// even if it has newlines in it, so typically we won't see trailing newlines
@@ -2070,17 +2072,17 @@ BuildTextRunsScanner::BuildTextRunForFra
}
if (textFlags & nsTextFrameUtils::TEXT_HAS_TAB) {
textFlags |= gfxTextRunFactory::TEXT_ENABLE_SPACING;
}
if (textFlags & nsTextFrameUtils::TEXT_HAS_SHY) {
textFlags |= gfxTextRunFactory::TEXT_ENABLE_HYPHEN_BREAKS;
}
- if (mBidiEnabled && (IS_LEVEL_RTL(NS_GET_EMBEDDING_LEVEL(firstFrame)))) {
+ if (mBidiEnabled && (IS_LEVEL_RTL(nsBidi::GetEmbeddingLevel(firstFrame)))) {
textFlags |= gfxTextRunFactory::TEXT_IS_RTL;
}
if (mNextRunContextInfo & nsTextFrameUtils::INCOMING_WHITESPACE) {
textFlags |= nsTextFrameUtils::TEXT_TRAILING_WHITESPACE;
}
if (mNextRunContextInfo & nsTextFrameUtils::INCOMING_ARABICCHAR) {
textFlags |= gfxTextRunFactory::TEXT_TRAILING_ARABICCHAR;
}