1998-09-09 02:34:40 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
1999-11-06 06:40:37 +03:00
|
|
|
* The contents of this file are subject to the Netscape Public
|
|
|
|
* License Version 1.1 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.mozilla.org/NPL/
|
1998-09-09 02:34:40 +04:00
|
|
|
*
|
1999-11-06 06:40:37 +03:00
|
|
|
* Software distributed under the License is distributed on an "AS
|
|
|
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
* implied. See the License for the specific language governing
|
|
|
|
* rights and limitations under the License.
|
1998-09-09 02:34:40 +04:00
|
|
|
*
|
1999-11-06 06:40:37 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
1998-09-09 02:34:40 +04:00
|
|
|
* Communications Corporation. Portions created by Netscape are
|
1999-11-06 06:40:37 +03:00
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
1998-09-09 02:34:40 +04:00
|
|
|
*/
|
|
|
|
#include "nsHTMLParts.h"
|
|
|
|
#include "nsIHTMLContent.h"
|
|
|
|
#include "nsFrame.h"
|
1998-09-15 04:19:49 +04:00
|
|
|
#include "nsLineLayout.h"
|
1998-09-09 02:34:40 +04:00
|
|
|
#include "nsHTMLIIDs.h"
|
|
|
|
#include "nsIPresContext.h"
|
|
|
|
#include "nsHTMLAtoms.h"
|
|
|
|
#include "nsUnitConversion.h"
|
|
|
|
#include "nsIStyleContext.h"
|
|
|
|
#include "nsStyleConsts.h"
|
1998-12-20 04:21:23 +03:00
|
|
|
#include "nsINameSpaceManager.h"
|
1998-09-09 02:34:40 +04:00
|
|
|
|
|
|
|
// Spacer type's
|
|
|
|
#define TYPE_WORD 0 // horizontal space
|
|
|
|
#define TYPE_LINE 1 // line-break + vertical space
|
|
|
|
#define TYPE_IMAGE 2 // acts like a sized image with nothing to see
|
|
|
|
|
1998-10-03 08:28:05 +04:00
|
|
|
class SpacerFrame : public nsFrame {
|
1998-09-09 02:34:40 +04:00
|
|
|
public:
|
1999-12-05 02:49:50 +03:00
|
|
|
friend nsresult NS_NewSpacerFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame);
|
1999-05-12 02:03:29 +04:00
|
|
|
|
1998-10-03 08:28:05 +04:00
|
|
|
// nsIHTMLReflow
|
1999-11-24 09:03:41 +03:00
|
|
|
NS_IMETHOD Reflow(nsIPresContext* aPresContext,
|
1998-10-03 08:28:05 +04:00
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus);
|
1998-09-09 02:34:40 +04:00
|
|
|
|
|
|
|
PRUint8 GetType();
|
|
|
|
|
|
|
|
protected:
|
1999-05-12 02:03:29 +04:00
|
|
|
SpacerFrame();
|
1998-09-09 02:34:40 +04:00
|
|
|
virtual ~SpacerFrame();
|
|
|
|
};
|
|
|
|
|
|
|
|
nsresult
|
1999-12-05 02:49:50 +03:00
|
|
|
NS_NewSpacerFrame(nsIPresShell* aPresShell, 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;
|
|
|
|
}
|
1999-12-05 02:49:50 +03:00
|
|
|
SpacerFrame* it = new (aPresShell) SpacerFrame;
|
1999-05-12 02:03:29 +04:00
|
|
|
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-05-12 02:03:29 +04:00
|
|
|
SpacerFrame::SpacerFrame()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
1998-09-09 02:34:40 +04:00
|
|
|
SpacerFrame::~SpacerFrame()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-11-24 09:03:41 +03:00
|
|
|
SpacerFrame::Reflow(nsIPresContext* aPresContext,
|
1998-10-03 08:28:05 +04:00
|
|
|
nsHTMLReflowMetrics& aMetrics,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
1998-09-09 02:34:40 +04:00
|
|
|
{
|
2000-04-21 18:59:47 +04:00
|
|
|
DO_GLOBAL_REFLOW_COUNT("SpacerFrame", aReflowState.reason);
|
1998-10-03 08:28:05 +04:00
|
|
|
aStatus = NS_FRAME_COMPLETE;
|
1998-09-09 02:34:40 +04:00
|
|
|
|
|
|
|
// By default, we have no area
|
|
|
|
aMetrics.width = 0;
|
|
|
|
aMetrics.height = 0;
|
|
|
|
aMetrics.ascent = 0;
|
|
|
|
aMetrics.descent = 0;
|
|
|
|
|
2000-05-09 09:09:55 +04:00
|
|
|
const nsStylePosition* position;
|
|
|
|
GetStyleData(eStyleStruct_Position, (const nsStyleStruct*&)position);
|
|
|
|
|
|
|
|
PRUint8 type = GetType();
|
1998-09-09 02:34:40 +04:00
|
|
|
switch (type) {
|
|
|
|
case TYPE_WORD:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TYPE_LINE:
|
2000-05-09 09:09:55 +04:00
|
|
|
aStatus = NS_INLINE_LINE_BREAK_AFTER(NS_FRAME_COMPLETE);
|
|
|
|
if (eStyleUnit_Coord == position->mHeight.GetUnit()) {
|
|
|
|
aMetrics.width = position->mHeight.GetCoordValue();
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
2000-05-09 09:09:55 +04:00
|
|
|
aMetrics.ascent = aMetrics.height;
|
1998-09-09 02:34:40 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TYPE_IMAGE:
|
2000-05-09 09:09:55 +04:00
|
|
|
// width
|
|
|
|
nsStyleUnit unit = position->mWidth.GetUnit();
|
|
|
|
if (eStyleUnit_Coord == unit) {
|
|
|
|
aMetrics.width = position->mWidth.GetCoordValue();
|
|
|
|
}
|
|
|
|
else if (eStyleUnit_Percent == unit)
|
|
|
|
{
|
|
|
|
if (NS_UNCONSTRAINEDSIZE != aReflowState.availableWidth)
|
|
|
|
{
|
|
|
|
float factor = position->mWidth.GetPercentValue();
|
|
|
|
aMetrics.width = NSToCoordRound (factor * aReflowState.availableWidth);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// height
|
|
|
|
unit = position->mHeight.GetUnit();
|
|
|
|
if (eStyleUnit_Coord == unit) {
|
|
|
|
aMetrics.height = position->mHeight.GetCoordValue();
|
|
|
|
}
|
|
|
|
else if (eStyleUnit_Percent == unit)
|
|
|
|
{
|
|
|
|
if (NS_UNCONSTRAINEDSIZE != aReflowState.availableHeight)
|
|
|
|
{
|
|
|
|
float factor = position->mHeight.GetPercentValue();
|
|
|
|
aMetrics.width = NSToCoordRound (factor * aReflowState.availableHeight);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// accent
|
1998-09-09 02:34:40 +04:00
|
|
|
aMetrics.ascent = aMetrics.height;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1999-09-22 04:39:47 +04:00
|
|
|
if (aMetrics.width || aMetrics.height) {
|
|
|
|
// Make sure that the other dimension is non-zero
|
|
|
|
if (!aMetrics.width) aMetrics.width = 1;
|
|
|
|
if (!aMetrics.height) aMetrics.height = 1;
|
|
|
|
}
|
|
|
|
|
1998-09-09 02:34:40 +04:00
|
|
|
if (nsnull != aMetrics.maxElementSize) {
|
|
|
|
aMetrics.maxElementSize->width = aMetrics.width;
|
|
|
|
aMetrics.maxElementSize->height = aMetrics.height;
|
|
|
|
}
|
|
|
|
|
1998-10-03 08:28:05 +04:00
|
|
|
return NS_OK;
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
PRUint8
|
|
|
|
SpacerFrame::GetType()
|
|
|
|
{
|
|
|
|
PRUint8 type = TYPE_WORD;
|
|
|
|
nsAutoString value;
|
1999-09-22 04:39:47 +04:00
|
|
|
if (NS_CONTENT_ATTR_HAS_VALUE ==
|
|
|
|
mContent->GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::type, value)) {
|
1998-09-09 02:34:40 +04:00
|
|
|
if (value.EqualsIgnoreCase("line") ||
|
|
|
|
value.EqualsIgnoreCase("vert") ||
|
|
|
|
value.EqualsIgnoreCase("vertical")) {
|
|
|
|
return TYPE_LINE;
|
|
|
|
}
|
|
|
|
if (value.EqualsIgnoreCase("block")) {
|
|
|
|
return TYPE_IMAGE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return type;
|
|
|
|
}
|