void browser_WBMouseMove(object sender, csExWB.HTMLMouseEventArgs e) { if (SelectorOn) { Selector.Highlight((mshtml.IHTMLElement)e.SrcElement); } }
void WebBrower_WBLButtonDown(object sender, csExWB.HTMLMouseEventArgs e) { m_mposX = e.ClientX; m_mposY = e.ClientY; if (e.SrcElement != null) { //if (e.SrcElement.tagName == "HTML") // return; //AllForms.m_frmLog.AppendToLog("cEXWB1_WBLButtonDown==>" + e.SrcElement.tagName); this.Text = e.SrcElement.innerHTML; } else { //AllForms.m_frmLog.AppendToLog("cEXWB1_WBLButtonDown"); } }
void WebBrower_WBLButtonUp(object sender, csExWB.HTMLMouseEventArgs e) { if (e.SrcElement != null) { //user is scrolling using scrollbars //if (e.SrcElement.tagName == "HTML") // return; //If DIV then we can look for an HTML child element //AllForms.m_frmLog.AppendToLog("cEXWB1_WBLButtonUp==>" + e.SrcElement.tagName); TreeNodeEx tnRet = null; foreach (var tn in HtmlTree.Nodes) { var treeNodeEx = tn as TreeNodeEx; var selectedElement = new SelectedElement(); selectedElement.tagName = e.SrcElement.tagName.ToLower(); selectedElement.innerText = e.SrcElement.innerText; tnRet = this.FindNodeExt(treeNodeEx, selectedElement); if (tnRet != null) { break; } } if (tnRet != null) { tnRet.ForeColor = Color.Red; tnRet.Expand(); HtmlTree.SelectedNode = tnRet; var sb = new StringBuilder(); sb.AppendLine("xpath:" + tnRet.HtmlNode.XPath); sb.AppendLine(HtmlAgilityPackHelper.GetStringByXPath(Html, tnRet.HtmlNode.XPath, "|")); richTextBox.Text += sb.ToString(); } } else { //AllForms.m_frmLog.AppendToLog("cEXWB1_WBLButtonUp"); } //Rectangle rt = new Rectangle(m_mposX - 1, m_mposY - 1, 2, 2); //if (rt.Contains(e.ClientX, e.ClientY)) //{ // //AllForms.m_frmLog.AppendToLog("MOUSE CLICKED"); //} }
private bool FireMouseEvent(int ievent) { //Allow default processing bool result = false; IHTMLElement elem = null; m_offsetx = 0; m_offsety = 0; //Get client x + y coordinates of mouse m_clientx = WinApis.GET_X_LPARAM(m_LParam); m_clienty = WinApis.GET_Y_LPARAM(m_LParam); //Determine if Ctrl + Shift are down m_ctrl = ((m_WParam & (int)KeyStateMasks.MK_CONTROL) != 0); m_shift = ((m_WParam & (int)KeyStateMasks.MK_SHIFT) != 0); //Get the main document IHTMLDocument2 pdoc2 = browser.WebbrowserObject.Document as IHTMLDocument2; if (pdoc2 != null) { elem = pdoc2.elementFromPoint(m_clientx, m_clienty); } //Get the tagname if (elem != null) m_tagname = elem.tagName.ToLower(); //Do we have a frame or iframe? if( (!string.IsNullOrEmpty(m_tagname)) && ((m_tagname == "frame") || (m_tagname == "iframe")) ) { IHTMLElement offsetparent = elem.offsetParent; IHTMLElement2 elem2 = null; //Account for offsetLeft, offsetTop, scrollLeft, scrollTop //First get the main document scrolltop and scrollleft IHTMLDocument3 pdoc3 = browser.WebbrowserObject.Document as IHTMLDocument3; if (pdoc3 != null) { elem2 = pdoc3.documentElement as IHTMLElement2; if (elem2 != null) { m_offsetx -= elem2.scrollLeft; m_offsety -= elem2.scrollTop; } } //This is needed if we have a fame elem2 = elem as IHTMLElement2; if (elem2 != null) { m_offsetx -= elem2.scrollLeft; m_offsety -= elem2.scrollTop; } m_offsetx += elem.offsetLeft; m_offsety += elem.offsetTop; //For frame+iframe while (offsetparent != null) { m_offsetx += offsetparent.offsetLeft; m_offsety += offsetparent.offsetTop; offsetparent = offsetparent.offsetParent; } //Cast it to IWebBrowser2 IWebBrowser2 pwb = elem as IWebBrowser2; if (pwb != null) { //Now get the document //If you attempt to access the document via IHTMLFrameBase2.contentWindow //you will get a "Access Denied" exception pdoc2 = pwb.Document as IHTMLDocument2; IHTMLElement loopelem = null; if (pdoc2 != null) { elem = pdoc2.elementFromPoint(m_clientx - m_offsetx, m_clienty - m_offsety); loopelem = elem; //There is only one website that I know of that has so many nested frames //MSDN archive website. while ((loopelem != null) && (loopelem.tagName.ToLower() == "frame" || loopelem.tagName.ToLower() == "iframe")) { pwb = loopelem as IWebBrowser2; if (pwb == null) break; pdoc2 = pwb.Document as IHTMLDocument2; if (pdoc2 == null) break; if (elem.offsetParent != null) { m_offsetx += elem.offsetParent.offsetLeft; m_offsety += elem.offsetParent.offsetTop; } m_offsetx += elem.offsetLeft; m_offsety += elem.offsetTop; loopelem = pdoc2.elementFromPoint(m_clientx - m_offsetx, m_clienty - m_offsety); if (loopelem != null) { elem = loopelem; } } } } } //Set up the event argument HTMLMouseEventArgs args = new HTMLMouseEventArgs( elem, m_clientx, m_clienty, m_ctrl, m_shift, m_offsetx, m_offsety); //Generate the event switch (ievent) { case 1: //LButtonDown browser.WBLButtonDown(browser, args); result = args.Handled; break; case 2: //LButtonUp browser.WBLButtonUp(browser, args); break; case 3: //MouseMove browser.WBMouseMove(browser, args); result = args.Handled; break; default: break; } return result; }