2000-03-28 10:15:19 +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/
|
2002-01-25 07:03:43 +00:00
|
|
|
*
|
2000-03-28 10:15:19 +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.
|
2002-01-25 07:03:43 +00:00
|
|
|
*
|
2000-03-28 10:15:19 +00:00
|
|
|
* The Original Code is Mozilla MathML Project.
|
2002-01-25 07:03:43 +00:00
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is The University Of
|
2000-03-28 10:15:19 +00:00
|
|
|
* Queensland. Portions created by The University Of Queensland are
|
|
|
|
* Copyright (C) 1999 The University Of Queensland. All Rights Reserved.
|
2002-01-25 07:03:43 +00:00
|
|
|
*
|
|
|
|
* Contributor(s):
|
2000-03-28 10:15:19 +00:00
|
|
|
* Roger B. Sidje <rbs@maths.uq.edu.au>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsHTMLParts.h"
|
|
|
|
#include "nsIHTMLContent.h"
|
|
|
|
#include "nsFrame.h"
|
|
|
|
#include "nsAreaFrame.h"
|
|
|
|
#include "nsLineLayout.h"
|
|
|
|
#include "nsHTMLIIDs.h"
|
|
|
|
#include "nsIPresContext.h"
|
|
|
|
#include "nsHTMLAtoms.h"
|
|
|
|
#include "nsUnitConversion.h"
|
|
|
|
#include "nsIStyleContext.h"
|
|
|
|
#include "nsStyleConsts.h"
|
|
|
|
#include "nsINameSpaceManager.h"
|
|
|
|
#include "nsIRenderingContext.h"
|
|
|
|
#include "nsIFontMetrics.h"
|
|
|
|
#include "nsStyleUtil.h"
|
|
|
|
|
2000-05-16 13:18:42 +00:00
|
|
|
#include "nsVoidArray.h"
|
|
|
|
#include "nsIFrameManager.h"
|
2002-01-25 07:03:43 +00:00
|
|
|
#include "nsStyleChangeList.h"
|
2000-05-16 13:18:42 +00:00
|
|
|
#include "nsTableOuterFrame.h"
|
2002-01-25 07:03:43 +00:00
|
|
|
#include "nsTableFrame.h"
|
2000-05-16 13:18:42 +00:00
|
|
|
#include "nsTableCellFrame.h"
|
|
|
|
|
2000-03-28 10:15:19 +00:00
|
|
|
#include "nsMathMLmtableFrame.h"
|
|
|
|
|
|
|
|
//
|
|
|
|
// <mtable> -- table or matrix - implementation
|
|
|
|
//
|
|
|
|
|
2000-05-16 13:18:42 +00:00
|
|
|
// helper function to perform an in-place split of a space-delimited string,
|
2001-05-19 10:00:01 +00:00
|
|
|
// and return an array of pointers for the beginning of each segment, i.e.,
|
2000-05-16 13:18:42 +00:00
|
|
|
// aOffset[0] is the first string, aOffset[1] is the second string, etc.
|
|
|
|
// Used to parse attributes like columnalign='left right', rowalign='top bottom'
|
2001-05-19 10:00:01 +00:00
|
|
|
static void
|
2000-05-16 13:18:42 +00:00
|
|
|
SplitString(nsString& aString, // [IN/OUT]
|
|
|
|
nsVoidArray& aOffset) // [OUT]
|
|
|
|
{
|
|
|
|
static const PRUnichar kNullCh = PRUnichar('\0');
|
|
|
|
|
|
|
|
aString.Append(kNullCh); // put an extra null at the end
|
|
|
|
|
2001-06-30 11:02:25 +00:00
|
|
|
PRUnichar* start = (PRUnichar*)(const PRUnichar*)aString.get();
|
2000-05-16 13:18:42 +00:00
|
|
|
PRUnichar* end = start;
|
|
|
|
|
|
|
|
while (kNullCh != *start) {
|
|
|
|
while ((kNullCh != *start) && nsCRT::IsAsciiSpace(*start)) { // skip leading space
|
|
|
|
start++;
|
|
|
|
}
|
|
|
|
end = start;
|
|
|
|
|
|
|
|
while ((kNullCh != *end) && (PR_FALSE == nsCRT::IsAsciiSpace(*end))) { // look for space or end
|
|
|
|
end++;
|
|
|
|
}
|
|
|
|
*end = kNullCh; // end string here
|
|
|
|
|
|
|
|
if (start < end) {
|
|
|
|
aOffset.AppendElement(start); // record the beginning of this segment
|
|
|
|
}
|
|
|
|
|
|
|
|
start = ++end;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct nsValueList
|
|
|
|
{
|
2001-05-19 10:00:01 +00:00
|
|
|
nsString mData;
|
|
|
|
nsVoidArray mArray;
|
2000-05-16 13:18:42 +00:00
|
|
|
|
2001-05-19 10:00:01 +00:00
|
|
|
nsValueList(nsString& aData) {
|
2000-05-16 13:18:42 +00:00
|
|
|
mData.Assign(aData);
|
|
|
|
SplitString(mData, mArray);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Each rowalign='top bottom' or columnalign='left right center' (from
|
|
|
|
// <mtable> or <mtr>) is split once (lazily) into a nsValueList which is
|
|
|
|
// stored in the frame manager. Cell frames query the frame manager
|
|
|
|
// to see what values apply to them.
|
|
|
|
|
2002-01-25 07:03:43 +00:00
|
|
|
// XXX See bug 69409 - MathML attributes are not mapped to style.
|
2001-05-19 10:00:01 +00:00
|
|
|
// This code is not suitable for dynamic updates, for example when the
|
2000-05-16 13:18:42 +00:00
|
|
|
// rowalign and columalign attributes are changed with JavaScript.
|
|
|
|
// The code doesn't include hooks for AttributeChanged() notifications.
|
|
|
|
|
|
|
|
static void
|
|
|
|
DestroyValueListFunc(nsIPresContext* aPresContext,
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
nsIAtom* aPropertyName,
|
|
|
|
void* aPropertyValue)
|
|
|
|
{
|
2001-05-19 10:00:01 +00:00
|
|
|
delete NS_STATIC_CAST(nsValueList*, aPropertyValue);
|
2000-05-16 13:18:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static PRUnichar*
|
2002-01-25 07:03:43 +00:00
|
|
|
GetValueAt(nsIPresContext* aPresContext,
|
|
|
|
nsIFrame* aTableOrRowFrame,
|
|
|
|
nsIAtom* aAttributeAtom,
|
|
|
|
PRInt32 aRowOrColIndex)
|
2000-05-16 13:18:42 +00:00
|
|
|
{
|
2001-05-19 10:00:01 +00:00
|
|
|
PRUnichar* result = nsnull;
|
2000-05-16 13:18:42 +00:00
|
|
|
nsValueList* valueList = nsnull;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPresShell> presShell;
|
|
|
|
aPresContext->GetShell(getter_AddRefs(presShell));
|
2001-05-19 10:00:01 +00:00
|
|
|
if (presShell) {
|
2000-05-16 13:18:42 +00:00
|
|
|
nsCOMPtr<nsIFrameManager> frameManager;
|
|
|
|
presShell->GetFrameManager(getter_AddRefs(frameManager));
|
2001-05-19 10:00:01 +00:00
|
|
|
if (frameManager) {
|
|
|
|
frameManager->GetFrameProperty(aTableOrRowFrame, aAttributeAtom,
|
2000-05-16 13:18:42 +00:00
|
|
|
0, (void**)&valueList);
|
2001-05-19 10:00:01 +00:00
|
|
|
if (!valueList) {
|
2000-05-16 13:18:42 +00:00
|
|
|
// The property isn't there yet, so set it
|
|
|
|
nsAutoString values;
|
|
|
|
nsCOMPtr<nsIContent> content;
|
|
|
|
aTableOrRowFrame->GetContent(getter_AddRefs(content));
|
2001-08-17 09:54:04 +00:00
|
|
|
if (NS_CONTENT_ATTR_HAS_VALUE == content->GetAttr(kNameSpaceID_None, aAttributeAtom, values)) {
|
2000-05-16 13:18:42 +00:00
|
|
|
valueList = new nsValueList(values);
|
2001-05-19 10:00:01 +00:00
|
|
|
if (valueList) {
|
2000-05-16 13:18:42 +00:00
|
|
|
frameManager->SetFrameProperty(aTableOrRowFrame, aAttributeAtom,
|
|
|
|
valueList, DestroyValueListFunc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-05-19 10:00:01 +00:00
|
|
|
if (valueList) {
|
2000-05-16 13:18:42 +00:00
|
|
|
PRInt32 count = valueList->mArray.Count();
|
2002-01-25 07:03:43 +00:00
|
|
|
result = (aRowOrColIndex < count)
|
|
|
|
? (PRUnichar*)(valueList->mArray[aRowOrColIndex])
|
2000-05-16 13:18:42 +00:00
|
|
|
: (PRUnichar*)(valueList->mArray[count-1]);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2002-01-25 07:03:43 +00:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
#define DEBUG_VERIFY_THAT_FRAME_IS(_frame, _expected) \
|
|
|
|
PR_BEGIN_MACRO \
|
|
|
|
const nsStyleDisplay* display; \
|
|
|
|
_frame->GetStyleData(eStyleStruct_Display, (const nsStyleStruct *&)display); \
|
|
|
|
NS_ASSERTION(NS_STYLE_DISPLAY_##_expected == display->mDisplay, "internal error"); \
|
|
|
|
PR_END_MACRO
|
|
|
|
#else
|
|
|
|
#define DEBUG_VERIFY_THAT_FRAME_IS(_frame, _expected)
|
|
|
|
#endif
|
|
|
|
|
2000-05-16 13:18:42 +00:00
|
|
|
static void
|
2002-01-25 07:03:43 +00:00
|
|
|
MapAttributesInto(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aCellContent,
|
|
|
|
nsIFrame* aCellFrame,
|
|
|
|
nsIFrame* aCellInnerFrame)
|
2000-05-16 13:18:42 +00:00
|
|
|
{
|
2002-01-25 07:03:43 +00:00
|
|
|
nsTableCellFrame* cellFrame = NS_STATIC_CAST(nsTableCellFrame*, aCellFrame);
|
|
|
|
nsTableCellFrame* sibling;
|
2000-05-16 13:18:42 +00:00
|
|
|
|
2002-01-25 07:03:43 +00:00
|
|
|
PRInt32 rowIndex, colIndex;
|
|
|
|
nsresult rv = cellFrame->GetCellIndexes(rowIndex, colIndex);
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "cannot find the position of the cell frame");
|
|
|
|
if (NS_FAILED(rv)) return;
|
2000-05-16 13:18:42 +00:00
|
|
|
|
|
|
|
nsIFrame* tableFrame;
|
|
|
|
nsIFrame* rowgroupFrame;
|
|
|
|
nsIFrame* rowFrame;
|
|
|
|
|
|
|
|
cellFrame->GetParent(&rowFrame);
|
|
|
|
rowFrame->GetParent(&rowgroupFrame);
|
|
|
|
rowgroupFrame->GetParent(&tableFrame);
|
2002-01-25 07:03:43 +00:00
|
|
|
DEBUG_VERIFY_THAT_FRAME_IS(rowFrame, TABLE_ROW);
|
|
|
|
DEBUG_VERIFY_THAT_FRAME_IS(rowgroupFrame, TABLE_ROW_GROUP);
|
|
|
|
DEBUG_VERIFY_THAT_FRAME_IS(tableFrame, TABLE);
|
2002-01-27 19:26:42 +00:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
PRBool originates;
|
|
|
|
((nsTableFrame*)tableFrame)->GetCellInfoAt(rowIndex, colIndex, &originates);
|
|
|
|
NS_ASSERTION(originates, "internal error");
|
|
|
|
#endif
|
2002-01-25 07:03:43 +00:00
|
|
|
|
|
|
|
nsIAtom* atom;
|
|
|
|
PRUnichar* attr;
|
|
|
|
nsAutoString value;
|
|
|
|
PRBool hasChanged = PR_FALSE;
|
|
|
|
NS_NAMED_LITERAL_STRING(trueStr, "true");
|
2000-05-16 13:18:42 +00:00
|
|
|
|
|
|
|
//////////////////////////////////////
|
2002-01-25 07:03:43 +00:00
|
|
|
// process attributes that depend on the index of the row
|
|
|
|
// rowalign, rowlines
|
|
|
|
|
|
|
|
// see if the rowalign attribute is not already set
|
|
|
|
atom = nsMathMLAtoms::rowalign_;
|
|
|
|
rv = aCellContent->GetAttr(kNameSpaceID_None, atom, value);
|
|
|
|
if (NS_CONTENT_ATTR_NOT_THERE == rv) {
|
|
|
|
// see if the rowalign attribute was specified on the row
|
|
|
|
attr = GetValueAt(aPresContext, rowFrame, atom, rowIndex);
|
|
|
|
if (!attr) {
|
|
|
|
// see if the rowalign attribute was specified on the table
|
|
|
|
attr = GetValueAt(aPresContext, tableFrame, atom, rowIndex);
|
2000-05-16 13:18:42 +00:00
|
|
|
}
|
2002-01-25 07:03:43 +00:00
|
|
|
// set the attribute without notifying that we want a reflow
|
|
|
|
if (attr) {
|
|
|
|
hasChanged = PR_TRUE;
|
|
|
|
aCellContent->SetAttr(kNameSpaceID_None, atom, nsDependentString(attr), PR_FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// if we are not on the first row, see if |rowlines| was specified on the table.
|
|
|
|
// Note that we pass 'rowIndex-1' because the CSS rule in mathml.css is associated
|
|
|
|
// to 'border-top', and it as if we draw the line on behalf of the previous row.
|
|
|
|
// This way of doing so allows us to handle selective lines, [row]\hline[row][row]',
|
|
|
|
// and cases of spanning cells without further complications.
|
|
|
|
if (rowIndex > 0) {
|
|
|
|
attr = GetValueAt(aPresContext, tableFrame, nsMathMLAtoms::rowlines_, rowIndex-1);
|
|
|
|
// set the special -moz-math-rowline without notifying that we want a reflow
|
|
|
|
if (attr) {
|
|
|
|
hasChanged = PR_TRUE;
|
|
|
|
aCellContent->SetAttr(kNameSpaceID_None, nsMathMLAtoms::rowline, nsDependentString(attr), PR_FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2002-01-25 21:57:47 +00:00
|
|
|
// set the special -moz-math-firstrow to annotate that we are on the first row
|
2002-01-25 07:03:43 +00:00
|
|
|
hasChanged = PR_TRUE;
|
|
|
|
aCellContent->SetAttr(kNameSpaceID_None, nsMathMLAtoms::firstrow, trueStr, PR_FALSE);
|
|
|
|
}
|
2002-01-25 21:57:47 +00:00
|
|
|
// if we are on the last row, set the special -moz-math-lastrow
|
2002-01-27 19:26:42 +00:00
|
|
|
PRInt32 rowSpan = ((nsTableFrame*)tableFrame)->GetEffectiveRowSpan(*cellFrame);
|
|
|
|
sibling = ((nsTableFrame*)tableFrame)->GetCellFrameAt(rowIndex+rowSpan, colIndex);
|
2002-01-25 07:03:43 +00:00
|
|
|
if (!sibling) {
|
|
|
|
hasChanged = PR_TRUE;
|
|
|
|
aCellContent->SetAttr(kNameSpaceID_None, nsMathMLAtoms::lastrow, trueStr, PR_FALSE);
|
2000-05-16 13:18:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////
|
2002-01-25 07:03:43 +00:00
|
|
|
// process attributes that depend on the index of the column
|
|
|
|
// columnalign, columnlines, XXX need columnwidth too
|
|
|
|
|
|
|
|
// see if the columnalign attribute is not already set
|
|
|
|
atom = nsMathMLAtoms::columnalign_;
|
|
|
|
rv = aCellContent->GetAttr(kNameSpaceID_None, atom, value);
|
|
|
|
if (NS_CONTENT_ATTR_NOT_THERE == rv) {
|
|
|
|
// see if the columnalign attribute was specified on the row
|
|
|
|
attr = GetValueAt(aPresContext, rowFrame, atom, colIndex);
|
|
|
|
if (!attr) {
|
|
|
|
// see if the columnalign attribute was specified on the table
|
|
|
|
attr = GetValueAt(aPresContext, tableFrame, atom, colIndex);
|
|
|
|
}
|
|
|
|
if (attr) {
|
|
|
|
hasChanged = PR_TRUE;
|
|
|
|
aCellContent->SetAttr(kNameSpaceID_None, atom, nsDependentString(attr), PR_FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// if we are not on the first column, see if |columnlines| was specified on
|
|
|
|
// the table. Note that we pass 'colIndex-1' because the CSS rule in mathml.css
|
|
|
|
// is associated to 'border-left', and it as if we draw the line on behalf
|
|
|
|
// of the previous cell. This way of doing so allows us to handle selective lines,
|
|
|
|
// e.g., 'r|cl', and cases of spanning cells without further complications.
|
|
|
|
if (colIndex > 0) {
|
|
|
|
attr = GetValueAt(aPresContext, tableFrame, nsMathMLAtoms::columnlines_, colIndex-1);
|
|
|
|
// set the special -moz-math-columnline without notifying that we want a reflow
|
|
|
|
if (attr) {
|
|
|
|
hasChanged = PR_TRUE;
|
|
|
|
aCellContent->SetAttr(kNameSpaceID_None, nsMathMLAtoms::columnline, nsDependentString(attr), PR_FALSE);
|
2000-05-16 13:18:42 +00:00
|
|
|
}
|
|
|
|
}
|
2002-01-25 07:03:43 +00:00
|
|
|
else {
|
2002-01-25 21:57:47 +00:00
|
|
|
// set the special -moz-math-firstcolumn to annotate that we are on the first column
|
2002-01-25 07:03:43 +00:00
|
|
|
hasChanged = PR_TRUE;
|
|
|
|
aCellContent->SetAttr(kNameSpaceID_None, nsMathMLAtoms::firstcolumn, trueStr, PR_FALSE);
|
|
|
|
}
|
2002-01-25 21:57:47 +00:00
|
|
|
// if we are on the last column, set the special -moz-math-lastcolumn
|
2002-01-27 19:26:42 +00:00
|
|
|
PRInt32 colSpan = ((nsTableFrame*)tableFrame)->GetEffectiveColSpan(*cellFrame);
|
|
|
|
sibling = ((nsTableFrame*)tableFrame)->GetCellFrameAt(rowIndex, colIndex+colSpan);
|
2002-01-25 07:03:43 +00:00
|
|
|
if (!sibling) {
|
|
|
|
hasChanged = PR_TRUE;
|
|
|
|
aCellContent->SetAttr(kNameSpaceID_None, nsMathMLAtoms::lastcolumn, trueStr, PR_FALSE);
|
|
|
|
}
|
2000-05-16 13:18:42 +00:00
|
|
|
|
2002-01-25 07:03:43 +00:00
|
|
|
// now, re-resolve the style contexts in our subtree to pick up any changes
|
|
|
|
if (hasChanged) {
|
|
|
|
nsCOMPtr<nsIPresShell> presShell;
|
|
|
|
aPresContext->GetShell(getter_AddRefs(presShell));
|
|
|
|
if (presShell) {
|
|
|
|
nsCOMPtr<nsIFrameManager> fm;
|
|
|
|
presShell->GetFrameManager(getter_AddRefs(fm));
|
|
|
|
if (fm) {
|
|
|
|
PRInt32 maxChange, minChange = NS_STYLE_HINT_NONE;
|
|
|
|
nsStyleChangeList changeList;
|
|
|
|
fm->ComputeStyleChangeFor(aPresContext, aCellFrame, kNameSpaceID_None, nsnull,
|
|
|
|
changeList, minChange, maxChange);
|
|
|
|
}
|
2001-05-19 10:00:01 +00:00
|
|
|
}
|
2000-05-16 13:18:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-01-25 07:03:43 +00:00
|
|
|
// the align attribute of mtable can have a row number which indicates
|
|
|
|
// from where to anchor the table, e.g., top5 means anchor the table at
|
|
|
|
// the top of the 5th row, axis-1 means anchor the table on the axis of
|
|
|
|
// the last row (could have been nicer if the REC used the '#' separator,
|
|
|
|
// e.g., top#5, or axis#-1)
|
|
|
|
|
|
|
|
enum eAlign {
|
|
|
|
eAlign_top,
|
|
|
|
eAlign_bottom,
|
|
|
|
eAlign_center,
|
|
|
|
eAlign_baseline,
|
|
|
|
eAlign_axis
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
ParseAlignAttribute(nsString& aValue, eAlign& aAlign, PRInt32& aRowIndex)
|
|
|
|
{
|
|
|
|
// by default, the table is centered about the axis
|
|
|
|
aRowIndex = 0;
|
|
|
|
aAlign = eAlign_axis;
|
|
|
|
PRInt32 len = 0;
|
|
|
|
if (0 == aValue.Find("top")) {
|
|
|
|
len = 3; // 3 is the length of 'top'
|
|
|
|
aAlign = eAlign_top;
|
|
|
|
}
|
|
|
|
else if (0 == aValue.Find("bottom")) {
|
|
|
|
len = 6; // 6 is the length of 'bottom'
|
|
|
|
aAlign = eAlign_bottom;
|
|
|
|
}
|
|
|
|
else if (0 == aValue.Find("center")) {
|
|
|
|
len = 6; // 6 is the length of 'center'
|
|
|
|
aAlign = eAlign_center;
|
|
|
|
}
|
|
|
|
else if (0 == aValue.Find("baseline")) {
|
|
|
|
len = 8; // 8 is the length of 'baseline'
|
|
|
|
aAlign = eAlign_baseline;
|
|
|
|
}
|
|
|
|
else if (0 == aValue.Find("axis")) {
|
|
|
|
len = 4; // 4 is the length of 'axis'
|
|
|
|
aAlign = eAlign_axis;
|
|
|
|
}
|
|
|
|
if (len) {
|
|
|
|
PRInt32 error;
|
|
|
|
aValue.Cut(0, len); // aValue is not a const here
|
|
|
|
aRowIndex = aValue.ToInteger(&error);
|
|
|
|
if (error)
|
|
|
|
aRowIndex = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-03-28 10:15:19 +00:00
|
|
|
// --------
|
|
|
|
// implementation of nsMathMLmtableOuterFrame
|
|
|
|
|
2001-02-23 16:10:51 +00:00
|
|
|
NS_IMPL_ADDREF_INHERITED(nsMathMLmtableOuterFrame, nsMathMLFrame)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(nsMathMLmtableOuterFrame, nsMathMLFrame)
|
|
|
|
NS_IMPL_QUERY_INTERFACE_INHERITED1(nsMathMLmtableOuterFrame, nsTableOuterFrame, nsMathMLFrame)
|
|
|
|
|
2000-03-28 10:15:19 +00:00
|
|
|
nsresult
|
|
|
|
NS_NewMathMLmtableOuterFrame (nsIPresShell* aPresShell, nsIFrame** aNewFrame)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aNewFrame, "null OUT ptr");
|
|
|
|
if (nsnull == aNewFrame) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
nsMathMLmtableOuterFrame* it = new (aPresShell) nsMathMLmtableOuterFrame;
|
|
|
|
if (!it)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
*aNewFrame = it;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsMathMLmtableOuterFrame::nsMathMLmtableOuterFrame()
|
|
|
|
:nsTableOuterFrame()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsMathMLmtableOuterFrame::~nsMathMLmtableOuterFrame()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMathMLmtableOuterFrame::Init(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aContent,
|
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIStyleContext* aContext,
|
|
|
|
nsIFrame* aPrevInFlow)
|
|
|
|
{
|
|
|
|
nsresult rv = nsTableOuterFrame::Init(aPresContext, aContent, aParent, aContext, aPrevInFlow);
|
|
|
|
|
2001-02-23 16:10:51 +00:00
|
|
|
// XXX the REC says that by default, displaystyle=false in <mtable>
|
|
|
|
|
2002-01-12 03:04:14 +00:00
|
|
|
// now, inherit the scriptlevel and displaystyle from our parent
|
2002-01-12 08:06:08 +00:00
|
|
|
GetPresentationDataFrom(aParent, mPresentationData);
|
2001-02-23 16:10:51 +00:00
|
|
|
|
|
|
|
// see if the displaystyle attribute is there and let it override what we inherited
|
|
|
|
nsAutoString value;
|
2001-05-19 10:00:01 +00:00
|
|
|
if (NS_CONTENT_ATTR_HAS_VALUE ==
|
2002-01-12 08:06:08 +00:00
|
|
|
GetAttribute(mContent, nsnull, nsMathMLAtoms::displaystyle_, value)) {
|
2001-05-19 10:00:01 +00:00
|
|
|
if (value.Equals(NS_LITERAL_STRING("true"))) {
|
2001-02-23 16:10:51 +00:00
|
|
|
mPresentationData.flags |= NS_MATHML_DISPLAYSTYLE;
|
|
|
|
}
|
2001-05-19 10:00:01 +00:00
|
|
|
else if (value.Equals(NS_LITERAL_STRING("false"))) {
|
2001-02-23 16:10:51 +00:00
|
|
|
mPresentationData.flags &= ~NS_MATHML_DISPLAYSTYLE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-03-28 10:15:19 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2002-01-25 07:03:43 +00:00
|
|
|
nsIFrame*
|
|
|
|
nsMathMLmtableOuterFrame::GetRowFrameAt(nsIPresContext* aPresContext,
|
|
|
|
PRInt32 aRowIndex)
|
|
|
|
{
|
|
|
|
// To find the row at the given index, we will iterate downwards or
|
|
|
|
// upwards depending on the sign of the index
|
|
|
|
nsTableIteration dir = eTableLTR;
|
|
|
|
if (aRowIndex < 0) {
|
|
|
|
aRowIndex = -aRowIndex;
|
|
|
|
dir = eTableRTL;
|
|
|
|
}
|
|
|
|
// if our inner table says that the index is valid, find the row now
|
|
|
|
PRInt32 rowCount, colCount;
|
|
|
|
GetTableSize(rowCount, colCount);
|
|
|
|
if (aRowIndex <= rowCount) {
|
|
|
|
nsIFrame* innerTableFrame = mFrames.FirstChild();
|
|
|
|
nsTableIterator rowgroupIter(aPresContext, *innerTableFrame, dir);
|
|
|
|
nsIFrame* rowgroupFrame = rowgroupIter.First();
|
|
|
|
while (rowgroupFrame) {
|
|
|
|
nsTableIterator rowIter(aPresContext, *rowgroupFrame, dir);
|
|
|
|
nsIFrame* rowFrame = rowIter.First();
|
|
|
|
while (rowFrame) {
|
|
|
|
if (--aRowIndex == 0) {
|
|
|
|
DEBUG_VERIFY_THAT_FRAME_IS(rowFrame, TABLE_ROW);
|
|
|
|
return rowFrame;
|
|
|
|
}
|
|
|
|
rowFrame = rowIter.Next();
|
|
|
|
}
|
|
|
|
rowgroupFrame = rowgroupIter.Next();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
2000-03-28 10:15:19 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMathMLmtableOuterFrame::Reflow(nsIPresContext* aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
2001-05-19 10:00:01 +00:00
|
|
|
nsresult rv;
|
2002-01-25 07:03:43 +00:00
|
|
|
nsAutoString value;
|
|
|
|
// we want to return a table that is anchored according to the align attribute
|
2001-05-19 10:00:01 +00:00
|
|
|
|
|
|
|
nsHTMLReflowState reflowState(aReflowState);
|
|
|
|
if ((NS_FRAME_FIRST_REFLOW & mState) &&
|
|
|
|
(NS_UNCONSTRAINEDSIZE == reflowState.availableWidth)) {
|
|
|
|
// We are going to reflow twice because the table frame code is
|
|
|
|
// skipping the Pass 2 reflow when, at the Pass 1 reflow, the available
|
|
|
|
// size is unconstrained. Skipping the Pass2 messes the MathML vertical
|
|
|
|
// alignments that are resolved during the reflow of cell frames.
|
|
|
|
|
|
|
|
nscoord oldComputedWidth = reflowState.mComputedWidth;
|
|
|
|
reflowState.availableWidth = NS_UNCONSTRAINEDSIZE;
|
|
|
|
reflowState.mComputedWidth = NS_UNCONSTRAINEDSIZE;
|
|
|
|
reflowState.reason = eReflowReason_Initial;
|
|
|
|
|
|
|
|
rv = nsTableOuterFrame::Reflow(aPresContext, aDesiredSize, reflowState, aStatus);
|
|
|
|
|
|
|
|
// The second reflow will just be a reflow with a constrained width
|
|
|
|
reflowState.availableWidth = aDesiredSize.width;
|
|
|
|
reflowState.mComputedWidth = oldComputedWidth;
|
|
|
|
reflowState.reason = eReflowReason_StyleChange;
|
|
|
|
|
|
|
|
mState &= ~NS_FRAME_FIRST_REFLOW;
|
|
|
|
}
|
|
|
|
else if (mRect.width) {
|
|
|
|
reflowState.availableWidth = mRect.width;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = nsTableOuterFrame::Reflow(aPresContext, aDesiredSize, reflowState, aStatus);
|
|
|
|
NS_ASSERTION(aDesiredSize.height >= 0, "illegal height for mtable");
|
|
|
|
NS_ASSERTION(aDesiredSize.width >= 0, "illegal width for mtable");
|
2000-03-28 10:15:19 +00:00
|
|
|
|
2000-05-08 07:23:22 +00:00
|
|
|
// see if the user has set the align attribute on the <mtable>
|
2000-05-16 13:18:42 +00:00
|
|
|
// XXX should we also check <mstyle> ?
|
2002-01-25 07:03:43 +00:00
|
|
|
PRInt32 rowIndex = 0;
|
|
|
|
eAlign tableAlign = eAlign_axis;
|
2001-05-19 10:00:01 +00:00
|
|
|
if (NS_CONTENT_ATTR_HAS_VALUE ==
|
2002-01-12 08:06:08 +00:00
|
|
|
GetAttribute(mContent, nsnull, nsMathMLAtoms::align_, value)) {
|
2002-01-25 07:03:43 +00:00
|
|
|
ParseAlignAttribute(value, tableAlign, rowIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
// adjustments if there is a specified row from where to anchor the table
|
|
|
|
// (conceptually: when there is no row of reference, picture the table as if
|
|
|
|
// it is wrapped in a single big fictional row at dy = 0, this way of
|
|
|
|
// doing so allows us to have a single code path for all cases).
|
|
|
|
nscoord dy = 0;
|
|
|
|
nscoord height = aDesiredSize.height;
|
|
|
|
nsIFrame* rowFrame = nsnull;
|
|
|
|
if (rowIndex) {
|
|
|
|
rowFrame = GetRowFrameAt(aPresContext, rowIndex);
|
|
|
|
if (rowFrame) {
|
|
|
|
// translate the coordinates to be relative to us
|
|
|
|
nsRect rect;
|
|
|
|
nsIFrame* frame = rowFrame;
|
|
|
|
frame->GetRect(rect);
|
|
|
|
height = rect.height;
|
|
|
|
do {
|
|
|
|
dy += rect.y;
|
|
|
|
frame->GetParent(&frame);
|
|
|
|
frame->GetRect(rect);
|
|
|
|
} while (frame != this);
|
2000-05-08 07:23:22 +00:00
|
|
|
}
|
2002-01-25 07:03:43 +00:00
|
|
|
}
|
|
|
|
switch (tableAlign) {
|
|
|
|
case eAlign_top:
|
|
|
|
aDesiredSize.ascent = dy;
|
|
|
|
break;
|
|
|
|
case eAlign_bottom:
|
|
|
|
aDesiredSize.ascent = dy + height;
|
|
|
|
break;
|
|
|
|
case eAlign_center:
|
|
|
|
aDesiredSize.ascent = dy + height/2;
|
|
|
|
break;
|
|
|
|
case eAlign_baseline:
|
|
|
|
if (rowFrame) {
|
|
|
|
// anchor the table on the baseline of the row of reference
|
|
|
|
nscoord rowAscent = ((nsTableRowFrame*)rowFrame)->GetMaxCellAscent();
|
|
|
|
if (rowAscent) { // the row has at least one cell with 'vertical-align: baseline'
|
|
|
|
aDesiredSize.ascent = dy + rowAscent;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// in other situations, fallback to center
|
|
|
|
aDesiredSize.ascent = dy + height/2;
|
|
|
|
break;
|
|
|
|
case eAlign_axis:
|
|
|
|
default: {
|
|
|
|
// XXX should instead use style data from the row of reference here ?
|
|
|
|
const nsStyleFont* font;
|
|
|
|
GetStyleData(eStyleStruct_Font, (const nsStyleStruct *&)font);
|
|
|
|
aReflowState.rendContext->SetFont(font->mFont);
|
|
|
|
nsCOMPtr<nsIFontMetrics> fm;
|
|
|
|
aReflowState.rendContext->GetFontMetrics(*getter_AddRefs(fm));
|
|
|
|
nscoord axisHeight;
|
|
|
|
GetAxisHeight(*aReflowState.rendContext, fm, axisHeight);
|
|
|
|
if (rowFrame) {
|
2002-01-27 19:26:42 +00:00
|
|
|
// anchor the table on the axis of the row of reference
|
2002-01-25 07:03:43 +00:00
|
|
|
// XXX fallback to baseline because it is a hard problem
|
2002-01-27 19:26:42 +00:00
|
|
|
// XXX need to fetch the axis of the row; would need rowalign=axis to work better
|
2002-01-25 07:03:43 +00:00
|
|
|
nscoord rowAscent = ((nsTableRowFrame*)rowFrame)->GetMaxCellAscent();
|
|
|
|
if (rowAscent) { // the row has at least one cell with 'vertical-align: baseline'
|
|
|
|
aDesiredSize.ascent = dy + rowAscent;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// in other situations, fallback to using half of the height
|
|
|
|
aDesiredSize.ascent = dy + height/2 + axisHeight;
|
2000-05-08 07:23:22 +00:00
|
|
|
}
|
|
|
|
}
|
2002-01-25 07:03:43 +00:00
|
|
|
aDesiredSize.descent = aDesiredSize.height - aDesiredSize.ascent;
|
2001-05-31 22:19:43 +00:00
|
|
|
|
2002-01-25 07:03:43 +00:00
|
|
|
mReference.x = 0;
|
|
|
|
mReference.y = aDesiredSize.ascent;
|
2000-03-28 10:15:19 +00:00
|
|
|
|
|
|
|
// just make-up a bounding metrics
|
|
|
|
mBoundingMetrics.Clear();
|
|
|
|
mBoundingMetrics.ascent = aDesiredSize.ascent;
|
|
|
|
mBoundingMetrics.descent = aDesiredSize.descent;
|
|
|
|
mBoundingMetrics.width = aDesiredSize.width;
|
|
|
|
mBoundingMetrics.leftBearing = 0;
|
|
|
|
mBoundingMetrics.rightBearing = aDesiredSize.width;
|
|
|
|
|
|
|
|
aDesiredSize.mBoundingMetrics = mBoundingMetrics;
|
2000-05-16 13:18:42 +00:00
|
|
|
|
2000-03-28 10:15:19 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2002-01-25 07:03:43 +00:00
|
|
|
// --------
|
|
|
|
// implementation of nsMathMLmtdFrame
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF_INHERITED(nsMathMLmtdFrame, nsTableCellFrame)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(nsMathMLmtdFrame, nsTableCellFrame)
|
|
|
|
NS_IMPL_QUERY_INTERFACE_INHERITED0(nsMathMLmtdFrame, nsTableCellFrame)
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
NS_NewMathMLmtdFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aNewFrame, "null OUT ptr");
|
|
|
|
if (nsnull == aNewFrame) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
nsMathMLmtdFrame* it = new (aPresShell) nsMathMLmtdFrame;
|
|
|
|
if (nsnull == it) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
*aNewFrame = it;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsMathMLmtdFrame::nsMathMLmtdFrame()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsMathMLmtdFrame::~nsMathMLmtdFrame()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32
|
|
|
|
nsMathMLmtdFrame::GetRowSpan()
|
|
|
|
{
|
|
|
|
PRInt32 rowspan = 1;
|
|
|
|
nsAutoString value;
|
|
|
|
if (NS_CONTENT_ATTR_HAS_VALUE == mContent->GetAttr(kNameSpaceID_None,
|
|
|
|
nsMathMLAtoms::rowspan_, value)) {
|
|
|
|
PRInt32 error;
|
|
|
|
rowspan = value.ToInteger(&error);
|
|
|
|
if (error)
|
|
|
|
rowspan = 1;
|
|
|
|
}
|
|
|
|
return rowspan;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32
|
|
|
|
nsMathMLmtdFrame::GetColSpan()
|
|
|
|
{
|
|
|
|
PRInt32 colspan = 1;
|
|
|
|
nsAutoString value;
|
|
|
|
if (NS_CONTENT_ATTR_HAS_VALUE == mContent->GetAttr(kNameSpaceID_None,
|
|
|
|
nsMathMLAtoms::columnspan_, value)) {
|
|
|
|
PRInt32 error;
|
|
|
|
colspan = value.ToInteger(&error);
|
|
|
|
if (error)
|
|
|
|
colspan = 1;
|
|
|
|
}
|
|
|
|
return colspan;
|
|
|
|
}
|
2000-05-16 13:18:42 +00:00
|
|
|
|
2000-03-28 10:15:19 +00:00
|
|
|
// --------
|
2001-05-19 10:00:01 +00:00
|
|
|
// implementation of nsMathMLmtdInnerFrame
|
2000-03-28 10:15:19 +00:00
|
|
|
|
2001-05-19 10:00:01 +00:00
|
|
|
NS_IMPL_ADDREF_INHERITED(nsMathMLmtdInnerFrame, nsMathMLFrame)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(nsMathMLmtdInnerFrame, nsMathMLFrame)
|
|
|
|
NS_IMPL_QUERY_INTERFACE_INHERITED1(nsMathMLmtdInnerFrame, nsBlockFrame, nsMathMLFrame)
|
2001-02-23 16:10:51 +00:00
|
|
|
|
2000-03-28 10:15:19 +00:00
|
|
|
nsresult
|
2001-05-19 10:00:01 +00:00
|
|
|
NS_NewMathMLmtdInnerFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame)
|
2000-03-28 10:15:19 +00:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aNewFrame, "null OUT ptr");
|
|
|
|
if (nsnull == aNewFrame) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
2001-05-19 10:00:01 +00:00
|
|
|
nsMathMLmtdInnerFrame* it = new (aPresShell) nsMathMLmtdInnerFrame;
|
2000-03-28 10:15:19 +00:00
|
|
|
if (nsnull == it) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
*aNewFrame = it;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-05-19 10:00:01 +00:00
|
|
|
nsMathMLmtdInnerFrame::nsMathMLmtdInnerFrame()
|
2000-03-28 10:15:19 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2001-05-19 10:00:01 +00:00
|
|
|
nsMathMLmtdInnerFrame::~nsMathMLmtdInnerFrame()
|
2000-03-28 10:15:19 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2001-02-23 16:10:51 +00:00
|
|
|
NS_IMETHODIMP
|
2001-05-19 10:00:01 +00:00
|
|
|
nsMathMLmtdInnerFrame::Init(nsIPresContext* aPresContext,
|
2002-01-09 18:51:30 +00:00
|
|
|
nsIContent* aContent,
|
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIStyleContext* aContext,
|
|
|
|
nsIFrame* aPrevInFlow)
|
2001-02-23 16:10:51 +00:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
rv = nsBlockFrame::Init(aPresContext, aContent, aParent, aContext, aPrevInFlow);
|
|
|
|
|
2001-05-19 10:00:01 +00:00
|
|
|
// record that children that are ignorable whitespace should be excluded
|
2001-02-23 16:10:51 +00:00
|
|
|
mState |= NS_FRAME_EXCLUDE_IGNORABLE_WHITESPACE;
|
|
|
|
|
2002-01-12 03:04:14 +00:00
|
|
|
// now, inherit the scriptlevel and displaystyle from our parent
|
2002-01-12 08:06:08 +00:00
|
|
|
GetPresentationDataFrom(aParent, mPresentationData);
|
2001-02-23 16:10:51 +00:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2000-03-28 10:15:19 +00:00
|
|
|
NS_IMETHODIMP
|
2001-05-19 10:00:01 +00:00
|
|
|
nsMathMLmtdInnerFrame::Reflow(nsIPresContext* aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
2000-03-28 10:15:19 +00:00
|
|
|
{
|
2001-05-19 10:00:01 +00:00
|
|
|
// Map attributes to style (hopefully, bug 69409 will eventually help here).
|
2000-05-16 13:18:42 +00:00
|
|
|
if (NS_FRAME_FIRST_REFLOW & mState) {
|
2002-01-25 07:03:43 +00:00
|
|
|
MapAttributesInto(aPresContext, mContent, mParent, this);
|
2000-05-16 13:18:42 +00:00
|
|
|
}
|
|
|
|
|
2000-03-28 10:15:19 +00:00
|
|
|
// Let the base class do the reflow
|
2000-05-11 23:03:19 +00:00
|
|
|
nsresult rv = nsBlockFrame::Reflow(aPresContext, aDesiredSize, aReflowState, aStatus);
|
2000-03-28 10:15:19 +00:00
|
|
|
|
|
|
|
// more about <maligngroup/> and <malignmark/> later
|
|
|
|
// ...
|
|
|
|
return rv;
|
|
|
|
}
|