1998-09-08 22:34:40 +00: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-09 20:53:18 +00:00
|
|
|
#include "nsCOMPtr.h"
|
1998-09-08 22:34:40 +00:00
|
|
|
#include "nsFrame.h"
|
|
|
|
#include "nsHTMLParts.h"
|
|
|
|
#include "nsHTMLIIDs.h"
|
|
|
|
#include "nsIPresContext.h"
|
1998-09-15 00:19:49 +00:00
|
|
|
#include "nsLineLayout.h"
|
1998-09-08 22:34:40 +00:00
|
|
|
#include "nsStyleConsts.h"
|
|
|
|
#include "nsHTMLAtoms.h"
|
|
|
|
#include "nsIStyleContext.h"
|
|
|
|
#include "nsIFontMetrics.h"
|
|
|
|
#include "nsIRenderingContext.h"
|
|
|
|
|
1998-10-03 04:28:05 +00:00
|
|
|
class BRFrame : public nsFrame {
|
1998-09-08 22:34:40 +00:00
|
|
|
public:
|
|
|
|
// nsIFrame
|
|
|
|
NS_IMETHOD Paint(nsIPresContext& aPresContext,
|
|
|
|
nsIRenderingContext& aRenderingContext,
|
1998-12-18 15:54:23 +00:00
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
nsFramePaintLayer aWhichLayer);
|
1998-09-08 22:34:40 +00:00
|
|
|
|
1998-10-03 04:28:05 +00:00
|
|
|
// nsIHTMLReflow
|
|
|
|
NS_IMETHOD Reflow(nsIPresContext& aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus);
|
1999-06-19 20:36:44 +00:00
|
|
|
NS_IMETHOD GetPosition(nsIPresContext& aCX,
|
1999-09-09 20:53:18 +00:00
|
|
|
nscoord aXCoord,
|
|
|
|
nsIContent** aNewContent,
|
|
|
|
PRInt32& aContentOffset,
|
|
|
|
PRInt32& aContentOffsetEnd);
|
1998-09-08 22:34:40 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~BRFrame();
|
|
|
|
};
|
|
|
|
|
|
|
|
nsresult
|
1999-05-11 22:03:29 +00:00
|
|
|
NS_NewBRFrame(nsIFrame** aNewFrame)
|
1998-09-08 22:34:40 +00:00
|
|
|
{
|
1999-05-11 22:03:29 +00:00
|
|
|
NS_PRECONDITION(aNewFrame, "null OUT ptr");
|
|
|
|
if (nsnull == aNewFrame) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
1998-12-03 06:31:43 +00:00
|
|
|
nsIFrame* frame = new BRFrame;
|
1998-09-08 22:34:40 +00:00
|
|
|
if (nsnull == frame) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
1999-05-11 22:03:29 +00:00
|
|
|
*aNewFrame = frame;
|
1998-09-08 22:34:40 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
BRFrame::~BRFrame()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
1999-09-09 20:53:18 +00:00
|
|
|
NS_IMETHODIMP
|
1998-09-29 22:31:22 +00:00
|
|
|
BRFrame::Paint(nsIPresContext& aPresContext,
|
1998-09-08 22:34:40 +00:00
|
|
|
nsIRenderingContext& aRenderingContext,
|
1998-12-18 15:54:23 +00:00
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
nsFramePaintLayer aWhichLayer)
|
1998-09-08 22:34:40 +00:00
|
|
|
{
|
1999-03-26 00:37:22 +00:00
|
|
|
if ((NS_FRAME_PAINT_LAYER_DEBUG == aWhichLayer) && GetShowFrameBorders()) {
|
1999-02-12 17:45:58 +00:00
|
|
|
float p2t;
|
|
|
|
aPresContext.GetPixelsToTwips(&p2t);
|
1998-09-29 22:31:22 +00:00
|
|
|
nscoord five = NSIntPixelsToTwips(5, p2t);
|
1998-09-08 22:34:40 +00:00
|
|
|
aRenderingContext.SetColor(NS_RGB(0, 255, 255));
|
1998-09-29 22:31:22 +00:00
|
|
|
aRenderingContext.FillRect(0, 0, five, five*2);
|
1998-09-08 22:34:40 +00:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1998-10-03 04:28:05 +00:00
|
|
|
BRFrame::Reflow(nsIPresContext& aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aMetrics,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
1998-09-08 22:34:40 +00:00
|
|
|
{
|
1999-09-09 20:53:18 +00:00
|
|
|
if (aMetrics.maxElementSize) {
|
1998-09-08 22:34:40 +00:00
|
|
|
aMetrics.maxElementSize->width = 0;
|
|
|
|
aMetrics.maxElementSize->height = 0;
|
|
|
|
}
|
1998-09-29 22:31:22 +00:00
|
|
|
aMetrics.height = 0;
|
1998-09-08 22:34:40 +00:00
|
|
|
aMetrics.width = 0;
|
1998-10-02 21:49:47 +00:00
|
|
|
aMetrics.ascent = 0;
|
|
|
|
aMetrics.descent = 0;
|
1998-09-08 22:34:40 +00:00
|
|
|
|
1999-03-26 00:37:22 +00:00
|
|
|
// Only when the BR is operating in a line-layout situation will it
|
|
|
|
// behave like a BR.
|
1999-07-20 03:51:46 +00:00
|
|
|
if (nsnull != aReflowState.mLineLayout) {
|
|
|
|
if (aReflowState.mLineLayout->CanPlaceFloaterNow()) {
|
1999-04-03 18:57:30 +00: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-09 20:53:18 +00: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 18:57:30 +00:00
|
|
|
}
|
1999-03-26 00:37:22 +00:00
|
|
|
|
|
|
|
// Return our reflow status
|
|
|
|
PRUint32 breakType = aReflowState.mStyleDisplay->mBreakType;
|
|
|
|
if (NS_STYLE_CLEAR_NONE == breakType) {
|
|
|
|
breakType = NS_STYLE_CLEAR_LINE;
|
|
|
|
}
|
1998-10-03 04:28:05 +00:00
|
|
|
|
1999-03-26 00:37:22 +00:00
|
|
|
aStatus = NS_INLINE_BREAK | NS_INLINE_BREAK_AFTER |
|
|
|
|
NS_INLINE_MAKE_BREAK_TYPE(breakType);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
aStatus = NS_FRAME_COMPLETE;
|
|
|
|
}
|
1998-10-03 04:28:05 +00:00
|
|
|
return NS_OK;
|
1998-09-08 22:34:40 +00:00
|
|
|
}
|
1999-06-19 20:36:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
1999-09-08 19:43:17 +00:00
|
|
|
NS_IMETHODIMP BRFrame::GetPosition(nsIPresContext& aCX,
|
|
|
|
nscoord aCoord,
|
|
|
|
nsIContent ** aContent,
|
|
|
|
PRInt32& aOffsetBegin,
|
|
|
|
PRInt32& aOffsetEnd)
|
1999-06-19 20:36:44 +00:00
|
|
|
{
|
1999-09-08 19:43:17 +00: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-19 20:36:44 +00:00
|
|
|
}
|