2001-09-28 20:14:13 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 14:30:37 +00:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1998-09-08 22:34:40 +00:00
|
|
|
*
|
2004-04-18 14:30:37 +00: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-08 22:34:40 +00:00
|
|
|
*
|
2001-09-28 20:14:13 +00: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-08 22:34:40 +00:00
|
|
|
*
|
1999-11-06 03:40:37 +00:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-18 14:30:37 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-28 20:14:13 +00:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 03:40:37 +00:00
|
|
|
*
|
2001-09-28 20:14:13 +00:00
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-18 14:30:37 +00: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-28 20:14:13 +00: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 14:30:37 +00:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-28 20:14:13 +00: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 14:30:37 +00:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-28 20:14:13 +00:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2006-03-29 18:29:03 +00:00
|
|
|
|
|
|
|
/* rendering object for HTML <spacer> element */
|
|
|
|
|
1998-09-08 22:34:40 +00:00
|
|
|
#include "nsHTMLParts.h"
|
|
|
|
#include "nsFrame.h"
|
1998-09-15 00:19:49 +00:00
|
|
|
#include "nsLineLayout.h"
|
2004-07-31 23:15:21 +00:00
|
|
|
#include "nsPresContext.h"
|
2006-12-26 17:47:52 +00:00
|
|
|
#include "nsGkAtoms.h"
|
1998-09-08 22:34:40 +00:00
|
|
|
#include "nsUnitConversion.h"
|
|
|
|
#include "nsStyleConsts.h"
|
1998-12-20 01:21:23 +00:00
|
|
|
#include "nsINameSpaceManager.h"
|
1998-09-08 22:34:40 +00: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 04:28:05 +00:00
|
|
|
class SpacerFrame : public nsFrame {
|
1998-09-08 22:34:40 +00:00
|
|
|
public:
|
2006-03-26 21:30:36 +00:00
|
|
|
friend nsIFrame* NS_NewSpacerFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
|
1999-05-11 22:03:29 +00:00
|
|
|
|
1998-10-03 04:28:05 +00:00
|
|
|
// nsIHTMLReflow
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 05:38:33 +00:00
|
|
|
virtual nscoord GetMinWidth(nsIRenderingContext *aRenderingContext);
|
|
|
|
virtual nscoord GetPrefWidth(nsIRenderingContext *aRenderingContext);
|
2004-07-31 23:15:21 +00:00
|
|
|
NS_IMETHOD Reflow(nsPresContext* aPresContext,
|
1998-10-03 04:28:05 +00:00
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus);
|
1998-09-08 22:34:40 +00:00
|
|
|
|
|
|
|
PRUint8 GetType();
|
|
|
|
|
|
|
|
protected:
|
2006-03-26 21:30:36 +00:00
|
|
|
SpacerFrame(nsStyleContext* aContext) : nsFrame(aContext) {}
|
1998-09-08 22:34:40 +00:00
|
|
|
virtual ~SpacerFrame();
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 05:38:33 +00:00
|
|
|
void GetDesiredSize(nsHTMLReflowMetrics& aMetrics, nsSize aPercentBase);
|
1998-09-08 22:34:40 +00:00
|
|
|
};
|
|
|
|
|
2005-11-01 20:40:54 +00:00
|
|
|
nsIFrame*
|
2006-03-26 21:30:36 +00:00
|
|
|
NS_NewSpacerFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
1999-05-11 22:03:29 +00:00
|
|
|
{
|
2006-03-26 21:30:36 +00:00
|
|
|
return new (aPresShell) SpacerFrame(aContext);
|
1999-05-11 22:03:29 +00:00
|
|
|
}
|
|
|
|
|
1998-09-08 22:34:40 +00:00
|
|
|
SpacerFrame::~SpacerFrame()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 05:38:33 +00:00
|
|
|
/* virtual */ nscoord
|
|
|
|
SpacerFrame::GetMinWidth(nsIRenderingContext *aRenderingContext)
|
|
|
|
{
|
|
|
|
nsHTMLReflowMetrics metrics;
|
|
|
|
DISPLAY_MIN_WIDTH(this, metrics.width);
|
|
|
|
GetDesiredSize(metrics, nsSize(0, 0));
|
|
|
|
return metrics.width;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ nscoord
|
|
|
|
SpacerFrame::GetPrefWidth(nsIRenderingContext *aRenderingContext)
|
|
|
|
{
|
|
|
|
nsHTMLReflowMetrics metrics;
|
|
|
|
DISPLAY_PREF_WIDTH(this, metrics.width);
|
|
|
|
GetDesiredSize(metrics, nsSize(0, 0));
|
|
|
|
return metrics.width;
|
|
|
|
}
|
|
|
|
|
1998-09-08 22:34:40 +00:00
|
|
|
NS_IMETHODIMP
|
2004-07-31 23:15:21 +00:00
|
|
|
SpacerFrame::Reflow(nsPresContext* aPresContext,
|
1998-10-03 04:28:05 +00:00
|
|
|
nsHTMLReflowMetrics& aMetrics,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
1998-09-08 22:34:40 +00:00
|
|
|
{
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 05:38:33 +00:00
|
|
|
DO_GLOBAL_REFLOW_COUNT("SpacerFrame");
|
2001-11-14 13:40:03 +00:00
|
|
|
DISPLAY_REFLOW(aPresContext, this, aReflowState, aMetrics, aStatus);
|
1998-10-03 04:28:05 +00:00
|
|
|
aStatus = NS_FRAME_COMPLETE;
|
1998-09-08 22:34:40 +00:00
|
|
|
|
2007-05-03 23:11:00 +00:00
|
|
|
// XXX Bug 379654 Should use containing block size!
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 05:38:33 +00:00
|
|
|
nsSize percentBase(aReflowState.availableWidth, aReflowState.availableHeight);
|
|
|
|
if (percentBase.width == NS_UNCONSTRAINEDSIZE)
|
|
|
|
percentBase.width = 0;
|
|
|
|
if (percentBase.height == NS_UNCONSTRAINEDSIZE)
|
|
|
|
percentBase.height = 0;
|
|
|
|
|
|
|
|
if (GetType() == TYPE_LINE)
|
|
|
|
aStatus = NS_INLINE_LINE_BREAK_AFTER(NS_FRAME_COMPLETE);
|
|
|
|
|
|
|
|
GetDesiredSize(aMetrics, percentBase);
|
|
|
|
|
|
|
|
NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aMetrics);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SpacerFrame::GetDesiredSize(nsHTMLReflowMetrics& aMetrics, nsSize aPercentBase)
|
|
|
|
{
|
1998-09-08 22:34:40 +00:00
|
|
|
// By default, we have no area
|
|
|
|
aMetrics.width = 0;
|
|
|
|
aMetrics.height = 0;
|
|
|
|
|
2007-05-03 23:11:00 +00:00
|
|
|
// XXX Bug 379654 This code doesn't handle some value types for width
|
|
|
|
// and height, doesn't handle min/max-width/height, doesn't handle
|
|
|
|
// border and padding, doesn't handle 'ch' units, doesn't handle the
|
|
|
|
// enumerated values on width, etc. But it probably doesn't much
|
|
|
|
// matter.
|
|
|
|
|
2003-05-15 03:42:21 +00:00
|
|
|
const nsStylePosition* position = GetStylePosition();
|
2000-05-09 05:09:55 +00:00
|
|
|
|
|
|
|
PRUint8 type = GetType();
|
1998-09-08 22:34:40 +00:00
|
|
|
switch (type) {
|
|
|
|
case TYPE_WORD:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TYPE_LINE:
|
2000-05-09 05:09:55 +00:00
|
|
|
if (eStyleUnit_Coord == position->mHeight.GetUnit()) {
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 05:38:33 +00:00
|
|
|
aMetrics.height = position->mHeight.GetCoordValue();
|
1998-09-08 22:34:40 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TYPE_IMAGE:
|
2000-05-09 05:09:55 +00:00
|
|
|
// width
|
|
|
|
nsStyleUnit unit = position->mWidth.GetUnit();
|
|
|
|
if (eStyleUnit_Coord == unit) {
|
|
|
|
aMetrics.width = position->mWidth.GetCoordValue();
|
|
|
|
}
|
|
|
|
else if (eStyleUnit_Percent == unit)
|
|
|
|
{
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 05:38:33 +00:00
|
|
|
float factor = position->mWidth.GetPercentValue();
|
|
|
|
aMetrics.width = NSToCoordRound(factor * aPercentBase.width);
|
2000-05-09 05:09:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// height
|
|
|
|
unit = position->mHeight.GetUnit();
|
|
|
|
if (eStyleUnit_Coord == unit) {
|
|
|
|
aMetrics.height = position->mHeight.GetCoordValue();
|
|
|
|
}
|
|
|
|
else if (eStyleUnit_Percent == unit)
|
|
|
|
{
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 05:38:33 +00:00
|
|
|
float factor = position->mHeight.GetPercentValue();
|
2007-05-03 23:11:00 +00:00
|
|
|
aMetrics.height = NSToCoordRound(factor * aPercentBase.height);
|
2000-05-09 05:09:55 +00:00
|
|
|
}
|
1998-09-08 22:34:40 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1999-09-22 00:39:47 +00: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-08 22:34:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PRUint8
|
|
|
|
SpacerFrame::GetType()
|
|
|
|
{
|
|
|
|
PRUint8 type = TYPE_WORD;
|
2006-04-24 05:40:11 +00:00
|
|
|
static nsIContent::AttrValuesArray strings[] =
|
2006-12-26 17:47:52 +00:00
|
|
|
{&nsGkAtoms::line, &nsGkAtoms::vert, &nsGkAtoms::vertical,
|
|
|
|
&nsGkAtoms::block, nsnull};
|
|
|
|
switch (mContent->FindAttrValueIn(kNameSpaceID_None, nsGkAtoms::type,
|
2006-04-24 05:40:11 +00:00
|
|
|
strings, eIgnoreCase)) {
|
|
|
|
case 0:
|
|
|
|
case 1:
|
|
|
|
case 2:
|
1998-09-08 22:34:40 +00:00
|
|
|
return TYPE_LINE;
|
2006-04-24 05:40:11 +00:00
|
|
|
case 3:
|
1998-09-08 22:34:40 +00:00
|
|
|
return TYPE_IMAGE;
|
|
|
|
}
|
|
|
|
return type;
|
|
|
|
}
|