2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifdef IBMBIDI
|
|
|
|
|
|
|
|
#include "nsBidiPresUtils.h"
|
|
|
|
#include "nsTextFragment.h"
|
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsPresContext.h"
|
2011-04-07 18:04:40 -07:00
|
|
|
#include "nsRenderingContext.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsFrameManager.h"
|
|
|
|
#include "nsBidiUtils.h"
|
|
|
|
#include "nsCSSFrameConstructor.h"
|
2011-12-27 12:18:48 -08:00
|
|
|
#include "nsContainerFrame.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsInlineFrame.h"
|
2007-08-29 01:21:38 -07:00
|
|
|
#include "nsPlaceholderFrame.h"
|
2010-03-17 10:30:30 -07:00
|
|
|
#include "nsFirstLetterFrame.h"
|
2012-02-24 02:15:46 -08:00
|
|
|
#include "nsUnicodeProperties.h"
|
2011-04-11 01:00:28 -07:00
|
|
|
#include "nsTextFrame.h"
|
2012-08-02 04:38:51 -07:00
|
|
|
#include "nsStyleStructInlines.h"
|
2013-01-15 04:22:03 -08:00
|
|
|
#include <algorithm>
|
2011-03-24 02:28:44 -07:00
|
|
|
|
2011-04-11 00:59:29 -07:00
|
|
|
#undef NOISY_BIDI
|
|
|
|
#undef REALLY_NOISY_BIDI
|
|
|
|
|
2010-03-28 18:46:55 -07:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
static const PRUnichar kSpace = 0x0020;
|
2012-02-25 23:12:55 -08:00
|
|
|
static const PRUnichar kZWSP = 0x200B;
|
2007-03-22 10:30:00 -07:00
|
|
|
static const PRUnichar kLineSeparator = 0x2028;
|
|
|
|
static const PRUnichar kObjectSubstitute = 0xFFFC;
|
|
|
|
static const PRUnichar kLRE = 0x202A;
|
|
|
|
static const PRUnichar kRLE = 0x202B;
|
|
|
|
static const PRUnichar kLRO = 0x202D;
|
|
|
|
static const PRUnichar kRLO = 0x202E;
|
|
|
|
static const PRUnichar kPDF = 0x202C;
|
|
|
|
|
2011-04-11 00:59:30 -07:00
|
|
|
#define NS_BIDI_CONTROL_FRAME ((nsIFrame*)0xfffb1d1)
|
2011-04-13 02:23:49 -07:00
|
|
|
|
2011-04-13 02:23:49 -07:00
|
|
|
struct BidiParagraphData {
|
|
|
|
nsString mBuffer;
|
|
|
|
nsAutoTArray<PRUnichar, 16> mEmbeddingStack;
|
|
|
|
nsTArray<nsIFrame*> mLogicalFrames;
|
|
|
|
nsTArray<nsLineBox*> mLinePerFrame;
|
2012-08-22 08:56:38 -07:00
|
|
|
nsDataHashtable<nsISupportsHashKey, int32_t> mContentToFrameIndex;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mIsVisual;
|
2011-12-07 02:07:42 -08:00
|
|
|
bool mReset;
|
2011-04-13 02:23:49 -07:00
|
|
|
nsBidiLevel mParaLevel;
|
|
|
|
nsIContent* mPrevContent;
|
|
|
|
nsAutoPtr<nsBidi> mBidiEngine;
|
|
|
|
nsIFrame* mPrevFrame;
|
2011-10-18 05:51:57 -07:00
|
|
|
nsAutoPtr<BidiParagraphData> mSubParagraph;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t mParagraphDepth;
|
2011-04-13 02:23:49 -07:00
|
|
|
|
|
|
|
void Init(nsBlockFrame *aBlockFrame)
|
|
|
|
{
|
|
|
|
mContentToFrameIndex.Init();
|
|
|
|
mBidiEngine = new nsBidi();
|
2012-07-30 07:20:58 -07:00
|
|
|
mPrevContent = nullptr;
|
2012-01-11 11:26:02 -08:00
|
|
|
mParagraphDepth = 0;
|
2011-10-18 05:51:58 -07:00
|
|
|
|
|
|
|
bool styleDirectionIsRTL =
|
|
|
|
(NS_STYLE_DIRECTION_RTL == aBlockFrame->GetStyleVisibility()->mDirection);
|
|
|
|
if (aBlockFrame->GetStyleTextReset()->mUnicodeBidi &
|
|
|
|
NS_STYLE_UNICODE_BIDI_PLAINTEXT) {
|
|
|
|
// unicode-bidi: plaintext: the Bidi algorithm will determine the
|
|
|
|
// directionality of the paragraph according to the first strong
|
2012-02-22 00:30:32 -08:00
|
|
|
// directional character, defaulting to LTR if there is none.
|
|
|
|
mParaLevel = NSBIDI_DEFAULT_LTR;
|
2011-10-18 05:51:58 -07:00
|
|
|
} else {
|
|
|
|
mParaLevel = styleDirectionIsRTL ? NSBIDI_RTL : NSBIDI_LTR;
|
|
|
|
}
|
2011-04-13 02:23:49 -07:00
|
|
|
|
|
|
|
mIsVisual = aBlockFrame->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()) {
|
2011-10-17 07:59:28 -07:00
|
|
|
mIsVisual = false;
|
2011-04-13 02:23:49 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-04-13 02:23:49 -07:00
|
|
|
}
|
|
|
|
|
2011-10-18 05:51:57 -07:00
|
|
|
BidiParagraphData* GetSubParagraph()
|
|
|
|
{
|
|
|
|
if (!mSubParagraph) {
|
|
|
|
mSubParagraph = new BidiParagraphData();
|
|
|
|
mSubParagraph->Init(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
return mSubParagraph;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Initialise a sub-paragraph from its containing paragraph
|
|
|
|
void Init(BidiParagraphData *aBpd)
|
|
|
|
{
|
|
|
|
mContentToFrameIndex.Init();
|
|
|
|
mBidiEngine = new nsBidi();
|
2012-07-30 07:20:58 -07:00
|
|
|
mPrevContent = nullptr;
|
2011-10-18 05:51:57 -07:00
|
|
|
mIsVisual = aBpd->mIsVisual;
|
2011-12-07 02:07:42 -08:00
|
|
|
mReset = false;
|
2011-10-18 05:51:57 -07:00
|
|
|
}
|
|
|
|
|
2012-01-11 11:26:02 -08:00
|
|
|
void Reset(nsIFrame* aBDIFrame, BidiParagraphData *aBpd)
|
2011-10-18 05:51:57 -07:00
|
|
|
{
|
2011-12-07 02:07:42 -08:00
|
|
|
mReset = true;
|
2011-10-18 05:51:57 -07:00
|
|
|
mLogicalFrames.Clear();
|
|
|
|
mLinePerFrame.Clear();
|
|
|
|
mContentToFrameIndex.Clear();
|
|
|
|
mBuffer.SetLength(0);
|
|
|
|
mPrevFrame = aBpd->mPrevFrame;
|
2012-01-11 11:26:02 -08:00
|
|
|
mParagraphDepth = aBpd->mParagraphDepth + 1;
|
2011-10-18 05:51:57 -07:00
|
|
|
|
2012-05-09 01:44:52 -07:00
|
|
|
const nsStyleTextReset* text = aBDIFrame->GetStyleTextReset();
|
2011-10-18 05:51:57 -07:00
|
|
|
bool isRTL = (NS_STYLE_DIRECTION_RTL ==
|
2012-01-11 11:26:02 -08:00
|
|
|
aBDIFrame->GetStyleVisibility()->mDirection);
|
2011-10-18 05:51:57 -07:00
|
|
|
|
2012-05-09 01:44:52 -07:00
|
|
|
if (text->mUnicodeBidi & NS_STYLE_UNICODE_BIDI_PLAINTEXT) {
|
|
|
|
mParaLevel = NSBIDI_DEFAULT_LTR;
|
|
|
|
} else {
|
|
|
|
mParaLevel = mParagraphDepth * 2;
|
|
|
|
if (isRTL) ++mParaLevel;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (text->mUnicodeBidi & NS_STYLE_UNICODE_BIDI_OVERRIDE) {
|
2011-10-18 05:51:57 -07:00
|
|
|
PushBidiControl(isRTL ? kRLO : kLRO);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-08 09:22:38 -07:00
|
|
|
void EmptyBuffer()
|
|
|
|
{
|
|
|
|
mBuffer.SetLength(0);
|
|
|
|
}
|
|
|
|
|
2011-04-13 02:23:49 -07:00
|
|
|
nsresult SetPara()
|
|
|
|
{
|
|
|
|
return mBidiEngine->SetPara(mBuffer.get(), BufferLength(),
|
2012-07-30 07:20:58 -07:00
|
|
|
mParaLevel, nullptr);
|
2011-04-13 02:23:49 -07:00
|
|
|
}
|
|
|
|
|
2011-10-18 05:51:58 -07:00
|
|
|
/**
|
2012-02-22 00:30:32 -08:00
|
|
|
* mParaLevel can be NSBIDI_DEFAULT_LTR as well as NSBIDI_LTR or NSBIDI_RTL.
|
2011-10-18 05:51:58 -07:00
|
|
|
* GetParaLevel() returns the actual (resolved) paragraph level which is
|
|
|
|
* always either NSBIDI_LTR or NSBIDI_RTL
|
|
|
|
*/
|
|
|
|
nsBidiLevel GetParaLevel()
|
|
|
|
{
|
|
|
|
nsBidiLevel paraLevel = mParaLevel;
|
|
|
|
if (IS_DEFAULT_LEVEL(paraLevel)) {
|
|
|
|
mBidiEngine->GetParaLevel(¶Level);
|
|
|
|
}
|
|
|
|
return paraLevel;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
nsresult CountRuns(int32_t *runCount){ return mBidiEngine->CountRuns(runCount); }
|
2011-04-13 02:23:49 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
nsresult GetLogicalRun(int32_t aLogicalStart,
|
|
|
|
int32_t* aLogicalLimit,
|
2011-04-13 02:23:49 -07:00
|
|
|
nsBidiLevel* aLevel)
|
|
|
|
{
|
|
|
|
nsresult rv = mBidiEngine->GetLogicalRun(aLogicalStart,
|
|
|
|
aLogicalLimit, aLevel);
|
|
|
|
if (mIsVisual || NS_FAILED(rv))
|
2011-10-18 05:51:58 -07:00
|
|
|
*aLevel = GetParaLevel();
|
2011-04-13 02:23:49 -07:00
|
|
|
return rv;
|
2011-04-13 02:23:49 -07:00
|
|
|
}
|
2011-04-13 02:23:49 -07:00
|
|
|
|
|
|
|
void ResetData()
|
|
|
|
{
|
|
|
|
mLogicalFrames.Clear();
|
|
|
|
mLinePerFrame.Clear();
|
|
|
|
mContentToFrameIndex.Clear();
|
|
|
|
mBuffer.SetLength(0);
|
2012-07-30 07:20:58 -07:00
|
|
|
mPrevContent = nullptr;
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i < mEmbeddingStack.Length(); ++i) {
|
2011-04-13 02:23:49 -07:00
|
|
|
mBuffer.Append(mEmbeddingStack[i]);
|
|
|
|
mLogicalFrames.AppendElement(NS_BIDI_CONTROL_FRAME);
|
2012-07-30 07:20:58 -07:00
|
|
|
mLinePerFrame.AppendElement((nsLineBox*)nullptr);
|
2011-04-13 02:23:49 -07:00
|
|
|
}
|
2011-04-13 02:23:49 -07:00
|
|
|
}
|
|
|
|
|
2011-04-13 02:23:49 -07:00
|
|
|
void AppendFrame(nsIFrame* aFrame,
|
|
|
|
nsBlockInFlowLineIterator* aLineIter,
|
2012-07-30 07:20:58 -07:00
|
|
|
nsIContent* aContent = nullptr)
|
2011-04-13 02:23:49 -07:00
|
|
|
{
|
|
|
|
if (aContent) {
|
|
|
|
mContentToFrameIndex.Put(aContent, FrameCount());
|
|
|
|
}
|
|
|
|
mLogicalFrames.AppendElement(aFrame);
|
|
|
|
|
|
|
|
AdvanceLineIteratorToFrame(aFrame, aLineIter, mPrevFrame);
|
|
|
|
mLinePerFrame.AppendElement(aLineIter->GetLine().get());
|
|
|
|
}
|
|
|
|
|
|
|
|
void AdvanceAndAppendFrame(nsIFrame** aFrame,
|
|
|
|
nsBlockInFlowLineIterator* aLineIter,
|
|
|
|
nsIFrame** aNextSibling)
|
|
|
|
{
|
|
|
|
nsIFrame* frame = *aFrame;
|
|
|
|
nsIFrame* nextSibling = *aNextSibling;
|
|
|
|
|
|
|
|
frame = frame->GetNextContinuation();
|
|
|
|
if (frame) {
|
2012-07-30 07:20:58 -07:00
|
|
|
AppendFrame(frame, aLineIter, nullptr);
|
2011-04-13 02:23:49 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If we have already overshot the saved next-sibling while
|
|
|
|
* scanning the frame's continuations, advance it.
|
|
|
|
*/
|
|
|
|
if (frame == nextSibling) {
|
|
|
|
nextSibling = frame->GetNextSibling();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*aFrame = frame;
|
|
|
|
*aNextSibling = nextSibling;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t GetLastFrameForContent(nsIContent *aContent)
|
2011-04-13 02:23:49 -07:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t index = 0;
|
2011-04-13 02:23:49 -07:00
|
|
|
mContentToFrameIndex.Get(aContent, &index);
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t FrameCount(){ return mLogicalFrames.Length(); }
|
2011-04-13 02:23:49 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t BufferLength(){ return mBuffer.Length(); }
|
2011-04-13 02:23:49 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
nsIFrame* FrameAt(int32_t aIndex){ return mLogicalFrames[aIndex]; }
|
2011-04-13 02:23:49 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
nsLineBox* GetLineForFrameAt(int32_t aIndex){ return mLinePerFrame[aIndex]; }
|
2011-04-13 02:23:49 -07:00
|
|
|
|
|
|
|
void AppendUnichar(PRUnichar aCh){ mBuffer.Append(aCh); }
|
|
|
|
|
|
|
|
void AppendString(const nsDependentSubstring& aString){ mBuffer.Append(aString); }
|
|
|
|
|
2011-10-18 05:51:57 -07:00
|
|
|
void AppendControlChar(PRUnichar aCh)
|
2011-04-13 02:23:49 -07:00
|
|
|
{
|
2011-10-18 05:51:57 -07:00
|
|
|
mLogicalFrames.AppendElement(NS_BIDI_CONTROL_FRAME);
|
2012-07-30 07:20:58 -07:00
|
|
|
mLinePerFrame.AppendElement((nsLineBox*)nullptr);
|
2011-04-13 02:23:49 -07:00
|
|
|
AppendUnichar(aCh);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PushBidiControl(PRUnichar aCh)
|
|
|
|
{
|
2011-10-18 05:51:57 -07:00
|
|
|
AppendControlChar(aCh);
|
2011-04-13 02:23:49 -07:00
|
|
|
mEmbeddingStack.AppendElement(aCh);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PopBidiControl()
|
|
|
|
{
|
2011-10-18 05:51:57 -07:00
|
|
|
AppendControlChar(kPDF);
|
2011-04-13 02:23:49 -07:00
|
|
|
NS_ASSERTION(mEmbeddingStack.Length(), "embedding/override underflow");
|
|
|
|
mEmbeddingStack.TruncateLength(mEmbeddingStack.Length() - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClearBidiControls()
|
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i < mEmbeddingStack.Length(); ++i) {
|
2011-10-18 05:51:57 -07:00
|
|
|
AppendControlChar(kPDF);
|
2011-04-13 02:23:49 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool
|
2011-04-13 02:23:49 -07:00
|
|
|
IsFrameInCurrentLine(nsBlockInFlowLineIterator* aLineIter,
|
|
|
|
nsIFrame* aPrevFrame, nsIFrame* aFrame)
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
nsIFrame* endFrame = aLineIter->IsLastLineInList() ? nullptr :
|
2011-04-13 02:23:49 -07:00
|
|
|
aLineIter->GetLine().next()->mFirstChild;
|
|
|
|
nsIFrame* startFrame = aPrevFrame ? aPrevFrame : aLineIter->GetLine()->mFirstChild;
|
|
|
|
for (nsIFrame* frame = startFrame; frame && frame != endFrame;
|
|
|
|
frame = frame->GetNextSibling()) {
|
|
|
|
if (frame == aFrame)
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2011-04-13 02:23:49 -07:00
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2011-04-13 02:23:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
AdvanceLineIteratorToFrame(nsIFrame* aFrame,
|
|
|
|
nsBlockInFlowLineIterator* aLineIter,
|
|
|
|
nsIFrame*& aPrevFrame)
|
|
|
|
{
|
|
|
|
// Advance aLine to the line containing aFrame
|
|
|
|
nsIFrame* child = aFrame;
|
2012-06-10 16:44:50 -07:00
|
|
|
nsIFrame* parent = nsLayoutUtils::GetParentOrPlaceholderFor(child);
|
2011-04-13 02:23:49 -07:00
|
|
|
while (parent && !nsLayoutUtils::GetAsBlock(parent)) {
|
|
|
|
child = parent;
|
2012-06-10 16:44:50 -07:00
|
|
|
parent = nsLayoutUtils::GetParentOrPlaceholderFor(child);
|
2011-04-13 02:23:49 -07:00
|
|
|
}
|
|
|
|
NS_ASSERTION (parent, "aFrame is not a descendent of aBlockFrame");
|
|
|
|
while (!IsFrameInCurrentLine(aLineIter, aPrevFrame, child)) {
|
|
|
|
#ifdef DEBUG
|
2011-09-28 23:19:26 -07:00
|
|
|
bool hasNext =
|
2011-04-13 02:23:49 -07:00
|
|
|
#endif
|
|
|
|
aLineIter->Next();
|
|
|
|
NS_ASSERTION(hasNext, "Can't find frame in lines!");
|
2012-07-30 07:20:58 -07:00
|
|
|
aPrevFrame = nullptr;
|
2011-04-13 02:23:49 -07:00
|
|
|
}
|
|
|
|
aPrevFrame = child;
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
struct BidiLineData {
|
|
|
|
nsTArray<nsIFrame*> mLogicalFrames;
|
|
|
|
nsTArray<nsIFrame*> mVisualFrames;
|
2012-08-22 08:56:38 -07:00
|
|
|
nsTArray<int32_t> mIndexMap;
|
|
|
|
nsAutoTArray<uint8_t, 18> mLevels;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mIsReordered;
|
2011-04-13 02:23:49 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
BidiLineData(nsIFrame* aFirstFrameOnLine, int32_t aNumFramesOnLine)
|
2011-04-13 02:23:49 -07:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Initialize the logically-ordered array of frames using the top-level
|
|
|
|
* frames of a single line
|
|
|
|
*/
|
|
|
|
mLogicalFrames.Clear();
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isReordered = false;
|
|
|
|
bool hasRTLFrames = false;
|
2011-04-13 02:23:49 -07:00
|
|
|
|
|
|
|
for (nsIFrame* frame = aFirstFrameOnLine;
|
|
|
|
frame && aNumFramesOnLine--;
|
|
|
|
frame = frame->GetNextSibling()) {
|
|
|
|
AppendFrame(frame);
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t level = nsBidiPresUtils::GetFrameEmbeddingLevel(frame);
|
2011-04-13 02:23:49 -07:00
|
|
|
mLevels.AppendElement(level);
|
|
|
|
mIndexMap.AppendElement(0);
|
|
|
|
if (level & 1) {
|
2011-10-17 07:59:28 -07:00
|
|
|
hasRTLFrames = true;
|
2011-04-13 02:23:49 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reorder the line
|
|
|
|
nsBidi::ReorderVisual(mLevels.Elements(), FrameCount(),
|
|
|
|
mIndexMap.Elements());
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
for (int32_t i = 0; i < FrameCount(); i++) {
|
2011-04-13 02:23:49 -07:00
|
|
|
mVisualFrames.AppendElement(LogicalFrameAt(mIndexMap[i]));
|
|
|
|
if (i != mIndexMap[i]) {
|
2011-10-17 07:59:28 -07:00
|
|
|
isReordered = true;
|
2011-04-13 02:23:49 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If there's an RTL frame, assume the line is reordered
|
|
|
|
mIsReordered = isReordered || hasRTLFrames;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AppendFrame(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
mLogicalFrames.AppendElement(aFrame);
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t FrameCount(){ return mLogicalFrames.Length(); }
|
2011-04-13 02:23:49 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
nsIFrame* LogicalFrameAt(int32_t aIndex){ return mLogicalFrames[aIndex]; }
|
2011-04-13 02:23:49 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
nsIFrame* VisualFrameAt(int32_t aIndex){ return mVisualFrames[aIndex]; }
|
2011-04-13 02:23:49 -07:00
|
|
|
};
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/* Some helper methods for Resolve() */
|
|
|
|
|
|
|
|
// Should this frame be split between text runs?
|
2012-06-21 03:51:38 -07:00
|
|
|
static bool
|
|
|
|
IsBidiSplittable(nsIFrame* aFrame)
|
|
|
|
{
|
2007-03-22 10:30:00 -07:00
|
|
|
// Bidi inline containers should be split, unless they're line frames.
|
|
|
|
return aFrame->IsFrameOfType(nsIFrame::eBidiInlineContainer)
|
2012-06-21 03:51:38 -07:00
|
|
|
&& aFrame->GetType() != nsGkAtoms::lineFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Should this frame be treated as a leaf (e.g. when building mLogicalFrames)?
|
|
|
|
static bool
|
|
|
|
IsBidiLeaf(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
nsIFrame* kid = aFrame->GetFirstPrincipalChild();
|
|
|
|
return !kid || !aFrame->IsFrameOfType(nsIFrame::eBidiInlineContainer);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-01-11 11:26:02 -08:00
|
|
|
/**
|
|
|
|
* Create non-fluid continuations for the ancestors of a given frame all the way
|
|
|
|
* up the frame tree until we hit a non-splittable frame (a line or a block).
|
|
|
|
*
|
|
|
|
* @param aParent the first parent frame to be split
|
|
|
|
* @param aFrame the child frames after this frame are reparented to the
|
|
|
|
* newly-created continuation of aParent.
|
|
|
|
* If aFrame is null, all the children of aParent are reparented.
|
|
|
|
*/
|
2007-03-22 10:30:00 -07:00
|
|
|
static nsresult
|
2012-01-11 11:26:02 -08:00
|
|
|
SplitInlineAncestors(nsIFrame* aParent,
|
|
|
|
nsIFrame* aFrame)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-01-11 11:26:02 -08:00
|
|
|
nsPresContext *presContext = aParent->PresContext();
|
2007-08-29 02:19:16 -07:00
|
|
|
nsIPresShell *presShell = presContext->PresShell();
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIFrame* frame = aFrame;
|
2012-01-11 11:26:02 -08:00
|
|
|
nsIFrame* parent = aParent;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIFrame* newParent;
|
|
|
|
|
|
|
|
while (IsBidiSplittable(parent)) {
|
|
|
|
nsIFrame* grandparent = parent->GetParent();
|
|
|
|
NS_ASSERTION(grandparent, "Couldn't get parent's parent in nsBidiPresUtils::SplitInlineAncestors");
|
|
|
|
|
2012-01-11 11:26:02 -08:00
|
|
|
// Split the child list after |frame|, unless it is the last child.
|
|
|
|
if (!frame || frame->GetNextSibling()) {
|
2012-08-13 20:51:36 -07:00
|
|
|
|
|
|
|
nsresult rv = presShell->FrameConstructor()->
|
|
|
|
CreateContinuingFrame(presContext, parent, grandparent, &newParent, false);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2012-01-11 11:26:02 -08:00
|
|
|
nsContainerFrame* container = do_QueryFrame(parent);
|
|
|
|
nsFrameList tail = container->StealFramesAfter(frame);
|
|
|
|
|
|
|
|
// Reparent views as necessary
|
|
|
|
rv = nsContainerFrame::ReparentFrameViewList(presContext, tail, parent, newParent);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-01-11 11:26:02 -08:00
|
|
|
// The parent's continuation adopts the siblings after the split.
|
2012-07-30 07:20:58 -07:00
|
|
|
rv = newParent->InsertFrames(nsIFrame::kNoReflowPrincipalList, nullptr, tail);
|
2012-01-11 11:26:02 -08:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-13 20:51:36 -07:00
|
|
|
// The list name kNoReflowPrincipalList would indicate we don't want reflow
|
|
|
|
nsFrameList temp(newParent, newParent);
|
|
|
|
rv = grandparent->InsertFrames(nsIFrame::kNoReflowPrincipalList, parent, temp);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
frame = parent;
|
|
|
|
parent = grandparent;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-04-11 01:00:28 -07:00
|
|
|
static void
|
|
|
|
MakeContinuationFluid(nsIFrame* aFrame, nsIFrame* aNext)
|
|
|
|
{
|
|
|
|
NS_ASSERTION (!aFrame->GetNextInFlow() || aFrame->GetNextInFlow() == aNext,
|
|
|
|
"next-in-flow is not next continuation!");
|
|
|
|
aFrame->SetNextInFlow(aNext);
|
|
|
|
|
|
|
|
NS_ASSERTION (!aNext->GetPrevInFlow() || aNext->GetPrevInFlow() == aFrame,
|
|
|
|
"prev-in-flow is not prev continuation!");
|
|
|
|
aNext->SetPrevInFlow(aFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
// If aFrame is the last child of its parent, convert bidi continuations to
|
|
|
|
// fluid continuations for all of its inline ancestors.
|
2012-03-21 16:50:54 -07:00
|
|
|
// If it isn't the last child, make sure that its continuation is fluid.
|
2008-03-21 01:39:16 -07:00
|
|
|
static void
|
2008-03-21 01:17:41 -07:00
|
|
|
JoinInlineAncestors(nsIFrame* aFrame)
|
|
|
|
{
|
2012-03-21 16:50:54 -07:00
|
|
|
nsIFrame* frame = aFrame;
|
|
|
|
do {
|
2008-03-21 01:17:41 -07:00
|
|
|
nsIFrame* next = frame->GetNextContinuation();
|
|
|
|
if (next) {
|
2012-01-11 11:26:02 -08:00
|
|
|
// Don't join frames if they come from different paragraph depths (i.e.
|
|
|
|
// one is bidi isolated relative to the other
|
|
|
|
if (nsBidiPresUtils::GetParagraphDepth(frame) ==
|
|
|
|
nsBidiPresUtils::GetParagraphDepth(next)) {
|
|
|
|
MakeContinuationFluid(frame, next);
|
|
|
|
}
|
2008-03-21 01:17:41 -07:00
|
|
|
}
|
2008-03-27 12:27:32 -07:00
|
|
|
// Join the parent only as long as we're its last child.
|
|
|
|
if (frame->GetNextSibling())
|
|
|
|
break;
|
2008-03-21 01:17:41 -07:00
|
|
|
frame = frame->GetParent();
|
2012-03-21 16:50:54 -07:00
|
|
|
} while (frame && IsBidiSplittable(frame));
|
2008-03-21 01:17:41 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
static nsresult
|
2011-04-11 01:00:28 -07:00
|
|
|
CreateContinuation(nsIFrame* aFrame,
|
|
|
|
nsIFrame** aNewFrame,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aIsFluid)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aNewFrame, "null OUT ptr");
|
|
|
|
NS_PRECONDITION(aFrame, "null ptr");
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
*aNewFrame = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-08-29 02:19:16 -07:00
|
|
|
nsPresContext *presContext = aFrame->PresContext();
|
|
|
|
nsIPresShell *presShell = presContext->PresShell();
|
2011-04-11 01:00:28 -07:00
|
|
|
NS_ASSERTION(presShell, "PresShell must be set on PresContext before calling nsBidiPresUtils::CreateContinuation");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsIFrame* parent = aFrame->GetParent();
|
2011-04-11 01:00:28 -07:00
|
|
|
NS_ASSERTION(parent, "Couldn't get frame parent in nsBidiPresUtils::CreateContinuation");
|
2009-10-27 19:00:57 -07:00
|
|
|
|
2010-03-17 10:30:30 -07:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
2009-10-27 19:00:57 -07:00
|
|
|
// Have to special case floating first letter frames because the continuation
|
|
|
|
// doesn't go in the first letter frame. The continuation goes with the rest
|
|
|
|
// of the text that the first letter frame was made out of.
|
|
|
|
if (parent->GetType() == nsGkAtoms::letterFrame &&
|
2012-08-02 04:38:49 -07:00
|
|
|
parent->IsFloating()) {
|
2010-03-17 10:30:30 -07:00
|
|
|
nsFirstLetterFrame* letterFrame = do_QueryFrame(parent);
|
|
|
|
rv = letterFrame->CreateContinuationForFloatingParent(presContext, aFrame,
|
2011-04-11 01:00:28 -07:00
|
|
|
aNewFrame, aIsFluid);
|
2010-03-17 10:30:30 -07:00
|
|
|
return rv;
|
|
|
|
}
|
2009-10-27 19:00:57 -07:00
|
|
|
|
2010-03-17 10:30:30 -07:00
|
|
|
rv = presShell->FrameConstructor()->
|
2011-04-11 01:00:28 -07:00
|
|
|
CreateContinuingFrame(presContext, aFrame, parent, aNewFrame, aIsFluid);
|
2010-03-17 10:30:30 -07:00
|
|
|
if (NS_FAILED(rv)) {
|
2009-10-27 19:00:57 -07:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2011-08-24 13:54:30 -07:00
|
|
|
// The list name kNoReflowPrincipalList would indicate we don't want reflow
|
2009-07-30 10:23:32 -07:00
|
|
|
// XXXbz this needs higher-level framelist love
|
2009-09-18 04:09:36 -07:00
|
|
|
nsFrameList temp(*aNewFrame, *aNewFrame);
|
2011-08-24 13:54:30 -07:00
|
|
|
rv = parent->InsertFrames(nsIFrame::kNoReflowPrincipalList, aFrame, temp);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2011-04-11 01:00:28 -07:00
|
|
|
|
|
|
|
if (!aIsFluid) {
|
|
|
|
// Split inline ancestor frames
|
2012-01-11 11:26:02 -08:00
|
|
|
rv = SplitInlineAncestors(parent, aFrame);
|
2011-04-11 01:00:28 -07:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Overview of the implementation of Resolve():
|
|
|
|
*
|
|
|
|
* Walk through the descendants of aBlockFrame and build:
|
2009-02-03 06:42:18 -08:00
|
|
|
* * mLogicalFrames: an nsTArray of nsIFrame* pointers in logical order
|
2011-04-11 01:00:28 -07:00
|
|
|
* * mBuffer: an nsString containing a representation of
|
2007-03-22 10:30:00 -07:00
|
|
|
* the content of the frames.
|
|
|
|
* In the case of text frames, this is the actual text context of the
|
|
|
|
* frames, but some other elements are represented in a symbolic form which
|
|
|
|
* will make the Unicode Bidi Algorithm give the correct results.
|
|
|
|
* Bidi embeddings and overrides set by CSS or <bdo> elements are
|
|
|
|
* represented by the corresponding Unicode control characters.
|
|
|
|
* <br> elements are represented by U+2028 LINE SEPARATOR
|
|
|
|
* Other inline elements are represented by U+FFFC OBJECT REPLACEMENT
|
|
|
|
* CHARACTER
|
|
|
|
*
|
|
|
|
* Then pass mBuffer to the Bidi engine for resolving of embedding levels
|
|
|
|
* by nsBidi::SetPara() and division into directional runs by
|
|
|
|
* nsBidi::CountRuns().
|
|
|
|
*
|
|
|
|
* Finally, walk these runs in logical order using nsBidi::GetLogicalRun() and
|
2009-02-03 06:42:18 -08:00
|
|
|
* correlate them with the frames indexed in mLogicalFrames, setting the
|
2010-05-10 23:14:05 -07:00
|
|
|
* baseLevel and embeddingLevel properties according to the results returned
|
|
|
|
* by the Bidi engine.
|
2007-03-22 10:30:00 -07:00
|
|
|
*
|
|
|
|
* The rendering layer requires each text frame to contain text in only one
|
2010-05-10 23:14:05 -07:00
|
|
|
* direction, so we may need to call EnsureBidiContinuation() to split frames.
|
|
|
|
* We may also need to call RemoveBidiContinuation() to convert frames created
|
|
|
|
* by EnsureBidiContinuation() in previous reflows into fluid continuations.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
|
|
|
nsresult
|
2010-04-25 05:15:17 -07:00
|
|
|
nsBidiPresUtils::Resolve(nsBlockFrame* aBlockFrame)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-04-13 02:23:49 -07:00
|
|
|
BidiParagraphData bpd;
|
|
|
|
bpd.Init(aBlockFrame);
|
2011-04-11 00:59:30 -07:00
|
|
|
|
2012-06-21 03:51:38 -07:00
|
|
|
// Handle bidi-override being set on the block itself before calling
|
2011-04-11 00:59:30 -07:00
|
|
|
// TraverseFrames.
|
2007-03-22 10:30:00 -07:00
|
|
|
const nsStyleTextReset* text = aBlockFrame->GetStyleTextReset();
|
2011-04-11 00:59:30 -07:00
|
|
|
PRUnichar ch = 0;
|
2011-10-18 05:51:57 -07:00
|
|
|
if (text->mUnicodeBidi & NS_STYLE_UNICODE_BIDI_OVERRIDE) {
|
2011-04-13 02:23:49 -07:00
|
|
|
const nsStyleVisibility* vis = aBlockFrame->GetStyleVisibility();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (NS_STYLE_DIRECTION_RTL == vis->mDirection) {
|
2011-04-11 00:59:30 -07:00
|
|
|
ch = kRLO;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else if (NS_STYLE_DIRECTION_LTR == vis->mDirection) {
|
2011-04-11 00:59:30 -07:00
|
|
|
ch = kLRO;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-04-11 00:59:30 -07:00
|
|
|
if (ch != 0) {
|
2011-04-13 02:23:49 -07:00
|
|
|
bpd.PushBidiControl(ch);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2007-12-20 02:06:14 -08:00
|
|
|
for (nsBlockFrame* block = aBlockFrame; block;
|
|
|
|
block = static_cast<nsBlockFrame*>(block->GetNextContinuation())) {
|
|
|
|
block->RemoveStateBits(NS_BLOCK_NEEDS_BIDI_RESOLUTION);
|
2012-03-07 17:57:37 -08:00
|
|
|
nsBlockInFlowLineIterator lineIter(block, block->begin_lines());
|
2012-07-30 07:20:58 -07:00
|
|
|
bpd.mPrevFrame = nullptr;
|
|
|
|
bpd.GetSubParagraph()->mPrevFrame = nullptr;
|
2011-08-24 13:54:30 -07:00
|
|
|
TraverseFrames(aBlockFrame, &lineIter, block->GetFirstPrincipalChild(), &bpd);
|
2012-06-21 03:51:38 -07:00
|
|
|
// XXX what about overflow lines?
|
2007-12-20 02:06:14 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-04-11 00:59:30 -07:00
|
|
|
if (ch != 0) {
|
2011-04-13 02:23:49 -07:00
|
|
|
bpd.PopBidiControl();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-05-08 09:22:38 -07:00
|
|
|
BidiParagraphData* subParagraph = bpd.GetSubParagraph();
|
|
|
|
if (subParagraph->BufferLength()) {
|
|
|
|
ResolveParagraph(aBlockFrame, subParagraph);
|
2012-09-04 00:46:43 -07:00
|
|
|
subParagraph->EmptyBuffer();
|
2012-05-08 09:22:38 -07:00
|
|
|
}
|
2011-04-13 02:23:49 -07:00
|
|
|
return ResolveParagraph(aBlockFrame, &bpd);
|
2011-04-11 00:59:30 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-04-13 02:23:49 -07:00
|
|
|
nsresult
|
|
|
|
nsBidiPresUtils::ResolveParagraph(nsBlockFrame* aBlockFrame,
|
|
|
|
BidiParagraphData* aBpd)
|
2011-04-11 00:59:30 -07:00
|
|
|
{
|
|
|
|
nsPresContext *presContext = aBlockFrame->PresContext();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-04-13 02:23:49 -07:00
|
|
|
if (aBpd->BufferLength() < 1) {
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-04-13 02:23:49 -07:00
|
|
|
aBpd->mBuffer.ReplaceChar("\t\r\n", kSpace);
|
2011-04-11 00:59:30 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t runCount;
|
2011-04-13 02:23:49 -07:00
|
|
|
|
2011-04-13 02:23:49 -07:00
|
|
|
nsresult rv = aBpd->SetPara();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t embeddingLevel = aBpd->GetParaLevel();
|
2011-10-18 05:51:58 -07:00
|
|
|
|
2011-04-13 02:23:49 -07:00
|
|
|
rv = aBpd->CountRuns(&runCount);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t runLength = 0; // the length of the current run of text
|
|
|
|
int32_t lineOffset = 0; // the start of the current run
|
|
|
|
int32_t logicalLimit = 0; // the end of the current run + 1
|
|
|
|
int32_t numRun = -1;
|
|
|
|
int32_t fragmentLength = 0; // the length of the current text frame
|
|
|
|
int32_t frameIndex = -1; // index to the frames in mLogicalFrames
|
|
|
|
int32_t frameCount = aBpd->FrameCount();
|
|
|
|
int32_t contentOffset = 0; // offset of current frame in its content node
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isTextFrame = false;
|
2012-07-30 07:20:58 -07:00
|
|
|
nsIFrame* frame = nullptr;
|
|
|
|
nsIContent* content = nullptr;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t contentTextLength = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-28 18:46:55 -07:00
|
|
|
FramePropertyTable *propTable = presContext->PropertyTable();
|
2012-07-30 07:20:58 -07:00
|
|
|
nsLineBox* currentLine = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-04-11 00:59:29 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
#ifdef NOISY_BIDI
|
2011-10-18 05:51:57 -07:00
|
|
|
printf("Before Resolve(), aBlockFrame=0x%p, mBuffer='%s', frameCount=%d, runCount=%d\n",
|
|
|
|
(void*)aBlockFrame, NS_ConvertUTF16toUTF8(aBpd->mBuffer).get(), frameCount, runCount);
|
2011-04-11 00:59:29 -07:00
|
|
|
#ifdef REALLY_NOISY_BIDI
|
|
|
|
printf(" block frame tree=:\n");
|
|
|
|
aBlockFrame->List(stdout, 0);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
nsIFrame* firstFrame = nullptr;
|
|
|
|
nsIFrame* lastFrame = nullptr;
|
2012-01-11 11:26:02 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
for (; ;) {
|
|
|
|
if (fragmentLength <= 0) {
|
2009-07-01 00:16:26 -07:00
|
|
|
// Get the next frame from mLogicalFrames
|
2007-03-22 10:30:00 -07:00
|
|
|
if (++frameIndex >= frameCount) {
|
|
|
|
break;
|
|
|
|
}
|
2011-04-13 02:23:49 -07:00
|
|
|
frame = aBpd->FrameAt(frameIndex);
|
2011-04-11 00:59:30 -07:00
|
|
|
if (frame == NS_BIDI_CONTROL_FRAME ||
|
|
|
|
nsGkAtoms::textFrame != frame->GetType()) {
|
|
|
|
/*
|
|
|
|
* Any non-text frame corresponds to a single character in the text buffer
|
|
|
|
* (a bidi control character, LINE SEPARATOR, or OBJECT SUBSTITUTE)
|
|
|
|
*/
|
2011-10-17 07:59:28 -07:00
|
|
|
isTextFrame = false;
|
2011-04-11 00:59:30 -07:00
|
|
|
fragmentLength = 1;
|
|
|
|
}
|
|
|
|
else {
|
2012-01-11 11:26:02 -08:00
|
|
|
if (!firstFrame) {
|
|
|
|
firstFrame = frame;
|
|
|
|
}
|
|
|
|
lastFrame = frame;
|
2011-04-13 02:23:49 -07:00
|
|
|
currentLine = aBpd->GetLineForFrameAt(frameIndex);
|
2007-03-22 10:30:00 -07:00
|
|
|
content = frame->GetContent();
|
|
|
|
if (!content) {
|
2011-04-13 02:23:49 -07:00
|
|
|
rv = NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
2009-04-19 01:19:27 -07:00
|
|
|
contentTextLength = content->TextLength();
|
|
|
|
if (contentTextLength == 0) {
|
|
|
|
frame->AdjustOffsetsForBidi(0, 0);
|
2009-04-28 02:23:53 -07:00
|
|
|
// Set the base level and embedding level of the current run even
|
|
|
|
// on an empty frame. Otherwise frame reordering will not be correct.
|
2010-03-28 18:46:55 -07:00
|
|
|
propTable->Set(frame, nsIFrame::EmbeddingLevelProperty(),
|
|
|
|
NS_INT32_TO_PTR(embeddingLevel));
|
|
|
|
propTable->Set(frame, nsIFrame::BaseLevelProperty(),
|
2011-10-18 05:51:58 -07:00
|
|
|
NS_INT32_TO_PTR(aBpd->GetParaLevel()));
|
2012-01-11 11:26:02 -08:00
|
|
|
propTable->Set(frame, nsIFrame::ParagraphDepthProperty(),
|
|
|
|
NS_INT32_TO_PTR(aBpd->mParagraphDepth));
|
2009-04-19 01:19:27 -07:00
|
|
|
continue;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t start, end;
|
2009-04-19 01:19:27 -07:00
|
|
|
frame->GetOffsets(start, end);
|
2010-08-10 00:08:59 -07:00
|
|
|
NS_ASSERTION(!(contentTextLength < end - start),
|
|
|
|
"Frame offsets don't fit in content");
|
2013-01-15 04:22:03 -08:00
|
|
|
fragmentLength = std::min(contentTextLength, end - start);
|
2009-04-19 01:19:27 -07:00
|
|
|
contentOffset = start;
|
2011-10-17 07:59:28 -07:00
|
|
|
isTextFrame = true;
|
2009-07-01 00:16:26 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
} // if (fragmentLength <= 0)
|
2009-07-01 00:16:26 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (runLength <= 0) {
|
2009-07-01 00:16:26 -07:00
|
|
|
// Get the next run of text from the Bidi engine
|
2007-03-22 10:30:00 -07:00
|
|
|
if (++numRun >= runCount) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
lineOffset = logicalLimit;
|
2011-04-13 02:23:49 -07:00
|
|
|
if (NS_FAILED(aBpd->GetLogicalRun(
|
2007-03-22 10:30:00 -07:00
|
|
|
lineOffset, &logicalLimit, &embeddingLevel) ) ) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
runLength = logicalLimit - lineOffset;
|
|
|
|
} // if (runLength <= 0)
|
|
|
|
|
2011-04-11 00:59:30 -07:00
|
|
|
if (frame == NS_BIDI_CONTROL_FRAME) {
|
2012-07-30 07:20:58 -07:00
|
|
|
frame = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
++lineOffset;
|
|
|
|
}
|
|
|
|
else {
|
2010-03-28 18:46:55 -07:00
|
|
|
propTable->Set(frame, nsIFrame::EmbeddingLevelProperty(),
|
|
|
|
NS_INT32_TO_PTR(embeddingLevel));
|
|
|
|
propTable->Set(frame, nsIFrame::BaseLevelProperty(),
|
2011-10-18 05:51:58 -07:00
|
|
|
NS_INT32_TO_PTR(aBpd->GetParaLevel()));
|
2012-01-11 11:26:02 -08:00
|
|
|
propTable->Set(frame, nsIFrame::ParagraphDepthProperty(),
|
|
|
|
NS_INT32_TO_PTR(aBpd->mParagraphDepth));
|
2007-03-22 10:30:00 -07:00
|
|
|
if (isTextFrame) {
|
|
|
|
if ( (runLength > 0) && (runLength < fragmentLength) ) {
|
2009-07-01 00:16:26 -07:00
|
|
|
/*
|
|
|
|
* The text in this frame continues beyond the end of this directional run.
|
|
|
|
* Create a non-fluid continuation frame for the next directional run.
|
|
|
|
*/
|
2011-06-08 23:29:08 -07:00
|
|
|
currentLine->MarkDirty();
|
2009-07-01 00:16:26 -07:00
|
|
|
nsIFrame* nextBidi;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t runEnd = contentOffset + runLength;
|
2011-04-13 02:23:49 -07:00
|
|
|
rv = EnsureBidiContinuation(frame, &nextBidi, frameIndex,
|
|
|
|
contentOffset,
|
|
|
|
runEnd);
|
|
|
|
if (NS_FAILED(rv)) {
|
2008-03-24 00:30:49 -07:00
|
|
|
break;
|
|
|
|
}
|
2010-01-03 00:46:19 -08:00
|
|
|
nextBidi->AdjustOffsetsForBidi(runEnd,
|
|
|
|
contentOffset + fragmentLength);
|
2012-01-11 11:26:02 -08:00
|
|
|
lastFrame = frame = nextBidi;
|
2010-01-03 00:46:19 -08:00
|
|
|
contentOffset = runEnd;
|
2007-03-22 10:30:00 -07:00
|
|
|
} // if (runLength < fragmentLength)
|
|
|
|
else {
|
2009-04-19 01:19:27 -07:00
|
|
|
if (contentOffset + fragmentLength == contentTextLength) {
|
2009-07-01 00:16:26 -07:00
|
|
|
/*
|
|
|
|
* We have finished all the text in this content node. Convert any
|
|
|
|
* further non-fluid continuations to fluid continuations and advance
|
|
|
|
* frameIndex to the last frame in the content node
|
|
|
|
*/
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t newIndex = aBpd->GetLastFrameForContent(content);
|
2009-04-19 01:19:27 -07:00
|
|
|
if (newIndex > frameIndex) {
|
2011-04-13 02:23:49 -07:00
|
|
|
RemoveBidiContinuation(aBpd, frame,
|
|
|
|
frameIndex, newIndex, lineOffset);
|
2009-04-19 01:19:27 -07:00
|
|
|
frameIndex = newIndex;
|
2012-03-21 16:50:37 -07:00
|
|
|
lastFrame = frame = aBpd->FrameAt(frameIndex);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2009-07-01 00:16:26 -07:00
|
|
|
} else if (fragmentLength > 0 && runLength > fragmentLength) {
|
|
|
|
/*
|
|
|
|
* There is more text that belongs to this directional run in the next
|
|
|
|
* text frame: make sure it is a fluid continuation of the current frame.
|
|
|
|
* Do not advance frameIndex, because the next frame may contain
|
|
|
|
* multi-directional text and need to be split
|
|
|
|
*/
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t newIndex = frameIndex;
|
2009-07-01 00:16:26 -07:00
|
|
|
do {
|
2011-04-11 01:00:28 -07:00
|
|
|
} while (++newIndex < frameCount &&
|
2011-04-13 02:23:49 -07:00
|
|
|
aBpd->FrameAt(newIndex) == NS_BIDI_CONTROL_FRAME);
|
2011-04-11 01:00:28 -07:00
|
|
|
if (newIndex < frameCount) {
|
2011-04-13 02:23:49 -07:00
|
|
|
RemoveBidiContinuation(aBpd, frame,
|
|
|
|
frameIndex, newIndex, lineOffset);
|
2011-04-11 01:00:28 -07:00
|
|
|
}
|
2012-12-12 12:55:09 -08:00
|
|
|
} else if (runLength == fragmentLength &&
|
|
|
|
frame->GetNextSibling()) {
|
2009-10-07 21:53:50 -07:00
|
|
|
/*
|
2012-12-12 12:55:09 -08:00
|
|
|
* If the directional run ends at the end of the frame, and this is
|
|
|
|
* not the containing frame's last child, make sure that the next
|
|
|
|
* frame is a non-fluid continuation
|
2009-10-07 21:53:50 -07:00
|
|
|
*/
|
|
|
|
nsIFrame* next = frame->GetNextInFlow();
|
|
|
|
if (next) {
|
|
|
|
frame->SetNextContinuation(next);
|
|
|
|
next->SetPrevContinuation(frame);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2007-11-11 11:34:06 -08:00
|
|
|
frame->AdjustOffsetsForBidi(contentOffset, contentOffset + fragmentLength);
|
2011-06-08 23:29:08 -07:00
|
|
|
currentLine->MarkDirty();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
} // isTextFrame
|
|
|
|
else {
|
|
|
|
++lineOffset;
|
|
|
|
}
|
2011-04-11 00:59:30 -07:00
|
|
|
} // not bidi control frame
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t temp = runLength;
|
2007-03-22 10:30:00 -07:00
|
|
|
runLength -= fragmentLength;
|
|
|
|
fragmentLength -= temp;
|
|
|
|
|
2008-03-21 01:17:41 -07:00
|
|
|
if (frame && fragmentLength <= 0) {
|
2011-04-11 00:59:30 -07:00
|
|
|
// If the frame is at the end of a run, and this is not the end of our
|
|
|
|
// paragrah, split all ancestor inlines that need splitting.
|
2010-06-20 22:33:34 -07:00
|
|
|
// To determine whether we're at the end of the run, we check that we've
|
|
|
|
// finished processing the current run, and that the current frame
|
|
|
|
// doesn't have a fluid continuation (it could have a fluid continuation
|
|
|
|
// of zero length, so testing runLength alone is not sufficient).
|
2011-07-12 00:34:46 -07:00
|
|
|
if (runLength <= 0 && !frame->GetNextInFlow()) {
|
|
|
|
if (numRun + 1 < runCount) {
|
|
|
|
nsIFrame* child = frame;
|
|
|
|
nsIFrame* parent = frame->GetParent();
|
|
|
|
// As long as we're on the last sibling, the parent doesn't have to
|
|
|
|
// be split.
|
|
|
|
// However, if the parent has a fluid continuation, we do have to make
|
|
|
|
// it non-fluid. This can happen e.g. when we have a first-letter
|
|
|
|
// frame and the end of the first-letter coincides with the end of a
|
|
|
|
// directional run.
|
|
|
|
while (parent &&
|
|
|
|
IsBidiSplittable(parent) &&
|
|
|
|
!child->GetNextSibling()) {
|
|
|
|
nsIFrame* next = parent->GetNextInFlow();
|
|
|
|
if (next) {
|
|
|
|
parent->SetNextContinuation(next);
|
|
|
|
next->SetPrevContinuation(parent);
|
|
|
|
}
|
|
|
|
child = parent;
|
|
|
|
parent = child->GetParent();
|
2010-06-13 20:16:55 -07:00
|
|
|
}
|
2012-01-11 11:26:02 -08:00
|
|
|
if (parent && IsBidiSplittable(parent)) {
|
|
|
|
SplitInlineAncestors(parent, child);
|
|
|
|
}
|
2008-03-21 01:17:41 -07:00
|
|
|
}
|
|
|
|
}
|
2011-04-11 01:00:28 -07:00
|
|
|
else {
|
|
|
|
// We're not at an end of a run. If |frame| is the last child of its
|
|
|
|
// parent, and its ancestors happen to have bidi continuations, convert
|
|
|
|
// them into fluid continuations.
|
|
|
|
JoinInlineAncestors(frame);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} // for
|
2011-04-11 00:59:29 -07:00
|
|
|
|
2012-01-11 11:26:02 -08:00
|
|
|
if (aBpd->mParagraphDepth > 1) {
|
|
|
|
nsIFrame* child;
|
|
|
|
nsIFrame* parent;
|
|
|
|
if (firstFrame) {
|
|
|
|
child = firstFrame->GetParent();
|
|
|
|
if (child) {
|
|
|
|
parent = child->GetParent();
|
|
|
|
if (parent && IsBidiSplittable(parent)) {
|
2012-10-25 01:36:37 -07:00
|
|
|
nsIFrame* prev = child->GetPrevSibling();
|
|
|
|
if (prev) {
|
|
|
|
SplitInlineAncestors(parent, prev);
|
|
|
|
}
|
2012-01-11 11:26:02 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (lastFrame) {
|
|
|
|
child = lastFrame->GetParent();
|
|
|
|
if (child) {
|
|
|
|
parent = child->GetParent();
|
|
|
|
if (parent && IsBidiSplittable(parent)) {
|
|
|
|
SplitInlineAncestors(parent, child);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-11 00:59:29 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
#ifdef REALLY_NOISY_BIDI
|
|
|
|
printf("---\nAfter Resolve(), frameTree =:\n");
|
|
|
|
aBlockFrame->List(stdout, 0);
|
|
|
|
printf("===\n");
|
|
|
|
#endif
|
|
|
|
#endif
|
2011-04-13 02:23:49 -07:00
|
|
|
|
|
|
|
return rv;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-08-29 02:19:16 -07:00
|
|
|
void
|
2011-04-11 00:59:30 -07:00
|
|
|
nsBidiPresUtils::TraverseFrames(nsBlockFrame* aBlockFrame,
|
|
|
|
nsBlockInFlowLineIterator* aLineIter,
|
2011-04-13 02:23:49 -07:00
|
|
|
nsIFrame* aCurrentFrame,
|
2011-11-07 06:26:50 -08:00
|
|
|
BidiParagraphData* aBpd)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-12-20 02:06:14 -08:00
|
|
|
if (!aCurrentFrame)
|
|
|
|
return;
|
|
|
|
|
2011-04-11 00:59:30 -07:00
|
|
|
nsIFrame* childFrame = aCurrentFrame;
|
|
|
|
do {
|
|
|
|
/*
|
|
|
|
* It's important to get the next sibling and next continuation *before*
|
|
|
|
* handling the frame: If we encounter a forced paragraph break and call
|
|
|
|
* ResolveParagraph within this loop, doing GetNextSibling and
|
|
|
|
* GetNextContinuation after that could return a bidi continuation that had
|
|
|
|
* just been split from the original childFrame and we would process it
|
|
|
|
* twice.
|
|
|
|
*/
|
|
|
|
nsIFrame* nextSibling = childFrame->GetNextSibling();
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isLastFrame = !childFrame->GetNextContinuation();
|
2011-10-18 05:51:57 -07:00
|
|
|
bool isFirstFrame = !childFrame->GetPrevContinuation();
|
2007-08-29 01:21:38 -07:00
|
|
|
|
2010-09-06 07:33:18 -07:00
|
|
|
// If the real frame for a placeholder is a first letter frame, we need to
|
|
|
|
// drill down into it and include its contents in Bidi resolution.
|
|
|
|
// If not, we just use the placeholder.
|
2007-09-03 07:30:38 -07:00
|
|
|
nsIFrame* frame = childFrame;
|
|
|
|
if (nsGkAtoms::placeholderFrame == childFrame->GetType()) {
|
|
|
|
nsIFrame* realFrame =
|
|
|
|
nsPlaceholderFrame::GetRealFrameForPlaceholder(childFrame);
|
2010-09-06 07:33:18 -07:00
|
|
|
if (realFrame->GetType() == nsGkAtoms::letterFrame) {
|
2007-09-03 07:30:38 -07:00
|
|
|
frame = realFrame;
|
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-05-06 03:29:58 -07:00
|
|
|
PRUnichar ch = 0;
|
2007-08-29 02:19:16 -07:00
|
|
|
if (frame->IsFrameOfType(nsIFrame::eBidiInlineContainer)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
const nsStyleVisibility* vis = frame->GetStyleVisibility();
|
|
|
|
const nsStyleTextReset* text = frame->GetStyleTextReset();
|
2011-10-18 05:51:57 -07:00
|
|
|
if (text->mUnicodeBidi & NS_STYLE_UNICODE_BIDI_OVERRIDE) {
|
|
|
|
if (NS_STYLE_DIRECTION_RTL == vis->mDirection) {
|
|
|
|
ch = kRLO;
|
|
|
|
}
|
|
|
|
else if (NS_STYLE_DIRECTION_LTR == vis->mDirection) {
|
|
|
|
ch = kLRO;
|
|
|
|
}
|
|
|
|
} else if (text->mUnicodeBidi & NS_STYLE_UNICODE_BIDI_EMBED) {
|
|
|
|
if (NS_STYLE_DIRECTION_RTL == vis->mDirection) {
|
|
|
|
ch = kRLE;
|
|
|
|
}
|
|
|
|
else if (NS_STYLE_DIRECTION_LTR == vis->mDirection) {
|
|
|
|
ch = kLRE;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-04-11 00:59:30 -07:00
|
|
|
// Add a dummy frame pointer representing a bidi control code before the
|
|
|
|
// first frame of an element specifying embedding or override
|
2011-10-18 05:51:57 -07:00
|
|
|
if (ch != 0 && isFirstFrame) {
|
2011-04-13 02:23:49 -07:00
|
|
|
aBpd->PushBidiControl(ch);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IsBidiLeaf(frame)) {
|
|
|
|
/* Bidi leaf frame: add the frame to the mLogicalFrames array,
|
|
|
|
* and add its index to the mContentToFrameIndex hashtable. This
|
|
|
|
* will be used in RemoveBidiContinuation() to identify the last
|
|
|
|
* frame in the array with a given content.
|
|
|
|
*/
|
|
|
|
nsIContent* content = frame->GetContent();
|
2011-04-13 02:23:49 -07:00
|
|
|
aBpd->AppendFrame(frame, aLineIter, content);
|
2011-06-08 23:29:08 -07:00
|
|
|
|
2011-04-11 00:59:30 -07:00
|
|
|
// Append the content of the frame to the paragraph buffer
|
|
|
|
nsIAtom* frameType = frame->GetType();
|
|
|
|
if (nsGkAtoms::textFrame == frameType) {
|
2011-04-13 02:23:49 -07:00
|
|
|
if (content != aBpd->mPrevContent) {
|
|
|
|
aBpd->mPrevContent = content;
|
2011-04-11 01:00:28 -07:00
|
|
|
if (!frame->GetStyleContext()->GetStyleText()->NewlineIsSignificant()) {
|
2011-04-13 02:23:49 -07:00
|
|
|
content->AppendTextTo(aBpd->mBuffer);
|
2011-04-11 01:00:28 -07:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* For preformatted text we have to do bidi resolution on each line
|
|
|
|
* separately.
|
|
|
|
*/
|
|
|
|
nsAutoString text;
|
|
|
|
content->AppendTextTo(text);
|
|
|
|
nsIFrame* next;
|
|
|
|
do {
|
2012-07-30 07:20:58 -07:00
|
|
|
next = nullptr;
|
2011-04-11 01:00:28 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t start, end;
|
2011-04-11 01:00:28 -07:00
|
|
|
frame->GetOffsets(start, end);
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t endLine = text.FindChar('\n', start);
|
2011-04-11 01:00:28 -07:00
|
|
|
if (endLine == -1) {
|
|
|
|
/*
|
2011-06-15 00:45:57 -07:00
|
|
|
* If there is no newline in the text content, just save the
|
|
|
|
* text from this frame and its continuations, and do bidi
|
|
|
|
* resolution later
|
2011-04-11 01:00:28 -07:00
|
|
|
*/
|
2011-04-13 02:23:49 -07:00
|
|
|
aBpd->AppendString(Substring(text, start));
|
2011-06-15 00:45:57 -07:00
|
|
|
while (frame && nextSibling) {
|
2011-04-13 02:23:49 -07:00
|
|
|
aBpd->AdvanceAndAppendFrame(&frame, aLineIter, &nextSibling);
|
2011-06-15 00:45:57 -07:00
|
|
|
}
|
2011-04-11 01:00:28 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If there is a newline in the frame, break the frame after the
|
2011-06-27 09:30:04 -07:00
|
|
|
* newline, do bidi resolution and repeat until the last sibling
|
2011-04-11 01:00:28 -07:00
|
|
|
*/
|
|
|
|
++endLine;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the frame ends before the new line, save the text and move
|
|
|
|
* into the next continuation
|
|
|
|
*/
|
2011-04-13 02:23:49 -07:00
|
|
|
aBpd->AppendString(Substring(text, start,
|
2013-01-15 04:22:03 -08:00
|
|
|
std::min(end, endLine) - start));
|
2011-06-15 00:51:36 -07:00
|
|
|
while (end < endLine && nextSibling) {
|
2011-04-13 02:23:49 -07:00
|
|
|
aBpd->AdvanceAndAppendFrame(&frame, aLineIter, &nextSibling);
|
2011-04-11 01:00:28 -07:00
|
|
|
NS_ASSERTION(frame, "Premature end of continuation chain");
|
|
|
|
frame->GetOffsets(start, end);
|
2011-04-13 02:23:49 -07:00
|
|
|
aBpd->AppendString(Substring(text, start,
|
2013-01-15 04:22:03 -08:00
|
|
|
std::min(end, endLine) - start));
|
2011-04-11 01:00:28 -07:00
|
|
|
}
|
|
|
|
|
2011-07-12 00:34:52 -07:00
|
|
|
if (end < endLine) {
|
2012-07-30 07:20:58 -07:00
|
|
|
aBpd->mPrevContent = nullptr;
|
2011-07-12 00:34:52 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool createdContinuation = false;
|
2012-08-22 08:56:38 -07:00
|
|
|
if (uint32_t(endLine) < text.Length()) {
|
2011-04-11 01:00:28 -07:00
|
|
|
/*
|
|
|
|
* Timing is everything here: if the frame already has a bidi
|
|
|
|
* continuation, we need to make the continuation fluid *before*
|
|
|
|
* resetting the length of the current frame. Otherwise
|
|
|
|
* nsTextFrame::SetLength won't set the continuation frame's
|
|
|
|
* text offsets correctly.
|
|
|
|
*
|
|
|
|
* On the other hand, if the frame doesn't have a continuation,
|
|
|
|
* we need to create one *after* resetting the length, or
|
|
|
|
* CreateContinuingFrame will complain that there is no more
|
|
|
|
* content for the continuation.
|
|
|
|
*/
|
|
|
|
next = frame->GetNextInFlow();
|
|
|
|
if (!next) {
|
|
|
|
// If the frame already has a bidi continuation, make it fluid
|
|
|
|
next = frame->GetNextContinuation();
|
|
|
|
if (next) {
|
|
|
|
MakeContinuationFluid(frame, next);
|
|
|
|
JoinInlineAncestors(frame);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsTextFrame* textFrame = static_cast<nsTextFrame*>(frame);
|
2012-07-30 07:20:58 -07:00
|
|
|
textFrame->SetLength(endLine - start, nullptr);
|
2011-04-11 01:00:28 -07:00
|
|
|
|
|
|
|
if (!next) {
|
|
|
|
// If the frame has no next in flow, create one.
|
2011-10-17 07:59:28 -07:00
|
|
|
CreateContinuation(frame, &next, true);
|
|
|
|
createdContinuation = true;
|
2011-04-11 01:00:28 -07:00
|
|
|
}
|
|
|
|
}
|
2011-04-13 02:23:49 -07:00
|
|
|
ResolveParagraphWithinBlock(aBlockFrame, aBpd);
|
2011-04-11 01:00:28 -07:00
|
|
|
|
|
|
|
if (!nextSibling && !createdContinuation) {
|
|
|
|
break;
|
|
|
|
} else if (next) {
|
|
|
|
frame = next;
|
2011-04-13 02:23:49 -07:00
|
|
|
aBpd->AppendFrame(frame, aLineIter);
|
2011-04-11 01:00:28 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we have already overshot the saved next-sibling while
|
|
|
|
* scanning the frame's continuations, advance it.
|
|
|
|
*/
|
|
|
|
if (frame && frame == nextSibling) {
|
|
|
|
nextSibling = frame->GetNextSibling();
|
|
|
|
}
|
|
|
|
|
|
|
|
} while (next);
|
|
|
|
}
|
2011-04-11 00:59:30 -07:00
|
|
|
}
|
|
|
|
} else if (nsGkAtoms::brFrame == frameType) {
|
|
|
|
// break frame -- append line separator
|
2011-04-13 02:23:49 -07:00
|
|
|
aBpd->AppendUnichar(kLineSeparator);
|
|
|
|
ResolveParagraphWithinBlock(aBlockFrame, aBpd);
|
2011-04-11 00:59:30 -07:00
|
|
|
} else {
|
|
|
|
// other frame type -- see the Unicode Bidi Algorithm:
|
|
|
|
// "...inline objects (such as graphics) are treated as if they are ...
|
|
|
|
// U+FFFC"
|
2012-02-25 23:12:55 -08:00
|
|
|
// <wbr>, however, is treated as U+200B ZERO WIDTH SPACE. See
|
|
|
|
// http://dev.w3.org/html5/spec/Overview.html#phrasing-content-1
|
|
|
|
aBpd->AppendUnichar(content->IsHTML(nsGkAtoms::wbr) ?
|
|
|
|
kZWSP : kObjectSubstitute);
|
2012-08-02 04:38:51 -07:00
|
|
|
if (!frame->IsInlineOutside()) {
|
2011-04-11 00:59:30 -07:00
|
|
|
// if it is not inline, end the paragraph
|
2011-04-13 02:23:49 -07:00
|
|
|
ResolveParagraphWithinBlock(aBlockFrame, aBpd);
|
2011-04-11 00:59:30 -07:00
|
|
|
}
|
2011-04-11 00:59:30 -07:00
|
|
|
}
|
2012-06-21 03:51:38 -07:00
|
|
|
} else {
|
2011-04-11 00:59:30 -07:00
|
|
|
// For a non-leaf frame, recurse into TraverseFrames
|
2011-08-24 13:54:30 -07:00
|
|
|
nsIFrame* kid = frame->GetFirstPrincipalChild();
|
2012-06-21 03:51:38 -07:00
|
|
|
nsIFrame* overflowKid = frame->GetFirstChild(nsIFrame::kOverflowList);
|
|
|
|
if (kid || overflowKid) {
|
2011-10-18 05:51:57 -07:00
|
|
|
const nsStyleTextReset* text = frame->GetStyleTextReset();
|
2012-05-09 01:44:52 -07:00
|
|
|
if (text->mUnicodeBidi & NS_STYLE_UNICODE_BIDI_ISOLATE ||
|
|
|
|
text->mUnicodeBidi & NS_STYLE_UNICODE_BIDI_PLAINTEXT) {
|
2011-10-18 05:51:57 -07:00
|
|
|
// css "unicode-bidi: isolate" and html5 bdi:
|
|
|
|
// resolve the element as a separate paragraph
|
2011-11-07 06:26:50 -08:00
|
|
|
BidiParagraphData* subParagraph = aBpd->GetSubParagraph();
|
2011-11-24 06:16:42 -08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* As at the beginning of the loop, it's important to check for
|
|
|
|
* next-continuations before handling the frame. If we do
|
|
|
|
* TraverseFrames and *then* do GetNextContinuation on the original
|
|
|
|
* first frame, it could return a bidi continuation that had only
|
|
|
|
* just been created, and we would skip doing bidi resolution on the
|
|
|
|
* last part of the sub-paragraph.
|
|
|
|
*/
|
|
|
|
bool isLastContinuation = !frame->GetNextContinuation();
|
2011-12-07 02:07:42 -08:00
|
|
|
if (!frame->GetPrevContinuation() || !subParagraph->mReset) {
|
2012-05-08 09:22:38 -07:00
|
|
|
if (subParagraph->BufferLength()) {
|
|
|
|
ResolveParagraph(aBlockFrame, subParagraph);
|
|
|
|
}
|
2012-01-11 11:26:02 -08:00
|
|
|
subParagraph->Reset(frame, aBpd);
|
2011-11-07 06:26:50 -08:00
|
|
|
}
|
|
|
|
TraverseFrames(aBlockFrame, aLineIter, kid, subParagraph);
|
2012-06-21 03:51:38 -07:00
|
|
|
TraverseFrames(aBlockFrame, aLineIter, overflowKid, subParagraph);
|
2011-11-24 06:16:42 -08:00
|
|
|
if (isLastContinuation) {
|
2011-11-07 06:26:50 -08:00
|
|
|
ResolveParagraph(aBlockFrame, subParagraph);
|
2012-05-08 09:22:38 -07:00
|
|
|
subParagraph->EmptyBuffer();
|
2011-11-07 06:26:50 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Treat the element as a neutral character within its containing
|
|
|
|
// paragraph.
|
|
|
|
aBpd->AppendControlChar(kObjectSubstitute);
|
2011-10-18 05:51:57 -07:00
|
|
|
} else {
|
|
|
|
TraverseFrames(aBlockFrame, aLineIter, kid, aBpd);
|
2012-06-21 03:51:38 -07:00
|
|
|
TraverseFrames(aBlockFrame, aLineIter, overflowKid, aBpd);
|
2011-10-18 05:51:57 -07:00
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// If the element is attributed by dir, indicate direction pop (add PDF frame)
|
2011-10-18 05:51:57 -07:00
|
|
|
if (isLastFrame) {
|
|
|
|
if (ch) {
|
|
|
|
// Add a dummy frame pointer representing a bidi control code after the
|
|
|
|
// last frame of an element specifying embedding or override
|
|
|
|
aBpd->PopBidiControl();
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-04-11 00:59:30 -07:00
|
|
|
childFrame = nextSibling;
|
|
|
|
} while (childFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-04-13 02:23:49 -07:00
|
|
|
nsBidiPresUtils::ResolveParagraphWithinBlock(nsBlockFrame* aBlockFrame,
|
|
|
|
BidiParagraphData* aBpd)
|
2011-04-11 00:59:30 -07:00
|
|
|
{
|
2011-04-13 02:23:49 -07:00
|
|
|
aBpd->ClearBidiControls();
|
|
|
|
ResolveParagraph(aBlockFrame, aBpd);
|
|
|
|
aBpd->ResetData();
|
2011-03-24 02:28:44 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
void
|
2007-08-29 02:19:16 -07:00
|
|
|
nsBidiPresUtils::ReorderFrames(nsIFrame* aFirstFrameOnLine,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aNumFramesOnLine)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// If this line consists of a line frame, reorder the line frame's children.
|
|
|
|
if (aFirstFrameOnLine->GetType() == nsGkAtoms::lineFrame) {
|
2011-08-24 13:54:30 -07:00
|
|
|
aFirstFrameOnLine = aFirstFrameOnLine->GetFirstPrincipalChild();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!aFirstFrameOnLine)
|
|
|
|
return;
|
|
|
|
// All children of the line frame are on the first line. Setting aNumFramesOnLine
|
|
|
|
// to -1 makes InitLogicalArrayFromLine look at all of them.
|
|
|
|
aNumFramesOnLine = -1;
|
|
|
|
}
|
2011-04-27 01:47:18 -07:00
|
|
|
|
2011-04-13 02:23:49 -07:00
|
|
|
BidiLineData bld(aFirstFrameOnLine, aNumFramesOnLine);
|
|
|
|
RepositionInlineFrames(&bld, aFirstFrameOnLine);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-01-11 11:26:02 -08:00
|
|
|
nsIFrame*
|
|
|
|
nsBidiPresUtils::GetFirstLeaf(nsIFrame* aFrame)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsIFrame* firstLeaf = aFrame;
|
|
|
|
while (!IsBidiLeaf(firstLeaf)) {
|
2011-08-24 13:54:30 -07:00
|
|
|
nsIFrame* firstChild = firstLeaf->GetFirstPrincipalChild();
|
2010-09-06 07:33:18 -07:00
|
|
|
nsIFrame* realFrame = nsPlaceholderFrame::GetRealFrameFor(firstChild);
|
|
|
|
firstLeaf = (realFrame->GetType() == nsGkAtoms::letterFrame) ?
|
|
|
|
realFrame : firstChild;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2012-01-11 11:26:02 -08:00
|
|
|
return firstLeaf;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsBidiLevel
|
|
|
|
nsBidiPresUtils::GetFrameEmbeddingLevel(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
return NS_GET_EMBEDDING_LEVEL(nsBidiPresUtils::GetFirstLeaf(aFrame));
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t
|
2012-01-11 11:26:02 -08:00
|
|
|
nsBidiPresUtils::GetParagraphDepth(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
return NS_GET_PARAGRAPH_DEPTH(nsBidiPresUtils::GetFirstLeaf(aFrame));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-01-11 11:26:02 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsBidiLevel
|
|
|
|
nsBidiPresUtils::GetFrameBaseLevel(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
nsIFrame* firstLeaf = aFrame;
|
|
|
|
while (!IsBidiLeaf(firstLeaf)) {
|
2011-08-24 13:54:30 -07:00
|
|
|
firstLeaf = firstLeaf->GetFirstPrincipalChild();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
return NS_GET_BASE_LEVEL(firstLeaf);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsBidiPresUtils::IsLeftOrRightMost(nsIFrame* aFrame,
|
|
|
|
nsContinuationStates* aContinuationStates,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool& aIsLeftMost /* out */,
|
|
|
|
bool& aIsRightMost /* out */)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
const nsStyleVisibility* vis = aFrame->GetStyleVisibility();
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isLTR = (NS_STYLE_DIRECTION_LTR == vis->mDirection);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Since we lay out frames from left to right (in both LTR and RTL), visiting a
|
2012-07-30 07:20:58 -07:00
|
|
|
* frame with 'mFirstVisualFrame == nullptr', means it's the first appearance of
|
2007-03-22 10:30:00 -07:00
|
|
|
* one of its continuation chain frames on the line.
|
|
|
|
* To determine if it's the last visual frame of its continuation chain on the line
|
|
|
|
* or not, we count the number of frames of the chain on the line, and then reduce
|
|
|
|
* it when we lay out a frame of the chain. If this value becomes 1 it means
|
|
|
|
* that it's the last visual frame of its continuation chain on this line.
|
|
|
|
*/
|
|
|
|
|
|
|
|
nsFrameContinuationState* frameState = aContinuationStates->GetEntry(aFrame);
|
|
|
|
nsFrameContinuationState* firstFrameState;
|
|
|
|
|
|
|
|
if (!frameState->mFirstVisualFrame) {
|
|
|
|
// aFrame is the first visual frame of its continuation chain
|
|
|
|
nsFrameContinuationState* contState;
|
|
|
|
nsIFrame* frame;
|
|
|
|
|
|
|
|
frameState->mFrameCount = 1;
|
|
|
|
frameState->mFirstVisualFrame = aFrame;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Traverse continuation chain of aFrame in both backward and forward
|
|
|
|
* directions while the frames are on this line. Count the frames and
|
|
|
|
* set their mFirstVisualFrame to aFrame.
|
|
|
|
*/
|
|
|
|
// Traverse continuation chain backward
|
|
|
|
for (frame = aFrame->GetPrevContinuation();
|
|
|
|
frame && (contState = aContinuationStates->GetEntry(frame));
|
|
|
|
frame = frame->GetPrevContinuation()) {
|
|
|
|
frameState->mFrameCount++;
|
|
|
|
contState->mFirstVisualFrame = aFrame;
|
|
|
|
}
|
2012-07-30 07:20:58 -07:00
|
|
|
frameState->mHasContOnPrevLines = (frame != nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Traverse continuation chain forward
|
|
|
|
for (frame = aFrame->GetNextContinuation();
|
|
|
|
frame && (contState = aContinuationStates->GetEntry(frame));
|
|
|
|
frame = frame->GetNextContinuation()) {
|
|
|
|
frameState->mFrameCount++;
|
|
|
|
contState->mFirstVisualFrame = aFrame;
|
|
|
|
}
|
2012-07-30 07:20:58 -07:00
|
|
|
frameState->mHasContOnNextLines = (frame != nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
aIsLeftMost = isLTR ? !frameState->mHasContOnPrevLines
|
|
|
|
: !frameState->mHasContOnNextLines;
|
|
|
|
firstFrameState = frameState;
|
|
|
|
} else {
|
|
|
|
// aFrame is not the first visual frame of its continuation chain
|
2011-10-17 07:59:28 -07:00
|
|
|
aIsLeftMost = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
firstFrameState = aContinuationStates->GetEntry(frameState->mFirstVisualFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
aIsRightMost = (firstFrameState->mFrameCount == 1) &&
|
|
|
|
(isLTR ? !firstFrameState->mHasContOnNextLines
|
|
|
|
: !firstFrameState->mHasContOnPrevLines);
|
|
|
|
|
2009-05-11 19:04:58 -07:00
|
|
|
if ((aIsLeftMost || aIsRightMost) &&
|
|
|
|
(aFrame->GetStateBits() & NS_FRAME_IS_SPECIAL)) {
|
2009-09-18 11:00:21 -07:00
|
|
|
// For ib splits, don't treat anything except the last part as
|
|
|
|
// endmost or anything except the first part as startmost.
|
|
|
|
// As an optimization, only get the first continuation once.
|
|
|
|
nsIFrame* firstContinuation = aFrame->GetFirstContinuation();
|
|
|
|
if (nsLayoutUtils::FrameIsNonLastInIBSplit(firstContinuation)) {
|
2009-05-11 19:04:58 -07:00
|
|
|
// We are not endmost
|
|
|
|
if (isLTR) {
|
2011-10-17 07:59:28 -07:00
|
|
|
aIsRightMost = false;
|
2009-05-11 19:04:58 -07:00
|
|
|
} else {
|
2011-10-17 07:59:28 -07:00
|
|
|
aIsLeftMost = false;
|
2009-05-11 19:04:58 -07:00
|
|
|
}
|
2009-09-18 11:00:21 -07:00
|
|
|
}
|
|
|
|
if (nsLayoutUtils::FrameIsNonFirstInIBSplit(firstContinuation)) {
|
2009-05-11 19:04:58 -07:00
|
|
|
// We are not startmost
|
|
|
|
if (isLTR) {
|
2011-10-17 07:59:28 -07:00
|
|
|
aIsLeftMost = false;
|
2009-05-11 19:04:58 -07:00
|
|
|
} else {
|
2011-10-17 07:59:28 -07:00
|
|
|
aIsRightMost = false;
|
2009-05-11 19:04:58 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Reduce number of remaining frames of the continuation chain on the line.
|
|
|
|
firstFrameState->mFrameCount--;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsBidiPresUtils::RepositionFrame(nsIFrame* aFrame,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aIsOddLevel,
|
2007-03-22 10:30:00 -07:00
|
|
|
nscoord& aLeft,
|
2011-04-13 02:23:49 -07:00
|
|
|
nsContinuationStates* aContinuationStates)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (!aFrame)
|
|
|
|
return;
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isLeftMost, isRightMost;
|
2007-03-22 10:30:00 -07:00
|
|
|
IsLeftOrRightMost(aFrame,
|
|
|
|
aContinuationStates,
|
|
|
|
isLeftMost /* out */,
|
|
|
|
isRightMost /* out */);
|
|
|
|
|
2009-01-12 11:20:59 -08:00
|
|
|
nsInlineFrame* testFrame = do_QueryFrame(aFrame);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (testFrame) {
|
|
|
|
aFrame->AddStateBits(NS_INLINE_FRAME_BIDI_VISUAL_STATE_IS_SET);
|
|
|
|
|
|
|
|
if (isLeftMost)
|
|
|
|
aFrame->AddStateBits(NS_INLINE_FRAME_BIDI_VISUAL_IS_LEFT_MOST);
|
|
|
|
else
|
|
|
|
aFrame->RemoveStateBits(NS_INLINE_FRAME_BIDI_VISUAL_IS_LEFT_MOST);
|
|
|
|
|
|
|
|
if (isRightMost)
|
|
|
|
aFrame->AddStateBits(NS_INLINE_FRAME_BIDI_VISUAL_IS_RIGHT_MOST);
|
|
|
|
else
|
|
|
|
aFrame->RemoveStateBits(NS_INLINE_FRAME_BIDI_VISUAL_IS_RIGHT_MOST);
|
|
|
|
}
|
2008-01-26 22:54:08 -08:00
|
|
|
// This method is called from nsBlockFrame::PlaceLine via the call to
|
|
|
|
// bidiUtils->ReorderFrames, so this is guaranteed to be after the inlines
|
|
|
|
// have been reflowed, which is required for GetUsedMargin/Border/Padding
|
|
|
|
nsMargin margin = aFrame->GetUsedMargin();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (isLeftMost)
|
|
|
|
aLeft += margin.left;
|
|
|
|
|
|
|
|
nscoord start = aLeft;
|
|
|
|
|
|
|
|
if (!IsBidiLeaf(aFrame))
|
|
|
|
{
|
|
|
|
nscoord x = 0;
|
2008-01-26 22:54:08 -08:00
|
|
|
nsMargin borderPadding = aFrame->GetUsedBorderAndPadding();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (isLeftMost) {
|
|
|
|
x += borderPadding.left;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If aIsOddLevel is true, so we need to traverse the child list
|
|
|
|
// in reverse order, to make it O(n) we store the list locally and
|
|
|
|
// iterate the list reversely
|
2009-02-03 06:42:18 -08:00
|
|
|
nsTArray<nsIFrame*> childList;
|
2011-08-24 13:54:30 -07:00
|
|
|
nsIFrame *frame = aFrame->GetFirstPrincipalChild();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (frame && aIsOddLevel) {
|
2012-07-30 07:20:58 -07:00
|
|
|
childList.AppendElement((nsIFrame*)nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
while (frame) {
|
|
|
|
childList.AppendElement(frame);
|
|
|
|
frame = frame->GetNextSibling();
|
|
|
|
}
|
2009-02-03 06:42:18 -08:00
|
|
|
frame = childList[childList.Length() - 1];
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Reposition the child frames
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t index = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
while (frame) {
|
|
|
|
RepositionFrame(frame,
|
|
|
|
aIsOddLevel,
|
|
|
|
x,
|
|
|
|
aContinuationStates);
|
|
|
|
index++;
|
|
|
|
frame = aIsOddLevel ?
|
2009-02-03 06:42:18 -08:00
|
|
|
childList[childList.Length() - index - 1] :
|
2007-03-22 10:30:00 -07:00
|
|
|
frame->GetNextSibling();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isRightMost) {
|
|
|
|
x += borderPadding.right;
|
|
|
|
}
|
|
|
|
aLeft += x;
|
|
|
|
} else {
|
|
|
|
aLeft += aFrame->GetSize().width;
|
|
|
|
}
|
|
|
|
nsRect rect = aFrame->GetRect();
|
|
|
|
aFrame->SetRect(nsRect(start, rect.y, aLeft - start, rect.height));
|
|
|
|
|
|
|
|
if (isRightMost)
|
|
|
|
aLeft += margin.right;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsBidiPresUtils::InitContinuationStates(nsIFrame* aFrame,
|
2011-04-13 02:23:49 -07:00
|
|
|
nsContinuationStates* aContinuationStates)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsFrameContinuationState* state = aContinuationStates->PutEntry(aFrame);
|
2012-07-30 07:20:58 -07:00
|
|
|
state->mFirstVisualFrame = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
state->mFrameCount = 0;
|
|
|
|
|
|
|
|
if (!IsBidiLeaf(aFrame)) {
|
|
|
|
// Continue for child frames
|
|
|
|
nsIFrame* frame;
|
2011-08-24 13:54:30 -07:00
|
|
|
for (frame = aFrame->GetFirstPrincipalChild();
|
2007-03-22 10:30:00 -07:00
|
|
|
frame;
|
|
|
|
frame = frame->GetNextSibling()) {
|
|
|
|
InitContinuationStates(frame,
|
|
|
|
aContinuationStates);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-04-13 02:23:49 -07:00
|
|
|
nsBidiPresUtils::RepositionInlineFrames(BidiLineData *aBld,
|
|
|
|
nsIFrame* aFirstChild)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
const nsStyleVisibility* vis = aFirstChild->GetStyleVisibility();
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isLTR = (NS_STYLE_DIRECTION_LTR == vis->mDirection);
|
2007-03-22 10:30:00 -07:00
|
|
|
nscoord leftSpace = 0;
|
|
|
|
|
2008-01-26 22:54:08 -08:00
|
|
|
// This method is called from nsBlockFrame::PlaceLine via the call to
|
|
|
|
// bidiUtils->ReorderFrames, so this is guaranteed to be after the inlines
|
|
|
|
// have been reflowed, which is required for GetUsedMargin/Border/Padding
|
|
|
|
nsMargin margin = aFirstChild->GetUsedMargin();
|
2009-05-11 19:04:58 -07:00
|
|
|
if (!aFirstChild->GetPrevContinuation() &&
|
2009-09-18 11:00:21 -07:00
|
|
|
!nsLayoutUtils::FrameIsNonFirstInIBSplit(aFirstChild))
|
2007-03-22 10:30:00 -07:00
|
|
|
leftSpace = isLTR ? margin.left : margin.right;
|
|
|
|
|
|
|
|
nscoord left = aFirstChild->GetPosition().x - leftSpace;
|
|
|
|
nsIFrame* frame;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t count = aBld->mVisualFrames.Length();
|
|
|
|
int32_t index;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsContinuationStates continuationStates;
|
|
|
|
|
|
|
|
continuationStates.Init();
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
// Initialize continuation states to (nullptr, 0) for
|
2007-03-22 10:30:00 -07:00
|
|
|
// each frame on the line.
|
|
|
|
for (index = 0; index < count; index++) {
|
2011-04-13 02:23:49 -07:00
|
|
|
InitContinuationStates(aBld->VisualFrameAt(index), &continuationStates);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Reposition frames in visual order
|
|
|
|
for (index = 0; index < count; index++) {
|
2011-04-13 02:23:49 -07:00
|
|
|
frame = aBld->VisualFrameAt(index);
|
2007-03-22 10:30:00 -07:00
|
|
|
RepositionFrame(frame,
|
2011-04-13 02:23:49 -07:00
|
|
|
(aBld->mLevels[aBld->mIndexMap[index]] & 1),
|
2007-03-22 10:30:00 -07:00
|
|
|
left,
|
|
|
|
&continuationStates);
|
|
|
|
} // for
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsBidiPresUtils::CheckLineOrder(nsIFrame* aFirstFrameOnLine,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aNumFramesOnLine,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIFrame** aFirstVisual,
|
|
|
|
nsIFrame** aLastVisual)
|
|
|
|
{
|
2011-04-13 02:23:49 -07:00
|
|
|
BidiLineData bld(aFirstFrameOnLine, aNumFramesOnLine);
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t count = bld.FrameCount();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (aFirstVisual) {
|
2011-04-13 02:23:49 -07:00
|
|
|
*aFirstVisual = bld.VisualFrameAt(0);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
if (aLastVisual) {
|
2011-04-13 02:23:49 -07:00
|
|
|
*aLastVisual = bld.VisualFrameAt(count-1);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-04-13 02:23:49 -07:00
|
|
|
return bld.mIsReordered;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame*
|
|
|
|
nsBidiPresUtils::GetFrameToRightOf(const nsIFrame* aFrame,
|
|
|
|
nsIFrame* aFirstFrameOnLine,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aNumFramesOnLine)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-04-13 02:23:49 -07:00
|
|
|
BidiLineData bld(aFirstFrameOnLine, aNumFramesOnLine);
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t count = bld.mVisualFrames.Length();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
if (aFrame == nullptr && count)
|
2011-04-13 02:23:49 -07:00
|
|
|
return bld.VisualFrameAt(0);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
for (int32_t i = 0; i < count - 1; i++) {
|
2011-04-13 02:23:49 -07:00
|
|
|
if (bld.VisualFrameAt(i) == aFrame) {
|
|
|
|
return bld.VisualFrameAt(i+1);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame*
|
|
|
|
nsBidiPresUtils::GetFrameToLeftOf(const nsIFrame* aFrame,
|
|
|
|
nsIFrame* aFirstFrameOnLine,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aNumFramesOnLine)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-04-13 02:23:49 -07:00
|
|
|
BidiLineData bld(aFirstFrameOnLine, aNumFramesOnLine);
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t count = bld.mVisualFrames.Length();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
if (aFrame == nullptr && count)
|
2011-04-13 02:23:49 -07:00
|
|
|
return bld.VisualFrameAt(count-1);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
for (int32_t i = 1; i < count; i++) {
|
2011-04-13 02:23:49 -07:00
|
|
|
if (bld.VisualFrameAt(i) == aFrame) {
|
|
|
|
return bld.VisualFrameAt(i-1);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-04-13 02:23:49 -07:00
|
|
|
inline nsresult
|
2007-08-29 02:19:16 -07:00
|
|
|
nsBidiPresUtils::EnsureBidiContinuation(nsIFrame* aFrame,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIFrame** aNewFrame,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t& aFrameIndex,
|
|
|
|
int32_t aStart,
|
|
|
|
int32_t aEnd)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aNewFrame, "null OUT ptr");
|
|
|
|
NS_PRECONDITION(aFrame, "aFrame is null");
|
|
|
|
|
2008-01-29 20:13:06 -08:00
|
|
|
aFrame->AdjustOffsetsForBidi(aStart, aEnd);
|
2011-10-17 07:59:28 -07:00
|
|
|
return CreateContinuation(aFrame, aNewFrame, false);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-04-13 02:23:49 -07:00
|
|
|
nsBidiPresUtils::RemoveBidiContinuation(BidiParagraphData *aBpd,
|
|
|
|
nsIFrame* aFrame,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aFirstIndex,
|
|
|
|
int32_t aLastIndex,
|
|
|
|
int32_t& aOffset)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-03-28 18:46:55 -07:00
|
|
|
FrameProperties props = aFrame->Properties();
|
|
|
|
nsBidiLevel embeddingLevel =
|
2010-05-10 23:14:05 -07:00
|
|
|
(nsBidiLevel)NS_PTR_TO_INT32(props.Get(nsIFrame::EmbeddingLevelProperty()));
|
2010-03-28 18:46:55 -07:00
|
|
|
nsBidiLevel baseLevel =
|
2010-05-10 23:14:05 -07:00
|
|
|
(nsBidiLevel)NS_PTR_TO_INT32(props.Get(nsIFrame::BaseLevelProperty()));
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t paragraphDepth =
|
2012-01-11 11:26:02 -08:00
|
|
|
NS_PTR_TO_INT32(props.Get(nsIFrame::ParagraphDepthProperty()));
|
2010-03-28 18:46:55 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
for (int32_t index = aFirstIndex + 1; index <= aLastIndex; index++) {
|
2011-04-13 02:23:49 -07:00
|
|
|
nsIFrame* frame = aBpd->FrameAt(index);
|
2011-04-11 00:59:30 -07:00
|
|
|
if (frame == NS_BIDI_CONTROL_FRAME) {
|
2007-03-22 10:30:00 -07:00
|
|
|
++aOffset;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Make the frame and its continuation ancestors fluid,
|
|
|
|
// so they can be reused or deleted by normal reflow code
|
2010-03-28 18:46:55 -07:00
|
|
|
FrameProperties frameProps = frame->Properties();
|
|
|
|
frameProps.Set(nsIFrame::EmbeddingLevelProperty(),
|
|
|
|
NS_INT32_TO_PTR(embeddingLevel));
|
|
|
|
frameProps.Set(nsIFrame::BaseLevelProperty(),
|
|
|
|
NS_INT32_TO_PTR(baseLevel));
|
2012-01-11 11:26:02 -08:00
|
|
|
frameProps.Set(nsIFrame::ParagraphDepthProperty(),
|
|
|
|
NS_INT32_TO_PTR(paragraphDepth));
|
2007-03-22 10:30:00 -07:00
|
|
|
frame->AddStateBits(NS_FRAME_IS_BIDI);
|
|
|
|
while (frame) {
|
|
|
|
nsIFrame* prev = frame->GetPrevContinuation();
|
|
|
|
if (prev) {
|
2011-04-11 01:00:28 -07:00
|
|
|
MakeContinuationFluid(prev, frame);
|
2007-03-22 10:30:00 -07:00
|
|
|
frame = frame->GetParent();
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-03-21 16:50:37 -07:00
|
|
|
|
|
|
|
// Make sure that the last continuation we made fluid does not itself have a
|
|
|
|
// fluid continuation (this can happen when re-resolving after dynamic changes
|
|
|
|
// to content)
|
|
|
|
nsIFrame* lastFrame = aBpd->FrameAt(aLastIndex);
|
|
|
|
nsIFrame* next = lastFrame->GetNextInFlow();
|
|
|
|
if (next) {
|
|
|
|
lastFrame->SetNextContinuation(next);
|
|
|
|
next->SetPrevContinuation(lastFrame);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsBidiPresUtils::FormatUnicodeText(nsPresContext* aPresContext,
|
|
|
|
PRUnichar* aText,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t& aTextLength,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCharType aCharType,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aIsOddLevel)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
// ahmed
|
|
|
|
//adjusted for correct numeral shaping
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t bidiOptions = aPresContext->GetBidi();
|
2007-03-22 10:30:00 -07:00
|
|
|
switch (GET_BIDI_OPTION_NUMERAL(bidiOptions)) {
|
|
|
|
|
|
|
|
case IBMBIDI_NUMERAL_HINDI:
|
|
|
|
HandleNumbers(aText,aTextLength,IBMBIDI_NUMERAL_HINDI);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IBMBIDI_NUMERAL_ARABIC:
|
|
|
|
HandleNumbers(aText,aTextLength,IBMBIDI_NUMERAL_ARABIC);
|
|
|
|
break;
|
|
|
|
|
2009-01-30 00:13:17 -08:00
|
|
|
case IBMBIDI_NUMERAL_PERSIAN:
|
|
|
|
HandleNumbers(aText,aTextLength,IBMBIDI_NUMERAL_PERSIAN);
|
|
|
|
break;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
case IBMBIDI_NUMERAL_REGULAR:
|
|
|
|
|
|
|
|
switch (aCharType) {
|
|
|
|
|
|
|
|
case eCharType_EuropeanNumber:
|
|
|
|
HandleNumbers(aText,aTextLength,IBMBIDI_NUMERAL_ARABIC);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eCharType_ArabicNumber:
|
|
|
|
HandleNumbers(aText,aTextLength,IBMBIDI_NUMERAL_HINDI);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2009-01-30 00:13:17 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
case IBMBIDI_NUMERAL_HINDICONTEXT:
|
|
|
|
if ( ( (GET_BIDI_OPTION_DIRECTION(bidiOptions)==IBMBIDI_TEXTDIRECTION_RTL) && (IS_ARABIC_DIGIT (aText[0])) ) || (eCharType_ArabicNumber == aCharType) )
|
|
|
|
HandleNumbers(aText,aTextLength,IBMBIDI_NUMERAL_HINDI);
|
|
|
|
else if (eCharType_EuropeanNumber == aCharType)
|
|
|
|
HandleNumbers(aText,aTextLength,IBMBIDI_NUMERAL_ARABIC);
|
|
|
|
break;
|
|
|
|
|
2009-01-30 00:13:17 -08:00
|
|
|
case IBMBIDI_NUMERAL_PERSIANCONTEXT:
|
|
|
|
if ( ( (GET_BIDI_OPTION_DIRECTION(bidiOptions)==IBMBIDI_TEXTDIRECTION_RTL) && (IS_ARABIC_DIGIT (aText[0])) ) || (eCharType_ArabicNumber == aCharType) )
|
|
|
|
HandleNumbers(aText,aTextLength,IBMBIDI_NUMERAL_PERSIAN);
|
|
|
|
else if (eCharType_EuropeanNumber == aCharType)
|
|
|
|
HandleNumbers(aText,aTextLength,IBMBIDI_NUMERAL_ARABIC);
|
|
|
|
break;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
case IBMBIDI_NUMERAL_NOMINAL:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
StripBidiControlCharacters(aText, aTextLength);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsBidiPresUtils::StripBidiControlCharacters(PRUnichar* aText,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t& aTextLength)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
if ( (nullptr == aText) || (aTextLength < 1) ) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t stripLen = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
for (int32_t i = 0; i < aTextLength; i++) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// XXX: This silently ignores surrogate characters.
|
|
|
|
// As of Unicode 4.0, all Bidi control characters are within the BMP.
|
2012-08-22 08:56:38 -07:00
|
|
|
if (IsBidiControl((uint32_t)aText[i])) {
|
2007-03-22 10:30:00 -07:00
|
|
|
++stripLen;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
aText[i - stripLen] = aText[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
aTextLength -= stripLen;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0 // XXX: for the future use ???
|
|
|
|
void
|
|
|
|
RemoveDiacritics(PRUnichar* aText,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t& aTextLength)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (aText && (aTextLength > 0) ) {
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t offset = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
for (int32_t i = 0; i < aTextLength && aText[i]; i++) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (IS_BIDI_DIACRITIC(aText[i]) ) {
|
|
|
|
++offset;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
aText[i - offset] = aText[i];
|
|
|
|
}
|
|
|
|
aTextLength = i - offset;
|
|
|
|
aText[aTextLength] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void
|
2011-04-13 02:23:49 -07:00
|
|
|
nsBidiPresUtils::CalculateCharType(nsBidi* aBidiEngine,
|
|
|
|
const PRUnichar* aText,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t& aOffset,
|
|
|
|
int32_t aCharTypeLimit,
|
|
|
|
int32_t& aRunLimit,
|
|
|
|
int32_t& aRunLength,
|
|
|
|
int32_t& aRunCount,
|
|
|
|
uint8_t& aCharType,
|
|
|
|
uint8_t& aPrevCharType)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
{
|
2011-09-28 23:19:26 -07:00
|
|
|
bool strongTypeFound = false;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t offset;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCharType charType;
|
|
|
|
|
|
|
|
aCharType = eCharType_OtherNeutral;
|
|
|
|
|
|
|
|
for (offset = aOffset; offset < aCharTypeLimit; offset++) {
|
|
|
|
// Make sure we give RTL chartype to all characters that would be classified
|
|
|
|
// as Right-To-Left by a bidi platform.
|
|
|
|
// (May differ from the UnicodeData, eg we set RTL chartype to some NSMs.)
|
2011-04-13 02:23:49 -07:00
|
|
|
if (IS_HEBREW_CHAR(aText[offset]) ) {
|
2007-03-22 10:30:00 -07:00
|
|
|
charType = eCharType_RightToLeft;
|
|
|
|
}
|
2011-04-13 02:23:49 -07:00
|
|
|
else if (IS_ARABIC_ALPHABETIC(aText[offset]) ) {
|
2007-03-22 10:30:00 -07:00
|
|
|
charType = eCharType_RightToLeftArabic;
|
|
|
|
}
|
|
|
|
else {
|
2011-04-13 02:23:49 -07:00
|
|
|
aBidiEngine->GetCharTypeAt(offset, &charType);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!CHARTYPE_IS_WEAK(charType) ) {
|
|
|
|
|
|
|
|
if (strongTypeFound
|
|
|
|
&& (charType != aPrevCharType)
|
|
|
|
&& (CHARTYPE_IS_RTL(charType) || CHARTYPE_IS_RTL(aPrevCharType) ) ) {
|
|
|
|
// Stop at this point to ensure uni-directionality of the text
|
|
|
|
// (from platform's point of view).
|
|
|
|
// Also, don't mix Arabic and Hebrew content (since platform may
|
|
|
|
// provide BIDI support to one of them only).
|
|
|
|
aRunLength = offset - aOffset;
|
|
|
|
aRunLimit = offset;
|
|
|
|
++aRunCount;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( (eCharType_RightToLeftArabic == aPrevCharType
|
|
|
|
|| eCharType_ArabicNumber == aPrevCharType)
|
|
|
|
&& eCharType_EuropeanNumber == charType) {
|
|
|
|
charType = eCharType_ArabicNumber;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set PrevCharType to the last strong type in this frame
|
|
|
|
// (for correct numeric shaping)
|
|
|
|
aPrevCharType = charType;
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
strongTypeFound = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
aCharType = charType;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
aOffset = offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsBidiPresUtils::ProcessText(const PRUnichar* aText,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aLength,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsBidiDirection aBaseDirection,
|
|
|
|
nsPresContext* aPresContext,
|
2008-07-18 11:29:06 -07:00
|
|
|
BidiProcessor& aprocessor,
|
2007-03-22 10:30:00 -07:00
|
|
|
Mode aMode,
|
|
|
|
nsBidiPositionResolve* aPosResolve,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aPosResolveCount,
|
2011-04-13 02:23:49 -07:00
|
|
|
nscoord* aWidth,
|
|
|
|
nsBidi* aBidiEngine)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_ASSERTION((aPosResolve == nullptr) != (aPosResolveCount > 0), "Incorrect aPosResolve / aPosResolveCount arguments");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t runCount;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-04-13 02:23:49 -07:00
|
|
|
nsAutoString textBuffer(aText, aLength);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
nsresult rv = aBidiEngine->SetPara(aText, aLength, aBaseDirection, nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2011-04-13 02:23:49 -07:00
|
|
|
rv = aBidiEngine->CountRuns(&runCount);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2008-07-18 11:29:06 -07:00
|
|
|
nscoord xOffset = 0;
|
2011-04-13 02:23:49 -07:00
|
|
|
nscoord width, xEndRun = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
nscoord totalWidth = 0;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t i, start, limit, length;
|
|
|
|
uint32_t visualStart = 0;
|
|
|
|
uint8_t charType;
|
|
|
|
uint8_t prevType = eCharType_LeftToRight;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsBidiLevel level;
|
|
|
|
|
|
|
|
for(int nPosResolve=0; nPosResolve < aPosResolveCount; ++nPosResolve)
|
|
|
|
{
|
|
|
|
aPosResolve[nPosResolve].visualIndex = kNotFound;
|
|
|
|
aPosResolve[nPosResolve].visualLeftTwips = kNotFound;
|
2009-03-21 01:38:14 -07:00
|
|
|
aPosResolve[nPosResolve].visualWidth = kNotFound;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < runCount; i++) {
|
2011-04-13 02:23:49 -07:00
|
|
|
rv = aBidiEngine->GetVisualRun(i, &start, &length, &aBaseDirection);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2011-04-13 02:23:49 -07:00
|
|
|
rv = aBidiEngine->GetLogicalRun(start, &limit, &level);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t subRunLength = limit - start;
|
|
|
|
int32_t lineOffset = start;
|
2013-01-15 04:22:03 -08:00
|
|
|
int32_t typeLimit = std::min(limit, aLength);
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t subRunCount = 1;
|
|
|
|
int32_t subRunLimit = typeLimit;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If |level| is even, i.e. the direction of the run is left-to-right, we
|
|
|
|
* render the subruns from left to right and increment the x-coordinate
|
2008-07-18 11:29:06 -07:00
|
|
|
* |xOffset| by the width of each subrun after rendering.
|
2007-03-22 10:30:00 -07:00
|
|
|
*
|
|
|
|
* If |level| is odd, i.e. the direction of the run is right-to-left, we
|
2008-07-18 11:29:06 -07:00
|
|
|
* render the subruns from right to left. We begin by incrementing |xOffset| by
|
2007-03-22 10:30:00 -07:00
|
|
|
* the width of the whole run, and then decrement it by the width of each
|
|
|
|
* subrun before rendering. After rendering all the subruns, we restore the
|
|
|
|
* x-coordinate of the end of the run for the start of the next run.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (level & 1) {
|
2008-07-18 11:29:06 -07:00
|
|
|
aprocessor.SetText(aText + start, subRunLength, nsBidiDirection(level & 1));
|
|
|
|
width = aprocessor.GetWidth();
|
|
|
|
xOffset += width;
|
|
|
|
xEndRun = xOffset;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
while (subRunCount > 0) {
|
|
|
|
// CalculateCharType can increment subRunCount if the run
|
|
|
|
// contains mixed character types
|
2011-04-13 02:23:49 -07:00
|
|
|
CalculateCharType(aBidiEngine, aText, lineOffset, typeLimit, subRunLimit, subRunLength, subRunCount, charType, prevType);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsAutoString runVisualText;
|
|
|
|
runVisualText.Assign(aText + start, subRunLength);
|
2012-08-22 08:56:38 -07:00
|
|
|
if (int32_t(runVisualText.Length()) < subRunLength)
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
FormatUnicodeText(aPresContext, runVisualText.BeginWriting(), subRunLength,
|
2008-08-11 08:19:01 -07:00
|
|
|
(nsCharType)charType, level & 1);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-07-18 11:29:06 -07:00
|
|
|
aprocessor.SetText(runVisualText.get(), subRunLength, nsBidiDirection(level & 1));
|
|
|
|
width = aprocessor.GetWidth();
|
2007-03-22 10:30:00 -07:00
|
|
|
totalWidth += width;
|
|
|
|
if (level & 1) {
|
2008-07-18 11:29:06 -07:00
|
|
|
xOffset -= width;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
if (aMode == MODE_DRAW) {
|
2008-07-18 11:29:06 -07:00
|
|
|
aprocessor.DrawText(xOffset, width);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The caller may request to calculate the visual position of one
|
|
|
|
* or more characters.
|
|
|
|
*/
|
|
|
|
for(int nPosResolve=0; nPosResolve<aPosResolveCount; ++nPosResolve)
|
|
|
|
{
|
|
|
|
nsBidiPositionResolve* posResolve = &aPosResolve[nPosResolve];
|
|
|
|
/*
|
|
|
|
* Did we already resolve this position's visual metric? If so, skip.
|
|
|
|
*/
|
|
|
|
if (posResolve->visualLeftTwips != kNotFound)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* First find out if the logical position is within this run.
|
|
|
|
*/
|
|
|
|
if (start <= posResolve->logicalIndex &&
|
|
|
|
start + subRunLength > posResolve->logicalIndex) {
|
|
|
|
/*
|
|
|
|
* If this run is only one character long, we have an easy case:
|
|
|
|
* the visual position is the x-coord of the start of the run
|
2008-07-18 11:29:06 -07:00
|
|
|
* less the x-coord of the start of the whole text.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
|
|
|
if (subRunLength == 1) {
|
|
|
|
posResolve->visualIndex = visualStart;
|
2008-07-18 11:29:06 -07:00
|
|
|
posResolve->visualLeftTwips = xOffset;
|
2009-03-21 01:38:14 -07:00
|
|
|
posResolve->visualWidth = width;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Otherwise, we need to measure the width of the run's part
|
|
|
|
* which is to the visual left of the index.
|
|
|
|
* In other words, the run is broken in two, around the logical index,
|
|
|
|
* and we measure the part which is visually left.
|
|
|
|
* If the run is right-to-left, this part will span from after the index
|
|
|
|
* up to the end of the run; if it is left-to-right, this part will span
|
|
|
|
* from the start of the run up to (and inclduing) the character before the index.
|
|
|
|
*/
|
|
|
|
else {
|
2009-03-21 01:38:14 -07:00
|
|
|
/*
|
|
|
|
* Here is a description of how the width of the current character
|
|
|
|
* (posResolve->visualWidth) is calculated:
|
|
|
|
*
|
|
|
|
* LTR (current char: "P"):
|
|
|
|
* S A M P L E (logical index: 3, visual index: 3)
|
|
|
|
* ^ (visualLeftPart)
|
|
|
|
* ^ (visualRightSide)
|
|
|
|
* visualLeftLength == 3
|
|
|
|
* ^^^^^^ (subWidth)
|
|
|
|
* ^^^^^^^^ (aprocessor.GetWidth() -- with visualRightSide)
|
|
|
|
* ^^ (posResolve->visualWidth)
|
|
|
|
*
|
|
|
|
* RTL (current char: "M"):
|
|
|
|
* E L P M A S (logical index: 2, visual index: 3)
|
|
|
|
* ^ (visualLeftPart)
|
|
|
|
* ^ (visualRightSide)
|
|
|
|
* visualLeftLength == 3
|
|
|
|
* ^^^^^^ (subWidth)
|
|
|
|
* ^^^^^^^^ (aprocessor.GetWidth() -- with visualRightSide)
|
|
|
|
* ^^ (posResolve->visualWidth)
|
|
|
|
*/
|
2007-03-22 10:30:00 -07:00
|
|
|
nscoord subWidth;
|
|
|
|
// The position in the text where this run's "left part" begins.
|
2009-03-21 01:38:14 -07:00
|
|
|
const PRUnichar* visualLeftPart, *visualRightSide;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (level & 1) {
|
|
|
|
// One day, son, this could all be replaced with mBidiEngine.GetVisualIndex ...
|
|
|
|
posResolve->visualIndex = visualStart + (subRunLength - (posResolve->logicalIndex + 1 - start));
|
|
|
|
// Skipping to the "left part".
|
|
|
|
visualLeftPart = aText + posResolve->logicalIndex + 1;
|
2009-03-21 01:38:14 -07:00
|
|
|
// Skipping to the right side of the current character
|
|
|
|
visualRightSide = visualLeftPart - 1;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
posResolve->visualIndex = visualStart + (posResolve->logicalIndex - start);
|
|
|
|
// Skipping to the "left part".
|
|
|
|
visualLeftPart = aText + start;
|
2009-03-21 01:38:14 -07:00
|
|
|
// In LTR mode this is the same as visualLeftPart
|
|
|
|
visualRightSide = visualLeftPart;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
// The delta between the start of the run and the left part's end.
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t visualLeftLength = posResolve->visualIndex - visualStart;
|
2008-07-18 11:29:06 -07:00
|
|
|
aprocessor.SetText(visualLeftPart, visualLeftLength, nsBidiDirection(level & 1));
|
|
|
|
subWidth = aprocessor.GetWidth();
|
2009-03-21 01:38:14 -07:00
|
|
|
aprocessor.SetText(visualRightSide, visualLeftLength + 1, nsBidiDirection(level & 1));
|
2008-07-18 11:29:06 -07:00
|
|
|
posResolve->visualLeftTwips = xOffset + subWidth;
|
2009-03-21 01:38:14 -07:00
|
|
|
posResolve->visualWidth = aprocessor.GetWidth() - subWidth;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(level & 1)) {
|
2008-07-18 11:29:06 -07:00
|
|
|
xOffset += width;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
--subRunCount;
|
|
|
|
start = lineOffset;
|
|
|
|
subRunLimit = typeLimit;
|
|
|
|
subRunLength = typeLimit - lineOffset;
|
|
|
|
} // while
|
|
|
|
if (level & 1) {
|
2008-07-18 11:29:06 -07:00
|
|
|
xOffset = xEndRun;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
visualStart += length;
|
|
|
|
} // for
|
|
|
|
|
|
|
|
if (aWidth) {
|
|
|
|
*aWidth = totalWidth;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2008-07-18 11:29:06 -07:00
|
|
|
|
|
|
|
class NS_STACK_CLASS nsIRenderingContextBidiProcessor : public nsBidiPresUtils::BidiProcessor {
|
|
|
|
public:
|
2011-04-07 18:04:40 -07:00
|
|
|
nsIRenderingContextBidiProcessor(nsRenderingContext* aCtx,
|
|
|
|
nsRenderingContext* aTextRunConstructionContext,
|
2008-07-18 11:29:06 -07:00
|
|
|
const nsPoint& aPt)
|
2011-01-16 12:23:33 -08:00
|
|
|
: mCtx(aCtx), mTextRunConstructionContext(aTextRunConstructionContext), mPt(aPt) { }
|
2008-07-18 11:29:06 -07:00
|
|
|
|
|
|
|
~nsIRenderingContextBidiProcessor()
|
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
mCtx->SetTextRunRTL(false);
|
2008-07-18 11:29:06 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void SetText(const PRUnichar* aText,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aLength,
|
2008-07-18 11:29:06 -07:00
|
|
|
nsBidiDirection aDirection)
|
|
|
|
{
|
2011-01-16 12:23:33 -08:00
|
|
|
mTextRunConstructionContext->SetTextRunRTL(aDirection==NSBIDI_RTL);
|
2008-07-18 11:29:06 -07:00
|
|
|
mText = aText;
|
|
|
|
mLength = aLength;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual nscoord GetWidth()
|
|
|
|
{
|
2011-04-07 18:04:40 -07:00
|
|
|
return mTextRunConstructionContext->GetWidth(mText, mLength);
|
2008-07-18 11:29:06 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void DrawText(nscoord aXOffset,
|
|
|
|
nscoord)
|
|
|
|
{
|
2011-04-07 18:04:40 -07:00
|
|
|
mCtx->FontMetrics()->DrawString(mText, mLength, mPt.x + aXOffset, mPt.y,
|
|
|
|
mCtx, mTextRunConstructionContext);
|
2008-07-18 11:29:06 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2011-04-07 18:04:40 -07:00
|
|
|
nsRenderingContext* mCtx;
|
|
|
|
nsRenderingContext* mTextRunConstructionContext;
|
2009-04-19 01:19:27 -07:00
|
|
|
nsPoint mPt;
|
2008-07-18 11:29:06 -07:00
|
|
|
const PRUnichar* mText;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t mLength;
|
2008-07-18 11:29:06 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
nsresult nsBidiPresUtils::ProcessTextForRenderingContext(const PRUnichar* aText,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aLength,
|
2008-07-18 11:29:06 -07:00
|
|
|
nsBidiDirection aBaseDirection,
|
|
|
|
nsPresContext* aPresContext,
|
2011-04-07 18:04:40 -07:00
|
|
|
nsRenderingContext& aRenderingContext,
|
|
|
|
nsRenderingContext& aTextRunConstructionContext,
|
2008-07-18 11:29:06 -07:00
|
|
|
Mode aMode,
|
|
|
|
nscoord aX,
|
|
|
|
nscoord aY,
|
|
|
|
nsBidiPositionResolve* aPosResolve,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aPosResolveCount,
|
2008-07-18 11:29:06 -07:00
|
|
|
nscoord* aWidth)
|
|
|
|
{
|
2011-01-16 12:23:33 -08:00
|
|
|
nsIRenderingContextBidiProcessor processor(&aRenderingContext, &aTextRunConstructionContext, nsPoint(aX, aY));
|
2011-04-13 02:23:49 -07:00
|
|
|
nsBidi bidiEngine;
|
2008-07-18 11:29:06 -07:00
|
|
|
return ProcessText(aText, aLength, aBaseDirection, aPresContext, processor,
|
2011-04-13 02:23:49 -07:00
|
|
|
aMode, aPosResolve, aPosResolveCount, aWidth, &bidiEngine);
|
2008-07-18 11:29:06 -07:00
|
|
|
}
|
2010-05-31 19:19:35 -07:00
|
|
|
|
2011-01-04 00:52:17 -08:00
|
|
|
/* static */
|
|
|
|
void nsBidiPresUtils::WriteReverse(const PRUnichar* aSrc,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aSrcLength,
|
2011-01-04 00:52:17 -08:00
|
|
|
PRUnichar* aDest)
|
|
|
|
{
|
2012-02-28 13:24:04 -08:00
|
|
|
PRUnichar* dest = aDest + aSrcLength;
|
|
|
|
mozilla::unicode::ClusterIterator iter(aSrc, aSrcLength);
|
|
|
|
|
|
|
|
while (!iter.AtEnd()) {
|
|
|
|
iter.Next();
|
|
|
|
for (const PRUnichar *cp = iter; cp > aSrc; ) {
|
|
|
|
// Here we rely on the fact that there are no non-BMP mirrored pairs
|
|
|
|
// currently in Unicode, so we don't need to look for surrogates
|
|
|
|
*--dest = mozilla::unicode::GetMirroredChar(*--cp);
|
2011-01-04 00:52:17 -08:00
|
|
|
}
|
2012-02-28 13:24:04 -08:00
|
|
|
aSrc = iter;
|
2011-01-04 00:52:17 -08:00
|
|
|
}
|
|
|
|
|
2012-02-28 13:24:04 -08:00
|
|
|
NS_ASSERTION(dest == aDest, "Whole string not copied");
|
2011-01-04 00:52:17 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* static */
|
2011-09-28 23:19:26 -07:00
|
|
|
bool nsBidiPresUtils::WriteLogicalToVisual(const PRUnichar* aSrc,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aSrcLength,
|
2012-02-28 13:24:04 -08:00
|
|
|
PRUnichar* aDest,
|
|
|
|
nsBidiLevel aBaseDirection,
|
|
|
|
nsBidi* aBidiEngine)
|
2011-01-04 00:52:17 -08:00
|
|
|
{
|
|
|
|
const PRUnichar* src = aSrc;
|
2012-07-30 07:20:58 -07:00
|
|
|
nsresult rv = aBidiEngine->SetPara(src, aSrcLength, aBaseDirection, nullptr);
|
2011-01-04 00:52:17 -08:00
|
|
|
if (NS_FAILED(rv)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2011-01-04 00:52:17 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
nsBidiDirection dir;
|
|
|
|
rv = aBidiEngine->GetDirection(&dir);
|
|
|
|
// NSBIDI_LTR returned from GetDirection means the whole text is LTR
|
|
|
|
if (NS_FAILED(rv) || dir == NSBIDI_LTR) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2011-01-04 00:52:17 -08:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t runCount;
|
2011-01-04 00:52:17 -08:00
|
|
|
rv = aBidiEngine->CountRuns(&runCount);
|
|
|
|
if (NS_FAILED(rv)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2011-01-04 00:52:17 -08:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t runIndex, start, length;
|
2011-01-04 00:52:17 -08:00
|
|
|
PRUnichar* dest = aDest;
|
|
|
|
|
|
|
|
for (runIndex = 0; runIndex < runCount; ++runIndex) {
|
|
|
|
rv = aBidiEngine->GetVisualRun(runIndex, &start, &length, &dir);
|
|
|
|
if (NS_FAILED(rv)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2011-01-04 00:52:17 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
src = aSrc + start;
|
|
|
|
|
|
|
|
if (dir == NSBIDI_RTL) {
|
|
|
|
WriteReverse(src, length, dest);
|
|
|
|
dest += length;
|
|
|
|
} else {
|
|
|
|
do {
|
|
|
|
NS_ASSERTION(src >= aSrc && src < aSrc + aSrcLength,
|
|
|
|
"logical index out of range");
|
|
|
|
NS_ASSERTION(dest < aDest + aSrcLength, "visual index out of range");
|
|
|
|
*(dest++) = *(src++);
|
|
|
|
} while (--length);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-14 22:42:40 -07:00
|
|
|
NS_ASSERTION(static_cast<uint32_t>(dest - aDest) == aSrcLength,
|
|
|
|
"whole string not copied");
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2011-01-04 00:52:17 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsBidiPresUtils::CopyLogicalToVisual(const nsAString& aSource,
|
|
|
|
nsAString& aDest,
|
|
|
|
nsBidiLevel aBaseDirection,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aOverride)
|
2011-01-04 00:52:17 -08:00
|
|
|
{
|
|
|
|
aDest.SetLength(0);
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t srcLength = aSource.Length();
|
2011-01-04 00:52:17 -08:00
|
|
|
if (srcLength == 0)
|
|
|
|
return;
|
|
|
|
if (!EnsureStringLength(aDest, srcLength)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
nsAString::const_iterator fromBegin, fromEnd;
|
|
|
|
nsAString::iterator toBegin;
|
|
|
|
aSource.BeginReading(fromBegin);
|
|
|
|
aSource.EndReading(fromEnd);
|
|
|
|
aDest.BeginWriting(toBegin);
|
|
|
|
|
|
|
|
if (aOverride) {
|
|
|
|
if (aBaseDirection == NSBIDI_RTL) {
|
|
|
|
// no need to use the converter -- just copy the string in reverse order
|
|
|
|
WriteReverse(fromBegin.get(), srcLength, toBegin.get());
|
|
|
|
} else {
|
|
|
|
// if aOverride && aBaseDirection == NSBIDI_LTR, fall through to the
|
|
|
|
// simple copy
|
|
|
|
aDest.SetLength(0);
|
|
|
|
}
|
|
|
|
} else {
|
2011-04-13 02:23:49 -07:00
|
|
|
nsBidi bidiEngine;
|
2011-01-04 00:52:17 -08:00
|
|
|
if (!WriteLogicalToVisual(fromBegin.get(), srcLength, toBegin.get(),
|
2011-04-13 02:23:49 -07:00
|
|
|
aBaseDirection, &bidiEngine)) {
|
2011-01-04 00:52:17 -08:00
|
|
|
aDest.SetLength(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aDest.IsEmpty()) {
|
|
|
|
// Either there was an error or the source is unidirectional
|
|
|
|
// left-to-right. In either case, just copy source to dest.
|
|
|
|
CopyUnicodeTo(aSource.BeginReading(fromBegin), aSource.EndReading(fromEnd),
|
|
|
|
aDest);
|
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif // IBMBIDI
|