public int UpdateUI() { //return 0; //Debug.WriteLine("UpdateUI"); if (this.mFullyActive && (this.m_document != null) && (this.container.mDesignMode == true)) { try { HTMLDocument thisdoc = (HTMLDocument)m_document; //we need IDisplayServices to get the caret position IDisplayServices ds = (IDisplayServices)thisdoc; if (ds == null) { return(HRESULT.S_OK); } IHTMLCaret caret; int iRetVal = ds.GetCaret(out caret); if (caret == null) { return(HRESULT.S_OK); } win32POINT pt = new win32POINT(); caret.GetLocation(out pt, true); IHTMLDocument2 htmldoc = (IHTMLDocument2)this.m_document; IHTMLElement el = htmldoc.ElementFromPoint(pt.x, pt.y); if (el == null) { return(HRESULT.S_OK); } container.mcurrentElement = el; container.InvokeUpdateUI(el); } catch (Exception e) { Debug.WriteLine(e.Message + e.StackTrace); } } //should always return S_OK unless error return(HRESULT.S_OK); }
private static Bitmap GetElementPreviewImage(IHTMLDocument3 doc3, IHTMLElement element, int snapshotWidth, int snapshotHeight) { try { // @RIBBON TODO: Need to make this work for RTL as well. IDisplayServices displayServices = ((IDisplayServices)doc3); element.scrollIntoView(true); tagPOINT offset = new tagPOINT(); offset.x = 0; offset.y = 0; displayServices.TransformPoint(ref offset, _COORD_SYSTEM.COORD_SYSTEM_CONTENT, _COORD_SYSTEM.COORD_SYSTEM_GLOBAL, element); using (Bitmap snapshotAfter = HtmlScreenCaptureCore.TakeSnapshot((IViewObject)doc3, snapshotWidth, snapshotHeight)) { //snapshotAfter.Save(@"c:\temp\snapshot" + element.id + ".bmp"); Rectangle elementRect; elementRect = new Rectangle(Math.Max(2, offset.x), 2, Math.Min(element.offsetWidth, element.offsetParent.offsetWidth), element.offsetHeight); if (element.offsetWidth <= 0 || element.offsetHeight <= 0) { return(null); } Bitmap cropped = ImageHelper2.CropBitmap(snapshotAfter, elementRect); //cropped.Save(@"c:\temp\snapshot" + element.id + ".cropped.bmp"); return(cropped); } } catch (Exception ex) { Trace.Fail("Failed to get element preview image for id " + element.id + ": " + ex); return(null); } }