diff --git a/layout/html/base/src/nsHTMLContainer.cpp b/layout/html/base/src/nsHTMLContainer.cpp index 5c331d10c658..71f35c5f15a5 100644 --- a/layout/html/base/src/nsHTMLContainer.cpp +++ b/layout/html/base/src/nsHTMLContainer.cpp @@ -279,218 +279,11 @@ nsHTMLContainer::CreateFrame(nsIPresContext* aPresContext, //---------------------------------------------------------------------- -static nsHTMLTagContent::EnumTable kListTypeTable[] = { - { "none", NS_STYLE_LIST_STYLE_NONE }, - { "disc", NS_STYLE_LIST_STYLE_DISC }, - { "circle", NS_STYLE_LIST_STYLE_CIRCLE }, - { "round", NS_STYLE_LIST_STYLE_CIRCLE }, - { "square", NS_STYLE_LIST_STYLE_SQUARE }, - { "decimal", NS_STYLE_LIST_STYLE_DECIMAL }, - { "lower-roman", NS_STYLE_LIST_STYLE_LOWER_ROMAN }, - { "upper-roman", NS_STYLE_LIST_STYLE_UPPER_ROMAN }, - { "lower-alpha", NS_STYLE_LIST_STYLE_LOWER_ALPHA }, - { "upper-alpha", NS_STYLE_LIST_STYLE_UPPER_ALPHA }, - { "A", NS_STYLE_LIST_STYLE_UPPER_ALPHA }, - { "a", NS_STYLE_LIST_STYLE_LOWER_ALPHA }, - { "I", NS_STYLE_LIST_STYLE_UPPER_ROMAN }, - { "i", NS_STYLE_LIST_STYLE_LOWER_ROMAN }, - { 0 } -}; - -static nsHTMLTagContent::EnumTable kListItemTypeTable[] = { - { "circle", NS_STYLE_LIST_STYLE_CIRCLE }, - { "round", NS_STYLE_LIST_STYLE_CIRCLE }, - { "square", NS_STYLE_LIST_STYLE_SQUARE }, - { "A", NS_STYLE_LIST_STYLE_UPPER_ALPHA }, - { "a", NS_STYLE_LIST_STYLE_LOWER_ALPHA }, - { "I", NS_STYLE_LIST_STYLE_UPPER_ROMAN }, - { "i", NS_STYLE_LIST_STYLE_LOWER_ROMAN }, - { 0 } -}; - -static nsHTMLTagContent::EnumTable kDirTable[] = { - { "ltr", NS_STYLE_DIRECTION_LTR }, - { "rtl", NS_STYLE_DIRECTION_RTL }, - { 0 } -}; - NS_IMETHODIMP nsHTMLContainer::SetAttribute(nsIAtom* aAttribute, const nsString& aValue, PRBool aNotify) { - // Special handling code for various html container attributes; note - // that if an attribute doesn't require special handling then we - // fall through and use the default base class implementation. - nsHTMLValue val; - - // Check for attributes common to most html containers - if (aAttribute == nsHTMLAtoms::dir) { - if (ParseEnumValue(aValue, kDirTable, val)) { - return nsHTMLTagContent::SetAttribute(aAttribute, val, aNotify); - } - } - else if (aAttribute == nsHTMLAtoms::lang) { - return nsHTMLTagContent::SetAttribute(aAttribute, aValue, aNotify); - } - - if (mTag == nsHTMLAtoms::p) { - if ((aAttribute == nsHTMLAtoms::align) && - ParseDivAlignParam(aValue, val)) { - return nsHTMLTagContent::SetAttribute(aAttribute, val, aNotify); - } - } - else if (mTag == nsHTMLAtoms::a) { - if (aAttribute == nsHTMLAtoms::href) { - nsAutoString href(aValue); - href.StripWhitespace(); - return nsHTMLTagContent::SetAttribute(aAttribute, href, aNotify); - } - if (aAttribute == nsHTMLAtoms::suppress) { - if (aValue.EqualsIgnoreCase("true")) { - nsHTMLValue val; - val.SetEmptyValue(); - return nsHTMLTagContent::SetAttribute(aAttribute, val, aNotify); - } - } - // XXX PRE? - } - else if (mTag == nsHTMLAtoms::font) { - if ((aAttribute == nsHTMLAtoms::size) || - (aAttribute == nsHTMLAtoms::pointSize) || - (aAttribute == nsHTMLAtoms::fontWeight)) { - nsAutoString tmp(aValue); - PRInt32 ec, v = tmp.ToInteger(&ec); - tmp.CompressWhitespace(PR_TRUE, PR_FALSE); - PRUnichar ch = tmp.First(); - val.SetIntValue(v, ((ch == '+') || (ch == '-')) ? - eHTMLUnit_Integer : eHTMLUnit_Enumerated); - return nsHTMLTagContent::SetAttribute(aAttribute, val, aNotify); - } - if (aAttribute == nsHTMLAtoms::color) { - ParseColor(aValue, val); - return nsHTMLTagContent::SetAttribute(aAttribute, val, aNotify); - } - } - else if ((mTag == nsHTMLAtoms::div) || (mTag == nsHTMLAtoms::multicol)) { - if ((mTag == nsHTMLAtoms::div) && (aAttribute == nsHTMLAtoms::align) && - ParseDivAlignParam(aValue, val)) { - return nsHTMLTagContent::SetAttribute(aAttribute, val, aNotify); - } - if (aAttribute == nsHTMLAtoms::cols) { - ParseValue(aValue, 0, val, eHTMLUnit_Integer); - return nsHTMLTagContent::SetAttribute(aAttribute, val, aNotify); - } - - // Note: These attributes only apply when cols > 1 - if (aAttribute == nsHTMLAtoms::gutter) { - ParseValue(aValue, 1, val, eHTMLUnit_Pixel); - return nsHTMLTagContent::SetAttribute(aAttribute, val, aNotify); - } - if (aAttribute == nsHTMLAtoms::width) { - ParseValueOrPercent(aValue, val, eHTMLUnit_Pixel); - return nsHTMLTagContent::SetAttribute(aAttribute, val, aNotify); - } - } - else if ((mTag == nsHTMLAtoms::h1) || (mTag == nsHTMLAtoms::h2) || - (mTag == nsHTMLAtoms::h3) || (mTag == nsHTMLAtoms::h4) || - (mTag == nsHTMLAtoms::h5) || (mTag == nsHTMLAtoms::h6)) { - if ((aAttribute == nsHTMLAtoms::align) && - ParseDivAlignParam(aValue, val)) { - return nsHTMLTagContent::SetAttribute(aAttribute, val, aNotify); - } - } - else if (mTag == nsHTMLAtoms::pre) { - if ((aAttribute == nsHTMLAtoms::wrap) || - (aAttribute == nsHTMLAtoms::variable)) { - val.SetEmptyValue(); - return nsHTMLTagContent::SetAttribute(aAttribute, val, aNotify); - } - if (aAttribute == nsHTMLAtoms::cols) { - ParseValue(aValue, 0, val, eHTMLUnit_Integer); - return nsHTMLTagContent::SetAttribute(aAttribute, val, aNotify); - } - if (aAttribute == nsHTMLAtoms::tabstop) { - PRInt32 ec, tabstop = aValue.ToInteger(&ec); - if (tabstop <= 0) { - tabstop = 8; - } - val.SetIntValue(tabstop, eHTMLUnit_Integer); - return nsHTMLTagContent::SetAttribute(aAttribute, val, aNotify); - } - } - else if (mTag == nsHTMLAtoms::li) { - if (aAttribute == nsHTMLAtoms::type) { - if (ParseEnumValue(aValue, kListItemTypeTable, val)) { - return nsHTMLTagContent::SetAttribute(aAttribute, val, aNotify); - } - // Illegal type values are left as is for the dom - } - if (aAttribute == nsHTMLAtoms::value) { - ParseValue(aValue, 1, val, eHTMLUnit_Integer); - return nsHTMLTagContent::SetAttribute(aAttribute, val, aNotify); - } - } - else if ((mTag == nsHTMLAtoms::ul) || (mTag == nsHTMLAtoms::ol) || - (mTag == nsHTMLAtoms::menu) || (mTag == nsHTMLAtoms::dir)) { - if (aAttribute == nsHTMLAtoms::type) { - if (!ParseEnumValue(aValue, kListTypeTable, val)) { - val.SetIntValue(NS_STYLE_LIST_STYLE_BASIC, eHTMLUnit_Enumerated); - } - return nsHTMLTagContent::SetAttribute(aAttribute, val, aNotify); - } - if (aAttribute == nsHTMLAtoms::start) { - ParseValue(aValue, 1, val, eHTMLUnit_Integer); - return nsHTMLTagContent::SetAttribute(aAttribute, val, aNotify); - } - if (aAttribute == nsHTMLAtoms::compact) { - val.SetEmptyValue(); - return nsHTMLTagContent::SetAttribute(aAttribute, val, aNotify); - } - } - else if (mTag == nsHTMLAtoms::dl) { - if (aAttribute == nsHTMLAtoms::compact) { - val.SetEmptyValue(); - return nsHTMLTagContent::SetAttribute(aAttribute, val, aNotify); - } - } - else if (mTag == nsHTMLAtoms::body) { - if (aAttribute == nsHTMLAtoms::background) { - nsAutoString href(aValue); - href.StripWhitespace(); - return nsHTMLTagContent::SetAttribute(aAttribute, href, aNotify); - } - if (aAttribute == nsHTMLAtoms::bgcolor) { - ParseColor(aValue, val); - return nsHTMLTagContent::SetAttribute(aAttribute, val, aNotify); - } - if (aAttribute == nsHTMLAtoms::text) { - ParseColor(aValue, val); - return nsHTMLTagContent::SetAttribute(aAttribute, val, aNotify); - } - if (aAttribute == nsHTMLAtoms::link) { - ParseColor(aValue, val); - return nsHTMLTagContent::SetAttribute(aAttribute, val, aNotify); - } - if (aAttribute == nsHTMLAtoms::alink) { - ParseColor(aValue, val); - return nsHTMLTagContent::SetAttribute(aAttribute, val, aNotify); - } - if (aAttribute == nsHTMLAtoms::vlink) { - ParseColor(aValue, val); - return nsHTMLTagContent::SetAttribute(aAttribute, val, aNotify); - } - if (aAttribute == nsHTMLAtoms::marginwidth) { - ParseValue(aValue, 0, val, eHTMLUnit_Pixel); - return nsHTMLTagContent::SetAttribute(aAttribute, val, aNotify); - } - if (aAttribute == nsHTMLAtoms::marginheight) { - ParseValue(aValue, 0, val, eHTMLUnit_Pixel); - return nsHTMLTagContent::SetAttribute(aAttribute, val, aNotify); - } - } - - // Use default attribute catching code return nsHTMLTagContent::SetAttribute(aAttribute, aValue, aNotify); } @@ -499,336 +292,13 @@ nsHTMLContainer::AttributeToString(nsIAtom* aAttribute, nsHTMLValue& aValue, nsString& aResult) const { - nsresult ca = NS_CONTENT_ATTR_NOT_THERE; - if (aValue.GetUnit() == eHTMLUnit_Enumerated) { - if (aAttribute == nsHTMLAtoms::align) { - DivAlignParamToString(aValue, aResult); - ca = NS_CONTENT_ATTR_HAS_VALUE; - } - else if (mTag == nsHTMLAtoms::li) { - if (aAttribute == nsHTMLAtoms::type) { - EnumValueToString(aValue, kListItemTypeTable, aResult); - ca = NS_CONTENT_ATTR_HAS_VALUE; - } - } - else if ((mTag == nsHTMLAtoms::ul) || (mTag == nsHTMLAtoms::ol) || - (mTag == nsHTMLAtoms::menu) || (mTag == nsHTMLAtoms::dir)) { - if (aAttribute == nsHTMLAtoms::type) { - EnumValueToString(aValue, kListTypeTable, aResult); - ca = NS_CONTENT_ATTR_HAS_VALUE; - } - } - else if (mTag == nsHTMLAtoms::font) { - if ((aAttribute == nsHTMLAtoms::size) || - (aAttribute == nsHTMLAtoms::pointSize) || - (aAttribute == nsHTMLAtoms::fontWeight)) { - aResult.Truncate(); - aResult.Append(aValue.GetIntValue(), 10); - ca = NS_CONTENT_ATTR_HAS_VALUE; - } - } - } - else if (aValue.GetUnit() == eHTMLUnit_Integer) { - if (mTag == nsHTMLAtoms::font) { - if ((aAttribute == nsHTMLAtoms::size) || - (aAttribute == nsHTMLAtoms::pointSize) || - (aAttribute == nsHTMLAtoms::fontWeight)) { - aResult.Truncate(); - PRInt32 value = aValue.GetIntValue(); - if (value >= 0) { - aResult.Append('+'); - } - aResult.Append(value, 10); - ca = NS_CONTENT_ATTR_HAS_VALUE; - } - } - } - else { - ca = nsHTMLTagContent::AttributeToString(aAttribute, aValue, aResult); - } - return ca; + return nsHTMLTagContent::AttributeToString(aAttribute, aValue, aResult); } NS_IMETHODIMP nsHTMLContainer::MapAttributesInto(nsIStyleContext* aContext, nsIPresContext* aPresContext) { - if (nsnull != mAttributes) { - nsHTMLValue value; - - // Check for attributes common to most html containers - GetAttribute(nsHTMLAtoms::dir, value); - if (value.GetUnit() == eHTMLUnit_Enumerated) { - nsStyleDisplay* display = (nsStyleDisplay*) - aContext->GetMutableStyleData(eStyleStruct_Display); - display->mDirection = value.GetIntValue(); - } - - if (mTag == nsHTMLAtoms::p) { - // align: enum - GetAttribute(nsHTMLAtoms::align, value); - if (value.GetUnit() == eHTMLUnit_Enumerated) { - nsStyleText* text = (nsStyleText*)aContext->GetMutableStyleData(eStyleStruct_Text); - text->mTextAlign = value.GetIntValue(); - } - } - else if (mTag == nsHTMLAtoms::a) { - // suppress: bool (absolute) - GetAttribute(nsHTMLAtoms::suppress, value); - if (value.GetUnit() == eHTMLUnit_Empty) { - // XXX set suppress - } - } - else if (mTag == nsHTMLAtoms::font) { - nsStyleFont* font = (nsStyleFont*)aContext->GetMutableStyleData(eStyleStruct_Font); - const nsStyleFont* parentFont = font; - nsIStyleContext* parentContext = aContext->GetParent(); - if (nsnull != parentContext) { - parentFont = (const nsStyleFont*)parentContext->GetStyleData(eStyleStruct_Font); - } - const nsFont& defaultFont = aPresContext->GetDefaultFont(); - const nsFont& defaultFixedFont = aPresContext->GetDefaultFixedFont(); - - // face: string list - GetAttribute(nsHTMLAtoms::face, value); - if (value.GetUnit() == eHTMLUnit_String) { - - nsIDeviceContext* dc = aPresContext->GetDeviceContext(); - if (nsnull != dc) { - nsAutoString familyList; - - value.GetStringValue(familyList); - - font->mFont.name = familyList; - nsAutoString face; - if (NS_OK == dc->FirstExistingFont(font->mFont, face)) { - if (face.EqualsIgnoreCase("monospace")) { - font->mFont = font->mFixedFont; - } - else { - font->mFixedFont.name = familyList; - } - } - else { - font->mFont.name = defaultFont.name; - font->mFixedFont.name= defaultFixedFont.name; - } - font->mFlags |= NS_STYLE_FONT_FACE_EXPLICIT; - NS_RELEASE(dc); - } - } - - // pointSize: int, enum - GetAttribute(nsHTMLAtoms::pointSize, value); - if (value.GetUnit() == eHTMLUnit_Integer) { - // XXX should probably sanitize value - font->mFont.size = parentFont->mFont.size + NSIntPointsToTwips(value.GetIntValue()); - font->mFixedFont.size = parentFont->mFixedFont.size + NSIntPointsToTwips(value.GetIntValue()); - font->mFlags |= NS_STYLE_FONT_SIZE_EXPLICIT; - } - else if (value.GetUnit() == eHTMLUnit_Enumerated) { - font->mFont.size = NSIntPointsToTwips(value.GetIntValue()); - font->mFixedFont.size = NSIntPointsToTwips(value.GetIntValue()); - font->mFlags |= NS_STYLE_FONT_SIZE_EXPLICIT; - } - else { - // size: int, enum , NOTE: this does not count as an explicit size - // also this has no effect if font is already explicit - if (0 == (font->mFlags & NS_STYLE_FONT_SIZE_EXPLICIT)) { - GetAttribute(nsHTMLAtoms::size, value); - if ((value.GetUnit() == eHTMLUnit_Integer) || (value.GetUnit() == eHTMLUnit_Enumerated)) { - PRInt32 size = value.GetIntValue(); - - if (value.GetUnit() == eHTMLUnit_Integer) { // int (+/-) - size = 3 + size; // XXX should be BASEFONT, not three - } - size = ((0 < size) ? ((size < 8) ? size : 7) : 1); - PRInt32 scaler = aPresContext->GetFontScaler(); - float scaleFactor = nsStyleUtil::GetScalingFactor(scaler); - font->mFont.size = nsStyleUtil::CalcFontPointSize(size, (PRInt32)defaultFont.size, scaleFactor); - font->mFixedFont.size = nsStyleUtil::CalcFontPointSize(size, (PRInt32)defaultFixedFont.size, scaleFactor); - } - } - } - - // fontWeight: int, enum - GetAttribute(nsHTMLAtoms::fontWeight, value); - if (value.GetUnit() == eHTMLUnit_Integer) { // +/- - PRInt32 weight = parentFont->mFont.weight + value.GetIntValue(); - font->mFont.weight = ((100 < weight) ? ((weight < 700) ? weight : 700) : 100); - font->mFixedFont.weight = ((100 < weight) ? ((weight < 700) ? weight : 700) : 100); - } - else if (value.GetUnit() == eHTMLUnit_Enumerated) { - PRInt32 weight = value.GetIntValue(); - weight = ((100 < weight) ? ((weight < 700) ? weight : 700) : 100); - font->mFont.weight = weight; - font->mFixedFont.weight = weight; - } - - // color: color - GetAttribute(nsHTMLAtoms::color, value); - if (value.GetUnit() == eHTMLUnit_Color) { - nsStyleColor* color = (nsStyleColor*)aContext->GetMutableStyleData(eStyleStruct_Color); - color->mColor = value.GetColorValue(); - } - else if (value.GetUnit() == eHTMLUnit_String) { - nsAutoString buffer; - value.GetStringValue(buffer); - char cbuf[40]; - buffer.ToCString(cbuf, sizeof(cbuf)); - - nsStyleColor* color = (nsStyleColor*)aContext->GetMutableStyleData(eStyleStruct_Color); - NS_ColorNameToRGB(cbuf, &(color->mColor)); - } - - NS_IF_RELEASE(parentContext); - } - else if ((mTag == nsHTMLAtoms::div) || (mTag == nsHTMLAtoms::multicol)) { - if (mTag == nsHTMLAtoms::div) { - // align: enum - GetAttribute(nsHTMLAtoms::align, value); - if (value.GetUnit() == eHTMLUnit_Enumerated) { - // XXX set align - } - } - - PRInt32 numCols = 1; - // cols: int - GetAttribute(nsHTMLAtoms::cols, value); - if (value.GetUnit() == eHTMLUnit_Integer) { - numCols = value.GetIntValue(); - // XXX - } - - // Note: These attributes only apply when cols > 1 - if (1 < numCols) { - // gutter: int - GetAttribute(nsHTMLAtoms::gutter, value); - if (value.GetUnit() == eHTMLUnit_Pixel) { - // XXX set - } - - // width: pixel, % - GetAttribute(nsHTMLAtoms::width, value); - if (value.GetUnit() == eHTMLUnit_Pixel) { - // XXX set - } - else if (value.GetUnit() == eHTMLUnit_Percent) { - // XXX set - } - } - } - else if ((mTag == nsHTMLAtoms::h1) || (mTag == nsHTMLAtoms::h2) || - (mTag == nsHTMLAtoms::h3) || (mTag == nsHTMLAtoms::h4) || - (mTag == nsHTMLAtoms::h5) || (mTag == nsHTMLAtoms::h6)) { - // align: enum - GetAttribute(nsHTMLAtoms::align, value); - if (value.GetUnit() == eHTMLUnit_Enumerated) { - // XXX set - } - } - else if (mTag == nsHTMLAtoms::pre) { - // wrap: empty - GetAttribute(nsHTMLAtoms::wrap, value); - if (value.GetUnit() == eHTMLUnit_Empty) { - // XXX set - } - - // variable: empty - GetAttribute(nsHTMLAtoms::variable, value); - if (value.GetUnit() == eHTMLUnit_Empty) { - nsStyleFont* font = (nsStyleFont*) - aContext->GetMutableStyleData(eStyleStruct_Font); - font->mFont.name = "serif"; - } - - // cols: int - GetAttribute(nsHTMLAtoms::cols, value); - if (value.GetUnit() == eHTMLUnit_Integer) { - // XXX set - } - - // tabstop: int - if (value.GetUnit() == eHTMLUnit_Integer) { - // XXX set - } - } - else if (mTag == nsHTMLAtoms::li) { - nsStyleList* list = (nsStyleList*)aContext->GetMutableStyleData(eStyleStruct_List); - - // type: enum - GetAttribute(nsHTMLAtoms::type, value); - if (value.GetUnit() == eHTMLUnit_Enumerated) { - list->mListStyleType = value.GetIntValue(); - } - } - else if ((mTag == nsHTMLAtoms::ul) || (mTag == nsHTMLAtoms::ol) || - (mTag == nsHTMLAtoms::menu) || (mTag == nsHTMLAtoms::dir)) { - nsStyleList* list = (nsStyleList*)aContext->GetMutableStyleData(eStyleStruct_List); - - // type: enum - GetAttribute(nsHTMLAtoms::type, value); - if (value.GetUnit() == eHTMLUnit_Enumerated) { - list->mListStyleType = value.GetIntValue(); - } - - // compact: empty - GetAttribute(nsHTMLAtoms::compact, value); - if (value.GetUnit() == eHTMLUnit_Empty) { - // XXX set - } - } - else if (mTag == nsHTMLAtoms::dl) { - // compact: flag - GetAttribute(nsHTMLAtoms::compact, value); - if (value.GetUnit() == eHTMLUnit_Empty) { - // XXX set - } - } - else if (mTag == nsHTMLAtoms::body) { - MapBackgroundAttributesInto(aContext, aPresContext); - GetAttribute(nsHTMLAtoms::text, value); - if (eHTMLUnit_Color == value.GetUnit()) { - nsStyleColor* color = (nsStyleColor*) - aContext->GetMutableStyleData(eStyleStruct_Color); - color->mColor = value.GetColorValue(); - aPresContext->SetDefaultColor(color->mColor); - } - - nsIHTMLDocument* htmlDoc; - if (NS_OK == mDocument->QueryInterface(kIHTMLDocumentIID, (void**)&htmlDoc)) { - nsIHTMLStyleSheet* styleSheet; - if (NS_OK == htmlDoc->GetAttributeStyleSheet(&styleSheet)) { - GetAttribute(nsHTMLAtoms::link, value); - if (eHTMLUnit_Color == value.GetUnit()) { - styleSheet->SetLinkColor(value.GetColorValue()); - } - - GetAttribute(nsHTMLAtoms::alink, value); - if (eHTMLUnit_Color == value.GetUnit()) { - styleSheet->SetActiveLinkColor(value.GetColorValue()); - } - - GetAttribute(nsHTMLAtoms::vlink, value); - if (eHTMLUnit_Color == value.GetUnit()) { - styleSheet->SetVisitedLinkColor(value.GetColorValue()); - } - } - NS_RELEASE(htmlDoc); - } - - // marginwidth/height get set by a special style rule - - // set up the basefont (defaults to 3) - nsStyleFont* font = (nsStyleFont*)aContext->GetMutableStyleData(eStyleStruct_Font); - const nsFont& defaultFont = aPresContext->GetDefaultFont(); - const nsFont& defaultFixedFont = aPresContext->GetDefaultFixedFont(); - PRInt32 scaler = aPresContext->GetFontScaler(); - float scaleFactor = nsStyleUtil::GetScalingFactor(scaler); - font->mFont.size = nsStyleUtil::CalcFontPointSize(3, (PRInt32)defaultFont.size, scaleFactor); - font->mFixedFont.size = nsStyleUtil::CalcFontPointSize(3, (PRInt32)defaultFixedFont.size, scaleFactor); - } - } return NS_OK; }