2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 18:30:37 +04:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1998-09-09 02:34:40 +04:00
|
|
|
*
|
2004-04-18 18:30:37 +04:00
|
|
|
* The contents of this file are subject to the Mozilla 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/MPL/
|
1998-09-09 02:34:40 +04:00
|
|
|
*
|
2001-09-29 00:14:13 +04: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.
|
|
|
|
*
|
2004-04-18 18:30:37 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-29 00:14:13 +04:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 06:40:37 +03:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-18 18:30:37 +04:00
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
2001-09-29 00:14:13 +04:00
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
2004-04-18 18:30:37 +04:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-29 00:14:13 +04:00
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2004-04-18 18:30:37 +04:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-29 00:14:13 +04:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2006-03-29 22:29:03 +04:00
|
|
|
|
|
|
|
/* rendering object for HTML <spacer> element */
|
|
|
|
|
1998-09-09 02:34:40 +04:00
|
|
|
#include "nsHTMLParts.h"
|
|
|
|
#include "nsFrame.h"
|
1998-09-15 04:19:49 +04:00
|
|
|
#include "nsLineLayout.h"
|
2004-08-01 03:15:21 +04:00
|
|
|
#include "nsPresContext.h"
|
1998-09-09 02:34:40 +04:00
|
|
|
#include "nsHTMLAtoms.h"
|
|
|
|
#include "nsUnitConversion.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:
|
2006-03-27 01:30:36 +04:00
|
|
|
friend nsIFrame* NS_NewSpacerFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
|
1999-05-12 02:03:29 +04:00
|
|
|
|
1998-10-03 08:28:05 +04:00
|
|
|
// nsIHTMLReflow
|
2004-08-01 03:15:21 +04:00
|
|
|
NS_IMETHOD Reflow(nsPresContext* 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:
|
2006-03-27 01:30:36 +04:00
|
|
|
SpacerFrame(nsStyleContext* aContext) : nsFrame(aContext) {}
|
1998-09-09 02:34:40 +04:00
|
|
|
virtual ~SpacerFrame();
|
|
|
|
};
|
|
|
|
|
2005-11-01 23:40:54 +03:00
|
|
|
nsIFrame*
|
2006-03-27 01:30:36 +04:00
|
|
|
NS_NewSpacerFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
1999-05-12 02:03:29 +04:00
|
|
|
{
|
2006-03-27 01:30:36 +04:00
|
|
|
return new (aPresShell) SpacerFrame(aContext);
|
1999-05-12 02:03:29 +04:00
|
|
|
}
|
|
|
|
|
1998-09-09 02:34:40 +04:00
|
|
|
SpacerFrame::~SpacerFrame()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2004-08-01 03:15:21 +04:00
|
|
|
SpacerFrame::Reflow(nsPresContext* 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);
|
2001-11-14 16:40:03 +03:00
|
|
|
DISPLAY_REFLOW(aPresContext, this, aReflowState, aMetrics, aStatus);
|
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;
|
|
|
|
|
2003-05-15 07:42:21 +04:00
|
|
|
const nsStylePosition* position = GetStylePosition();
|
2000-05-09 09:09:55 +04:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2003-01-09 17:26:32 +03:00
|
|
|
if (aMetrics.mComputeMEW) {
|
2004-08-31 22:50:40 +04:00
|
|
|
aMetrics.SetMEWToActualWidth(aReflowState.mStylePosition->mWidth.GetUnit());
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
|
|
|
|
2002-05-29 02:50:43 +04:00
|
|
|
NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aMetrics);
|
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;
|
2005-10-28 15:25:24 +04:00
|
|
|
if (mContent->GetAttr(kNameSpaceID_None, nsHTMLAtoms::type, value)) {
|
2004-06-17 04:13:25 +04:00
|
|
|
if (value.LowerCaseEqualsLiteral("line") ||
|
|
|
|
value.LowerCaseEqualsLiteral("vert") ||
|
|
|
|
value.LowerCaseEqualsLiteral("vertical")) {
|
1998-09-09 02:34:40 +04:00
|
|
|
return TYPE_LINE;
|
|
|
|
}
|
2004-06-17 04:13:25 +04:00
|
|
|
if (value.LowerCaseEqualsLiteral("block")) {
|
1998-09-09 02:34:40 +04:00
|
|
|
return TYPE_IMAGE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return type;
|
|
|
|
}
|