Bug 263359 part 2: split nsBidiPresUtils::Resolve into Resolve and ResolveParagraph. r=roc

This commit is contained in:
Simon Montagu 2011-03-24 11:28:44 +02:00
Родитель 53a261431c
Коммит 0fc4771947
2 изменённых файлов: 65 добавлений и 51 удалений

Просмотреть файл

@ -320,11 +320,49 @@ nsBidiPresUtils::Resolve(nsBlockFrame* aBlockFrame)
nsPresContext *presContext = aBlockFrame->PresContext();
const nsStyleVisibility* vis = aBlockFrame->GetStyleVisibility();
mParaLevel = (NS_STYLE_DIRECTION_RTL == vis->mDirection) ?
NSBIDI_RTL : NSBIDI_LTR;
mLineIter = new nsBlockInFlowLineIterator(aBlockFrame,
aBlockFrame->begin_lines(),
PR_FALSE);
if (mLineIter->GetLine() == aBlockFrame->end_lines()) {
// Advance to first valid line (might be in a next-continuation)
mLineIter->Next();
}
mIsVisual = presContext->IsVisualMode();
if (mIsVisual) {
/**
* Drill up in content to detect whether this is an element that needs to be
* rendered with logical order even on visual pages.
*
* We always use logical order on form controls, firstly so that text entry
* will be in logical order, but also because visual pages were written with
* the assumption that even if the browser had no support for right-to-left
* text rendering, it would use native widgets with bidi support to display
* form controls.
*
* We also use logical order in XUL elements, since we expect that if a XUL
* element appears in a visual page, it will be generated by an XBL binding
* and contain localized text which will be in logical order.
*/
for (nsIContent* content = aBlockFrame->GetContent() ; content;
content = content->GetParent()) {
if (content->IsNodeOfType(nsINode::eHTML_FORM_CONTROL) ||
content->IsXUL()) {
mIsVisual = PR_FALSE;
break;
}
}
}
mPrevFrame = nsnull;
// handle bidi-override being set on the block itself before calling
// InitLogicalArray.
const nsStyleVisibility* vis = aBlockFrame->GetStyleVisibility();
const nsStyleTextReset* text = aBlockFrame->GetStyleTextReset();
PRUnichar ch = 0;
if (text->mUnicodeBidi == NS_STYLE_UNICODE_BIDI_OVERRIDE) {
if (NS_STYLE_DIRECTION_RTL == vis->mDirection) {
@ -352,28 +390,31 @@ nsBidiPresUtils::Resolve(nsBlockFrame* aBlockFrame)
// XXX: TODO: Handle preformatted text ('\n')
mBuffer.ReplaceChar("\t\r\n", kSpace);
ResolveParagraph(aBlockFrame);
return mSuccess;
}
void
nsBidiPresUtils::ResolveParagraph(nsBlockFrame* aBlockFrame)
{
nsPresContext *presContext = aBlockFrame->PresContext();
PRInt32 bufferLength = mBuffer.Length();
if (bufferLength < 1) {
mSuccess = NS_OK;
return mSuccess;
return;
}
PRInt32 runCount;
PRUint8 embeddingLevel;
PRUint8 embeddingLevel = mParaLevel;
nsBidiLevel paraLevel = embeddingLevel =
(NS_STYLE_DIRECTION_RTL == vis->mDirection)
? NSBIDI_RTL : NSBIDI_LTR;
mSuccess = mBidiEngine->SetPara(mBuffer.get(), bufferLength, paraLevel, nsnull);
mSuccess = mBidiEngine->SetPara(mBuffer.get(), bufferLength, mParaLevel, nsnull);
if (NS_FAILED(mSuccess) ) {
return mSuccess;
return;
}
mSuccess = mBidiEngine->CountRuns(&runCount);
if (NS_FAILED(mSuccess) ) {
return mSuccess;
return;
}
PRInt32 runLength = 0; // the length of the current run of text
PRInt32 lineOffset = 0; // the start of the current run
@ -389,38 +430,7 @@ nsBidiPresUtils::Resolve(nsBlockFrame* aBlockFrame)
PRInt32 contentTextLength;
FramePropertyTable *propTable = presContext->PropertyTable();
nsBlockInFlowLineIterator lineIter(aBlockFrame, aBlockFrame->begin_lines(), PR_FALSE);
if (lineIter.GetLine() == aBlockFrame->end_lines()) {
// Advance to first valid line (might be in a next-continuation)
lineIter.Next();
}
nsIFrame* prevFrame = nsnull;
PRBool lineNeedsUpdate = PR_FALSE;
PRBool isVisual = presContext->IsVisualMode();
if (isVisual) {
/**
* Drill up in content to detect whether this is an element that needs to be
* rendered with logical order even on visual pages.
*
* We always use logical order on form controls, firstly so that text entry
* will be in logical order, but also because visual pages were written with
* the assumption that even if the browser had no support for right-to-left
* text rendering, it would use native widgets with bidi support to display
* form controls.
*
* We also use logical order in XUL elements, since we expect that if a XUL
* element appears in a visual page, it will be generated by an XBL binding
* and contain localized text which will be in logical order.
*/
for (content = aBlockFrame->GetContent() ; content; content = content->GetParent()) {
if (content->IsNodeOfType(nsINode::eHTML_FORM_CONTROL) || content->IsXUL()) {
isVisual = PR_FALSE;
break;
}
}
}
#ifdef NOISY_BIDI
if (mBuffer[0] != kObjectSubstitute) {
@ -463,7 +473,7 @@ nsBidiPresUtils::Resolve(nsBlockFrame* aBlockFrame)
propTable->Set(frame, nsIFrame::EmbeddingLevelProperty(),
NS_INT32_TO_PTR(embeddingLevel));
propTable->Set(frame, nsIFrame::BaseLevelProperty(),
NS_INT32_TO_PTR(paraLevel));
NS_INT32_TO_PTR(mParaLevel));
continue;
}
PRInt32 start, end;
@ -487,8 +497,8 @@ nsBidiPresUtils::Resolve(nsBlockFrame* aBlockFrame)
break;
}
runLength = logicalLimit - lineOffset;
if (isVisual) {
embeddingLevel = paraLevel;
if (mIsVisual) {
embeddingLevel = mParaLevel;
}
} // if (runLength <= 0)
@ -500,7 +510,7 @@ nsBidiPresUtils::Resolve(nsBlockFrame* aBlockFrame)
propTable->Set(frame, nsIFrame::EmbeddingLevelProperty(),
NS_INT32_TO_PTR(embeddingLevel));
propTable->Set(frame, nsIFrame::BaseLevelProperty(),
NS_INT32_TO_PTR(paraLevel));
NS_INT32_TO_PTR(mParaLevel));
if (isTextFrame) {
if ( (runLength > 0) && (runLength < fragmentLength) ) {
/*
@ -508,10 +518,10 @@ nsBidiPresUtils::Resolve(nsBlockFrame* aBlockFrame)
* Create a non-fluid continuation frame for the next directional run.
*/
if (lineNeedsUpdate) {
AdvanceLineIteratorToFrame(frame, &lineIter, prevFrame);
AdvanceLineIteratorToFrame(frame, mLineIter, mPrevFrame);
lineNeedsUpdate = PR_FALSE;
}
lineIter.GetLine()->MarkDirty();
mLineIter->GetLine()->MarkDirty();
nsIFrame* nextBidi;
PRInt32 runEnd = contentOffset + runLength;
EnsureBidiContinuation(frame, &nextBidi, frameIndex,
@ -562,10 +572,10 @@ nsBidiPresUtils::Resolve(nsBlockFrame* aBlockFrame)
}
frame->AdjustOffsetsForBidi(contentOffset, contentOffset + fragmentLength);
if (lineNeedsUpdate) {
AdvanceLineIteratorToFrame(frame, &lineIter, prevFrame);
AdvanceLineIteratorToFrame(frame, mLineIter, mPrevFrame);
lineNeedsUpdate = PR_FALSE;
}
lineIter.GetLine()->MarkDirty();
mLineIter->GetLine()->MarkDirty();
}
} // isTextFrame
else {
@ -621,7 +631,6 @@ nsBidiPresUtils::Resolve(nsBlockFrame* aBlockFrame)
printf("===\n");
}
#endif
return mSuccess;
}
// Should this frame be treated as a leaf (e.g. when building mLogicalFrames)?

Просмотреть файл

@ -175,6 +175,7 @@ public:
* @lina 06/18/2000
*/
nsresult Resolve(nsBlockFrame* aBlockFrame);
void ResolveParagraph(nsBlockFrame* aBlockFrame);
/**
* Reorder this line using Bidi engine.
@ -514,8 +515,12 @@ private:
PRInt32* mIndexMap;
PRUint8* mLevels;
nsresult mSuccess;
PRPackedBool mIsVisual;
nsBidiLevel mParaLevel;
nsIFrame* mPrevFrame;
nsIContent* mPrevContent;
nsAutoPtr<nsBlockInFlowLineIterator> mLineIter;
nsBidi* mBidiEngine;
};