protected virtual TestIEDocument[] GetFrames(TestIEDocument root) { if (root != null) { IHTMLDocument doc = root.Document; if (doc != null) { IHTMLDocument[] frames = COMUtil.GetFrames(doc); if (frames != null && frames.Length > 0) { List <TestIEDocument> framesDocs = new List <TestIEDocument>(); foreach (IHTMLDocument frame in frames) { try { TestIEDocument frameDoc = new TestIEDocument(frame as IHTMLDocument2); framesDocs.Add(frameDoc); } catch { } } return(framesDocs.ToArray()); } } } return(null); }
private void CallJavaScript(string callFunctionName, params object[] args) { try { Type typeIOleObject = this.GetType().GetInterface("IOleObject", true); object oleClientSite = typeIOleObject.InvokeMember("GetClientSite", BindingFlags.Instance | BindingFlags.InvokeMethod | BindingFlags.Public, null, this, null); IOleClientSite oleClientSite2 = oleClientSite as IOleClientSite; IOleContainer pObj; oleClientSite2.GetContainer(out pObj); IHTMLDocument pDoc2 = (IHTMLDocument)pObj; object script = pDoc2.Script; try { script.GetType().InvokeMember(callFunctionName, BindingFlags.Instance | BindingFlags.InvokeMethod | BindingFlags.Public, null, script, args); } catch { LogException(new Exception("1.未实现JS方法:" + callFunctionName + ";2.在调用该方法时发生内部错误")); } } catch { } }
/// <summary> /// 调用JS函数 /// </summary> /// <param name="fnName">js函数名</param> /// <param name="args">入参</param> protected void CallJSFun(string fnName, params object[] args) { if (typeIOleObject == null) { typeIOleObject = this.GetType().GetInterface("IOleObject", true); object tmpOldClientSite = typeIOleObject.InvokeMember("GetClientSite", BindingFlags.Instance | BindingFlags.InvokeMethod | BindingFlags.Public, null, this, null); oleClientSite = tmpOldClientSite as IOleClientSite; oleClientSite.GetContainer(out pObj); } //获取页面的Script集合 IHTMLDocument pDoc2 = (IHTMLDocument)pObj; object script = pDoc2.Script; try { //调用JavaScript方法OnScaned并传递参数,因为此方法可能并没有在页面中实现,所以要进行异常处理 script.GetType().InvokeMember(fnName, BindingFlags.Instance | BindingFlags.InvokeMethod | BindingFlags.Public, null, script, args); } catch { } }
internal HtmlDocument(HtmlShimManager shimManager, IHTMLDocument doc) { htmlDocument2 = (IHTMLDocument2)doc; Debug.Assert(NativeHtmlDocument2 != null, "The document should implement IHtmlDocument2"); this.shimManager = shimManager; }
private void Init(IHTMLDocument document, MshtmlMarkupServices markupServices, MarkupRange selectionRange, MarkupRangeFilter filter, DamageFunction damageFunction, bool expandRange) { // save references this.htmlDocument = document; this.markupServices = markupServices; this.selectionRange = selectionRange; this.filter = filter; this.damageFunction = damageFunction; // If the range is already the body, don't expand it or else it will be the whole document if (expandRange) { ExpandRangeToWordBoundaries(selectionRange); } // initialize pointer to beginning of selection range MarkupPointer wordStart = MarkupServices.CreateMarkupPointer(selectionRange.Start); MarkupPointer wordEnd = MarkupServices.CreateMarkupPointer(selectionRange.Start); //create the range for holding the current word. //Be sure to set its gravity so that it stays around text that get replaced. currentWordRange = MarkupServices.CreateMarkupRange(wordStart, wordEnd); currentWordRange.Start.Gravity = _POINTER_GRAVITY.POINTER_GRAVITY_Left; currentWordRange.End.Gravity = _POINTER_GRAVITY.POINTER_GRAVITY_Right; currentVirtualPosition = currentWordRange.End.Clone(); }
/// <summary> /// 向指定HTML文档中附加js脚本。 /// </summary> /// <param name="doc">要安装js脚本的HTML文档顶级节点。</param> /// <param name="code">js脚本代码。</param> public static void AttachScript(IHTMLDocument doc, string code, HtmlElementInsertionOrientation orient) { string position = "beforeEnd"; switch (orient) { case HtmlElementInsertionOrientation.AfterBegin: position = "afterBegin"; break; case HtmlElementInsertionOrientation.AfterEnd: position = "afterEnd"; break; case HtmlElementInsertionOrientation.BeforeBegin: position = "beforeBegin"; break; } IHTMLElement head = GetDocHead(doc); IHTMLElement script = ((IHTMLDocument2)doc).createElement("script"); script.setAttribute("type", "text/javascript"); script.setAttribute("text", code); ((IHTMLElement2)head).insertAdjacentElement(position, script); }
private void button1_Click(object sender, EventArgs e) { if (this.webBrowser1.ReadyState == WebBrowserReadyState.Loading || this.webBrowser1.ReadyState == WebBrowserReadyState.Uninitialized) { MessageBox.Show("Please wait for RadEditor to load first."); return; } //Register a script function to extract editor's html string jsFunction = @" function GetEditorHtml() { return RadEditor1.GetHtml(true); }"; IHTMLDocument doc1 = (IHTMLDocument)this.webBrowser1.Document.DomDocument; HTMLWindow2 iHtmlWindow2 = (HTMLWindow2)doc1.Script; //register iHtmlWindow2.execScript(jsFunction, "javascript"); //call the function to get editor's text try { object res = this.webBrowser1.Document.InvokeScript("GetEditorHtml"); MessageBox.Show(res == null ? "null" : res.ToString(), this.Text); } catch (Exception ex) { MessageBox.Show(ex.ToString(), "RadEditor's text: " + this.Text); } }
private void Init(IHTMLDocument document, MshtmlMarkupServices markupServices, MarkupRange selectionRange, MarkupRangeFilter filter, DamageFunction damageFunction, bool expandRange) { // save references this.htmlDocument = document; this.markupServices = markupServices; this.selectionRange = selectionRange; this.filter = filter; this.damageFunction = damageFunction; // If the range is already the body, don't expand it or else it will be the whole document if (expandRange) ExpandRangeToWordBoundaries(selectionRange); // initialize pointer to beginning of selection range MarkupPointer wordStart = MarkupServices.CreateMarkupPointer(selectionRange.Start); MarkupPointer wordEnd = MarkupServices.CreateMarkupPointer(selectionRange.Start); //create the range for holding the current word. //Be sure to set its gravity so that it stays around text that get replaced. currentWordRange = MarkupServices.CreateMarkupRange(wordStart, wordEnd); currentWordRange.Start.Gravity = _POINTER_GRAVITY.POINTER_GRAVITY_Left; currentWordRange.End.Gravity = _POINTER_GRAVITY.POINTER_GRAVITY_Right; currentVirtualPosition = currentWordRange.End.Clone(); }
public static IHTMLDocument[] GetFrames(IHTMLDocument doc) { if (doc != null) { try { IHTMLDocument2 doc2 = doc as IHTMLDocument2; if (doc2 != null) { IHTMLFramesCollection2 frames = doc2.frames; if (frames != null && frames.length > 0) { List <IHTMLDocument> res = new List <IHTMLDocument>(); for (int i = 0; i < frames.length; i++) { object index = i; IHTMLWindow2 frame = frames.item(ref index) as IHTMLWindow2; IHTMLDocument temp = GetFrameDocument(frame); if (temp != null) { res.Add(temp); } } return(res.ToArray()); } } } catch { } } return(null); }
public static IAccessible IHTMLDocumentToMSAA(IHTMLDocument doc) { if (doc == null) { return(null); } IServiceProvider spServiceProvider = doc as IServiceProvider; if (spServiceProvider == null) { return(null); } object spAccessible; Guid guid = typeof(IAccessible).GUID; int hRes = spServiceProvider.QueryService(ref guid, ref guid, out spAccessible); if (hRes != 0) { return(null); } return(spAccessible as IAccessible); }
/* IHTMLElement GetObjectFromPoint(int x, int y) * return element at expected point. */ public Object GetElementByPoint(int x, int y) { try { IHTMLElement ele = _rootDocument.GetElementByPoint(x, y) as IHTMLElement; IHTMLDocument rootDoc = _rootDocument.Document; IHTMLDocument frameDoc = null; while (ele != null && (ele is IHTMLIFrameElement || ele is IHTMLFrameElement)) { frameDoc = COMUtil.GetFrameDocument(ele as IHTMLFrameBase2); Rectangle rect = WindowsAsstFunctions.GetOffsetPostion(rootDoc, frameDoc); x = x - rect.Left; y = y - rect.Top; ele = (frameDoc as IHTMLDocument2).elementFromPoint(x, y); rootDoc = frameDoc; } if (ele.parentElement is IHTMLAnchorElement) { ele = ele.parentElement; } return(ele); } catch (Exception ex) { throw new ObjectNotFoundException("Can not found object at point: (" + x.ToString() + "," + y.ToString() + "): " + ex.ToString()); } }
public object InvokeScript(IWebBrowser2 wb, string ScriptName, object[] Data) { object oRet = null; if (wb == null) { return(oRet); } IHTMLDocument doc = wb.Document as IHTMLDocument; if (doc == null) { return(oRet); } object oScript = doc.Script; if (oScript == null) { return(oRet); } //Invoke script if (Data == null) { Data = new object[] { } } ; oRet = oScript.GetType().InvokeMember(ScriptName, System.Reflection.BindingFlags.InvokeMethod, null, oScript, Data); return(oRet); }
/// <summary> /// 获取JS变量值 /// </summary> /// <param name="varName"></param> /// <returns></returns> protected object GetJSvar(string varName) { if (typeIOleObject == null) { typeIOleObject = this.GetType().GetInterface("IOleObject", true); object tmpOldClientSite = typeIOleObject.InvokeMember("GetClientSite", BindingFlags.Instance | BindingFlags.InvokeMethod | BindingFlags.Public, null, this, null); oleClientSite = tmpOldClientSite as IOleClientSite; oleClientSite.GetContainer(out pObj); } //获取页面的Script集合 IHTMLDocument pDoc2 = (IHTMLDocument)pObj; object script = pDoc2.Script; try { return(script.GetType().InvokeMember(varName, BindingFlags.GetProperty, null, script, new object[] {})); } catch { return(null); } }
private static void AttachHasJQueryFunction(IHTMLDocument document) { IHTMLElement head = GetDocHead(document); IHTMLElement script = ((IHTMLDocument2)document).createElement("script"); script.setAttribute("type", "text/javascript"); script.setAttribute("text", @"function hasJQuery(){return window.jQuery != null && window.jQuery != undefined;}"); ((IHTMLElement2)head).insertAdjacentElement("beforeEnd", script); }
public static object InvokeScript(IHTMLDocument doc, string scriptName, object[] args) { object result = null; NativeMethods.tagDISPPARAMS tagDISPPARAMS = new NativeMethods.tagDISPPARAMS(); tagDISPPARAMS.rgvarg = IntPtr.Zero; try { IDispatch dispatch = doc.Script as IDispatch; if (dispatch != null) { Guid empty = Guid.Empty; string[] rgszNames = new string[] { scriptName }; int[] array = new int[] { -1 }; int iDsOfNames = dispatch.GetIDsOfNames(ref empty, rgszNames, 1, SafeNativeMethods.GetThreadLCID(), array); if (SafeNativeMethods.Succeeded(iDsOfNames) && array[0] != -1) { if (args != null) { Array.Reverse(args); } tagDISPPARAMS.rgvarg = ((args == null) ? IntPtr.Zero : SafeNativeMethods.ArrayToVARIANTVector(args)); tagDISPPARAMS.cArgs = ((args == null) ? 0 : args.Length); tagDISPPARAMS.rgdispidNamedArgs = IntPtr.Zero; tagDISPPARAMS.cNamedArgs = 0; object[] array2 = new object[1]; if (dispatch.Invoke(array[0], ref empty, SafeNativeMethods.GetThreadLCID(), 1, tagDISPPARAMS, array2, new NativeMethods.tagEXCEPINFO(), null) == 0) { result = array2[0]; } } } } catch (Exception ex) { if (ClientUtils.IsSecurityOrCriticalException(ex)) { throw; } } finally { if (tagDISPPARAMS.rgvarg != IntPtr.Zero) { SafeNativeMethods.FreeVARIANTVector(tagDISPPARAMS.rgvarg, args.Length); } } return(result); }
/// <summary> /// 查询指定HTML文档中是否可执行jQuery。 /// </summary> /// <param name="document">要查询的HTML文档。</param> /// <returns></returns> public static bool HasJQuery(IHTMLDocument document) { object result = InvokeScript(document, "hasJQuery"); if (result == null) { AttachHasJQueryFunction(document); result = InvokeScript(document, "hasJQuery"); } return(result != null && (bool)result); }
private void InitializeSubDocument(IHTMLDocument document) { foreach (IHTMLElement item in ((IHTMLDocument3)document).getElementsByTagName("IFRAME")) { try { subFrameDocument.Add(((IHTMLFrameBase2)item).contentWindow.document); InitializeSubDocument(((IHTMLFrameBase2)item).contentWindow.document); } catch (UnauthorizedAccessException) { } } }
/// <summary> /// 向指定HTML文档中安装jQuery。 /// </summary> /// <param name="document">要安装jQuery的HTML文档顶级节点。</param> public static void InstallJQuery(IHTMLDocument document, bool force) { IHTMLElement head = GetDocHead(document); if (force || HasJQuery(document) == false) { IHTMLElement script = ((IHTMLDocument2)document).createElement("script"); script.setAttribute("type", "text/javascript"); script.setAttribute("text", jQueryHelper.jQuery_1_11_1); ((IHTMLElement2)head).insertAdjacentElement("beforeEnd", script); } }
public DocumentAdapter(object document) { //_documentUri = documentUri; _raw = document; _document = document as IHTMLDocument; _document2 = document as IHTMLDocument2; _document3 = document as IHTMLDocument3; _document4 = document as IHTMLDocument4; _document5 = document as IHTMLDocument5; }
public DocumentAdapter( object document ) { //_documentUri = documentUri; _raw = document; _document = document as IHTMLDocument; _document2 = document as IHTMLDocument2; _document3 = document as IHTMLDocument3; _document4 = document as IHTMLDocument4; _document5 = document as IHTMLDocument5; }
private void bindIFrameHandler(IHTMLDocument idoc) { DHTMLEventHandler onIframeClick = new DHTMLEventHandler(idoc as HTMLDocument); DHTMLEventHandler onIframeMouseOver = new DHTMLEventHandler(idoc as HTMLDocument); DHTMLEventHandler onIframeMouseOut = new DHTMLEventHandler(idoc as HTMLDocument); onIframeClick.Handler += new DHTMLEvent(this.onIframeClick); onIframeMouseOver.Handler += new DHTMLEvent(this.OnMouseOver); onIframeMouseOut.Handler += new DHTMLEvent(this.OnMouseOut); ((mshtml.DispHTMLDocument)idoc).onmouseup = onIframeClick; ((mshtml.DispHTMLDocument)idoc).onmouseover = onIframeMouseOver; ((mshtml.DispHTMLDocument)idoc).onmouseout = onIframeMouseOut; }
public static Rectangle GetOffsetPostion(IHTMLDocument root, IHTMLDocument frame) { if (root != null && frame != null) { Rectangle rootPosition = COMUtil.GetIHTMLDocumentPosition(root); Rectangle framePosition = COMUtil.GetIHTMLDocumentPosition(frame); int left = framePosition.Left - rootPosition.Left; int top = framePosition.Top - rootPosition.Top; return(new Rectangle(left, top, framePosition.Width, framePosition.Height)); } return(new Rectangle()); }
private static IHTMLElement GetDocHead(IHTMLDocument doc) { IHTMLElementCollection collection = ((IHTMLDocument3)doc).getElementsByTagName("html"); IHTMLElement head = null; if (collection != null && collection.length > 0) { head = collection.item(0) as IHTMLElement; } else { head = ((IHTMLDocument2)doc).body; } return(head); }
public static IHTMLDocument WithContent(this IHTMLDocument document, params object[] content) { document.open("text/html", "replace"); var doc = new XElement("body"); doc.Add(new XAttribute("style", "border: 0; margin: 0; padding: 0;")); doc.Add(content); document.write(doc.ToString()); document.close(); return(document); }
public static Rectangle GetIHTMLDocumentPosition(IHTMLDocument doc) { if (doc != null) { IAccessible pAcc = IHTMLDocumentToMSAA(doc); if (pAcc != null) { int left, top, width, height; pAcc.accLocation(out left, out top, out width, out height, 0); return(new Rectangle(left, top, width, height)); } } return(new Rectangle(0, 0, 0, 0)); }
private void PrintDomBegin() { if (web1.Document != null) { IHTMLElementCollection elemColl = null; IHTMLDocument doc = (IHTMLDocument)web1.Document; if (doc != null) { // elemColl = doc.get .getElementsByTagName("HTML"); // String str = PrintDom(elemColl, new System.Text.StringBuilder(), 0); // web1.doc .DocumentText = str; //web1.Document. = str; } } }
/// <summary> /// Initialize word range for the specified markup-range within the document /// </summary> public MshtmlWordRange(IHTMLDocument document, bool useDocumentSelectionRange, MarkupRangeFilter filter, DamageFunction damageFunction) { MshtmlMarkupServices markupServices = new MshtmlMarkupServices((IMarkupServicesRaw)document); IHTMLDocument2 document2 = (IHTMLDocument2)document; MarkupRange markupRange; if (useDocumentSelectionRange) { markupRange = markupServices.CreateMarkupRange(document2.selection); } else { // TODO: Although this works fine, it would be better to only spellcheck inside editable regions. markupRange = markupServices.CreateMarkupRange(document2.body, false); } Init(document, markupServices, markupRange, filter, damageFunction, useDocumentSelectionRange); }
public void InitializeSubDocument(IHTMLDocument document) { IHTMLDocument3 buffer = document as IHTMLDocument3; foreach (IHTMLElement item in buffer.getElementsByTagName("IFRAME")) { try { IHTMLFrameBase2 ele = item as IHTMLFrameBase2; IHTMLDocument subDoc = ele.contentWindow.document; subFrame.Add(subDoc); InitializeSubDocument(ele.contentWindow.document); } catch (UnauthorizedAccessException) { //권한 에러는 무시 } } }
private void findIFrame(IHTMLWindow2 frame) { if (frame.frames.length == 0) { return; } object j; for (int i = 0; i < frame.frames.length; i++) { j = i; IHTMLWindow2 childframe = frame.frames.item(ref j) as IHTMLWindow2; IHTMLDocument idoc = CodecentrixSample.CrossFrameIE.GetDocumentFromWindow(childframe); bindIFrameHandler(idoc); findIFrame(childframe); } }
public static void WhenContentReady(this IHTMLDocument doc, Action <IHTMLBody> y) { if (doc.body != null) { y(doc.body); } else { new Timer( t => { if (doc.body == null) { return; } t.Stop(); y(doc.body); } ).StartInterval(15); } }
/// <summary> /// 文档加载完成触发事件 /// </summary> /// <param name="pDisp"></param> /// <param name="URL"></param> public void OnDocumentComplete(object pDisp, ref object URL) { document = (HTMLDocument)webBrowser.Document; HTMLDocument doc = this.document as HTMLDocument; //拿到HTML页面的Document bindHandler(doc); //给页面绑定事件 object j; //变量得到的document是否为iframe框架元素内 for (int i = 0; i < doc.parentWindow.frames.length; i++) { j = i; IHTMLWindow2 frame = doc.frames.item(ref j) as IHTMLWindow2; IHTMLDocument idoc = CodecentrixSample.CrossFrameIE.GetDocumentFromWindow(frame); bindIFrameHandler(idoc); //绑定iframe下的文档 findIFrame(frame); } insertScript(); //插入JS语句 }
/// <summary> /// Attaches runtime defined styles that can be used to tweak the editing /// behavior of the editing template. /// </summary> /// <param name="document"></param> private void AttachEditingStyles(IHTMLDocument document) { IHTMLDocument3 doc3 = (IHTMLDocument3)document; IHTMLElementCollection c = doc3.getElementsByTagName("HEAD"); IHTMLElement head = (IHTMLElement)c.item(0, 0); MarkupPointer insertionPoint = MarkupServices.CreateMarkupPointer(head, _ELEMENT_ADJACENCY.ELEM_ADJ_BeforeEnd); int major; int minor; BrowserHelper.GetInstalledVersion(out major, out minor); string postTitleStyles = "margin: 0px 0px 10px 0px; padding: 0px; border: 0px;"; //add some space btwn the title and body //set a minimum height for the body element so that it takes up a larger space when its empty. string postBodyStyles = String.Format(CultureInfo.InvariantCulture, "margin: 0px; padding: 0px; border: 0px; {0}", _postBodyInlineStyle); string defaultCssStyles = ".postTitle {" + postTitleStyles + "} .postBody {" + postBodyStyles + "}"; string style = String.Format(CultureInfo.InvariantCulture, "<style>{0}</style>", defaultCssStyles); MarkupServices.InsertHtml(style, insertionPoint); RemoveProblematicEditingStyles(); //bug 297804: on IE7 beta3, updating the head styles doesn't update the display of the rendered document, //so we need to invalidate the postBody layout. InvalidatePostBodyElement(); }
public ScrapNode(IHTMLDocument document) { this.document = document; InitializeSubDocument(document); }
/// <summary> /// The event object passed to the OnHtmlElementEvent handler. /// </summary> /// <param name="pElem">The element that caused the event as a mshtml.IHTMLElement</param> /// <param name="pEventType">A string representing the type of event that occured. (onClick, onChange, etc)</param> /// <param name="pBubbled">A boolean. If true there was a handler assigned to this event other than this one and /// was executed before processing this handler. Otherwise, there was no handler /// other than this one assigned to this event</param> public HtmlElementEventArgs(IHTMLElement pElem, string pEventType, Boolean pBubbled) { srcElement = pElem; owningDocument = (IHTMLDocument)pElem.document; eventType = pEventType; bubbled = pBubbled; }
/// <summary> /// Initialize word range for the specified markup-range within the document /// </summary> public MshtmlWordRange(IHTMLDocument document, MarkupRange markupRange, MarkupRangeFilter filter, DamageFunction damageFunction) { MshtmlMarkupServices markupServices = new MshtmlMarkupServices((IMarkupServicesRaw)document); Init(document, markupServices, markupRange, filter, damageFunction, true); }
public static IHTMLDocument[] GetFrames(IHTMLDocument doc) { if (doc != null) { try { IHTMLDocument2 doc2 = doc as IHTMLDocument2; if (doc2 != null) { IHTMLFramesCollection2 frames = doc2.frames; if (frames != null && frames.length > 0) { List<IHTMLDocument> res = new List<IHTMLDocument>(); for (int i = 0; i < frames.length; i++) { object index = i; IHTMLWindow2 frame = frames.item(ref index) as IHTMLWindow2; IHTMLDocument temp = GetFrameDocument(frame); if (temp != null) { res.Add(temp); } } return res.ToArray(); } } } catch { } } return null; }
public static Rectangle GetIHTMLDocumentPosition(IHTMLDocument doc) { if (doc != null) { IAccessible pAcc = IHTMLDocumentToMSAA(doc); if (pAcc != null) { int left, top, width, height; pAcc.accLocation(out left, out top, out width, out height, 0); return new Rectangle(left, top, width, height); } } return new Rectangle(0, 0, 0, 0); }
/// <summary> /// Disambiguates a set of title regions to determine which should be editable based on proximity to the main post body element. /// </summary> /// <param name="bodyElement"></param> /// <param name="doc"></param> /// <param name="titleElements"></param> /// <returns>The title region in closest proximity to the post body element.</returns> protected static IHTMLElement GetPrimaryEditableTitleElement(IHTMLElement bodyElement, IHTMLDocument doc, IHTMLElement[] titleElements) { IHTMLDocument2 doc2 = (IHTMLDocument2)doc; IHTMLElement titleElement = titleElements[0]; if (titleElements.Length > 1) { try { MshtmlMarkupServices markupServices = new MshtmlMarkupServices((IMarkupServicesRaw)doc2); MarkupRange bodyRange = markupServices.CreateMarkupRange(bodyElement, true); MarkupPointer titlePointer = null; MarkupPointer tempPointer = markupServices.CreateMarkupPointer(); foreach (IHTMLElement title in titleElements) { tempPointer.MoveAdjacentToElement(title, _ELEMENT_ADJACENCY.ELEM_ADJ_AfterBegin); if (titlePointer == null) titlePointer = markupServices.CreateMarkupPointer(title, _ELEMENT_ADJACENCY.ELEM_ADJ_AfterBegin); else { tempPointer.MoveAdjacentToElement(title, _ELEMENT_ADJACENCY.ELEM_ADJ_AfterBegin); if (tempPointer.IsLeftOf(bodyRange.End) && tempPointer.IsRightOf(titlePointer)) { //the temp pointer is closer to the body element, so assume it is more appropriate //to use as the title. titleElement = title; titlePointer.MoveToPointer(tempPointer); } } } } catch (COMException ex) { Trace.WriteLine("Failed to differentiate between multiple nodes with title text, using the first node. Exception: " + ex); } catch (InvalidCastException ex) { Trace.WriteLine("Failed to differentiate between multiple nodes with title text, using the first node. Exception: " + ex); } } return titleElement; }
public static IAccessible IHTMLDocumentToMSAA(IHTMLDocument doc) { if (doc == null) { return null; } IServiceProvider spServiceProvider = doc as IServiceProvider; if (spServiceProvider == null) { return null; } object spAccessible; Guid guid = typeof(IAccessible).GUID; int hRes = spServiceProvider.QueryService(ref guid, ref guid, out spAccessible); if (hRes != 0) { return null; } return spAccessible as IAccessible; }
public static Rectangle GetOffsetPostion(IHTMLDocument root, IHTMLDocument frame) { if (root != null && frame != null) { Rectangle rootPosition = COMUtil.GetIHTMLDocumentPosition(root); Rectangle framePosition = COMUtil.GetIHTMLDocumentPosition(frame); int left = framePosition.Left - rootPosition.Left; int top = framePosition.Top - rootPosition.Top; return new Rectangle(left, top, framePosition.Width, framePosition.Height); } return new Rectangle(); }