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-09-10 00:53:18 +04:00
|
|
|
#include "nsCOMPtr.h"
|
1998-09-09 02:34:40 +04:00
|
|
|
#include "nsFrame.h"
|
|
|
|
#include "nsHTMLParts.h"
|
|
|
|
#include "nsHTMLIIDs.h"
|
|
|
|
#include "nsIPresContext.h"
|
1998-09-15 04:19:49 +04:00
|
|
|
#include "nsLineLayout.h"
|
1998-09-09 02:34:40 +04:00
|
|
|
#include "nsStyleConsts.h"
|
|
|
|
#include "nsHTMLAtoms.h"
|
|
|
|
#include "nsIStyleContext.h"
|
|
|
|
#include "nsIFontMetrics.h"
|
|
|
|
#include "nsIRenderingContext.h"
|
|
|
|
|
1998-10-03 08:28:05 +04:00
|
|
|
class BRFrame : public nsFrame {
|
1998-09-09 02:34:40 +04:00
|
|
|
public:
|
|
|
|
// 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-10-03 08:28:05 +04:00
|
|
|
// nsIHTMLReflow
|
|
|
|
NS_IMETHOD Reflow(nsIPresContext& aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus);
|
1999-06-20 00:36:44 +04:00
|
|
|
NS_IMETHOD GetPosition(nsIPresContext& aCX,
|
1999-09-10 00:53:18 +04:00
|
|
|
nscoord aXCoord,
|
|
|
|
nsIContent** aNewContent,
|
|
|
|
PRInt32& aContentOffset,
|
|
|
|
PRInt32& aContentOffsetEnd);
|
1998-09-09 02:34:40 +04:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~BRFrame();
|
|
|
|
};
|
|
|
|
|
|
|
|
nsresult
|
1999-05-12 02:03:29 +04:00
|
|
|
NS_NewBRFrame(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;
|
|
|
|
}
|
1998-12-03 09:31:43 +03:00
|
|
|
nsIFrame* frame = new BRFrame;
|
1998-09-09 02:34:40 +04:00
|
|
|
if (nsnull == frame) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
1999-05-12 02:03:29 +04:00
|
|
|
*aNewFrame = frame;
|
1998-09-09 02:34:40 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
BRFrame::~BRFrame()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
1999-09-10 00:53:18 +04:00
|
|
|
NS_IMETHODIMP
|
1998-09-30 02:31:22 +04:00
|
|
|
BRFrame::Paint(nsIPresContext& aPresContext,
|
1998-09-09 02:34:40 +04:00
|
|
|
nsIRenderingContext& aRenderingContext,
|
1998-12-18 18:54:23 +03:00
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
nsFramePaintLayer aWhichLayer)
|
1998-09-09 02:34:40 +04:00
|
|
|
{
|
1999-03-26 03:37:22 +03:00
|
|
|
if ((NS_FRAME_PAINT_LAYER_DEBUG == aWhichLayer) && GetShowFrameBorders()) {
|
1999-02-12 20:45:58 +03:00
|
|
|
float p2t;
|
|
|
|
aPresContext.GetPixelsToTwips(&p2t);
|
1998-09-30 02:31:22 +04:00
|
|
|
nscoord five = NSIntPixelsToTwips(5, p2t);
|
1998-09-09 02:34:40 +04:00
|
|
|
aRenderingContext.SetColor(NS_RGB(0, 255, 255));
|
1998-09-30 02:31:22 +04:00
|
|
|
aRenderingContext.FillRect(0, 0, five, five*2);
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1998-10-03 08:28:05 +04:00
|
|
|
BRFrame::Reflow(nsIPresContext& aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aMetrics,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
1998-09-09 02:34:40 +04:00
|
|
|
{
|
1999-09-10 00:53:18 +04:00
|
|
|
if (aMetrics.maxElementSize) {
|
1998-09-09 02:34:40 +04:00
|
|
|
aMetrics.maxElementSize->width = 0;
|
|
|
|
aMetrics.maxElementSize->height = 0;
|
|
|
|
}
|
1998-09-30 02:31:22 +04:00
|
|
|
aMetrics.height = 0;
|
1998-09-09 02:34:40 +04:00
|
|
|
aMetrics.width = 0;
|
1998-10-03 01:49:47 +04:00
|
|
|
aMetrics.ascent = 0;
|
|
|
|
aMetrics.descent = 0;
|
1998-09-09 02:34:40 +04:00
|
|
|
|
1999-03-26 03:37:22 +03:00
|
|
|
// Only when the BR is operating in a line-layout situation will it
|
|
|
|
// behave like a BR.
|
1999-07-20 07:51:46 +04:00
|
|
|
if (nsnull != aReflowState.mLineLayout) {
|
|
|
|
if (aReflowState.mLineLayout->CanPlaceFloaterNow()) {
|
1999-04-03 22:57:30 +04:00
|
|
|
// If we can place a floater on the line now it means that the
|
|
|
|
// line is effectively empty (there may be zero sized compressed
|
|
|
|
// white-space frames on the line, but they are to be ignored).
|
|
|
|
//
|
|
|
|
// Because this frame is going to terminate the line we know
|
|
|
|
// that nothing else will go on the line. Therefore, in this
|
|
|
|
// case only, we provide some height for the BR frame so that it
|
|
|
|
// creates some vertical whitespace.
|
|
|
|
const nsStyleFont* font = (const nsStyleFont*)
|
|
|
|
mStyleContext->GetStyleData(eStyleStruct_Font);
|
|
|
|
aReflowState.rendContext->SetFont(font->mFont);
|
1999-09-10 00:53:18 +04:00
|
|
|
nsCOMPtr<nsIFontMetrics> fm;
|
|
|
|
aReflowState.rendContext->GetFontMetrics(*getter_AddRefs(fm));
|
|
|
|
if (fm) {
|
|
|
|
fm->GetHeight(aMetrics.height);
|
|
|
|
aMetrics.ascent = aMetrics.height;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
aMetrics.ascent = aMetrics.height = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXX temporary until I figure out a better solution; see the
|
|
|
|
// code in nsLineLayout::VerticalAlignFrames that zaps minY/maxY
|
|
|
|
// if the width is zero.
|
|
|
|
// XXX This also fixes bug 10036!
|
|
|
|
aMetrics.width = 1;
|
|
|
|
|
|
|
|
// Update max-element-size to keep us honest
|
|
|
|
if (aMetrics.maxElementSize) {
|
|
|
|
if (aMetrics.width > aMetrics.maxElementSize->width) {
|
|
|
|
aMetrics.maxElementSize->width = aMetrics.width;
|
|
|
|
}
|
|
|
|
if (aMetrics.height > aMetrics.maxElementSize->height) {
|
|
|
|
aMetrics.maxElementSize->height = aMetrics.height;
|
|
|
|
}
|
|
|
|
}
|
1999-04-03 22:57:30 +04:00
|
|
|
}
|
1999-03-26 03:37:22 +03:00
|
|
|
|
|
|
|
// Return our reflow status
|
|
|
|
PRUint32 breakType = aReflowState.mStyleDisplay->mBreakType;
|
|
|
|
if (NS_STYLE_CLEAR_NONE == breakType) {
|
|
|
|
breakType = NS_STYLE_CLEAR_LINE;
|
|
|
|
}
|
1998-10-03 08:28:05 +04:00
|
|
|
|
1999-03-26 03:37:22 +03:00
|
|
|
aStatus = NS_INLINE_BREAK | NS_INLINE_BREAK_AFTER |
|
|
|
|
NS_INLINE_MAKE_BREAK_TYPE(breakType);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
aStatus = NS_FRAME_COMPLETE;
|
|
|
|
}
|
1998-10-03 08:28:05 +04:00
|
|
|
return NS_OK;
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
1999-06-20 00:36:44 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
1999-09-08 23:43:17 +04:00
|
|
|
NS_IMETHODIMP BRFrame::GetPosition(nsIPresContext& aCX,
|
|
|
|
nscoord aCoord,
|
|
|
|
nsIContent ** aContent,
|
|
|
|
PRInt32& aOffsetBegin,
|
|
|
|
PRInt32& aOffsetEnd)
|
1999-06-20 00:36:44 +04:00
|
|
|
{
|
1999-09-08 23:43:17 +04:00
|
|
|
nsresult returnval = nsFrame::GetPosition(aCX,aCoord,aContent,aOffsetBegin,aOffsetEnd);
|
|
|
|
if (NS_SUCCEEDED(returnval))
|
|
|
|
aOffsetEnd = aOffsetBegin;//BRFrames should return a collapsed selection before itself
|
|
|
|
return returnval;
|
1999-06-20 00:36:44 +04:00
|
|
|
}
|