gecko-dev/layout/generic/nsBRFrame.cpp

179 строки
5.8 KiB
C++
Исходник Обычный вид История

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.
*/
#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"
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
// nsIHTMLReflow
NS_IMETHOD Reflow(nsIPresContext& aPresContext,
nsHTMLReflowMetrics& aDesiredSize,
const nsHTMLReflowState& aReflowState,
nsReflowStatus& aStatus);
NS_IMETHOD GetContentAndOffsetsFromPoint(nsIPresContext& aCX,
const nsPoint& aPoint,
nsIContent** aNewContent,
PRInt32& aContentOffset,
PRInt32& aContentOffsetEnd,
PRBool& aBeginFrameContent);
1998-09-09 02:34:40 +04:00
protected:
virtual ~BRFrame();
};
nsresult
NS_NewBRFrame(nsIFrame** aNewFrame)
1998-09-09 02:34:40 +04:00
{
NS_PRECONDITION(aNewFrame, "null OUT ptr");
if (nsnull == aNewFrame) {
return NS_ERROR_NULL_POINTER;
}
nsIFrame* frame = new BRFrame;
1998-09-09 02:34:40 +04:00
if (nsnull == frame) {
return NS_ERROR_OUT_OF_MEMORY;
}
*aNewFrame = frame;
1998-09-09 02:34:40 +04:00
return NS_OK;
}
BRFrame::~BRFrame()
{
}
NS_IMETHODIMP
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()) {
float p2t;
aPresContext.GetPixelsToTwips(&p2t);
nscoord five = NSIntPixelsToTwips(5, p2t);
1998-09-09 02:34:40 +04:00
aRenderingContext.SetColor(NS_RGB(0, 255, 255));
aRenderingContext.FillRect(0, 0, five, five*2);
1998-09-09 02:34:40 +04:00
}
return NS_OK;
}
NS_IMETHODIMP
BRFrame::Reflow(nsIPresContext& aPresContext,
nsHTMLReflowMetrics& aMetrics,
const nsHTMLReflowState& aReflowState,
nsReflowStatus& aStatus)
1998-09-09 02:34:40 +04:00
{
if (aMetrics.maxElementSize) {
1998-09-09 02:34:40 +04:00
aMetrics.maxElementSize->width = 0;
aMetrics.maxElementSize->height = 0;
}
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.
if (nsnull != aReflowState.mLineLayout) {
if (aReflowState.mLineLayout->CanPlaceFloaterNow()) {
// 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);
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-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;
}
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;
}
return NS_OK;
1998-09-09 02:34:40 +04:00
}
NS_IMETHODIMP BRFrame::GetContentAndOffsetsFromPoint(nsIPresContext& aCX,
const nsPoint& aPoint,
nsIContent ** aContent,
PRInt32& aOffsetBegin,
PRInt32& aOffsetEnd,
PRBool& aBeginFrameContent)
{
nsresult result = nsFrame::GetContentAndOffsetsFromPoint(aCX,aPoint,aContent,aOffsetBegin,aOffsetEnd,aBeginFrameContent);
if (NS_SUCCEEDED(result))
{
// BRFrames should return a collapsed selection before itself
aOffsetEnd = aOffsetBegin;
}
return result;
}