1998-09-09 02:34:40 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Netscape Public License
|
|
|
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
|
|
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
|
|
|
* http://www.mozilla.org/NPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* NPL.
|
|
|
|
*
|
|
|
|
* The Initial Developer of this code under the NPL is Netscape
|
|
|
|
* Communications Corporation. Portions created by Netscape are
|
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
|
|
|
* Reserved.
|
|
|
|
*/
|
1999-02-12 20:45:58 +03:00
|
|
|
#include "nsCOMPtr.h"
|
1998-09-09 02:34:40 +04:00
|
|
|
#include "nsHTMLParts.h"
|
|
|
|
#include "nsCRT.h"
|
|
|
|
#include "nsSplittableFrame.h"
|
1998-09-15 04:19:49 +04:00
|
|
|
#include "nsLineLayout.h"
|
1998-09-09 02:34:40 +04:00
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsIPresContext.h"
|
1999-04-13 05:15:16 +04:00
|
|
|
#include "nsIContent.h"
|
1998-09-09 02:34:40 +04:00
|
|
|
#include "nsStyleConsts.h"
|
|
|
|
#include "nsIStyleContext.h"
|
|
|
|
#include "nsCoord.h"
|
|
|
|
#include "nsIFontMetrics.h"
|
|
|
|
#include "nsIRenderingContext.h"
|
|
|
|
#include "nsHTMLIIDs.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsIView.h"
|
|
|
|
#include "nsIViewManager.h"
|
|
|
|
#include "nsITimerCallback.h"
|
|
|
|
#include "nsITimer.h"
|
|
|
|
#include "prtime.h"
|
|
|
|
#include "nsVoidArray.h"
|
|
|
|
#include "prprf.h"
|
|
|
|
#include "nsIDOMText.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIDeviceContext.h"
|
1999-02-12 02:12:28 +03:00
|
|
|
#include "nsIFocusTracker.h"
|
1999-06-17 03:55:48 +04:00
|
|
|
#include "nsICaret.h"
|
1998-09-09 02:34:40 +04:00
|
|
|
#include "nsXIFConverter.h"
|
1998-10-26 20:27:53 +03:00
|
|
|
#include "nsHTMLAtoms.h"
|
1999-02-24 21:21:23 +03:00
|
|
|
#include "nsILineBreaker.h"
|
1999-04-07 02:41:44 +04:00
|
|
|
#include "nsIWordBreaker.h"
|
1998-09-09 02:34:40 +04:00
|
|
|
|
1998-10-20 04:21:18 +04:00
|
|
|
#include "nsITextContent.h"
|
1999-04-20 04:23:33 +04:00
|
|
|
#include "nsTextRun.h"
|
1998-10-20 04:21:18 +04:00
|
|
|
#include "nsTextFragment.h"
|
|
|
|
#include "nsTextTransformer.h"
|
1999-02-24 08:33:40 +03:00
|
|
|
#include "nsLayoutAtoms.h"
|
1999-03-12 03:17:14 +03:00
|
|
|
#include "nsIFrameSelection.h"
|
1999-04-26 08:02:04 +04:00
|
|
|
#include "nsIDOMSelection.h"
|
|
|
|
#include "nsIDOMRange.h"
|
1998-10-20 04:21:18 +04:00
|
|
|
|
1999-06-20 00:36:44 +04:00
|
|
|
#include "nsILineIterator.h"
|
|
|
|
|
1999-09-15 05:57:50 +04:00
|
|
|
#ifndef PR_ABS
|
|
|
|
#define PR_ABS(x) (x < 0 ? -x : x)
|
|
|
|
#endif
|
|
|
|
|
1998-09-09 02:34:40 +04:00
|
|
|
static NS_DEFINE_IID(kIDOMTextIID, NS_IDOMTEXT_IID);
|
|
|
|
|
|
|
|
#ifdef NS_DEBUG
|
|
|
|
#undef NOISY_BLINK
|
1998-10-10 08:35:21 +04:00
|
|
|
#undef DEBUG_WORD_WRAPPING
|
1999-09-18 03:14:47 +04:00
|
|
|
#undef NOISY_REFLOW
|
1998-09-09 02:34:40 +04:00
|
|
|
#else
|
|
|
|
#undef NOISY_BLINK
|
1998-10-10 08:35:21 +04:00
|
|
|
#undef DEBUG_WORD_WRAPPING
|
1999-09-18 03:14:47 +04:00
|
|
|
#undef NOISY_REFLOW
|
1998-09-09 02:34:40 +04:00
|
|
|
#endif
|
|
|
|
|
1999-08-19 10:06:57 +04:00
|
|
|
// #define DEBUGWORDJUMP
|
|
|
|
|
1998-10-20 04:21:18 +04:00
|
|
|
#define WORD_BUF_SIZE 100
|
|
|
|
#define TEXT_BUF_SIZE 1000
|
|
|
|
|
1999-04-20 04:23:33 +04:00
|
|
|
// Helper class for managing blinking text
|
1998-09-09 02:34:40 +04:00
|
|
|
|
1999-04-20 04:23:33 +04:00
|
|
|
class nsBlinkTimer : public nsITimerCallback {
|
1998-09-09 02:34:40 +04:00
|
|
|
public:
|
1999-04-20 04:23:33 +04:00
|
|
|
nsBlinkTimer();
|
|
|
|
virtual ~nsBlinkTimer();
|
1998-09-09 02:34:40 +04:00
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
1999-04-20 04:23:33 +04:00
|
|
|
void AddFrame(nsIFrame* aFrame);
|
1998-09-09 02:34:40 +04:00
|
|
|
|
1999-04-20 04:23:33 +04:00
|
|
|
PRBool RemoveFrame(nsIFrame* aFrame);
|
1998-09-09 02:34:40 +04:00
|
|
|
|
|
|
|
PRInt32 FrameCount();
|
|
|
|
|
|
|
|
void Start();
|
|
|
|
|
|
|
|
void Stop();
|
|
|
|
|
|
|
|
virtual void Notify(nsITimer *timer);
|
|
|
|
|
|
|
|
nsITimer* mTimer;
|
|
|
|
nsVoidArray mFrames;
|
|
|
|
};
|
|
|
|
|
1999-04-20 04:23:33 +04:00
|
|
|
static PRBool gBlinkTextOff;
|
|
|
|
static nsBlinkTimer* gTextBlinker;
|
|
|
|
#ifdef NOISY_BLINK
|
|
|
|
static PRTime gLastTick;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
nsBlinkTimer::nsBlinkTimer()
|
|
|
|
{
|
|
|
|
NS_INIT_REFCNT();
|
|
|
|
mTimer = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsBlinkTimer::~nsBlinkTimer()
|
|
|
|
{
|
|
|
|
Stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsBlinkTimer::Start()
|
|
|
|
{
|
|
|
|
nsresult rv = NS_NewTimer(&mTimer);
|
|
|
|
if (NS_OK == rv) {
|
|
|
|
mTimer->Init(this, 750);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsBlinkTimer::Stop()
|
|
|
|
{
|
|
|
|
if (nsnull != mTimer) {
|
|
|
|
mTimer->Cancel();
|
|
|
|
NS_RELEASE(mTimer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static NS_DEFINE_IID(kITimerCallbackIID, NS_ITIMERCALLBACK_IID);
|
|
|
|
NS_IMPL_ISUPPORTS(nsBlinkTimer, kITimerCallbackIID);
|
|
|
|
|
|
|
|
void nsBlinkTimer::AddFrame(nsIFrame* aFrame) {
|
|
|
|
mFrames.AppendElement(aFrame);
|
|
|
|
if (1 == mFrames.Count()) {
|
|
|
|
Start();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool nsBlinkTimer::RemoveFrame(nsIFrame* aFrame) {
|
|
|
|
PRBool rv = mFrames.RemoveElement(aFrame);
|
|
|
|
if (0 == mFrames.Count()) {
|
|
|
|
Stop();
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 nsBlinkTimer::FrameCount() {
|
|
|
|
return mFrames.Count();
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsBlinkTimer::Notify(nsITimer *timer)
|
|
|
|
{
|
|
|
|
// Toggle blink state bit so that text code knows whether or not to
|
|
|
|
// render. All text code shares the same flag so that they all blink
|
|
|
|
// in unison.
|
|
|
|
gBlinkTextOff = PRBool(!gBlinkTextOff);
|
|
|
|
|
|
|
|
// XXX hack to get auto-repeating timers; restart before doing
|
|
|
|
// expensive work so that time between ticks is more even
|
|
|
|
Stop();
|
|
|
|
Start();
|
|
|
|
|
|
|
|
#ifdef NOISY_BLINK
|
|
|
|
PRTime now = PR_Now();
|
|
|
|
char buf[50];
|
|
|
|
PRTime delta;
|
|
|
|
LL_SUB(delta, now, gLastTick);
|
|
|
|
gLastTick = now;
|
|
|
|
PR_snprintf(buf, sizeof(buf), "%lldusec", delta);
|
|
|
|
printf("%s\n", buf);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
PRInt32 i, n = mFrames.Count();
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
nsIFrame* text = (nsIFrame*) mFrames.ElementAt(i);
|
|
|
|
|
|
|
|
// Determine damaged area and tell view manager to redraw it
|
|
|
|
nsPoint offset;
|
|
|
|
nsRect bounds;
|
|
|
|
text->GetRect(bounds);
|
|
|
|
nsIView* view;
|
|
|
|
text->GetOffsetFromView(offset, &view);
|
|
|
|
nsIViewManager* vm;
|
|
|
|
view->GetViewManager(vm);
|
|
|
|
bounds.x = offset.x;
|
|
|
|
bounds.y = offset.y;
|
|
|
|
vm->UpdateView(view, bounds, 0);
|
|
|
|
NS_RELEASE(vm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
class nsTextFrame : public nsSplittableFrame {
|
1998-09-09 02:34:40 +04:00
|
|
|
public:
|
1999-04-20 04:23:33 +04:00
|
|
|
nsTextFrame();
|
1998-09-09 02:34:40 +04:00
|
|
|
|
|
|
|
// nsIFrame
|
|
|
|
NS_IMETHOD Paint(nsIPresContext& aPresContext,
|
|
|
|
nsIRenderingContext& aRenderingContext,
|
1998-12-18 18:54:23 +03:00
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
nsFramePaintLayer aWhichLayer);
|
1998-09-09 02:34:40 +04:00
|
|
|
|
1998-11-18 08:25:26 +03:00
|
|
|
NS_IMETHOD GetCursor(nsIPresContext& aPresContext,
|
|
|
|
nsPoint& aPoint,
|
|
|
|
PRInt32& aCursor);
|
1998-09-09 02:34:40 +04:00
|
|
|
|
1998-09-30 03:48:07 +04:00
|
|
|
NS_IMETHOD ContentChanged(nsIPresContext* aPresContext,
|
1998-09-09 02:34:40 +04:00
|
|
|
nsIContent* aChild,
|
|
|
|
nsISupports* aSubContent);
|
|
|
|
|
1999-01-16 03:00:50 +03:00
|
|
|
NS_IMETHOD List(FILE* out, PRInt32 aIndent) const;
|
1998-09-09 02:34:40 +04:00
|
|
|
|
1999-02-24 08:33:40 +03:00
|
|
|
/**
|
|
|
|
* Get the "type" of the frame
|
|
|
|
*
|
|
|
|
* @see nsLayoutAtoms::textFrame
|
|
|
|
*/
|
|
|
|
NS_IMETHOD GetFrameType(nsIAtom** aType) const;
|
|
|
|
|
1998-11-19 20:22:29 +03:00
|
|
|
NS_IMETHOD GetFrameName(nsString& aResult) const;
|
1998-09-09 02:34:40 +04:00
|
|
|
|
1999-09-01 05:02:16 +04:00
|
|
|
#ifdef DEBUG
|
1999-08-31 07:09:40 +04:00
|
|
|
NS_IMETHOD SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const;
|
1999-09-01 05:02:16 +04:00
|
|
|
#endif
|
1999-08-31 07:09:40 +04:00
|
|
|
|
1998-10-02 05:12:39 +04:00
|
|
|
NS_IMETHOD GetPosition(nsIPresContext& aCX,
|
1999-06-11 01:08:17 +04:00
|
|
|
nscoord aXCoord,
|
1999-05-17 04:21:18 +04:00
|
|
|
nsIContent ** aNewContent,
|
1999-06-11 01:08:17 +04:00
|
|
|
PRInt32& aContentOffset,
|
|
|
|
PRInt32& aContentOffsetEnd);
|
1998-09-09 02:34:40 +04:00
|
|
|
|
1999-04-26 08:02:04 +04:00
|
|
|
NS_IMETHOD GetPositionSlowly(nsIPresContext& aCX,
|
|
|
|
nsIRenderingContext * aRendContext,
|
1999-06-11 01:08:17 +04:00
|
|
|
nscoord aXCoord,
|
1999-05-17 23:50:29 +04:00
|
|
|
nsIContent ** aNewContent,
|
1999-06-11 01:08:17 +04:00
|
|
|
PRInt32& aOffset);
|
1999-04-26 08:02:04 +04:00
|
|
|
|
|
|
|
|
1999-05-20 04:52:00 +04:00
|
|
|
NS_IMETHOD SetSelected(nsIDOMRange *aRange,PRBool aSelected, nsSpread aSpread);
|
1999-04-26 08:02:04 +04:00
|
|
|
|
1999-09-10 22:29:37 +04:00
|
|
|
NS_IMETHOD PeekOffset(nsPeekOffsetStruct *aPos);
|
1999-02-02 03:23:40 +03:00
|
|
|
|
1999-05-17 04:21:18 +04:00
|
|
|
NS_IMETHOD HandleMultiplePress(nsIPresContext& aPresContext,
|
|
|
|
nsGUIEvent * aEvent,
|
|
|
|
nsEventStatus& aEventStatus);
|
|
|
|
|
1999-01-22 21:58:14 +03:00
|
|
|
NS_IMETHOD GetOffsets(PRInt32 &start, PRInt32 &end)const;
|
|
|
|
|
1999-02-12 03:02:31 +03:00
|
|
|
NS_IMETHOD GetPointFromOffset(nsIPresContext* inPresContext,
|
|
|
|
nsIRenderingContext* inRendContext,
|
|
|
|
PRInt32 inOffset,
|
|
|
|
nsPoint* outPoint);
|
|
|
|
|
|
|
|
NS_IMETHOD GetChildFrameContainingOffset(PRInt32 inContentOffset,
|
1999-09-11 04:18:02 +04:00
|
|
|
PRBool inHint,
|
1999-02-12 03:02:31 +03:00
|
|
|
PRInt32* outFrameContentOffset,
|
|
|
|
nsIFrame* *outChildFrame);
|
|
|
|
|
1998-10-03 08:28:05 +04:00
|
|
|
// nsIHTMLReflow
|
1998-10-10 03:46:02 +04:00
|
|
|
NS_IMETHOD FindTextRuns(nsLineLayout& aLineLayout);
|
1998-10-03 08:28:05 +04:00
|
|
|
NS_IMETHOD Reflow(nsIPresContext& aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aMetrics,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus);
|
1998-10-27 19:52:34 +03:00
|
|
|
NS_IMETHOD AdjustFrameSize(nscoord aExtraSpace, nscoord& aUsedSpace);
|
1999-05-04 00:55:12 +04:00
|
|
|
NS_IMETHOD TrimTrailingWhiteSpace(nsIPresContext* aPresContext,
|
1998-10-27 19:52:34 +03:00
|
|
|
nsIRenderingContext& aRC,
|
|
|
|
nscoord& aDeltaWidth);
|
1998-09-09 02:34:40 +04:00
|
|
|
|
1998-10-26 20:27:53 +03:00
|
|
|
struct TextStyle {
|
|
|
|
const nsStyleFont* mFont;
|
|
|
|
const nsStyleText* mText;
|
|
|
|
const nsStyleColor* mColor;
|
|
|
|
nsIFontMetrics* mNormalFont;
|
|
|
|
nsIFontMetrics* mSmallFont;
|
|
|
|
nsIFontMetrics* mLastFont;
|
|
|
|
PRBool mSmallCaps;
|
|
|
|
nscoord mWordSpacing;
|
|
|
|
nscoord mLetterSpacing;
|
|
|
|
nscolor mSelectionTextColor;
|
|
|
|
nscolor mSelectionBGColor;
|
|
|
|
nscoord mSpaceWidth;
|
1998-10-27 19:52:34 +03:00
|
|
|
PRBool mJustifying;
|
1999-03-31 08:12:46 +04:00
|
|
|
PRBool mPreformatted;
|
1998-10-27 19:52:34 +03:00
|
|
|
PRIntn mNumSpaces;
|
|
|
|
nscoord mExtraSpacePerSpace;
|
|
|
|
nscoord mRemainingExtraSpace;
|
1998-10-26 20:27:53 +03:00
|
|
|
|
1999-04-20 04:23:33 +04:00
|
|
|
TextStyle(nsIPresContext* aPresContext,
|
1998-10-26 20:27:53 +03:00
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
nsIStyleContext* sc)
|
|
|
|
{
|
|
|
|
// Get style data
|
|
|
|
mColor = (const nsStyleColor*) sc->GetStyleData(eStyleStruct_Color);
|
|
|
|
mFont = (const nsStyleFont*) sc->GetStyleData(eStyleStruct_Font);
|
|
|
|
mText = (const nsStyleText*) sc->GetStyleData(eStyleStruct_Text);
|
|
|
|
|
1999-06-08 01:18:51 +04:00
|
|
|
// Cache the original decorations and reuse the current font
|
|
|
|
// to query metrics, rather than creating a new font which is expensive.
|
1999-06-08 22:12:20 +04:00
|
|
|
nsFont* plainFont = (nsFont *)&mFont->mFont; //XXX: Change to use a CONST_CAST macro.
|
|
|
|
PRUint8 originalDecorations = plainFont->decorations;
|
|
|
|
plainFont->decorations = NS_FONT_DECORATION_NONE;
|
|
|
|
aPresContext->GetMetricsFor(*plainFont, &mNormalFont);
|
1998-10-26 20:27:53 +03:00
|
|
|
aRenderingContext.SetFont(mNormalFont);
|
|
|
|
aRenderingContext.GetWidth(' ', mSpaceWidth);
|
|
|
|
mLastFont = mNormalFont;
|
|
|
|
|
|
|
|
// Get the small-caps font if needed
|
1999-06-08 22:12:20 +04:00
|
|
|
mSmallCaps = NS_STYLE_FONT_VARIANT_SMALL_CAPS == plainFont->variant;
|
1998-10-26 20:27:53 +03:00
|
|
|
if (mSmallCaps) {
|
1999-06-08 22:12:20 +04:00
|
|
|
nscoord originalSize = plainFont->size;
|
|
|
|
plainFont->size = nscoord(0.7 * plainFont->size);
|
|
|
|
aPresContext->GetMetricsFor(*plainFont, &mSmallFont);
|
1999-06-08 01:18:51 +04:00
|
|
|
// Reset to the size value saved earlier.
|
1999-06-08 22:12:20 +04:00
|
|
|
plainFont->size = originalSize;
|
1998-10-26 20:27:53 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
mSmallFont = nsnull;
|
|
|
|
}
|
|
|
|
|
1999-06-08 01:18:51 +04:00
|
|
|
// Reset to the decoration saved earlier
|
1999-06-08 22:12:20 +04:00
|
|
|
plainFont->decorations = originalDecorations;
|
1999-06-08 01:18:51 +04:00
|
|
|
|
1998-10-26 20:27:53 +03:00
|
|
|
// XXX Get these from style
|
|
|
|
mSelectionBGColor = NS_RGB(0, 0, 0);
|
|
|
|
mSelectionTextColor = NS_RGB(255, 255, 255);
|
|
|
|
|
|
|
|
// Get the word and letter spacing
|
|
|
|
mWordSpacing = 0;
|
|
|
|
mLetterSpacing = 0;
|
1999-03-31 08:12:46 +04:00
|
|
|
PRIntn unit = mText->mWordSpacing.GetUnit();
|
|
|
|
if (eStyleUnit_Coord == unit) {
|
|
|
|
mWordSpacing = mText->mWordSpacing.GetCoordValue();
|
|
|
|
}
|
|
|
|
unit = mText->mLetterSpacing.GetUnit();
|
|
|
|
if (eStyleUnit_Coord == unit) {
|
|
|
|
mLetterSpacing = mText->mLetterSpacing.GetCoordValue();
|
1998-10-26 20:27:53 +03:00
|
|
|
}
|
1998-10-27 19:52:34 +03:00
|
|
|
mNumSpaces = 0;
|
|
|
|
mRemainingExtraSpace = 0;
|
|
|
|
mExtraSpacePerSpace = 0;
|
1999-03-31 08:12:46 +04:00
|
|
|
mPreformatted = (NS_STYLE_WHITESPACE_PRE == mText->mWhiteSpace) ||
|
|
|
|
(NS_STYLE_WHITESPACE_MOZ_PRE_WRAP == mText->mWhiteSpace);
|
1998-10-26 20:27:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
~TextStyle() {
|
|
|
|
NS_RELEASE(mNormalFont);
|
|
|
|
NS_IF_RELEASE(mSmallFont);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
1999-04-20 04:23:33 +04:00
|
|
|
nsIDocument* GetDocument(nsIPresContext* aPresContext);
|
|
|
|
|
1999-02-10 21:55:25 +03:00
|
|
|
PRIntn PrepareUnicodeText(nsTextTransformer& aTransformer,
|
1998-10-27 19:52:34 +03:00
|
|
|
PRInt32* aIndicies,
|
|
|
|
PRUnichar* aBuffer,
|
1999-04-20 04:23:33 +04:00
|
|
|
PRInt32* aTextLen);
|
1998-09-09 02:34:40 +04:00
|
|
|
|
1998-09-17 04:18:25 +04:00
|
|
|
void PaintTextDecorations(nsIRenderingContext& aRenderingContext,
|
1998-10-26 20:27:53 +03:00
|
|
|
nsIStyleContext* aStyleContext,
|
|
|
|
TextStyle& aStyle,
|
1999-07-15 22:19:03 +04:00
|
|
|
nscoord aX, nscoord aY, nscoord aWidth,
|
|
|
|
PRUnichar* aText = nsnull,
|
|
|
|
SelectionDetails *aDetails = nsnull,
|
|
|
|
PRUint32 aIndex = 0,
|
|
|
|
PRUint32 aLength = 0,
|
|
|
|
const nscoord* aSpacing = nsnull);
|
1998-09-17 04:18:25 +04:00
|
|
|
|
1999-04-20 04:23:33 +04:00
|
|
|
void PaintTextSlowly(nsIPresContext* aPresContext,
|
1998-10-26 20:27:53 +03:00
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
nsIStyleContext* aStyleContext,
|
|
|
|
TextStyle& aStyle,
|
|
|
|
nscoord aX, nscoord aY);
|
|
|
|
|
|
|
|
void RenderString(nsIRenderingContext& aRenderingContext,
|
|
|
|
nsIStyleContext* aStyleContext,
|
|
|
|
TextStyle& aStyle,
|
|
|
|
PRUnichar* aBuffer, PRInt32 aLength,
|
|
|
|
nscoord aX, nscoord aY,
|
1999-07-15 22:19:03 +04:00
|
|
|
nscoord aWidth,
|
|
|
|
SelectionDetails *aDetails = nsnull);
|
1998-10-20 20:46:14 +04:00
|
|
|
|
|
|
|
void MeasureSmallCapsText(const nsHTMLReflowState& aReflowState,
|
1998-10-26 20:27:53 +03:00
|
|
|
TextStyle& aStyle,
|
1998-10-20 20:46:14 +04:00
|
|
|
PRUnichar* aWord,
|
|
|
|
PRInt32 aWordLength,
|
1999-04-20 04:23:33 +04:00
|
|
|
nscoord* aWidthResult);
|
1998-10-20 20:46:14 +04:00
|
|
|
|
1998-10-26 20:27:53 +03:00
|
|
|
void GetWidth(nsIRenderingContext& aRenderingContext,
|
|
|
|
TextStyle& aStyle,
|
|
|
|
PRUnichar* aBuffer, PRInt32 aLength,
|
1999-04-20 04:23:33 +04:00
|
|
|
nscoord* aWidthResult);
|
1998-10-20 20:46:14 +04:00
|
|
|
|
1999-04-20 04:23:33 +04:00
|
|
|
void PaintUnicodeText(nsIPresContext* aPresContext,
|
1998-09-09 02:34:40 +04:00
|
|
|
nsIRenderingContext& aRenderingContext,
|
1998-10-26 20:27:53 +03:00
|
|
|
nsIStyleContext* aStyleContext,
|
|
|
|
TextStyle& aStyle,
|
1998-09-09 02:34:40 +04:00
|
|
|
nscoord dx, nscoord dy);
|
|
|
|
|
1999-04-20 04:23:33 +04:00
|
|
|
void PaintAsciiText(nsIPresContext* aPresContext,
|
1998-09-09 02:34:40 +04:00
|
|
|
nsIRenderingContext& aRenderingContext,
|
1998-10-26 20:27:53 +03:00
|
|
|
nsIStyleContext* aStyleContext,
|
|
|
|
TextStyle& aStyle,
|
1998-09-09 02:34:40 +04:00
|
|
|
nscoord dx, nscoord dy);
|
|
|
|
|
1999-04-20 04:23:33 +04:00
|
|
|
nscoord ComputeTotalWordWidth(nsIPresContext* aPresContext,
|
1999-09-17 03:31:59 +04:00
|
|
|
nsILineBreaker* aLineBreaker,
|
1999-03-29 08:15:07 +04:00
|
|
|
nsLineLayout& aLineLayout,
|
1998-10-10 08:35:21 +04:00
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsIFrame* aNextFrame,
|
1999-07-27 18:47:24 +04:00
|
|
|
nscoord aBaseWidth,
|
|
|
|
const PRUnichar* aWordBuf,
|
|
|
|
PRUint32 aWordBufLen,
|
|
|
|
PRUint32 aWordBufSize);
|
1998-10-10 08:35:21 +04:00
|
|
|
|
1999-04-20 04:23:33 +04:00
|
|
|
nscoord ComputeWordFragmentWidth(nsIPresContext* aPresContext,
|
1999-09-17 03:31:59 +04:00
|
|
|
nsILineBreaker* aLineBreaker,
|
1999-03-29 08:15:07 +04:00
|
|
|
nsLineLayout& aLineLayout,
|
1998-10-10 08:35:21 +04:00
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsIFrame* aNextFrame,
|
1999-09-18 03:14:47 +04:00
|
|
|
nsIContent* aContent,
|
1998-10-10 08:35:21 +04:00
|
|
|
nsITextContent* aText,
|
1999-07-27 18:47:24 +04:00
|
|
|
PRBool* aStop,
|
|
|
|
const PRUnichar* aWordBuf,
|
|
|
|
PRUint32 &aWordBufLen,
|
|
|
|
PRUint32 aWordBufSize);
|
1998-10-10 08:35:21 +04:00
|
|
|
|
1999-04-20 04:23:33 +04:00
|
|
|
void ToCString(nsString& aBuf, PRInt32* aContentLength) const;
|
1998-10-20 04:21:18 +04:00
|
|
|
|
1998-09-09 02:34:40 +04:00
|
|
|
protected:
|
1999-04-20 04:23:33 +04:00
|
|
|
virtual ~nsTextFrame();
|
1998-09-09 02:34:40 +04:00
|
|
|
|
|
|
|
PRInt32 mContentOffset;
|
|
|
|
PRInt32 mContentLength;
|
1998-10-20 04:21:18 +04:00
|
|
|
PRInt32 mColumn;
|
1998-10-27 19:52:34 +03:00
|
|
|
nscoord mComputedWidth;
|
1998-09-09 02:34:40 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
// Flag information used by rendering code. This information is
|
1999-09-01 05:02:16 +04:00
|
|
|
// computed by the ResizeReflow code. The flags are stored in the
|
|
|
|
// mState variable in the frame class private section.
|
1998-10-20 04:21:18 +04:00
|
|
|
|
|
|
|
// Flag indicating that whitespace was skipped
|
1999-09-01 05:02:16 +04:00
|
|
|
#define TEXT_SKIP_LEADING_WS 0x01000000
|
1998-10-20 04:21:18 +04:00
|
|
|
|
1999-09-01 05:02:16 +04:00
|
|
|
#define TEXT_HAS_MULTIBYTE 0x02000000
|
1998-09-09 02:34:40 +04:00
|
|
|
|
1999-09-01 05:02:16 +04:00
|
|
|
#define TEXT_IN_WORD 0x04000000
|
1998-09-09 02:34:40 +04:00
|
|
|
|
1999-09-01 05:02:16 +04:00
|
|
|
#define TEXT_TRIMMED_WS 0x08000000
|
1998-10-27 19:52:34 +03:00
|
|
|
|
1999-03-26 03:41:36 +03:00
|
|
|
// This bit is set on the first frame in a continuation indicating
|
1999-09-01 05:02:16 +04:00
|
|
|
// that it was chopped short because of :first-letter style.
|
|
|
|
#define TEXT_FIRST_LETTER 0x10000000
|
|
|
|
|
|
|
|
// Bits in mState used for reflow flags
|
1999-09-18 20:22:34 +04:00
|
|
|
#define TEXT_REFLOW_FLAGS 0x1F000000
|
1999-09-01 05:02:16 +04:00
|
|
|
|
1999-09-18 20:22:34 +04:00
|
|
|
#define TEXT_OPTIMIZE_RESIZE 0x40000000
|
1999-09-01 05:02:16 +04:00
|
|
|
#define TEXT_BLINK_ON 0x80000000
|
1999-03-26 03:41:36 +03:00
|
|
|
|
1998-09-09 02:34:40 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
nsresult
|
1999-05-12 02:03:29 +04:00
|
|
|
NS_NewTextFrame(nsIFrame** aNewFrame)
|
1998-09-09 02:34:40 +04:00
|
|
|
{
|
1999-05-12 02:03:29 +04:00
|
|
|
NS_PRECONDITION(aNewFrame, "null OUT ptr");
|
|
|
|
if (nsnull == aNewFrame) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
nsTextFrame* it = new nsTextFrame;
|
|
|
|
if (nsnull == it) {
|
1998-09-09 02:34:40 +04:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
1999-05-12 02:03:29 +04:00
|
|
|
*aNewFrame = it;
|
1998-09-09 02:34:40 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-04-20 04:23:33 +04:00
|
|
|
nsTextFrame::nsTextFrame()
|
1998-12-03 09:31:43 +03:00
|
|
|
: nsSplittableFrame()
|
1998-09-09 02:34:40 +04:00
|
|
|
{
|
|
|
|
if (nsnull == gTextBlinker) {
|
|
|
|
// Create text timer the first time out
|
1999-04-20 04:23:33 +04:00
|
|
|
gTextBlinker = new nsBlinkTimer();
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
|
|
|
NS_ADDREF(gTextBlinker);
|
|
|
|
}
|
|
|
|
|
1999-04-20 04:23:33 +04:00
|
|
|
nsTextFrame::~nsTextFrame()
|
1998-09-09 02:34:40 +04:00
|
|
|
{
|
1999-09-01 05:02:16 +04:00
|
|
|
if (0 != (mState & TEXT_BLINK_ON)) {
|
1998-09-09 02:34:40 +04:00
|
|
|
NS_ASSERTION(nsnull != gTextBlinker, "corrupted blinker");
|
|
|
|
gTextBlinker->RemoveFrame(this);
|
|
|
|
}
|
|
|
|
if (0 == gTextBlinker->Release()) {
|
|
|
|
// Release text timer when the last text frame is gone
|
|
|
|
gTextBlinker = nsnull;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-04-20 04:23:33 +04:00
|
|
|
nsIDocument*
|
|
|
|
nsTextFrame::GetDocument(nsIPresContext* aPresContext)
|
|
|
|
{
|
|
|
|
nsIDocument* result = nsnull;
|
|
|
|
if (mContent) {
|
|
|
|
mContent->GetDocument(result);
|
|
|
|
}
|
|
|
|
if (!result && aPresContext) {
|
|
|
|
nsIPresShell* shell;
|
|
|
|
aPresContext->GetShell(&shell);
|
|
|
|
if (shell) {
|
|
|
|
shell->GetDocument(&result);
|
|
|
|
NS_RELEASE(shell);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1998-09-09 02:34:40 +04:00
|
|
|
NS_IMETHODIMP
|
1999-04-20 04:23:33 +04:00
|
|
|
nsTextFrame::GetCursor(nsIPresContext& aPresContext,
|
|
|
|
nsPoint& aPoint,
|
|
|
|
PRInt32& aCursor)
|
1998-09-09 02:34:40 +04:00
|
|
|
{
|
1998-11-18 08:25:26 +03:00
|
|
|
const nsStyleColor* styleColor;
|
|
|
|
GetStyleData(eStyleStruct_Color, (const nsStyleStruct*&)styleColor);
|
|
|
|
aCursor = styleColor->mCursor;
|
|
|
|
|
1999-01-14 08:16:23 +03:00
|
|
|
if (NS_STYLE_CURSOR_AUTO == aCursor && nsnull != mParent) {
|
|
|
|
mParent->GetCursor(aPresContext, aPoint, aCursor);
|
1998-11-18 08:25:26 +03:00
|
|
|
if (NS_STYLE_CURSOR_AUTO == aCursor) {
|
|
|
|
aCursor = NS_STYLE_CURSOR_TEXT;
|
|
|
|
}
|
1998-11-18 05:11:54 +03:00
|
|
|
}
|
1998-09-09 02:34:40 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-04-20 04:23:33 +04:00
|
|
|
nsTextFrame::ContentChanged(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aChild,
|
|
|
|
nsISupports* aSubContent)
|
1998-09-09 02:34:40 +04:00
|
|
|
{
|
|
|
|
// Generate a reflow command with this frame as the target frame
|
|
|
|
nsIReflowCommand* cmd;
|
1999-02-12 20:45:58 +03:00
|
|
|
nsresult rv;
|
1998-09-09 02:34:40 +04:00
|
|
|
|
1999-02-12 20:45:58 +03:00
|
|
|
rv = NS_NewHTMLReflowCommand(&cmd, this, nsIReflowCommand::ContentChanged);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
|
|
|
rv = aPresContext->GetShell(getter_AddRefs(shell));
|
1999-02-12 21:41:26 +03:00
|
|
|
if (NS_SUCCEEDED(rv) && shell) {
|
1999-02-12 20:45:58 +03:00
|
|
|
shell->AppendReflowCommand(cmd);
|
|
|
|
NS_RELEASE(cmd);
|
|
|
|
}
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
|
|
|
|
1999-02-12 20:45:58 +03:00
|
|
|
return rv;
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-04-20 04:23:33 +04:00
|
|
|
nsTextFrame::Paint(nsIPresContext& aPresContext,
|
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
nsFramePaintLayer aWhichLayer)
|
1998-09-09 02:34:40 +04:00
|
|
|
{
|
1999-03-26 03:41:36 +03:00
|
|
|
if (NS_FRAME_PAINT_LAYER_FOREGROUND != aWhichLayer) {
|
1998-12-18 18:54:23 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-09-01 05:02:16 +04:00
|
|
|
if ((0 != (mState & TEXT_BLINK_ON)) && gBlinkTextOff) {
|
1998-09-09 02:34:40 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-10-26 20:27:53 +03:00
|
|
|
nsIStyleContext* sc = mStyleContext;
|
|
|
|
const nsStyleDisplay* disp = (const nsStyleDisplay*)
|
|
|
|
sc->GetStyleData(eStyleStruct_Display);
|
1998-09-09 02:34:40 +04:00
|
|
|
if (disp->mVisible) {
|
1999-04-20 04:23:33 +04:00
|
|
|
TextStyle ts(&aPresContext, aRenderingContext, mStyleContext);
|
1998-10-26 20:27:53 +03:00
|
|
|
if (ts.mSmallCaps || (0 != ts.mWordSpacing) || (0 != ts.mLetterSpacing) ||
|
1998-10-27 19:52:34 +03:00
|
|
|
((NS_STYLE_TEXT_ALIGN_JUSTIFY == ts.mText->mTextAlign) &&
|
|
|
|
(mRect.width > mComputedWidth))) {
|
1999-04-20 04:23:33 +04:00
|
|
|
PaintTextSlowly(&aPresContext, aRenderingContext, sc, ts, 0, 0);
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
|
|
|
else {
|
1998-10-26 20:27:53 +03:00
|
|
|
// Choose rendering pathway based on rendering context
|
|
|
|
// performance hint.
|
1998-10-20 20:46:14 +04:00
|
|
|
PRUint32 hints = 0;
|
|
|
|
aRenderingContext.GetHints(hints);
|
1999-09-01 05:02:16 +04:00
|
|
|
if ((TEXT_HAS_MULTIBYTE & mState) ||
|
1998-10-20 20:46:14 +04:00
|
|
|
(0 == (hints & NS_RENDERING_HINT_FAST_8BIT_TEXT))) {
|
|
|
|
// Use PRUnichar rendering routine
|
1999-04-20 04:23:33 +04:00
|
|
|
PaintUnicodeText(&aPresContext, aRenderingContext, sc, ts, 0, 0);
|
1998-10-20 20:46:14 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Use char rendering routine
|
1999-04-20 04:23:33 +04:00
|
|
|
PaintAsciiText(&aPresContext, aRenderingContext, sc, ts, 0, 0);
|
1998-10-20 20:46:14 +04:00
|
|
|
}
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Prepare the text in the content for rendering. If aIndexes is not nsnull
|
|
|
|
* then fill in aIndexes's with the mapping from the original input to
|
|
|
|
* the prepared output.
|
|
|
|
*/
|
1998-10-27 19:52:34 +03:00
|
|
|
PRIntn
|
1999-04-20 04:23:33 +04:00
|
|
|
nsTextFrame::PrepareUnicodeText(nsTextTransformer& aTX,
|
|
|
|
PRInt32* aIndexes,
|
|
|
|
PRUnichar* aBuffer,
|
|
|
|
PRInt32* aTextLen)
|
1998-09-09 02:34:40 +04:00
|
|
|
{
|
1998-10-27 19:52:34 +03:00
|
|
|
PRIntn numSpaces = 0;
|
1998-10-20 04:21:18 +04:00
|
|
|
PRUnichar* dst = aBuffer;
|
1998-09-09 02:34:40 +04:00
|
|
|
|
1998-10-20 04:21:18 +04:00
|
|
|
// Setup transform to operate starting in the content at our content
|
|
|
|
// offset
|
1999-09-17 03:31:59 +04:00
|
|
|
aTX.Init(this, mContent, mContentOffset);
|
1998-09-09 02:34:40 +04:00
|
|
|
|
|
|
|
PRInt32 strInx = mContentOffset;
|
1998-10-20 04:21:18 +04:00
|
|
|
|
|
|
|
// Skip over the leading whitespace
|
|
|
|
PRInt32 n = mContentLength;
|
1999-09-01 05:02:16 +04:00
|
|
|
if (0 != (mState & TEXT_SKIP_LEADING_WS)) {
|
1998-10-22 00:03:54 +04:00
|
|
|
PRBool isWhitespace;
|
|
|
|
PRInt32 wordLen, contentLen;
|
|
|
|
aTX.GetNextWord(PR_FALSE, wordLen, contentLen, isWhitespace);
|
1999-09-01 05:02:16 +04:00
|
|
|
NS_ASSERTION(isWhitespace, "mState and content are out of sync");
|
1998-10-22 00:03:54 +04:00
|
|
|
if (isWhitespace) {
|
|
|
|
if (nsnull != aIndexes) {
|
|
|
|
// Point mapping indicies at the same content index since
|
|
|
|
// all of the compressed whitespace maps down to the same
|
|
|
|
// renderable character.
|
|
|
|
PRInt32 i = contentLen;
|
|
|
|
while (--i >= 0) {
|
|
|
|
*aIndexes++ = strInx;
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
|
|
|
}
|
1998-10-22 00:03:54 +04:00
|
|
|
n -= contentLen;
|
|
|
|
NS_ASSERTION(n >= 0, "whoops");
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-10-20 04:21:18 +04:00
|
|
|
// Rescan the content and transform it. Stop when we have consumed
|
|
|
|
// mContentLength characters.
|
1999-09-01 05:02:16 +04:00
|
|
|
PRBool inWord = (TEXT_IN_WORD & mState) ? PR_TRUE : PR_FALSE;
|
1998-10-20 04:21:18 +04:00
|
|
|
PRInt32 column = mColumn;
|
|
|
|
PRInt32 textLength = 0;
|
|
|
|
while (0 != n) {
|
|
|
|
PRUnichar* bp;
|
1998-10-22 00:03:54 +04:00
|
|
|
PRBool isWhitespace;
|
1998-10-20 04:21:18 +04:00
|
|
|
PRInt32 wordLen, contentLen;
|
1998-10-22 00:03:54 +04:00
|
|
|
|
|
|
|
// Get the next word
|
|
|
|
bp = aTX.GetNextWord(inWord, wordLen, contentLen, isWhitespace);
|
|
|
|
if (nsnull == bp) {
|
|
|
|
break;
|
|
|
|
}
|
1998-11-12 19:31:38 +03:00
|
|
|
if (contentLen > n) {
|
|
|
|
contentLen = n;
|
|
|
|
}
|
|
|
|
if (wordLen > n) {
|
|
|
|
wordLen = n;
|
|
|
|
}
|
1998-10-22 00:03:54 +04:00
|
|
|
inWord = PR_FALSE;
|
|
|
|
if (isWhitespace) {
|
1998-10-27 19:52:34 +03:00
|
|
|
numSpaces++;
|
1998-10-20 04:21:18 +04:00
|
|
|
if ('\t' == bp[0]) {
|
|
|
|
PRInt32 spaces = 8 - (7 & column);
|
|
|
|
PRUnichar* tp = bp;
|
|
|
|
wordLen = spaces;
|
|
|
|
while (--spaces >= 0) {
|
|
|
|
*tp++ = ' ';
|
|
|
|
}
|
|
|
|
// XXX This is a one to many mapping that I think isn't handled well
|
|
|
|
if (nsnull != aIndexes) {
|
|
|
|
*aIndexes++ = strInx;
|
1999-04-01 00:12:42 +04:00
|
|
|
strInx += wordLen;
|
1998-10-20 04:21:18 +04:00
|
|
|
}
|
1998-09-29 20:24:32 +04:00
|
|
|
}
|
1998-10-22 00:03:54 +04:00
|
|
|
else if (0 == wordLen) {
|
1999-03-27 03:18:32 +03:00
|
|
|
if (nsnull != aIndexes)
|
|
|
|
*aIndexes++ = strInx;
|
1998-10-20 04:21:18 +04:00
|
|
|
break;
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
1998-10-22 00:03:54 +04:00
|
|
|
else if (nsnull != aIndexes) {
|
|
|
|
// Point mapping indicies at the same content index since
|
|
|
|
// all of the compressed whitespace maps down to the same
|
|
|
|
// renderable character.
|
|
|
|
PRInt32 i = contentLen;
|
|
|
|
while (--i >= 0) {
|
1998-10-20 04:21:18 +04:00
|
|
|
*aIndexes++ = strInx;
|
|
|
|
}
|
1998-10-22 00:03:54 +04:00
|
|
|
strInx++;
|
1998-09-29 20:24:32 +04:00
|
|
|
}
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
1998-10-20 04:21:18 +04:00
|
|
|
else {
|
1998-10-22 00:03:54 +04:00
|
|
|
if (nsnull != aIndexes) {
|
|
|
|
// Point mapping indicies at each content index in the word
|
|
|
|
PRInt32 i = contentLen;
|
|
|
|
while (--i >= 0) {
|
|
|
|
*aIndexes++ = strInx++;
|
1998-10-20 04:21:18 +04:00
|
|
|
}
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
|
|
|
}
|
1998-10-22 00:03:54 +04:00
|
|
|
column += wordLen;
|
1998-10-20 04:21:18 +04:00
|
|
|
textLength += wordLen;
|
|
|
|
n -= contentLen;
|
1998-10-22 00:03:54 +04:00
|
|
|
nsCRT::memcpy(dst, bp, sizeof(PRUnichar) * wordLen);
|
|
|
|
dst += wordLen;
|
1998-10-03 04:48:19 +04:00
|
|
|
}
|
|
|
|
|
1998-10-27 19:52:34 +03:00
|
|
|
// Remove trailing whitespace if it was trimmed after reflow
|
1999-09-01 05:02:16 +04:00
|
|
|
if (TEXT_TRIMMED_WS & mState) {
|
1998-10-27 19:52:34 +03:00
|
|
|
if (--dst >= aBuffer) {
|
|
|
|
PRUnichar ch = *dst;
|
|
|
|
if (XP_IS_SPACE(ch)) {
|
1998-10-20 04:21:18 +04:00
|
|
|
textLength--;
|
|
|
|
}
|
|
|
|
}
|
1998-10-27 19:52:34 +03:00
|
|
|
numSpaces--;
|
1998-10-20 04:21:18 +04:00
|
|
|
}
|
1998-10-27 19:52:34 +03:00
|
|
|
|
1999-04-20 04:23:33 +04:00
|
|
|
*aTextLen = textLength;
|
1998-10-27 19:52:34 +03:00
|
|
|
return numSpaces;
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
|
|
|
|
1999-03-31 08:12:46 +04:00
|
|
|
|
1999-04-16 00:42:53 +04:00
|
|
|
//#define SHOW_SELECTION_CURSOR // should be turned off when the caret code is activated
|
1999-02-12 03:05:19 +03:00
|
|
|
|
|
|
|
#ifdef SHOW_SELECTION_CURSOR
|
|
|
|
|
1998-09-09 02:34:40 +04:00
|
|
|
// XXX This clearly needs to be done by the container, *somehow*
|
|
|
|
#define CURSOR_COLOR NS_RGB(0,0,255)
|
|
|
|
static void
|
|
|
|
RenderSelectionCursor(nsIRenderingContext& aRenderingContext,
|
|
|
|
nscoord dx, nscoord dy, nscoord aHeight,
|
|
|
|
nscolor aCursorColor)
|
|
|
|
{
|
|
|
|
nsPoint pnts[4];
|
|
|
|
nscoord ox = aHeight / 4;
|
|
|
|
nscoord oy = ox;
|
|
|
|
nscoord x0 = dx;
|
|
|
|
nscoord y0 = dy + aHeight;
|
|
|
|
pnts[0].x = x0 - ox;
|
|
|
|
pnts[0].y = y0;
|
|
|
|
pnts[1].x = x0;
|
|
|
|
pnts[1].y = y0 - oy;
|
|
|
|
pnts[2].x = x0 + ox;
|
|
|
|
pnts[2].y = y0;
|
|
|
|
pnts[3].x = x0 - ox;
|
|
|
|
pnts[3].y = y0;
|
|
|
|
|
1998-09-09 20:18:40 +04:00
|
|
|
// Draw little blue triangle
|
|
|
|
aRenderingContext.SetColor(aCursorColor);
|
1998-09-09 02:34:40 +04:00
|
|
|
aRenderingContext.FillPolygon(pnts, 4);
|
|
|
|
}
|
|
|
|
|
1999-02-12 03:05:19 +03:00
|
|
|
#endif
|
|
|
|
|
1998-09-09 02:34:40 +04:00
|
|
|
// XXX letter-spacing
|
|
|
|
// XXX word-spacing
|
|
|
|
|
1998-09-17 04:18:25 +04:00
|
|
|
void
|
1999-04-20 04:23:33 +04:00
|
|
|
nsTextFrame::PaintTextDecorations(nsIRenderingContext& aRenderingContext,
|
|
|
|
nsIStyleContext* aStyleContext,
|
|
|
|
TextStyle& aTextStyle,
|
1999-07-15 22:19:03 +04:00
|
|
|
nscoord aX, nscoord aY, nscoord aWidth,
|
|
|
|
PRUnichar *aText, /*=nsnull*/
|
|
|
|
SelectionDetails *aDetails,/*= nsnull*/
|
|
|
|
PRUint32 aIndex, /*= 0*/
|
|
|
|
PRUint32 aLength, /*= 0*/
|
|
|
|
const nscoord* aSpacing /* = nsnull*/ )
|
|
|
|
|
1998-09-17 04:18:25 +04:00
|
|
|
{
|
1998-10-28 05:03:40 +03:00
|
|
|
nscolor overColor;
|
|
|
|
nscolor underColor;
|
|
|
|
nscolor strikeColor;
|
|
|
|
nsIStyleContext* context = aStyleContext;
|
|
|
|
PRUint8 decorations = aTextStyle.mFont->mFont.decorations;
|
|
|
|
PRUint8 decorMask = decorations;
|
|
|
|
|
|
|
|
NS_ADDREF(context);
|
|
|
|
do { // find decoration colors
|
|
|
|
const nsStyleText* styleText =
|
|
|
|
(const nsStyleText*)context->GetStyleData(eStyleStruct_Text);
|
|
|
|
if (decorMask & styleText->mTextDecoration) { // a decoration defined here
|
|
|
|
const nsStyleColor* styleColor =
|
|
|
|
(const nsStyleColor*)context->GetStyleData(eStyleStruct_Color);
|
|
|
|
if (NS_STYLE_TEXT_DECORATION_UNDERLINE & decorMask & styleText->mTextDecoration) {
|
|
|
|
underColor = styleColor->mColor;
|
|
|
|
decorMask &= ~NS_STYLE_TEXT_DECORATION_UNDERLINE;
|
1998-09-17 04:18:25 +04:00
|
|
|
}
|
1998-10-28 05:03:40 +03:00
|
|
|
if (NS_STYLE_TEXT_DECORATION_OVERLINE & decorMask & styleText->mTextDecoration) {
|
|
|
|
overColor = styleColor->mColor;
|
|
|
|
decorMask &= ~NS_STYLE_TEXT_DECORATION_OVERLINE;
|
1998-09-17 04:18:25 +04:00
|
|
|
}
|
1998-10-28 05:03:40 +03:00
|
|
|
if (NS_STYLE_TEXT_DECORATION_LINE_THROUGH & decorMask & styleText->mTextDecoration) {
|
|
|
|
strikeColor = styleColor->mColor;
|
|
|
|
decorMask &= ~NS_STYLE_TEXT_DECORATION_LINE_THROUGH;
|
1998-09-17 04:18:25 +04:00
|
|
|
}
|
|
|
|
}
|
1998-10-28 05:03:40 +03:00
|
|
|
if (0 != decorMask) {
|
|
|
|
nsIStyleContext* lastContext = context;
|
|
|
|
context = context->GetParent();
|
|
|
|
NS_RELEASE(lastContext);
|
|
|
|
}
|
|
|
|
} while ((nsnull != context) && (0 != decorMask));
|
|
|
|
NS_IF_RELEASE(context);
|
|
|
|
|
|
|
|
nscoord offset;
|
|
|
|
nscoord size;
|
|
|
|
nscoord baseline;
|
|
|
|
aTextStyle.mNormalFont->GetMaxAscent(baseline);
|
|
|
|
if (decorations & (NS_FONT_DECORATION_OVERLINE | NS_FONT_DECORATION_UNDERLINE)) {
|
|
|
|
aTextStyle.mNormalFont->GetUnderline(offset, size);
|
|
|
|
if (decorations & NS_FONT_DECORATION_OVERLINE) {
|
|
|
|
aRenderingContext.SetColor(overColor);
|
|
|
|
aRenderingContext.FillRect(aX, aY, aWidth, size);
|
|
|
|
}
|
|
|
|
if (decorations & NS_FONT_DECORATION_UNDERLINE) {
|
|
|
|
aRenderingContext.SetColor(underColor);
|
1998-09-17 04:18:25 +04:00
|
|
|
aRenderingContext.FillRect(aX, aY + baseline - offset, aWidth, size);
|
|
|
|
}
|
1998-10-28 05:03:40 +03:00
|
|
|
}
|
|
|
|
if (decorations & NS_FONT_DECORATION_LINE_THROUGH) {
|
|
|
|
aTextStyle.mNormalFont->GetStrikeout(offset, size);
|
|
|
|
aRenderingContext.SetColor(strikeColor);
|
|
|
|
aRenderingContext.FillRect(aX, aY + baseline - offset, aWidth, size);
|
1998-09-17 04:18:25 +04:00
|
|
|
}
|
1999-07-15 22:19:03 +04:00
|
|
|
if (aDetails){
|
|
|
|
nsRect rect;
|
|
|
|
GetRect(rect);
|
|
|
|
PRInt32 startOffset = 0;
|
|
|
|
PRInt32 textWidth = 0;
|
|
|
|
while(aDetails){
|
|
|
|
PRInt32 start = PR_MAX(0,(aDetails->mStart - (PRInt32)aIndex));
|
|
|
|
PRInt32 end = PR_MIN((PRInt32)aLength,(aDetails->mEnd - (PRInt32)aIndex));
|
|
|
|
PRInt32 i;
|
|
|
|
if (start < end && (aLength - start) > 0)
|
|
|
|
{
|
|
|
|
//aDetails allready processed to have offsets from frame start not content offsets
|
|
|
|
if (start < end){
|
|
|
|
if (aLength == 1)
|
|
|
|
textWidth = aWidth;
|
|
|
|
else {
|
|
|
|
if (aDetails->mStart > 0){
|
|
|
|
if (aSpacing)
|
|
|
|
{
|
|
|
|
for (i = 0; i < start;i ++){
|
|
|
|
startOffset += *aSpacing ++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
aRenderingContext.GetWidth(aText, start, startOffset);
|
|
|
|
}
|
|
|
|
if (aSpacing){
|
|
|
|
for (i = start; i < end;i ++){
|
|
|
|
textWidth += *aSpacing ++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
aRenderingContext.GetWidth(aText + start,
|
|
|
|
PRUint32(end - start), textWidth);
|
|
|
|
|
|
|
|
}
|
|
|
|
switch (aDetails->mType)
|
|
|
|
{
|
|
|
|
case SELECTION_NORMAL:{
|
1999-07-20 11:26:09 +04:00
|
|
|
//
|
|
|
|
// XOR InvertRect is currently implemented only in the unix and windows
|
|
|
|
// rendering contexts. When other platforms implement InvertRect(), they
|
|
|
|
// can be added here. Eventually this #ifdef should die.
|
|
|
|
//
|
|
|
|
// For platforms that dont implement InvertRect(), the selection will be
|
|
|
|
// a non-filled rectangle.
|
1999-07-21 03:38:55 +04:00
|
|
|
#if defined(XP_PC) || defined(XP_UNIX) || defined(XP_MAC)
|
1999-07-20 11:26:09 +04:00
|
|
|
aRenderingContext.SetColor(NS_RGB(255,255,255));
|
|
|
|
aRenderingContext.InvertRect(aX + startOffset, aY, textWidth, rect.height);
|
|
|
|
#else
|
1999-07-15 22:19:03 +04:00
|
|
|
aRenderingContext.SetColor(NS_RGB(0,0,0));
|
|
|
|
aRenderingContext.DrawRect(aX + startOffset, aY, textWidth, rect.height);
|
1999-07-20 11:26:09 +04:00
|
|
|
#endif
|
1999-07-15 22:19:03 +04:00
|
|
|
}break;
|
|
|
|
case SELECTION_SPELLCHECK:{
|
|
|
|
aTextStyle.mNormalFont->GetUnderline(offset, size);
|
|
|
|
aRenderingContext.SetColor(NS_RGB(255,0,0));
|
|
|
|
aRenderingContext.FillRect(aX, aY + baseline - offset, aWidth, size);
|
|
|
|
}break;
|
|
|
|
case SELECTION_IME_SOLID:{
|
|
|
|
aTextStyle.mNormalFont->GetUnderline(offset, size);
|
|
|
|
aRenderingContext.SetColor(NS_RGB(0,0,255));
|
|
|
|
aRenderingContext.FillRect(aX, aY + baseline - offset, aWidth, size);
|
|
|
|
}break;
|
|
|
|
case SELECTION_IME_DASHED:{
|
|
|
|
aTextStyle.mNormalFont->GetUnderline(offset, size);
|
|
|
|
aRenderingContext.SetColor(NS_RGB(128,0,255));
|
|
|
|
aRenderingContext.FillRect(aX, aY + baseline - offset, aWidth, size);
|
|
|
|
}break;
|
1999-09-02 01:40:16 +04:00
|
|
|
default:
|
|
|
|
NS_ASSERTION(0,"what type of selection do i not know about?");
|
|
|
|
break;
|
1999-07-15 22:19:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
aDetails = aDetails->mNext;
|
|
|
|
}
|
|
|
|
}
|
1998-09-17 04:18:25 +04:00
|
|
|
}
|
|
|
|
|
1998-09-09 02:34:40 +04:00
|
|
|
void
|
1999-04-20 04:23:33 +04:00
|
|
|
nsTextFrame::PaintUnicodeText(nsIPresContext* aPresContext,
|
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
nsIStyleContext* aStyleContext,
|
|
|
|
TextStyle& aTextStyle,
|
|
|
|
nscoord dx, nscoord dy)
|
1998-09-09 02:34:40 +04:00
|
|
|
{
|
1999-04-20 04:23:33 +04:00
|
|
|
nsCOMPtr<nsIDocument> doc(getter_AddRefs(GetDocument(aPresContext)));
|
|
|
|
|
1999-09-19 04:59:38 +04:00
|
|
|
PRBool displaySelection;
|
|
|
|
displaySelection = doc->GetDisplaySelection();
|
1998-09-09 02:34:40 +04:00
|
|
|
|
1998-10-20 04:21:18 +04:00
|
|
|
// Make enough space to transform
|
|
|
|
PRUnichar wordBufMem[WORD_BUF_SIZE];
|
|
|
|
PRUnichar paintBufMem[TEXT_BUF_SIZE];
|
|
|
|
PRInt32 indicies[TEXT_BUF_SIZE];
|
1998-09-09 02:34:40 +04:00
|
|
|
PRInt32* ip = indicies;
|
1998-10-20 04:21:18 +04:00
|
|
|
PRUnichar* paintBuf = paintBufMem;
|
|
|
|
if (mContentLength > TEXT_BUF_SIZE) {
|
1999-01-26 02:29:53 +03:00
|
|
|
ip = new PRInt32[mContentLength+1];
|
1998-10-20 04:21:18 +04:00
|
|
|
paintBuf = new PRUnichar[mContentLength];
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
1998-10-03 04:48:19 +04:00
|
|
|
nscoord width = mRect.width;
|
1998-10-20 04:21:18 +04:00
|
|
|
PRInt32 textLength;
|
|
|
|
|
|
|
|
// Transform text from content into renderable form
|
1999-02-24 21:21:23 +03:00
|
|
|
nsCOMPtr<nsILineBreaker> lb;
|
1999-09-19 04:59:38 +04:00
|
|
|
doc->GetLineBreaker(getter_AddRefs(lb));
|
1999-08-10 11:23:56 +04:00
|
|
|
// nsCOMPtr<nsIWordBreaker> wb;
|
|
|
|
// doc->GetWordBreaker(getter_AddRefs(wb));
|
|
|
|
nsTextTransformer tx(wordBufMem, WORD_BUF_SIZE,lb,nsnull);
|
1999-04-20 04:23:33 +04:00
|
|
|
PrepareUnicodeText(tx, (displaySelection ? ip : nsnull),
|
|
|
|
paintBuf, &textLength);
|
1998-10-20 04:21:18 +04:00
|
|
|
PRUnichar* text = paintBuf;
|
1999-04-26 08:02:04 +04:00
|
|
|
nsFrameState frameState;
|
|
|
|
PRBool isSelected;
|
|
|
|
GetFrameState(&frameState);
|
|
|
|
isSelected = (frameState & NS_FRAME_SELECTED_CONTENT) == NS_FRAME_SELECTED_CONTENT;
|
|
|
|
|
1998-09-09 02:34:40 +04:00
|
|
|
if (0 != textLength) {
|
1999-04-26 08:02:04 +04:00
|
|
|
if (!displaySelection || !isSelected ) {
|
1998-09-09 02:34:40 +04:00
|
|
|
// When there is no selection showing, use the fastest and
|
|
|
|
// simplest rendering approach
|
1999-07-08 23:52:57 +04:00
|
|
|
aRenderingContext.SetColor(aTextStyle.mColor->mColor);
|
1999-01-28 08:03:58 +03:00
|
|
|
aRenderingContext.DrawString(text, PRUint32(textLength), dx, dy);
|
1998-10-26 20:27:53 +03:00
|
|
|
PaintTextDecorations(aRenderingContext, aStyleContext, aTextStyle,
|
|
|
|
dx, dy, width);
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
|
|
|
else {
|
1999-03-27 03:18:32 +03:00
|
|
|
ip[mContentLength] = ip[mContentLength-1];
|
1999-04-20 04:23:33 +04:00
|
|
|
if ((ip[mContentLength]-mContentOffset) < textLength) {
|
|
|
|
//must set up last one for selection beyond edge if in boundary
|
1999-03-27 03:18:32 +03:00
|
|
|
ip[mContentLength]++;
|
1999-04-20 04:23:33 +04:00
|
|
|
}
|
1999-07-15 22:19:03 +04:00
|
|
|
SelectionDetails *details = nsnull;
|
1999-04-26 08:02:04 +04:00
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
|
|
|
nsCOMPtr<nsIFrameSelection> frameSelection;
|
|
|
|
|
|
|
|
nsresult rv = aPresContext->GetShell(getter_AddRefs(shell));
|
|
|
|
if (NS_SUCCEEDED(rv) && shell){
|
1999-07-18 06:27:19 +04:00
|
|
|
rv = shell->GetFrameSelection(getter_AddRefs(frameSelection));
|
|
|
|
if (NS_SUCCEEDED(rv) && frameSelection){
|
1999-04-26 08:02:04 +04:00
|
|
|
nsCOMPtr<nsIContent> content;
|
|
|
|
rv = GetContent(getter_AddRefs(content));
|
1999-07-18 06:27:19 +04:00
|
|
|
if (NS_SUCCEEDED(rv) && content){
|
1999-04-26 08:02:04 +04:00
|
|
|
rv = frameSelection->LookUpSelection(content, mContentOffset,
|
1999-07-15 22:19:03 +04:00
|
|
|
mContentLength , &details);// last param notused
|
1999-04-26 08:02:04 +04:00
|
|
|
}
|
|
|
|
}
|
1998-12-14 21:34:14 +03:00
|
|
|
}
|
1999-02-13 07:46:47 +03:00
|
|
|
|
1999-04-26 08:02:04 +04:00
|
|
|
|
1999-07-15 22:19:03 +04:00
|
|
|
//where are the selection points "really"
|
|
|
|
SelectionDetails *sdptr = details;
|
|
|
|
while (sdptr){
|
|
|
|
sdptr->mStart = ip[sdptr->mStart] - mContentOffset;
|
|
|
|
sdptr->mEnd = ip[sdptr->mEnd] - mContentOffset;
|
|
|
|
sdptr = sdptr->mNext;
|
|
|
|
}
|
|
|
|
aRenderingContext.SetColor(aTextStyle.mColor->mColor);
|
|
|
|
aRenderingContext.DrawString(text, PRUint32(textLength), dx, dy);
|
|
|
|
PaintTextDecorations(aRenderingContext, aStyleContext,
|
|
|
|
aTextStyle, dx, dy, width, text, details,0,(PRUint32)textLength);
|
|
|
|
sdptr = details;
|
|
|
|
if (details){
|
1999-08-09 23:15:04 +04:00
|
|
|
while ((sdptr = details->mNext) != nsnull) {
|
1999-07-15 22:19:03 +04:00
|
|
|
delete details;
|
|
|
|
details = sdptr;
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
1999-07-15 22:19:03 +04:00
|
|
|
delete details;
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-07-15 22:19:03 +04:00
|
|
|
|
1998-09-09 02:34:40 +04:00
|
|
|
// Cleanup
|
1998-10-20 04:21:18 +04:00
|
|
|
if (paintBuf != paintBufMem) {
|
|
|
|
delete [] paintBuf;
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
|
|
|
if (ip != indicies) {
|
|
|
|
delete [] ip;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-06-11 01:08:17 +04:00
|
|
|
|
1999-03-13 00:38:16 +03:00
|
|
|
//measure Spaced Textvoid
|
1999-04-20 04:23:33 +04:00
|
|
|
nsresult
|
1999-04-26 08:02:04 +04:00
|
|
|
nsTextFrame::GetPositionSlowly(nsIPresContext& aPresContext,
|
1999-04-20 04:23:33 +04:00
|
|
|
nsIRenderingContext* aRendContext,
|
1999-06-11 01:08:17 +04:00
|
|
|
nscoord aXCoord,
|
1999-05-17 23:50:29 +04:00
|
|
|
nsIContent** aNewContent,
|
1999-04-26 08:02:04 +04:00
|
|
|
PRInt32& aOffset)
|
1999-03-13 00:38:16 +03:00
|
|
|
|
|
|
|
{
|
1999-06-11 01:08:17 +04:00
|
|
|
if (!aRendContext || !aNewContent) {
|
1999-03-13 00:38:16 +03:00
|
|
|
return NS_ERROR_NULL_POINTER;
|
1999-04-20 04:23:33 +04:00
|
|
|
}
|
|
|
|
|
1999-04-26 08:02:04 +04:00
|
|
|
TextStyle ts(&aPresContext, *aRendContext, mStyleContext);
|
1999-04-20 04:23:33 +04:00
|
|
|
if (!ts.mSmallCaps && !ts.mWordSpacing && !ts.mLetterSpacing) {
|
1999-03-13 00:38:16 +03:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
1999-04-20 04:23:33 +04:00
|
|
|
}
|
1999-09-15 03:16:22 +04:00
|
|
|
nsIView * view;
|
|
|
|
nsPoint origin;
|
|
|
|
GetView(&view);
|
|
|
|
GetOffsetFromView(origin, &view);
|
1999-03-13 00:38:16 +03:00
|
|
|
|
1999-09-15 03:16:22 +04:00
|
|
|
if (aXCoord - origin.x <0)
|
|
|
|
{
|
|
|
|
*aNewContent = mContent;
|
|
|
|
aOffset =0;
|
|
|
|
}
|
1999-04-26 08:02:04 +04:00
|
|
|
nsCOMPtr<nsIDocument> doc(getter_AddRefs(GetDocument(&aPresContext)));
|
1999-03-13 00:38:16 +03:00
|
|
|
|
|
|
|
// Make enough space to transform
|
|
|
|
PRUnichar paintBufMem[TEXT_BUF_SIZE];
|
|
|
|
PRInt32 indicies[TEXT_BUF_SIZE];
|
|
|
|
PRUnichar wordBufMem[WORD_BUF_SIZE];
|
|
|
|
PRInt32* ip = indicies;
|
|
|
|
PRUnichar* paintBuf = paintBufMem;
|
|
|
|
if (mContentLength > TEXT_BUF_SIZE) {
|
|
|
|
ip = new PRInt32[mContentLength+1];
|
|
|
|
paintBuf = new PRUnichar[mContentLength];
|
|
|
|
}
|
|
|
|
PRInt32 textLength;
|
1999-09-15 03:16:22 +04:00
|
|
|
PRInt32 actualLength;
|
1999-03-13 00:38:16 +03:00
|
|
|
|
|
|
|
// Transform text from content into renderable form
|
|
|
|
nsCOMPtr<nsILineBreaker> lb;
|
|
|
|
doc->GetLineBreaker(getter_AddRefs(lb));
|
1999-08-10 11:23:56 +04:00
|
|
|
//nsCOMPtr<nsIWordBreaker> wb;
|
|
|
|
//doc->GetWordBreaker(getter_AddRefs(wb));
|
|
|
|
nsTextTransformer tx(wordBufMem, WORD_BUF_SIZE, lb,nsnull);
|
1999-04-20 04:23:33 +04:00
|
|
|
PrepareUnicodeText(tx, ip, paintBuf, &textLength);
|
1999-06-20 00:36:44 +04:00
|
|
|
if (textLength <= 0)
|
|
|
|
return NS_ERROR_FAILURE;
|
1999-09-15 03:16:22 +04:00
|
|
|
actualLength = textLength;
|
1999-03-13 00:38:16 +03:00
|
|
|
|
|
|
|
nscoord charWidth,widthsofar = 0;
|
1999-09-01 05:02:16 +04:00
|
|
|
PRInt32 indx = 0;
|
1999-03-13 00:38:16 +03:00
|
|
|
PRBool found = PR_FALSE;
|
|
|
|
PRUnichar* startBuf = paintBuf;
|
|
|
|
nsIFontMetrics* lastFont = ts.mLastFont;
|
1999-09-01 05:02:16 +04:00
|
|
|
for (; --textLength >= 0; paintBuf++,indx++) {
|
1999-03-13 00:38:16 +03:00
|
|
|
nsIFontMetrics* nextFont;
|
|
|
|
nscoord glyphWidth;
|
|
|
|
PRUnichar ch = *paintBuf;
|
|
|
|
if (ts.mSmallCaps && nsCRT::IsLower(ch)) {
|
|
|
|
nextFont = ts.mSmallFont;
|
|
|
|
ch = nsCRT::ToUpper(ch);
|
|
|
|
if (lastFont != ts.mSmallFont) {
|
|
|
|
aRendContext->SetFont(ts.mSmallFont);
|
|
|
|
aRendContext->GetWidth(ch, charWidth);
|
|
|
|
aRendContext->SetFont(ts.mNormalFont);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
aRendContext->GetWidth(ch, charWidth);
|
|
|
|
}
|
|
|
|
glyphWidth = charWidth + ts.mLetterSpacing;
|
|
|
|
}
|
|
|
|
else if (ch == ' ') {
|
1999-04-28 02:13:42 +04:00
|
|
|
nextFont = lastFont;
|
1999-03-13 00:38:16 +03:00
|
|
|
glyphWidth = ts.mSpaceWidth + ts.mWordSpacing;
|
|
|
|
nscoord extra = ts.mExtraSpacePerSpace;
|
|
|
|
if (--ts.mNumSpaces == 0) {
|
|
|
|
extra += ts.mRemainingExtraSpace;
|
|
|
|
}
|
|
|
|
glyphWidth += extra;
|
|
|
|
}
|
|
|
|
else {
|
1999-04-28 02:13:42 +04:00
|
|
|
nextFont = lastFont;
|
1999-03-13 00:38:16 +03:00
|
|
|
aRendContext->GetWidth(ch, charWidth);
|
|
|
|
glyphWidth = charWidth + ts.mLetterSpacing;
|
|
|
|
}
|
1999-06-11 01:08:17 +04:00
|
|
|
if ((aXCoord - origin.x) >= widthsofar && (aXCoord - origin.x) <= (widthsofar + glyphWidth)){
|
|
|
|
if ( ((aXCoord - origin.x) - widthsofar) <= (glyphWidth /2)){
|
1999-09-01 05:02:16 +04:00
|
|
|
aOffset = indx;
|
1999-03-13 00:38:16 +03:00
|
|
|
found = PR_TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else{
|
1999-09-01 05:02:16 +04:00
|
|
|
aOffset = indx+1;
|
1999-03-13 00:38:16 +03:00
|
|
|
found = PR_TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
if (nextFont != lastFont)
|
|
|
|
lastFont = nextFont;
|
|
|
|
|
|
|
|
widthsofar += glyphWidth;
|
|
|
|
}
|
|
|
|
paintBuf = startBuf;
|
|
|
|
if (!found){
|
1999-04-26 08:02:04 +04:00
|
|
|
aOffset = textLength;
|
1999-09-15 03:16:22 +04:00
|
|
|
if (aOffset <0)
|
|
|
|
aOffset = actualLength;//max length before textlength was reduced
|
1999-03-13 00:38:16 +03:00
|
|
|
}
|
1999-06-11 01:08:17 +04:00
|
|
|
aOffset += mContentOffset;//offset;//((nsTextFrame *)aNewFrame)->mContentOffset;
|
1999-03-13 00:38:16 +03:00
|
|
|
PRInt32 i;
|
|
|
|
for (i = 0;i <= mContentLength; i ++){
|
1999-06-11 01:08:17 +04:00
|
|
|
if (ip[i] == aOffset){ //reverse mapping
|
1999-06-11 01:55:14 +04:00
|
|
|
aOffset = i + mContentOffset;
|
1999-04-20 04:23:33 +04:00
|
|
|
break;
|
1999-03-13 00:38:16 +03:00
|
|
|
}
|
|
|
|
}
|
1999-04-20 04:23:33 +04:00
|
|
|
|
1999-03-13 00:38:16 +03:00
|
|
|
// Cleanup
|
|
|
|
if (paintBuf != paintBufMem) {
|
|
|
|
delete [] paintBuf;
|
|
|
|
}
|
|
|
|
if (ip != indicies) {
|
|
|
|
delete [] ip;
|
|
|
|
}
|
1999-05-17 23:50:29 +04:00
|
|
|
*aNewContent = mContent;
|
|
|
|
if (*aNewContent)
|
|
|
|
(*aNewContent)->AddRef();
|
1999-03-13 00:38:16 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-10-20 20:46:14 +04:00
|
|
|
void
|
1999-04-20 04:23:33 +04:00
|
|
|
nsTextFrame::RenderString(nsIRenderingContext& aRenderingContext,
|
|
|
|
nsIStyleContext* aStyleContext,
|
|
|
|
TextStyle& aTextStyle,
|
|
|
|
PRUnichar* aBuffer, PRInt32 aLength,
|
|
|
|
nscoord aX, nscoord aY,
|
1999-07-15 22:19:03 +04:00
|
|
|
nscoord aWidth,
|
|
|
|
SelectionDetails *aDetails /*=nsnull*/)
|
1998-10-20 20:46:14 +04:00
|
|
|
{
|
|
|
|
PRUnichar buf[TEXT_BUF_SIZE];
|
|
|
|
PRUnichar* bp0 = buf;
|
|
|
|
if (aLength > TEXT_BUF_SIZE) {
|
|
|
|
bp0 = new PRUnichar[aLength];
|
|
|
|
}
|
|
|
|
PRUnichar* bp = bp0;
|
|
|
|
|
1998-10-26 20:27:53 +03:00
|
|
|
PRBool spacing = (0 != aTextStyle.mLetterSpacing) ||
|
1998-10-27 19:52:34 +03:00
|
|
|
(0 != aTextStyle.mWordSpacing) || (mRect.width > mComputedWidth);
|
1998-10-26 20:27:53 +03:00
|
|
|
nscoord spacingMem[TEXT_BUF_SIZE];
|
|
|
|
PRIntn* sp0 = spacingMem;
|
|
|
|
if (spacing && (aLength > TEXT_BUF_SIZE)) {
|
|
|
|
sp0 = new nscoord[aLength];
|
|
|
|
}
|
|
|
|
PRIntn* sp = sp0;
|
|
|
|
|
|
|
|
nscoord smallY = aY;
|
|
|
|
if (aTextStyle.mSmallCaps) {
|
|
|
|
nscoord normalAscent, smallAscent;
|
|
|
|
aTextStyle.mNormalFont->GetMaxAscent(normalAscent);
|
|
|
|
aTextStyle.mSmallFont->GetMaxAscent(smallAscent);
|
|
|
|
if (normalAscent > smallAscent) {
|
|
|
|
smallY = aY + normalAscent - smallAscent;
|
|
|
|
}
|
1998-10-20 20:46:14 +04:00
|
|
|
}
|
|
|
|
|
1998-10-26 20:27:53 +03:00
|
|
|
nsIFontMetrics* lastFont = aTextStyle.mLastFont;
|
|
|
|
nscoord lastY = aY;
|
|
|
|
if (lastFont == aTextStyle.mSmallFont) {
|
|
|
|
lastY = smallY;
|
|
|
|
}
|
1998-10-20 20:46:14 +04:00
|
|
|
PRInt32 pendingCount;
|
|
|
|
PRUnichar* runStart = bp;
|
1998-10-26 20:27:53 +03:00
|
|
|
nscoord charWidth, width = 0;
|
1999-07-15 22:19:03 +04:00
|
|
|
PRInt32 countSoFar = 0;
|
1998-10-20 20:46:14 +04:00
|
|
|
for (; --aLength >= 0; aBuffer++) {
|
|
|
|
nsIFontMetrics* nextFont;
|
1998-10-26 20:27:53 +03:00
|
|
|
nscoord nextY, glyphWidth;
|
1998-10-20 20:46:14 +04:00
|
|
|
PRUnichar ch = *aBuffer;
|
1999-03-02 21:25:22 +03:00
|
|
|
if (aTextStyle.mSmallCaps && nsCRT::IsLower(ch)) {
|
1998-10-26 20:27:53 +03:00
|
|
|
nextFont = aTextStyle.mSmallFont;
|
|
|
|
nextY = smallY;
|
1999-03-02 21:25:22 +03:00
|
|
|
ch = nsCRT::ToUpper(ch);
|
1998-10-26 20:27:53 +03:00
|
|
|
if (lastFont != aTextStyle.mSmallFont) {
|
|
|
|
aRenderingContext.SetFont(aTextStyle.mSmallFont);
|
|
|
|
aRenderingContext.GetWidth(ch, charWidth);
|
|
|
|
aRenderingContext.SetFont(aTextStyle.mNormalFont);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
aRenderingContext.GetWidth(ch, charWidth);
|
|
|
|
}
|
|
|
|
glyphWidth = charWidth + aTextStyle.mLetterSpacing;
|
|
|
|
}
|
|
|
|
else if (ch == ' ') {
|
|
|
|
nextFont = aTextStyle.mNormalFont;
|
|
|
|
nextY = aY;
|
|
|
|
glyphWidth = aTextStyle.mSpaceWidth + aTextStyle.mWordSpacing;
|
1998-10-27 19:52:34 +03:00
|
|
|
nscoord extra = aTextStyle.mExtraSpacePerSpace;
|
|
|
|
if (--aTextStyle.mNumSpaces == 0) {
|
|
|
|
extra += aTextStyle.mRemainingExtraSpace;
|
|
|
|
}
|
|
|
|
glyphWidth += extra;
|
1998-10-20 20:46:14 +04:00
|
|
|
}
|
|
|
|
else {
|
1998-10-26 20:27:53 +03:00
|
|
|
if (lastFont != aTextStyle.mNormalFont) {
|
|
|
|
aRenderingContext.SetFont(aTextStyle.mNormalFont);
|
|
|
|
aRenderingContext.GetWidth(ch, charWidth);
|
|
|
|
aRenderingContext.SetFont(aTextStyle.mSmallFont);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
aRenderingContext.GetWidth(ch, charWidth);
|
|
|
|
}
|
|
|
|
nextFont = aTextStyle.mNormalFont;
|
|
|
|
nextY = aY;
|
|
|
|
glyphWidth = charWidth + aTextStyle.mLetterSpacing;
|
1998-10-20 20:46:14 +04:00
|
|
|
}
|
|
|
|
if (nextFont != lastFont) {
|
|
|
|
pendingCount = bp - runStart;
|
|
|
|
if (0 != pendingCount) {
|
|
|
|
// Measure previous run of characters using the previous font
|
1999-07-08 23:52:57 +04:00
|
|
|
aRenderingContext.SetColor(aTextStyle.mColor->mColor);
|
1998-10-26 20:27:53 +03:00
|
|
|
aRenderingContext.DrawString(runStart, pendingCount,
|
1999-01-28 08:03:58 +03:00
|
|
|
aX, lastY, -1,
|
1998-10-26 20:27:53 +03:00
|
|
|
spacing ? sp0 : nsnull);
|
1998-10-28 05:03:40 +03:00
|
|
|
|
|
|
|
// Note: use aY not small-y so that decorations are drawn with
|
|
|
|
// respect to the normal-font not the current font.
|
1998-10-26 20:27:53 +03:00
|
|
|
PaintTextDecorations(aRenderingContext, aStyleContext, aTextStyle,
|
1999-07-15 22:19:03 +04:00
|
|
|
aX, aY, width, runStart, aDetails,countSoFar,pendingCount, spacing ? sp0 : nsnull);
|
|
|
|
countSoFar += pendingCount;
|
1998-10-27 19:52:34 +03:00
|
|
|
aWidth -= width;
|
1998-10-26 20:27:53 +03:00
|
|
|
aX += width;
|
|
|
|
runStart = bp = bp0;
|
|
|
|
sp = sp0;
|
|
|
|
width = 0;
|
1998-10-20 20:46:14 +04:00
|
|
|
}
|
|
|
|
aRenderingContext.SetFont(nextFont);
|
|
|
|
lastFont = nextFont;
|
1998-10-26 20:27:53 +03:00
|
|
|
lastY = nextY;
|
1998-10-20 20:46:14 +04:00
|
|
|
}
|
|
|
|
*bp++ = ch;
|
1998-10-26 20:27:53 +03:00
|
|
|
*sp++ = glyphWidth;
|
|
|
|
width += glyphWidth;
|
1998-10-20 20:46:14 +04:00
|
|
|
}
|
|
|
|
pendingCount = bp - runStart;
|
|
|
|
if (0 != pendingCount) {
|
|
|
|
// Measure previous run of characters using the previous font
|
1999-07-08 23:52:57 +04:00
|
|
|
aRenderingContext.SetColor(aTextStyle.mColor->mColor);
|
1999-01-28 08:03:58 +03:00
|
|
|
aRenderingContext.DrawString(runStart, pendingCount, aX, lastY, -1,
|
1998-10-26 20:27:53 +03:00
|
|
|
spacing ? sp0 : nsnull);
|
1998-10-28 05:03:40 +03:00
|
|
|
|
|
|
|
// Note: use aY not small-y so that decorations are drawn with
|
|
|
|
// respect to the normal-font not the current font.
|
1998-10-26 20:27:53 +03:00
|
|
|
PaintTextDecorations(aRenderingContext, aStyleContext, aTextStyle,
|
1999-07-15 22:19:03 +04:00
|
|
|
aX, aY, aWidth, runStart, aDetails,countSoFar,pendingCount,
|
|
|
|
spacing ? sp0 : nsnull);
|
1998-10-20 20:46:14 +04:00
|
|
|
}
|
1998-10-26 20:27:53 +03:00
|
|
|
aTextStyle.mLastFont = lastFont;
|
1998-10-20 20:46:14 +04:00
|
|
|
|
|
|
|
if (bp0 != buf) {
|
|
|
|
delete [] bp0;
|
|
|
|
}
|
1998-10-26 20:27:53 +03:00
|
|
|
if (sp0 != spacingMem) {
|
|
|
|
delete [] sp0;
|
|
|
|
}
|
1998-10-20 20:46:14 +04:00
|
|
|
}
|
|
|
|
|
1998-10-26 20:27:53 +03:00
|
|
|
inline void
|
1999-04-20 04:23:33 +04:00
|
|
|
nsTextFrame::MeasureSmallCapsText(const nsHTMLReflowState& aReflowState,
|
|
|
|
TextStyle& aTextStyle,
|
|
|
|
PRUnichar* aWord,
|
|
|
|
PRInt32 aWordLength,
|
|
|
|
nscoord* aWidthResult)
|
1998-10-20 20:46:14 +04:00
|
|
|
{
|
|
|
|
nsIRenderingContext& rc = *aReflowState.rendContext;
|
1998-10-26 20:27:53 +03:00
|
|
|
GetWidth(rc, aTextStyle, aWord, aWordLength, aWidthResult);
|
|
|
|
if (aTextStyle.mLastFont != aTextStyle.mNormalFont) {
|
|
|
|
rc.SetFont(aTextStyle.mNormalFont);
|
|
|
|
aTextStyle.mLastFont = aTextStyle.mNormalFont;
|
1998-10-20 20:46:14 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-10-27 19:52:34 +03:00
|
|
|
// XXX factor in logic from RenderString into here; gaps, justification, etc.
|
1998-10-20 20:46:14 +04:00
|
|
|
void
|
1999-04-20 04:23:33 +04:00
|
|
|
nsTextFrame::GetWidth(nsIRenderingContext& aRenderingContext,
|
|
|
|
TextStyle& aTextStyle,
|
|
|
|
PRUnichar* aBuffer, PRInt32 aLength,
|
|
|
|
nscoord* aWidthResult)
|
1998-10-20 20:46:14 +04:00
|
|
|
{
|
|
|
|
PRUnichar buf[TEXT_BUF_SIZE];
|
|
|
|
PRUnichar* bp0 = buf;
|
|
|
|
if (aLength > TEXT_BUF_SIZE) {
|
|
|
|
bp0 = new PRUnichar[aLength];
|
|
|
|
}
|
|
|
|
PRUnichar* bp = bp0;
|
|
|
|
|
1998-10-26 20:27:53 +03:00
|
|
|
nsIFontMetrics* lastFont = aTextStyle.mLastFont;
|
1999-03-13 00:38:16 +03:00
|
|
|
nscoord sum = 0;
|
|
|
|
nscoord charWidth;
|
1998-10-20 20:46:14 +04:00
|
|
|
for (; --aLength >= 0; aBuffer++) {
|
1999-03-19 00:02:40 +03:00
|
|
|
nscoord glyphWidth;
|
1998-10-20 20:46:14 +04:00
|
|
|
PRUnichar ch = *aBuffer;
|
1999-03-02 21:25:22 +03:00
|
|
|
if (aTextStyle.mSmallCaps && nsCRT::IsLower(ch)) {
|
|
|
|
ch = nsCRT::ToUpper(ch);
|
1999-03-13 00:38:16 +03:00
|
|
|
if (lastFont != aTextStyle.mSmallFont) {
|
1999-03-19 00:02:40 +03:00
|
|
|
lastFont = aTextStyle.mSmallFont;
|
|
|
|
aRenderingContext.SetFont(lastFont);
|
1999-03-13 00:38:16 +03:00
|
|
|
}
|
1999-03-19 00:02:40 +03:00
|
|
|
aRenderingContext.GetWidth(ch, charWidth);
|
1999-03-13 00:38:16 +03:00
|
|
|
glyphWidth = charWidth + aTextStyle.mLetterSpacing;
|
1998-10-20 20:46:14 +04:00
|
|
|
}
|
1999-03-13 00:38:16 +03:00
|
|
|
else if (ch == ' ') {
|
|
|
|
glyphWidth = aTextStyle.mSpaceWidth + aTextStyle.mWordSpacing;
|
|
|
|
nscoord extra = aTextStyle.mExtraSpacePerSpace;
|
|
|
|
if (--aTextStyle.mNumSpaces == 0) {
|
|
|
|
extra += aTextStyle.mRemainingExtraSpace;
|
|
|
|
}
|
|
|
|
glyphWidth += extra;
|
1998-10-20 20:46:14 +04:00
|
|
|
}
|
1999-03-13 00:38:16 +03:00
|
|
|
else {
|
|
|
|
if (lastFont != aTextStyle.mNormalFont) {
|
1999-03-19 00:02:40 +03:00
|
|
|
lastFont = aTextStyle.mNormalFont;
|
|
|
|
aRenderingContext.SetFont(lastFont);
|
1998-10-20 20:46:14 +04:00
|
|
|
}
|
1999-03-19 00:02:40 +03:00
|
|
|
aRenderingContext.GetWidth(ch, charWidth);
|
1999-03-13 00:38:16 +03:00
|
|
|
glyphWidth = charWidth + aTextStyle.mLetterSpacing;
|
1998-10-20 20:46:14 +04:00
|
|
|
}
|
1999-03-13 00:38:16 +03:00
|
|
|
sum += glyphWidth;
|
1998-10-20 20:46:14 +04:00
|
|
|
*bp++ = ch;
|
|
|
|
}
|
|
|
|
if (bp0 != buf) {
|
|
|
|
delete [] bp0;
|
|
|
|
}
|
1998-10-26 20:27:53 +03:00
|
|
|
aTextStyle.mLastFont = lastFont;
|
1999-04-20 04:23:33 +04:00
|
|
|
*aWidthResult = sum;
|
1998-10-20 20:46:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-04-20 04:23:33 +04:00
|
|
|
nsTextFrame::PaintTextSlowly(nsIPresContext* aPresContext,
|
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
nsIStyleContext* aStyleContext,
|
|
|
|
TextStyle& aTextStyle,
|
|
|
|
nscoord dx, nscoord dy)
|
1998-10-20 20:46:14 +04:00
|
|
|
{
|
1999-04-20 04:23:33 +04:00
|
|
|
nsCOMPtr<nsIDocument> doc(getter_AddRefs(GetDocument(aPresContext)));
|
|
|
|
|
1998-10-20 20:46:14 +04:00
|
|
|
PRBool displaySelection;
|
|
|
|
displaySelection = doc->GetDisplaySelection();
|
|
|
|
|
|
|
|
// Make enough space to transform
|
|
|
|
PRUnichar wordBufMem[WORD_BUF_SIZE];
|
|
|
|
PRUnichar paintBufMem[TEXT_BUF_SIZE];
|
|
|
|
PRInt32 indicies[TEXT_BUF_SIZE];
|
|
|
|
PRInt32* ip = indicies;
|
|
|
|
PRUnichar* paintBuf = paintBufMem;
|
|
|
|
if (mContentLength > TEXT_BUF_SIZE) {
|
1999-02-20 02:47:36 +03:00
|
|
|
ip = new PRInt32[mContentLength+1];
|
1998-10-20 20:46:14 +04:00
|
|
|
paintBuf = new PRUnichar[mContentLength];
|
|
|
|
}
|
|
|
|
nscoord width = mRect.width;
|
|
|
|
PRInt32 textLength;
|
|
|
|
|
|
|
|
// Transform text from content into renderable form
|
1999-02-24 21:21:23 +03:00
|
|
|
nsCOMPtr<nsILineBreaker> lb;
|
|
|
|
doc->GetLineBreaker(getter_AddRefs(lb));
|
1999-08-10 11:23:56 +04:00
|
|
|
//nsCOMPtr<nsIWordBreaker> wb;
|
|
|
|
//doc->GetWordBreaker(getter_AddRefs(wb));
|
|
|
|
nsTextTransformer tx(wordBufMem, WORD_BUF_SIZE, lb,nsnull);
|
1999-02-10 21:55:25 +03:00
|
|
|
aTextStyle.mNumSpaces = PrepareUnicodeText(tx,
|
1998-10-27 19:52:34 +03:00
|
|
|
displaySelection ? ip : nsnull,
|
1999-04-20 04:23:33 +04:00
|
|
|
paintBuf, &textLength);
|
1998-10-27 19:52:34 +03:00
|
|
|
if (mRect.width > mComputedWidth) {
|
|
|
|
if (0 != aTextStyle.mNumSpaces) {
|
|
|
|
nscoord extra = mRect.width - mComputedWidth;
|
1999-02-12 20:45:58 +03:00
|
|
|
#if XXX
|
1998-10-27 19:52:34 +03:00
|
|
|
nscoord adjustPerSpace =
|
|
|
|
aTextStyle.mExtraSpacePerSpace = extra / aTextStyle.mNumSpaces;
|
1999-02-12 20:45:58 +03:00
|
|
|
#endif
|
1998-10-27 19:52:34 +03:00
|
|
|
aTextStyle.mRemainingExtraSpace = extra -
|
|
|
|
(aTextStyle.mExtraSpacePerSpace * aTextStyle.mNumSpaces);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// We have no whitespace but were given some extra space. There
|
|
|
|
// are two plausible places to put the extra space: to the left
|
|
|
|
// and to the right. If this is anywhere but the last place on
|
|
|
|
// the line then the correct answer is to the right.
|
|
|
|
}
|
|
|
|
}
|
1998-10-20 20:46:14 +04:00
|
|
|
|
|
|
|
PRUnichar* text = paintBuf;
|
1999-04-26 08:02:04 +04:00
|
|
|
nsFrameState frameState;
|
|
|
|
PRBool isSelected;
|
|
|
|
GetFrameState(&frameState);
|
|
|
|
isSelected = (frameState & NS_FRAME_SELECTED_CONTENT) == NS_FRAME_SELECTED_CONTENT;
|
1998-10-20 20:46:14 +04:00
|
|
|
if (0 != textLength) {
|
1999-04-26 08:02:04 +04:00
|
|
|
if (!displaySelection || !isSelected) {
|
1998-10-20 20:46:14 +04:00
|
|
|
// When there is no selection showing, use the fastest and
|
|
|
|
// simplest rendering approach
|
1998-10-26 20:27:53 +03:00
|
|
|
RenderString(aRenderingContext, aStyleContext, aTextStyle,
|
|
|
|
text, textLength, dx, dy, width);
|
1998-10-20 20:46:14 +04:00
|
|
|
}
|
|
|
|
else {
|
1999-07-15 22:19:03 +04:00
|
|
|
SelectionDetails *details = nsnull;
|
1999-03-27 03:18:32 +03:00
|
|
|
ip[mContentLength] = ip[mContentLength-1];
|
1999-04-26 08:02:04 +04:00
|
|
|
if ((ip[mContentLength]-mContentOffset) < textLength) {
|
|
|
|
//must set up last one for selection beyond edge if in boundary
|
1999-03-27 03:18:32 +03:00
|
|
|
ip[mContentLength]++;
|
1999-02-20 02:47:36 +03:00
|
|
|
}
|
1999-04-26 08:02:04 +04:00
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
|
|
|
nsCOMPtr<nsIFrameSelection> frameSelection;
|
|
|
|
nsresult rv = aPresContext->GetShell(getter_AddRefs(shell));
|
|
|
|
if (NS_SUCCEEDED(rv) && shell){
|
1999-07-18 06:27:19 +04:00
|
|
|
rv = shell->GetFrameSelection(getter_AddRefs(frameSelection));
|
|
|
|
if (NS_SUCCEEDED(rv) && frameSelection){
|
1999-04-26 08:02:04 +04:00
|
|
|
nsCOMPtr<nsIContent> content;
|
|
|
|
rv = GetContent(getter_AddRefs(content));
|
|
|
|
if (NS_SUCCEEDED(rv)){
|
|
|
|
rv = frameSelection->LookUpSelection(content, mContentOffset,
|
1999-07-15 22:19:03 +04:00
|
|
|
mContentLength , &details);// last param notused
|
1999-04-26 08:02:04 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-02-13 07:46:47 +03:00
|
|
|
|
1999-07-15 22:19:03 +04:00
|
|
|
//where are the selection points "really"
|
|
|
|
SelectionDetails *sdptr = details;
|
|
|
|
while (sdptr){
|
|
|
|
sdptr->mStart = ip[sdptr->mStart] - mContentOffset;
|
|
|
|
sdptr->mEnd = ip[sdptr->mEnd] - mContentOffset;
|
|
|
|
sdptr = sdptr->mNext;
|
|
|
|
}
|
|
|
|
aRenderingContext.SetColor(aTextStyle.mColor->mColor);
|
|
|
|
RenderString(aRenderingContext,aStyleContext, aTextStyle, text,
|
|
|
|
PRUint32(textLength), dx, dy, width, details);
|
|
|
|
sdptr = details;
|
|
|
|
if (details){
|
1999-08-09 23:15:04 +04:00
|
|
|
while ((sdptr = details->mNext) != nsnull) {
|
1999-07-15 22:19:03 +04:00
|
|
|
delete details;
|
|
|
|
details = sdptr;
|
1998-10-20 20:46:14 +04:00
|
|
|
}
|
1999-07-15 22:19:03 +04:00
|
|
|
delete details;
|
1998-10-20 20:46:14 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Cleanup
|
|
|
|
if (paintBuf != paintBufMem) {
|
|
|
|
delete [] paintBuf;
|
|
|
|
}
|
|
|
|
if (ip != indicies) {
|
|
|
|
delete [] ip;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-09-09 02:34:40 +04:00
|
|
|
void
|
1999-04-20 04:23:33 +04:00
|
|
|
nsTextFrame::PaintAsciiText(nsIPresContext* aPresContext,
|
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
nsIStyleContext* aStyleContext,
|
|
|
|
TextStyle& aTextStyle,
|
|
|
|
nscoord dx, nscoord dy)
|
1998-09-09 02:34:40 +04:00
|
|
|
{
|
1999-04-20 04:23:33 +04:00
|
|
|
nsCOMPtr<nsIDocument> doc(getter_AddRefs(GetDocument(aPresContext)));
|
|
|
|
|
1998-09-09 02:34:40 +04:00
|
|
|
PRBool displaySelection;
|
|
|
|
displaySelection = doc->GetDisplaySelection();
|
|
|
|
|
1998-10-20 04:21:18 +04:00
|
|
|
// Make enough space to transform
|
|
|
|
PRUnichar wordBufMem[WORD_BUF_SIZE];
|
|
|
|
char paintBufMem[TEXT_BUF_SIZE];
|
1998-10-22 00:03:54 +04:00
|
|
|
PRUnichar rawPaintBufMem[TEXT_BUF_SIZE];
|
1998-10-20 04:21:18 +04:00
|
|
|
PRInt32 indicies[TEXT_BUF_SIZE];
|
1998-09-09 02:34:40 +04:00
|
|
|
PRInt32* ip = indicies;
|
1998-10-20 04:21:18 +04:00
|
|
|
char* paintBuf = paintBufMem;
|
1998-10-22 00:03:54 +04:00
|
|
|
PRUnichar* rawPaintBuf = rawPaintBufMem;
|
1998-10-20 04:21:18 +04:00
|
|
|
if (mContentLength > TEXT_BUF_SIZE) {
|
1998-09-09 02:34:40 +04:00
|
|
|
ip = new PRInt32[mContentLength];
|
1998-10-20 04:21:18 +04:00
|
|
|
paintBuf = new char[mContentLength];
|
1998-10-22 00:03:54 +04:00
|
|
|
rawPaintBuf = new PRUnichar[mContentLength];
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
1998-10-03 04:48:19 +04:00
|
|
|
nscoord width = mRect.width;
|
1998-10-20 04:21:18 +04:00
|
|
|
PRInt32 textLength;
|
|
|
|
|
|
|
|
// Transform text from content into renderable form
|
1999-02-24 21:21:23 +03:00
|
|
|
nsCOMPtr<nsILineBreaker> lb;
|
|
|
|
doc->GetLineBreaker(getter_AddRefs(lb));
|
1999-08-10 11:23:56 +04:00
|
|
|
//nsCOMPtr<nsIWordBreaker> wb;
|
|
|
|
//doc->GetWordBreaker(getter_AddRefs(wb));
|
|
|
|
nsTextTransformer tx(wordBufMem, WORD_BUF_SIZE,lb,nsnull);
|
1999-04-20 04:23:33 +04:00
|
|
|
PrepareUnicodeText(tx, (displaySelection ? ip : nsnull),
|
|
|
|
rawPaintBuf, &textLength);
|
1998-10-22 00:03:54 +04:00
|
|
|
// Translate unicode data into ascii for rendering
|
|
|
|
char* dst = paintBuf;
|
|
|
|
char* end = dst + textLength;
|
|
|
|
PRUnichar* src = rawPaintBuf;
|
|
|
|
while (dst < end) {
|
|
|
|
*dst++ = (char) ((unsigned char) *src++);
|
|
|
|
}
|
1998-10-20 04:21:18 +04:00
|
|
|
|
|
|
|
char* text = paintBuf;
|
1999-04-26 08:02:04 +04:00
|
|
|
nsFrameState frameState;
|
|
|
|
PRBool isSelected;
|
|
|
|
GetFrameState(&frameState);
|
|
|
|
isSelected = (frameState & NS_FRAME_SELECTED_CONTENT) == NS_FRAME_SELECTED_CONTENT;
|
|
|
|
|
1998-09-09 02:34:40 +04:00
|
|
|
if (0 != textLength) {
|
1999-04-26 08:02:04 +04:00
|
|
|
if (!displaySelection || !isSelected) {
|
1999-01-26 02:29:53 +03:00
|
|
|
//if selection is > content length then selection has "slid off"
|
1998-09-09 02:34:40 +04:00
|
|
|
// When there is no selection showing, use the fastest and
|
|
|
|
// simplest rendering approach
|
1999-07-08 23:52:57 +04:00
|
|
|
aRenderingContext.SetColor(aTextStyle.mColor->mColor);
|
1999-01-28 08:03:58 +03:00
|
|
|
aRenderingContext.DrawString(text, PRUint32(textLength), dx, dy);
|
1998-10-26 20:27:53 +03:00
|
|
|
PaintTextDecorations(aRenderingContext, aStyleContext, aTextStyle,
|
|
|
|
dx, dy, width);
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
|
|
|
else {
|
1999-07-15 22:19:03 +04:00
|
|
|
SelectionDetails *details;
|
1999-03-27 03:18:32 +03:00
|
|
|
ip[mContentLength] = ip[mContentLength-1];
|
1999-04-26 08:02:04 +04:00
|
|
|
if ((ip[mContentLength]-mContentOffset) < textLength) {
|
|
|
|
//must set up last one for selection beyond edge if in boundary
|
1999-03-27 03:18:32 +03:00
|
|
|
ip[mContentLength]++;
|
1999-01-23 03:00:46 +03:00
|
|
|
}
|
1999-04-26 08:02:04 +04:00
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
|
|
|
nsCOMPtr<nsIFrameSelection> frameSelection;
|
|
|
|
nsresult rv = aPresContext->GetShell(getter_AddRefs(shell));
|
|
|
|
if (NS_SUCCEEDED(rv) && shell){
|
1999-07-18 06:27:19 +04:00
|
|
|
rv = shell->GetFrameSelection(getter_AddRefs(frameSelection));
|
|
|
|
if (NS_SUCCEEDED(rv) && frameSelection){
|
1999-04-26 08:02:04 +04:00
|
|
|
nsCOMPtr<nsIContent> content;
|
|
|
|
rv = GetContent(getter_AddRefs(content));
|
|
|
|
if (NS_SUCCEEDED(rv)){
|
|
|
|
rv = frameSelection->LookUpSelection(content, mContentOffset,
|
1999-07-15 22:19:03 +04:00
|
|
|
mContentLength , &details);// last param notused
|
1999-04-26 08:02:04 +04:00
|
|
|
}
|
|
|
|
}
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
1999-04-26 08:02:04 +04:00
|
|
|
|
|
|
|
|
1999-07-15 22:19:03 +04:00
|
|
|
//where are the selection points "really"
|
|
|
|
SelectionDetails *sdptr = details;
|
|
|
|
while (sdptr){
|
|
|
|
sdptr->mStart = ip[sdptr->mStart] - mContentOffset;
|
|
|
|
sdptr->mEnd = ip[sdptr->mEnd] - mContentOffset;
|
|
|
|
sdptr = sdptr->mNext;
|
|
|
|
}
|
|
|
|
aRenderingContext.SetColor(aTextStyle.mColor->mColor);
|
|
|
|
aRenderingContext.DrawString(text, PRUint32(textLength), dx, dy);
|
|
|
|
PaintTextDecorations(aRenderingContext, aStyleContext,
|
1999-07-16 03:11:35 +04:00
|
|
|
aTextStyle, dx, dy, width, rawPaintBuf, details,0,textLength);
|
1999-07-15 22:19:03 +04:00
|
|
|
sdptr = details;
|
|
|
|
if (details){
|
1999-08-09 23:15:04 +04:00
|
|
|
while ((sdptr = details->mNext) != nsnull) {
|
1999-07-15 22:19:03 +04:00
|
|
|
delete details;
|
|
|
|
details = sdptr;
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
1999-07-15 22:19:03 +04:00
|
|
|
delete details;
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Cleanup
|
1998-10-20 04:21:18 +04:00
|
|
|
if (paintBuf != paintBufMem) {
|
|
|
|
delete [] paintBuf;
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
|
|
|
if (ip != indicies) {
|
|
|
|
delete [] ip;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-04-20 04:23:33 +04:00
|
|
|
nsTextFrame::FindTextRuns(nsLineLayout& aLineLayout)
|
1998-09-09 02:34:40 +04:00
|
|
|
{
|
|
|
|
if (nsnull == mPrevInFlow) {
|
|
|
|
aLineLayout.AddText(this);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-09-10 23:18:01 +04:00
|
|
|
//---------------------------------------------------
|
|
|
|
// Uses a binary search for find where the cursor falls in the line of text
|
|
|
|
// It also keeps track of the part of the string that has already been measured
|
|
|
|
// so it doesn't have to keep measuring the same text over and over
|
|
|
|
//
|
|
|
|
// Param "aBaseWidth" contains the width in twips of the portion
|
|
|
|
// of the text that has already been measured, and aBaseInx contains
|
|
|
|
// the index of the text that has already been measured.
|
|
|
|
//
|
|
|
|
// aTextWidth returns the (in twips) the length of the text that falls before the cursor
|
|
|
|
// aIndex contains the index of the text where the cursor falls
|
|
|
|
static PRBool
|
1998-10-02 05:12:39 +04:00
|
|
|
BinarySearchForPosition(nsIRenderingContext* acx,
|
1998-09-10 23:18:01 +04:00
|
|
|
PRUnichar* aText,
|
|
|
|
PRInt32 aBaseWidth,
|
|
|
|
PRInt32 aBaseInx,
|
|
|
|
PRInt32 aStartInx,
|
|
|
|
PRInt32 aEndInx,
|
|
|
|
PRInt32 aCursorPos,
|
|
|
|
PRInt32& aIndex,
|
|
|
|
PRInt32& aTextWidth)
|
|
|
|
{
|
|
|
|
PRInt32 range = aEndInx - aStartInx;
|
|
|
|
if (range == 1) {
|
|
|
|
aIndex = aStartInx + aBaseInx;
|
1998-12-14 21:34:14 +03:00
|
|
|
acx->GetWidth(aText, aIndex, aTextWidth);
|
1998-09-10 23:18:01 +04:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
PRInt32 inx = aStartInx + (range / 2);
|
|
|
|
|
1999-04-26 08:02:04 +04:00
|
|
|
PRInt32 textWidth = 0;
|
1998-10-02 05:12:39 +04:00
|
|
|
acx->GetWidth(aText, inx, textWidth);
|
1998-09-10 23:18:01 +04:00
|
|
|
|
|
|
|
PRInt32 fullWidth = aBaseWidth + textWidth;
|
|
|
|
if (fullWidth == aCursorPos) {
|
1999-09-15 05:57:50 +04:00
|
|
|
aTextWidth = textWidth;
|
1998-09-10 23:18:01 +04:00
|
|
|
aIndex = inx;
|
|
|
|
return PR_TRUE;
|
|
|
|
} else if (aCursorPos < fullWidth) {
|
|
|
|
aTextWidth = aBaseWidth;
|
1998-10-02 05:12:39 +04:00
|
|
|
if (BinarySearchForPosition(acx, aText, aBaseWidth, aBaseInx, aStartInx, inx, aCursorPos, aIndex, aTextWidth)) {
|
1998-09-10 23:18:01 +04:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
aTextWidth = fullWidth;
|
1998-12-14 21:34:14 +03:00
|
|
|
if (BinarySearchForPosition(acx, aText, aBaseWidth, aBaseInx, inx, aEndInx, aCursorPos, aIndex, aTextWidth)) {
|
1998-09-10 23:18:01 +04:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
1998-09-09 02:34:40 +04:00
|
|
|
|
1998-09-10 23:18:01 +04:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
// Uses a binary search to find the position of the cursor in the text.
|
|
|
|
// The "indices array is used to map from the compressed text back to the
|
|
|
|
// un-compressed text, selection is based on the un-compressed text, the visual
|
|
|
|
// display of selection is based on the compressed text.
|
|
|
|
//---------------------------------------------------------------------------
|
1998-10-02 05:12:39 +04:00
|
|
|
NS_IMETHODIMP
|
1999-06-11 01:08:17 +04:00
|
|
|
nsTextFrame::GetPosition(nsIPresContext& aCX,
|
|
|
|
nscoord aXCoord,
|
|
|
|
nsIContent ** aNewContent,
|
|
|
|
PRInt32& aContentOffset,
|
|
|
|
PRInt32& aContentOffsetEnd)
|
|
|
|
|
1998-09-09 02:34:40 +04:00
|
|
|
{
|
1999-06-08 06:19:26 +04:00
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
1999-06-11 01:08:17 +04:00
|
|
|
nsresult rv = aCX.GetShell(getter_AddRefs(shell));
|
1999-06-08 06:19:26 +04:00
|
|
|
if (NS_SUCCEEDED(rv) && shell) {
|
|
|
|
nsCOMPtr<nsIRenderingContext> acx;
|
|
|
|
rv = shell->CreateRenderingContext(this, getter_AddRefs(acx));
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
1999-06-11 01:08:17 +04:00
|
|
|
TextStyle ts(&aCX, *acx, mStyleContext);
|
1999-06-08 06:19:26 +04:00
|
|
|
if (ts.mSmallCaps || ts.mWordSpacing || ts.mLetterSpacing) {
|
|
|
|
|
1999-06-11 01:08:17 +04:00
|
|
|
nsresult result = GetPositionSlowly(aCX, acx, aXCoord, aNewContent,
|
|
|
|
aContentOffset);
|
|
|
|
aContentOffsetEnd = aContentOffset;
|
1999-06-08 06:19:26 +04:00
|
|
|
return result;
|
|
|
|
}
|
1999-04-20 04:23:33 +04:00
|
|
|
|
1999-06-08 06:19:26 +04:00
|
|
|
PRUnichar wordBufMem[WORD_BUF_SIZE];
|
|
|
|
PRUnichar paintBufMem[TEXT_BUF_SIZE];
|
|
|
|
PRInt32 indicies[TEXT_BUF_SIZE];
|
|
|
|
PRInt32* ip = indicies;
|
|
|
|
PRUnichar* paintBuf = paintBufMem;
|
|
|
|
if (mContentLength >= TEXT_BUF_SIZE) {
|
|
|
|
ip = new PRInt32[mContentLength+1];
|
|
|
|
paintBuf = new PRUnichar[mContentLength];
|
|
|
|
}
|
|
|
|
PRInt32 textLength;
|
|
|
|
|
|
|
|
// Find the font metrics for this text
|
|
|
|
nsIStyleContext* styleContext;
|
1999-06-11 01:08:17 +04:00
|
|
|
GetStyleContext(&styleContext);
|
1999-06-08 06:19:26 +04:00
|
|
|
const nsStyleFont *font = (const nsStyleFont*)
|
|
|
|
styleContext->GetStyleData(eStyleStruct_Font);
|
|
|
|
NS_RELEASE(styleContext);
|
|
|
|
nsCOMPtr<nsIFontMetrics> fm;
|
1999-06-11 01:08:17 +04:00
|
|
|
aCX.GetMetricsFor(font->mFont, getter_AddRefs(fm));
|
1999-06-08 06:19:26 +04:00
|
|
|
acx->SetFont(fm);
|
|
|
|
|
|
|
|
// Get the document
|
1999-06-11 01:08:17 +04:00
|
|
|
nsCOMPtr<nsIDocument> doc(getter_AddRefs(GetDocument(&aCX)));
|
1999-06-08 06:19:26 +04:00
|
|
|
|
|
|
|
// Get the renderable form of the text
|
|
|
|
nsCOMPtr<nsILineBreaker> lb;
|
|
|
|
doc->GetLineBreaker(getter_AddRefs(lb));
|
1999-08-10 11:23:56 +04:00
|
|
|
//nsCOMPtr<nsIWordBreaker> wb;
|
|
|
|
//doc->GetWordBreaker(getter_AddRefs(wb));
|
|
|
|
nsTextTransformer tx(wordBufMem, WORD_BUF_SIZE,lb,nsnull);
|
1999-06-08 06:19:26 +04:00
|
|
|
PrepareUnicodeText(tx, ip, paintBuf, &textLength);
|
1999-06-20 00:36:44 +04:00
|
|
|
if (textLength <=0) //invalid frame to get position on
|
|
|
|
return NS_ERROR_FAILURE;
|
1999-06-08 06:19:26 +04:00
|
|
|
ip[mContentLength] = ip[mContentLength-1];
|
|
|
|
if ((ip[mContentLength]-mContentOffset) < textLength) {
|
|
|
|
//must set up last one for selection beyond edge if in boundary
|
|
|
|
ip[mContentLength]++;
|
|
|
|
}
|
1998-09-09 02:34:40 +04:00
|
|
|
|
1999-09-01 05:02:16 +04:00
|
|
|
PRInt32 indx;
|
1999-06-08 06:19:26 +04:00
|
|
|
PRInt32 textWidth = 0;
|
|
|
|
PRUnichar* text = paintBuf;
|
|
|
|
nsPoint origin;
|
|
|
|
nsIView * view;
|
|
|
|
GetOffsetFromView(origin, &view);
|
|
|
|
PRBool found = BinarySearchForPosition(acx, text, origin.x, 0, 0,
|
|
|
|
PRInt32(textLength),
|
1999-06-11 01:08:17 +04:00
|
|
|
PRInt32(aXCoord) , //go to local coordinates
|
1999-09-01 05:02:16 +04:00
|
|
|
indx, textWidth);
|
1999-06-08 06:19:26 +04:00
|
|
|
if (found) {
|
|
|
|
PRInt32 charWidth;
|
1999-09-01 05:02:16 +04:00
|
|
|
acx->GetWidth(text[indx], charWidth);
|
1999-06-08 06:19:26 +04:00
|
|
|
charWidth /= 2;
|
|
|
|
|
1999-09-15 05:57:50 +04:00
|
|
|
if (PR_ABS(PRInt32(aXCoord) - origin.x) > textWidth+charWidth) {
|
1999-09-01 05:02:16 +04:00
|
|
|
indx++;
|
1999-06-08 06:19:26 +04:00
|
|
|
}
|
1998-09-10 23:18:01 +04:00
|
|
|
}
|
1998-09-09 02:34:40 +04:00
|
|
|
|
1999-06-08 06:19:26 +04:00
|
|
|
if (ip != indicies) {
|
|
|
|
delete [] ip;
|
|
|
|
}
|
|
|
|
if (paintBuf != paintBufMem) {
|
|
|
|
delete [] paintBuf;
|
|
|
|
}
|
1998-09-09 02:34:40 +04:00
|
|
|
|
1999-09-01 05:02:16 +04:00
|
|
|
aContentOffset = indx + mContentOffset;
|
1999-06-11 01:55:14 +04:00
|
|
|
//reusing wordBufMem
|
1999-06-08 06:19:26 +04:00
|
|
|
PRInt32 i;
|
|
|
|
for (i = 0;i <= mContentLength; i ++){
|
1999-06-11 01:08:17 +04:00
|
|
|
if (ip[i] == aContentOffset){ //reverse mapping
|
1999-06-11 01:55:14 +04:00
|
|
|
aContentOffset = i + mContentOffset;
|
1999-06-08 06:19:26 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
1999-06-11 01:55:14 +04:00
|
|
|
aContentOffsetEnd = aContentOffset;
|
1999-06-08 06:19:26 +04:00
|
|
|
NS_ASSERTION(i<= mContentLength, "offset we got from binary search is messed up");
|
1999-06-11 01:55:14 +04:00
|
|
|
|
1999-06-08 06:19:26 +04:00
|
|
|
*aNewContent = mContent;
|
|
|
|
if (*aNewContent) {
|
|
|
|
(*aNewContent)->AddRef();
|
|
|
|
}
|
1999-01-26 02:29:53 +03:00
|
|
|
}
|
|
|
|
}
|
1998-12-14 21:34:14 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-10-02 05:12:39 +04:00
|
|
|
|
1999-03-12 03:17:14 +03:00
|
|
|
|
1999-04-26 08:02:04 +04:00
|
|
|
// [HACK] Foward Declarations
|
|
|
|
void ForceDrawFrame(nsFrame * aFrame);
|
1998-12-14 21:34:14 +03:00
|
|
|
|
1999-05-20 04:52:00 +04:00
|
|
|
//null range means the whole thing
|
1999-01-22 21:58:14 +03:00
|
|
|
NS_IMETHODIMP
|
1999-05-20 04:52:00 +04:00
|
|
|
nsTextFrame::SetSelected(nsIDOMRange *aRange,PRBool aSelected, nsSpread aSpread)
|
1999-01-22 21:58:14 +03:00
|
|
|
{
|
1999-04-26 08:02:04 +04:00
|
|
|
nsresult result;
|
1999-06-02 03:04:13 +04:00
|
|
|
if (aSelected && ParentDisablesSelection())
|
|
|
|
return NS_OK;
|
|
|
|
if (aSpread == eSpreadDown)
|
|
|
|
{
|
1999-04-26 08:02:04 +04:00
|
|
|
nsIFrame *frame = GetPrevInFlow();
|
|
|
|
while(frame){
|
1999-05-20 04:52:00 +04:00
|
|
|
frame->SetSelected(aRange,aSelected,eSpreadNone);
|
1999-04-26 08:02:04 +04:00
|
|
|
result = frame->GetPrevInFlow(&frame);
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
frame = GetNextInFlow();
|
1999-09-08 03:40:17 +04:00
|
|
|
while (frame){
|
1999-05-20 04:52:00 +04:00
|
|
|
frame->SetSelected(aRange,aSelected,eSpreadNone);
|
1999-04-26 08:02:04 +04:00
|
|
|
result = frame->GetNextInFlow(&frame);
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
break;
|
|
|
|
}
|
1999-01-25 04:48:01 +03:00
|
|
|
}
|
1999-05-20 04:52:00 +04:00
|
|
|
nsFrameState frameState;
|
|
|
|
GetFrameState(&frameState);
|
1999-06-03 06:09:03 +04:00
|
|
|
PRBool isSelected = ((frameState & NS_FRAME_SELECTED_CONTENT) == NS_FRAME_SELECTED_CONTENT);
|
1999-06-05 03:00:24 +04:00
|
|
|
if (!aSelected && !isSelected) //already set thanks
|
1999-06-02 03:04:13 +04:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-01-25 04:48:01 +03:00
|
|
|
|
1999-05-18 02:31:10 +04:00
|
|
|
PRBool found = PR_FALSE;
|
1999-05-20 04:52:00 +04:00
|
|
|
if (aRange) {
|
|
|
|
//lets see if the range contains us, if so we must redraw!
|
|
|
|
nsCOMPtr<nsIDOMNode> endNode;
|
|
|
|
PRInt32 endOffset;
|
|
|
|
nsCOMPtr<nsIDOMNode> startNode;
|
|
|
|
PRInt32 startOffset;
|
|
|
|
aRange->GetEndParent(getter_AddRefs(endNode));
|
|
|
|
aRange->GetEndOffset(&endOffset);
|
|
|
|
aRange->GetStartParent(getter_AddRefs(startNode));
|
|
|
|
aRange->GetStartOffset(&startOffset);
|
|
|
|
nsCOMPtr<nsIContent> content;
|
|
|
|
result = GetContent(getter_AddRefs(content));
|
|
|
|
nsCOMPtr<nsIDOMNode> thisNode;
|
|
|
|
thisNode = do_QueryInterface(content);
|
|
|
|
|
|
|
|
if (thisNode == startNode){
|
|
|
|
if ((mContentOffset + mContentLength) >= startOffset){
|
|
|
|
found = PR_TRUE;
|
|
|
|
if (thisNode == endNode){ //special case
|
1999-08-09 23:15:04 +04:00
|
|
|
if (endOffset == startOffset) //no need to redraw since drawing takes place with cursor
|
1999-05-20 04:52:00 +04:00
|
|
|
found = PR_FALSE;
|
1999-08-09 23:15:04 +04:00
|
|
|
|
1999-05-20 04:52:00 +04:00
|
|
|
if (mContentOffset > endOffset)
|
|
|
|
found = PR_FALSE;
|
|
|
|
}
|
1999-01-25 04:48:01 +03:00
|
|
|
}
|
|
|
|
}
|
1999-05-20 04:52:00 +04:00
|
|
|
else if (thisNode == endNode){
|
|
|
|
if (mContentOffset < endOffset)
|
|
|
|
found = PR_TRUE;
|
|
|
|
else
|
|
|
|
found = PR_FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
found = PR_TRUE;
|
1999-01-22 21:58:14 +03:00
|
|
|
}
|
1999-05-20 04:52:00 +04:00
|
|
|
else {
|
|
|
|
if ( aSelected != (PRBool)(frameState | NS_FRAME_SELECTED_CONTENT) ){
|
1999-05-19 02:29:27 +04:00
|
|
|
found = PR_TRUE;
|
1999-05-20 04:52:00 +04:00
|
|
|
}
|
1999-05-19 02:29:27 +04:00
|
|
|
}
|
1999-05-20 04:52:00 +04:00
|
|
|
|
1999-06-02 03:04:13 +04:00
|
|
|
if ( aSelected )
|
|
|
|
frameState |= NS_FRAME_SELECTED_CONTENT;
|
|
|
|
else
|
|
|
|
frameState &= ~NS_FRAME_SELECTED_CONTENT;
|
1999-04-26 08:02:04 +04:00
|
|
|
SetFrameState(frameState);
|
1999-04-28 06:43:02 +04:00
|
|
|
if (found){ //if range contains this frame...
|
|
|
|
nsRect frameRect;
|
|
|
|
GetRect(frameRect);
|
|
|
|
nsRect rect(0, 0, frameRect.width, frameRect.height);
|
1999-05-20 04:52:00 +04:00
|
|
|
Invalidate(rect, PR_FALSE);
|
1999-04-28 06:43:02 +04:00
|
|
|
// ForceDrawFrame(this);
|
|
|
|
}
|
1998-10-02 05:12:39 +04:00
|
|
|
return NS_OK;
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
|
|
|
|
1999-02-12 03:02:31 +03:00
|
|
|
NS_IMETHODIMP
|
1999-04-20 04:23:33 +04:00
|
|
|
nsTextFrame::GetPointFromOffset(nsIPresContext* aPresContext,
|
|
|
|
nsIRenderingContext* inRendContext,
|
|
|
|
PRInt32 inOffset,
|
|
|
|
nsPoint* outPoint)
|
1999-02-12 03:02:31 +03:00
|
|
|
{
|
1999-04-20 04:23:33 +04:00
|
|
|
if (!aPresContext || !inRendContext || !outPoint)
|
1999-03-13 00:38:16 +03:00
|
|
|
return NS_ERROR_NULL_POINTER;
|
1999-03-17 01:55:49 +03:00
|
|
|
|
|
|
|
if (mContentLength <= 0) {
|
|
|
|
outPoint->x = 0;
|
|
|
|
outPoint->y = 0;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-03-13 00:38:16 +03:00
|
|
|
inOffset-=mContentOffset;
|
|
|
|
if (inOffset < 0){
|
|
|
|
NS_ASSERTION(0,"offset less than this frame has in GetPointFromOffset");
|
|
|
|
inOffset = 0;
|
|
|
|
}
|
1999-04-20 04:23:33 +04:00
|
|
|
TextStyle ts(aPresContext, *inRendContext, mStyleContext);
|
1999-02-12 03:02:31 +03:00
|
|
|
|
|
|
|
|
1999-03-13 00:38:16 +03:00
|
|
|
PRUnichar wordBufMem[WORD_BUF_SIZE];
|
|
|
|
PRUnichar paintBufMem[TEXT_BUF_SIZE];
|
|
|
|
PRInt32 indicies[TEXT_BUF_SIZE];
|
|
|
|
PRUnichar* paintBuf = paintBufMem;
|
|
|
|
PRInt32* ip = indicies;
|
|
|
|
if (mContentLength > TEXT_BUF_SIZE) {
|
1999-02-12 03:02:31 +03:00
|
|
|
ip = new PRInt32[mContentLength+1];
|
|
|
|
paintBuf = new PRUnichar[mContentLength];
|
|
|
|
}
|
|
|
|
nscoord width = mRect.width;
|
|
|
|
PRInt32 textLength;
|
|
|
|
|
1999-04-20 04:23:33 +04:00
|
|
|
// Get the document
|
|
|
|
nsCOMPtr<nsIDocument> doc(getter_AddRefs(GetDocument(aPresContext)));
|
1999-03-13 00:38:16 +03:00
|
|
|
|
1999-04-20 04:23:33 +04:00
|
|
|
// Transform text from content into renderable form
|
1999-02-24 21:21:23 +03:00
|
|
|
nsCOMPtr<nsILineBreaker> lb;
|
|
|
|
doc->GetLineBreaker(getter_AddRefs(lb));
|
1999-08-10 11:23:56 +04:00
|
|
|
//nsCOMPtr<nsIWordBreaker> wb;
|
|
|
|
//doc->GetWordBreaker(getter_AddRefs(wb));
|
|
|
|
nsTextTransformer tx(wordBufMem, WORD_BUF_SIZE, lb,nsnull);
|
1999-04-20 04:23:33 +04:00
|
|
|
PrepareUnicodeText(tx, ip, paintBuf, &textLength);
|
1999-03-27 03:18:32 +03:00
|
|
|
ip[mContentLength] = ip[mContentLength-1];
|
1999-04-08 02:56:09 +04:00
|
|
|
if ((ip[mContentLength]-mContentOffset) < textLength)//must set up last one for selection beyond edge if in boundary
|
1999-03-27 03:18:32 +03:00
|
|
|
ip[mContentLength]++;
|
1999-03-13 00:38:16 +03:00
|
|
|
if (inOffset > mContentLength){
|
|
|
|
NS_ASSERTION(0, "invalid offset passed to GetPointFromOffset");
|
|
|
|
inOffset = mContentLength;
|
|
|
|
}
|
|
|
|
GetWidth(*inRendContext, ts,
|
|
|
|
paintBuf, ip[inOffset]-mContentOffset,
|
1999-04-20 04:23:33 +04:00
|
|
|
&width);
|
1999-03-13 00:38:16 +03:00
|
|
|
(*outPoint).x = width;
|
|
|
|
(*outPoint).y = 0;
|
1999-02-12 03:02:31 +03:00
|
|
|
|
|
|
|
if (paintBuf != paintBufMem)
|
|
|
|
delete [] paintBuf;
|
1999-03-13 00:38:16 +03:00
|
|
|
if (ip != indicies) {
|
1999-02-12 03:02:31 +03:00
|
|
|
delete [] ip;
|
1999-03-13 00:38:16 +03:00
|
|
|
}
|
1999-02-12 03:02:31 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-04-20 04:23:33 +04:00
|
|
|
nsTextFrame::GetChildFrameContainingOffset(PRInt32 inContentOffset,
|
1999-09-11 04:18:02 +04:00
|
|
|
PRBool inHint,
|
1999-04-20 04:23:33 +04:00
|
|
|
PRInt32* outFrameContentOffset,
|
|
|
|
nsIFrame **outChildFrame)
|
1999-02-12 03:02:31 +03:00
|
|
|
{
|
|
|
|
if (nsnull == outChildFrame)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
1999-07-15 22:19:03 +04:00
|
|
|
nsresult result;
|
1999-02-12 03:02:31 +03:00
|
|
|
PRInt32 contentOffset = inContentOffset;
|
|
|
|
|
|
|
|
if (contentOffset != -1) //-1 signified the end of the current content
|
|
|
|
contentOffset = inContentOffset - mContentOffset;
|
|
|
|
|
1999-09-11 04:18:02 +04:00
|
|
|
if ((contentOffset > mContentLength) || ((contentOffset == mContentLength) && inHint) )
|
1999-02-12 03:02:31 +03:00
|
|
|
{
|
|
|
|
//this is not the frame we are looking for.
|
1999-05-13 04:44:23 +04:00
|
|
|
nsIFrame *nextInFlow;
|
|
|
|
nextInFlow = GetNextInFlow();
|
1999-02-12 03:02:31 +03:00
|
|
|
if (nextInFlow)
|
1999-09-14 02:19:31 +04:00
|
|
|
{
|
1999-09-11 04:18:02 +04:00
|
|
|
return nextInFlow->GetChildFrameContainingOffset(inContentOffset, inHint, outFrameContentOffset, outChildFrame);
|
1999-09-14 02:19:31 +04:00
|
|
|
}
|
|
|
|
else if (contentOffset != mContentLength) //that condition was only for when there is a choice
|
1999-02-12 03:02:31 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
1999-09-14 02:19:31 +04:00
|
|
|
|
|
|
|
if (inContentOffset < mContentOffset) //could happen with floaters!
|
1999-07-15 22:19:03 +04:00
|
|
|
{
|
|
|
|
result = GetPrevInFlow(outChildFrame);
|
1999-09-15 03:16:22 +04:00
|
|
|
if (NS_SUCCEEDED(result) && outChildFrame)
|
1999-09-11 04:18:02 +04:00
|
|
|
return (*outChildFrame)->GetChildFrameContainingOffset(inContentOffset, inHint,
|
1999-07-15 22:19:03 +04:00
|
|
|
outFrameContentOffset,outChildFrame);
|
|
|
|
else
|
|
|
|
return result;
|
|
|
|
}
|
1999-02-12 03:02:31 +03:00
|
|
|
|
|
|
|
*outFrameContentOffset = contentOffset;
|
|
|
|
*outChildFrame = this;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-01-22 21:58:14 +03:00
|
|
|
|
1999-02-02 03:23:40 +03:00
|
|
|
NS_IMETHODIMP
|
1999-09-10 22:29:37 +04:00
|
|
|
nsTextFrame::PeekOffset(nsPeekOffsetStruct *aPos)
|
1999-02-02 03:23:40 +03:00
|
|
|
{
|
1999-05-13 04:44:23 +04:00
|
|
|
|
1999-09-10 22:29:37 +04:00
|
|
|
if (!aPos || !mContent)
|
1999-02-02 03:23:40 +03:00
|
|
|
return NS_ERROR_NULL_POINTER;
|
1999-09-10 22:29:37 +04:00
|
|
|
if (aPos->mStartOffset < 0 )
|
|
|
|
aPos->mStartOffset = mContentLength + mContentOffset;
|
|
|
|
if (aPos->mStartOffset < mContentOffset){
|
|
|
|
aPos->mStartOffset = mContentOffset;
|
1999-05-13 04:44:23 +04:00
|
|
|
}
|
1999-09-10 22:29:37 +04:00
|
|
|
if (aPos->mStartOffset > (mContentOffset + mContentLength)){
|
1999-05-13 04:44:23 +04:00
|
|
|
nsIFrame *nextInFlow;
|
|
|
|
nextInFlow = GetNextInFlow();
|
|
|
|
if (!nextInFlow){
|
|
|
|
NS_ASSERTION(PR_FALSE,"nsTextFrame::PeekOffset no more flow \n");
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
1999-09-10 22:29:37 +04:00
|
|
|
return nextInFlow->PeekOffset(aPos);
|
1999-05-13 04:44:23 +04:00
|
|
|
}
|
1999-09-10 22:29:37 +04:00
|
|
|
|
|
|
|
if (aPos->mAmount == eSelectLine || aPos->mAmount == eSelectBeginLine
|
|
|
|
|| aPos->mAmount == eSelectEndLine)
|
1999-09-02 01:40:16 +04:00
|
|
|
{
|
1999-09-10 22:29:37 +04:00
|
|
|
return nsFrame::PeekOffset(aPos);
|
1999-09-02 01:40:16 +04:00
|
|
|
}
|
1999-05-13 04:44:23 +04:00
|
|
|
|
1999-02-02 03:23:40 +03:00
|
|
|
PRUnichar wordBufMem[WORD_BUF_SIZE];
|
|
|
|
PRUnichar paintBufMem[TEXT_BUF_SIZE];
|
|
|
|
PRInt32 indicies[TEXT_BUF_SIZE];
|
|
|
|
PRInt32* ip = indicies;
|
|
|
|
PRUnichar* paintBuf = paintBufMem;
|
|
|
|
if (mContentLength > TEXT_BUF_SIZE) {
|
|
|
|
ip = new PRInt32[mContentLength+1];
|
|
|
|
paintBuf = new PRUnichar[mContentLength];
|
|
|
|
}
|
|
|
|
PRInt32 textLength;
|
1999-07-15 22:19:03 +04:00
|
|
|
nsresult result(NS_OK);
|
1999-02-24 21:21:23 +03:00
|
|
|
|
1999-09-11 04:18:02 +04:00
|
|
|
aPos->mResultContent = mContent;//do this right off
|
1999-04-20 04:23:33 +04:00
|
|
|
|
1999-09-10 22:29:37 +04:00
|
|
|
switch (aPos->mAmount){
|
1999-02-10 21:55:25 +03:00
|
|
|
case eSelectNoAmount : {
|
1999-09-10 22:29:37 +04:00
|
|
|
aPos->mContentOffset = aPos->mStartOffset;
|
1999-02-16 05:42:08 +03:00
|
|
|
}
|
1999-02-10 21:55:25 +03:00
|
|
|
break;
|
|
|
|
case eSelectCharacter : {
|
1999-08-10 11:23:56 +04:00
|
|
|
// Transform text from content into renderable form
|
|
|
|
nsIDocument* doc;
|
|
|
|
result = mContent->GetDocument(doc);
|
|
|
|
if (NS_FAILED(result) || !doc)
|
|
|
|
return result;
|
|
|
|
nsCOMPtr<nsILineBreaker> lb;
|
|
|
|
doc->GetLineBreaker(getter_AddRefs(lb));
|
|
|
|
//nsCOMPtr<nsIWordBreaker> wb;
|
|
|
|
//doc->GetWordBreaker(getter_AddRefs(wb));
|
|
|
|
NS_RELEASE(doc);
|
|
|
|
|
|
|
|
nsTextTransformer tx(wordBufMem, WORD_BUF_SIZE,lb,nsnull);
|
|
|
|
|
1999-04-20 04:23:33 +04:00
|
|
|
PrepareUnicodeText(tx, ip, paintBuf, &textLength);
|
1999-03-27 03:18:32 +03:00
|
|
|
ip[mContentLength] = ip[mContentLength-1];
|
1999-04-08 02:56:09 +04:00
|
|
|
if ((ip[mContentLength]-mContentOffset) < textLength)//must set up last one for selection beyond edge if in boundary
|
1999-03-27 03:18:32 +03:00
|
|
|
ip[mContentLength]++;
|
1999-02-22 06:20:59 +03:00
|
|
|
nsIFrame *frameUsed = nsnull;
|
|
|
|
PRInt32 start;
|
|
|
|
PRBool found = PR_TRUE;
|
1999-09-10 22:29:37 +04:00
|
|
|
if (aPos->mDirection == eDirPrevious){
|
1999-09-15 05:57:50 +04:00
|
|
|
aPos->mContentOffset = 0;
|
1999-02-02 04:18:41 +03:00
|
|
|
PRInt32 i;
|
1999-09-10 22:29:37 +04:00
|
|
|
for (i = aPos->mStartOffset -1 - mContentOffset; i >=0; i--){
|
|
|
|
if (ip[i] < ip[aPos->mStartOffset - mContentOffset]){
|
|
|
|
aPos->mContentOffset = i + mContentOffset;
|
1999-02-02 03:23:40 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
1999-02-10 21:55:25 +03:00
|
|
|
if (i <0){
|
1999-02-22 06:20:59 +03:00
|
|
|
found = PR_FALSE;
|
|
|
|
frameUsed = GetPrevInFlow();
|
1999-05-13 04:44:23 +04:00
|
|
|
start = mContentOffset;
|
1999-02-10 21:55:25 +03:00
|
|
|
}
|
1999-02-02 03:23:40 +03:00
|
|
|
}
|
1999-09-10 22:29:37 +04:00
|
|
|
else if (aPos->mDirection == eDirNext){
|
1999-02-22 06:20:59 +03:00
|
|
|
PRInt32 i;
|
1999-09-15 05:57:50 +04:00
|
|
|
aPos->mContentOffset = mContentLength;
|
1999-09-10 22:29:37 +04:00
|
|
|
for (i = aPos->mStartOffset +1 - mContentOffset; i <= mContentLength; i++){
|
|
|
|
if (ip[i] > ip[aPos->mStartOffset - mContentOffset]){
|
|
|
|
aPos->mContentOffset = i + mContentOffset;
|
1999-02-22 06:20:59 +03:00
|
|
|
break;
|
1999-02-10 21:55:25 +03:00
|
|
|
}
|
1999-02-02 03:23:40 +03:00
|
|
|
}
|
1999-09-01 05:02:16 +04:00
|
|
|
/* if (aStartOffset == 0 && (mState & TEXT_SKIP_LEADING_WS))
|
1999-02-22 06:20:59 +03:00
|
|
|
i--; //back up because we just skipped over some white space. why skip over the char also?
|
1999-05-13 04:44:23 +04:00
|
|
|
*/
|
1999-02-22 06:20:59 +03:00
|
|
|
if (i > mContentLength){
|
|
|
|
found = PR_FALSE;
|
|
|
|
frameUsed = GetNextInFlow();
|
1999-05-13 04:44:23 +04:00
|
|
|
start = mContentOffset + mContentLength;
|
1999-02-22 06:20:59 +03:00
|
|
|
}
|
1999-02-02 03:23:40 +03:00
|
|
|
}
|
1999-02-22 06:20:59 +03:00
|
|
|
if (!found){
|
|
|
|
if (frameUsed){
|
1999-09-10 22:29:37 +04:00
|
|
|
result = frameUsed->PeekOffset(aPos);
|
1999-02-22 06:20:59 +03:00
|
|
|
}
|
|
|
|
else {//reached end ask the frame for help
|
1999-09-10 22:29:37 +04:00
|
|
|
result = nsFrame::PeekOffset(aPos);
|
1999-02-22 06:20:59 +03:00
|
|
|
}
|
|
|
|
}
|
1999-05-13 04:44:23 +04:00
|
|
|
else {
|
1999-09-10 22:29:37 +04:00
|
|
|
aPos->mResultContent = mContent;
|
1999-03-03 04:51:21 +03:00
|
|
|
}
|
1999-05-13 04:44:23 +04:00
|
|
|
}
|
1999-02-02 03:23:40 +03:00
|
|
|
break;
|
1999-02-22 06:20:59 +03:00
|
|
|
case eSelectWord : {
|
1999-08-10 11:23:56 +04:00
|
|
|
// Transform text from content into renderable form
|
|
|
|
nsIDocument* doc;
|
|
|
|
result = mContent->GetDocument(doc);
|
|
|
|
if (NS_FAILED(result) || !doc)
|
|
|
|
return result;
|
|
|
|
nsCOMPtr<nsILineBreaker> lb;
|
|
|
|
doc->GetLineBreaker(getter_AddRefs(lb));
|
|
|
|
nsCOMPtr<nsIWordBreaker> wb;
|
|
|
|
doc->GetWordBreaker(getter_AddRefs(wb));
|
|
|
|
NS_RELEASE(doc);
|
|
|
|
|
|
|
|
nsTextTransformer tx(wordBufMem, WORD_BUF_SIZE,lb,wb);
|
|
|
|
|
|
|
|
PrepareUnicodeText(tx, ip, paintBuf, &textLength);
|
1999-02-22 06:20:59 +03:00
|
|
|
nsIFrame *frameUsed = nsnull;
|
1999-09-19 04:59:38 +04:00
|
|
|
PRBool keepSearching; //if you run out of chars before you hit the end of word, maybe next frame has more text to select?
|
|
|
|
PRInt32 start;
|
1999-02-22 07:59:52 +03:00
|
|
|
PRBool found = PR_FALSE;
|
1999-02-22 06:20:59 +03:00
|
|
|
PRBool isWhitespace;
|
|
|
|
PRInt32 wordLen, contentLen;
|
1999-09-10 22:29:37 +04:00
|
|
|
if (aPos->mDirection == eDirPrevious){
|
1999-03-03 04:51:21 +03:00
|
|
|
keepSearching = PR_TRUE;
|
1999-09-17 03:31:59 +04:00
|
|
|
tx.Init(this, mContent, aPos->mStartOffset);
|
1999-04-07 02:41:44 +04:00
|
|
|
if (tx.GetPrevWord(PR_FALSE, wordLen, contentLen, isWhitespace, PR_FALSE)){
|
1999-09-10 22:29:37 +04:00
|
|
|
if ((aPos->mEatingWS && !isWhitespace) || !aPos->mEatingWS){
|
|
|
|
aPos->mContentOffset = aPos->mStartOffset - contentLen;
|
1999-03-03 04:51:21 +03:00
|
|
|
//check for whitespace next.
|
1999-09-10 22:29:37 +04:00
|
|
|
if (aPos->mContentOffset > mContentOffset)
|
1999-03-03 04:51:21 +03:00
|
|
|
keepSearching = PR_FALSE;//reached the beginning of a word
|
1999-09-10 22:29:37 +04:00
|
|
|
aPos->mEatingWS = !isWhitespace;//nowhite space, just eat chars.
|
1999-04-07 02:41:44 +04:00
|
|
|
while (isWhitespace && tx.GetPrevWord(PR_FALSE, wordLen, contentLen, isWhitespace, PR_FALSE)){
|
1999-09-10 22:29:37 +04:00
|
|
|
aPos->mContentOffset -= contentLen;
|
|
|
|
aPos->mEatingWS = PR_FALSE;
|
1999-03-03 04:51:21 +03:00
|
|
|
}
|
1999-09-10 22:29:37 +04:00
|
|
|
keepSearching = aPos->mContentOffset <= mContentOffset;
|
1999-03-03 04:51:21 +03:00
|
|
|
if (!isWhitespace){
|
|
|
|
if (!keepSearching)
|
|
|
|
found = PR_TRUE;
|
|
|
|
else
|
1999-09-10 22:29:37 +04:00
|
|
|
aPos->mEatingWS = PR_TRUE;
|
1999-03-03 04:51:21 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
1999-09-10 22:29:37 +04:00
|
|
|
aPos->mContentOffset = mContentLength + mContentOffset;
|
1999-02-22 07:59:52 +03:00
|
|
|
found = PR_TRUE;
|
1999-03-03 04:51:21 +03:00
|
|
|
}
|
1999-02-22 06:20:59 +03:00
|
|
|
}
|
|
|
|
frameUsed = GetPrevInFlow();
|
|
|
|
start = -1; //start at end
|
|
|
|
}
|
1999-09-10 22:29:37 +04:00
|
|
|
else if (aPos->mDirection == eDirNext){
|
1999-09-17 03:31:59 +04:00
|
|
|
tx.Init(this, mContent, aPos->mStartOffset );
|
1999-08-19 10:06:57 +04:00
|
|
|
|
|
|
|
#ifdef DEBUGWORDJUMP
|
1999-09-10 22:29:37 +04:00
|
|
|
printf("Next- Start=%d aPos->mEatingWS=%s\n", aPos->mStartOffset, aPos->mEatingWS ? "TRUE" : "FALSE");
|
1999-08-19 10:06:57 +04:00
|
|
|
#endif
|
|
|
|
|
1999-04-07 02:41:44 +04:00
|
|
|
if (tx.GetNextWord(PR_FALSE, wordLen, contentLen, isWhitespace, PR_FALSE)){
|
1999-08-19 10:06:57 +04:00
|
|
|
|
|
|
|
#ifdef DEBUGWORDJUMP
|
|
|
|
printf("GetNextWord return non null, wordLen%d, contentLen%d isWhitespace=%s\n",
|
|
|
|
wordLen, contentLen, isWhitespace ? "WS" : "NOT WS");
|
|
|
|
#endif
|
|
|
|
|
1999-09-10 22:29:37 +04:00
|
|
|
if ((aPos->mEatingWS && isWhitespace) || !aPos->mEatingWS){
|
|
|
|
aPos->mContentOffset = aPos->mStartOffset + contentLen;
|
1999-02-22 07:59:52 +03:00
|
|
|
//check for whitespace next.
|
1999-03-03 04:51:21 +03:00
|
|
|
keepSearching = PR_TRUE;
|
|
|
|
isWhitespace = PR_TRUE;
|
1999-04-07 02:41:44 +04:00
|
|
|
while (tx.GetNextWord(PR_FALSE, wordLen, contentLen, isWhitespace, PR_FALSE) && isWhitespace){
|
1999-08-19 10:06:57 +04:00
|
|
|
#ifdef DEBUGWORDJUMP
|
|
|
|
printf("2-GetNextWord return non null, wordLen%d, contentLen%d isWhitespace=%s\n",
|
|
|
|
wordLen, contentLen, isWhitespace ? "WS" : "NOT WS");
|
|
|
|
#endif
|
1999-09-10 22:29:37 +04:00
|
|
|
aPos->mContentOffset += contentLen;
|
1999-03-03 04:51:21 +03:00
|
|
|
keepSearching = PR_FALSE;
|
1999-05-13 04:44:23 +04:00
|
|
|
isWhitespace = PR_FALSE;
|
1999-03-03 04:51:21 +03:00
|
|
|
}
|
1999-02-22 07:59:52 +03:00
|
|
|
}
|
1999-09-10 22:29:37 +04:00
|
|
|
else if (aPos->mEatingWS)
|
|
|
|
aPos->mContentOffset = mContentOffset;
|
1999-02-22 07:59:52 +03:00
|
|
|
|
|
|
|
if (!isWhitespace){
|
|
|
|
found = PR_TRUE;
|
1999-09-10 22:29:37 +04:00
|
|
|
aPos->mEatingWS = PR_FALSE;
|
1999-02-22 07:59:52 +03:00
|
|
|
}
|
1999-03-03 04:51:21 +03:00
|
|
|
else if (!keepSearching) //we have found the "whole" word so just looking for WS
|
1999-09-10 22:29:37 +04:00
|
|
|
aPos->mEatingWS = PR_TRUE;
|
1999-02-22 06:20:59 +03:00
|
|
|
}
|
|
|
|
frameUsed = GetNextInFlow();
|
|
|
|
start = 0;
|
|
|
|
}
|
1999-08-19 10:06:57 +04:00
|
|
|
#ifdef DEBUGWORDJUMP
|
1999-09-10 22:29:37 +04:00
|
|
|
printf("aEatingWS = %s\n" , aPos->mEatingWS ? "TRUE" : "FALSE");
|
1999-08-19 10:06:57 +04:00
|
|
|
#endif
|
1999-09-10 22:29:37 +04:00
|
|
|
if (!found || (aPos->mContentOffset > (mContentOffset + mContentLength)) || (aPos->mContentOffset < mContentOffset)){ //gone too far
|
1999-02-22 06:20:59 +03:00
|
|
|
if (frameUsed){
|
1999-09-11 04:18:02 +04:00
|
|
|
aPos->mStartOffset = start;
|
1999-09-10 22:29:37 +04:00
|
|
|
result = frameUsed->PeekOffset(aPos);
|
1999-02-22 06:20:59 +03:00
|
|
|
}
|
|
|
|
else {//reached end ask the frame for help
|
1999-09-10 22:29:37 +04:00
|
|
|
result = nsFrame::PeekOffset(aPos);
|
1999-02-22 06:20:59 +03:00
|
|
|
}
|
|
|
|
}
|
1999-03-03 04:51:21 +03:00
|
|
|
else {
|
1999-09-10 22:29:37 +04:00
|
|
|
aPos->mResultContent = mContent;
|
1999-03-03 04:51:21 +03:00
|
|
|
}
|
1999-05-13 04:44:23 +04:00
|
|
|
}
|
1999-02-22 06:20:59 +03:00
|
|
|
break;
|
1999-02-02 03:23:40 +03:00
|
|
|
default: result = NS_ERROR_FAILURE; break;
|
|
|
|
}
|
|
|
|
// Cleanup
|
|
|
|
if (paintBuf != paintBufMem) {
|
|
|
|
delete [] paintBuf;
|
|
|
|
}
|
|
|
|
if (ip != indicies) {
|
|
|
|
delete [] ip;
|
|
|
|
}
|
1999-03-03 04:51:21 +03:00
|
|
|
if (NS_FAILED(result)){
|
1999-09-10 22:29:37 +04:00
|
|
|
aPos->mResultContent = mContent;
|
1999-09-11 04:18:02 +04:00
|
|
|
//aPos->mContentOffset = aPos->mStartOffset;
|
1999-03-03 04:51:21 +03:00
|
|
|
result = NS_OK;
|
|
|
|
}
|
1999-09-10 22:29:37 +04:00
|
|
|
aPos->mResultFrame = this;
|
1999-02-02 03:23:40 +03:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1999-05-17 04:21:18 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTextFrame::HandleMultiplePress(nsIPresContext& aPresContext,
|
|
|
|
nsGUIEvent* aEvent,
|
|
|
|
nsEventStatus& aEventStatus)
|
|
|
|
{
|
|
|
|
if (!DisplaySelection(aPresContext)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-09-11 04:18:02 +04:00
|
|
|
nsMouseEvent *me = (nsMouseEvent *)aEvent;
|
|
|
|
if (me->clickCount > 2)
|
|
|
|
return nsFrame::HandleMultiplePress(aPresContext,aEvent,aEventStatus);
|
1999-05-17 04:21:18 +04:00
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
|
|
|
nsresult rv = aPresContext.GetShell(getter_AddRefs(shell));
|
|
|
|
if (NS_SUCCEEDED(rv) && shell) {
|
|
|
|
nsCOMPtr<nsIRenderingContext> acx;
|
1999-06-20 00:36:44 +04:00
|
|
|
nsCOMPtr<nsIFocusTracker> tracker;
|
|
|
|
tracker = do_QueryInterface(shell, &rv);
|
|
|
|
if (NS_FAILED(rv) || !tracker)
|
1999-06-11 01:08:17 +04:00
|
|
|
return rv;
|
1999-05-17 04:21:18 +04:00
|
|
|
rv = shell->CreateRenderingContext(this, getter_AddRefs(acx));
|
|
|
|
if (NS_SUCCEEDED(rv)){
|
|
|
|
PRInt32 startPos = 0;
|
|
|
|
PRInt32 contentOffsetEnd = 0;
|
|
|
|
nsCOMPtr<nsIContent> newContent;
|
1999-06-11 01:08:17 +04:00
|
|
|
if (NS_SUCCEEDED(GetPosition(aPresContext, aEvent->point.x,
|
|
|
|
getter_AddRefs(newContent), startPos, contentOffsetEnd))){
|
1999-05-17 04:21:18 +04:00
|
|
|
//find which word needs to be selected! use peek offset one way then the other
|
|
|
|
nsCOMPtr<nsIContent> startContent;
|
|
|
|
nsCOMPtr<nsIDOMNode> startNode;
|
|
|
|
nsCOMPtr<nsIContent> endContent;
|
|
|
|
nsCOMPtr<nsIDOMNode> endNode;
|
|
|
|
//peeks{}
|
1999-09-10 22:29:37 +04:00
|
|
|
nsPeekOffsetStruct startpos;
|
|
|
|
startpos.SetData(tracker,
|
1999-06-20 00:36:44 +04:00
|
|
|
0,
|
1999-06-11 01:08:17 +04:00
|
|
|
eSelectWord,
|
1999-05-17 04:21:18 +04:00
|
|
|
eDirPrevious,
|
1999-06-11 01:08:17 +04:00
|
|
|
startPos,
|
1999-09-10 22:29:37 +04:00
|
|
|
PR_FALSE,
|
|
|
|
PR_TRUE);
|
|
|
|
rv = PeekOffset(&startpos);
|
1999-05-17 04:21:18 +04:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
1999-09-10 22:29:37 +04:00
|
|
|
nsPeekOffsetStruct endpos;
|
|
|
|
endpos.SetData(tracker,
|
1999-06-20 00:36:44 +04:00
|
|
|
0,
|
1999-06-11 01:08:17 +04:00
|
|
|
eSelectWord,
|
1999-05-17 04:21:18 +04:00
|
|
|
eDirNext,
|
1999-06-11 01:08:17 +04:00
|
|
|
startPos,
|
1999-09-10 22:29:37 +04:00
|
|
|
PR_FALSE,
|
1999-09-11 04:18:02 +04:00
|
|
|
PR_FALSE);
|
1999-09-10 22:29:37 +04:00
|
|
|
rv = PeekOffset(&endpos);
|
1999-05-17 04:21:18 +04:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
1999-09-10 22:29:37 +04:00
|
|
|
endNode = do_QueryInterface(endpos.mResultContent,&rv);
|
1999-05-17 04:21:18 +04:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
1999-09-10 22:29:37 +04:00
|
|
|
startNode = do_QueryInterface(startpos.mResultContent,&rv);
|
1999-05-17 04:21:18 +04:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMSelection> selection;
|
1999-07-18 06:27:19 +04:00
|
|
|
if (NS_SUCCEEDED(shell->GetSelection(SELECTION_NORMAL, getter_AddRefs(selection)))){
|
1999-09-10 22:29:37 +04:00
|
|
|
rv = selection->Collapse(startNode,startpos.mContentOffset);
|
1999-05-17 04:21:18 +04:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
1999-09-10 22:29:37 +04:00
|
|
|
rv = selection->Extend(endNode,endpos.mContentOffset);
|
1999-05-17 04:21:18 +04:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
//no release
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
1999-01-22 21:58:14 +03:00
|
|
|
NS_IMETHODIMP
|
1999-04-20 04:23:33 +04:00
|
|
|
nsTextFrame::GetOffsets(PRInt32 &start, PRInt32 &end) const
|
1999-01-22 21:58:14 +03:00
|
|
|
{
|
|
|
|
start = mContentOffset;
|
|
|
|
end = mContentOffset+mContentLength;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-09-09 02:34:40 +04:00
|
|
|
NS_IMETHODIMP
|
1999-04-20 04:23:33 +04:00
|
|
|
nsTextFrame::Reflow(nsIPresContext& aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aMetrics,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
1998-09-09 02:34:40 +04:00
|
|
|
{
|
1999-09-18 03:14:47 +04:00
|
|
|
#ifdef NOISY_REFLOW
|
|
|
|
ListTag(stdout);
|
|
|
|
printf(": BeginReflow: availableSize=%d,%d\n",
|
|
|
|
aReflowState.availableWidth, aReflowState.availableHeight);
|
|
|
|
#endif
|
1998-09-09 02:34:40 +04:00
|
|
|
|
1998-11-17 05:14:38 +03:00
|
|
|
// XXX If there's no line layout, we shouldn't even have created this
|
|
|
|
// frame. This may happen if, for example, this is text inside a table
|
|
|
|
// but not inside a cell. For now, just don't reflow.
|
1999-07-20 07:51:46 +04:00
|
|
|
if (nsnull == aReflowState.mLineLayout) {
|
1999-04-28 02:13:42 +04:00
|
|
|
// XXX Add a method to aMetrics that does this; we do it several places
|
|
|
|
aMetrics.width = 0;
|
|
|
|
aMetrics.height = 0;
|
|
|
|
aMetrics.ascent = 0;
|
|
|
|
aMetrics.descent = 0;
|
|
|
|
if (nsnull != aMetrics.maxElementSize) {
|
|
|
|
aMetrics.maxElementSize->width = 0;
|
|
|
|
aMetrics.maxElementSize->height = 0;
|
|
|
|
}
|
1998-11-17 05:14:38 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-09-09 02:34:40 +04:00
|
|
|
// Get starting offset into the content
|
|
|
|
PRInt32 startingOffset = 0;
|
|
|
|
if (nsnull != mPrevInFlow) {
|
1999-04-20 04:23:33 +04:00
|
|
|
nsTextFrame* prev = (nsTextFrame*) mPrevInFlow;
|
1998-09-09 02:34:40 +04:00
|
|
|
startingOffset = prev->mContentOffset + prev->mContentLength;
|
1999-09-18 20:22:34 +04:00
|
|
|
|
|
|
|
// If our starting offset doesn't agree with mContentOffset, then our
|
|
|
|
// prev-in-flow has changed the number of characters it maps and so we
|
|
|
|
// need to measure text and not try and optimize a resize reflow
|
|
|
|
if (startingOffset != mContentOffset) {
|
|
|
|
mState &= ~TEXT_OPTIMIZE_RESIZE;
|
|
|
|
}
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
|
|
|
|
1999-07-20 07:51:46 +04:00
|
|
|
nsLineLayout& lineLayout = *aReflowState.mLineLayout;
|
1999-04-20 04:23:33 +04:00
|
|
|
TextStyle ts(&aPresContext, *aReflowState.rendContext, mStyleContext);
|
1998-09-09 02:34:40 +04:00
|
|
|
|
1999-09-01 05:02:16 +04:00
|
|
|
// Clear out the reflow state flags in mState (without destroying
|
|
|
|
// the TEXT_BLINK_ON bit).
|
|
|
|
mState &= ~TEXT_REFLOW_FLAGS;
|
1998-10-26 20:27:53 +03:00
|
|
|
if (ts.mFont->mFont.decorations & NS_STYLE_TEXT_DECORATION_BLINK) {
|
1999-09-01 05:02:16 +04:00
|
|
|
if (0 == (mState & TEXT_BLINK_ON)) {
|
|
|
|
mState |= TEXT_BLINK_ON;
|
1998-09-09 02:34:40 +04:00
|
|
|
gTextBlinker->AddFrame(this);
|
|
|
|
}
|
|
|
|
}
|
1998-11-06 03:50:27 +03:00
|
|
|
else {
|
1999-09-01 05:02:16 +04:00
|
|
|
if (0 != (mState & TEXT_BLINK_ON)) {
|
|
|
|
mState &= ~TEXT_BLINK_ON;
|
1998-11-06 03:50:27 +03:00
|
|
|
gTextBlinker->RemoveFrame(this);
|
|
|
|
}
|
|
|
|
}
|
1998-09-09 02:34:40 +04:00
|
|
|
|
1999-03-31 08:12:46 +04:00
|
|
|
PRBool wrapping = (NS_STYLE_WHITESPACE_NORMAL == ts.mText->mWhiteSpace) ||
|
|
|
|
(NS_STYLE_WHITESPACE_MOZ_PRE_WRAP == ts.mText->mWhiteSpace);
|
1998-11-05 22:27:42 +03:00
|
|
|
PRBool firstLetterOK = lineLayout.GetFirstLetterStyleOK();
|
1998-11-15 00:01:26 +03:00
|
|
|
PRBool justDidFirstLetter = PR_FALSE;
|
1998-10-26 20:27:53 +03:00
|
|
|
|
1998-09-09 02:34:40 +04:00
|
|
|
// Set whitespace skip flag
|
|
|
|
PRBool skipWhitespace = PR_FALSE;
|
1999-03-31 08:12:46 +04:00
|
|
|
if (!ts.mPreformatted) {
|
1998-11-01 01:48:21 +03:00
|
|
|
if (lineLayout.GetEndsInWhiteSpace()) {
|
1998-10-22 00:03:54 +04:00
|
|
|
skipWhitespace = PR_TRUE;
|
|
|
|
}
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nscoord x = 0;
|
1999-01-06 02:31:18 +03:00
|
|
|
nscoord maxWidth = aReflowState.availableWidth;
|
1998-09-09 02:34:40 +04:00
|
|
|
nscoord maxWordWidth = 0;
|
1998-10-10 08:35:21 +04:00
|
|
|
nscoord prevMaxWordWidth = 0;
|
1998-09-09 02:34:40 +04:00
|
|
|
PRBool endsInWhitespace = PR_FALSE;
|
1998-10-22 00:03:54 +04:00
|
|
|
PRBool endsInNewline = PR_FALSE;
|
1998-09-09 02:34:40 +04:00
|
|
|
|
1999-02-24 21:21:23 +03:00
|
|
|
nsCOMPtr<nsIDocument> doc;
|
1999-09-17 03:31:59 +04:00
|
|
|
mContent->GetDocument(*getter_AddRefs(doc));
|
1998-10-20 04:21:18 +04:00
|
|
|
// Setup text transformer to transform this frames text content
|
|
|
|
PRUnichar wordBuf[WORD_BUF_SIZE];
|
1999-02-24 21:21:23 +03:00
|
|
|
nsCOMPtr<nsILineBreaker> lb;
|
1999-09-19 04:59:38 +04:00
|
|
|
doc->GetLineBreaker(getter_AddRefs(lb));
|
1999-08-10 11:23:56 +04:00
|
|
|
nsTextTransformer tx(wordBuf, WORD_BUF_SIZE,lb,nsnull);
|
1999-09-17 03:31:59 +04:00
|
|
|
nsresult rv = tx.Init(this, mContent, startingOffset);
|
1998-10-20 04:21:18 +04:00
|
|
|
if (NS_OK != rv) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
PRInt32 contentLength = tx.GetContentLength();
|
|
|
|
|
|
|
|
// Offset tracks how far along we are in the content
|
1998-10-22 00:03:54 +04:00
|
|
|
PRInt32 offset = startingOffset;
|
1998-10-20 04:21:18 +04:00
|
|
|
PRInt32 prevOffset = -1;
|
|
|
|
nscoord lastWordWidth = 0;
|
|
|
|
|
1998-10-20 20:46:14 +04:00
|
|
|
// Loop over words and whitespace in content and measure. Set inWord
|
|
|
|
// to true if we are part of a previous piece of text's word. This
|
|
|
|
// is only valid for one pass through the measuring loop.
|
1999-03-26 03:41:36 +03:00
|
|
|
PRBool inWord = lineLayout.InWord() ||
|
|
|
|
((nsnull != mPrevInFlow) &&
|
1999-09-01 05:02:16 +04:00
|
|
|
(((nsTextFrame*)mPrevInFlow)->mState & TEXT_FIRST_LETTER));
|
1998-10-20 20:46:14 +04:00
|
|
|
if (inWord) {
|
1999-09-01 05:02:16 +04:00
|
|
|
mState |= TEXT_IN_WORD;
|
1998-10-20 20:46:14 +04:00
|
|
|
}
|
1999-09-01 05:02:16 +04:00
|
|
|
mState &= ~TEXT_FIRST_LETTER;
|
1999-03-26 03:41:36 +03:00
|
|
|
|
1998-10-22 00:03:54 +04:00
|
|
|
PRInt32 column = lineLayout.GetColumn();
|
|
|
|
PRInt32 prevColumn = column;
|
|
|
|
mColumn = column;
|
1999-03-21 04:13:17 +03:00
|
|
|
PRBool breakable = lineLayout.LineIsBreakable();
|
1999-09-19 04:59:38 +04:00
|
|
|
PRInt32 lastWordLen;
|
1999-08-19 10:06:57 +04:00
|
|
|
PRUnichar* bp = nsnull;
|
1999-09-18 20:22:34 +04:00
|
|
|
PRBool measureText = PR_TRUE;
|
|
|
|
|
|
|
|
// We can avoid actually measuring the text if:
|
|
|
|
// - this is a resize reflow
|
|
|
|
// - we don't have a next in flow
|
|
|
|
// - the previous reflow successfully reflowed all text in the available space
|
|
|
|
// - the available width is at least as big as our current frame width
|
|
|
|
// - we aren't computing the max element size (that requires we measure
|
|
|
|
// text)
|
|
|
|
// - we're not preformatted text or we're at the same column as before (this
|
|
|
|
// is an issue for tabbed text)
|
|
|
|
if (eReflowReason_Resize == aReflowState.reason) {
|
|
|
|
if (!mNextInFlow && (mState & TEXT_OPTIMIZE_RESIZE) &&
|
|
|
|
(maxWidth >= mRect.width) && !aMetrics.maxElementSize &&
|
|
|
|
(!ts.mPreformatted || (prevColumn == column))) {
|
|
|
|
|
|
|
|
// We can skip measuring of text and use the value from our previous reflow
|
|
|
|
measureText = PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-10-20 04:21:18 +04:00
|
|
|
for (;;) {
|
|
|
|
// Get next word/whitespace from the text
|
1998-09-09 02:34:40 +04:00
|
|
|
PRBool isWhitespace;
|
1998-10-20 04:21:18 +04:00
|
|
|
PRInt32 wordLen, contentLen;
|
1999-08-19 10:06:57 +04:00
|
|
|
bp = tx.GetNextWord(inWord, wordLen, contentLen, isWhitespace);
|
1998-10-20 04:21:18 +04:00
|
|
|
if (nsnull == bp) {
|
|
|
|
break;
|
|
|
|
}
|
1999-07-27 18:47:24 +04:00
|
|
|
lastWordLen = wordLen;
|
1998-10-20 20:46:14 +04:00
|
|
|
inWord = PR_FALSE;
|
1998-10-20 04:21:18 +04:00
|
|
|
|
|
|
|
// Measure the word/whitespace
|
1998-09-09 02:34:40 +04:00
|
|
|
nscoord width;
|
1998-10-20 04:21:18 +04:00
|
|
|
if (isWhitespace) {
|
1998-10-22 00:03:54 +04:00
|
|
|
if (0 == wordLen) {
|
|
|
|
// We hit a newline. Stop looping.
|
|
|
|
prevOffset = offset;
|
|
|
|
offset++;
|
|
|
|
endsInWhitespace = PR_TRUE;
|
1999-03-31 08:12:46 +04:00
|
|
|
if (ts.mPreformatted) {
|
1999-03-16 22:36:49 +03:00
|
|
|
endsInNewline = PR_TRUE;
|
|
|
|
}
|
1998-10-22 00:03:54 +04:00
|
|
|
break;
|
|
|
|
}
|
1998-09-09 02:34:40 +04:00
|
|
|
if (skipWhitespace) {
|
1998-10-20 04:21:18 +04:00
|
|
|
offset += contentLen;
|
1998-09-09 02:34:40 +04:00
|
|
|
skipWhitespace = PR_FALSE;
|
1998-10-20 04:21:18 +04:00
|
|
|
|
|
|
|
// Only set flag when we actually do skip whitespace
|
1999-09-01 05:02:16 +04:00
|
|
|
mState |= TEXT_SKIP_LEADING_WS;
|
1998-09-09 02:34:40 +04:00
|
|
|
continue;
|
|
|
|
}
|
1998-10-22 00:03:54 +04:00
|
|
|
if ('\t' == bp[0]) {
|
|
|
|
// Expand tabs to the proper width
|
|
|
|
wordLen = 8 - (7 & column);
|
1998-10-26 20:27:53 +03:00
|
|
|
width = ts.mSpaceWidth * wordLen;
|
1998-10-22 00:03:54 +04:00
|
|
|
}
|
|
|
|
else {
|
1998-10-26 20:27:53 +03:00
|
|
|
width = ts.mSpaceWidth + ts.mWordSpacing;/* XXX simplistic */
|
1998-10-22 00:03:54 +04:00
|
|
|
}
|
1998-11-01 01:48:21 +03:00
|
|
|
breakable = PR_TRUE;
|
1998-11-05 22:27:42 +03:00
|
|
|
firstLetterOK = PR_FALSE;
|
1998-09-09 02:34:40 +04:00
|
|
|
} else {
|
1998-11-12 19:31:38 +03:00
|
|
|
if (firstLetterOK) {
|
|
|
|
// XXX need a lookup function here; plus look ahead using the
|
|
|
|
// text-runs
|
1999-02-12 20:45:58 +03:00
|
|
|
if ((bp[0] == '\'') || (bp[0] == '\"')) {
|
1998-11-15 00:01:26 +03:00
|
|
|
wordLen = 2;
|
|
|
|
contentLen = 2;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
wordLen = 1;
|
|
|
|
contentLen = 1;
|
|
|
|
}
|
|
|
|
justDidFirstLetter = PR_TRUE;
|
1998-11-12 19:31:38 +03:00
|
|
|
}
|
1999-09-18 20:22:34 +04:00
|
|
|
|
|
|
|
if (measureText) {
|
|
|
|
if (ts.mSmallCaps) {
|
|
|
|
MeasureSmallCapsText(aReflowState, ts, bp, wordLen, &width);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
aReflowState.rendContext->GetWidth(bp, wordLen, width);
|
|
|
|
if (ts.mLetterSpacing) {
|
|
|
|
width += ts.mLetterSpacing * wordLen;
|
|
|
|
}
|
1999-05-04 00:55:12 +04:00
|
|
|
}
|
1999-09-18 20:22:34 +04:00
|
|
|
lastWordWidth = width;
|
1998-10-26 20:27:53 +03:00
|
|
|
}
|
1998-09-09 02:34:40 +04:00
|
|
|
skipWhitespace = PR_FALSE;
|
|
|
|
}
|
|
|
|
|
1998-10-20 04:21:18 +04:00
|
|
|
// See if there is room for the text
|
1999-09-18 20:22:34 +04:00
|
|
|
if (measureText) {
|
|
|
|
if ((0 != x) && wrapping && (x + width > maxWidth)) {
|
|
|
|
// The text will not fit.
|
|
|
|
#ifdef NOISY_REFLOW
|
|
|
|
ListTag(stdout);
|
|
|
|
printf(": won't fit (at offset=%d) x=%d width=%d maxWidth=%d\n",
|
|
|
|
offset, x, width, maxWidth);
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
x += width;
|
|
|
|
prevMaxWordWidth = maxWordWidth;
|
|
|
|
if (width > maxWordWidth) {
|
|
|
|
maxWordWidth = width;
|
|
|
|
}
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
1999-09-18 20:22:34 +04:00
|
|
|
|
1998-10-22 00:03:54 +04:00
|
|
|
prevColumn = column;
|
|
|
|
column += wordLen;
|
1998-09-09 02:34:40 +04:00
|
|
|
endsInWhitespace = isWhitespace;
|
1998-10-20 04:21:18 +04:00
|
|
|
prevOffset = offset;
|
|
|
|
offset += contentLen;
|
1998-11-15 00:01:26 +03:00
|
|
|
if (!isWhitespace && justDidFirstLetter) {
|
1998-11-12 19:31:38 +03:00
|
|
|
// Time to stop
|
|
|
|
break;
|
|
|
|
}
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
1998-10-20 04:21:18 +04:00
|
|
|
if (tx.HasMultibyte()) {
|
1999-09-01 05:02:16 +04:00
|
|
|
mState |= TEXT_HAS_MULTIBYTE;
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
1998-10-10 08:35:21 +04:00
|
|
|
|
1999-09-18 20:22:34 +04:00
|
|
|
// If we didn't actually measure any text, then make sure it looks
|
|
|
|
// like we did
|
|
|
|
if (!measureText) {
|
|
|
|
x = mRect.width;
|
|
|
|
}
|
|
|
|
|
1998-10-20 04:21:18 +04:00
|
|
|
// Post processing logic to deal with word-breaking that spans
|
|
|
|
// multiple frames.
|
1998-10-22 00:03:54 +04:00
|
|
|
if (lineLayout.InWord()) {
|
1998-10-20 04:21:18 +04:00
|
|
|
// We are already in a word. This means a text frame prior to this
|
|
|
|
// one had a fragment of a nbword that is joined with this
|
1998-10-10 08:35:21 +04:00
|
|
|
// frame. It also means that the prior frame already found this
|
1998-10-20 04:21:18 +04:00
|
|
|
// frame and recorded it as part of the word.
|
1998-10-10 08:35:21 +04:00
|
|
|
#ifdef DEBUG_WORD_WRAPPING
|
|
|
|
ListTag(stdout);
|
1998-10-22 00:03:54 +04:00
|
|
|
printf(": in word; skipping\n");
|
1998-10-10 08:35:21 +04:00
|
|
|
#endif
|
1998-10-22 00:03:54 +04:00
|
|
|
lineLayout.ForgetWordFrame(this);
|
1998-10-10 08:35:21 +04:00
|
|
|
}
|
1999-02-24 08:24:06 +03:00
|
|
|
|
|
|
|
if (!lineLayout.InWord()) {
|
1998-10-20 04:21:18 +04:00
|
|
|
// There is no currently active word. This frame may contain the
|
1998-10-10 08:35:21 +04:00
|
|
|
// start of one.
|
|
|
|
if (endsInWhitespace) {
|
1998-10-20 04:21:18 +04:00
|
|
|
// Nope, this frame doesn't start a word.
|
1998-10-22 00:03:54 +04:00
|
|
|
lineLayout.ForgetWordFrames();
|
1998-10-10 08:35:21 +04:00
|
|
|
}
|
1998-10-22 00:03:54 +04:00
|
|
|
else if ((offset == contentLength) && (prevOffset >= 0)) {
|
1998-11-01 01:48:21 +03:00
|
|
|
// Force breakable to false when we aren't wrapping (this
|
|
|
|
// guarantees that the combined word will stay together)
|
|
|
|
if (!wrapping) {
|
|
|
|
breakable = PR_FALSE;
|
|
|
|
}
|
|
|
|
|
1998-10-20 04:21:18 +04:00
|
|
|
// This frame does start a word. However, there is no point
|
1998-11-01 01:48:21 +03:00
|
|
|
// messing around with it if we are already out of room. We
|
|
|
|
// always have room if we are not breakable.
|
|
|
|
if (!breakable || (x <= maxWidth)) {
|
1998-10-20 04:21:18 +04:00
|
|
|
// There is room for this word fragment. It's possible that
|
|
|
|
// this word fragment is the end of the text-run. If it's not
|
1998-10-10 08:35:21 +04:00
|
|
|
// then we continue with the look-ahead processing.
|
1998-10-22 00:03:54 +04:00
|
|
|
nsIFrame* next = lineLayout.FindNextText(this);
|
1998-10-10 08:35:21 +04:00
|
|
|
if (nsnull != next) {
|
|
|
|
#ifdef DEBUG_WORD_WRAPPING
|
1998-11-01 01:48:21 +03:00
|
|
|
nsAutoString tmp(tx.GetTextAt(0), offset-prevOffset);
|
1998-10-10 08:35:21 +04:00
|
|
|
ListTag(stdout);
|
|
|
|
printf(": start='");
|
|
|
|
fputs(tmp, stdout);
|
1999-09-18 03:14:47 +04:00
|
|
|
printf("' baseWidth=%d [%d,%d] next=",
|
|
|
|
lastWordWidth, prevOffset, offset);
|
|
|
|
ListTag(stdout, next);
|
|
|
|
printf("\n");
|
1998-10-10 08:35:21 +04:00
|
|
|
#endif
|
1999-08-19 10:06:57 +04:00
|
|
|
PRUnichar* pWordBuf = wordBuf;
|
|
|
|
PRUint32 aWordBufLen = WORD_BUF_SIZE;
|
|
|
|
if((nsnull !=bp) && (bp != wordBuf))
|
|
|
|
{
|
|
|
|
pWordBuf = bp;
|
|
|
|
// XXX To Do:
|
|
|
|
// make the aWordBufLen equal to mBufferLength of nsTextTransformer here
|
|
|
|
}
|
1998-10-20 04:21:18 +04:00
|
|
|
// Look ahead in the text-run and compute the final word
|
1998-10-10 08:35:21 +04:00
|
|
|
// width, taking into account any style changes and stopping
|
|
|
|
// at the first breakable point.
|
1999-09-18 20:22:34 +04:00
|
|
|
if (!measureText) {
|
|
|
|
// We didn't measure any text so we don't know lastWordWidth.
|
|
|
|
// We have to compute it now
|
|
|
|
if (ts.mSmallCaps) {
|
|
|
|
MeasureSmallCapsText(aReflowState, ts, tx.GetTextAt(prevOffset),
|
|
|
|
lastWordLen, &lastWordWidth);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
aReflowState.rendContext->GetWidth(tx.GetTextAt(prevOffset),
|
|
|
|
lastWordLen, lastWordWidth);
|
|
|
|
if (ts.mLetterSpacing) {
|
|
|
|
lastWordWidth += ts.mLetterSpacing * lastWordLen;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-09-17 03:31:59 +04:00
|
|
|
nscoord wordWidth = ComputeTotalWordWidth(&aPresContext, lb, lineLayout,
|
1999-04-20 04:23:33 +04:00
|
|
|
aReflowState, next,
|
1999-07-27 18:47:24 +04:00
|
|
|
lastWordWidth,
|
1999-08-19 10:06:57 +04:00
|
|
|
pWordBuf,
|
1999-07-27 18:47:24 +04:00
|
|
|
lastWordLen,
|
1999-08-19 10:06:57 +04:00
|
|
|
aWordBufLen
|
1999-07-27 18:47:24 +04:00
|
|
|
);
|
1998-11-01 01:48:21 +03:00
|
|
|
if (!breakable || (x - lastWordWidth + wordWidth <= maxWidth)) {
|
1998-10-20 04:21:18 +04:00
|
|
|
// The fully joined word has fit. Account for the joined
|
|
|
|
// word's affect on the max-element-size here (since the
|
|
|
|
// joined word is large than it's pieces, the right effect
|
|
|
|
// will occur from the perspective of the container
|
|
|
|
// reflowing this frame)
|
|
|
|
if (wordWidth > maxWordWidth) {
|
|
|
|
maxWordWidth = wordWidth;
|
1998-10-10 08:35:21 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
1999-09-18 03:14:47 +04:00
|
|
|
#ifdef NOISY_REFLOW
|
|
|
|
ListTag(stdout);
|
|
|
|
printf(": look-ahead (didn't fit) x=%d wordWidth=%d lastWordWidth=%d\n",
|
|
|
|
x, wordWidth, lastWordWidth);
|
|
|
|
#endif
|
1998-10-20 04:21:18 +04:00
|
|
|
// The fully joined word won't fit. We need to reduce our
|
1998-10-10 08:35:21 +04:00
|
|
|
// size by the lastWordWidth.
|
|
|
|
x -= lastWordWidth;
|
|
|
|
maxWordWidth = prevMaxWordWidth;
|
1998-10-20 04:21:18 +04:00
|
|
|
offset = prevOffset;
|
1998-10-22 00:03:54 +04:00
|
|
|
column = prevColumn;
|
1998-10-10 08:35:21 +04:00
|
|
|
#ifdef DEBUG_WORD_WRAPPING
|
|
|
|
printf(" x=%d maxWordWidth=%d len=%d\n", x, maxWordWidth,
|
1998-11-01 01:48:21 +03:00
|
|
|
offset - startingOffset);
|
1998-10-10 08:35:21 +04:00
|
|
|
#endif
|
1998-10-22 00:03:54 +04:00
|
|
|
lineLayout.ForgetWordFrames();
|
1998-10-10 08:35:21 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
1998-10-22 00:03:54 +04:00
|
|
|
lineLayout.SetColumn(column);
|
1998-09-09 02:34:40 +04:00
|
|
|
|
1998-11-01 01:48:21 +03:00
|
|
|
// Inform line layout of how this piece of text ends in whitespace
|
|
|
|
// (only text objects do this). Note that if x is zero then this
|
|
|
|
// text object collapsed into nothingness which means it shouldn't
|
|
|
|
// effect the current setting of the ends-in-whitespace flag.
|
|
|
|
lineLayout.SetUnderstandsWhiteSpace(PR_TRUE);
|
|
|
|
if (0 != x) {
|
|
|
|
lineLayout.SetEndsInWhiteSpace(endsInWhitespace);
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
1998-11-15 00:01:26 +03:00
|
|
|
if (justDidFirstLetter) {
|
1999-03-26 03:41:36 +03:00
|
|
|
lineLayout.SetFirstLetterFrame(this);
|
1998-11-15 00:01:26 +03:00
|
|
|
lineLayout.SetFirstLetterStyleOK(PR_FALSE);
|
1999-09-01 05:02:16 +04:00
|
|
|
mState |= TEXT_FIRST_LETTER;
|
1998-11-15 00:01:26 +03:00
|
|
|
}
|
1998-09-09 02:34:40 +04:00
|
|
|
|
1998-10-20 04:21:18 +04:00
|
|
|
// Setup metrics for caller; store final max-element-size information
|
1998-09-09 02:34:40 +04:00
|
|
|
aMetrics.width = x;
|
1998-10-27 19:52:34 +03:00
|
|
|
mComputedWidth = x;
|
1999-03-31 08:12:46 +04:00
|
|
|
if ((0 == x) && !ts.mPreformatted) {
|
1998-10-20 04:21:18 +04:00
|
|
|
aMetrics.height = 0;
|
|
|
|
aMetrics.ascent = 0;
|
|
|
|
aMetrics.descent = 0;
|
|
|
|
}
|
|
|
|
else {
|
1998-10-26 20:27:53 +03:00
|
|
|
ts.mNormalFont->GetHeight(aMetrics.height);
|
|
|
|
ts.mNormalFont->GetMaxAscent(aMetrics.ascent);
|
|
|
|
ts.mNormalFont->GetMaxDescent(aMetrics.descent);
|
1998-10-20 04:21:18 +04:00
|
|
|
}
|
1998-09-09 02:34:40 +04:00
|
|
|
if (!wrapping) {
|
|
|
|
maxWordWidth = x;
|
|
|
|
}
|
|
|
|
if (nsnull != aMetrics.maxElementSize) {
|
|
|
|
aMetrics.maxElementSize->width = maxWordWidth;
|
1998-10-20 04:21:18 +04:00
|
|
|
aMetrics.maxElementSize->height = aMetrics.height;
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
1998-10-26 20:27:53 +03:00
|
|
|
|
1998-10-22 00:03:54 +04:00
|
|
|
// Set content offset and length
|
|
|
|
mContentOffset = startingOffset;
|
|
|
|
mContentLength = offset - startingOffset;
|
|
|
|
|
1999-07-14 19:20:01 +04:00
|
|
|
// If it's an incremental reflow command, then invalidate our existing
|
|
|
|
// bounds.
|
|
|
|
// XXX We need a finer granularity than this, but it isn't clear what
|
|
|
|
// has actually changed...
|
|
|
|
if (eReflowReason_Incremental == aReflowState.reason) {
|
|
|
|
Invalidate(mRect);
|
|
|
|
}
|
|
|
|
|
1998-12-14 21:34:14 +03:00
|
|
|
//go to selection and ask if we are selected here. and where!!
|
1999-01-22 21:58:14 +03:00
|
|
|
|
1998-10-22 00:03:54 +04:00
|
|
|
nsReflowStatus rs = (offset == contentLength)
|
|
|
|
? NS_FRAME_COMPLETE
|
|
|
|
: NS_FRAME_NOT_COMPLETE;
|
|
|
|
if (endsInNewline) {
|
|
|
|
rs = NS_INLINE_LINE_BREAK_AFTER(rs);
|
1998-10-12 22:44:58 +04:00
|
|
|
}
|
1999-02-13 22:18:45 +03:00
|
|
|
else if ((offset != contentLength) && (offset == startingOffset)) {
|
|
|
|
// Break-before a long-word that doesn't fit here
|
1998-10-22 00:03:54 +04:00
|
|
|
rs = NS_INLINE_LINE_BREAK_BEFORE();
|
1998-10-12 22:44:58 +04:00
|
|
|
}
|
1998-10-22 00:03:54 +04:00
|
|
|
aStatus = rs;
|
|
|
|
|
1999-09-18 20:22:34 +04:00
|
|
|
// For future resize reflows we would like to avoid measuring the text.
|
|
|
|
// We can only do this if after this reflow we're:
|
|
|
|
// - complete. If we're not complete then our desired width doesn't
|
|
|
|
// represent our total size
|
|
|
|
// - we fit in the available space. We may be complete, but if we
|
|
|
|
// return a larger desired width than is available we may get pushed
|
|
|
|
// and our frame width won't get set
|
|
|
|
if ((NS_FRAME_COMPLETE == aStatus) && (aMetrics.width <= maxWidth)) {
|
|
|
|
mState |= TEXT_OPTIMIZE_RESIZE;
|
|
|
|
mRect.width = aMetrics.width;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mState &= ~TEXT_OPTIMIZE_RESIZE;
|
|
|
|
}
|
|
|
|
|
1999-09-18 03:14:47 +04:00
|
|
|
#ifdef NOISY_REFLOW
|
|
|
|
ListTag(stdout);
|
|
|
|
printf(": desiredSize=%d,%d(a=%d/d=%d) status=%x\n",
|
|
|
|
aMetrics.width, aMetrics.height, aMetrics.ascent, aMetrics.descent,
|
|
|
|
aStatus);
|
|
|
|
#endif
|
1998-10-22 00:03:54 +04:00
|
|
|
return NS_OK;
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
|
|
|
|
1998-10-27 19:52:34 +03:00
|
|
|
NS_IMETHODIMP
|
1999-04-20 04:23:33 +04:00
|
|
|
nsTextFrame::AdjustFrameSize(nscoord aExtraSpace, nscoord& aUsedSpace)
|
1998-10-27 19:52:34 +03:00
|
|
|
{
|
|
|
|
// Get the text fragments that make up our content
|
1998-12-02 19:45:20 +03:00
|
|
|
const nsTextFragment* frag;
|
1998-10-27 19:52:34 +03:00
|
|
|
PRInt32 numFrags;
|
|
|
|
nsITextContent* tc;
|
|
|
|
if (NS_OK == mContent->QueryInterface(kITextContentIID, (void**) &tc)) {
|
|
|
|
tc->GetText(frag, numFrags);
|
|
|
|
NS_RELEASE(tc);
|
|
|
|
|
|
|
|
// Find fragment that contains the end of the mapped content
|
|
|
|
PRInt32 endIndex = mContentOffset + mContentLength;
|
|
|
|
PRInt32 offset = 0;
|
1998-12-02 19:45:20 +03:00
|
|
|
const nsTextFragment* lastFrag = frag + numFrags;
|
1998-10-27 19:52:34 +03:00
|
|
|
while (frag < lastFrag) {
|
|
|
|
PRInt32 fragLen = frag->GetLength();
|
|
|
|
if (endIndex <= offset + fragLen) {
|
|
|
|
offset = mContentOffset - offset;
|
|
|
|
if (frag->Is2b()) {
|
|
|
|
const PRUnichar* cp = frag->Get2b() + offset;
|
|
|
|
const PRUnichar* end = cp + mContentLength;
|
|
|
|
while (cp < end) {
|
|
|
|
PRUnichar ch = *cp++;
|
|
|
|
if (XP_IS_SPACE(ch)) {
|
|
|
|
aUsedSpace = aExtraSpace;
|
|
|
|
mRect.width += aExtraSpace;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
const unsigned char* cp =
|
|
|
|
((const unsigned char*)frag->Get1b()) + offset;
|
|
|
|
const unsigned char* end = cp + mContentLength;
|
|
|
|
while (cp < end) {
|
|
|
|
PRUnichar ch = PRUnichar(*cp++);
|
|
|
|
if (XP_IS_SPACE(ch)) {
|
|
|
|
aUsedSpace = aExtraSpace;
|
|
|
|
mRect.width += aExtraSpace;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
offset += fragLen;
|
|
|
|
frag++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
aUsedSpace = 0;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-05-04 00:55:12 +04:00
|
|
|
nsTextFrame::TrimTrailingWhiteSpace(nsIPresContext* aPresContext,
|
1999-04-20 04:23:33 +04:00
|
|
|
nsIRenderingContext& aRC,
|
|
|
|
nscoord& aDeltaWidth)
|
1998-10-27 19:52:34 +03:00
|
|
|
{
|
|
|
|
nscoord dw = 0;
|
|
|
|
const nsStyleText* textStyle = (const nsStyleText*)
|
|
|
|
mStyleContext->GetStyleData(eStyleStruct_Text);
|
1999-03-31 08:12:46 +04:00
|
|
|
if ((NS_STYLE_WHITESPACE_PRE != textStyle->mWhiteSpace) &&
|
|
|
|
(NS_STYLE_WHITESPACE_MOZ_PRE_WRAP != textStyle->mWhiteSpace)) {
|
1998-10-27 19:52:34 +03:00
|
|
|
// Get font metrics for a space so we can adjust the width by the
|
|
|
|
// right amount.
|
|
|
|
const nsStyleFont* fontStyle = (const nsStyleFont*)
|
|
|
|
mStyleContext->GetStyleData(eStyleStruct_Font);
|
|
|
|
nscoord spaceWidth;
|
|
|
|
aRC.SetFont(fontStyle->mFont);
|
|
|
|
aRC.GetWidth(' ', spaceWidth);
|
|
|
|
|
|
|
|
// Get the text fragments that make up our content
|
1998-12-02 19:45:20 +03:00
|
|
|
const nsTextFragment* frag;
|
1998-10-27 19:52:34 +03:00
|
|
|
PRInt32 numFrags;
|
|
|
|
nsITextContent* tc;
|
|
|
|
if (NS_OK == mContent->QueryInterface(kITextContentIID, (void**) &tc)) {
|
|
|
|
tc->GetText(frag, numFrags);
|
|
|
|
NS_RELEASE(tc);
|
|
|
|
|
|
|
|
// Find fragment that contains the end of the mapped content
|
|
|
|
PRInt32 endIndex = mContentOffset + mContentLength;
|
|
|
|
PRInt32 offset = 0;
|
1998-12-02 19:45:20 +03:00
|
|
|
const nsTextFragment* lastFrag = frag + numFrags;
|
1998-10-27 19:52:34 +03:00
|
|
|
while (frag < lastFrag) {
|
|
|
|
PRInt32 fragLen = frag->GetLength();
|
|
|
|
if (endIndex <= offset + fragLen) {
|
|
|
|
// Look inside the fragments last few characters and see if they
|
|
|
|
// are whitespace. If so, count how much width was supplied by
|
|
|
|
// them.
|
|
|
|
offset = mContentOffset - offset;
|
|
|
|
if (frag->Is2b()) {
|
|
|
|
// XXX If by chance the last content fragment is *all*
|
|
|
|
// whitespace then this won't back up far enough.
|
|
|
|
const PRUnichar* cp = frag->Get2b() + offset;
|
|
|
|
const PRUnichar* end = cp + mContentLength;
|
|
|
|
if (--end >= cp) {
|
|
|
|
PRUnichar ch = *end;
|
|
|
|
if (XP_IS_SPACE(ch)) {
|
|
|
|
dw = spaceWidth;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
const unsigned char* cp =
|
|
|
|
((const unsigned char*)frag->Get1b()) + offset;
|
|
|
|
const unsigned char* end = cp + mContentLength;
|
|
|
|
if (--end >= cp) {
|
|
|
|
PRUnichar ch = PRUnichar(*end);
|
|
|
|
if (XP_IS_SPACE(ch)) {
|
|
|
|
dw = spaceWidth;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
offset += fragLen;
|
|
|
|
frag++;
|
|
|
|
}
|
|
|
|
}
|
1998-11-01 01:48:21 +03:00
|
|
|
if (mRect.width > dw) {
|
|
|
|
mRect.width -= dw;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
dw = mRect.width;
|
|
|
|
mRect.width = 0;
|
|
|
|
}
|
1998-10-27 19:52:34 +03:00
|
|
|
mComputedWidth -= dw;
|
|
|
|
}
|
|
|
|
if (0 != dw) {
|
1999-09-01 05:02:16 +04:00
|
|
|
mState |= TEXT_TRIMMED_WS;
|
1998-10-27 19:52:34 +03:00
|
|
|
}
|
|
|
|
else {
|
1999-09-01 05:02:16 +04:00
|
|
|
mState &= ~TEXT_TRIMMED_WS;
|
1998-10-27 19:52:34 +03:00
|
|
|
}
|
|
|
|
aDeltaWidth = dw;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-10-10 08:35:21 +04:00
|
|
|
nscoord
|
1999-04-20 04:23:33 +04:00
|
|
|
nsTextFrame::ComputeTotalWordWidth(nsIPresContext* aPresContext,
|
1999-09-17 03:31:59 +04:00
|
|
|
nsILineBreaker* aLineBreaker,
|
1999-04-20 04:23:33 +04:00
|
|
|
nsLineLayout& aLineLayout,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsIFrame* aNextFrame,
|
1999-07-27 18:47:24 +04:00
|
|
|
nscoord aBaseWidth,
|
|
|
|
const PRUnichar* aWordBuf,
|
|
|
|
PRUint32 aWordBufLen,
|
|
|
|
PRUint32 aWordBufSize)
|
1998-10-10 08:35:21 +04:00
|
|
|
{
|
|
|
|
nscoord addedWidth = 0;
|
|
|
|
while (nsnull != aNextFrame) {
|
1999-04-21 23:59:16 +04:00
|
|
|
nsIContent* content = nsnull;
|
|
|
|
if ((NS_OK == aNextFrame->GetContent(&content)) && (nsnull != content)) {
|
1998-10-10 08:35:21 +04:00
|
|
|
#ifdef DEBUG_WORD_WRAPPING
|
1999-04-21 23:59:16 +04:00
|
|
|
printf(" next textRun=");
|
|
|
|
nsFrame::ListTag(stdout, aNextFrame);
|
|
|
|
printf("\n");
|
1998-10-10 08:35:21 +04:00
|
|
|
#endif
|
1999-04-21 23:59:16 +04:00
|
|
|
nsITextContent* tc;
|
|
|
|
if (NS_OK == content->QueryInterface(kITextContentIID, (void**)&tc)) {
|
|
|
|
PRBool stop;
|
|
|
|
nscoord moreWidth = ComputeWordFragmentWidth(aPresContext,
|
1999-09-17 03:31:59 +04:00
|
|
|
aLineBreaker,
|
1999-04-21 23:59:16 +04:00
|
|
|
aLineLayout,
|
|
|
|
aReflowState,
|
1999-09-18 03:14:47 +04:00
|
|
|
aNextFrame, content, tc,
|
1999-07-27 18:47:24 +04:00
|
|
|
&stop,
|
|
|
|
aWordBuf,
|
|
|
|
aWordBufLen,
|
|
|
|
aWordBufSize);
|
1999-04-21 23:59:16 +04:00
|
|
|
NS_RELEASE(tc);
|
|
|
|
NS_RELEASE(content);
|
|
|
|
addedWidth += moreWidth;
|
1998-10-10 08:35:21 +04:00
|
|
|
#ifdef DEBUG_WORD_WRAPPING
|
1999-04-21 23:59:16 +04:00
|
|
|
printf(" moreWidth=%d (addedWidth=%d) stop=%c\n", moreWidth,
|
|
|
|
addedWidth, stop?'T':'F');
|
1998-10-10 08:35:21 +04:00
|
|
|
#endif
|
1999-04-21 23:59:16 +04:00
|
|
|
if (stop) {
|
1998-10-10 08:35:21 +04:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
1999-04-21 23:59:16 +04:00
|
|
|
else {
|
|
|
|
// It claimed it was text but it doesn't implement the
|
|
|
|
// nsITextContent API. Therefore I don't know what to do with it
|
|
|
|
// and can't look inside it. Oh well.
|
|
|
|
NS_RELEASE(content);
|
|
|
|
goto done;
|
|
|
|
}
|
1998-10-10 08:35:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Move on to the next frame in the text-run
|
|
|
|
aNextFrame = aLineLayout.FindNextText(aNextFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
done:;
|
|
|
|
#ifdef DEBUG_WORD_WRAPPING
|
|
|
|
printf(" total word width=%d\n", aBaseWidth + addedWidth);
|
|
|
|
#endif
|
|
|
|
return aBaseWidth + addedWidth;
|
|
|
|
}
|
|
|
|
|
1999-04-20 04:23:33 +04:00
|
|
|
#if 0
|
|
|
|
nsIStyleContext*
|
|
|
|
nsTextFrame::GetCorrectStyleContext(nsIPresContext* aPresContext,
|
1999-03-29 08:15:07 +04:00
|
|
|
nsLineLayout& aLineLayout,
|
1998-10-10 08:35:21 +04:00
|
|
|
const nsHTMLReflowState& aReflowState,
|
1999-04-20 04:23:33 +04:00
|
|
|
nsIFrame* aTextFrame)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
nscoord
|
|
|
|
nsTextFrame::ComputeWordFragmentWidth(nsIPresContext* aPresContext,
|
1999-09-17 03:31:59 +04:00
|
|
|
nsILineBreaker* aLineBreaker,
|
1999-04-20 04:23:33 +04:00
|
|
|
nsLineLayout& aLineLayout,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsIFrame* aTextFrame,
|
1999-09-18 03:14:47 +04:00
|
|
|
nsIContent* aContent,
|
1999-04-20 04:23:33 +04:00
|
|
|
nsITextContent* aText,
|
1999-07-27 18:47:24 +04:00
|
|
|
PRBool* aStop,
|
|
|
|
const PRUnichar* aWordBuf,
|
|
|
|
PRUint32 &aWordBufLen,
|
|
|
|
PRUint32 aWordBufSize)
|
1998-10-10 08:35:21 +04:00
|
|
|
{
|
1998-10-20 04:21:18 +04:00
|
|
|
PRUnichar buf[TEXT_BUF_SIZE];
|
1999-09-17 03:31:59 +04:00
|
|
|
nsTextTransformer tx(buf, TEXT_BUF_SIZE,aLineBreaker,nsnull);
|
1999-09-18 03:14:47 +04:00
|
|
|
tx.Init(aTextFrame, aContent, 0);
|
1998-10-20 04:21:18 +04:00
|
|
|
|
|
|
|
PRBool isWhitespace;
|
|
|
|
PRInt32 wordLen, contentLen;
|
1998-10-20 20:46:14 +04:00
|
|
|
PRUnichar* bp = tx.GetNextWord(PR_TRUE, wordLen, contentLen, isWhitespace);
|
1998-10-20 04:21:18 +04:00
|
|
|
if ((nsnull == bp) || isWhitespace) {
|
1998-10-10 08:35:21 +04:00
|
|
|
// Don't bother measuring nothing
|
1999-04-20 04:23:33 +04:00
|
|
|
*aStop = PR_TRUE;
|
1998-10-10 08:35:21 +04:00
|
|
|
return 0;
|
|
|
|
}
|
1999-04-20 04:23:33 +04:00
|
|
|
*aStop = contentLen < tx.GetContentLength();
|
1998-10-10 08:35:21 +04:00
|
|
|
|
1999-07-27 18:47:24 +04:00
|
|
|
// we need to adjust the length by look at the two pieces together
|
|
|
|
PRUint32 copylen = 2*( ((wordLen + aWordBufLen) > aWordBufSize) ?
|
|
|
|
(aWordBufSize - aWordBufLen) :
|
|
|
|
wordLen
|
|
|
|
);
|
1999-09-04 02:46:16 +04:00
|
|
|
if((aWordBufSize > aWordBufLen) && (copylen > 0))
|
1999-07-27 18:47:24 +04:00
|
|
|
{
|
|
|
|
nsCRT::memcpy((void*)&(aWordBuf[aWordBufLen]), buf, copylen);
|
|
|
|
|
|
|
|
PRUint32 breakP=0;
|
|
|
|
PRBool needMore=PR_TRUE;
|
1999-09-19 04:59:38 +04:00
|
|
|
nsresult lres = aLineBreaker->Next(aWordBuf, aWordBufLen+wordLen, 0, &breakP, &needMore);
|
1999-07-27 18:47:24 +04:00
|
|
|
if(NS_SUCCEEDED(lres))
|
|
|
|
{
|
|
|
|
// when we look at two pieces text together, we might decide to break
|
|
|
|
// eariler than if we only look at the 2nd pieces of text
|
|
|
|
if(!needMore && (breakP < (aWordBufLen + wordLen)))
|
|
|
|
{
|
|
|
|
wordLen = breakP - aWordBufLen;
|
|
|
|
if(wordLen < 0)
|
|
|
|
wordLen = 0;
|
|
|
|
*aStop = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// if we don't stop, we need to extent the buf so the next
|
|
|
|
// one can see this part otherwise, it does not matter since we will stop anyway
|
|
|
|
if(! *aStop)
|
|
|
|
aWordBufLen += wordLen;
|
|
|
|
}
|
|
|
|
if((*aStop) && (wordLen == 0))
|
|
|
|
return 0;
|
|
|
|
|
1998-10-26 20:27:53 +03:00
|
|
|
nsIStyleContext* sc;
|
1999-02-10 03:42:56 +03:00
|
|
|
if ((NS_OK == aTextFrame->GetStyleContext(&sc)) &&
|
1998-10-26 20:27:53 +03:00
|
|
|
(nsnull != sc)) {
|
1998-10-10 08:35:21 +04:00
|
|
|
// Measure the piece of text. Note that we have to select the
|
|
|
|
// appropriate font into the text first because the rendering
|
|
|
|
// context has our font in it, not the font that aText is using.
|
|
|
|
nscoord width;
|
|
|
|
nsIRenderingContext& rc = *aReflowState.rendContext;
|
1998-10-30 05:08:25 +03:00
|
|
|
nsIFontMetrics* oldfm;
|
|
|
|
rc.GetFontMetrics(oldfm);
|
1998-10-26 20:27:53 +03:00
|
|
|
|
1999-04-20 04:23:33 +04:00
|
|
|
TextStyle ts(&aLineLayout.mPresContext, rc, sc);
|
1998-10-26 20:27:53 +03:00
|
|
|
if (ts.mSmallCaps) {
|
1999-04-20 04:23:33 +04:00
|
|
|
MeasureSmallCapsText(aReflowState, ts, buf, wordLen, &width);
|
1998-10-20 04:21:18 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
rc.GetWidth(buf, wordLen, width);
|
|
|
|
}
|
1998-10-10 08:35:21 +04:00
|
|
|
rc.SetFont(oldfm);
|
1998-11-28 07:24:46 +03:00
|
|
|
NS_IF_RELEASE(oldfm);
|
1998-10-26 20:27:53 +03:00
|
|
|
NS_RELEASE(sc);
|
1998-10-20 04:21:18 +04:00
|
|
|
|
1998-10-10 08:35:21 +04:00
|
|
|
#ifdef DEBUG_WORD_WRAPPING
|
1998-10-20 04:21:18 +04:00
|
|
|
nsAutoString tmp(bp, wordLen);
|
1998-10-10 08:35:21 +04:00
|
|
|
printf(" fragment='");
|
|
|
|
fputs(tmp, stdout);
|
1998-10-20 04:21:18 +04:00
|
|
|
printf("' width=%d [wordLen=%d contentLen=%d ContentLength=%d]\n",
|
|
|
|
width, wordLen, contentLen, tx.GetContentLength());
|
1998-10-10 08:35:21 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// Remember the text frame for later so that we don't bother doing
|
|
|
|
// the word look ahead.
|
|
|
|
aLineLayout.RecordWordFrame(aTextFrame);
|
|
|
|
return width;
|
|
|
|
}
|
|
|
|
|
1999-04-20 04:23:33 +04:00
|
|
|
*aStop = PR_TRUE;
|
1998-10-10 08:35:21 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1998-10-20 04:21:18 +04:00
|
|
|
// Translate the mapped content into a string that's printable
|
|
|
|
void
|
1999-04-20 04:23:33 +04:00
|
|
|
nsTextFrame::ToCString(nsString& aBuf, PRInt32* aContentLength) const
|
1998-09-09 02:34:40 +04:00
|
|
|
{
|
1998-10-20 04:21:18 +04:00
|
|
|
const nsTextFragment* frag;
|
|
|
|
PRInt32 numFrags;
|
|
|
|
|
|
|
|
// Get the frames text content
|
|
|
|
nsITextContent* tc;
|
|
|
|
if (NS_OK != mContent->QueryInterface(kITextContentIID, (void**) &tc)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
tc->GetText(frag, numFrags);
|
|
|
|
NS_RELEASE(tc);
|
|
|
|
|
|
|
|
// Compute the total length of the text content.
|
|
|
|
PRInt32 sum = 0;
|
|
|
|
PRInt32 i, n = numFrags;
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
sum += frag[i].GetLength();
|
|
|
|
}
|
1999-04-20 04:23:33 +04:00
|
|
|
*aContentLength = sum;
|
1998-10-20 04:21:18 +04:00
|
|
|
|
|
|
|
// Set current fragment and current fragment offset
|
|
|
|
PRInt32 fragOffset = 0, offset = 0;
|
|
|
|
n = numFrags;
|
|
|
|
while (--n >= 0) {
|
|
|
|
if (mContentOffset < offset + frag->GetLength()) {
|
|
|
|
fragOffset = mContentOffset - offset;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
offset += frag->GetLength();
|
|
|
|
frag++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (0 == mContentLength) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
n = mContentLength;
|
|
|
|
for (;;) {
|
|
|
|
PRUnichar ch = frag->CharAt(fragOffset);
|
1998-09-09 02:34:40 +04:00
|
|
|
if (ch == '\r') {
|
|
|
|
aBuf.Append("\\r");
|
|
|
|
} else if (ch == '\n') {
|
|
|
|
aBuf.Append("\\n");
|
|
|
|
} else if (ch == '\t') {
|
|
|
|
aBuf.Append("\\t");
|
|
|
|
} else if ((ch < ' ') || (ch >= 127)) {
|
|
|
|
aBuf.Append("\\0");
|
|
|
|
aBuf.Append((PRInt32)ch, 8);
|
|
|
|
} else {
|
|
|
|
aBuf.Append(ch);
|
|
|
|
}
|
1998-10-20 04:21:18 +04:00
|
|
|
if (--n == 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (++fragOffset == frag->GetLength()) {
|
|
|
|
frag++;
|
|
|
|
fragOffset = 0;
|
|
|
|
}
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-02-24 08:33:40 +03:00
|
|
|
NS_IMETHODIMP
|
1999-04-20 04:23:33 +04:00
|
|
|
nsTextFrame::GetFrameType(nsIAtom** aType) const
|
1999-02-24 08:33:40 +03:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aType, "null OUT parameter pointer");
|
|
|
|
*aType = nsLayoutAtoms::textFrame;
|
|
|
|
NS_ADDREF(*aType);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-09-01 05:02:16 +04:00
|
|
|
#ifdef DEBUG
|
1999-08-31 07:09:40 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTextFrame::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const
|
|
|
|
{
|
|
|
|
if (!aResult) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
*aResult = sizeof(*this);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-09-01 05:02:16 +04:00
|
|
|
#endif
|
1999-08-31 07:09:40 +04:00
|
|
|
|
1998-09-09 02:34:40 +04:00
|
|
|
NS_IMETHODIMP
|
1999-04-20 04:23:33 +04:00
|
|
|
nsTextFrame::GetFrameName(nsString& aResult) const
|
1998-09-09 02:34:40 +04:00
|
|
|
{
|
1998-11-19 20:22:29 +03:00
|
|
|
return MakeFrameName("Text", aResult);
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-04-20 04:23:33 +04:00
|
|
|
nsTextFrame::List(FILE* out, PRInt32 aIndent) const
|
1998-09-09 02:34:40 +04:00
|
|
|
{
|
|
|
|
// Output the tag
|
1999-03-05 07:28:40 +03:00
|
|
|
IndentBy(out, aIndent);
|
1998-09-09 02:34:40 +04:00
|
|
|
ListTag(out);
|
|
|
|
nsIView* view;
|
1999-02-10 08:38:18 +03:00
|
|
|
GetView(&view);
|
1998-09-09 02:34:40 +04:00
|
|
|
if (nsnull != view) {
|
|
|
|
fprintf(out, " [view=%p]", view);
|
|
|
|
}
|
|
|
|
|
1998-10-20 04:21:18 +04:00
|
|
|
PRInt32 contentLength;
|
|
|
|
nsAutoString tmp;
|
1999-04-20 04:23:33 +04:00
|
|
|
ToCString(tmp, &contentLength);
|
1998-09-09 02:34:40 +04:00
|
|
|
|
1998-10-20 04:21:18 +04:00
|
|
|
// Output the first/last content offset and prev/next in flow info
|
|
|
|
PRBool isComplete = (mContentOffset + mContentLength) == contentLength;
|
1999-09-01 05:02:16 +04:00
|
|
|
fprintf(out, "[%d,%d,%c] ",
|
1998-09-09 02:34:40 +04:00
|
|
|
mContentOffset, mContentOffset+mContentLength-1,
|
1999-09-01 05:02:16 +04:00
|
|
|
isComplete ? 'T':'F');
|
1999-03-26 03:41:36 +03:00
|
|
|
|
1999-04-28 02:13:42 +04:00
|
|
|
if (nsnull != mNextSibling) {
|
|
|
|
fprintf(out, " next=%p", mNextSibling);
|
|
|
|
}
|
1998-09-09 02:34:40 +04:00
|
|
|
if (nsnull != mPrevInFlow) {
|
|
|
|
fprintf(out, "prev-in-flow=%p ", mPrevInFlow);
|
|
|
|
}
|
|
|
|
if (nsnull != mNextInFlow) {
|
|
|
|
fprintf(out, "next-in-flow=%p ", mNextInFlow);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Output the rect and state
|
1999-03-05 07:28:40 +03:00
|
|
|
fprintf(out, " {%d,%d,%d,%d}", mRect.x, mRect.y, mRect.width, mRect.height);
|
1998-09-09 02:34:40 +04:00
|
|
|
if (0 != mState) {
|
|
|
|
fprintf(out, " [state=%08x]", mState);
|
|
|
|
}
|
1999-04-28 02:13:42 +04:00
|
|
|
fprintf(out, " sc=%p<\n", mStyleContext);
|
1998-09-09 02:34:40 +04:00
|
|
|
|
|
|
|
// Output the text
|
|
|
|
aIndent++;
|
|
|
|
|
1999-03-05 07:28:40 +03:00
|
|
|
IndentBy(out, aIndent);
|
1998-09-09 02:34:40 +04:00
|
|
|
fputs("\"", out);
|
|
|
|
fputs(tmp, out);
|
|
|
|
fputs("\"\n", out);
|
|
|
|
|
|
|
|
aIndent--;
|
1999-03-05 07:28:40 +03:00
|
|
|
IndentBy(out, aIndent);
|
1998-09-09 02:34:40 +04:00
|
|
|
fputs(">\n", out);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-06-20 00:36:44 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//STORAGE FOR LATER MAYBE
|
|
|
|
#if 0
|
|
|
|
nsTextFrame *frame = this;
|
|
|
|
while(frame = (nsTextFrame *)frame->GetPrevInFlow()){
|
|
|
|
result = NS_OK;
|
|
|
|
nsPoint futurecoord;
|
|
|
|
frame->GetOffsetFromView(futurecoord, &view);
|
|
|
|
if (view == nsnull) return NS_ERROR_UNEXPECTED;
|
|
|
|
nscoord x,y;
|
|
|
|
do {
|
|
|
|
view->GetPosition(&x, &y);
|
|
|
|
futurecoord.x += x;
|
|
|
|
futurecoord.y += y;
|
|
|
|
view->GetParent(view);
|
|
|
|
} while (view);
|
|
|
|
if (coord.y > futurecoord.y)
|
|
|
|
{
|
|
|
|
if (coord.x < futurecoord.x)
|
|
|
|
{//keep going back until y is up again or coord.x is greater than future coord.x
|
|
|
|
nsTextFrame *lookahead = nsnull;
|
|
|
|
while(lookahead = (nsTextFrame *)frame->GetPrevInFlow()){
|
|
|
|
result = NS_OK;
|
|
|
|
nsPoint futurecoord2;
|
|
|
|
lookahead->GetOffsetFromView(futurecoord2, &view);
|
|
|
|
if (view == nsnull) return NS_ERROR_UNEXPECTED;
|
|
|
|
do {
|
|
|
|
view->GetPosition(&x, &y);
|
|
|
|
futurecoord2.x += x;
|
|
|
|
futurecoord2.y += y;
|
|
|
|
view->GetParent(view);
|
|
|
|
} while (view);
|
|
|
|
if (futurecoord.y > futurecoord2.y)//gone too far
|
|
|
|
break;
|
|
|
|
frame = lookahead;
|
|
|
|
futurecoord = futurecoord2;
|
|
|
|
if (coord.x >=futurecoord2.x)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//definately this one then
|
|
|
|
nscoord newcoord;
|
|
|
|
newcoord = coord.x ;//- futurecoord.x;
|
|
|
|
#endif
|