public void AttachEventHandler(CefDomNode parentNode, string indexPath, RSEventListener listener) { if (parentNode.HasChildren) { CefDomNode node = parentNode.FirstChild; if (node == null) return; int index = 0; string indexPath1 = indexPath + "." + index.ToString(); if (indexPath1 == _item.id) { node.AddEventListener(_item.eventName, listener, true); return; } AttachEventHandler(node, indexPath1, listener); node = node.NextSibling; while (node != null) { index++; indexPath1 = indexPath + "." + index.ToString(); if (indexPath1 == _item.id) { node.AddEventListener(_item.eventName, listener, true); return; } AttachEventHandler(node, indexPath1, listener); node = node.NextSibling; System.Windows.Forms.Application.DoEvents(); } } }
public void AppendAllChildElement(CefDomNode parentNode,CwbElement parentElement, string indePath) { if (parentNode.HasChildren) { CefDomNode node = parentNode.FirstChild; if (node == null) return; int index = 0; CwbElement childElement = CreateElement(node); childElement.IndexPath = indePath + "."+index.ToString(); parentElement.ChildElements.Add(childElement); AppendAllChildElement(node, childElement, childElement.IndexPath); node = node.NextSibling; while (node != null) { childElement = CreateElement(node); index++; childElement.IndexPath = indePath + "." + index.ToString(); parentElement.ChildElements.Add(childElement); AppendAllChildElement(node, childElement, childElement.IndexPath); node = node.NextSibling; System.Windows.Forms.Application.DoEvents(); } } }
public CefXmlReader(CefDomDocument cefDomDocument) { this.document = cefDomDocument; this.rootNode = document.GetDocument(); this.nameTable = new NameTable(); this.namespaceManager = new XmlNamespaceManager(nameTable); }
protected override void Dispose(bool disposing) { if (disposing) { this.rootNode.Dispose(); this.rootNode = null; this.document = null; //System.GC.Collect(); //System.GC.WaitForPendingFinalizers(); } base.Dispose(disposing); }
private CwbElement CreateElement(CefDomNode node) { string id = string.Empty; if (node.HasAttribute("id")) { id = node.GetAttribute("id"); } CwbElement retValue = new CwbElement(browser,id, node.ElementTagName,node.GetAttribute("value"), node.IsElement,node.IsEditable, node.HasChildren,node.InnerText, node.HasAttributes ); foreach (KeyValuePair<string, string> item in node.GetAttributes()) { retValue.Attributes.Add(item); } return retValue; }
protected override void Dispose(bool disposing) { if (disposing) { if (this.currentNode != null) { this.currentNode.Dispose(); this.currentNode = null; } foreach (var node in this.nodeStack) { node.Dispose(); } this.nodeStack.Clear(); this.document = null; //System.GC.Collect(); //System.GC.WaitForPendingFinalizers(); } base.Dispose(disposing); }
public override bool Read() { // First call to Read if (ReadState == System.Xml.ReadState.Initial) { var rootNode = this.document.Root; this.nodeStack.Push(rootNode); currentNode = rootNode.FirstChild; return(CheckReadStateAndReturn()); } if (xmlReader != null) { var result = xmlReader.Read(); if (result && xmlReader.Depth > 0) { return(result); } else { xmlReader.Close(); textReader.Dispose(); xmlReader = null; textReader = null; } } switch (traverseDirection) { case TraverseDirection.Down: // As long as there're children go down (depth first) if (currentNode.HasChildren) { nodeStack.Push(currentNode); currentNode = currentNode.FirstChild; } else { var parent = nodeStack.Peek(); using (var lastChild = parent.LastChild) { if (currentNode.IsSame(lastChild)) { // Time to move back up nodeStack.Pop(); traverseDirection = TraverseDirection.Up; currentNode.Dispose(); currentNode = parent; } else { // There're still siblings left to visit var nextSibling = currentNode.NextSibling; currentNode.Dispose(); currentNode = nextSibling; } } } break; case TraverseDirection.Up: // See if we can find siblings (need to have a parent) if (nodeStack.Count > 1) { var parent = nodeStack.Peek(); using (var lastChild = parent.LastChild) { if (currentNode.IsSame(lastChild)) { // No sibling left, go further up nodeStack.Pop(); currentNode.Dispose(); currentNode = parent; } else { // There's a sibling, try to traverse down again (depth first) traverseDirection = TraverseDirection.Down; var nextSibling = currentNode.NextSibling; currentNode.Dispose(); currentNode = nextSibling; } } } else { // No parent left, we have to be the root -> EOF currentNode.Dispose(); currentNode = null; readState = System.Xml.ReadState.EndOfFile; return(false); } break; } if (currentNode != null) { // See if this node defines a new namespace if (currentNode.IsElement && currentNode.HasAttributes) { attributeMap = currentNode.GetAttributes(); switch (traverseDirection) { case TraverseDirection.Down: foreach (var entry in attributeMap) { var key = entry.Key; var value = entry.Value; if (key.StartsWith("xmlns")) { var prefix = GetLocalName(key); namespaceManager.AddNamespace(prefix, value); break; } } namespaceManager.PushScope(); break; case TraverseDirection.Up: namespaceManager.PopScope(); break; } } else { attributeMap = null; } } return(CheckReadStateAndReturn()); }
protected override void OnFocusedNodeChanged(CefBrowser browser, CefFrame frame, CefDomNode node) { base.OnFocusedNodeChanged(browser, frame, node); }
protected override void Visit(CefDomDocument document) { CefDomNode element; switch (_businID) { case CwbBusinStyle.bsGetElementValue: Global.Result = ""; element = document.GetElementById(_elementID); if (element == null) { Global.flag = true; return; } Global.Result = element.Value; if (element.ElementTagName.ToLower() != "input") Global.Result = element.InnerText; Global.flag = true; break; case CwbBusinStyle.bsSetElementValue: element = document.GetElementById(_elementID); if (element == null) return; if (element.IsEditable) element.SetAttribute("value", _elementValue); else { string code = "document.getElementById('{0}').innerHTML = '{1}';"; code = string.Format(code,_elementID,_elementValue); Global.instance.ExecuteScript(code); } break; case CwbBusinStyle.bsAddElementEvent: element = document.GetElementById(_item.id); if (element == null) return; element.AddEventListener(_item.eventName,new RSEventListener(_item.elementListener),true); break; case CwbBusinStyle.bsVisitDocument: Global.flag = false; CefDomNode root = document.Root; CwbElement Root = CreateElement(root); if (Global.RootList.ContainsKey(browser.Identifier)) { Global.RootList[ browser.Identifier ] = Root; } else { Global.RootList.Add(browser.Identifier, Root); } string indexPath = "0"; Root.IndexPath = indexPath; AppendAllChildElement(root, Root, indexPath); Global.flag = true; break; case CwbBusinStyle.bsAttachElementEvent: CefDomNode root1 = document.Root; string indexPath1 = "0"; AttachEventHandler(root1, indexPath1, new RSEventListener(_item.elementListener)); Global.flag = true; break; } _businID = CwbBusinStyle.bsNone; }
protected override void OnFocusedNodeChanged(CefBrowser browser, CefFrame frame, CefDomNode node) { Log.Trace("RenderProcessHandler.OnFocusedNodeChanged( browser: {0}, frame: {1}, node: {2} )", browser.Identifier, frame.Identifier, node != null ? node.ElementTagName : "HTML"); base.OnFocusedNodeChanged(browser, frame, node); }
public override bool Read() { // First call to Read if (ReadState == System.Xml.ReadState.Initial) { nodeStack.Push(rootNode); currentNode = rootNode.GetFirstChild(); return(CheckReadStateAndReturn()); } if (xmlReader != null) { var result = xmlReader.Read(); if (result && xmlReader.Depth > 0) { return(result); } else { xmlReader.Close(); textReader.Dispose(); xmlReader = null; textReader = null; } } switch (traverseDirection) { case TraverseDirection.Down: // As long as there're children go down (depth first) if (currentNode.HasChildren) { nodeStack.Push(currentNode); currentNode = currentNode.GetFirstChild(); } else { var parent = nodeStack.Peek(); var lastChild = parent.GetLastChild(); if (currentNode.IsSame(lastChild)) { // Time to move back up nodeStack.Pop(); traverseDirection = TraverseDirection.Up; currentNode.Dispose(); currentNode = parent; } else { // There're still siblings left to visit var nextSibling = currentNode.GetNextSibling(); currentNode.Dispose(); currentNode = nextSibling; } // Avoid double disposal GC.SuppressFinalize(lastChild); } break; case TraverseDirection.Up: // See if we can find siblings (need to have a parent) if (nodeStack.Count > 1) { var parent = nodeStack.Peek(); var lastChild = parent.GetLastChild(); if (currentNode.IsSame(lastChild)) { // No sibling left, go further up nodeStack.Pop(); currentNode.Dispose(); currentNode = parent; } else { // There's a sibling, try to traverse down again (depth first) traverseDirection = TraverseDirection.Down; var nextSibling = currentNode.GetNextSibling(); currentNode.Dispose(); currentNode = nextSibling; } // Avoid double disposal GC.SuppressFinalize(lastChild); } else { // No parent left, we have to be the root -> EOF currentNode.Dispose(); currentNode = null; readState = System.Xml.ReadState.EndOfFile; return(false); } break; } if (currentNode != null) { // See if this node defines a new namespace if (currentNode.HasElementAttributes()) { attributeMap = currentNode.GetElementAttributes(); switch (traverseDirection) { case TraverseDirection.Down: for (int i = 0; i < attributeMap.Count; i++) { string key, value; if (attributeMap.TryGetKey(i, out key) && attributeMap.TryGetValue(i, out value)) { if (key.StartsWith("xmlns")) { var prefix = GetPrefix(key); namespaceManager.AddNamespace(prefix, value); } } } namespaceManager.PushScope(); break; case TraverseDirection.Up: namespaceManager.PopScope(); break; } } else { attributeMap = null; } } return(CheckReadStateAndReturn()); }