Bug 749044 - Selection attribute on maction is now considered by default. Checking for a rendering error in maction has been added. r=karlt

This commit is contained in:
Andrii Zui 2012-06-12 20:05:58 -04:00
Родитель 1243a80775
Коммит 7de01144b5
2 изменённых файлов: 53 добавлений и 22 удалений

Просмотреть файл

@ -32,10 +32,20 @@
// <maction> -- bind actions to a subexpression - implementation // <maction> -- bind actions to a subexpression - implementation
// //
#define NS_MATHML_ACTION_TYPE_NONE 0 enum nsMactionActionTypes {
#define NS_MATHML_ACTION_TYPE_TOGGLE 1 NS_MATHML_ACTION_TYPE_CLASS_ERROR = 0x10,
#define NS_MATHML_ACTION_TYPE_STATUSLINE 2 NS_MATHML_ACTION_TYPE_CLASS_USE_SELECTION = 0x20,
#define NS_MATHML_ACTION_TYPE_TOOLTIP 3 // unsupported NS_MATHML_ACTION_TYPE_CLASS_IGNORE_SELECTION = 0x40,
NS_MATHML_ACTION_TYPE_CLASS_BITMASK = 0xF0,
NS_MATHML_ACTION_TYPE_NONE = NS_MATHML_ACTION_TYPE_CLASS_ERROR|0x01,
NS_MATHML_ACTION_TYPE_TOGGLE = NS_MATHML_ACTION_TYPE_CLASS_USE_SELECTION|0x01,
NS_MATHML_ACTION_TYPE_UNKNOWN = NS_MATHML_ACTION_TYPE_CLASS_USE_SELECTION|0x02,
NS_MATHML_ACTION_TYPE_STATUSLINE = NS_MATHML_ACTION_TYPE_CLASS_IGNORE_SELECTION|0x01,
NS_MATHML_ACTION_TYPE_TOOLTIP = NS_MATHML_ACTION_TYPE_CLASS_IGNORE_SELECTION|0x02
};
// helper function to parse actiontype attribute // helper function to parse actiontype attribute
@ -44,8 +54,10 @@ GetActionType(nsIContent* aContent)
{ {
nsAutoString value; nsAutoString value;
if (aContent) if (aContent) {
aContent->GetAttr(kNameSpaceID_None, nsGkAtoms::actiontype_, value); if (!aContent->GetAttr(kNameSpaceID_None, nsGkAtoms::actiontype_, value))
return NS_MATHML_ACTION_TYPE_NONE;
}
if (value.EqualsLiteral("toggle")) if (value.EqualsLiteral("toggle"))
return NS_MATHML_ACTION_TYPE_TOGGLE; return NS_MATHML_ACTION_TYPE_TOGGLE;
@ -54,7 +66,7 @@ GetActionType(nsIContent* aContent)
if (value.EqualsLiteral("tooltip")) if (value.EqualsLiteral("tooltip"))
return NS_MATHML_ACTION_TYPE_TOOLTIP; return NS_MATHML_ACTION_TYPE_TOOLTIP;
return NS_MATHML_ACTION_TYPE_NONE; return NS_MATHML_ACTION_TYPE_UNKNOWN;
} }
nsIFrame* nsIFrame*
@ -135,8 +147,18 @@ nsMathMLmactionFrame::GetSelectedFrame()
nsAutoString value; nsAutoString value;
PRInt32 selection; PRInt32 selection;
// selection is applied only to toggle, return first child otherwise if ((mActionType & NS_MATHML_ACTION_TYPE_CLASS_BITMASK) ==
if (NS_MATHML_ACTION_TYPE_TOGGLE != mActionType) { NS_MATHML_ACTION_TYPE_CLASS_ERROR) {
// Mark mSelection as an error.
mSelection = -1;
mSelectedFrame = nsnull;
return mSelectedFrame;
}
// Selection is not applied to tooltip and statusline.
// Thereby return the first child.
if ((mActionType & NS_MATHML_ACTION_TYPE_CLASS_BITMASK) ==
NS_MATHML_ACTION_TYPE_CLASS_IGNORE_SELECTION) {
// We don't touch mChildCount here. It's incorrect to assign it 1, // We don't touch mChildCount here. It's incorrect to assign it 1,
// and it's inefficient to count the children. It's fine to leave // and it's inefficient to count the children. It's fine to leave
// it be equal -1 because it's not used with other actiontypes. // it be equal -1 because it's not used with other actiontypes.
@ -157,8 +179,8 @@ nsMathMLmactionFrame::GetSelectedFrame()
if (-1 != mChildCount) { // we have been in this function before... if (-1 != mChildCount) { // we have been in this function before...
// cater for invalid user-supplied selection // cater for invalid user-supplied selection
if (selection > mChildCount || selection < 1) if (selection > mChildCount || selection < 1)
selection = 1; selection = -1;
// quick return if it is identical with our cache // quick return if it is identical with our cache
if (selection == mSelection) if (selection == mSelection)
return mSelectedFrame; return mSelectedFrame;
@ -176,8 +198,8 @@ nsMathMLmactionFrame::GetSelectedFrame()
childFrame = childFrame->GetNextSibling(); childFrame = childFrame->GetNextSibling();
} }
// cater for invalid user-supplied selection // cater for invalid user-supplied selection
if (selection > count || selection < 1) if (selection > count || selection < 1)
selection = 1; selection = -1;
mChildCount = count; mChildCount = count;
mSelection = selection; mSelection = selection;
@ -223,16 +245,14 @@ nsMathMLmactionFrame::AttributeChanged(PRInt32 aNameSpaceID,
PRInt32 oldActionType = mActionType; PRInt32 oldActionType = mActionType;
mActionType = GetActionType(mContent); mActionType = GetActionType(mContent);
// We have to initiate a reflow only when changing actiontype // Initiate a reflow when actiontype classes are different.
// from toggle or to toggle. if ((oldActionType & NS_MATHML_ACTION_TYPE_CLASS_BITMASK) !=
if (oldActionType == NS_MATHML_ACTION_TYPE_TOGGLE || (mActionType & NS_MATHML_ACTION_TYPE_CLASS_BITMASK)) {
mActionType == NS_MATHML_ACTION_TYPE_TOGGLE) {
needsReflow = true; needsReflow = true;
} }
} else if (aAttribute == nsGkAtoms::selection_) { } else if (aAttribute == nsGkAtoms::selection_) {
// When the selection attribute is changed we have to initiate a reflow if ((mActionType & NS_MATHML_ACTION_TYPE_CLASS_BITMASK) ==
// only when actiontype is toggle. NS_MATHML_ACTION_TYPE_CLASS_USE_SELECTION) {
if (NS_MATHML_ACTION_TYPE_TOGGLE == mActionType) {
needsReflow = true; needsReflow = true;
} }
} else { } else {
@ -256,6 +276,13 @@ nsMathMLmactionFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
const nsRect& aDirtyRect, const nsRect& aDirtyRect,
const nsDisplayListSet& aLists) const nsDisplayListSet& aLists)
{ {
// Report an error if something wrong was found in this frame.
// We can't call nsDisplayMathMLError from here,
// so ask nsMathMLContainerFrame to do the work for us.
if (NS_MATHML_HAS_ERROR(mPresentationData.flags)) {
return nsMathMLContainerFrame::BuildDisplayList(aBuilder, aDirtyRect, aLists);
}
nsresult rv = DisplayBorderBackgroundOutline(aBuilder, aLists); nsresult rv = DisplayBorderBackgroundOutline(aBuilder, aLists);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
@ -309,10 +336,15 @@ nsMathMLmactionFrame::Place(nsRenderingContext& aRenderingContext,
bool aPlaceOrigin, bool aPlaceOrigin,
nsHTMLReflowMetrics& aDesiredSize) nsHTMLReflowMetrics& aDesiredSize)
{ {
nsIFrame* childFrame = GetSelectedFrame();
if (mSelection == -1) {
return ReflowError(aRenderingContext, aDesiredSize);
}
aDesiredSize.width = aDesiredSize.height = 0; aDesiredSize.width = aDesiredSize.height = 0;
aDesiredSize.ascent = 0; aDesiredSize.ascent = 0;
mBoundingMetrics = nsBoundingMetrics(); mBoundingMetrics = nsBoundingMetrics();
nsIFrame* childFrame = GetSelectedFrame();
if (childFrame) { if (childFrame) {
GetReflowAndBoundingMetricsFor(childFrame, aDesiredSize, mBoundingMetrics); GetReflowAndBoundingMetricsFor(childFrame, aDesiredSize, mBoundingMetrics);
if (aPlaceOrigin) { if (aPlaceOrigin) {

Просмотреть файл

@ -81,7 +81,6 @@ private:
PRInt32 mChildCount; PRInt32 mChildCount;
PRInt32 mSelection; PRInt32 mSelection;
nsIFrame* mSelectedFrame; nsIFrame* mSelectedFrame;
nsString mRestyle;
nsCOMPtr<MouseListener> mListener; nsCOMPtr<MouseListener> mListener;
// helper to return the frame for the attribute selection="number" // helper to return the frame for the attribute selection="number"