public static void ParseHtmlDom(TextSource snapSource, IHtmlDocument htmldoc, WebDom.DomElement parentElement) { var parser = GetHtmlParser(); //------------------------ parser.Parse(snapSource, (LayoutFarm.WebDom.Impl.HtmlDocument)htmldoc, parentElement); FreeHtmlParser(parser); }
public static MyHtmlContainer CreateHtmlContainer( HtmlHost htmlHost, WebDom.WebDocument htmldoc, HtmlRenderBox htmlFrgmentRenderBox) { //1. builder var renderTreeBuilder = htmlHost.GetRenderTreeBuilder(); //------------------------------------------------------------------- //2. generate render tree ////build rootbox from htmldoc var rootElement = renderTreeBuilder.BuildCssRenderTree(htmldoc, htmlHost.BaseStylesheet, htmlFrgmentRenderBox); //3. create small htmlContainer var htmlContainer = new MyHtmlContainer(htmlHost); htmlContainer.WebDocument = htmldoc; htmlContainer.RootCssBox = rootElement; htmlContainer.SetMaxSize(htmlFrgmentRenderBox.Width, 0); var lay = htmlHost.GetSharedHtmlLayoutVisitor(htmlContainer); htmlContainer.PerformLayout(lay); htmlHost.ReleaseHtmlLayoutVisitor(lay); htmlFrgmentRenderBox.SetHtmlContainer(htmlContainer, rootElement); return htmlContainer; }
private HtmlHost(WebDom.CssActiveSheet activeSheet) { this.BaseStylesheet = activeSheet; this.commonHtmlDoc = new HtmlDocument(); this.commonHtmlDoc.CssActiveSheet = activeSheet; }
void AddRuleSet(WebDom.CssRuleSet ruleset) { List<CssRuleSetGroup> relatedRuleSets = new List<CssRuleSetGroup>(); ExpandSelector(relatedRuleSets, ruleset.GetSelector()); CssPropertyAssignmentCollection assignmentCollection = new CssPropertyAssignmentCollection(null); assignmentCollection.LoadRuleSet(ruleset); foreach (var ruleSetGroup in relatedRuleSets) { //start with share*** rule set ruleSetGroup.AddRuleSet(assignmentCollection); } }
public override DomElement GetPresentationDomNode(WebDom.Impl.HtmlDocument htmldoc) { //TODO: use template engine, //ideas: AngularJS style ? //1. create body node // and content //style 2, lambda and adhoc attach event if (pnode != null) return pnode; //--------------------------------------------------- pnode = htmldoc.CreateElement("div"); pnode.AddChild("img", img => { //init bool is_close = true; img.SetAttribute("src", "../../Demo/arrow_close.png"); img.AttachMouseDownEvent(e => { img.SetAttribute("src", is_close ? "../../Demo/arrow_open.png" : "../../Demo/arrow_close.png"); is_close = !is_close; e.StopPropagation(); }); }); //pnode.AddChild("img", img => //{ // //change style // bool is_close = true; // img.SetAttribute("src", "../../Demo/arrow_close.png"); // //3. attach event to specific span // img.AttachMouseDownEvent(e => // { // img.SetAttribute("src", is_close ? // "../../Demo/arrow_open.png" : // "../../Demo/arrow_close.png"); // is_close = !is_close; // e.StopPropagation(); // this.InvalidateGraphics(); // }); //}); pnode.AddChild("span", span => { span.AddTextContent(this.checkBoxText); }); return pnode; }
DomElement CreateFloatPartDom(WebDom.Impl.HtmlDocument htmldoc) { //create land part var div = htmldoc.CreateElement("div"); div.SetAttribute("style", "position:absolute;left:0px;top:0px;width:300px;height:500px;"); for (int i = 0; i < 10; ++i) { div.AddChild("div", div2 => { div2.AddTextContent("HELLO!" + i); }); } return div; }
public override DomElement GetPresentationDomNode(WebDom.Impl.HtmlDocument htmldoc) { if (pnode != null) return pnode; //create primary presentation node pnode = htmldoc.CreateElement("div"); pnode.SetAttribute("style", "font:10pt tahoma"); int j = treeNodes.Count; for (int i = 0; i < j; ++i) { pnode.AddChild(treeNodes[i].GetPrimaryPresentationNode(pnode)); } return pnode; }
static void SetBorderSpacing(BoxSpec box, WebDom.CssCodeValueExpression value) { WebDom.CssCodePrimitiveExpression primValue = value as WebDom.CssCodePrimitiveExpression; if (primValue == null) { //2 values? //box.BorderSpacingHorizontal = new CssLength(r[0].Value); //box.BorderSpacingVertical = new CssLength(r[1].Value); throw new NotSupportedException(); } else { //primitive value box.BorderSpacingHorizontal = box.BorderSpacingVertical = UserMapUtil.AsLength(primValue); } }
/// <summary> /// Parse the given stylesheet source to CSS blocks dictionary.<br/> /// The CSS blocks are organized into two level buckets of media type and class name.<br/> /// Root media type are found under 'all' bucket.<br/> /// If <paramref name="combineWithDefault"/> is true the parsed css blocks are added to the /// default css data (as defined by W3), merged if class name already exists. If false only the data in the given stylesheet is returned. /// </summary> /// <seealso cref="http://www.w3.org/TR/CSS21/sample.html"/> /// <param name="stylesheet">raw css stylesheet to parse</param> /// <param name="combineWithDefault">true - combine the parsed css data with default css data, false - return only the parsed css data</param> /// <returns>the CSS data with parsed CSS objects (never null)</returns> public static WebDom.CssActiveSheet ParseStyleSheet( string stylesheet, WebDom.CssActiveSheet defaultActiveSheet, bool combineWithDefault) { //TODO: check if can clone CssActiveSheet var cssData = combineWithDefault ? defaultActiveSheet.Clone() : new WebDom.CssActiveSheet(); if (!string.IsNullOrEmpty(stylesheet)) { ParseStyleSheet(cssData, stylesheet); } return cssData; }
public override WebDom.DomElement GetPresentationDomNode(WebDom.Impl.HtmlDocument htmldoc) { if (pnode != null) return pnode; //-------------------------------- pnode = htmldoc.CreateElement("div"); pnode.SetAttribute("style", "font:10pt tahoma;overflow:scroll;height:300px;"); int j = items.Count; if (j > 0) { for (int i = 0; i < j; ++i) { //itemnode pnode.AddChild(items[i].GetPresentationNode(pnode)); } } return pnode; }
public void LoadCssDoc(WebDom.CssDocument cssDoc) { foreach (WebDom.CssDocMember cssDocMember in cssDoc.GetCssDocMemberIter()) { switch (cssDocMember.MemberKind) { case WebDom.CssDocMemberKind.RuleSet: this.AddRuleSet((WebDom.CssRuleSet)cssDocMember); break; case WebDom.CssDocMemberKind.Media: this.AddMedia((WebDom.CssAtMedia)cssDocMember); break; default: case WebDom.CssDocMemberKind.Page: throw new NotSupportedException(); } } }
static CssRuleSetGroup GetGroupOrCreateIfNotExists(Dictionary<string, CssRuleSetGroup> dic, WebDom.CssSimpleElementSelector simpleSelector) { CssRuleSetGroup ruleSetGroup; if (!dic.TryGetValue(simpleSelector.Name, out ruleSetGroup)) { ruleSetGroup = new CssRuleSetGroup(simpleSelector.Name); dic.Add(simpleSelector.Name, ruleSetGroup); } //------------- if (simpleSelector.Parent != null) { //get or create subgroup return ruleSetGroup.GetOrCreateSubgroup(simpleSelector); } //------------- return ruleSetGroup; }
public override DomElement GetPresentationDomNode(WebDom.Impl.HtmlDocument htmldoc) { if (presentationNode != null) { return presentationNode; } //------------------- presentationNode = htmldoc.CreateElement("div"); presentationNode.AddChild("div", div => { div.SetAttribute("style", "font:10pt tahoma;"); div.AddChild("img", img => { //init img.SetAttribute("src", "../../Demo/arrow_close.png"); img.AttachMouseDownEvent(e => { //img.SetAttribute("src", this.IsOpen ? // "../../Demo/arrow_open.png" : // "../../Demo/arrow_close.png"); ////------------------------------ if (this.IsOpen) { img.SetAttribute("src", "../../Demo/arrow_close.png"); this.CloseHinge(); } else { img.SetAttribute("src", "../../Demo/arrow_open.png"); this.OpenHinge(); } //----------------------------- e.StopPropagation(); }); }); }); //------------------- this.floatPartDomElement = this.CreateFloatPartDom(htmldoc); return presentationNode; }
public override DomElement GetPresentationDomNode(WebDom.Impl.HtmlDocument htmldoc) { if (pnode != null) return pnode; //---------------------------------- pnode = htmldoc.CreateElement("div"); pnode.SetAttribute("style", "display:inline-block;width:" + Width + "px;height:" + this.Height + "px;"); pnode.AddChild("div", div2 => { //init div2.SetAttribute("style", "padding:5px;background-color:#dddddd;"); div2.AddChild("span", span => { span.AddTextContent(this.buttonText); }); //------------------------------ div2.AttachMouseDownEvent(e => { #if DEBUG div2.dbugMark = 1; #endif // div2.SetAttribute("style", "padding:5px;background-color:#aaaaaa;"); EaseScriptElement ee = new EaseScriptElement(div2); ee.ChangeBackgroundColor(Color.FromArgb(0xaa, 0xaa, 0xaa)); //div2.SetAttribute("style", "padding:5px;background-color:#aaaaaa;"); e.StopPropagation(); }); div2.AttachMouseUpEvent(e => { #if DEBUG div2.dbugMark = 2; #endif //div2.SetAttribute("style", "padding:5px;background-color:#dddddd;"); EaseScriptElement ee = new EaseScriptElement(div2); ee.ChangeBackgroundColor(Color.FromArgb(0xdd, 0xdd, 0xdd)); e.StopPropagation(); }); }); return pnode; }
/// <summary> /// Parse the given stylesheet source to CSS blocks dictionary.<br/> /// The CSS blocks are organized into two level buckets of media type and class name.<br/> /// Root media type are found under 'all' bucket.<br/> /// The parsed css blocks are added to the given css data, merged if class name already exists. /// </summary> /// <param name="cssData">the CSS data to fill with parsed CSS objects</param> /// <param name="cssTextSource">raw css stylesheet to parse</param> public static void ParseStyleSheet(WebDom.CssActiveSheet cssData, string cssTextSource) { if (!String.IsNullOrEmpty(cssTextSource)) { var parser = new WebDom.Parser.CssParser(); parser.ParseCssStyleSheet(cssTextSource.ToCharArray()); //----------------------------------- WebDom.CssDocument cssDoc = parser.OutputCssDocument; WebDom.CssActiveSheet cssActiveDoc = new WebDom.CssActiveSheet(); cssActiveDoc.LoadCssDoc(cssDoc); if (cssData != null) { //merge ? cssData.Combine(cssActiveDoc); } else { //cssData.ActiveDoc = cssActiveDoc; } } }
void EvaluateRuleSet(WebDom.CssRuleSet ruleset) { //only some prop need to be alter List<CssPropertyDeclaration> newProps = null; foreach (CssPropertyDeclaration decl in ruleset.GetAssignmentIter()) { switch (decl.WellknownPropertyName) { case WellknownCssPropertyName.Font: { if (newProps == null) newProps = new List<CssPropertyDeclaration>(); ExpandFontProperty(decl, newProps); decl.IsExpand = true; } break; case WellknownCssPropertyName.Border: { if (newProps == null) newProps = new List<CssPropertyDeclaration>(); ExpandBorderProperty(decl, BorderDirection.All, newProps); decl.IsExpand = true; } break; case WellknownCssPropertyName.BorderLeft: { if (newProps == null) newProps = new List<CssPropertyDeclaration>(); ExpandBorderProperty(decl, BorderDirection.Left, newProps); decl.IsExpand = true; } break; case WellknownCssPropertyName.BorderRight: { if (newProps == null) newProps = new List<CssPropertyDeclaration>(); ExpandBorderProperty(decl, BorderDirection.Right, newProps); decl.IsExpand = true; } break; case WellknownCssPropertyName.BorderTop: { if (newProps == null) newProps = new List<CssPropertyDeclaration>(); ExpandBorderProperty(decl, BorderDirection.Top, newProps); decl.IsExpand = true; } break; case WellknownCssPropertyName.BorderBottom: { if (newProps == null) newProps = new List<CssPropertyDeclaration>(); ExpandBorderProperty(decl, BorderDirection.Bottom, newProps); decl.IsExpand = true; } break; //--------------------------- case WellknownCssPropertyName.BorderStyle: { if (newProps == null) newProps = new List<CssPropertyDeclaration>(); ExpandCssEdgeProperty(decl, WellknownCssPropertyName.BorderLeftStyle, WellknownCssPropertyName.BorderTopStyle, WellknownCssPropertyName.BorderRightStyle, WellknownCssPropertyName.BorderBottomStyle, newProps); decl.IsExpand = true; } break; case WellknownCssPropertyName.BorderWidth: { if (newProps == null) newProps = new List<CssPropertyDeclaration>(); ExpandCssEdgeProperty(decl, WellknownCssPropertyName.BorderLeftWidth, WellknownCssPropertyName.BorderTopWidth, WellknownCssPropertyName.BorderRightWidth, WellknownCssPropertyName.BorderBottomWidth, newProps); decl.IsExpand = true; } break; case WellknownCssPropertyName.BorderColor: { if (newProps == null) newProps = new List<CssPropertyDeclaration>(); ExpandCssEdgeProperty(decl, WellknownCssPropertyName.BorderLeftColor, WellknownCssPropertyName.BorderTopColor, WellknownCssPropertyName.BorderRightColor, WellknownCssPropertyName.BorderBottomColor, newProps); decl.IsExpand = true; } break; //--------------------------- case WellknownCssPropertyName.Margin: { if (newProps == null) newProps = new List<CssPropertyDeclaration>(); ExpandCssEdgeProperty(decl, WellknownCssPropertyName.MarginLeft, WellknownCssPropertyName.MarginTop, WellknownCssPropertyName.MarginRight, WellknownCssPropertyName.MarginBottom, newProps); decl.IsExpand = true; } break; case WellknownCssPropertyName.Padding: { if (newProps == null) newProps = new List<CssPropertyDeclaration>(); ExpandCssEdgeProperty(decl, WellknownCssPropertyName.PaddingLeft, WellknownCssPropertyName.PaddingTop, WellknownCssPropertyName.PaddingRight, WellknownCssPropertyName.PaddingBottom, newProps); decl.IsExpand = true; } break; } } //-------------------- //add new prop to ruleset if (newProps == null) { return; } //------------ int newPropCount = newProps.Count; for (int i = 0; i < newPropCount; ++i) { //add new prop to ruleset ruleset.AddCssCodeProperty(newProps[i]); } }
void ExpandSelector(List<CssRuleSetGroup> relatedRuleSets, WebDom.CssElementSelector selector) { //recursive //create active element set if (selector.IsSimpleSelector) { WebDom.CssSimpleElementSelector simpleSelector = (WebDom.CssSimpleElementSelector)selector; switch (simpleSelector.selectorType) { default: { throw new NotSupportedException(); } case WebDom.SimpleElementSelectorKind.ClassName: { //any element with specific class name relatedRuleSets.Add( GetGroupOrCreateIfNotExists( rulesForClassName, simpleSelector)); } break; case WebDom.SimpleElementSelectorKind.Extend: { } break; case WebDom.SimpleElementSelectorKind.Id: { //element with id relatedRuleSets.Add( GetGroupOrCreateIfNotExists( rulesForElementId, simpleSelector)); } break; case WebDom.SimpleElementSelectorKind.PseudoClass: { relatedRuleSets.Add( GetGroupOrCreateIfNotExists( rulesForPsedoClass, simpleSelector)); } break; case WebDom.SimpleElementSelectorKind.TagName: { relatedRuleSets.Add( GetGroupOrCreateIfNotExists( rulesForTagName, simpleSelector)); } break; case WebDom.SimpleElementSelectorKind.All: { relatedRuleSets.Add( GetGroupOrCreateIfNotExists( rulesForAll, simpleSelector)); } break; } } else { WebDom.CssCompundElementSelector combiSelector = (WebDom.CssCompundElementSelector)selector; switch (combiSelector.OperatorName) { case WebDom.CssCombinatorOperator.List: { ExpandSelector(relatedRuleSets, combiSelector.LeftSelector); ExpandSelector(relatedRuleSets, combiSelector.RightSelector); } break; case WebDom.CssCombinatorOperator.Descendant: { //focus on right side? ExpandSelector(relatedRuleSets, combiSelector.RightSelector); } break; default: { throw new NotSupportedException(); } } } //----------------------------------------------------------------------------- }
public WebDom.DomElement GetPresentationNode(WebDom.DomElement hostNode) { if (pnode != null) return pnode; //------------------------------ if (itemText == null) { itemText = ""; } var ownerdoc = hostNode.OwnerDocument; pnode = ownerdoc.CreateElement("div"); // pnode.SetAttribute("style", "font:10pt tahoma"); textSpanNode = ownerdoc.CreateElement("span"); textSpanNode.AddChild(ownerdoc.CreateTextNode(itemText.ToCharArray())); pnode.AddChild(textSpanNode); return pnode; }
public WebDom.CssPropertyDeclaration GetPropertyDeclaration(WebDom.WellknownCssPropertyName wellknownPropName) { if (_assignments != null) { WebDom.CssPropertyDeclaration decl; _assignments.GetDeclarations().TryGetValue(wellknownPropName, out decl); return decl; } return null; }
private CssRuleSetGroup(CssRuleSetGroup parent, string name, WebDom.CssSimpleElementSelector simpleSelector) { this.Name = name; this._parent = parent; this._originalSelector = simpleSelector; }
public CssRuleSetGroup GetOrCreateSubgroup(WebDom.CssSimpleElementSelector simpleSelector) { if (_subGroups == null) { _subGroups = new List<CssRuleSetGroup>(); } int j = _subGroups.Count; for (int i = 0; i < j; ++i) { //find sub group for specific selector WebDom.CssSimpleElementSelector selector = _subGroups[i]._originalSelector; if (WebDom.CssSimpleElementSelector.IsCompatible(selector, simpleSelector)) { //found return _subGroups[i]; } } //if not found then create new one CssRuleSetGroup newSubgroup = new CssRuleSetGroup(this, this.Name, simpleSelector); this._subGroups.Add(newSubgroup); return newSubgroup; }
public override DomElement GetPresentationDomNode(WebDom.Impl.HtmlDocument htmldoc) { if (pnode != null) return pnode; this.htmldoc = htmldoc; pnode = htmldoc.CreateElement("div"); //TODO: review IsLandPart again, this is temp fixed if (!this.IsLandPart) { pnode.SetAttribute("style", "position:absolute;width:100px;height:200px"); } if (menuItems != null) { int j = menuItems.Count; for (int i = 0; i < j; ++i) { pnode.AddChild(menuItems[i].GetPresentationDomNode(pnode)); } } return pnode; }
void AddMedia(WebDom.CssAtMedia atMedia) { if (!atMedia.HasMediaName) { //global media foreach (WebDom.CssRuleSet ruleSet in atMedia.GetRuleSetIter()) { this.AddRuleSet(ruleSet); } } else { //has media name } }
public abstract WebDom.DomElement GetPresentationDomNode(WebDom.Impl.HtmlDocument htmldoc);
public void SetCssLength(CssLength len, WebDom.CssValueEvaluatedAs evalAs) { this.cachedLength = len; this.evaluatedAs = evalAs; }
public void LoadAnotherStylesheet(WebDom.CssActiveSheet anotherActiveSheet) { CloneActiveCssSheetOnce(); activeSheet.Combine(anotherActiveSheet); }
public override WebDom.DomElement GetPresentationDomNode(WebDom.Impl.HtmlDocument htmldoc) { if (pnode != null) return pnode; //------------------------------ pnode = htmldoc.CreateElement("div"); pnode.SetAttribute("style", "font:10pt tahoma"); //------------------------------ titleBar = htmldoc.CreateElement("div"); titleBar.AddTextContent("hello tabPage"); pnode.AddChild(titleBar); //------------------------------ tabTitleList = htmldoc.CreateElement("div"); pnode.AddChild(tabTitleList); //------------------------------ contentNode = htmldoc.CreateElement("div"); pnode.AddChild(contentNode); //------------------------------ return pnode; }
void EvaluateMedia(WebDom.CssAtMedia atMedia) { foreach (var ruleset in atMedia.GetRuleSetIter()) { EvaluateRuleSet(ruleset); } }
public CssBox CreateBox2(CssBox parentBox, WebDom.Impl.HtmlElement childElement, bool fullmode) { return CreateBox(parentBox, (HtmlElement)childElement, fullmode); }
public EaseDomElement(WebDom.DomElement domElement) { this.easeScriptElement = new EaseScriptElement(domElement); }