static void AssignStylesFromTranslatedAttributesHTML5(HtmlElement tag) { //some html attr contains css value if (tag.AttributeCount > 0) { foreach (var attr in tag.GetAttributeIterForward()) { //attr switch by wellknown property name switch ((WebDom.WellknownName)attr.LocalNameIndex) { case WebDom.WellknownName.Align: { //deprecated in HTML4.1 //string value = attr.Value.ToLower(); //if (value == "left" // || value == "center" // || value == "right" // || value == "justify") //{ // WebDom.CssCodePrimitiveExpression propValue = new WebDom.CssCodePrimitiveExpression( // value, WebDom.CssValueHint.Iden); // box.CssTextAlign = UserMapUtil.GetTextAlign(propValue); //} //else //{ // WebDom.CssCodePrimitiveExpression propValue = new WebDom.CssCodePrimitiveExpression( // value, WebDom.CssValueHint.Iden); // box.VerticalAlign = UserMapUtil.GetVerticalAlign(propValue); //} //break; } break; case WebDom.WellknownName.Background: //deprecated in HTML4.1 //box.BackgroundImageBinder = new ImageBinder(attr.Value.ToLower()); break; case WebDom.WellknownName.BackgroundColor: //deprecated in HTML5 //box.BackgroundColor = CssValueParser.GetActualColor(attr.Value.ToLower()); break; case WebDom.WellknownName.Border: { //not support in HTML5 //CssLength borderLen = TranslateLength(UserMapUtil.MakeBorderLength(attr.Value.ToLower())); //if (!borderLen.HasError) //{ // if (borderLen.Number > 0) // { // box.BorderLeftStyle = // box.BorderTopStyle = // box.BorderRightStyle = // box.BorderBottomStyle = CssBorderStyle.Solid; // } // box.BorderLeftWidth = // box.BorderTopWidth = // box.BorderRightWidth = // box.BorderBottomWidth = borderLen; // if (tag.WellknownTagName == WellknownHtmlTagName.TABLE && borderLen.Number > 0) // { // //Cascades to the TD's the border spacified in the TABLE tag. // var borderWidth = CssLength.MakePixelLength(1); // ForEachCellInTable(box, cell => // { // //for all cells // cell.BorderLeftStyle = cell.BorderTopStyle = cell.BorderRightStyle = cell.BorderBottomStyle = CssBorderStyle.Solid; // CssConstants.Solid; // cell.BorderLeftWidth = cell.BorderTopWidth = cell.BorderRightWidth = cell.BorderBottomWidth = borderWidth; // }); // } //} } break; case WebDom.WellknownName.BorderColor: //box.BorderLeftColor = // box.BorderTopColor = // box.BorderRightColor = // box.BorderBottomColor = CssValueParser.GetActualColor(attr.Value.ToLower()); break; case WebDom.WellknownName.CellSpacing: //html5 not support in HTML5, use CSS instead //box.BorderSpacingHorizontal = box.BorderSpacingVertical = TranslateLength(attr); break; case WebDom.WellknownName.CellPadding: { //html5 not support in HTML5, use CSS instead *** // CssLength len01 = UserMapUtil.ParseGenericLength(attr.Value.ToLower()); // if (len01.HasError && (len01.Number > 0)) // { // CssLength len02 = CssLength.MakePixelLength(len01.Number); // ForEachCellInTable(box, cell => // { //#if DEBUG // // cell.dbugBB = dbugTT++; //#endif // cell.PaddingLeft = cell.PaddingTop = cell.PaddingRight = cell.PaddingBottom = len02; // }); // } // else // { // ForEachCellInTable(box, cell => // cell.PaddingLeft = cell.PaddingTop = cell.PaddingRight = cell.PaddingBottom = len01); // } } break; case WebDom.WellknownName.Color: //deprecate // box.Color = CssValueParser.GetActualColor(attr.Value.ToLower()); break; case WebDom.WellknownName.Dir: { WebDom.CssCodePrimitiveExpression propValue = new WebDom.CssCodePrimitiveExpression( attr.Value.ToLower(), WebDom.CssValueHint.Iden); //assign var spec = tag.Spec; spec.CssDirection = UserMapUtil.GetCssDirection(propValue); } break; case WebDom.WellknownName.Face: //deprecate //box.FontFamily = CssParser.ParseFontFamily(attr.Value.ToLower()); break; case WebDom.WellknownName.Height: { var spec = tag.Spec; spec.Height = TranslateLength(attr); } break; case WebDom.WellknownName.HSpace: //deprecated //box.MarginRight = box.MarginLeft = TranslateLength(attr); break; case WebDom.WellknownName.Nowrap: //deprecate //box.WhiteSpace = CssWhiteSpace.NoWrap; break; case WebDom.WellknownName.Size: { //deprecate //switch (tag.WellknownTagName) //{ // case WellknownHtmlTagName.HR: // { // box.Height = TranslateLength(attr); // } break; // case WellknownHtmlTagName.FONT: // { // var ruleset = activeTemplate.ParseCssBlock("", attr.Value.ToLower()); // foreach (WebDom.CssPropertyDeclaration propDecl in ruleset.GetAssignmentIter()) // { // //assign each property // AssignPropertyValue(box, box.ParentBox, propDecl); // } // //WebDom.CssCodePrimitiveExpression prim = new WebDom.CssCodePrimitiveExpression(value, // //box.SetFontSize(value); // } break; //} } break; case WebDom.WellknownName.VAlign: { //w3.org //valign for table display elements: //col,colgroup,tbody,td,tfoot,th,thead,tr WebDom.CssCodePrimitiveExpression propValue = new WebDom.CssCodePrimitiveExpression( attr.Value.ToLower(), WebDom.CssValueHint.Iden); tag.Spec.VerticalAlign = UserMapUtil.GetVerticalAlign(propValue); } break; case WebDom.WellknownName.VSpace: //deprecated //box.MarginTop = box.MarginBottom = TranslateLength(attr); break; case WebDom.WellknownName.Width: { var spec = tag.Spec; spec.Width = TranslateLength(attr); } break; case WellknownName.Src: { var cssBoxImage = HtmlElement.InternalGetPrincipalBox(tag) as CssBoxImage; if (cssBoxImage != null) { string imgsrc; //ImageBinder imgBinder = null; if (tag.TryGetAttribute(WellknownName.Src, out imgsrc)) { CssBoxImage cssBoxImage1 = HtmlElement.InternalGetPrincipalBox(tag) as CssBoxImage; PixelFarm.Drawing.ImageBinder imgbinder1 = cssBoxImage1.ImageBinder; if (imgbinder1.ImageSource != imgsrc) { //var clientImageBinder = new ClientImageBinder(imgsrc); //imgbinder1 = clientImageBinder; //clientImageBinder.SetOwner(tag); cssBoxImage1.ImageBinder = new PixelFarm.Drawing.ImageBinder(imgsrc); } } else { //var clientImageBinder = new ClientImageBinder(null); //imgBinder = clientImageBinder; //clientImageBinder.SetOwner(tag); } } } break; } } } }
static void SetPropertyValue(BoxSpec spec, WebDom.CssPropertyDeclaration decl) { //assign property CssCodeValueExpression cssValue = decl.GetPropertyValue(0); switch (decl.WellknownPropertyName) { case WellknownCssPropertyName.Display: spec.CssDisplay = UserMapUtil.GetDisplayType(cssValue); break; //------------------------------------------------ case WellknownCssPropertyName.BorderBottomWidth: spec.BorderBottomWidth = cssValue.AsBorderLength(); break; case WellknownCssPropertyName.BorderLeftWidth: spec.BorderLeftWidth = cssValue.AsBorderLength(); break; case WellknownCssPropertyName.BorderRightWidth: spec.BorderRightWidth = cssValue.AsBorderLength(); break; case WellknownCssPropertyName.BorderTopWidth: spec.BorderTopWidth = cssValue.AsBorderLength(); break; //------------------------------------------------ case WellknownCssPropertyName.BorderBottomStyle: spec.BorderBottomStyle = UserMapUtil.GetBorderStyle(cssValue); break; case WellknownCssPropertyName.BorderLeftStyle: spec.BorderLeftStyle = UserMapUtil.GetBorderStyle(cssValue); break; case WellknownCssPropertyName.BorderRightStyle: spec.BorderRightStyle = UserMapUtil.GetBorderStyle(cssValue); break; case WellknownCssPropertyName.BorderTopStyle: spec.BorderTopStyle = UserMapUtil.GetBorderStyle(cssValue); break; //------------------------------------------------ case WellknownCssPropertyName.BorderBottomColor: spec.BorderBottomColor = AsColor(cssValue); break; case WellknownCssPropertyName.BorderLeftColor: spec.BorderLeftColor = AsColor(cssValue); break; case WellknownCssPropertyName.BorderRightColor: spec.BorderRightColor = AsColor(cssValue); break; case WellknownCssPropertyName.BorderTopColor: spec.BorderTopColor = AsColor(cssValue);; break; //------------------------------------------------ case WellknownCssPropertyName.BorderSpacing: SetBorderSpacing(spec, cssValue); break; case WellknownCssPropertyName.BorderCollapse: spec.BorderCollapse = UserMapUtil.GetBorderCollapse(cssValue); break; //------------------------------------------------ case WellknownCssPropertyName.BoxSizing: spec.BoxSizing = UserMapUtil.GetBoxSizing(cssValue); break; case WellknownCssPropertyName.BoxShadow: SetBoxShadow(spec, decl); break; case WellknownCssPropertyName.CornerRadius: SetCornerRadius(spec, cssValue); break; case WellknownCssPropertyName.CornerNWRadius: spec.CornerNWRadius = cssValue.AsLength(); break; case WellknownCssPropertyName.CornerNERadius: spec.CornerNERadius = cssValue.AsLength(); break; case WellknownCssPropertyName.CornerSERadius: spec.CornerSERadius = cssValue.AsLength(); break; case WellknownCssPropertyName.CornerSWRadius: spec.CornerSWRadius = cssValue.AsLength(); break; //------------------------------------------------ case WellknownCssPropertyName.MarginBottom: spec.MarginBottom = cssValue.AsTranslatedLength(); break; case WellknownCssPropertyName.MarginLeft: spec.MarginLeft = cssValue.AsTranslatedLength(); break; case WellknownCssPropertyName.MarginRight: spec.MarginRight = cssValue.AsTranslatedLength(); break; case WellknownCssPropertyName.MarginTop: spec.MarginTop = cssValue.AsTranslatedLength(); break; //------------------------------------------------ case WellknownCssPropertyName.PaddingBottom: spec.PaddingBottom = cssValue.AsTranslatedLength(); break; case WellknownCssPropertyName.PaddingLeft: spec.PaddingLeft = cssValue.AsTranslatedLength(); break; case WellknownCssPropertyName.PaddingRight: spec.PaddingRight = cssValue.AsTranslatedLength(); break; case WellknownCssPropertyName.PaddingTop: spec.PaddingTop = cssValue.AsTranslatedLength(); break; //------------------------------------------------ case WellknownCssPropertyName.Left: spec.Left = cssValue.AsLength(); break; case WellknownCssPropertyName.Top: spec.Top = cssValue.AsLength(); break; case WellknownCssPropertyName.Width: spec.Width = cssValue.AsLength(); break; case WellknownCssPropertyName.MaxWidth: spec.MaxWidth = cssValue.AsLength(); break; case WellknownCssPropertyName.Height: spec.Height = cssValue.AsLength(); break; case WellknownCssPropertyName.BackgroundColor: spec.BackgroundColor = AsColor(cssValue); break; case WellknownCssPropertyName.BackgroundImage: spec.BackgroundImageBinder = new ClientImageBinder(cssValue.GetTranslatedStringValue()); break; case WellknownCssPropertyName.BackgroundPosition: SetBackgroundPosition(spec, cssValue); break; case WellknownCssPropertyName.BackgroundRepeat: spec.BackgroundRepeat = UserMapUtil.GetBackgroundRepeat(cssValue); break; case WellknownCssPropertyName.BackgroundGradient: spec.BackgroundGradient = AsColor(cssValue); break; case WellknownCssPropertyName.BackgroundGradientAngle: spec.BackgroundGradientAngle = cssValue.AsNumber(); break; case WellknownCssPropertyName.Color: spec.Color = AsColor(cssValue); break; case WellknownCssPropertyName.Direction: spec.CssDirection = UserMapUtil.GetCssDirection(cssValue); break; case WellknownCssPropertyName.EmptyCells: spec.EmptyCells = UserMapUtil.GetEmptyCell(cssValue); break; case WellknownCssPropertyName.Float: spec.Float = UserMapUtil.GetFloat(cssValue); break; case WellknownCssPropertyName.Position: spec.Position = UserMapUtil.GetCssPosition(cssValue); break; case WellknownCssPropertyName.LineHeight: spec.LineHeight = cssValue.AsLength(); break; case WellknownCssPropertyName.VerticalAlign: spec.VerticalAlign = UserMapUtil.GetVerticalAlign(cssValue); break; case WellknownCssPropertyName.TextIndent: spec.TextIndent = cssValue.AsLength(); break; case WellknownCssPropertyName.TextAlign: spec.CssTextAlign = UserMapUtil.GetTextAlign(cssValue); break; case WellknownCssPropertyName.TextDecoration: spec.TextDecoration = UserMapUtil.GetTextDecoration(cssValue); break; case WellknownCssPropertyName.Whitespace: spec.WhiteSpace = UserMapUtil.GetWhitespace(cssValue); break; case WellknownCssPropertyName.WordBreak: spec.WordBreak = UserMapUtil.GetWordBreak(cssValue); break; case WellknownCssPropertyName.Visibility: spec.Visibility = UserMapUtil.GetVisibility(cssValue); break; case WellknownCssPropertyName.WordSpacing: spec.WordSpacing = cssValue.AsLength(); break; case WellknownCssPropertyName.FontFamily: spec.FontFamily = cssValue.GetTranslatedStringValue(); break; case WellknownCssPropertyName.FontSize: SetFontSize(spec, cssValue); break; case WellknownCssPropertyName.FontStyle: spec.FontStyle = UserMapUtil.GetFontStyle(cssValue); break; case WellknownCssPropertyName.FontVariant: spec.FontVariant = UserMapUtil.GetFontVariant(cssValue); break; case WellknownCssPropertyName.FontWeight: spec.FontWeight = UserMapUtil.GetFontWeight(cssValue); break; case WellknownCssPropertyName.ListStyle: spec.ListStyle = cssValue.GetTranslatedStringValue(); break; case WellknownCssPropertyName.ListStylePosition: spec.ListStylePosition = UserMapUtil.GetListStylePosition(cssValue); break; case WellknownCssPropertyName.ListStyleImage: spec.ListStyleImage = cssValue.GetTranslatedStringValue(); break; case WellknownCssPropertyName.ListStyleType: spec.ListStyleType = UserMapUtil.GetListStyleType(cssValue); break; case WellknownCssPropertyName.Overflow: spec.Overflow = UserMapUtil.GetOverflow(cssValue); break; //------------------------------------------------ //for flex container case WellknownCssPropertyName.Flex: { //TODO: implement this } break; case WellknownCssPropertyName.FlexDirection: { //TODO: implement this } break; case WellknownCssPropertyName.FlexFlow: { //TODO: implement this } break; case WellknownCssPropertyName.FlexWrap: { //TODO: implement this } break; //------------------------------------------------ //for flex item case WellknownCssPropertyName.FlexGrow: spec.FlexGrow = (int)cssValue.AsNumber(); break; case WellknownCssPropertyName.FlexShrink: spec.FlexShrink = (int)cssValue.AsNumber(); break; case WellknownCssPropertyName.FlexOrder: spec.FlexOrder = (int)cssValue.AsNumber(); break; //------------------------------------------------ //experiment : for container case WellknownCssPropertyName.FlexExtensionNum: spec.FlexExtensionNum = (int)cssValue.AsNumber(); break; //experiment : for space part case WellknownCssPropertyName.FlexExtensionPart: spec.FlexExtensionPart = (int)cssValue.AsNumber(); break; } }