2004-02-23 21:29:06 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2004-04-18 14:30:37 +00:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
2002-01-25 07:03:43 +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/
|
|
|
|
*
|
|
|
|
* 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
|
|
|
*
|
2004-04-18 14:30:37 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* The University Of Queensland.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1999
|
|
|
|
* the Initial Developer. 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>
|
2004-04-18 14:30:37 +00:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* 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"),
|
|
|
|
* 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
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* 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
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2000-03-28 10:15:19 +00:00
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsFrame.h"
|
2008-12-29 15:07:38 +00:00
|
|
|
#include "nsBlockFrame.h"
|
2004-07-31 23:15:21 +00:00
|
|
|
#include "nsPresContext.h"
|
2003-02-22 00:32:13 +00:00
|
|
|
#include "nsStyleContext.h"
|
2000-03-28 10:15:19 +00:00
|
|
|
#include "nsStyleConsts.h"
|
|
|
|
#include "nsINameSpaceManager.h"
|
|
|
|
#include "nsIRenderingContext.h"
|
|
|
|
#include "nsIFontMetrics.h"
|
|
|
|
|
2009-02-03 14:42:18 +00:00
|
|
|
#include "nsTArray.h"
|
2006-09-07 03:45:45 +00:00
|
|
|
#include "nsCSSFrameConstructor.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"
|
2008-07-16 15:02:18 +00:00
|
|
|
#include "celldata.h"
|
2000-05-16 13:18:42 +00:00
|
|
|
|
2000-03-28 10:15:19 +00:00
|
|
|
#include "nsMathMLmtableFrame.h"
|
|
|
|
|
2010-03-29 01:46:55 +00:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2000-03-28 10:15:19 +00:00
|
|
|
//
|
|
|
|
// <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
|
2009-02-03 14:42:18 +00:00
|
|
|
SplitString(nsString& aString, // [IN/OUT]
|
|
|
|
nsTArray<PRUnichar*>& aOffset) // [OUT]
|
2000-05-16 13:18:42 +00:00
|
|
|
{
|
|
|
|
static const PRUnichar kNullCh = PRUnichar('\0');
|
|
|
|
|
|
|
|
aString.Append(kNullCh); // put an extra null at the end
|
|
|
|
|
2004-02-28 22:34:07 +00:00
|
|
|
PRUnichar* start = aString.BeginWriting();
|
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
|
|
|
|
{
|
2009-02-03 14:42:18 +00:00
|
|
|
nsString mData;
|
|
|
|
nsTArray<PRUnichar*> 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
|
2006-09-07 03:45:45 +00:00
|
|
|
// stored in the property table. Row/Cell frames query the property table
|
2000-05-16 13:18:42 +00:00
|
|
|
// 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.
|
2000-05-16 13:18:42 +00:00
|
|
|
|
|
|
|
static void
|
2010-03-29 01:46:55 +00:00
|
|
|
DestroyValueList(void* aPropertyValue)
|
2000-05-16 13:18:42 +00:00
|
|
|
{
|
2007-07-08 07:08:04 +00:00
|
|
|
delete static_cast<nsValueList*>(aPropertyValue);
|
2000-05-16 13:18:42 +00:00
|
|
|
}
|
|
|
|
|
2010-03-29 01:46:55 +00:00
|
|
|
NS_DECLARE_FRAME_PROPERTY(RowAlignProperty, DestroyValueList)
|
|
|
|
NS_DECLARE_FRAME_PROPERTY(RowLinesProperty, DestroyValueList)
|
|
|
|
NS_DECLARE_FRAME_PROPERTY(ColumnAlignProperty, DestroyValueList)
|
|
|
|
NS_DECLARE_FRAME_PROPERTY(ColumnLinesProperty, DestroyValueList)
|
|
|
|
|
|
|
|
static const FramePropertyDescriptor*
|
|
|
|
AttributeToProperty(nsIAtom* aAttribute)
|
|
|
|
{
|
|
|
|
if (aAttribute == nsGkAtoms::rowalign_)
|
|
|
|
return RowAlignProperty();
|
|
|
|
if (aAttribute == nsGkAtoms::rowlines_)
|
|
|
|
return RowLinesProperty();
|
|
|
|
if (aAttribute == nsGkAtoms::columnalign_)
|
|
|
|
return ColumnAlignProperty();
|
|
|
|
NS_ASSERTION(aAttribute == nsGkAtoms::columnlines_, "Invalid attribute");
|
|
|
|
return ColumnLinesProperty();
|
|
|
|
}
|
|
|
|
|
2000-05-16 13:18:42 +00:00
|
|
|
static PRUnichar*
|
2010-03-29 01:46:55 +00:00
|
|
|
GetValueAt(nsIFrame* aTableOrRowFrame,
|
|
|
|
const FramePropertyDescriptor* aProperty,
|
|
|
|
nsIAtom* aAttribute,
|
|
|
|
PRInt32 aRowOrColIndex)
|
2000-05-16 13:18:42 +00:00
|
|
|
{
|
2010-03-29 01:46:55 +00:00
|
|
|
FrameProperties props = aTableOrRowFrame->Properties();
|
|
|
|
nsValueList* valueList = static_cast<nsValueList*>(props.Get(aProperty));
|
2004-02-23 21:29:06 +00:00
|
|
|
if (!valueList) {
|
|
|
|
// The property isn't there yet, so set it
|
|
|
|
nsAutoString values;
|
2006-09-07 03:45:45 +00:00
|
|
|
aTableOrRowFrame->GetContent()->GetAttr(kNameSpaceID_None, aAttribute, values);
|
|
|
|
if (!values.IsEmpty())
|
2004-02-23 21:29:06 +00:00
|
|
|
valueList = new nsValueList(values);
|
2009-02-03 14:42:18 +00:00
|
|
|
if (!valueList || !valueList->mArray.Length()) {
|
2006-09-07 03:45:45 +00:00
|
|
|
delete valueList; // ok either way, delete is null safe
|
|
|
|
return nsnull;
|
2000-05-16 13:18:42 +00:00
|
|
|
}
|
2010-03-29 01:46:55 +00:00
|
|
|
props.Set(aProperty, valueList);
|
2000-05-16 13:18:42 +00:00
|
|
|
}
|
2009-02-03 14:42:18 +00:00
|
|
|
PRInt32 count = valueList->mArray.Length();
|
2006-09-07 03:45:45 +00:00
|
|
|
return (aRowOrColIndex < count)
|
2009-02-03 14:42:18 +00:00
|
|
|
? valueList->mArray[aRowOrColIndex]
|
|
|
|
: valueList->mArray[count-1];
|
2000-05-16 13:18:42 +00:00
|
|
|
}
|
|
|
|
|
2002-01-25 07:03:43 +00:00
|
|
|
#ifdef NS_DEBUG
|
2008-01-09 02:14:35 +00:00
|
|
|
static PRBool
|
|
|
|
IsTable(PRUint8 aDisplay)
|
|
|
|
{
|
|
|
|
if ((aDisplay == NS_STYLE_DISPLAY_TABLE) ||
|
|
|
|
(aDisplay == NS_STYLE_DISPLAY_INLINE_TABLE))
|
|
|
|
return PR_TRUE;
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2002-01-25 07:03:43 +00:00
|
|
|
#define DEBUG_VERIFY_THAT_FRAME_IS(_frame, _expected) \
|
2006-09-07 09:01:18 +00:00
|
|
|
NS_ASSERTION(NS_STYLE_DISPLAY_##_expected == _frame->GetStyleDisplay()->mDisplay, "internal error");
|
2008-01-09 02:14:35 +00:00
|
|
|
#define DEBUG_VERIFY_THAT_FRAME_IS_TABLE(_frame) \
|
|
|
|
NS_ASSERTION(IsTable(_frame->GetStyleDisplay()->mDisplay), "internal error");
|
2002-01-25 07:03:43 +00:00
|
|
|
#else
|
|
|
|
#define DEBUG_VERIFY_THAT_FRAME_IS(_frame, _expected)
|
2008-01-09 02:14:35 +00:00
|
|
|
#define DEBUG_VERIFY_THAT_FRAME_IS_TABLE(_frame)
|
2002-01-25 07:03:43 +00:00
|
|
|
#endif
|
|
|
|
|
2006-09-07 03:45:45 +00:00
|
|
|
// map attributes that depend on the index of the row:
|
|
|
|
// rowalign, rowlines, XXX need rowspacing too
|
2000-05-16 13:18:42 +00:00
|
|
|
static void
|
2006-09-07 03:45:45 +00:00
|
|
|
MapRowAttributesIntoCSS(nsIFrame* aTableFrame,
|
|
|
|
nsIFrame* aRowFrame)
|
2000-05-16 13:18:42 +00:00
|
|
|
{
|
2008-01-09 02:14:35 +00:00
|
|
|
DEBUG_VERIFY_THAT_FRAME_IS_TABLE(aTableFrame);
|
2006-09-07 09:01:18 +00:00
|
|
|
DEBUG_VERIFY_THAT_FRAME_IS(aRowFrame, TABLE_ROW);
|
2006-09-07 03:45:45 +00:00
|
|
|
PRInt32 rowIndex = ((nsTableRowFrame*)aRowFrame)->GetRowIndex();
|
|
|
|
nsIContent* rowContent = aRowFrame->GetContent();
|
2002-01-25 07:03:43 +00:00
|
|
|
PRUnichar* attr;
|
|
|
|
|
|
|
|
// see if the rowalign attribute is not already set
|
2006-12-26 17:47:52 +00:00
|
|
|
if (!rowContent->HasAttr(kNameSpaceID_None, nsGkAtoms::rowalign_) &&
|
2010-03-10 12:49:33 +00:00
|
|
|
!rowContent->HasAttr(kNameSpaceID_None, nsGkAtoms::_moz_math_rowalign_)) {
|
2006-09-07 03:45:45 +00:00
|
|
|
// see if the rowalign attribute was specified on the table
|
2010-03-29 01:46:55 +00:00
|
|
|
attr = GetValueAt(aTableFrame, RowAlignProperty(),
|
|
|
|
nsGkAtoms::rowalign_, rowIndex);
|
2002-01-25 07:03:43 +00:00
|
|
|
if (attr) {
|
2010-03-10 12:49:33 +00:00
|
|
|
// set our special _moz attribute on the row without notifying a reflow
|
|
|
|
rowContent->SetAttr(kNameSpaceID_None, nsGkAtoms::_moz_math_rowalign_,
|
2006-09-07 03:45:45 +00:00
|
|
|
nsDependentString(attr), PR_FALSE);
|
2002-01-25 07:03:43 +00:00
|
|
|
}
|
|
|
|
}
|
2006-09-07 03:45:45 +00:00
|
|
|
|
2002-01-25 07:03:43 +00:00
|
|
|
// 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
|
2002-02-01 15:10:50 +00:00
|
|
|
// to 'border-top', and it is as if we draw the line on behalf of the previous cell.
|
2002-01-25 07:03:43 +00:00
|
|
|
// This way of doing so allows us to handle selective lines, [row]\hline[row][row]',
|
|
|
|
// and cases of spanning cells without further complications.
|
2006-09-07 03:45:45 +00:00
|
|
|
if (rowIndex > 0 &&
|
2010-03-10 12:49:33 +00:00
|
|
|
!rowContent->HasAttr(kNameSpaceID_None, nsGkAtoms::_moz_math_rowline_)) {
|
2010-03-29 01:46:55 +00:00
|
|
|
attr = GetValueAt(aTableFrame, RowLinesProperty(),
|
|
|
|
nsGkAtoms::rowlines_, rowIndex-1);
|
2002-01-25 07:03:43 +00:00
|
|
|
if (attr) {
|
2010-03-10 12:49:33 +00:00
|
|
|
// set our special _moz attribute on the row without notifying a reflow
|
|
|
|
rowContent->SetAttr(kNameSpaceID_None, nsGkAtoms::_moz_math_rowline_,
|
2006-09-07 03:45:45 +00:00
|
|
|
nsDependentString(attr), PR_FALSE);
|
2002-01-25 07:03:43 +00:00
|
|
|
}
|
|
|
|
}
|
2006-09-07 03:45:45 +00:00
|
|
|
}
|
2000-05-16 13:18:42 +00:00
|
|
|
|
2006-09-07 03:45:45 +00:00
|
|
|
// map attributes that depend on the index of the column:
|
|
|
|
// columnalign, columnlines, XXX need columnwidth and columnspacing too
|
|
|
|
static void
|
|
|
|
MapColAttributesIntoCSS(nsIFrame* aTableFrame,
|
|
|
|
nsIFrame* aRowFrame,
|
|
|
|
nsIFrame* aCellFrame)
|
|
|
|
{
|
2008-01-09 02:14:35 +00:00
|
|
|
DEBUG_VERIFY_THAT_FRAME_IS_TABLE(aTableFrame);
|
2006-09-07 09:01:18 +00:00
|
|
|
DEBUG_VERIFY_THAT_FRAME_IS(aRowFrame, TABLE_ROW);
|
|
|
|
DEBUG_VERIFY_THAT_FRAME_IS(aCellFrame, TABLE_CELL);
|
2006-09-07 03:45:45 +00:00
|
|
|
PRInt32 rowIndex, colIndex;
|
|
|
|
((nsTableCellFrame*)aCellFrame)->GetCellIndexes(rowIndex, colIndex);
|
|
|
|
nsIContent* cellContent = aCellFrame->GetContent();
|
|
|
|
PRUnichar* attr;
|
2002-01-25 07:03:43 +00:00
|
|
|
|
|
|
|
// see if the columnalign attribute is not already set
|
2006-12-26 17:47:52 +00:00
|
|
|
if (!cellContent->HasAttr(kNameSpaceID_None, nsGkAtoms::columnalign_) &&
|
2010-03-10 12:49:33 +00:00
|
|
|
!cellContent->HasAttr(kNameSpaceID_None,
|
|
|
|
nsGkAtoms::_moz_math_columnalign_)) {
|
2002-01-25 07:03:43 +00:00
|
|
|
// see if the columnalign attribute was specified on the row
|
2010-03-29 01:46:55 +00:00
|
|
|
attr = GetValueAt(aRowFrame, ColumnAlignProperty(),
|
|
|
|
nsGkAtoms::columnalign_, colIndex);
|
2002-01-25 07:03:43 +00:00
|
|
|
if (!attr) {
|
2006-09-07 03:45:45 +00:00
|
|
|
// see if the columnalign attribute was specified on the table
|
2010-03-29 01:46:55 +00:00
|
|
|
attr = GetValueAt(aTableFrame, ColumnAlignProperty(),
|
|
|
|
nsGkAtoms::columnalign_, colIndex);
|
2002-01-25 07:03:43 +00:00
|
|
|
}
|
|
|
|
if (attr) {
|
2010-03-10 12:49:33 +00:00
|
|
|
// set our special _moz attribute without notifying a reflow
|
|
|
|
cellContent->SetAttr(kNameSpaceID_None, nsGkAtoms::_moz_math_columnalign_,
|
2006-09-07 03:45:45 +00:00
|
|
|
nsDependentString(attr), PR_FALSE);
|
2002-01-25 07:03:43 +00:00
|
|
|
}
|
|
|
|
}
|
2006-09-07 03:45:45 +00:00
|
|
|
|
2002-01-25 07:03:43 +00:00
|
|
|
// 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
|
2002-02-01 15:10:50 +00:00
|
|
|
// is associated to 'border-left', and it is as if we draw the line on behalf
|
2002-01-25 07:03:43 +00:00
|
|
|
// 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.
|
2006-09-07 03:45:45 +00:00
|
|
|
if (colIndex > 0 &&
|
2010-03-10 12:49:33 +00:00
|
|
|
!cellContent->HasAttr(kNameSpaceID_None,
|
|
|
|
nsGkAtoms::_moz_math_columnline_)) {
|
2010-03-29 01:46:55 +00:00
|
|
|
attr = GetValueAt(aTableFrame, ColumnLinesProperty(),
|
|
|
|
nsGkAtoms::columnlines_, colIndex-1);
|
2002-01-25 07:03:43 +00:00
|
|
|
if (attr) {
|
2010-03-10 12:49:33 +00:00
|
|
|
// set our special _moz attribute without notifying a reflow
|
|
|
|
cellContent->SetAttr(kNameSpaceID_None, nsGkAtoms::_moz_math_columnline_,
|
2006-09-07 03:45:45 +00:00
|
|
|
nsDependentString(attr), PR_FALSE);
|
2000-05-16 13:18:42 +00:00
|
|
|
}
|
|
|
|
}
|
2006-09-07 03:45:45 +00:00
|
|
|
}
|
2000-05-16 13:18:42 +00:00
|
|
|
|
2006-09-07 03:45:45 +00:00
|
|
|
// map all attribues within a table -- requires the indices of rows and cells.
|
|
|
|
// so it can only happen after they are made ready by the table base class.
|
|
|
|
static void
|
|
|
|
MapAllAttributesIntoCSS(nsIFrame* aTableFrame)
|
|
|
|
{
|
2006-09-19 04:43:14 +00:00
|
|
|
// mtable is simple and only has one (pseudo) row-group
|
2006-10-10 07:38:50 +00:00
|
|
|
nsIFrame* rgFrame = aTableFrame->GetFirstChild(nsnull);
|
|
|
|
if (!rgFrame || rgFrame->GetType() != nsGkAtoms::tableRowGroupFrame)
|
|
|
|
return;
|
2006-09-19 04:43:14 +00:00
|
|
|
|
2006-10-10 07:38:50 +00:00
|
|
|
nsIFrame* rowFrame = rgFrame->GetFirstChild(nsnull);
|
2006-09-19 04:43:14 +00:00
|
|
|
for ( ; rowFrame; rowFrame = rowFrame->GetNextSibling()) {
|
|
|
|
DEBUG_VERIFY_THAT_FRAME_IS(rowFrame, TABLE_ROW);
|
|
|
|
if (rowFrame->GetType() == nsGkAtoms::tableRowFrame) {
|
|
|
|
MapRowAttributesIntoCSS(aTableFrame, rowFrame);
|
|
|
|
nsIFrame* cellFrame = rowFrame->GetFirstChild(nsnull);
|
|
|
|
for ( ; cellFrame; cellFrame = cellFrame->GetNextSibling()) {
|
|
|
|
DEBUG_VERIFY_THAT_FRAME_IS(cellFrame, TABLE_CELL);
|
|
|
|
if (IS_TABLE_CELL(cellFrame->GetType())) {
|
|
|
|
MapColAttributesIntoCSS(aTableFrame, rowFrame, cellFrame);
|
2006-09-07 03:45:45 +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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-10-10 07:38:50 +00:00
|
|
|
#ifdef DEBUG_rbs_off
|
|
|
|
// call ListMathMLTree(mParent) to get the big picture
|
|
|
|
static void
|
|
|
|
ListMathMLTree(nsIFrame* atLeast)
|
|
|
|
{
|
|
|
|
// climb up to <math> or <body> if <math> isn't there
|
|
|
|
nsIFrame* f = atLeast;
|
|
|
|
for ( ; f; f = f->GetParent()) {
|
|
|
|
nsIContent* c = f->GetContent();
|
|
|
|
if (!c || c->Tag() == nsGkAtoms::math || c->Tag() == nsGkAtoms::body)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!f) f = atLeast;
|
2009-08-20 21:52:48 +00:00
|
|
|
f->List(stdout, 0);
|
2006-10-10 07:38:50 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2000-03-28 10:15:19 +00:00
|
|
|
// --------
|
|
|
|
// implementation of nsMathMLmtableOuterFrame
|
|
|
|
|
2009-01-12 19:20:59 +00:00
|
|
|
NS_QUERYFRAME_HEAD(nsMathMLmtableOuterFrame)
|
|
|
|
NS_QUERYFRAME_ENTRY(nsIMathMLFrame)
|
|
|
|
NS_QUERYFRAME_TAIL_INHERITING(nsTableOuterFrame)
|
2001-02-23 16:10:51 +00:00
|
|
|
|
2005-11-04 02:38:33 +00:00
|
|
|
nsIFrame*
|
2006-03-26 21:30:36 +00:00
|
|
|
NS_NewMathMLmtableOuterFrame (nsIPresShell* aPresShell, nsStyleContext* aContext)
|
2000-03-28 10:15:19 +00:00
|
|
|
{
|
2006-03-26 21:30:36 +00:00
|
|
|
return new (aPresShell) nsMathMLmtableOuterFrame(aContext);
|
2000-03-28 10:15:19 +00:00
|
|
|
}
|
|
|
|
|
2009-09-12 16:49:24 +00:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsMathMLmtableOuterFrame)
|
2010-03-29 01:46:55 +00:00
|
|
|
|
2000-03-28 10:15:19 +00:00
|
|
|
nsMathMLmtableOuterFrame::~nsMathMLmtableOuterFrame()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2005-02-07 01:57:50 +00:00
|
|
|
nsMathMLmtableOuterFrame::InheritAutomaticData(nsIFrame* aParent)
|
2000-03-28 10:15:19 +00:00
|
|
|
{
|
2001-02-23 16:10:51 +00:00
|
|
|
// XXX the REC says that by default, displaystyle=false in <mtable>
|
|
|
|
|
2008-01-09 09:38:28 +00:00
|
|
|
// let the base class inherit the displaystyle from our parent
|
2005-02-07 01:57:50 +00:00
|
|
|
nsMathMLFrame::InheritAutomaticData(aParent);
|
2001-02-23 16:10:51 +00:00
|
|
|
|
|
|
|
// see if the displaystyle attribute is there and let it override what we inherited
|
2006-12-26 17:47:52 +00:00
|
|
|
if (mContent->Tag() == nsGkAtoms::mtable_)
|
2006-10-10 07:38:50 +00:00
|
|
|
nsMathMLFrame::FindAttrDisplaystyle(mContent, mPresentationData);
|
2006-09-19 04:43:14 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// displaystyle is special in mtable...
|
|
|
|
// Since UpdatePresentation() and UpdatePresentationDataFromChildAt() can be called
|
|
|
|
// by a parent, ensure that the displaystyle attribute of mtable takes precedence
|
|
|
|
NS_IMETHODIMP
|
2008-01-09 09:38:28 +00:00
|
|
|
nsMathMLmtableOuterFrame::UpdatePresentationData(PRUint32 aFlagsValues,
|
2006-09-19 04:43:14 +00:00
|
|
|
PRUint32 aWhichFlags)
|
|
|
|
{
|
|
|
|
if (NS_MATHML_HAS_EXPLICIT_DISPLAYSTYLE(mPresentationData.flags)) {
|
|
|
|
// our current state takes precedence, disallow updating the displastyle
|
|
|
|
aWhichFlags &= ~NS_MATHML_DISPLAYSTYLE;
|
|
|
|
aFlagsValues &= ~NS_MATHML_DISPLAYSTYLE;
|
2005-10-28 11:25:24 +00:00
|
|
|
}
|
2006-09-19 04:43:14 +00:00
|
|
|
|
2008-01-09 09:38:28 +00:00
|
|
|
return nsMathMLFrame::UpdatePresentationData(aFlagsValues, aWhichFlags);
|
2006-09-19 04:43:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMathMLmtableOuterFrame::UpdatePresentationDataFromChildAt(PRInt32 aFirstIndex,
|
|
|
|
PRInt32 aLastIndex,
|
|
|
|
PRUint32 aFlagsValues,
|
|
|
|
PRUint32 aWhichFlags)
|
|
|
|
{
|
|
|
|
if (NS_MATHML_HAS_EXPLICIT_DISPLAYSTYLE(mPresentationData.flags)) {
|
|
|
|
// our current state takes precedence, disallow updating the displastyle
|
|
|
|
aWhichFlags &= ~NS_MATHML_DISPLAYSTYLE;
|
|
|
|
aFlagsValues &= ~NS_MATHML_DISPLAYSTYLE;
|
2001-02-23 16:10:51 +00:00
|
|
|
}
|
|
|
|
|
2006-09-19 04:43:14 +00:00
|
|
|
nsMathMLContainerFrame::PropagatePresentationDataFromChildAt(this,
|
2008-01-09 09:38:28 +00:00
|
|
|
aFirstIndex, aLastIndex, aFlagsValues, aWhichFlags);
|
2006-09-19 04:43:14 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
2002-02-01 15:10:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2006-09-19 04:43:14 +00:00
|
|
|
nsMathMLmtableOuterFrame::AttributeChanged(PRInt32 aNameSpaceID,
|
|
|
|
nsIAtom* aAttribute,
|
|
|
|
PRInt32 aModType)
|
2002-02-01 15:10:50 +00:00
|
|
|
{
|
2006-09-19 04:43:14 +00:00
|
|
|
// Attributes specific to <mtable>:
|
|
|
|
// frame : in mathml.css
|
|
|
|
// framespacing : not yet supported
|
|
|
|
// groupalign : not yet supported
|
|
|
|
// equalrows : not yet supported
|
|
|
|
// equalcolumns : not yet supported
|
|
|
|
// displaystyle : here
|
|
|
|
// align : in reflow
|
|
|
|
// rowalign : here
|
|
|
|
// rowlines : here
|
|
|
|
// rowspacing : not yet supported
|
|
|
|
// columnalign : here
|
|
|
|
// columnlines : here
|
|
|
|
// columnspacing : not yet supported
|
|
|
|
|
|
|
|
// mtable is simple and only has one (pseudo) row-group inside our inner-table
|
|
|
|
nsIFrame* tableFrame = mFrames.FirstChild();
|
2006-10-10 07:38:50 +00:00
|
|
|
if (!tableFrame || tableFrame->GetType() != nsGkAtoms::tableFrame)
|
|
|
|
return NS_OK;
|
|
|
|
nsIFrame* rgFrame = tableFrame->GetFirstChild(nsnull);
|
|
|
|
if (!rgFrame || rgFrame->GetType() != nsGkAtoms::tableRowGroupFrame)
|
|
|
|
return NS_OK;
|
2006-09-19 04:43:14 +00:00
|
|
|
|
|
|
|
// align - just need to issue a dirty (resize) reflow command
|
2006-12-26 17:47:52 +00:00
|
|
|
if (aAttribute == nsGkAtoms::align) {
|
2007-03-30 21:11:41 +00:00
|
|
|
PresContext()->PresShell()->
|
2007-05-06 19:16:51 +00:00
|
|
|
FrameNeedsReflow(this, nsIPresShell::eResize, NS_FRAME_IS_DIRTY);
|
2006-09-19 04:43:14 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// displaystyle - may seem innocuous, but it is actually very harsh --
|
|
|
|
// like changing an unit. Blow away and recompute all our automatic
|
|
|
|
// presentational data, and issue a style-changed reflow request
|
2006-12-26 17:47:52 +00:00
|
|
|
if (aAttribute == nsGkAtoms::displaystyle_) {
|
2006-09-19 04:43:14 +00:00
|
|
|
nsMathMLContainerFrame::RebuildAutomaticDataForChildren(mParent);
|
2007-05-06 22:50:21 +00:00
|
|
|
// Need to reflow the parent, not us, because this can actually
|
|
|
|
// affect siblings.
|
2007-03-30 21:11:41 +00:00
|
|
|
PresContext()->PresShell()->
|
2007-05-06 19:16:51 +00:00
|
|
|
FrameNeedsReflow(mParent, nsIPresShell::eStyleChange, NS_FRAME_IS_DIRTY);
|
2006-09-19 04:43:14 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ...and the other attributes affect rows or columns in one way or another
|
|
|
|
nsIAtom* MOZrowAtom = nsnull;
|
|
|
|
nsIAtom* MOZcolAtom = nsnull;
|
2006-12-26 17:47:52 +00:00
|
|
|
if (aAttribute == nsGkAtoms::rowalign_)
|
2010-03-10 12:49:33 +00:00
|
|
|
MOZrowAtom = nsGkAtoms::_moz_math_rowalign_;
|
2006-12-26 17:47:52 +00:00
|
|
|
else if (aAttribute == nsGkAtoms::rowlines_)
|
2010-03-10 12:49:33 +00:00
|
|
|
MOZrowAtom = nsGkAtoms::_moz_math_rowline_;
|
2006-12-26 17:47:52 +00:00
|
|
|
else if (aAttribute == nsGkAtoms::columnalign_)
|
2010-03-10 12:49:33 +00:00
|
|
|
MOZcolAtom = nsGkAtoms::_moz_math_columnalign_;
|
2006-12-26 17:47:52 +00:00
|
|
|
else if (aAttribute == nsGkAtoms::columnlines_)
|
2010-03-10 12:49:33 +00:00
|
|
|
MOZcolAtom = nsGkAtoms::_moz_math_columnline_;
|
2006-09-19 04:43:14 +00:00
|
|
|
|
|
|
|
if (!MOZrowAtom && !MOZcolAtom)
|
|
|
|
return NS_OK;
|
|
|
|
|
2010-03-29 01:46:55 +00:00
|
|
|
nsPresContext* presContext = tableFrame->PresContext();
|
2006-09-19 04:43:14 +00:00
|
|
|
// clear any cached nsValueList for this table
|
2010-03-29 01:46:55 +00:00
|
|
|
presContext->PropertyTable()->
|
|
|
|
Delete(tableFrame, AttributeToProperty(aAttribute));
|
2006-09-19 04:43:14 +00:00
|
|
|
|
2010-03-10 12:49:33 +00:00
|
|
|
// unset any _moz attribute that we may have set earlier, and re-sync
|
2006-10-10 07:38:50 +00:00
|
|
|
nsIFrame* rowFrame = rgFrame->GetFirstChild(nsnull);
|
2006-09-19 04:43:14 +00:00
|
|
|
for ( ; rowFrame; rowFrame = rowFrame->GetNextSibling()) {
|
|
|
|
if (rowFrame->GetType() == nsGkAtoms::tableRowFrame) {
|
|
|
|
if (MOZrowAtom) { // let rows do the work
|
|
|
|
rowFrame->GetContent()->UnsetAttr(kNameSpaceID_None, MOZrowAtom, PR_FALSE);
|
|
|
|
MapRowAttributesIntoCSS(tableFrame, rowFrame);
|
|
|
|
} else { // let cells do the work
|
|
|
|
nsIFrame* cellFrame = rowFrame->GetFirstChild(nsnull);
|
|
|
|
for ( ; cellFrame; cellFrame = cellFrame->GetNextSibling()) {
|
|
|
|
if (IS_TABLE_CELL(cellFrame->GetType())) {
|
|
|
|
cellFrame->GetContent()->UnsetAttr(kNameSpaceID_None, MOZcolAtom, PR_FALSE);
|
|
|
|
MapColAttributesIntoCSS(tableFrame, rowFrame, cellFrame);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Explicitly request a re-resolve and reflow in our subtree to pick up any changes
|
2010-03-29 01:46:55 +00:00
|
|
|
presContext->PresShell()->FrameConstructor()->
|
2010-06-18 16:23:05 +00:00
|
|
|
PostRestyleEvent(mContent->AsElement(), eRestyle_Subtree,
|
2010-05-14 17:04:51 +00:00
|
|
|
nsChangeHint_ReflowFrame);
|
2006-09-19 04:43:14 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
2000-03-28 10:15:19 +00:00
|
|
|
}
|
|
|
|
|
2002-01-25 07:03:43 +00:00
|
|
|
nsIFrame*
|
2004-07-31 23:15:21 +00:00
|
|
|
nsMathMLmtableOuterFrame::GetRowFrameAt(nsPresContext* aPresContext,
|
2002-01-25 07:03:43 +00:00
|
|
|
PRInt32 aRowIndex)
|
|
|
|
{
|
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
|
|
|
PRInt32 rowCount, colCount;
|
|
|
|
GetTableSize(rowCount, colCount);
|
|
|
|
|
|
|
|
// Negative indices mean to find upwards from the end.
|
2002-01-25 07:03:43 +00:00
|
|
|
if (aRowIndex < 0) {
|
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
|
|
|
aRowIndex = rowCount + aRowIndex;
|
2002-01-25 07:03:43 +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
|
|
|
// aRowIndex is 1-based, so convert it to a 0-based index
|
|
|
|
--aRowIndex;
|
|
|
|
|
2002-01-25 07:03:43 +00:00
|
|
|
// if our inner table says that the index is valid, find the row now
|
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
|
|
|
if (0 <= aRowIndex && aRowIndex <= rowCount) {
|
2006-10-10 07:38:50 +00:00
|
|
|
nsIFrame* tableFrame = mFrames.FirstChild();
|
|
|
|
if (!tableFrame || tableFrame->GetType() != nsGkAtoms::tableFrame)
|
|
|
|
return nsnull;
|
|
|
|
nsIFrame* rgFrame = tableFrame->GetFirstChild(nsnull);
|
|
|
|
if (!rgFrame || rgFrame->GetType() != nsGkAtoms::tableRowGroupFrame)
|
|
|
|
return nsnull;
|
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
|
|
|
nsTableIterator rowIter(*rgFrame);
|
2006-10-10 07:38:50 +00:00
|
|
|
nsIFrame* rowFrame = rowIter.First();
|
|
|
|
for ( ; rowFrame; rowFrame = rowIter.Next()) {
|
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
|
|
|
if (aRowIndex == 0) {
|
2006-10-10 07:38:50 +00:00
|
|
|
DEBUG_VERIFY_THAT_FRAME_IS(rowFrame, TABLE_ROW);
|
|
|
|
if (rowFrame->GetType() != nsGkAtoms::tableRowFrame)
|
|
|
|
return nsnull;
|
|
|
|
|
|
|
|
return rowFrame;
|
2002-01-25 07:03:43 +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
|
|
|
--aRowIndex;
|
2002-01-25 07:03:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
2000-03-28 10:15:19 +00:00
|
|
|
NS_IMETHODIMP
|
2004-07-31 23:15:21 +00:00
|
|
|
nsMathMLmtableOuterFrame::Reflow(nsPresContext* aPresContext,
|
2000-03-28 10:15:19 +00:00
|
|
|
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
|
|
|
|
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
|
|
|
rv = nsTableOuterFrame::Reflow(aPresContext, aDesiredSize, aReflowState,
|
|
|
|
aStatus);
|
2001-05-19 10:00:01 +00:00
|
|
|
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;
|
2006-12-26 17:47:52 +00:00
|
|
|
GetAttribute(mContent, nsnull, nsGkAtoms::align, value);
|
2005-10-28 11:25:24 +00:00
|
|
|
if (!value.IsEmpty()) {
|
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
|
|
|
|
nsIFrame* frame = rowFrame;
|
2003-07-08 11:00:00 +00:00
|
|
|
height = frame->GetSize().height;
|
2002-01-25 07:03:43 +00:00
|
|
|
do {
|
2003-07-08 11:00:00 +00:00
|
|
|
dy += frame->GetPosition().y;
|
|
|
|
frame = frame->GetParent();
|
2002-01-25 07:03:43 +00:00
|
|
|
} 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 ?
|
2010-02-24 17:57:44 +00:00
|
|
|
aReflowState.rendContext->SetFont(GetStyleFont()->mFont,
|
2008-12-04 16:09:53 +00:00
|
|
|
aPresContext->GetUserFontSet());
|
2002-01-25 07:03:43 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
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;
|
2007-01-23 04:06:56 +00:00
|
|
|
mBoundingMetrics.descent = aDesiredSize.height - aDesiredSize.ascent;
|
2000-03-28 10:15:19 +00:00
|
|
|
mBoundingMetrics.width = aDesiredSize.width;
|
|
|
|
mBoundingMetrics.leftBearing = 0;
|
|
|
|
mBoundingMetrics.rightBearing = aDesiredSize.width;
|
|
|
|
|
|
|
|
aDesiredSize.mBoundingMetrics = mBoundingMetrics;
|
2002-05-28 22:50:43 +00:00
|
|
|
NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aDesiredSize);
|
2000-05-16 13:18:42 +00:00
|
|
|
|
2000-03-28 10:15:19 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2006-09-07 03:45:45 +00:00
|
|
|
nsIFrame*
|
|
|
|
NS_NewMathMLmtableFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
|
|
|
{
|
|
|
|
return new (aPresShell) nsMathMLmtableFrame(aContext);
|
|
|
|
}
|
|
|
|
|
2009-09-12 16:49:24 +00:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsMathMLmtableFrame)
|
|
|
|
|
2006-09-07 03:45:45 +00:00
|
|
|
nsMathMLmtableFrame::~nsMathMLmtableFrame()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMathMLmtableFrame::SetInitialChildList(nsIAtom* aListName,
|
2009-07-28 12:53:20 +00:00
|
|
|
nsFrameList& aChildList)
|
2006-09-07 03:45:45 +00:00
|
|
|
{
|
|
|
|
nsresult rv = nsTableFrame::SetInitialChildList(aListName, aChildList);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
MapAllAttributesIntoCSS(this);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsMathMLmtableFrame::RestyleTable()
|
|
|
|
{
|
|
|
|
// re-sync MathML specific style data that may have changed
|
|
|
|
MapAllAttributesIntoCSS(this);
|
|
|
|
|
|
|
|
// Explicitly request a re-resolve and reflow in our subtree to pick up any changes
|
2007-03-30 21:11:41 +00:00
|
|
|
PresContext()->PresShell()->FrameConstructor()->
|
2010-06-18 16:23:05 +00:00
|
|
|
PostRestyleEvent(mContent->AsElement(), eRestyle_Subtree,
|
2010-05-14 17:04:51 +00:00
|
|
|
nsChangeHint_ReflowFrame);
|
2006-09-07 03:45:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// --------
|
|
|
|
// implementation of nsMathMLmtrFrame
|
|
|
|
|
|
|
|
nsIFrame*
|
|
|
|
NS_NewMathMLmtrFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
|
|
|
{
|
|
|
|
return new (aPresShell) nsMathMLmtrFrame(aContext);
|
|
|
|
}
|
|
|
|
|
2009-09-12 16:49:24 +00:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsMathMLmtrFrame)
|
|
|
|
|
2006-09-07 03:45:45 +00:00
|
|
|
nsMathMLmtrFrame::~nsMathMLmtrFrame()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMathMLmtrFrame::AttributeChanged(PRInt32 aNameSpaceID,
|
|
|
|
nsIAtom* aAttribute,
|
|
|
|
PRInt32 aModType)
|
|
|
|
{
|
|
|
|
// Attributes specific to <mtr>:
|
|
|
|
// groupalign : Not yet supported.
|
|
|
|
// rowalign : Fully specified in mathml.css, and so HasAttributeDependentStyle() will
|
|
|
|
// pick it up and nsCSSFrameConstructor will issue a PostRestyleEvent().
|
|
|
|
// columnalign : Need an explicit re-style call.
|
|
|
|
|
2006-12-26 17:47:52 +00:00
|
|
|
if (aAttribute == nsGkAtoms::rowalign_) {
|
2010-03-10 12:49:33 +00:00
|
|
|
// unset any _moz attribute that we may have set earlier, and re-sync
|
|
|
|
mContent->UnsetAttr(kNameSpaceID_None, nsGkAtoms::_moz_math_rowalign_,
|
|
|
|
PR_FALSE);
|
2006-09-07 03:45:45 +00:00
|
|
|
MapRowAttributesIntoCSS(nsTableFrame::GetTableFrame(this), this);
|
|
|
|
// That's all - see comment above.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-12-26 17:47:52 +00:00
|
|
|
if (aAttribute != nsGkAtoms::columnalign_)
|
2006-09-07 03:45:45 +00:00
|
|
|
return NS_OK;
|
|
|
|
|
2010-03-29 01:46:55 +00:00
|
|
|
nsPresContext* presContext = PresContext();
|
2006-09-07 03:45:45 +00:00
|
|
|
// Clear any cached columnalign's nsValueList for this row
|
2010-03-29 01:46:55 +00:00
|
|
|
presContext->PropertyTable()->Delete(this, AttributeToProperty(aAttribute));
|
2006-09-07 03:45:45 +00:00
|
|
|
|
2010-03-10 12:49:33 +00:00
|
|
|
// Clear any internal _moz attribute that we may have set earlier
|
2006-09-07 03:45:45 +00:00
|
|
|
// in our cells and re-sync their columnalign attribute
|
|
|
|
nsTableFrame* tableFrame = nsTableFrame::GetTableFrame(this);
|
|
|
|
nsIFrame* cellFrame = GetFirstChild(nsnull);
|
|
|
|
for ( ; cellFrame; cellFrame = cellFrame->GetNextSibling()) {
|
|
|
|
if (IS_TABLE_CELL(cellFrame->GetType())) {
|
|
|
|
cellFrame->GetContent()->
|
2010-03-10 12:49:33 +00:00
|
|
|
UnsetAttr(kNameSpaceID_None, nsGkAtoms::_moz_math_columnalign_,
|
|
|
|
PR_FALSE);
|
2006-09-07 03:45:45 +00:00
|
|
|
MapColAttributesIntoCSS(tableFrame, this, cellFrame);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Explicitly request a re-resolve and reflow in our subtree to pick up any changes
|
2010-03-29 01:46:55 +00:00
|
|
|
presContext->PresShell()->FrameConstructor()->
|
2010-06-18 16:23:05 +00:00
|
|
|
PostRestyleEvent(mContent->AsElement(), eRestyle_Subtree,
|
2010-05-14 17:04:51 +00:00
|
|
|
nsChangeHint_ReflowFrame);
|
2006-09-07 03:45:45 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-01-25 07:03:43 +00:00
|
|
|
// --------
|
|
|
|
// implementation of nsMathMLmtdFrame
|
|
|
|
|
2005-11-04 02:38:33 +00:00
|
|
|
nsIFrame*
|
2006-03-26 21:30:36 +00:00
|
|
|
NS_NewMathMLmtdFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
2002-01-25 07:03:43 +00:00
|
|
|
{
|
2006-03-26 21:30:36 +00:00
|
|
|
return new (aPresShell) nsMathMLmtdFrame(aContext);
|
2002-01-25 07:03:43 +00:00
|
|
|
}
|
|
|
|
|
2009-09-12 16:49:24 +00:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsMathMLmtdFrame)
|
|
|
|
|
2002-01-25 07:03:43 +00:00
|
|
|
nsMathMLmtdFrame::~nsMathMLmtdFrame()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32
|
|
|
|
nsMathMLmtdFrame::GetRowSpan()
|
|
|
|
{
|
|
|
|
PRInt32 rowspan = 1;
|
2007-02-19 20:46:31 +00:00
|
|
|
|
2008-01-26 16:32:16 +00:00
|
|
|
// Don't look at the content's rowspan if we're not an mtd or a pseudo cell.
|
2009-10-29 21:17:56 +00:00
|
|
|
if ((mContent->Tag() == nsGkAtoms::mtd_) && !GetStyleContext()->GetPseudo()) {
|
2007-02-19 20:46:31 +00:00
|
|
|
nsAutoString value;
|
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::rowspan, value);
|
|
|
|
if (!value.IsEmpty()) {
|
|
|
|
PRInt32 error;
|
|
|
|
rowspan = value.ToInteger(&error);
|
|
|
|
if (error || rowspan < 0)
|
|
|
|
rowspan = 1;
|
2009-09-16 15:01:36 +00:00
|
|
|
rowspan = NS_MIN(rowspan, MAX_ROWSPAN);
|
2007-02-19 20:46:31 +00:00
|
|
|
}
|
2002-01-25 07:03:43 +00:00
|
|
|
}
|
|
|
|
return rowspan;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32
|
|
|
|
nsMathMLmtdFrame::GetColSpan()
|
|
|
|
{
|
|
|
|
PRInt32 colspan = 1;
|
2007-02-19 20:46:31 +00:00
|
|
|
|
2008-01-26 16:32:16 +00:00
|
|
|
// Don't look at the content's colspan if we're not an mtd or a pseudo cell.
|
2009-10-29 21:17:56 +00:00
|
|
|
if ((mContent->Tag() == nsGkAtoms::mtd_) && !GetStyleContext()->GetPseudo()) {
|
2007-02-19 20:46:31 +00:00
|
|
|
nsAutoString value;
|
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::columnspan_, value);
|
|
|
|
if (!value.IsEmpty()) {
|
|
|
|
PRInt32 error;
|
|
|
|
colspan = value.ToInteger(&error);
|
2008-07-16 15:02:18 +00:00
|
|
|
if (error || colspan < 0 || colspan > MAX_COLSPAN)
|
2007-02-19 20:46:31 +00:00
|
|
|
colspan = 1;
|
|
|
|
}
|
2002-01-25 07:03:43 +00:00
|
|
|
}
|
|
|
|
return colspan;
|
|
|
|
}
|
2000-05-16 13:18:42 +00:00
|
|
|
|
2006-09-07 03:45:45 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMathMLmtdFrame::AttributeChanged(PRInt32 aNameSpaceID,
|
|
|
|
nsIAtom* aAttribute,
|
|
|
|
PRInt32 aModType)
|
|
|
|
{
|
|
|
|
// Attributes specific to <mtd>:
|
|
|
|
// groupalign : Not yet supported
|
|
|
|
// rowalign : in mathml.css
|
|
|
|
// columnalign : here
|
|
|
|
// rowspan : here
|
|
|
|
// columnspan : here
|
|
|
|
|
2006-12-26 17:47:52 +00:00
|
|
|
if (aAttribute == nsGkAtoms::columnalign_) {
|
2010-03-10 12:49:33 +00:00
|
|
|
// unset any _moz attribute that we may have set earlier, and re-sync
|
|
|
|
mContent->UnsetAttr(kNameSpaceID_None, nsGkAtoms::_moz_math_columnalign_,
|
|
|
|
PR_FALSE);
|
2006-09-07 03:45:45 +00:00
|
|
|
MapColAttributesIntoCSS(nsTableFrame::GetTableFrame(this), mParent, this);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-12-26 17:47:52 +00:00
|
|
|
if (aAttribute == nsGkAtoms::rowspan ||
|
|
|
|
aAttribute == nsGkAtoms::columnspan_) {
|
2006-09-07 03:45:45 +00:00
|
|
|
// use the naming expected by the base class
|
2006-12-26 17:47:52 +00:00
|
|
|
if (aAttribute == nsGkAtoms::columnspan_)
|
|
|
|
aAttribute = nsGkAtoms::colspan;
|
2006-09-07 03:45:45 +00:00
|
|
|
return nsTableCellFrame::AttributeChanged(aNameSpaceID, aAttribute, aModType);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2009-01-12 19:20:59 +00:00
|
|
|
NS_QUERYFRAME_HEAD(nsMathMLmtdInnerFrame)
|
|
|
|
NS_QUERYFRAME_ENTRY(nsIMathMLFrame)
|
|
|
|
NS_QUERYFRAME_TAIL_INHERITING(nsBlockFrame)
|
2001-02-23 16:10:51 +00:00
|
|
|
|
2005-11-04 02:38:33 +00:00
|
|
|
nsIFrame*
|
2006-03-26 21:30:36 +00:00
|
|
|
NS_NewMathMLmtdInnerFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
2000-03-28 10:15:19 +00:00
|
|
|
{
|
2006-03-26 21:30:36 +00:00
|
|
|
return new (aPresShell) nsMathMLmtdInnerFrame(aContext);
|
2000-03-28 10:15:19 +00:00
|
|
|
}
|
|
|
|
|
2009-09-12 16:49:24 +00:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsMathMLmtdInnerFrame)
|
|
|
|
|
2001-05-19 10:00:01 +00:00
|
|
|
nsMathMLmtdInnerFrame::~nsMathMLmtdInnerFrame()
|
2000-03-28 10:15:19 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2004-07-31 23:15:21 +00:00
|
|
|
nsMathMLmtdInnerFrame::Reflow(nsPresContext* aPresContext,
|
2001-05-19 10:00:01 +00:00
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
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;
|
|
|
|
}
|