mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-29 15:52:07 +00:00
Bug 731667 - Rewrite mtable implementation to avoid use of _moz-* attributes - implement parsing and rendering. r=karlt, r=bz
This commit is contained in:
parent
a5d20cf034
commit
6f30920da5
@ -5706,6 +5706,13 @@ nsBlockFrame::DeleteNextInFlowChild(nsPresContext* aPresContext,
|
||||
}
|
||||
}
|
||||
|
||||
const nsStyleText*
|
||||
nsBlockFrame::StyleTextForLineLayout()
|
||||
{
|
||||
// Return the pointer to an unmodified style text
|
||||
return StyleText();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// Float support
|
||||
|
||||
|
@ -314,6 +314,14 @@ public:
|
||||
nsIFrame* aNextInFlow,
|
||||
bool aDeletingEmptyFrames) MOZ_OVERRIDE;
|
||||
|
||||
/**
|
||||
* This is a special method that allows a child class of nsBlockFrame to
|
||||
* return a special, customized nsStyleText object to the nsLineLayout
|
||||
* constructor. It is used when the nsBlockFrame child needs to specify its
|
||||
* custom rendering style.
|
||||
*/
|
||||
virtual const nsStyleText* StyleTextForLineLayout();
|
||||
|
||||
/**
|
||||
* Determines whether the collapsed margin carried out of the last
|
||||
* line includes the margin-top of a line with clearance (in which
|
||||
|
@ -82,7 +82,12 @@ nsLineLayout::nsLineLayout(nsPresContext* aPresContext,
|
||||
MOZ_COUNT_CTOR(nsLineLayout);
|
||||
|
||||
// Stash away some style data that we need
|
||||
mStyleText = aOuterReflowState->frame->StyleText();
|
||||
nsBlockFrame* blockFrame = do_QueryFrame(aOuterReflowState->frame);
|
||||
if (blockFrame)
|
||||
mStyleText = blockFrame->StyleTextForLineLayout();
|
||||
else
|
||||
mStyleText = aOuterReflowState->frame->StyleText();
|
||||
|
||||
mLineNumber = 0;
|
||||
mTotalPlacedFrames = 0;
|
||||
mTopEdge = 0;
|
||||
@ -201,7 +206,8 @@ nsLineLayout::BeginLineReflow(nscoord aX, nscoord aY,
|
||||
|
||||
mTopEdge = aY;
|
||||
|
||||
psd->mNoWrap = !mStyleText->WhiteSpaceCanWrap(LineContainerFrame());
|
||||
psd->mNoWrap =
|
||||
!mStyleText->WhiteSpaceCanWrapStyle() || LineContainerFrame()->IsSVGText();
|
||||
psd->mDirection = aDirection;
|
||||
psd->mChangedFrameDirection = false;
|
||||
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "nsStyleConsts.h"
|
||||
#include "nsINameSpaceManager.h"
|
||||
#include "nsRenderingContext.h"
|
||||
#include "nsCSSRendering.h"
|
||||
|
||||
#include "nsTArray.h"
|
||||
#include "nsTableFrame.h"
|
||||
@ -17,74 +18,127 @@
|
||||
#include "RestyleManager.h"
|
||||
#include <algorithm>
|
||||
|
||||
#include "nsIScriptError.h"
|
||||
#include "nsContentUtils.h"
|
||||
|
||||
using namespace mozilla;
|
||||
|
||||
//
|
||||
// <mtable> -- table or matrix - implementation
|
||||
//
|
||||
|
||||
// helper function to perform an in-place split of a space-delimited string,
|
||||
// and return an array of pointers for the beginning of each segment, i.e.,
|
||||
// aOffset[0] is the first string, aOffset[1] is the second string, etc.
|
||||
// Used to parse attributes like columnalign='left right', rowalign='top bottom'
|
||||
static void
|
||||
SplitString(nsString& aString, // [IN/OUT]
|
||||
nsTArray<PRUnichar*>& aOffset) // [OUT]
|
||||
static int8_t
|
||||
ParseStyleValue(nsIAtom* aAttribute, const nsAString& aAttributeValue)
|
||||
{
|
||||
static const PRUnichar kNullCh = PRUnichar('\0');
|
||||
|
||||
aString.Append(kNullCh); // put an extra null at the end
|
||||
|
||||
PRUnichar* start = aString.BeginWriting();
|
||||
PRUnichar* end = start;
|
||||
|
||||
while (kNullCh != *start) {
|
||||
while ((kNullCh != *start) && nsCRT::IsAsciiSpace(*start)) { // skip leading space
|
||||
start++;
|
||||
}
|
||||
end = start;
|
||||
|
||||
while ((kNullCh != *end) && (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;
|
||||
if (aAttribute == nsGkAtoms::rowalign_) {
|
||||
if (aAttributeValue.EqualsLiteral("top"))
|
||||
return NS_STYLE_VERTICAL_ALIGN_TOP;
|
||||
else if (aAttributeValue.EqualsLiteral("bottom"))
|
||||
return NS_STYLE_VERTICAL_ALIGN_BOTTOM;
|
||||
else if (aAttributeValue.EqualsLiteral("center"))
|
||||
return NS_STYLE_VERTICAL_ALIGN_MIDDLE;
|
||||
else
|
||||
return NS_STYLE_VERTICAL_ALIGN_BASELINE;
|
||||
} else if (aAttribute == nsGkAtoms::columnalign_) {
|
||||
if (aAttributeValue.EqualsLiteral("left"))
|
||||
return NS_STYLE_TEXT_ALIGN_LEFT;
|
||||
else if (aAttributeValue.EqualsLiteral("right"))
|
||||
return NS_STYLE_TEXT_ALIGN_RIGHT;
|
||||
else
|
||||
return NS_STYLE_TEXT_ALIGN_CENTER;
|
||||
} else if (aAttribute == nsGkAtoms::rowlines_ ||
|
||||
aAttribute == nsGkAtoms::columnlines_) {
|
||||
if (aAttributeValue.EqualsLiteral("solid"))
|
||||
return NS_STYLE_BORDER_STYLE_SOLID;
|
||||
else if (aAttributeValue.EqualsLiteral("dashed"))
|
||||
return NS_STYLE_BORDER_STYLE_DASHED;
|
||||
else
|
||||
return NS_STYLE_BORDER_STYLE_NONE;
|
||||
} else {
|
||||
MOZ_CRASH("Unrecognized attribute.");
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct nsValueList
|
||||
static nsTArray<int8_t>*
|
||||
ExtractStyleValues(const nsAString& aString, nsIAtom* aAttribute,
|
||||
bool aAllowMultiValues)
|
||||
{
|
||||
nsString mData;
|
||||
nsTArray<PRUnichar*> mArray;
|
||||
nsTArray<int8_t>* styleArray = nullptr;
|
||||
|
||||
nsValueList(nsString& aData) {
|
||||
mData.Assign(aData);
|
||||
SplitString(mData, mArray);
|
||||
const PRUnichar* start = aString.BeginReading();
|
||||
const PRUnichar* end = aString.EndReading();
|
||||
|
||||
int32_t startIndex = 0;
|
||||
int32_t count = 0;
|
||||
|
||||
while (start < end) {
|
||||
// Skip leading spaces.
|
||||
while ((start < end) && nsCRT::IsAsciiSpace(*start)) {
|
||||
start++;
|
||||
startIndex++;
|
||||
}
|
||||
|
||||
// Look for the end of the string, or another space.
|
||||
while ((start < end) && !nsCRT::IsAsciiSpace(*start)) {
|
||||
start++;
|
||||
count++;
|
||||
}
|
||||
|
||||
// Grab the value found and process it.
|
||||
if (count > 0) {
|
||||
if (!styleArray)
|
||||
styleArray = new nsTArray<int8_t>();
|
||||
|
||||
// We want to return a null array if an attribute gives multiple values,
|
||||
// but multiple values aren't allowed.
|
||||
if (styleArray->Length() > 1 && !aAllowMultiValues) {
|
||||
delete styleArray;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
nsDependentSubstring valueString(aString, startIndex, count);
|
||||
int8_t styleValue = ParseStyleValue(aAttribute, valueString);
|
||||
styleArray->AppendElement(styleValue);
|
||||
|
||||
startIndex += count;
|
||||
count = 0;
|
||||
}
|
||||
}
|
||||
};
|
||||
return styleArray;
|
||||
}
|
||||
|
||||
static nsresult ReportParseError(nsIFrame* aFrame, const PRUnichar* aAttribute,
|
||||
const PRUnichar* aValue)
|
||||
{
|
||||
nsIContent* content = aFrame->GetContent();
|
||||
|
||||
const PRUnichar* params[] =
|
||||
{ aValue, aAttribute, content->Tag()->GetUTF16String() };
|
||||
|
||||
return nsContentUtils::ReportToConsole(nsIScriptError::errorFlag,
|
||||
NS_LITERAL_CSTRING("MathML"),
|
||||
content->OwnerDoc(),
|
||||
nsContentUtils::eMATHML_PROPERTIES,
|
||||
"AttributeParsingError", params, 3);
|
||||
}
|
||||
|
||||
// Each rowalign='top bottom' or columnalign='left right center' (from
|
||||
// <mtable> or <mtr>) is split once (lazily) into a nsValueList which is
|
||||
// <mtable> or <mtr>) is split once into an nsTArray<int8_t> which is
|
||||
// stored in the property table. Row/Cell frames query the property table
|
||||
// to see what values apply to them.
|
||||
|
||||
// XXX See bug 69409 - MathML attributes are not mapped to style.
|
||||
|
||||
static void
|
||||
DestroyValueList(void* aPropertyValue)
|
||||
DestroyStylePropertyList(void* aPropertyValue)
|
||||
{
|
||||
delete static_cast<nsValueList*>(aPropertyValue);
|
||||
delete static_cast<nsTArray<int8_t>*>(aPropertyValue);
|
||||
}
|
||||
|
||||
NS_DECLARE_FRAME_PROPERTY(RowAlignProperty, DestroyValueList)
|
||||
NS_DECLARE_FRAME_PROPERTY(RowLinesProperty, DestroyValueList)
|
||||
NS_DECLARE_FRAME_PROPERTY(ColumnAlignProperty, DestroyValueList)
|
||||
NS_DECLARE_FRAME_PROPERTY(ColumnLinesProperty, DestroyValueList)
|
||||
NS_DECLARE_FRAME_PROPERTY(RowAlignProperty, DestroyStylePropertyList)
|
||||
NS_DECLARE_FRAME_PROPERTY(RowLinesProperty, DestroyStylePropertyList)
|
||||
NS_DECLARE_FRAME_PROPERTY(ColumnAlignProperty, DestroyStylePropertyList)
|
||||
NS_DECLARE_FRAME_PROPERTY(ColumnLinesProperty, DestroyStylePropertyList)
|
||||
|
||||
static const FramePropertyDescriptor*
|
||||
AttributeToProperty(nsIAtom* aAttribute)
|
||||
@ -99,141 +153,132 @@ AttributeToProperty(nsIAtom* aAttribute)
|
||||
return ColumnLinesProperty();
|
||||
}
|
||||
|
||||
static PRUnichar*
|
||||
GetValueAt(nsIFrame* aTableOrRowFrame,
|
||||
const FramePropertyDescriptor* aProperty,
|
||||
nsIAtom* aAttribute,
|
||||
int32_t aRowOrColIndex)
|
||||
/* This method looks for a property that applies to a cell, but it looks
|
||||
* recursively because some cell properties can come from the cell, a row,
|
||||
* a table, etc. This function searches through the heirarchy for a property
|
||||
* and returns its value. The function stops searching after checking a <mtable>
|
||||
* frame.
|
||||
*/
|
||||
static nsTArray<int8_t>*
|
||||
FindCellProperty(const nsIFrame* aCellFrame,
|
||||
const FramePropertyDescriptor* aFrameProperty)
|
||||
{
|
||||
FrameProperties props = aTableOrRowFrame->Properties();
|
||||
nsValueList* valueList = static_cast<nsValueList*>(props.Get(aProperty));
|
||||
if (!valueList) {
|
||||
// The property isn't there yet, so set it
|
||||
nsAutoString values;
|
||||
aTableOrRowFrame->GetContent()->GetAttr(kNameSpaceID_None, aAttribute, values);
|
||||
if (!values.IsEmpty())
|
||||
valueList = new nsValueList(values);
|
||||
if (!valueList || !valueList->mArray.Length()) {
|
||||
delete valueList; // ok either way, delete is null safe
|
||||
return nullptr;
|
||||
}
|
||||
props.Set(aProperty, valueList);
|
||||
const nsIFrame* currentFrame = aCellFrame;
|
||||
nsTArray<int8_t>* propertyData = nullptr;
|
||||
|
||||
while (currentFrame) {
|
||||
FrameProperties props = currentFrame->Properties();
|
||||
propertyData = static_cast<nsTArray<int8_t>*>(props.Get(aFrameProperty));
|
||||
bool frameIsTable = (currentFrame->GetType() == nsGkAtoms::tableFrame);
|
||||
|
||||
if (propertyData || frameIsTable)
|
||||
currentFrame = nullptr; // A null frame pointer exits the loop
|
||||
else
|
||||
currentFrame = currentFrame->GetParent(); // Go to the parent frame
|
||||
}
|
||||
int32_t count = valueList->mArray.Length();
|
||||
return (aRowOrColIndex < count)
|
||||
? valueList->mArray[aRowOrColIndex]
|
||||
: valueList->mArray[count-1];
|
||||
|
||||
return propertyData;
|
||||
}
|
||||
|
||||
/*
|
||||
* A variant of the nsDisplayBorder contains special code to render a border
|
||||
* around a nsMathMLmtdFrame based on the rowline and columnline properties
|
||||
* set on the cell frame.
|
||||
*/
|
||||
class nsDisplaymtdBorder : public nsDisplayBorder {
|
||||
public:
|
||||
nsDisplaymtdBorder(nsDisplayListBuilder* aBuilder, nsMathMLmtdFrame* aFrame)
|
||||
: nsDisplayBorder(aBuilder, aFrame)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void Paint(nsDisplayListBuilder* aBuilder, nsRenderingContext* aCtx) MOZ_OVERRIDE
|
||||
{
|
||||
int32_t rowIndex;
|
||||
int32_t columnIndex;
|
||||
static_cast<nsTableCellFrame*>(mFrame)->
|
||||
GetCellIndexes(rowIndex, columnIndex);
|
||||
|
||||
nsStyleBorder styleBorder = *mFrame->StyleBorder();
|
||||
nscoord borderWidth =
|
||||
mFrame->PresContext()->GetBorderWidthTable()[NS_STYLE_BORDER_WIDTH_THIN];
|
||||
|
||||
nsTArray<int8_t>* rowLinesList =
|
||||
FindCellProperty(mFrame, RowLinesProperty());
|
||||
|
||||
nsTArray<int8_t>* columnLinesList =
|
||||
FindCellProperty(mFrame, ColumnLinesProperty());
|
||||
|
||||
// We don't place a row line on top of the first row
|
||||
if (rowIndex > 0 && rowLinesList) {
|
||||
// If the row number is greater than the number of provided rowline
|
||||
// values, we simply repeat the last value.
|
||||
int32_t listLength = rowLinesList->Length();
|
||||
if (rowIndex < listLength) {
|
||||
styleBorder.SetBorderStyle(NS_SIDE_TOP,
|
||||
rowLinesList->ElementAt(rowIndex - 1));
|
||||
} else {
|
||||
styleBorder.SetBorderStyle(NS_SIDE_TOP,
|
||||
rowLinesList->ElementAt(listLength - 1));
|
||||
}
|
||||
styleBorder.SetBorderWidth(NS_SIDE_TOP, borderWidth);
|
||||
}
|
||||
|
||||
// We don't place a column line on the left of the first column.
|
||||
if (columnIndex > 0 && columnLinesList) {
|
||||
// If the column number is greater than the number of provided columline
|
||||
// values, we simply repeat the last value.
|
||||
int32_t listLength = columnLinesList->Length();
|
||||
if (columnIndex < listLength) {
|
||||
styleBorder.SetBorderStyle(NS_SIDE_LEFT,
|
||||
columnLinesList->ElementAt(columnIndex - 1));
|
||||
} else {
|
||||
styleBorder.SetBorderStyle(NS_SIDE_LEFT,
|
||||
columnLinesList->ElementAt(listLength - 1));
|
||||
}
|
||||
styleBorder.SetBorderWidth(NS_SIDE_LEFT, borderWidth);
|
||||
}
|
||||
|
||||
nsPoint offset = ToReferenceFrame();
|
||||
nsCSSRendering::PaintBorderWithStyleBorder(mFrame->PresContext(), *aCtx,
|
||||
mFrame, mVisibleRect,
|
||||
nsRect(offset,
|
||||
mFrame->GetSize()),
|
||||
styleBorder,
|
||||
mFrame->StyleContext(),
|
||||
mFrame->GetSkipSides());
|
||||
}
|
||||
};
|
||||
|
||||
#ifdef DEBUG
|
||||
static bool
|
||||
IsTable(uint8_t aDisplay)
|
||||
{
|
||||
if ((aDisplay == NS_STYLE_DISPLAY_TABLE) ||
|
||||
(aDisplay == NS_STYLE_DISPLAY_INLINE_TABLE))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
#define DEBUG_VERIFY_THAT_FRAME_IS(_frame, _expected) \
|
||||
NS_ASSERTION(NS_STYLE_DISPLAY_##_expected == _frame->StyleDisplay()->mDisplay, "internal error");
|
||||
#define DEBUG_VERIFY_THAT_FRAME_IS_TABLE(_frame) \
|
||||
NS_ASSERTION(IsTable(_frame->StyleDisplay()->mDisplay), "internal error");
|
||||
#else
|
||||
#define DEBUG_VERIFY_THAT_FRAME_IS(_frame, _expected)
|
||||
#define DEBUG_VERIFY_THAT_FRAME_IS_TABLE(_frame)
|
||||
#endif
|
||||
|
||||
// map attributes that depend on the index of the row:
|
||||
// rowalign, rowlines, XXX need rowspacing too
|
||||
static void
|
||||
MapRowAttributesIntoCSS(nsIFrame* aTableFrame,
|
||||
nsIFrame* aRowFrame)
|
||||
ParseFrameAttribute(nsIFrame* aFrame, nsIAtom* aAttribute,
|
||||
bool aAllowMultiValues)
|
||||
{
|
||||
DEBUG_VERIFY_THAT_FRAME_IS_TABLE(aTableFrame);
|
||||
DEBUG_VERIFY_THAT_FRAME_IS(aRowFrame, TABLE_ROW);
|
||||
int32_t rowIndex = ((nsTableRowFrame*)aRowFrame)->GetRowIndex();
|
||||
nsIContent* rowContent = aRowFrame->GetContent();
|
||||
PRUnichar* attr;
|
||||
nsAutoString attrValue;
|
||||
|
||||
// see if the rowalign attribute is not already set
|
||||
if (!rowContent->HasAttr(kNameSpaceID_None, nsGkAtoms::rowalign_) &&
|
||||
!rowContent->HasAttr(kNameSpaceID_None, nsGkAtoms::_moz_math_rowalign_)) {
|
||||
// see if the rowalign attribute was specified on the table
|
||||
attr = GetValueAt(aTableFrame, RowAlignProperty(),
|
||||
nsGkAtoms::rowalign_, rowIndex);
|
||||
if (attr) {
|
||||
// set our special _moz attribute on the row without notifying a reflow
|
||||
rowContent->SetAttr(kNameSpaceID_None, nsGkAtoms::_moz_math_rowalign_,
|
||||
nsDependentString(attr), false);
|
||||
}
|
||||
}
|
||||
nsIContent* frameContent = aFrame->GetContent();
|
||||
frameContent->GetAttr(kNameSpaceID_None, aAttribute, attrValue);
|
||||
|
||||
// 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 is as if we draw the line on behalf of the previous cell.
|
||||
// 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 &&
|
||||
!rowContent->HasAttr(kNameSpaceID_None, nsGkAtoms::_moz_math_rowline_)) {
|
||||
attr = GetValueAt(aTableFrame, RowLinesProperty(),
|
||||
nsGkAtoms::rowlines_, rowIndex-1);
|
||||
if (attr) {
|
||||
// set our special _moz attribute on the row without notifying a reflow
|
||||
rowContent->SetAttr(kNameSpaceID_None, nsGkAtoms::_moz_math_rowline_,
|
||||
nsDependentString(attr), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!attrValue.IsEmpty()) {
|
||||
nsTArray<int8_t>* valueList =
|
||||
ExtractStyleValues(attrValue, aAttribute, aAllowMultiValues);
|
||||
|
||||
// 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)
|
||||
{
|
||||
DEBUG_VERIFY_THAT_FRAME_IS_TABLE(aTableFrame);
|
||||
DEBUG_VERIFY_THAT_FRAME_IS(aRowFrame, TABLE_ROW);
|
||||
DEBUG_VERIFY_THAT_FRAME_IS(aCellFrame, TABLE_CELL);
|
||||
int32_t rowIndex, colIndex;
|
||||
((nsTableCellFrame*)aCellFrame)->GetCellIndexes(rowIndex, colIndex);
|
||||
nsIContent* cellContent = aCellFrame->GetContent();
|
||||
PRUnichar* attr;
|
||||
|
||||
// see if the columnalign attribute is not already set
|
||||
if (!cellContent->HasAttr(kNameSpaceID_None, nsGkAtoms::columnalign_) &&
|
||||
!cellContent->HasAttr(kNameSpaceID_None,
|
||||
nsGkAtoms::_moz_math_columnalign_)) {
|
||||
// see if the columnalign attribute was specified on the row
|
||||
attr = GetValueAt(aRowFrame, ColumnAlignProperty(),
|
||||
nsGkAtoms::columnalign_, colIndex);
|
||||
if (!attr) {
|
||||
// see if the columnalign attribute was specified on the table
|
||||
attr = GetValueAt(aTableFrame, ColumnAlignProperty(),
|
||||
nsGkAtoms::columnalign_, colIndex);
|
||||
}
|
||||
if (attr) {
|
||||
// set our special _moz attribute without notifying a reflow
|
||||
cellContent->SetAttr(kNameSpaceID_None, nsGkAtoms::_moz_math_columnalign_,
|
||||
nsDependentString(attr), 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 is 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 &&
|
||||
!cellContent->HasAttr(kNameSpaceID_None,
|
||||
nsGkAtoms::_moz_math_columnline_)) {
|
||||
attr = GetValueAt(aTableFrame, ColumnLinesProperty(),
|
||||
nsGkAtoms::columnlines_, colIndex-1);
|
||||
if (attr) {
|
||||
// set our special _moz attribute without notifying a reflow
|
||||
cellContent->SetAttr(kNameSpaceID_None, nsGkAtoms::_moz_math_columnline_,
|
||||
nsDependentString(attr), false);
|
||||
// If valueList is null, that indicates a problem with the attribute value.
|
||||
// Only set properties on a valid attribute value.
|
||||
if (valueList) {
|
||||
// The code reading the property assumes that this list is nonempty.
|
||||
NS_ASSERTION(valueList->Length() >= 1, "valueList should not be empty!");
|
||||
FrameProperties props = aFrame->Properties();
|
||||
props.Set(AttributeToProperty(aAttribute), valueList);
|
||||
} else {
|
||||
ReportParseError(aFrame, aAttribute->GetUTF16String(), attrValue.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -243,6 +288,14 @@ MapColAttributesIntoCSS(nsIFrame* aTableFrame,
|
||||
static void
|
||||
MapAllAttributesIntoCSS(nsIFrame* aTableFrame)
|
||||
{
|
||||
// Map mtable rowalign & rowlines.
|
||||
ParseFrameAttribute(aTableFrame, nsGkAtoms::rowalign_, true);
|
||||
ParseFrameAttribute(aTableFrame, nsGkAtoms::rowlines_, true);
|
||||
|
||||
// Map mtable columnalign & columnlines.
|
||||
ParseFrameAttribute(aTableFrame, nsGkAtoms::columnalign_, true);
|
||||
ParseFrameAttribute(aTableFrame, nsGkAtoms::columnlines_, true);
|
||||
|
||||
// mtable is simple and only has one (pseudo) row-group
|
||||
nsIFrame* rgFrame = aTableFrame->GetFirstPrincipalChild();
|
||||
if (!rgFrame || rgFrame->GetType() != nsGkAtoms::tableRowGroupFrame)
|
||||
@ -252,12 +305,19 @@ MapAllAttributesIntoCSS(nsIFrame* aTableFrame)
|
||||
for ( ; rowFrame; rowFrame = rowFrame->GetNextSibling()) {
|
||||
DEBUG_VERIFY_THAT_FRAME_IS(rowFrame, TABLE_ROW);
|
||||
if (rowFrame->GetType() == nsGkAtoms::tableRowFrame) {
|
||||
MapRowAttributesIntoCSS(aTableFrame, rowFrame);
|
||||
// Map row rowalign.
|
||||
ParseFrameAttribute(rowFrame, nsGkAtoms::rowalign_, false);
|
||||
// Map row columnalign.
|
||||
ParseFrameAttribute(rowFrame, nsGkAtoms::columnalign_, true);
|
||||
|
||||
nsIFrame* cellFrame = rowFrame->GetFirstPrincipalChild();
|
||||
for ( ; cellFrame; cellFrame = cellFrame->GetNextSibling()) {
|
||||
DEBUG_VERIFY_THAT_FRAME_IS(cellFrame, TABLE_CELL);
|
||||
if (IS_TABLE_CELL(cellFrame->GetType())) {
|
||||
MapColAttributesIntoCSS(aTableFrame, rowFrame, cellFrame);
|
||||
// Map cell rowalign.
|
||||
ParseFrameAttribute(cellFrame, nsGkAtoms::rowalign_, false);
|
||||
// Map row columnalign.
|
||||
ParseFrameAttribute(cellFrame, nsGkAtoms::columnalign_, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -457,48 +517,27 @@ nsMathMLmtableOuterFrame::AttributeChanged(int32_t aNameSpaceID,
|
||||
}
|
||||
|
||||
// ...and the other attributes affect rows or columns in one way or another
|
||||
nsIAtom* MOZrowAtom = nullptr;
|
||||
nsIAtom* MOZcolAtom = nullptr;
|
||||
if (aAttribute == nsGkAtoms::rowalign_)
|
||||
MOZrowAtom = nsGkAtoms::_moz_math_rowalign_;
|
||||
else if (aAttribute == nsGkAtoms::rowlines_)
|
||||
MOZrowAtom = nsGkAtoms::_moz_math_rowline_;
|
||||
else if (aAttribute == nsGkAtoms::columnalign_)
|
||||
MOZcolAtom = nsGkAtoms::_moz_math_columnalign_;
|
||||
else if (aAttribute == nsGkAtoms::columnlines_)
|
||||
MOZcolAtom = nsGkAtoms::_moz_math_columnline_;
|
||||
|
||||
if (!MOZrowAtom && !MOZcolAtom)
|
||||
// Ignore attributes that do not affect layout.
|
||||
if (aAttribute != nsGkAtoms::rowalign_ &&
|
||||
aAttribute != nsGkAtoms::rowlines_ &&
|
||||
aAttribute != nsGkAtoms::columnalign_ &&
|
||||
aAttribute != nsGkAtoms::columnlines_) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsPresContext* presContext = tableFrame->PresContext();
|
||||
// clear any cached nsValueList for this table
|
||||
|
||||
// clear any cached property list for this table
|
||||
presContext->PropertyTable()->
|
||||
Delete(tableFrame, AttributeToProperty(aAttribute));
|
||||
|
||||
// unset any _moz attribute that we may have set earlier, and re-sync
|
||||
nsIFrame* rowFrame = rgFrame->GetFirstPrincipalChild();
|
||||
for ( ; rowFrame; rowFrame = rowFrame->GetNextSibling()) {
|
||||
if (rowFrame->GetType() == nsGkAtoms::tableRowFrame) {
|
||||
if (MOZrowAtom) { // let rows do the work
|
||||
rowFrame->GetContent()->UnsetAttr(kNameSpaceID_None, MOZrowAtom, false);
|
||||
MapRowAttributesIntoCSS(tableFrame, rowFrame);
|
||||
} else { // let cells do the work
|
||||
nsIFrame* cellFrame = rowFrame->GetFirstPrincipalChild();
|
||||
for ( ; cellFrame; cellFrame = cellFrame->GetNextSibling()) {
|
||||
if (IS_TABLE_CELL(cellFrame->GetType())) {
|
||||
cellFrame->GetContent()->UnsetAttr(kNameSpaceID_None, MOZcolAtom, false);
|
||||
MapColAttributesIntoCSS(tableFrame, rowFrame, cellFrame);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Reparse the new attribute on the table.
|
||||
ParseFrameAttribute(tableFrame, aAttribute, true);
|
||||
|
||||
// Explicitly request a re-resolve and reflow in our subtree to pick up any changes
|
||||
presContext->RestyleManager()->
|
||||
PostRestyleEvent(mContent->AsElement(), eRestyle_Subtree,
|
||||
nsChangeHint_AllReflowHints);
|
||||
// Explicitly request a reflow in our subtree to pick up any changes
|
||||
presContext->PresShell()->
|
||||
FrameNeedsReflow(this, nsIPresShell::eStyleChange, NS_FRAME_IS_DIRTY);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
@ -704,43 +743,26 @@ nsMathMLmtrFrame::AttributeChanged(int32_t aNameSpaceID,
|
||||
{
|
||||
// Attributes specific to <mtr>:
|
||||
// groupalign : Not yet supported.
|
||||
// rowalign : Fully specified in mathml.css, and so HasAttributeDependentStyle() will
|
||||
// pick it up and RestyleManager will issue a PostRestyleEvent().
|
||||
// columnalign : Need an explicit re-style call.
|
||||
|
||||
if (aAttribute == nsGkAtoms::rowalign_) {
|
||||
// unset any _moz attribute that we may have set earlier, and re-sync
|
||||
mContent->UnsetAttr(kNameSpaceID_None, nsGkAtoms::_moz_math_rowalign_,
|
||||
false);
|
||||
MapRowAttributesIntoCSS(nsTableFrame::GetTableFrame(this), this);
|
||||
// That's all - see comment above.
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (aAttribute != nsGkAtoms::columnalign_)
|
||||
return NS_OK;
|
||||
// rowalign : Here
|
||||
// columnalign : Here
|
||||
|
||||
nsPresContext* presContext = PresContext();
|
||||
// Clear any cached columnalign's nsValueList for this row
|
||||
presContext->PropertyTable()->Delete(this, AttributeToProperty(aAttribute));
|
||||
|
||||
// Clear any internal _moz attribute that we may have set earlier
|
||||
// in our cells and re-sync their columnalign attribute
|
||||
nsTableFrame* tableFrame = nsTableFrame::GetTableFrame(this);
|
||||
nsIFrame* cellFrame = GetFirstPrincipalChild();
|
||||
for ( ; cellFrame; cellFrame = cellFrame->GetNextSibling()) {
|
||||
if (IS_TABLE_CELL(cellFrame->GetType())) {
|
||||
cellFrame->GetContent()->
|
||||
UnsetAttr(kNameSpaceID_None, nsGkAtoms::_moz_math_columnalign_,
|
||||
false);
|
||||
MapColAttributesIntoCSS(tableFrame, this, cellFrame);
|
||||
}
|
||||
if (aAttribute != nsGkAtoms::rowalign_ &&
|
||||
aAttribute != nsGkAtoms::columnalign_) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Explicitly request a re-resolve and reflow in our subtree to pick up any changes
|
||||
presContext->RestyleManager()->
|
||||
PostRestyleEvent(mContent->AsElement(), eRestyle_Subtree,
|
||||
nsChangeHint_AllReflowHints);
|
||||
presContext->PropertyTable()->Delete(this, AttributeToProperty(aAttribute));
|
||||
|
||||
bool allowMultiValues = (aAttribute == nsGkAtoms::columnalign_);
|
||||
|
||||
// Reparse the new attribute.
|
||||
ParseFrameAttribute(this, aAttribute, allowMultiValues);
|
||||
|
||||
// Explicitly request a reflow in our subtree to pick up any changes
|
||||
presContext->PresShell()->
|
||||
FrameNeedsReflow(this, nsIPresShell::eStyleChange, NS_FRAME_IS_DIRTY);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
@ -806,16 +828,19 @@ nsMathMLmtdFrame::AttributeChanged(int32_t aNameSpaceID,
|
||||
{
|
||||
// Attributes specific to <mtd>:
|
||||
// groupalign : Not yet supported
|
||||
// rowalign : in mathml.css
|
||||
// rowalign : here
|
||||
// columnalign : here
|
||||
// rowspan : here
|
||||
// columnspan : here
|
||||
|
||||
if (aAttribute == nsGkAtoms::columnalign_) {
|
||||
// unset any _moz attribute that we may have set earlier, and re-sync
|
||||
mContent->UnsetAttr(kNameSpaceID_None, nsGkAtoms::_moz_math_columnalign_,
|
||||
false);
|
||||
MapColAttributesIntoCSS(nsTableFrame::GetTableFrame(this), mParent, this);
|
||||
if (aAttribute == nsGkAtoms::rowalign_ ||
|
||||
aAttribute == nsGkAtoms::columnalign_) {
|
||||
|
||||
nsPresContext* presContext = PresContext();
|
||||
presContext->PropertyTable()->Delete(this, AttributeToProperty(aAttribute));
|
||||
|
||||
// Reparse the attribute.
|
||||
ParseFrameAttribute(this, aAttribute, false);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -830,6 +855,38 @@ nsMathMLmtdFrame::AttributeChanged(int32_t aNameSpaceID,
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
uint8_t
|
||||
nsMathMLmtdFrame::GetVerticalAlign() const
|
||||
{
|
||||
// Set the default alignment in case no alignment was specified
|
||||
uint8_t alignment = nsTableCellFrame::GetVerticalAlign();
|
||||
|
||||
nsTArray<int8_t>* alignmentList = FindCellProperty(this, RowAlignProperty());
|
||||
|
||||
if (alignmentList) {
|
||||
int32_t rowIndex;
|
||||
GetRowIndex(rowIndex);
|
||||
|
||||
// If the row number is greater than the number of provided rowalign values,
|
||||
// we simply repeat the last value.
|
||||
if (rowIndex < (int32_t)alignmentList->Length())
|
||||
alignment = alignmentList->ElementAt(rowIndex);
|
||||
else
|
||||
alignment = alignmentList->ElementAt(alignmentList->Length() - 1);
|
||||
}
|
||||
|
||||
return alignment;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsMathMLmtdFrame::ProcessBorders(nsTableFrame* aFrame,
|
||||
nsDisplayListBuilder* aBuilder,
|
||||
const nsDisplayListSet& aLists)
|
||||
{
|
||||
aLists.BorderBackground()->AppendNewToTop(new (aBuilder)
|
||||
nsDisplaymtdBorder(aBuilder, this));
|
||||
return NS_OK;
|
||||
}
|
||||
// --------
|
||||
// implementation of nsMathMLmtdInnerFrame
|
||||
|
||||
@ -845,8 +902,16 @@ NS_NewMathMLmtdInnerFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
||||
|
||||
NS_IMPL_FRAMEARENA_HELPERS(nsMathMLmtdInnerFrame)
|
||||
|
||||
nsMathMLmtdInnerFrame::nsMathMLmtdInnerFrame(nsStyleContext* aContext)
|
||||
: nsBlockFrame(aContext)
|
||||
{
|
||||
// Make a copy of the parent nsStyleText for later modificaiton.
|
||||
mUniqueStyleText = new (PresContext()) nsStyleText(*StyleText());
|
||||
}
|
||||
|
||||
nsMathMLmtdInnerFrame::~nsMathMLmtdInnerFrame()
|
||||
{
|
||||
mUniqueStyleText->Destroy(PresContext());
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
@ -862,3 +927,37 @@ nsMathMLmtdInnerFrame::Reflow(nsPresContext* aPresContext,
|
||||
// ...
|
||||
return rv;
|
||||
}
|
||||
|
||||
const
|
||||
nsStyleText* nsMathMLmtdInnerFrame::StyleTextForLineLayout()
|
||||
{
|
||||
// Set the default alignment in case nothing was specified
|
||||
uint8_t alignment = StyleText()->mTextAlign;
|
||||
|
||||
nsTArray<int8_t>* alignmentList =
|
||||
FindCellProperty(this, ColumnAlignProperty());
|
||||
|
||||
if (alignmentList) {
|
||||
nsMathMLmtdFrame* cellFrame = (nsMathMLmtdFrame*)GetParent();
|
||||
int32_t columnIndex;
|
||||
cellFrame->GetColIndex(columnIndex);
|
||||
|
||||
// If the column number is greater than the number of provided columalign
|
||||
// values, we simply repeat the last value.
|
||||
if (columnIndex < (int32_t)alignmentList->Length())
|
||||
alignment = alignmentList->ElementAt(columnIndex);
|
||||
else
|
||||
alignment = alignmentList->ElementAt(alignmentList->Length() - 1);
|
||||
}
|
||||
|
||||
mUniqueStyleText->mTextAlign = alignment;
|
||||
return mUniqueStyleText;
|
||||
}
|
||||
|
||||
/* virtual */ void
|
||||
nsMathMLmtdInnerFrame::DidSetStyleContext(nsStyleContext* aOldStyleContext)
|
||||
{
|
||||
nsBlockFrame::DidSetStyleContext(aOldStyleContext);
|
||||
mUniqueStyleText->Destroy(PresContext());
|
||||
mUniqueStyleText = new (PresContext()) nsStyleText(*StyleText());
|
||||
}
|
||||
|
@ -209,6 +209,11 @@ public:
|
||||
nsIAtom* aAttribute,
|
||||
int32_t aModType) MOZ_OVERRIDE;
|
||||
|
||||
virtual uint8_t GetVerticalAlign() const;
|
||||
virtual nsresult ProcessBorders(nsTableFrame* aFrame,
|
||||
nsDisplayListBuilder* aBuilder,
|
||||
const nsDisplayListSet& aLists);
|
||||
|
||||
virtual int32_t GetRowSpan() MOZ_OVERRIDE;
|
||||
virtual int32_t GetColSpan() MOZ_OVERRIDE;
|
||||
virtual bool IsFrameOfType(uint32_t aFlags) const MOZ_OVERRIDE
|
||||
@ -256,9 +261,15 @@ public:
|
||||
~(nsIFrame::eMathML | nsIFrame::eExcludesIgnorableWhitespace));
|
||||
}
|
||||
|
||||
virtual const nsStyleText* StyleTextForLineLayout();
|
||||
virtual void DidSetStyleContext(nsStyleContext* aOldStyleContext) MOZ_OVERRIDE;
|
||||
|
||||
protected:
|
||||
nsMathMLmtdInnerFrame(nsStyleContext* aContext) : nsBlockFrame(aContext) {}
|
||||
nsMathMLmtdInnerFrame(nsStyleContext* aContext);
|
||||
virtual ~nsMathMLmtdInnerFrame();
|
||||
|
||||
nsStyleText* mUniqueStyleText;
|
||||
|
||||
}; // class nsMathMLmtdInnerFrame
|
||||
|
||||
#endif /* nsMathMLmtableFrame_h___ */
|
||||
|
@ -353,6 +353,24 @@ nsTableCellFrame::PaintCellBackground(nsRenderingContext& aRenderingContext,
|
||||
PaintBackground(aRenderingContext, aDirtyRect, aPt, aFlags);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsTableCellFrame::ProcessBorders(nsTableFrame* aFrame,
|
||||
nsDisplayListBuilder* aBuilder,
|
||||
const nsDisplayListSet& aLists)
|
||||
{
|
||||
const nsStyleBorder* borderStyle = StyleBorder();
|
||||
if (aFrame->IsBorderCollapse() || !borderStyle->HasBorder())
|
||||
return NS_OK;
|
||||
|
||||
if (!GetContentEmpty() ||
|
||||
StyleTableBorder()->mEmptyCells == NS_STYLE_TABLE_EMPTY_CELLS_SHOW) {
|
||||
aLists.BorderBackground()->AppendNewToTop(new (aBuilder)
|
||||
nsDisplayBorder(aBuilder, this));
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
class nsDisplayTableCellBackground : public nsDisplayTableItem {
|
||||
public:
|
||||
nsDisplayTableCellBackground(nsDisplayListBuilder* aBuilder,
|
||||
@ -486,11 +504,7 @@ nsTableCellFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
||||
}
|
||||
|
||||
// display borders if we need to
|
||||
if (!tableFrame->IsBorderCollapse() && borderStyle->HasBorder() &&
|
||||
emptyCellStyle == NS_STYLE_TABLE_EMPTY_CELLS_SHOW) {
|
||||
aLists.BorderBackground()->AppendNewToTop(new (aBuilder)
|
||||
nsDisplayBorder(aBuilder, this));
|
||||
}
|
||||
ProcessBorders(tableFrame, aBuilder, aLists);
|
||||
|
||||
// and display the selection border if we need to
|
||||
if (IsSelected()) {
|
||||
|
@ -101,6 +101,11 @@ public:
|
||||
const nsRect& aDirtyRect, nsPoint aPt,
|
||||
uint32_t aFlags);
|
||||
|
||||
|
||||
virtual nsresult ProcessBorders(nsTableFrame* aFrame,
|
||||
nsDisplayListBuilder* aBuilder,
|
||||
const nsDisplayListSet& aLists);
|
||||
|
||||
virtual nscoord GetMinWidth(nsRenderingContext *aRenderingContext) MOZ_OVERRIDE;
|
||||
virtual nscoord GetPrefWidth(nsRenderingContext *aRenderingContext) MOZ_OVERRIDE;
|
||||
virtual IntrinsicWidthOffsetData
|
||||
@ -129,7 +134,7 @@ public:
|
||||
* table cell, which means the result is always
|
||||
* NS_STYLE_VERTICAL_ALIGN_{TOP,MIDDLE,BOTTOM,BASELINE}.
|
||||
*/
|
||||
uint8_t GetVerticalAlign() const;
|
||||
virtual uint8_t GetVerticalAlign() const;
|
||||
|
||||
bool HasVerticalAlignBaseline() const {
|
||||
return GetVerticalAlign() == NS_STYLE_VERTICAL_ALIGN_BASELINE;
|
||||
|
Loading…
Reference in New Issue
Block a user