Bug 1281099 part 1 - Convert some macros to functions to help later change. r=jfkthame

MozReview-Commit-ID: 2OS5eIsNAYN
This commit is contained in:
Xidorn Quan
2016-06-21 17:21:09 +10:00
parent 0eb670016d
commit e4b1698b6a
6 changed files with 47 additions and 34 deletions

View File

@@ -662,14 +662,20 @@ public:
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;

View File

@@ -1293,13 +1293,13 @@ nsBidiPresUtils::GetFirstLeaf(nsIFrame* aFrame)
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));
}
@@ -1310,7 +1310,7 @@ nsBidiPresUtils::GetFrameBaseLevel(nsIFrame* aFrame)
while (!IsBidiLeaf(firstLeaf)) {
firstLeaf = firstLeaf->PrincipalChildList().FirstChild();
}
return NS_GET_BASE_LEVEL(firstLeaf);
return nsBidi::GetBaseLevel(firstLeaf);
}
void

View File

@@ -670,8 +670,9 @@ nsCaret::GetCaretFrameForNodeOffset(nsFrameSelection* aFrameSelection,
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;
@@ -718,7 +719,7 @@ nsCaret::GetCaretFrameForNodeOffset(nsFrameSelection* aFrameSelection,
// 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,
@@ -753,7 +754,7 @@ nsCaret::GetCaretFrameForNodeOffset(nsFrameSelection* aFrameSelection,
// 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,
@@ -774,7 +775,7 @@ nsCaret::GetCaretFrameForNodeOffset(nsFrameSelection* aFrameSelection,
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
@@ -788,7 +789,7 @@ nsCaret::GetCaretFrameForNodeOffset(nsFrameSelection* aFrameSelection,
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

View File

@@ -151,8 +151,12 @@ struct nsContentAndOffset
// 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"
@@ -7041,7 +7045,7 @@ nsIFrame::PeekOffsetParagraph(nsPeekOffsetStruct *aPos)
// 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);
}
@@ -7677,7 +7681,7 @@ nsIFrame::GetFrameFromDirection(nsDirection aDirection, bool aVisual,
*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;
}

View File

@@ -1123,8 +1123,8 @@ nsFrameSelection::MoveCaret(nsDirection aDirection,
// 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:
@@ -1133,7 +1133,7 @@ nsFrameSelection::MoveCaret(nsDirection aDirection,
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,
@@ -1363,9 +1363,8 @@ nsFrameSelection::GetPrevNextBidiLevels(nsIContent* aNode,
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;
}
@@ -1379,9 +1378,10 @@ nsFrameSelection::GetPrevNextBidiLevels(nsIContent* aNode,
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.
@@ -1441,7 +1441,7 @@ nsFrameSelection::GetFrameFromLevel(nsIFrame *aFrameIn,
foundFrame = frameTraversal->CurrentItem();
if (!foundFrame)
return NS_ERROR_FAILURE;
foundLevel = NS_GET_EMBEDDING_LEVEL(foundFrame);
foundLevel = nsBidi::GetEmbeddingLevel(foundFrame);
} while (foundLevel > aBidiLevel);
@@ -1541,7 +1541,7 @@ void nsFrameSelection::BidiLevelFromClick(nsIContent *aNode,
if (!clickInFrame)
return;
SetCaretBidiLevel(NS_GET_EMBEDDING_LEVEL(clickInFrame));
SetCaretBidiLevel(nsBidi::GetEmbeddingLevel(clickInFrame));
}
@@ -6366,7 +6366,7 @@ Selection::SelectionLanguageChange(bool aLangRTL)
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

View File

@@ -1607,8 +1607,10 @@ BuildTextRunsScanner::ContinueTextRunAcrossFrames(nsTextFrame* aFrame1, nsTextFr
// 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();
@@ -2075,7 +2077,7 @@ BuildTextRunsScanner::BuildTextRunForFrames(void* aTextBuffer)
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) {