2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 18:30:37 +04:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
2001-03-09 04:12:39 +03:00
|
|
|
*
|
2004-04-18 18:30:37 +04:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
2001-03-09 04:12:39 +03:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
2001-03-09 04:12:39 +03:00
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Communicator client code.
|
|
|
|
*
|
2004-04-18 18:30:37 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-29 00:14:13 +04:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
2001-03-09 04:12:39 +03:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* Contributor(s):
|
2006-02-22 00:33:47 +03:00
|
|
|
* Uri Bernstein <uriber@gmail.com>
|
2006-06-15 12:16:23 +04:00
|
|
|
* Haamed Gheibi <gheibi@metanetworking.com>
|
2009-01-30 11:13:17 +03:00
|
|
|
* Ehsan Akhgari <ehsan.akhgari@gmail.com>
|
2001-09-29 00:14:13 +04:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-18 18:30:37 +04:00
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
2001-09-29 00:14:13 +04:00
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
2004-04-18 18:30:37 +04:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-29 00:14:13 +04:00
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2004-04-18 18:30:37 +04:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-29 00:14:13 +04:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2001-03-09 04:12:39 +03:00
|
|
|
|
|
|
|
#ifdef IBMBIDI
|
|
|
|
|
|
|
|
#include "nsBidiPresUtils.h"
|
|
|
|
#include "nsTextFragment.h"
|
2007-01-30 03:06:41 +03:00
|
|
|
#include "nsGkAtoms.h"
|
2004-08-01 03:15:21 +04:00
|
|
|
#include "nsPresContext.h"
|
2001-03-09 04:12:39 +03:00
|
|
|
#include "nsIRenderingContext.h"
|
|
|
|
#include "nsIServiceManager.h"
|
2004-02-24 00:29:06 +03:00
|
|
|
#include "nsFrameManager.h"
|
2002-02-19 23:41:32 +03:00
|
|
|
#include "nsBidiUtils.h"
|
2006-02-22 00:33:47 +03:00
|
|
|
#include "nsCSSFrameConstructor.h"
|
2006-03-08 21:12:07 +03:00
|
|
|
#include "nsHTMLContainerFrame.h"
|
2006-06-15 12:16:23 +04:00
|
|
|
#include "nsInlineFrame.h"
|
2007-08-29 12:21:38 +04:00
|
|
|
#include "nsPlaceholderFrame.h"
|
2009-09-18 15:09:35 +04:00
|
|
|
#include "nsContainerFrame.h"
|
2010-03-17 20:30:30 +03:00
|
|
|
#include "nsFirstLetterFrame.h"
|
2011-01-04 11:52:17 +03:00
|
|
|
#include "gfxUnicodeProperties.h"
|
2011-01-16 23:23:33 +03:00
|
|
|
#include "nsIThebesFontMetrics.h"
|
2011-04-11 12:00:28 +04:00
|
|
|
#include "nsTextFrame.h"
|
2011-03-24 12:28:44 +03:00
|
|
|
|
2011-04-11 11:59:29 +04:00
|
|
|
#undef NOISY_BIDI
|
|
|
|
#undef REALLY_NOISY_BIDI
|
|
|
|
|
2010-03-29 05:46:55 +04:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2001-03-09 04:12:39 +03:00
|
|
|
static const PRUnichar kSpace = 0x0020;
|
|
|
|
static const PRUnichar kLineSeparator = 0x2028;
|
|
|
|
static const PRUnichar kObjectSubstitute = 0xFFFC;
|
|
|
|
static const PRUnichar kLRE = 0x202A;
|
|
|
|
static const PRUnichar kRLE = 0x202B;
|
2001-06-29 07:15:58 +04:00
|
|
|
static const PRUnichar kLRO = 0x202D;
|
|
|
|
static const PRUnichar kRLO = 0x202E;
|
2001-03-09 04:12:39 +03:00
|
|
|
static const PRUnichar kPDF = 0x202C;
|
2002-02-19 23:41:32 +03:00
|
|
|
|
2011-04-11 11:59:30 +04:00
|
|
|
#define NS_BIDI_CONTROL_FRAME ((nsIFrame*)0xfffb1d1)
|
2001-03-09 04:12:39 +03:00
|
|
|
|
2011-04-13 13:23:49 +04:00
|
|
|
struct BidiParagraphData {
|
|
|
|
nsString mBuffer;
|
|
|
|
nsAutoTArray<PRUnichar, 16> mEmbeddingStack;
|
|
|
|
nsTArray<nsIFrame*> mLogicalFrames;
|
|
|
|
nsDataHashtable<nsISupportsHashKey, PRInt32> mContentToFrameIndex;
|
|
|
|
PRPackedBool mIsVisual;
|
|
|
|
nsBidiLevel mParaLevel;
|
|
|
|
nsIContent* mPrevContent;
|
|
|
|
nsAutoPtr<nsBidi> mBidiEngine;
|
|
|
|
|
|
|
|
void Init(nsBlockFrame *aBlockFrame)
|
|
|
|
{
|
|
|
|
mContentToFrameIndex.Init();
|
|
|
|
mBidiEngine = new nsBidi();
|
|
|
|
mPrevContent = nsnull;
|
|
|
|
mParaLevel =
|
|
|
|
(NS_STYLE_DIRECTION_RTL == aBlockFrame->GetStyleVisibility()->mDirection) ?
|
|
|
|
NSBIDI_RTL : NSBIDI_LTR;
|
|
|
|
|
|
|
|
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()) {
|
|
|
|
mIsVisual = PR_FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-03-09 04:12:39 +03:00
|
|
|
}
|
|
|
|
|
2011-04-13 13:23:49 +04:00
|
|
|
nsresult SetPara()
|
|
|
|
{
|
|
|
|
return mBidiEngine->SetPara(mBuffer.get(), BufferLength(),
|
|
|
|
mParaLevel, nsnull);
|
2001-03-09 04:12:39 +03:00
|
|
|
}
|
2011-04-13 13:23:49 +04:00
|
|
|
|
|
|
|
nsresult CountRuns(PRInt32 *runCount){ return mBidiEngine->CountRuns(runCount); }
|
|
|
|
|
|
|
|
nsresult GetLogicalRun(PRInt32 aLogicalStart,
|
|
|
|
PRInt32* aLogicalLimit,
|
|
|
|
nsBidiLevel* aLevel)
|
|
|
|
{
|
|
|
|
nsresult rv = mBidiEngine->GetLogicalRun(aLogicalStart,
|
|
|
|
aLogicalLimit, aLevel);
|
|
|
|
if (mIsVisual || NS_FAILED(rv))
|
|
|
|
*aLevel = mParaLevel;
|
|
|
|
return rv;
|
2001-03-09 04:12:39 +03:00
|
|
|
}
|
|
|
|
|
2011-04-13 13:23:49 +04:00
|
|
|
void ResetData()
|
|
|
|
{
|
|
|
|
mLogicalFrames.Clear();
|
|
|
|
mContentToFrameIndex.Clear();
|
|
|
|
mBuffer.SetLength(0);
|
|
|
|
for (PRUint32 i = 0; i < mEmbeddingStack.Length(); ++i) {
|
|
|
|
mBuffer.Append(mEmbeddingStack[i]);
|
|
|
|
mLogicalFrames.AppendElement(NS_BIDI_CONTROL_FRAME);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AppendFrame(nsIFrame* aFrame, nsIContent* aContent = nsnull)
|
|
|
|
{
|
|
|
|
if (aContent) {
|
|
|
|
mContentToFrameIndex.Put(aContent, FrameCount());
|
|
|
|
}
|
|
|
|
mLogicalFrames.AppendElement(aFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 GetLastFrameForContent(nsIContent *aContent)
|
|
|
|
{
|
|
|
|
PRInt32 index = 0;
|
|
|
|
mContentToFrameIndex.Get(aContent, &index);
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 FrameCount(){ return mLogicalFrames.Length(); }
|
|
|
|
|
|
|
|
PRInt32 BufferLength(){ return mBuffer.Length(); }
|
|
|
|
|
|
|
|
nsIFrame* FrameAt(PRInt32 aIndex){ return mLogicalFrames[aIndex]; }
|
|
|
|
|
|
|
|
void AppendUnichar(PRUnichar aCh){ mBuffer.Append(aCh); }
|
|
|
|
|
|
|
|
void AppendString(const nsDependentSubstring& aString){ mBuffer.Append(aString); }
|
|
|
|
|
|
|
|
void PushBidiControl(PRUnichar aCh)
|
|
|
|
{
|
|
|
|
mLogicalFrames.AppendElement(NS_BIDI_CONTROL_FRAME);
|
|
|
|
mBuffer.Append(aCh);
|
|
|
|
mEmbeddingStack.AppendElement(aCh);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PopBidiControl()
|
|
|
|
{
|
|
|
|
mLogicalFrames.AppendElement(NS_BIDI_CONTROL_FRAME);
|
|
|
|
mBuffer.Append(kPDF);
|
|
|
|
NS_ASSERTION(mEmbeddingStack.Length(), "embedding/override underflow");
|
|
|
|
mEmbeddingStack.TruncateLength(mEmbeddingStack.Length() - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClearBidiControls()
|
|
|
|
{
|
|
|
|
for (PRUint32 i = 0; i < mEmbeddingStack.Length(); ++i) {
|
|
|
|
mBuffer.Append(kPDF);
|
|
|
|
mLogicalFrames.AppendElement(NS_BIDI_CONTROL_FRAME);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct BidiLineData {
|
|
|
|
nsTArray<nsIFrame*> mLogicalFrames;
|
|
|
|
nsTArray<nsIFrame*> mVisualFrames;
|
|
|
|
nsTArray<PRInt32> mIndexMap;
|
|
|
|
nsAutoTArray<PRUint8, 18> mLevels;
|
|
|
|
PRBool mIsReordered;
|
|
|
|
|
|
|
|
BidiLineData(nsIFrame* aFirstFrameOnLine, PRInt32 aNumFramesOnLine)
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Initialize the logically-ordered array of frames using the top-level
|
|
|
|
* frames of a single line
|
|
|
|
*/
|
|
|
|
mLogicalFrames.Clear();
|
|
|
|
|
|
|
|
PRBool isReordered = PR_FALSE;
|
|
|
|
PRBool hasRTLFrames = PR_FALSE;
|
|
|
|
|
|
|
|
for (nsIFrame* frame = aFirstFrameOnLine;
|
|
|
|
frame && aNumFramesOnLine--;
|
|
|
|
frame = frame->GetNextSibling()) {
|
|
|
|
AppendFrame(frame);
|
|
|
|
PRUint8 level = nsBidiPresUtils::GetFrameEmbeddingLevel(frame);
|
|
|
|
mLevels.AppendElement(level);
|
|
|
|
mIndexMap.AppendElement(0);
|
|
|
|
if (level & 1) {
|
|
|
|
hasRTLFrames = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reorder the line
|
|
|
|
nsBidi::ReorderVisual(mLevels.Elements(), FrameCount(),
|
|
|
|
mIndexMap.Elements());
|
|
|
|
|
|
|
|
for (PRInt32 i = 0; i < FrameCount(); i++) {
|
|
|
|
mVisualFrames.AppendElement(LogicalFrameAt(mIndexMap[i]));
|
|
|
|
if (i != mIndexMap[i]) {
|
|
|
|
isReordered = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If there's an RTL frame, assume the line is reordered
|
|
|
|
mIsReordered = isReordered || hasRTLFrames;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AppendFrame(nsIFrame* aFrame){ mLogicalFrames.AppendElement(aFrame); }
|
|
|
|
|
|
|
|
PRInt32 FrameCount(){ return mLogicalFrames.Length(); }
|
|
|
|
|
|
|
|
nsIFrame* LogicalFrameAt(PRInt32 aIndex){ return mLogicalFrames[aIndex]; }
|
|
|
|
|
|
|
|
nsIFrame* VisualFrameAt(PRInt32 aIndex){ return mVisualFrames[aIndex]; }
|
|
|
|
};
|
2001-03-09 04:12:39 +03:00
|
|
|
|
|
|
|
/* Some helper methods for Resolve() */
|
|
|
|
|
2007-01-13 21:20:28 +03:00
|
|
|
// Should this frame be split between text runs?
|
|
|
|
PRBool
|
|
|
|
IsBidiSplittable(nsIFrame* aFrame) {
|
|
|
|
nsIAtom* frameType = aFrame->GetType();
|
|
|
|
// Bidi inline containers should be split, unless they're line frames.
|
|
|
|
return aFrame->IsFrameOfType(nsIFrame::eBidiInlineContainer)
|
|
|
|
&& frameType != nsGkAtoms::lineFrame;
|
|
|
|
}
|
|
|
|
|
2006-02-22 00:33:47 +03:00
|
|
|
static nsresult
|
2007-08-29 13:19:16 +04:00
|
|
|
SplitInlineAncestors(nsIFrame* aFrame)
|
2006-02-22 00:33:47 +03:00
|
|
|
{
|
2007-08-29 13:19:16 +04:00
|
|
|
nsPresContext *presContext = aFrame->PresContext();
|
|
|
|
nsIPresShell *presShell = presContext->PresShell();
|
2006-02-22 00:33:47 +03:00
|
|
|
nsIFrame* frame = aFrame;
|
|
|
|
nsIFrame* parent = aFrame->GetParent();
|
|
|
|
nsIFrame* newParent;
|
|
|
|
|
2007-01-13 21:20:28 +03:00
|
|
|
while (IsBidiSplittable(parent)) {
|
2006-02-22 00:33:47 +03:00
|
|
|
nsIFrame* grandparent = parent->GetParent();
|
|
|
|
NS_ASSERTION(grandparent, "Couldn't get parent's parent in nsBidiPresUtils::SplitInlineAncestors");
|
|
|
|
|
|
|
|
nsresult rv = presShell->FrameConstructor()->
|
2007-08-29 13:19:16 +04:00
|
|
|
CreateContinuingFrame(presContext, parent, grandparent, &newParent, PR_FALSE);
|
2006-02-22 00:33:47 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2009-09-18 15:09:35 +04:00
|
|
|
// Split the child list after |frame|.
|
|
|
|
nsContainerFrame* container = do_QueryFrame(parent);
|
|
|
|
nsFrameList tail = container->StealFramesAfter(frame);
|
2006-03-08 21:12:07 +03:00
|
|
|
|
|
|
|
// Reparent views as necessary
|
2009-09-18 15:09:35 +04:00
|
|
|
rv = nsHTMLContainerFrame::ReparentFrameViewList(presContext, tail, parent, newParent);
|
2006-03-08 21:12:07 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2006-02-22 00:33:47 +03:00
|
|
|
|
2009-09-18 15:09:35 +04:00
|
|
|
// The parent's continuation adopts the siblings after the split.
|
|
|
|
rv = newParent->InsertFrames(nsGkAtoms::nextBidi, nsnull, tail);
|
2009-07-30 21:23:32 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2006-12-26 20:47:52 +03:00
|
|
|
// The list name nsGkAtoms::nextBidi would indicate we don't want reflow
|
2009-09-18 15:09:35 +04:00
|
|
|
nsFrameList temp(newParent, newParent);
|
|
|
|
rv = grandparent->InsertFrames(nsGkAtoms::nextBidi, parent, temp);
|
2006-02-22 00:33:47 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
frame = parent;
|
|
|
|
parent = grandparent;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-04-11 12:00:28 +04: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.
|
2008-03-21 11:39:16 +03:00
|
|
|
static void
|
2008-03-21 11:17:41 +03:00
|
|
|
JoinInlineAncestors(nsIFrame* aFrame)
|
|
|
|
{
|
2011-04-11 12:00:28 +04:00
|
|
|
if (aFrame->GetNextSibling()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
nsIFrame* frame = aFrame->GetParent();
|
2008-03-21 11:17:41 +03:00
|
|
|
while (frame && IsBidiSplittable(frame)) {
|
|
|
|
nsIFrame* next = frame->GetNextContinuation();
|
|
|
|
if (next) {
|
2011-04-11 12:00:28 +04:00
|
|
|
MakeContinuationFluid(frame, next);
|
2008-03-21 11:17:41 +03:00
|
|
|
}
|
2008-03-27 22:27:32 +03:00
|
|
|
// Join the parent only as long as we're its last child.
|
|
|
|
if (frame->GetNextSibling())
|
|
|
|
break;
|
2008-03-21 11:17:41 +03:00
|
|
|
frame = frame->GetParent();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-03-09 04:12:39 +03:00
|
|
|
static nsresult
|
2011-04-11 12:00:28 +04:00
|
|
|
CreateContinuation(nsIFrame* aFrame,
|
|
|
|
nsIFrame** aNewFrame,
|
|
|
|
PRBool aIsFluid)
|
2001-03-09 04:12:39 +03:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aNewFrame, "null OUT ptr");
|
2006-02-22 00:33:47 +03:00
|
|
|
NS_PRECONDITION(aFrame, "null ptr");
|
2001-03-09 04:12:39 +03:00
|
|
|
|
|
|
|
*aNewFrame = nsnull;
|
|
|
|
|
2007-08-29 13:19:16 +04:00
|
|
|
nsPresContext *presContext = aFrame->PresContext();
|
|
|
|
nsIPresShell *presShell = presContext->PresShell();
|
2011-04-11 12:00:28 +04:00
|
|
|
NS_ASSERTION(presShell, "PresShell must be set on PresContext before calling nsBidiPresUtils::CreateContinuation");
|
2001-03-09 04:12:39 +03:00
|
|
|
|
2003-07-02 14:30:00 +04:00
|
|
|
nsIFrame* parent = aFrame->GetParent();
|
2011-04-11 12:00:28 +04:00
|
|
|
NS_ASSERTION(parent, "Couldn't get frame parent in nsBidiPresUtils::CreateContinuation");
|
2009-10-28 05:00:57 +03:00
|
|
|
|
2010-03-17 20:30:30 +03:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
2009-10-28 05:00:57 +03: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 &&
|
|
|
|
parent->GetStyleDisplay()->IsFloating()) {
|
2010-03-17 20:30:30 +03:00
|
|
|
nsFirstLetterFrame* letterFrame = do_QueryFrame(parent);
|
|
|
|
rv = letterFrame->CreateContinuationForFloatingParent(presContext, aFrame,
|
2011-04-11 12:00:28 +04:00
|
|
|
aNewFrame, aIsFluid);
|
2010-03-17 20:30:30 +03:00
|
|
|
return rv;
|
|
|
|
}
|
2009-10-28 05:00:57 +03:00
|
|
|
|
2010-03-17 20:30:30 +03:00
|
|
|
rv = presShell->FrameConstructor()->
|
2011-04-11 12:00:28 +04:00
|
|
|
CreateContinuingFrame(presContext, aFrame, parent, aNewFrame, aIsFluid);
|
2010-03-17 20:30:30 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
2009-10-28 05:00:57 +03:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2006-12-26 20:47:52 +03:00
|
|
|
// The list name nsGkAtoms::nextBidi would indicate we don't want reflow
|
2009-07-30 21:23:32 +04:00
|
|
|
// XXXbz this needs higher-level framelist love
|
2009-09-18 15:09:36 +04:00
|
|
|
nsFrameList temp(*aNewFrame, *aNewFrame);
|
2009-07-30 21:23:32 +04:00
|
|
|
rv = parent->InsertFrames(nsGkAtoms::nextBidi, aFrame, temp);
|
2006-02-22 00:33:47 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2011-04-11 12:00:28 +04:00
|
|
|
if (!aIsFluid) {
|
|
|
|
// Split inline ancestor frames
|
|
|
|
rv = SplitInlineAncestors(aFrame);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2006-02-22 00:33:47 +03:00
|
|
|
}
|
2001-03-09 04:12:39 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2006-05-31 14:21:34 +04:00
|
|
|
|
2007-08-29 12:21:38 +04:00
|
|
|
static PRBool
|
2008-01-30 02:39:39 +03:00
|
|
|
IsFrameInCurrentLine(nsBlockInFlowLineIterator* aLineIter,
|
|
|
|
nsIFrame* aPrevFrame, nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
nsIFrame* endFrame = aLineIter->IsLastLineInList() ? nsnull :
|
|
|
|
aLineIter->GetLine().next()->mFirstChild;
|
|
|
|
nsIFrame* startFrame = aPrevFrame ? aPrevFrame : aLineIter->GetLine()->mFirstChild;
|
2009-09-18 15:09:36 +04:00
|
|
|
for (nsIFrame* frame = startFrame; frame && frame != endFrame;
|
|
|
|
frame = frame->GetNextSibling()) {
|
|
|
|
if (frame == aFrame)
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
2008-01-30 02:39:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-05-31 14:21:34 +04:00
|
|
|
AdvanceLineIteratorToFrame(nsIFrame* aFrame,
|
2008-01-30 02:39:39 +03:00
|
|
|
nsBlockInFlowLineIterator* aLineIter,
|
|
|
|
nsIFrame*& aPrevFrame)
|
2006-05-31 14:21:34 +04:00
|
|
|
{
|
|
|
|
// Advance aLine to the line containing aFrame
|
|
|
|
nsIFrame* child = aFrame;
|
2008-01-30 02:39:39 +03:00
|
|
|
nsFrameManager* frameManager = aFrame->PresContext()->FrameManager();
|
|
|
|
nsIFrame* parent = nsLayoutUtils::GetParentOrPlaceholderFor(frameManager, child);
|
|
|
|
while (parent && !nsLayoutUtils::GetAsBlock(parent)) {
|
2006-05-31 14:21:34 +04:00
|
|
|
child = parent;
|
2008-01-30 02:39:39 +03:00
|
|
|
parent = nsLayoutUtils::GetParentOrPlaceholderFor(frameManager, child);
|
2006-05-31 14:21:34 +04:00
|
|
|
}
|
|
|
|
NS_ASSERTION (parent, "aFrame is not a descendent of aBlockFrame");
|
2008-01-30 02:39:39 +03:00
|
|
|
while (!IsFrameInCurrentLine(aLineIter, aPrevFrame, child)) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
PRBool hasNext =
|
|
|
|
#endif
|
|
|
|
aLineIter->Next();
|
|
|
|
NS_ASSERTION(hasNext, "Can't find frame in lines!");
|
2006-06-08 12:41:51 +04:00
|
|
|
aPrevFrame = nsnull;
|
2006-05-31 14:21:34 +04:00
|
|
|
}
|
2006-06-08 12:41:51 +04:00
|
|
|
aPrevFrame = child;
|
2006-05-31 14:21:34 +04:00
|
|
|
}
|
|
|
|
|
2003-07-24 22:33:50 +04:00
|
|
|
/*
|
|
|
|
* Overview of the implementation of Resolve():
|
|
|
|
*
|
|
|
|
* Walk through the descendants of aBlockFrame and build:
|
2009-02-03 17:42:18 +03:00
|
|
|
* * mLogicalFrames: an nsTArray of nsIFrame* pointers in logical order
|
2011-04-11 12:00:28 +04:00
|
|
|
* * mBuffer: an nsString containing a representation of
|
2003-07-24 22:33:50 +04: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 17:42:18 +03:00
|
|
|
* correlate them with the frames indexed in mLogicalFrames, setting the
|
2010-05-11 10:14:05 +04:00
|
|
|
* baseLevel and embeddingLevel properties according to the results returned
|
|
|
|
* by the Bidi engine.
|
2003-07-24 22:33:50 +04:00
|
|
|
*
|
|
|
|
* The rendering layer requires each text frame to contain text in only one
|
2010-05-11 10:14:05 +04: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.
|
2003-07-24 22:33:50 +04:00
|
|
|
*/
|
2001-03-09 04:12:39 +03:00
|
|
|
nsresult
|
2010-04-25 16:15:17 +04:00
|
|
|
nsBidiPresUtils::Resolve(nsBlockFrame* aBlockFrame)
|
2001-03-09 04:12:39 +03:00
|
|
|
{
|
2011-04-13 13:23:49 +04:00
|
|
|
BidiParagraphData bpd;
|
|
|
|
bpd.Init(aBlockFrame);
|
2011-04-11 11:59:30 +04:00
|
|
|
|
2001-06-29 07:15:58 +04:00
|
|
|
// handle bidi-override being set on the block itself before calling
|
2011-04-11 11:59:30 +04:00
|
|
|
// TraverseFrames.
|
2003-05-15 07:42:21 +04:00
|
|
|
const nsStyleTextReset* text = aBlockFrame->GetStyleTextReset();
|
2011-04-11 11:59:30 +04:00
|
|
|
PRUnichar ch = 0;
|
2001-06-29 07:15:58 +04:00
|
|
|
if (text->mUnicodeBidi == NS_STYLE_UNICODE_BIDI_OVERRIDE) {
|
2011-04-13 13:23:49 +04:00
|
|
|
const nsStyleVisibility* vis = aBlockFrame->GetStyleVisibility();
|
2001-06-29 07:15:58 +04:00
|
|
|
if (NS_STYLE_DIRECTION_RTL == vis->mDirection) {
|
2011-04-11 11:59:30 +04:00
|
|
|
ch = kRLO;
|
2001-06-29 07:15:58 +04:00
|
|
|
}
|
|
|
|
else if (NS_STYLE_DIRECTION_LTR == vis->mDirection) {
|
2011-04-11 11:59:30 +04:00
|
|
|
ch = kLRO;
|
2001-06-29 07:15:58 +04:00
|
|
|
}
|
2011-04-11 11:59:30 +04:00
|
|
|
if (ch != 0) {
|
2011-04-13 13:23:49 +04:00
|
|
|
bpd.PushBidiControl(ch);
|
2001-06-29 07:15:58 +04:00
|
|
|
}
|
|
|
|
}
|
2007-12-20 13:06:14 +03:00
|
|
|
for (nsBlockFrame* block = aBlockFrame; block;
|
|
|
|
block = static_cast<nsBlockFrame*>(block->GetNextContinuation())) {
|
|
|
|
block->RemoveStateBits(NS_BLOCK_NEEDS_BIDI_RESOLUTION);
|
2011-04-13 13:23:49 +04:00
|
|
|
TraverseFrames(aBlockFrame, block->GetFirstChild(nsnull), &bpd);
|
2007-12-20 13:06:14 +03:00
|
|
|
}
|
2005-11-04 05:38:33 +03:00
|
|
|
|
2011-04-11 11:59:30 +04:00
|
|
|
if (ch != 0) {
|
2011-04-13 13:23:49 +04:00
|
|
|
bpd.PopBidiControl();
|
2001-06-29 07:15:58 +04:00
|
|
|
}
|
2001-03-09 04:12:39 +03:00
|
|
|
|
2011-04-11 11:59:30 +04:00
|
|
|
// Resolve final paragraph
|
2011-04-13 13:23:49 +04:00
|
|
|
return ResolveParagraph(aBlockFrame, &bpd);
|
2011-04-11 11:59:30 +04:00
|
|
|
}
|
2001-03-09 04:12:39 +03:00
|
|
|
|
2011-04-13 13:23:49 +04:00
|
|
|
nsresult
|
|
|
|
nsBidiPresUtils::ResolveParagraph(nsBlockFrame* aBlockFrame,
|
|
|
|
BidiParagraphData* aBpd)
|
2011-04-11 11:59:30 +04:00
|
|
|
{
|
|
|
|
nsPresContext *presContext = aBlockFrame->PresContext();
|
2001-03-09 04:12:39 +03:00
|
|
|
|
2011-04-13 13:23:49 +04:00
|
|
|
if (aBpd->BufferLength() < 1) {
|
|
|
|
return NS_OK;
|
2001-03-09 04:12:39 +03:00
|
|
|
}
|
2011-04-13 13:23:49 +04:00
|
|
|
aBpd->mBuffer.ReplaceChar("\t\r\n", kSpace);
|
2011-04-11 11:59:30 +04:00
|
|
|
|
2001-03-09 04:12:39 +03:00
|
|
|
PRInt32 runCount;
|
2011-04-13 13:23:49 +04:00
|
|
|
PRUint8 embeddingLevel = aBpd->mParaLevel;
|
2011-03-26 01:15:29 +03:00
|
|
|
|
2011-04-13 13:23:49 +04:00
|
|
|
nsresult rv = aBpd->SetPara();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = aBpd->CountRuns(&runCount);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2001-03-09 04:12:39 +03:00
|
|
|
|
2009-07-01 11:16:26 +04:00
|
|
|
PRInt32 runLength = 0; // the length of the current run of text
|
|
|
|
PRInt32 lineOffset = 0; // the start of the current run
|
|
|
|
PRInt32 logicalLimit = 0; // the end of the current run + 1
|
|
|
|
PRInt32 numRun = -1;
|
|
|
|
PRInt32 fragmentLength = 0; // the length of the current text frame
|
|
|
|
PRInt32 frameIndex = -1; // index to the frames in mLogicalFrames
|
2011-04-13 13:23:49 +04:00
|
|
|
PRInt32 frameCount = aBpd->FrameCount();
|
2009-07-01 11:16:26 +04:00
|
|
|
PRInt32 contentOffset = 0; // offset of current frame in its content node
|
|
|
|
PRBool isTextFrame = PR_FALSE;
|
|
|
|
nsIFrame* frame = nsnull;
|
|
|
|
nsIContent* content = nsnull;
|
2011-04-13 13:23:49 +04:00
|
|
|
PRInt32 contentTextLength = 0;
|
2001-03-09 04:12:39 +03:00
|
|
|
|
2010-03-29 05:46:55 +04:00
|
|
|
FramePropertyTable *propTable = presContext->PropertyTable();
|
2011-04-13 13:23:49 +04:00
|
|
|
|
|
|
|
nsBlockInFlowLineIterator lineIter(aBlockFrame,
|
|
|
|
aBlockFrame->begin_lines(),
|
|
|
|
PR_FALSE);
|
|
|
|
if (lineIter.GetLine() == aBlockFrame->end_lines()) {
|
|
|
|
// Advance to first valid line (might be in a next-continuation)
|
|
|
|
lineIter.Next();
|
|
|
|
}
|
|
|
|
nsIFrame* prevFrame = nsnull;
|
|
|
|
|
2011-03-26 01:15:29 +03:00
|
|
|
PRBool lineNeedsUpdate = PR_FALSE;
|
2006-03-15 23:52:02 +03:00
|
|
|
|
2011-04-11 11:59:29 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
#ifdef NOISY_BIDI
|
|
|
|
printf("Before Resolve(), aBlockFrame=0x%p, mBuffer='%s', frameCount=%d\n",
|
2011-04-13 13:23:49 +04:00
|
|
|
(void*)aBlockFrame, NS_ConvertUTF16toUTF8(aBpd->mBuffer).get(), frameCount);
|
2011-04-11 11:59:29 +04:00
|
|
|
#ifdef REALLY_NOISY_BIDI
|
|
|
|
printf(" block frame tree=:\n");
|
|
|
|
aBlockFrame->List(stdout, 0);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2001-03-09 04:12:39 +03:00
|
|
|
for (; ;) {
|
|
|
|
if (fragmentLength <= 0) {
|
2009-07-01 11:16:26 +04:00
|
|
|
// Get the next frame from mLogicalFrames
|
2001-03-09 04:12:39 +03:00
|
|
|
if (++frameIndex >= frameCount) {
|
|
|
|
break;
|
|
|
|
}
|
2011-04-13 13:23:49 +04:00
|
|
|
frame = aBpd->FrameAt(frameIndex);
|
2006-05-31 14:21:34 +04:00
|
|
|
lineNeedsUpdate = PR_TRUE;
|
2011-04-11 11:59:30 +04: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)
|
|
|
|
*/
|
|
|
|
isTextFrame = PR_FALSE;
|
|
|
|
fragmentLength = 1;
|
|
|
|
}
|
|
|
|
else {
|
2003-07-02 14:30:00 +04:00
|
|
|
content = frame->GetContent();
|
|
|
|
if (!content) {
|
2011-04-13 13:23:49 +04:00
|
|
|
rv = NS_OK;
|
2001-03-09 04:12:39 +03:00
|
|
|
break;
|
|
|
|
}
|
2009-04-19 12:19:27 +04:00
|
|
|
contentTextLength = content->TextLength();
|
|
|
|
if (contentTextLength == 0) {
|
|
|
|
frame->AdjustOffsetsForBidi(0, 0);
|
2009-04-28 13:23:53 +04: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-29 05:46:55 +04:00
|
|
|
propTable->Set(frame, nsIFrame::EmbeddingLevelProperty(),
|
|
|
|
NS_INT32_TO_PTR(embeddingLevel));
|
|
|
|
propTable->Set(frame, nsIFrame::BaseLevelProperty(),
|
2011-04-13 13:23:49 +04:00
|
|
|
NS_INT32_TO_PTR(aBpd->mParaLevel));
|
2009-04-19 12:19:27 +04:00
|
|
|
continue;
|
2001-03-09 04:12:39 +03:00
|
|
|
}
|
2009-04-19 12:19:27 +04:00
|
|
|
PRInt32 start, end;
|
|
|
|
frame->GetOffsets(start, end);
|
2010-08-10 11:08:59 +04:00
|
|
|
NS_ASSERTION(!(contentTextLength < end - start),
|
|
|
|
"Frame offsets don't fit in content");
|
|
|
|
fragmentLength = NS_MIN(contentTextLength, end - start);
|
2009-04-19 12:19:27 +04:00
|
|
|
contentOffset = start;
|
2001-03-09 04:12:39 +03:00
|
|
|
isTextFrame = PR_TRUE;
|
2009-07-01 11:16:26 +04:00
|
|
|
}
|
2001-03-09 04:12:39 +03:00
|
|
|
} // if (fragmentLength <= 0)
|
2009-07-01 11:16:26 +04:00
|
|
|
|
2001-03-09 04:12:39 +03:00
|
|
|
if (runLength <= 0) {
|
2009-07-01 11:16:26 +04:00
|
|
|
// Get the next run of text from the Bidi engine
|
2001-03-09 04:12:39 +03:00
|
|
|
if (++numRun >= runCount) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
lineOffset = logicalLimit;
|
2011-04-13 13:23:49 +04:00
|
|
|
if (NS_FAILED(aBpd->GetLogicalRun(
|
2001-03-09 04:12:39 +03:00
|
|
|
lineOffset, &logicalLimit, &embeddingLevel) ) ) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
runLength = logicalLimit - lineOffset;
|
|
|
|
} // if (runLength <= 0)
|
|
|
|
|
2011-04-11 11:59:30 +04:00
|
|
|
if (frame == NS_BIDI_CONTROL_FRAME) {
|
2006-02-22 00:33:47 +03:00
|
|
|
frame = nsnull;
|
2001-03-09 04:12:39 +03:00
|
|
|
++lineOffset;
|
|
|
|
}
|
|
|
|
else {
|
2010-03-29 05:46:55 +04:00
|
|
|
propTable->Set(frame, nsIFrame::EmbeddingLevelProperty(),
|
|
|
|
NS_INT32_TO_PTR(embeddingLevel));
|
|
|
|
propTable->Set(frame, nsIFrame::BaseLevelProperty(),
|
2011-04-13 13:23:49 +04:00
|
|
|
NS_INT32_TO_PTR(aBpd->mParaLevel));
|
2001-03-09 04:12:39 +03:00
|
|
|
if (isTextFrame) {
|
|
|
|
if ( (runLength > 0) && (runLength < fragmentLength) ) {
|
2009-07-01 11:16:26 +04: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.
|
|
|
|
*/
|
2006-05-31 14:21:34 +04:00
|
|
|
if (lineNeedsUpdate) {
|
2011-04-13 13:23:49 +04:00
|
|
|
AdvanceLineIteratorToFrame(frame, &lineIter, prevFrame);
|
2008-01-30 02:39:39 +03:00
|
|
|
lineNeedsUpdate = PR_FALSE;
|
2006-05-31 14:21:34 +04:00
|
|
|
}
|
2011-04-13 13:23:49 +04:00
|
|
|
lineIter.GetLine()->MarkDirty();
|
2009-07-01 11:16:26 +04:00
|
|
|
nsIFrame* nextBidi;
|
2010-01-03 11:46:19 +03:00
|
|
|
PRInt32 runEnd = contentOffset + runLength;
|
2011-04-13 13:23:49 +04:00
|
|
|
rv = EnsureBidiContinuation(frame, &nextBidi, frameIndex,
|
|
|
|
contentOffset,
|
|
|
|
runEnd);
|
|
|
|
if (NS_FAILED(rv)) {
|
2008-03-24 10:30:49 +03:00
|
|
|
break;
|
|
|
|
}
|
2010-01-03 11:46:19 +03:00
|
|
|
nextBidi->AdjustOffsetsForBidi(runEnd,
|
|
|
|
contentOffset + fragmentLength);
|
2001-03-09 04:12:39 +03:00
|
|
|
frame = nextBidi;
|
2010-01-03 11:46:19 +03:00
|
|
|
contentOffset = runEnd;
|
2001-03-09 04:12:39 +03:00
|
|
|
} // if (runLength < fragmentLength)
|
|
|
|
else {
|
2009-04-19 12:19:27 +04:00
|
|
|
if (contentOffset + fragmentLength == contentTextLength) {
|
2009-07-01 11:16:26 +04: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
|
|
|
|
*/
|
2011-04-13 13:23:49 +04:00
|
|
|
PRInt32 newIndex = aBpd->GetLastFrameForContent(content);
|
2009-04-19 12:19:27 +04:00
|
|
|
if (newIndex > frameIndex) {
|
2011-04-13 13:23:49 +04:00
|
|
|
RemoveBidiContinuation(aBpd, frame,
|
|
|
|
frameIndex, newIndex, lineOffset);
|
2009-04-19 12:19:27 +04:00
|
|
|
frameIndex = newIndex;
|
2006-05-31 14:21:34 +04:00
|
|
|
}
|
2009-07-01 11:16:26 +04: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
|
|
|
|
*/
|
|
|
|
PRInt32 newIndex = frameIndex;
|
|
|
|
do {
|
2011-04-11 12:00:28 +04:00
|
|
|
} while (++newIndex < frameCount &&
|
2011-04-13 13:23:49 +04:00
|
|
|
aBpd->FrameAt(newIndex) == NS_BIDI_CONTROL_FRAME);
|
2011-04-11 12:00:28 +04:00
|
|
|
if (newIndex < frameCount) {
|
2011-04-13 13:23:49 +04:00
|
|
|
RemoveBidiContinuation(aBpd, frame,
|
|
|
|
frameIndex, newIndex, lineOffset);
|
2011-04-11 12:00:28 +04:00
|
|
|
}
|
|
|
|
} else if (runLength == fragmentLength &&
|
|
|
|
numRun + 1 < runCount) {
|
2009-10-08 08:53:50 +04:00
|
|
|
/*
|
2011-04-11 12:00:28 +04:00
|
|
|
* If the directional run ends at the end of the frame, and this is
|
|
|
|
* not the end of our paragraph, make sure that the next frame is a
|
|
|
|
* non-fluid continuation
|
2009-10-08 08:53:50 +04:00
|
|
|
*/
|
|
|
|
nsIFrame* next = frame->GetNextInFlow();
|
|
|
|
if (next) {
|
|
|
|
frame->SetNextContinuation(next);
|
|
|
|
next->SetPrevContinuation(frame);
|
|
|
|
}
|
2001-03-09 04:12:39 +03:00
|
|
|
}
|
2007-11-11 22:34:06 +03:00
|
|
|
frame->AdjustOffsetsForBidi(contentOffset, contentOffset + fragmentLength);
|
2009-06-08 12:59:39 +04:00
|
|
|
if (lineNeedsUpdate) {
|
2011-04-13 13:23:49 +04:00
|
|
|
AdvanceLineIteratorToFrame(frame, &lineIter, prevFrame);
|
2009-06-08 12:59:39 +04:00
|
|
|
lineNeedsUpdate = PR_FALSE;
|
|
|
|
}
|
2011-04-13 13:23:49 +04:00
|
|
|
lineIter.GetLine()->MarkDirty();
|
2001-03-09 04:12:39 +03:00
|
|
|
}
|
|
|
|
} // isTextFrame
|
|
|
|
else {
|
|
|
|
++lineOffset;
|
|
|
|
}
|
2011-04-11 11:59:30 +04:00
|
|
|
} // not bidi control frame
|
2009-07-01 11:16:26 +04:00
|
|
|
PRInt32 temp = runLength;
|
2001-03-09 04:12:39 +03:00
|
|
|
runLength -= fragmentLength;
|
|
|
|
fragmentLength -= temp;
|
2006-02-22 00:33:47 +03:00
|
|
|
|
2008-03-21 11:17:41 +03:00
|
|
|
if (frame && fragmentLength <= 0) {
|
2011-04-11 11:59:30 +04: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-21 09:33:34 +04: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-04-11 11:59:30 +04:00
|
|
|
if (numRun + 1 < runCount && runLength <= 0 && !frame->GetNextInFlow()) {
|
2008-03-21 11:17:41 +03:00
|
|
|
nsIFrame* child = frame;
|
|
|
|
nsIFrame* parent = frame->GetParent();
|
|
|
|
// As long as we're on the last sibling, the parent doesn't have to be split.
|
2010-06-14 07:16:55 +04:00
|
|
|
// 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.
|
2008-03-21 11:17:41 +03:00
|
|
|
while (parent &&
|
|
|
|
IsBidiSplittable(parent) &&
|
|
|
|
!child->GetNextSibling()) {
|
2010-06-14 07:16:55 +04:00
|
|
|
nsIFrame* next = parent->GetNextInFlow();
|
|
|
|
if (next) {
|
|
|
|
parent->SetNextContinuation(next);
|
|
|
|
next->SetPrevContinuation(parent);
|
|
|
|
}
|
2008-03-21 11:17:41 +03:00
|
|
|
child = parent;
|
|
|
|
parent = child->GetParent();
|
|
|
|
}
|
|
|
|
if (parent && IsBidiSplittable(parent))
|
|
|
|
SplitInlineAncestors(child);
|
|
|
|
}
|
2011-04-11 12:00:28 +04: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);
|
2006-02-22 00:33:47 +03:00
|
|
|
}
|
|
|
|
}
|
2001-03-09 04:12:39 +03:00
|
|
|
} // for
|
2011-04-11 11:59:29 +04:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
#ifdef REALLY_NOISY_BIDI
|
|
|
|
printf("---\nAfter Resolve(), frameTree =:\n");
|
|
|
|
aBlockFrame->List(stdout, 0);
|
|
|
|
printf("===\n");
|
|
|
|
#endif
|
|
|
|
#endif
|
2011-04-13 13:23:49 +04:00
|
|
|
|
|
|
|
return rv;
|
2001-03-09 04:12:39 +03:00
|
|
|
}
|
|
|
|
|
2009-02-03 17:42:18 +03:00
|
|
|
// Should this frame be treated as a leaf (e.g. when building mLogicalFrames)?
|
2006-02-22 00:33:47 +03:00
|
|
|
PRBool IsBidiLeaf(nsIFrame* aFrame) {
|
|
|
|
nsIFrame* kid = aFrame->GetFirstChild(nsnull);
|
|
|
|
return !kid
|
2007-08-29 12:21:38 +04:00
|
|
|
|| !aFrame->IsFrameOfType(nsIFrame::eBidiInlineContainer);
|
2006-02-22 00:33:47 +03:00
|
|
|
}
|
|
|
|
|
2007-08-29 13:19:16 +04:00
|
|
|
void
|
2011-04-11 11:59:30 +04:00
|
|
|
nsBidiPresUtils::TraverseFrames(nsBlockFrame* aBlockFrame,
|
2011-04-13 13:23:49 +04:00
|
|
|
nsIFrame* aCurrentFrame,
|
|
|
|
BidiParagraphData* aBpd)
|
2001-03-09 04:12:39 +03:00
|
|
|
{
|
2007-12-20 13:06:14 +03:00
|
|
|
if (!aCurrentFrame)
|
|
|
|
return;
|
|
|
|
|
2011-04-11 11:59:30 +04: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();
|
|
|
|
PRBool isLastFrame = !childFrame->GetNextContinuation();
|
2007-08-29 12:21:38 +04:00
|
|
|
|
2010-09-06 18:33:18 +04: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 18:30:38 +04:00
|
|
|
nsIFrame* frame = childFrame;
|
|
|
|
if (nsGkAtoms::placeholderFrame == childFrame->GetType()) {
|
|
|
|
nsIFrame* realFrame =
|
|
|
|
nsPlaceholderFrame::GetRealFrameForPlaceholder(childFrame);
|
2010-09-06 18:33:18 +04:00
|
|
|
if (realFrame->GetType() == nsGkAtoms::letterFrame) {
|
2007-09-03 18:30:38 +04:00
|
|
|
frame = realFrame;
|
|
|
|
}
|
|
|
|
}
|
2006-03-27 01:30:36 +04:00
|
|
|
|
2007-05-06 14:29:58 +04:00
|
|
|
PRUnichar ch = 0;
|
2007-08-29 13:19:16 +04:00
|
|
|
if (frame->IsFrameOfType(nsIFrame::eBidiInlineContainer)) {
|
2003-05-15 07:42:21 +04:00
|
|
|
const nsStyleVisibility* vis = frame->GetStyleVisibility();
|
|
|
|
const nsStyleTextReset* text = frame->GetStyleTextReset();
|
2001-06-29 07:15:58 +04:00
|
|
|
switch (text->mUnicodeBidi) {
|
|
|
|
case NS_STYLE_UNICODE_BIDI_NORMAL:
|
|
|
|
break;
|
|
|
|
case NS_STYLE_UNICODE_BIDI_EMBED:
|
|
|
|
if (NS_STYLE_DIRECTION_RTL == vis->mDirection) {
|
2007-05-06 14:29:58 +04:00
|
|
|
ch = kRLE;
|
2001-06-29 07:15:58 +04:00
|
|
|
}
|
|
|
|
else if (NS_STYLE_DIRECTION_LTR == vis->mDirection) {
|
2007-05-06 14:29:58 +04:00
|
|
|
ch = kLRE;
|
2001-06-29 07:15:58 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NS_STYLE_UNICODE_BIDI_OVERRIDE:
|
|
|
|
if (NS_STYLE_DIRECTION_RTL == vis->mDirection) {
|
2007-05-06 14:29:58 +04:00
|
|
|
ch = kRLO;
|
2001-06-29 07:15:58 +04:00
|
|
|
}
|
|
|
|
else if (NS_STYLE_DIRECTION_LTR == vis->mDirection) {
|
2007-05-06 14:29:58 +04:00
|
|
|
ch = kLRO;
|
2001-06-29 07:15:58 +04:00
|
|
|
}
|
|
|
|
break;
|
2001-03-09 04:12:39 +03:00
|
|
|
}
|
2005-11-04 05:38:33 +03:00
|
|
|
|
2011-04-11 11:59:30 +04:00
|
|
|
// Add a dummy frame pointer representing a bidi control code before the
|
|
|
|
// first frame of an element specifying embedding or override
|
2007-05-06 14:29:58 +04:00
|
|
|
if (ch != 0 && !frame->GetPrevContinuation()) {
|
2011-04-13 13:23:49 +04:00
|
|
|
aBpd->PushBidiControl(ch);
|
2001-06-29 07:15:58 +04:00
|
|
|
}
|
|
|
|
}
|
2001-03-09 04:12:39 +03:00
|
|
|
|
2006-02-22 00:33:47 +03:00
|
|
|
if (IsBidiLeaf(frame)) {
|
2003-07-24 22:33:50 +04:00
|
|
|
/* 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 13:23:49 +04:00
|
|
|
aBpd->AppendFrame(frame, content);
|
2011-04-11 11:59:30 +04:00
|
|
|
|
|
|
|
// Append the content of the frame to the paragraph buffer
|
|
|
|
nsIAtom* frameType = frame->GetType();
|
|
|
|
if (nsGkAtoms::textFrame == frameType) {
|
2011-04-13 13:23:49 +04:00
|
|
|
if (content != aBpd->mPrevContent) {
|
|
|
|
aBpd->mPrevContent = content;
|
2011-04-11 12:00:28 +04:00
|
|
|
if (!frame->GetStyleContext()->GetStyleText()->NewlineIsSignificant()) {
|
2011-04-13 13:23:49 +04:00
|
|
|
content->AppendTextTo(aBpd->mBuffer);
|
2011-04-11 12:00:28 +04:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* For preformatted text we have to do bidi resolution on each line
|
|
|
|
* separately.
|
|
|
|
*/
|
|
|
|
nsAutoString text;
|
|
|
|
content->AppendTextTo(text);
|
|
|
|
nsIFrame* next;
|
|
|
|
do {
|
|
|
|
next = nsnull;
|
|
|
|
|
|
|
|
PRInt32 start, end;
|
|
|
|
frame->GetOffsets(start, end);
|
|
|
|
PRInt32 endLine = text.FindCharInSet(NS_LITERAL_STRING("\n\r"),
|
|
|
|
start);
|
|
|
|
if (endLine == -1) {
|
|
|
|
/*
|
|
|
|
* If there is no newline in the frame, just save the text and
|
|
|
|
* do bidi resolution later
|
|
|
|
*/
|
2011-04-13 13:23:49 +04:00
|
|
|
aBpd->AppendString(Substring(text, start));
|
2011-04-11 12:00:28 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If there is a newline in the frame, break the frame after the
|
|
|
|
* newline, do bidi resolution and repeat until the end of the
|
|
|
|
* element.
|
|
|
|
*/
|
|
|
|
++endLine;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the frame ends before the new line, save the text and move
|
|
|
|
* into the next continuation
|
|
|
|
*/
|
|
|
|
while (end < endLine) {
|
2011-04-13 13:23:49 +04:00
|
|
|
aBpd->AppendString(Substring(text, start, end - start));
|
2011-04-11 12:00:28 +04:00
|
|
|
frame = frame->GetNextContinuation();
|
|
|
|
NS_ASSERTION(frame, "Premature end of continuation chain");
|
|
|
|
frame->GetOffsets(start, end);
|
2011-04-13 13:23:49 +04:00
|
|
|
aBpd->AppendFrame(frame);
|
2011-04-11 12:00:28 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If we have already overshot the saved next-sibling while
|
|
|
|
* scanning the frame's continuations, advance it.
|
|
|
|
*/
|
|
|
|
if (frame == nextSibling) {
|
|
|
|
nextSibling = frame->GetNextSibling();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-13 13:23:49 +04:00
|
|
|
aBpd->AppendString(Substring(text, start, endLine - start));
|
2011-04-11 12:00:28 +04:00
|
|
|
|
|
|
|
if (PRUint32(endLine) < text.Length()) {
|
|
|
|
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);
|
|
|
|
} else {
|
|
|
|
// If the frame has no next in flow, create one
|
|
|
|
CreateContinuation(frame, &next, PR_TRUE);
|
|
|
|
}
|
|
|
|
}
|
2011-04-11 12:00:33 +04:00
|
|
|
nsTextFrame* textFrame = static_cast<nsTextFrame*>(frame);
|
|
|
|
textFrame->SetLength(endLine - start, nsnull);
|
2011-04-11 12:00:28 +04:00
|
|
|
}
|
2011-04-13 13:23:49 +04:00
|
|
|
ResolveParagraphWithinBlock(aBlockFrame, aBpd);
|
2011-04-11 12:00:28 +04:00
|
|
|
|
|
|
|
if (next) {
|
|
|
|
frame = next;
|
2011-04-13 13:23:49 +04:00
|
|
|
aBpd->AppendFrame(frame);
|
2011-04-11 12:00:28 +04: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 11:59:30 +04:00
|
|
|
}
|
|
|
|
} else if (nsGkAtoms::brFrame == frameType) {
|
|
|
|
// break frame -- append line separator
|
2011-04-13 13:23:49 +04:00
|
|
|
aBpd->AppendUnichar(kLineSeparator);
|
|
|
|
ResolveParagraphWithinBlock(aBlockFrame, aBpd);
|
2011-04-11 11:59:30 +04:00
|
|
|
} else {
|
|
|
|
// other frame type -- see the Unicode Bidi Algorithm:
|
|
|
|
// "...inline objects (such as graphics) are treated as if they are ...
|
|
|
|
// U+FFFC"
|
2011-04-13 13:23:49 +04:00
|
|
|
aBpd->AppendUnichar(kObjectSubstitute);
|
2011-04-11 11:59:30 +04:00
|
|
|
if (!frame->GetStyleContext()->GetStyleDisplay()->IsInlineOutside()) {
|
|
|
|
// if it is not inline, end the paragraph
|
2011-04-13 13:23:49 +04:00
|
|
|
ResolveParagraphWithinBlock(aBlockFrame, aBpd);
|
2011-04-11 11:59:30 +04:00
|
|
|
}
|
2011-04-11 11:59:30 +04:00
|
|
|
}
|
2001-03-09 04:12:39 +03:00
|
|
|
}
|
2006-02-22 00:33:47 +03:00
|
|
|
else {
|
2011-04-11 11:59:30 +04:00
|
|
|
// For a non-leaf frame, recurse into TraverseFrames
|
2006-02-22 00:33:47 +03:00
|
|
|
nsIFrame* kid = frame->GetFirstChild(nsnull);
|
2011-04-13 13:23:49 +04:00
|
|
|
TraverseFrames(aBlockFrame, kid, aBpd);
|
2006-02-22 00:33:47 +03:00
|
|
|
}
|
2001-03-09 04:12:39 +03:00
|
|
|
|
|
|
|
// If the element is attributed by dir, indicate direction pop (add PDF frame)
|
2011-04-11 11:59:30 +04:00
|
|
|
if (ch != 0 && isLastFrame) {
|
2011-04-11 11:59:30 +04:00
|
|
|
// Add a dummy frame pointer representing a bidi control code after the
|
|
|
|
// last frame of an element specifying embedding or override
|
2011-04-13 13:23:49 +04:00
|
|
|
aBpd->PopBidiControl();
|
2001-03-09 04:12:39 +03:00
|
|
|
}
|
2011-04-11 11:59:30 +04:00
|
|
|
childFrame = nextSibling;
|
|
|
|
} while (childFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-04-13 13:23:49 +04:00
|
|
|
nsBidiPresUtils::ResolveParagraphWithinBlock(nsBlockFrame* aBlockFrame,
|
|
|
|
BidiParagraphData* aBpd)
|
2011-04-11 11:59:30 +04:00
|
|
|
{
|
2011-04-13 13:23:49 +04:00
|
|
|
aBpd->ClearBidiControls();
|
2011-04-11 11:59:30 +04:00
|
|
|
|
2011-04-13 13:23:49 +04:00
|
|
|
ResolveParagraph(aBlockFrame, aBpd);
|
2011-04-11 11:59:30 +04:00
|
|
|
|
|
|
|
// Clear the frame array and paragraph buffer, and restore the stored
|
|
|
|
// embeddings and overrides
|
2011-04-13 13:23:49 +04:00
|
|
|
aBpd->ResetData();
|
2011-03-24 12:28:44 +03:00
|
|
|
}
|
|
|
|
|
2001-03-09 04:12:39 +03:00
|
|
|
void
|
2007-08-29 13:19:16 +04:00
|
|
|
nsBidiPresUtils::ReorderFrames(nsIFrame* aFirstFrameOnLine,
|
2006-03-12 12:49:48 +03:00
|
|
|
PRInt32 aNumFramesOnLine)
|
2001-03-09 04:12:39 +03:00
|
|
|
{
|
2007-01-13 21:20:28 +03:00
|
|
|
// If this line consists of a line frame, reorder the line frame's children.
|
|
|
|
if (aFirstFrameOnLine->GetType() == nsGkAtoms::lineFrame) {
|
|
|
|
aFirstFrameOnLine = aFirstFrameOnLine->GetFirstChild(nsnull);
|
2007-01-16 10:09:49 +03:00
|
|
|
if (!aFirstFrameOnLine)
|
|
|
|
return;
|
2007-01-13 21:20:28 +03:00
|
|
|
// 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-13 13:23:49 +04:00
|
|
|
BidiLineData bld(aFirstFrameOnLine, aNumFramesOnLine);
|
|
|
|
RepositionInlineFrames(&bld, aFirstFrameOnLine);
|
2001-03-09 04:12:39 +03:00
|
|
|
}
|
|
|
|
|
2006-03-12 12:49:48 +03:00
|
|
|
nsBidiLevel
|
|
|
|
nsBidiPresUtils::GetFrameEmbeddingLevel(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
nsIFrame* firstLeaf = aFrame;
|
|
|
|
while (!IsBidiLeaf(firstLeaf)) {
|
2010-09-06 18:33:18 +04:00
|
|
|
nsIFrame* firstChild = firstLeaf->GetFirstChild(nsnull);
|
|
|
|
nsIFrame* realFrame = nsPlaceholderFrame::GetRealFrameFor(firstChild);
|
|
|
|
firstLeaf = (realFrame->GetType() == nsGkAtoms::letterFrame) ?
|
|
|
|
realFrame : firstChild;
|
2006-03-12 12:49:48 +03:00
|
|
|
}
|
|
|
|
return NS_GET_EMBEDDING_LEVEL(firstLeaf);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsBidiLevel
|
|
|
|
nsBidiPresUtils::GetFrameBaseLevel(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
nsIFrame* firstLeaf = aFrame;
|
|
|
|
while (!IsBidiLeaf(firstLeaf)) {
|
|
|
|
firstLeaf = firstLeaf->GetFirstChild(nsnull);
|
|
|
|
}
|
|
|
|
return NS_GET_BASE_LEVEL(firstLeaf);
|
|
|
|
}
|
|
|
|
|
2006-06-15 12:16:23 +04:00
|
|
|
void
|
|
|
|
nsBidiPresUtils::IsLeftOrRightMost(nsIFrame* aFrame,
|
|
|
|
nsContinuationStates* aContinuationStates,
|
|
|
|
PRBool& aIsLeftMost /* out */,
|
2011-04-13 13:23:49 +04:00
|
|
|
PRBool& aIsRightMost /* out */)
|
2006-06-15 12:16:23 +04:00
|
|
|
{
|
|
|
|
const nsStyleVisibility* vis = aFrame->GetStyleVisibility();
|
|
|
|
PRBool isLTR = (NS_STYLE_DIRECTION_LTR == vis->mDirection);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Since we lay out frames from left to right (in both LTR and RTL), visiting a
|
|
|
|
* frame with 'mFirstVisualFrame == nsnull', means it's the first appearance of
|
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
frameState->mHasContOnPrevLines = (frame != nsnull);
|
|
|
|
|
|
|
|
// Traverse continuation chain forward
|
|
|
|
for (frame = aFrame->GetNextContinuation();
|
|
|
|
frame && (contState = aContinuationStates->GetEntry(frame));
|
|
|
|
frame = frame->GetNextContinuation()) {
|
|
|
|
frameState->mFrameCount++;
|
|
|
|
contState->mFirstVisualFrame = aFrame;
|
|
|
|
}
|
|
|
|
frameState->mHasContOnNextLines = (frame != nsnull);
|
|
|
|
|
|
|
|
aIsLeftMost = isLTR ? !frameState->mHasContOnPrevLines
|
|
|
|
: !frameState->mHasContOnNextLines;
|
|
|
|
firstFrameState = frameState;
|
|
|
|
} else {
|
|
|
|
// aFrame is not the first visual frame of its continuation chain
|
|
|
|
aIsLeftMost = PR_FALSE;
|
|
|
|
firstFrameState = aContinuationStates->GetEntry(frameState->mFirstVisualFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
aIsRightMost = (firstFrameState->mFrameCount == 1) &&
|
|
|
|
(isLTR ? !firstFrameState->mHasContOnNextLines
|
|
|
|
: !firstFrameState->mHasContOnPrevLines);
|
|
|
|
|
2009-05-12 06:04:58 +04:00
|
|
|
if ((aIsLeftMost || aIsRightMost) &&
|
|
|
|
(aFrame->GetStateBits() & NS_FRAME_IS_SPECIAL)) {
|
2009-09-18 22:00:21 +04: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-12 06:04:58 +04:00
|
|
|
// We are not endmost
|
|
|
|
if (isLTR) {
|
|
|
|
aIsRightMost = PR_FALSE;
|
|
|
|
} else {
|
|
|
|
aIsLeftMost = PR_FALSE;
|
|
|
|
}
|
2009-09-18 22:00:21 +04:00
|
|
|
}
|
|
|
|
if (nsLayoutUtils::FrameIsNonFirstInIBSplit(firstContinuation)) {
|
2009-05-12 06:04:58 +04:00
|
|
|
// We are not startmost
|
|
|
|
if (isLTR) {
|
|
|
|
aIsLeftMost = PR_FALSE;
|
|
|
|
} else {
|
|
|
|
aIsRightMost = PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-06-15 12:16:23 +04:00
|
|
|
// Reduce number of remaining frames of the continuation chain on the line.
|
|
|
|
firstFrameState->mFrameCount--;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsBidiPresUtils::RepositionFrame(nsIFrame* aFrame,
|
|
|
|
PRBool aIsOddLevel,
|
|
|
|
nscoord& aLeft,
|
2011-04-13 13:23:49 +04:00
|
|
|
nsContinuationStates* aContinuationStates)
|
2001-03-09 04:12:39 +03:00
|
|
|
{
|
2006-06-15 12:16:23 +04:00
|
|
|
if (!aFrame)
|
2001-03-09 04:12:39 +03:00
|
|
|
return;
|
2006-06-15 12:16:23 +04:00
|
|
|
|
|
|
|
PRBool isLeftMost, isRightMost;
|
|
|
|
IsLeftOrRightMost(aFrame,
|
|
|
|
aContinuationStates,
|
|
|
|
isLeftMost /* out */,
|
|
|
|
isRightMost /* out */);
|
|
|
|
|
2009-01-12 22:20:59 +03:00
|
|
|
nsInlineFrame* testFrame = do_QueryFrame(aFrame);
|
2006-06-15 12:16:23 +04: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-27 09:54:08 +03: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();
|
2006-06-15 12:16:23 +04:00
|
|
|
if (isLeftMost)
|
|
|
|
aLeft += margin.left;
|
|
|
|
|
|
|
|
nscoord start = aLeft;
|
|
|
|
|
|
|
|
if (!IsBidiLeaf(aFrame))
|
|
|
|
{
|
|
|
|
nscoord x = 0;
|
2008-01-27 09:54:08 +03:00
|
|
|
nsMargin borderPadding = aFrame->GetUsedBorderAndPadding();
|
2006-06-15 12:16:23 +04: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 17:42:18 +03:00
|
|
|
nsTArray<nsIFrame*> childList;
|
2006-06-15 12:16:23 +04:00
|
|
|
nsIFrame *frame = aFrame->GetFirstChild(nsnull);
|
|
|
|
if (frame && aIsOddLevel) {
|
2009-02-03 17:42:18 +03:00
|
|
|
childList.AppendElement((nsIFrame*)nsnull);
|
2006-06-15 12:16:23 +04:00
|
|
|
while (frame) {
|
|
|
|
childList.AppendElement(frame);
|
|
|
|
frame = frame->GetNextSibling();
|
|
|
|
}
|
2009-02-03 17:42:18 +03:00
|
|
|
frame = childList[childList.Length() - 1];
|
2006-06-15 12:16:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Reposition the child frames
|
|
|
|
PRInt32 index = 0;
|
|
|
|
while (frame) {
|
|
|
|
RepositionFrame(frame,
|
|
|
|
aIsOddLevel,
|
|
|
|
x,
|
|
|
|
aContinuationStates);
|
|
|
|
index++;
|
|
|
|
frame = aIsOddLevel ?
|
2009-02-03 17:42:18 +03:00
|
|
|
childList[childList.Length() - index - 1] :
|
2006-06-15 12:16:23 +04: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 13:23:49 +04:00
|
|
|
nsContinuationStates* aContinuationStates)
|
2006-06-15 12:16:23 +04:00
|
|
|
{
|
|
|
|
nsFrameContinuationState* state = aContinuationStates->PutEntry(aFrame);
|
|
|
|
state->mFirstVisualFrame = nsnull;
|
|
|
|
state->mFrameCount = 0;
|
|
|
|
|
2006-08-17 11:50:35 +04:00
|
|
|
if (!IsBidiLeaf(aFrame)) {
|
|
|
|
// Continue for child frames
|
|
|
|
nsIFrame* frame;
|
|
|
|
for (frame = aFrame->GetFirstChild(nsnull);
|
|
|
|
frame;
|
|
|
|
frame = frame->GetNextSibling()) {
|
|
|
|
InitContinuationStates(frame,
|
|
|
|
aContinuationStates);
|
|
|
|
}
|
2006-02-22 00:33:47 +03:00
|
|
|
}
|
2001-03-09 04:12:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-04-13 13:23:49 +04:00
|
|
|
nsBidiPresUtils::RepositionInlineFrames(BidiLineData *aBld,
|
|
|
|
nsIFrame* aFirstChild)
|
2001-03-09 04:12:39 +03:00
|
|
|
{
|
2006-06-15 12:16:23 +04:00
|
|
|
const nsStyleVisibility* vis = aFirstChild->GetStyleVisibility();
|
|
|
|
PRBool isLTR = (NS_STYLE_DIRECTION_LTR == vis->mDirection);
|
|
|
|
nscoord leftSpace = 0;
|
|
|
|
|
2008-01-27 09:54:08 +03: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-12 06:04:58 +04:00
|
|
|
if (!aFirstChild->GetPrevContinuation() &&
|
2009-09-18 22:00:21 +04:00
|
|
|
!nsLayoutUtils::FrameIsNonFirstInIBSplit(aFirstChild))
|
2006-06-15 12:16:23 +04:00
|
|
|
leftSpace = isLTR ? margin.left : margin.right;
|
|
|
|
|
|
|
|
nscoord left = aFirstChild->GetPosition().x - leftSpace;
|
2001-03-09 04:12:39 +03:00
|
|
|
nsIFrame* frame;
|
2011-04-13 13:23:49 +04:00
|
|
|
PRInt32 count = aBld->mVisualFrames.Length();
|
2006-06-15 12:16:23 +04:00
|
|
|
PRInt32 index;
|
|
|
|
nsContinuationStates continuationStates;
|
|
|
|
|
|
|
|
continuationStates.Init();
|
|
|
|
|
|
|
|
// Initialize continuation states to (nsnull, 0) for
|
|
|
|
// each frame on the line.
|
|
|
|
for (index = 0; index < count; index++) {
|
2011-04-13 13:23:49 +04:00
|
|
|
InitContinuationStates(aBld->VisualFrameAt(index), &continuationStates);
|
2006-06-15 12:16:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Reposition frames in visual order
|
|
|
|
for (index = 0; index < count; index++) {
|
2011-04-13 13:23:49 +04:00
|
|
|
frame = aBld->VisualFrameAt(index);
|
2006-06-15 12:16:23 +04:00
|
|
|
RepositionFrame(frame,
|
2011-04-13 13:23:49 +04:00
|
|
|
(aBld->mLevels[aBld->mIndexMap[index]] & 1),
|
2006-06-15 12:16:23 +04:00
|
|
|
left,
|
|
|
|
&continuationStates);
|
2006-02-22 00:33:47 +03:00
|
|
|
} // for
|
2001-03-09 04:12:39 +03:00
|
|
|
}
|
|
|
|
|
2006-03-12 12:49:48 +03:00
|
|
|
PRBool
|
|
|
|
nsBidiPresUtils::CheckLineOrder(nsIFrame* aFirstFrameOnLine,
|
|
|
|
PRInt32 aNumFramesOnLine,
|
|
|
|
nsIFrame** aFirstVisual,
|
|
|
|
nsIFrame** aLastVisual)
|
|
|
|
{
|
2011-04-13 13:23:49 +04:00
|
|
|
BidiLineData bld(aFirstFrameOnLine, aNumFramesOnLine);
|
|
|
|
PRInt32 count = bld.FrameCount();
|
2006-03-12 12:49:48 +03:00
|
|
|
|
|
|
|
if (aFirstVisual) {
|
2011-04-13 13:23:49 +04:00
|
|
|
*aFirstVisual = bld.VisualFrameAt(0);
|
2006-03-12 12:49:48 +03:00
|
|
|
}
|
|
|
|
if (aLastVisual) {
|
2011-04-13 13:23:49 +04:00
|
|
|
*aLastVisual = bld.VisualFrameAt(count-1);
|
2006-03-12 12:49:48 +03:00
|
|
|
}
|
|
|
|
|
2011-04-13 13:23:49 +04:00
|
|
|
return bld.mIsReordered;
|
2006-03-12 12:49:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame*
|
|
|
|
nsBidiPresUtils::GetFrameToRightOf(const nsIFrame* aFrame,
|
|
|
|
nsIFrame* aFirstFrameOnLine,
|
|
|
|
PRInt32 aNumFramesOnLine)
|
|
|
|
{
|
2011-04-13 13:23:49 +04:00
|
|
|
BidiLineData bld(aFirstFrameOnLine, aNumFramesOnLine);
|
|
|
|
|
|
|
|
PRInt32 count = bld.mVisualFrames.Length();
|
2006-03-12 12:49:48 +03:00
|
|
|
|
|
|
|
if (aFrame == nsnull)
|
2011-04-13 13:23:49 +04:00
|
|
|
return bld.VisualFrameAt(0);
|
2006-03-12 12:49:48 +03:00
|
|
|
|
|
|
|
for (PRInt32 i = 0; i < count - 1; i++) {
|
2011-04-13 13:23:49 +04:00
|
|
|
if (bld.VisualFrameAt(i) == aFrame) {
|
|
|
|
return bld.VisualFrameAt(i+1);
|
2006-03-12 12:49:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame*
|
|
|
|
nsBidiPresUtils::GetFrameToLeftOf(const nsIFrame* aFrame,
|
|
|
|
nsIFrame* aFirstFrameOnLine,
|
|
|
|
PRInt32 aNumFramesOnLine)
|
|
|
|
{
|
2011-04-13 13:23:49 +04:00
|
|
|
BidiLineData bld(aFirstFrameOnLine, aNumFramesOnLine);
|
|
|
|
|
|
|
|
PRInt32 count = bld.mVisualFrames.Length();
|
2006-03-12 12:49:48 +03:00
|
|
|
|
|
|
|
if (aFrame == nsnull)
|
2011-04-13 13:23:49 +04:00
|
|
|
return bld.VisualFrameAt(count-1);
|
2006-03-12 12:49:48 +03:00
|
|
|
|
|
|
|
for (PRInt32 i = 1; i < count; i++) {
|
2011-04-13 13:23:49 +04:00
|
|
|
if (bld.VisualFrameAt(i) == aFrame) {
|
|
|
|
return bld.VisualFrameAt(i-1);
|
2006-03-12 12:49:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
2011-04-13 13:23:49 +04:00
|
|
|
inline nsresult
|
2007-08-29 13:19:16 +04:00
|
|
|
nsBidiPresUtils::EnsureBidiContinuation(nsIFrame* aFrame,
|
2001-03-09 04:12:39 +03:00
|
|
|
nsIFrame** aNewFrame,
|
2008-01-30 07:13:06 +03:00
|
|
|
PRInt32& aFrameIndex,
|
|
|
|
PRInt32 aStart,
|
2009-04-19 12:19:27 +04:00
|
|
|
PRInt32 aEnd)
|
2001-03-09 04:12:39 +03:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aNewFrame, "null OUT ptr");
|
2006-03-13 01:09:28 +03:00
|
|
|
NS_PRECONDITION(aFrame, "aFrame is null");
|
2001-03-09 04:12:39 +03:00
|
|
|
|
2008-01-30 07:13:06 +03:00
|
|
|
aFrame->AdjustOffsetsForBidi(aStart, aEnd);
|
2011-04-13 13:23:49 +04:00
|
|
|
return CreateContinuation(aFrame, aNewFrame, PR_FALSE);
|
2001-03-09 04:12:39 +03:00
|
|
|
}
|
|
|
|
|
2003-07-24 22:33:50 +04:00
|
|
|
void
|
2011-04-13 13:23:49 +04:00
|
|
|
nsBidiPresUtils::RemoveBidiContinuation(BidiParagraphData *aBpd,
|
|
|
|
nsIFrame* aFrame,
|
2003-07-24 22:33:50 +04:00
|
|
|
PRInt32 aFirstIndex,
|
|
|
|
PRInt32 aLastIndex,
|
2011-04-13 13:23:49 +04:00
|
|
|
PRInt32& aOffset)
|
2001-03-09 04:12:39 +03:00
|
|
|
{
|
2010-03-29 05:46:55 +04:00
|
|
|
FrameProperties props = aFrame->Properties();
|
|
|
|
nsBidiLevel embeddingLevel =
|
2010-05-11 10:14:05 +04:00
|
|
|
(nsBidiLevel)NS_PTR_TO_INT32(props.Get(nsIFrame::EmbeddingLevelProperty()));
|
2010-03-29 05:46:55 +04:00
|
|
|
nsBidiLevel baseLevel =
|
2010-05-11 10:14:05 +04:00
|
|
|
(nsBidiLevel)NS_PTR_TO_INT32(props.Get(nsIFrame::BaseLevelProperty()));
|
2010-03-29 05:46:55 +04:00
|
|
|
|
2006-03-08 12:02:42 +03:00
|
|
|
for (PRInt32 index = aFirstIndex + 1; index <= aLastIndex; index++) {
|
2011-04-13 13:23:49 +04:00
|
|
|
nsIFrame* frame = aBpd->FrameAt(index);
|
2011-04-11 11:59:30 +04:00
|
|
|
if (frame == NS_BIDI_CONTROL_FRAME) {
|
2001-03-09 04:12:39 +03:00
|
|
|
++aOffset;
|
|
|
|
}
|
|
|
|
else {
|
2006-03-08 12:02:42 +03:00
|
|
|
// Make the frame and its continuation ancestors fluid,
|
|
|
|
// so they can be reused or deleted by normal reflow code
|
2010-03-29 05:46:55 +04:00
|
|
|
FrameProperties frameProps = frame->Properties();
|
|
|
|
frameProps.Set(nsIFrame::EmbeddingLevelProperty(),
|
|
|
|
NS_INT32_TO_PTR(embeddingLevel));
|
|
|
|
frameProps.Set(nsIFrame::BaseLevelProperty(),
|
|
|
|
NS_INT32_TO_PTR(baseLevel));
|
2006-04-10 21:05:01 +04:00
|
|
|
frame->AddStateBits(NS_FRAME_IS_BIDI);
|
2006-03-08 12:02:42 +03:00
|
|
|
while (frame) {
|
|
|
|
nsIFrame* prev = frame->GetPrevContinuation();
|
|
|
|
if (prev) {
|
2011-04-11 12:00:28 +04:00
|
|
|
MakeContinuationFluid(prev, frame);
|
2006-03-08 12:02:42 +03:00
|
|
|
frame = frame->GetParent();
|
|
|
|
} else {
|
|
|
|
break;
|
2002-04-23 02:55:19 +04:00
|
|
|
}
|
|
|
|
}
|
2001-03-09 04:12:39 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2004-08-01 03:15:21 +04:00
|
|
|
nsBidiPresUtils::FormatUnicodeText(nsPresContext* aPresContext,
|
2001-03-09 04:12:39 +03:00
|
|
|
PRUnichar* aText,
|
|
|
|
PRInt32& aTextLength,
|
|
|
|
nsCharType aCharType,
|
2008-08-11 19:19:01 +04:00
|
|
|
PRBool aIsOddLevel)
|
2001-03-09 04:12:39 +03:00
|
|
|
{
|
2002-06-12 01:00:20 +04:00
|
|
|
NS_ASSERTION(aIsOddLevel == 0 || aIsOddLevel == 1, "aIsOddLevel should be 0 or 1");
|
2001-10-01 07:43:42 +04:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
// ahmed
|
|
|
|
//adjusted for correct numeral shaping
|
2004-07-29 23:41:39 +04:00
|
|
|
PRUint32 bidiOptions = aPresContext->GetBidi();
|
2001-04-12 03:32:21 +04:00
|
|
|
switch (GET_BIDI_OPTION_NUMERAL(bidiOptions)) {
|
2001-03-09 04:12:39 +03:00
|
|
|
|
|
|
|
case IBMBIDI_NUMERAL_HINDI:
|
2002-02-19 23:41:32 +03:00
|
|
|
HandleNumbers(aText,aTextLength,IBMBIDI_NUMERAL_HINDI);
|
2001-03-09 04:12:39 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case IBMBIDI_NUMERAL_ARABIC:
|
2002-02-19 23:41:32 +03:00
|
|
|
HandleNumbers(aText,aTextLength,IBMBIDI_NUMERAL_ARABIC);
|
2001-03-09 04:12:39 +03:00
|
|
|
break;
|
|
|
|
|
2009-01-30 11:13:17 +03:00
|
|
|
case IBMBIDI_NUMERAL_PERSIAN:
|
|
|
|
HandleNumbers(aText,aTextLength,IBMBIDI_NUMERAL_PERSIAN);
|
|
|
|
break;
|
|
|
|
|
2001-03-09 04:12:39 +03:00
|
|
|
case IBMBIDI_NUMERAL_REGULAR:
|
|
|
|
|
|
|
|
switch (aCharType) {
|
|
|
|
|
|
|
|
case eCharType_EuropeanNumber:
|
2002-02-19 23:41:32 +03:00
|
|
|
HandleNumbers(aText,aTextLength,IBMBIDI_NUMERAL_ARABIC);
|
2001-03-09 04:12:39 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case eCharType_ArabicNumber:
|
2002-02-19 23:41:32 +03:00
|
|
|
HandleNumbers(aText,aTextLength,IBMBIDI_NUMERAL_HINDI);
|
2001-03-09 04:12:39 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2009-01-30 11:13:17 +03:00
|
|
|
|
2001-03-09 04:12:39 +03:00
|
|
|
case IBMBIDI_NUMERAL_HINDICONTEXT:
|
2001-04-12 03:32:21 +04:00
|
|
|
if ( ( (GET_BIDI_OPTION_DIRECTION(bidiOptions)==IBMBIDI_TEXTDIRECTION_RTL) && (IS_ARABIC_DIGIT (aText[0])) ) || (eCharType_ArabicNumber == aCharType) )
|
2002-02-19 23:41:32 +03:00
|
|
|
HandleNumbers(aText,aTextLength,IBMBIDI_NUMERAL_HINDI);
|
2001-03-09 04:12:39 +03:00
|
|
|
else if (eCharType_EuropeanNumber == aCharType)
|
2002-02-19 23:41:32 +03:00
|
|
|
HandleNumbers(aText,aTextLength,IBMBIDI_NUMERAL_ARABIC);
|
2001-03-09 04:12:39 +03:00
|
|
|
break;
|
|
|
|
|
2009-01-30 11:13:17 +03: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;
|
|
|
|
|
2003-05-08 22:38:19 +04:00
|
|
|
case IBMBIDI_NUMERAL_NOMINAL:
|
2001-03-09 04:12:39 +03:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2002-04-24 03:50:17 +04:00
|
|
|
StripBidiControlCharacters(aText, aTextLength);
|
2001-03-09 04:12:39 +03:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2002-04-24 03:50:17 +04:00
|
|
|
void
|
|
|
|
nsBidiPresUtils::StripBidiControlCharacters(PRUnichar* aText,
|
2011-04-13 13:23:49 +04:00
|
|
|
PRInt32& aTextLength)
|
2002-04-24 03:50:17 +04:00
|
|
|
{
|
|
|
|
if ( (nsnull == aText) || (aTextLength < 1) ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 stripLen = 0;
|
|
|
|
|
|
|
|
for (PRInt32 i = 0; i < aTextLength; i++) {
|
2004-05-18 15:01:49 +04:00
|
|
|
// XXX: This silently ignores surrogate characters.
|
|
|
|
// As of Unicode 4.0, all Bidi control characters are within the BMP.
|
2007-07-01 09:56:10 +04:00
|
|
|
if (IsBidiControl((PRUint32)aText[i])) {
|
2002-04-24 03:50:17 +04:00
|
|
|
++stripLen;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
aText[i - stripLen] = aText[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
aTextLength -= stripLen;
|
|
|
|
}
|
|
|
|
|
2001-03-09 04:12:39 +03:00
|
|
|
#if 0 // XXX: for the future use ???
|
|
|
|
void
|
|
|
|
RemoveDiacritics(PRUnichar* aText,
|
|
|
|
PRInt32& aTextLength)
|
|
|
|
{
|
|
|
|
if (aText && (aTextLength > 0) ) {
|
|
|
|
PRInt32 offset = 0;
|
|
|
|
|
|
|
|
for (PRInt32 i = 0; i < aTextLength && aText[i]; i++) {
|
|
|
|
if (IS_BIDI_DIACRITIC(aText[i]) ) {
|
|
|
|
++offset;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
aText[i - offset] = aText[i];
|
|
|
|
}
|
|
|
|
aTextLength = i - offset;
|
|
|
|
aText[aTextLength] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void
|
2011-04-13 13:23:49 +04:00
|
|
|
nsBidiPresUtils::CalculateCharType(nsBidi* aBidiEngine,
|
|
|
|
const PRUnichar* aText,
|
|
|
|
PRInt32& aOffset,
|
2001-06-29 07:15:58 +04:00
|
|
|
PRInt32 aCharTypeLimit,
|
|
|
|
PRInt32& aRunLimit,
|
|
|
|
PRInt32& aRunLength,
|
|
|
|
PRInt32& aRunCount,
|
2001-03-09 04:12:39 +03:00
|
|
|
PRUint8& aCharType,
|
2011-04-13 13:23:49 +04:00
|
|
|
PRUint8& aPrevCharType)
|
2001-06-29 07:15:58 +04:00
|
|
|
|
2001-03-09 04:12:39 +03:00
|
|
|
{
|
|
|
|
PRBool strongTypeFound = PR_FALSE;
|
|
|
|
PRInt32 offset;
|
|
|
|
nsCharType charType;
|
|
|
|
|
|
|
|
aCharType = eCharType_OtherNeutral;
|
|
|
|
|
2001-06-29 07:15:58 +04:00
|
|
|
for (offset = aOffset; offset < aCharTypeLimit; offset++) {
|
2005-06-23 12:03:24 +04:00
|
|
|
// Make sure we give RTL chartype to all characters that would be classified
|
2001-03-09 04:12:39 +03:00
|
|
|
// as Right-To-Left by a bidi platform.
|
2005-06-23 12:03:24 +04:00
|
|
|
// (May differ from the UnicodeData, eg we set RTL chartype to some NSMs.)
|
2011-04-13 13:23:49 +04:00
|
|
|
if (IS_HEBREW_CHAR(aText[offset]) ) {
|
2001-03-09 04:12:39 +03:00
|
|
|
charType = eCharType_RightToLeft;
|
|
|
|
}
|
2011-04-13 13:23:49 +04:00
|
|
|
else if (IS_ARABIC_ALPHABETIC(aText[offset]) ) {
|
2001-03-09 04:12:39 +03:00
|
|
|
charType = eCharType_RightToLeftArabic;
|
|
|
|
}
|
|
|
|
else {
|
2011-04-13 13:23:49 +04:00
|
|
|
aBidiEngine->GetCharTypeAt(offset, &charType);
|
2001-03-09 04:12:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!CHARTYPE_IS_WEAK(charType) ) {
|
2001-06-29 07:15:58 +04:00
|
|
|
|
|
|
|
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;
|
2001-10-01 07:43:42 +04:00
|
|
|
aRunLimit = offset;
|
2001-06-29 07:15:58 +04:00
|
|
|
++aRunCount;
|
2001-10-01 07:43:42 +04:00
|
|
|
break;
|
2001-06-29 07:15:58 +04:00
|
|
|
}
|
|
|
|
|
2001-03-09 04:12:39 +03:00
|
|
|
if ( (eCharType_RightToLeftArabic == aPrevCharType
|
2001-06-29 07:15:58 +04:00
|
|
|
|| eCharType_ArabicNumber == aPrevCharType)
|
2001-03-09 04:12:39 +03:00
|
|
|
&& eCharType_EuropeanNumber == charType) {
|
|
|
|
charType = eCharType_ArabicNumber;
|
|
|
|
}
|
2001-06-29 07:15:58 +04:00
|
|
|
|
2001-03-09 04:12:39 +03:00
|
|
|
// Set PrevCharType to the last strong type in this frame
|
|
|
|
// (for correct numeric shaping)
|
|
|
|
aPrevCharType = charType;
|
|
|
|
|
2001-10-01 07:43:42 +04:00
|
|
|
strongTypeFound = PR_TRUE;
|
|
|
|
aCharType = charType;
|
2001-03-09 04:12:39 +03:00
|
|
|
}
|
|
|
|
}
|
2001-10-01 07:43:42 +04:00
|
|
|
aOffset = offset;
|
2001-06-29 07:15:58 +04:00
|
|
|
}
|
|
|
|
|
2007-01-23 05:58:55 +03:00
|
|
|
nsresult nsBidiPresUtils::ProcessText(const PRUnichar* aText,
|
|
|
|
PRInt32 aLength,
|
|
|
|
nsBidiDirection aBaseDirection,
|
|
|
|
nsPresContext* aPresContext,
|
2008-07-18 22:29:06 +04:00
|
|
|
BidiProcessor& aprocessor,
|
2007-01-23 05:58:55 +03:00
|
|
|
Mode aMode,
|
|
|
|
nsBidiPositionResolve* aPosResolve,
|
|
|
|
PRInt32 aPosResolveCount,
|
2011-04-13 13:23:49 +04:00
|
|
|
nscoord* aWidth,
|
|
|
|
nsBidi* aBidiEngine)
|
2001-11-12 23:51:48 +03:00
|
|
|
{
|
2004-10-29 16:28:19 +04:00
|
|
|
NS_ASSERTION((aPosResolve == nsnull) != (aPosResolveCount > 0), "Incorrect aPosResolve / aPosResolveCount arguments");
|
|
|
|
|
2001-11-12 23:51:48 +03:00
|
|
|
PRInt32 runCount;
|
|
|
|
|
2011-04-13 13:23:49 +04:00
|
|
|
nsAutoString textBuffer(aText, aLength);
|
2001-11-12 23:51:48 +03:00
|
|
|
|
2011-04-13 13:23:49 +04:00
|
|
|
nsresult rv = aBidiEngine->SetPara(aText, aLength, aBaseDirection, nsnull);
|
2001-11-12 23:51:48 +03:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2011-04-13 13:23:49 +04:00
|
|
|
rv = aBidiEngine->CountRuns(&runCount);
|
2001-11-12 23:51:48 +03:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2008-07-18 22:29:06 +04:00
|
|
|
nscoord xOffset = 0;
|
2011-04-13 13:23:49 +04:00
|
|
|
nscoord width, xEndRun = 0;
|
2007-01-23 05:58:55 +03:00
|
|
|
nscoord totalWidth = 0;
|
2001-11-12 23:51:48 +03:00
|
|
|
PRInt32 i, start, limit, length;
|
2004-10-29 16:28:19 +04:00
|
|
|
PRUint32 visualStart = 0;
|
2001-11-12 23:51:48 +03:00
|
|
|
PRUint8 charType;
|
|
|
|
PRUint8 prevType = eCharType_LeftToRight;
|
|
|
|
nsBidiLevel level;
|
2004-10-29 16:28:19 +04:00
|
|
|
|
|
|
|
for(int nPosResolve=0; nPosResolve < aPosResolveCount; ++nPosResolve)
|
|
|
|
{
|
|
|
|
aPosResolve[nPosResolve].visualIndex = kNotFound;
|
|
|
|
aPosResolve[nPosResolve].visualLeftTwips = kNotFound;
|
2009-03-21 11:38:14 +03:00
|
|
|
aPosResolve[nPosResolve].visualWidth = kNotFound;
|
2004-10-29 16:28:19 +04:00
|
|
|
}
|
2001-11-12 23:51:48 +03:00
|
|
|
|
|
|
|
for (i = 0; i < runCount; i++) {
|
2011-04-13 13:23:49 +04:00
|
|
|
rv = aBidiEngine->GetVisualRun(i, &start, &length, &aBaseDirection);
|
2001-11-12 23:51:48 +03:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2011-04-13 13:23:49 +04:00
|
|
|
rv = aBidiEngine->GetLogicalRun(start, &limit, &level);
|
2001-11-12 23:51:48 +03:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2002-02-08 04:53:59 +03:00
|
|
|
PRInt32 subRunLength = limit - start;
|
|
|
|
PRInt32 lineOffset = start;
|
2009-09-16 19:01:36 +04:00
|
|
|
PRInt32 typeLimit = NS_MIN(limit, aLength);
|
2002-02-08 04:53:59 +03:00
|
|
|
PRInt32 subRunCount = 1;
|
|
|
|
PRInt32 subRunLimit = typeLimit;
|
2001-11-12 23:51:48 +03:00
|
|
|
|
2004-07-07 10:49:10 +04: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 22:29:06 +04:00
|
|
|
* |xOffset| by the width of each subrun after rendering.
|
2004-07-07 10:49:10 +04:00
|
|
|
*
|
|
|
|
* If |level| is odd, i.e. the direction of the run is right-to-left, we
|
2008-07-18 22:29:06 +04:00
|
|
|
* render the subruns from right to left. We begin by incrementing |xOffset| by
|
2004-07-07 10:49:10 +04: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.
|
|
|
|
*/
|
2007-01-23 05:58:55 +03:00
|
|
|
|
2004-07-07 10:49:10 +04:00
|
|
|
if (level & 1) {
|
2008-07-18 22:29:06 +04:00
|
|
|
aprocessor.SetText(aText + start, subRunLength, nsBidiDirection(level & 1));
|
|
|
|
width = aprocessor.GetWidth();
|
|
|
|
xOffset += width;
|
|
|
|
xEndRun = xOffset;
|
2004-07-07 10:49:10 +04:00
|
|
|
}
|
|
|
|
|
2002-02-08 04:53:59 +03:00
|
|
|
while (subRunCount > 0) {
|
|
|
|
// CalculateCharType can increment subRunCount if the run
|
|
|
|
// contains mixed character types
|
2011-04-13 13:23:49 +04:00
|
|
|
CalculateCharType(aBidiEngine, aText, lineOffset, typeLimit, subRunLimit, subRunLength, subRunCount, charType, prevType);
|
2004-10-29 16:28:19 +04:00
|
|
|
|
|
|
|
nsAutoString runVisualText;
|
|
|
|
runVisualText.Assign(aText + start, subRunLength);
|
2009-02-03 17:42:18 +03:00
|
|
|
if (PRInt32(runVisualText.Length()) < subRunLength)
|
2006-06-22 23:07:30 +04:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2004-10-29 16:28:19 +04:00
|
|
|
FormatUnicodeText(aPresContext, runVisualText.BeginWriting(), subRunLength,
|
2008-08-11 19:19:01 +04:00
|
|
|
(nsCharType)charType, level & 1);
|
2002-02-08 04:53:59 +03:00
|
|
|
|
2008-07-18 22:29:06 +04:00
|
|
|
aprocessor.SetText(runVisualText.get(), subRunLength, nsBidiDirection(level & 1));
|
|
|
|
width = aprocessor.GetWidth();
|
2007-01-23 05:58:55 +03:00
|
|
|
totalWidth += width;
|
2004-07-07 10:49:10 +04:00
|
|
|
if (level & 1) {
|
2008-07-18 22:29:06 +04:00
|
|
|
xOffset -= width;
|
2004-07-07 10:49:10 +04:00
|
|
|
}
|
2007-01-23 05:58:55 +03:00
|
|
|
if (aMode == MODE_DRAW) {
|
2008-07-18 22:29:06 +04:00
|
|
|
aprocessor.DrawText(xOffset, width);
|
2007-01-23 05:58:55 +03:00
|
|
|
}
|
2004-10-29 16:28:19 +04: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 22:29:06 +04:00
|
|
|
* less the x-coord of the start of the whole text.
|
2004-10-29 16:28:19 +04:00
|
|
|
*/
|
|
|
|
if (subRunLength == 1) {
|
|
|
|
posResolve->visualIndex = visualStart;
|
2008-07-18 22:29:06 +04:00
|
|
|
posResolve->visualLeftTwips = xOffset;
|
2009-03-21 11:38:14 +03:00
|
|
|
posResolve->visualWidth = width;
|
2004-10-29 16:28:19 +04: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 11:38:14 +03: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)
|
|
|
|
*/
|
2004-10-29 16:28:19 +04:00
|
|
|
nscoord subWidth;
|
|
|
|
// The position in the text where this run's "left part" begins.
|
2009-03-21 11:38:14 +03:00
|
|
|
const PRUnichar* visualLeftPart, *visualRightSide;
|
2004-10-29 16:28:19 +04: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 11:38:14 +03:00
|
|
|
// Skipping to the right side of the current character
|
|
|
|
visualRightSide = visualLeftPart - 1;
|
2004-10-29 16:28:19 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
posResolve->visualIndex = visualStart + (posResolve->logicalIndex - start);
|
|
|
|
// Skipping to the "left part".
|
|
|
|
visualLeftPart = aText + start;
|
2009-03-21 11:38:14 +03:00
|
|
|
// In LTR mode this is the same as visualLeftPart
|
|
|
|
visualRightSide = visualLeftPart;
|
2004-10-29 16:28:19 +04:00
|
|
|
}
|
|
|
|
// The delta between the start of the run and the left part's end.
|
|
|
|
PRInt32 visualLeftLength = posResolve->visualIndex - visualStart;
|
2008-07-18 22:29:06 +04:00
|
|
|
aprocessor.SetText(visualLeftPart, visualLeftLength, nsBidiDirection(level & 1));
|
|
|
|
subWidth = aprocessor.GetWidth();
|
2009-03-21 11:38:14 +03:00
|
|
|
aprocessor.SetText(visualRightSide, visualLeftLength + 1, nsBidiDirection(level & 1));
|
2008-07-18 22:29:06 +04:00
|
|
|
posResolve->visualLeftTwips = xOffset + subWidth;
|
2009-03-21 11:38:14 +03:00
|
|
|
posResolve->visualWidth = aprocessor.GetWidth() - subWidth;
|
2004-10-29 16:28:19 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-07-07 10:49:10 +04:00
|
|
|
if (!(level & 1)) {
|
2008-07-18 22:29:06 +04:00
|
|
|
xOffset += width;
|
2004-07-07 10:49:10 +04:00
|
|
|
}
|
2002-02-08 04:53:59 +03:00
|
|
|
|
|
|
|
--subRunCount;
|
|
|
|
start = lineOffset;
|
|
|
|
subRunLimit = typeLimit;
|
|
|
|
subRunLength = typeLimit - lineOffset;
|
|
|
|
} // while
|
2004-07-07 10:49:10 +04:00
|
|
|
if (level & 1) {
|
2008-07-18 22:29:06 +04:00
|
|
|
xOffset = xEndRun;
|
2004-07-07 10:49:10 +04:00
|
|
|
}
|
2004-10-29 16:28:19 +04:00
|
|
|
|
|
|
|
visualStart += length;
|
2001-11-12 23:51:48 +03:00
|
|
|
} // for
|
|
|
|
|
2007-01-23 05:58:55 +03:00
|
|
|
if (aWidth) {
|
|
|
|
*aWidth = totalWidth;
|
|
|
|
}
|
2001-11-12 23:51:48 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2008-07-18 22:29:06 +04:00
|
|
|
|
|
|
|
class NS_STACK_CLASS nsIRenderingContextBidiProcessor : public nsBidiPresUtils::BidiProcessor {
|
|
|
|
public:
|
|
|
|
nsIRenderingContextBidiProcessor(nsIRenderingContext* aCtx,
|
2011-01-16 23:23:33 +03:00
|
|
|
nsIRenderingContext* aTextRunConstructionContext,
|
2008-07-18 22:29:06 +04:00
|
|
|
const nsPoint& aPt)
|
2011-01-16 23:23:33 +03:00
|
|
|
: mCtx(aCtx), mTextRunConstructionContext(aTextRunConstructionContext), mPt(aPt) { }
|
2008-07-18 22:29:06 +04:00
|
|
|
|
|
|
|
~nsIRenderingContextBidiProcessor()
|
|
|
|
{
|
|
|
|
mCtx->SetRightToLeftText(PR_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void SetText(const PRUnichar* aText,
|
|
|
|
PRInt32 aLength,
|
|
|
|
nsBidiDirection aDirection)
|
|
|
|
{
|
2011-01-16 23:23:33 +03:00
|
|
|
mTextRunConstructionContext->SetTextRunRTL(aDirection==NSBIDI_RTL);
|
2008-07-18 22:29:06 +04:00
|
|
|
mText = aText;
|
|
|
|
mLength = aLength;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual nscoord GetWidth()
|
|
|
|
{
|
|
|
|
nscoord width;
|
2011-01-16 23:23:33 +03:00
|
|
|
mTextRunConstructionContext->GetWidth(mText, mLength, width, nsnull);
|
2008-07-18 22:29:06 +04:00
|
|
|
return width;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void DrawText(nscoord aXOffset,
|
|
|
|
nscoord)
|
|
|
|
{
|
2011-04-08 05:04:39 +04:00
|
|
|
nsCOMPtr<nsIFontMetrics> metrics = mCtx->GetFontMetrics();
|
2011-01-16 23:23:33 +03:00
|
|
|
nsIThebesFontMetrics* fm = static_cast<nsIThebesFontMetrics*>(metrics.get());
|
|
|
|
fm->DrawString(mText, mLength, mPt.x + aXOffset, mPt.y,
|
|
|
|
mCtx, mTextRunConstructionContext);
|
2008-07-18 22:29:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsIRenderingContext* mCtx;
|
2011-01-16 23:23:33 +03:00
|
|
|
nsIRenderingContext* mTextRunConstructionContext;
|
2009-04-19 12:19:27 +04:00
|
|
|
nsPoint mPt;
|
2008-07-18 22:29:06 +04:00
|
|
|
const PRUnichar* mText;
|
|
|
|
PRInt32 mLength;
|
|
|
|
nsBidiDirection mDirection;
|
|
|
|
};
|
|
|
|
|
|
|
|
nsresult nsBidiPresUtils::ProcessTextForRenderingContext(const PRUnichar* aText,
|
|
|
|
PRInt32 aLength,
|
|
|
|
nsBidiDirection aBaseDirection,
|
|
|
|
nsPresContext* aPresContext,
|
|
|
|
nsIRenderingContext& aRenderingContext,
|
2011-01-16 23:23:33 +03:00
|
|
|
nsIRenderingContext& aTextRunConstructionContext,
|
2008-07-18 22:29:06 +04:00
|
|
|
Mode aMode,
|
|
|
|
nscoord aX,
|
|
|
|
nscoord aY,
|
|
|
|
nsBidiPositionResolve* aPosResolve,
|
|
|
|
PRInt32 aPosResolveCount,
|
|
|
|
nscoord* aWidth)
|
|
|
|
{
|
2011-01-16 23:23:33 +03:00
|
|
|
nsIRenderingContextBidiProcessor processor(&aRenderingContext, &aTextRunConstructionContext, nsPoint(aX, aY));
|
2011-04-13 13:23:49 +04:00
|
|
|
nsBidi bidiEngine;
|
2008-07-18 22:29:06 +04:00
|
|
|
return ProcessText(aText, aLength, aBaseDirection, aPresContext, processor,
|
2011-04-13 13:23:49 +04:00
|
|
|
aMode, aPosResolve, aPosResolveCount, aWidth, &bidiEngine);
|
2008-07-18 22:29:06 +04:00
|
|
|
}
|
2010-06-01 06:19:35 +04:00
|
|
|
|
2011-01-04 11:52:17 +03:00
|
|
|
/* static */
|
|
|
|
void nsBidiPresUtils::WriteReverse(const PRUnichar* aSrc,
|
|
|
|
PRUint32 aSrcLength,
|
|
|
|
PRUnichar* aDest)
|
|
|
|
{
|
|
|
|
const PRUnichar* src = aSrc + aSrcLength;
|
|
|
|
PRUnichar* dest = aDest;
|
|
|
|
PRUint32 UTF32Char;
|
|
|
|
|
|
|
|
while (--src >= aSrc) {
|
|
|
|
if (NS_IS_LOW_SURROGATE(*src)) {
|
|
|
|
if (src > aSrc && NS_IS_HIGH_SURROGATE(*(src - 1))) {
|
|
|
|
UTF32Char = SURROGATE_TO_UCS4(*(src - 1), *src);
|
|
|
|
--src;
|
|
|
|
} else {
|
|
|
|
UTF32Char = UCS2_REPLACEMENT_CHAR;
|
|
|
|
}
|
|
|
|
} else if (NS_IS_HIGH_SURROGATE(*src)) {
|
|
|
|
// paired high surrogates are handled above, so this is a lone high surrogate
|
|
|
|
UTF32Char = UCS2_REPLACEMENT_CHAR;
|
|
|
|
} else {
|
|
|
|
UTF32Char = *src;
|
|
|
|
}
|
|
|
|
|
|
|
|
UTF32Char = gfxUnicodeProperties::GetMirroredChar(UTF32Char);
|
|
|
|
|
|
|
|
if (IS_IN_BMP(UTF32Char)) {
|
|
|
|
*(dest++) = UTF32Char;
|
|
|
|
} else {
|
|
|
|
*(dest++) = H_SURROGATE(UTF32Char);
|
|
|
|
*(dest++) = L_SURROGATE(UTF32Char);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(dest - aDest == aSrcLength, "Whole string not copied");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
PRBool nsBidiPresUtils::WriteLogicalToVisual(const PRUnichar* aSrc,
|
|
|
|
PRUint32 aSrcLength,
|
|
|
|
PRUnichar* aDest,
|
|
|
|
nsBidiLevel aBaseDirection,
|
|
|
|
nsBidi* aBidiEngine)
|
|
|
|
{
|
|
|
|
const PRUnichar* src = aSrc;
|
|
|
|
nsresult rv = aBidiEngine->SetPara(src, aSrcLength, aBaseDirection, nsnull);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsBidiDirection dir;
|
|
|
|
rv = aBidiEngine->GetDirection(&dir);
|
|
|
|
// NSBIDI_LTR returned from GetDirection means the whole text is LTR
|
|
|
|
if (NS_FAILED(rv) || dir == NSBIDI_LTR) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 runCount;
|
|
|
|
rv = aBidiEngine->CountRuns(&runCount);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 runIndex, start, length;
|
|
|
|
PRUnichar* dest = aDest;
|
|
|
|
|
|
|
|
for (runIndex = 0; runIndex < runCount; ++runIndex) {
|
|
|
|
rv = aBidiEngine->GetVisualRun(runIndex, &start, &length, &dir);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(dest - aDest == aSrcLength, "whole string not copied");
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsBidiPresUtils::CopyLogicalToVisual(const nsAString& aSource,
|
|
|
|
nsAString& aDest,
|
|
|
|
nsBidiLevel aBaseDirection,
|
|
|
|
PRBool aOverride)
|
|
|
|
{
|
|
|
|
aDest.SetLength(0);
|
|
|
|
PRUint32 srcLength = aSource.Length();
|
|
|
|
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 13:23:49 +04:00
|
|
|
nsBidi bidiEngine;
|
2011-01-04 11:52:17 +03:00
|
|
|
if (!WriteLogicalToVisual(fromBegin.get(), srcLength, toBegin.get(),
|
2011-04-13 13:23:49 +04:00
|
|
|
aBaseDirection, &bidiEngine)) {
|
2011-01-04 11:52:17 +03: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);
|
|
|
|
}
|
|
|
|
}
|
2001-03-09 04:12:39 +03:00
|
|
|
#endif // IBMBIDI
|