/// <summary>
        /// Try to extract the EditUri (RSD file URI) from the passed DOM
        /// </summary>
        /// <param name="weblogDOM"></param>
        /// <returns></returns>
        private static string ExtractEditUri(string homepageUrl, IHTMLDocument2 weblogDOM)
        {
            // look in the first HEAD tag
            IHTMLElementCollection headElements = ((IHTMLDocument3)weblogDOM).getElementsByTagName("HEAD");

            if (headElements.length > 0)
            {
                // get the first head element
                IHTMLElement2 firstHeadElement = (IHTMLElement2)headElements.item(0, 0);

                // look for link tags within the head
                foreach (IHTMLElement element in firstHeadElement.getElementsByTagName("LINK"))
                {
                    IHTMLLinkElement linkElement = element as IHTMLLinkElement;
                    if (linkElement != null)
                    {
                        string linkRel = linkElement.rel;
                        if (linkRel != null && (linkRel.ToUpperInvariant().Equals("EDITURI")))
                        {
                            return(UrlHelper.UrlCombineIfRelative(homepageUrl, linkElement.href));
                        }
                    }
                }
            }

            // couldn't find one
            return(null);
        }
Пример #2
0
        public static int GetParentContainerBlockWidth(MarkupRange markupRange)
        {
            IHTMLElement2 parentBlock = markupRange.Start.GetParentElement(ElementFilters.BLOCK_OR_TABLE_CELL_ELEMENTS) as IHTMLElement2;

            if (parentBlock != null)
            {
                // TODO: we would like to always clientWidth here however for an empty block element this will
                // be zero. So in this case we use scrollWidth which should be a proxy except in the case where
                // the parent element has a horizontal scroll bar (in which case we may insert a table which
                // is worst case too narrow). What we "should" do is insert and remove some bogus content
                // within the block element to force its clientWidth to the right value.
                int blockWidth = parentBlock.clientWidth;

                if (blockWidth == 0)
                {
                    blockWidth = parentBlock.scrollWidth;
                }

                return(blockWidth);
            }
            else
            {
                return(0);
            }
        }
Пример #3
0
        private void CorrectFrameLocations(IHTMLElement frameElement)
        {
            long         x       = 0;
            long         y       = 0;
            IHTMLElement element = frameElement;

            do
            {
                x      += element.offsetLeft;
                y      += element.offsetTop;
                element = element.offsetParent;
            } while (element != null);
            Point         elementLocation         = new Point((int)x, (int)y);
            IHTMLElement2 element2                = (IHTMLElement2)frameElement;
            IHTMLRect     rec                     = element2.getBoundingClientRect();
            Point         elementBoundingLocation = new Point(rec.left, rec.top);

            LOG.DebugFormat("Looking for iframe to correct at {0}", elementBoundingLocation);
            foreach (DocumentContainer foundFrame in frames)
            {
                Point frameLocation = foundFrame.SourceLocation;
                if (frameLocation.Equals(elementBoundingLocation))
                {
                    // Match found, correcting location
                    LOG.DebugFormat("Correcting frame from {0} to {1}", frameLocation, elementLocation);
                    foundFrame.SourceLocation      = elementLocation;
                    foundFrame.DestinationLocation = elementLocation;
                }
                else
                {
                    LOG.DebugFormat("{0} != {1}", frameLocation, elementBoundingLocation);
                }
            }
        }
Пример #4
0
        private bool TermAlreadyLinked(string term, string url)
        {
            IHTMLElement2          bodyElement = (IHTMLElement2)_blogPostHtmlEditorControl.PostBodyElement;
            IHTMLElementCollection aElements   = bodyElement.getElementsByTagName("a");

            foreach (IHTMLElement aElement in aElements)
            {
                try
                {
                    IHTMLAnchorElement anchor = aElement as IHTMLAnchorElement;
                    if (anchor != null && aElement.innerText != null &&
                        aElement.innerText.ToLower(CultureInfo.CurrentCulture) ==
                        term.ToLower(CultureInfo.CurrentCulture) &&
                        anchor.href != null && anchor.href.TrimEnd('/') == url.TrimEnd('/'))
                    {
                        return(true);
                    }
                }
                catch (COMException ex)
                {
                    // Bug 624250: Swallow operation failed exception
                    if (ex.ErrorCode != unchecked ((int)0x80004005))
                    {
                        throw;
                    }
                    else
                    {
                        Trace.WriteLine(ex.ToString());
                    }
                }
            }
            return(false);
        }
Пример #5
0
        private void InstallHTMLHooksForOnchange()
        {
            // Install onchange hook for <input type=password, text, file>.
            String       searchCondition    = String.Format("{0}!=1", CatStudioConstants.HOOKED_BY_REC_ATTR);
            IElementList inputElemNotHooked = this.twebstBrowser.FindAllElements("input", searchCondition);

            for (int i = 0; i < inputElemNotHooked.length; ++i)
            {
                IHTMLElement2 crntNativeElem2 = (IHTMLElement2)inputElemNotHooked[i].nativeElement;
                String        inputType       = ((IHTMLInputElement)crntNativeElem2).type.ToLower();
                IHTMLElement  crntElem        = (IHTMLElement)crntNativeElem2;

                if (("text" == inputType) || ("password" == inputType) || ("file" == inputType))
                {
                    IHTMLWindow2 wnd = ((IHTMLDocument2)crntElem.document).parentWindow;
                    crntNativeElem2.attachEvent("onchange", new HtmlHandler(this.OnHtmlChange, wnd));
                }

                crntElem.setAttribute(CatStudioConstants.HOOKED_BY_REC_ATTR, "1", 0);
            }

            // Install onchange hook for <select>.
            IElementList selectElemNotHooked = this.twebstBrowser.FindAllElements("select", searchCondition);

            InstalHTMLHookOnList(selectElemNotHooked, "onchange");

            // Install onchange hook for <textarea>.
            IElementList textAreaElemNotHooked = this.twebstBrowser.FindAllElements("textarea", searchCondition);

            InstalHTMLHookOnList(textAreaElemNotHooked, "onchange");
        }
Пример #6
0
        /// <summary>
        /// Create a CaptureElement for every element on the page, which can be used by the editor.
        /// </summary>
        /// <returns></returns>
        public CaptureElement CreateCaptureElements(Size documentSize)
        {
            LOG.DebugFormat("CreateCaptureElements for {0}", Name);
            IHTMLElement  baseElement  = document3.documentElement as IHTMLElement;
            IHTMLElement2 baseElement2 = baseElement as IHTMLElement2;
            IHTMLRect     htmlRect     = baseElement2.getBoundingClientRect();

            if (Size.Empty.Equals(documentSize))
            {
                documentSize = new Size(ScrollWidth, ScrollHeight);
            }
            Rectangle baseElementBounds = new Rectangle(DestinationLocation.X + htmlRect.left, DestinationLocation.Y + htmlRect.top, documentSize.Width, documentSize.Height);

            if (baseElementBounds.Width <= 0 || baseElementBounds.Height <= 0)
            {
                // not visisble
                return(null);
            }

            CaptureElement captureBaseElement = new CaptureElement(name, baseElementBounds);

            foreach (IHTMLElement bodyElement in baseElement.children)
            {
                if ("BODY".Equals(bodyElement.tagName))
                {
                    captureBaseElement.Children.AddRange(RecurseElements(bodyElement));
                }
            }
            return(captureBaseElement);
        }
        /// <summary>
        /// Inserts the extended entry break into the editor.
        /// </summary>
        internal void InsertExtendedEntryBreak()
        {
            IHTMLDocument3 doc3       = (IHTMLDocument3)HTMLElement.document;
            IHTMLElement2  entryBreak = (IHTMLElement2)doc3.getElementById(EXTENDED_ENTRY_ID);

            if (entryBreak == null)
            {
                using (IUndoUnit undo = EditorContext.CreateUndoUnit())
                {
                    using (EditorContext.DamageServices.CreateDamageTracker(ElementRange.Clone(), true))
                    {
                        MarkupPointer insertionPoint =
                            EditorContext.MarkupServices.CreateMarkupPointer(EditorContext.Selection.SelectedMarkupRange.Start);

                        //delete the parent block element of the insertion point if it is empty (bug 421500)
                        DeleteInsertionTargetBlockIfEmpty(insertionPoint);

                        IHTMLElement extendedEntryBreak = InsertExtendedEntryBreak(insertionPoint);

                        //reselect the insertion point
                        MarkupRange selection = EditorContext.MarkupServices.CreateMarkupRange();
                        insertionPoint.MoveAdjacentToElement(extendedEntryBreak, _ELEMENT_ADJACENCY.ELEM_ADJ_AfterEnd);
                        MarkupPointerMoveHelper.MoveUnitBounded(
                            insertionPoint, MarkupPointerMoveHelper.MoveDirection.RIGHT,
                            MarkupPointerAdjacency.AfterEnterBlock | MarkupPointerAdjacency.BeforeText
                            , HTMLElement);
                        selection.Start.MoveToPointer(insertionPoint);
                        selection.End.MoveToPointer(insertionPoint);
                        selection.ToTextRange().select();
                    }
                    undo.Commit();
                }
            }
        }
Пример #8
0
        private static IEnumerable <IHTMLElement> FindUsername(IHTMLElement passwordElement)
        {
            IHTMLElement2 root = (IHTMLElement2)FindClosestForm(passwordElement);

            if (root == null)
            {
                root = passwordElement.document.Body;
            }

            if (root != null)
            {
                foreach (IHTMLElement htmlElement in root.getElementsByTagName("input"))
                {
                    if (htmlElement != passwordElement)
                    {
                        string type = htmlElement.getAttribute("type");

                        if (type.ToUpper() != "TEXT" && type.ToUpper() != "EMAIL")
                        {
                            continue;
                        }

                        yield return(htmlElement);
                    }
                }
            }
        }
Пример #9
0
        public void CreateImageCaptcha()
        {
            IHTMLElement2 doc          = (IHTMLElement2)webBrowser1.Document.Body.DomElement;
            var           controlRange = (IHTMLControlRange)((HTMLBody)doc).createControlRange();

            foreach (IHTMLImgElement img in doc.getElementsByTagName("img"))
            {
                controlRange.add((IHTMLControlElement)img);
                controlRange.execCommand("Copy", false, null);
                pictureBoxCaptcha.Image = (Bitmap)Clipboard.GetDataObject().GetData(DataFormats.Bitmap);

                if (pictureBoxCaptcha.Image != null)
                {
                    // si quieres lo puedes salvar asi
                    using (Bitmap bmp = (Bitmap)Clipboard.GetDataObject().GetData(DataFormats.Bitmap))
                    {
                        bmp.Save("CaptchaWebBrowser.bmp");
                    }

                    // Read first frame of gif image
                    using (MagickImage image = new MagickImage("CaptchaWebBrowser.bmp"))
                    {
                        // Save frame as jpg
                        image.Write("CaptchaConvertido.jpg");
                    }
                }
            }
        }
Пример #10
0
        /// <summary>
        /// 要素に対して明示的に指定された属性を取得する
        /// </summary>
        /// <remarks>
        /// HtmlElementが隠ぺいしているMSHTML内のインターフェースから直接取得するため、
        /// HtmlElementでは取得できない属性も含まれる可能性がある。
        /// HtmlElementから取得できるものだけを取得したい場合はExtractUsableAttributesを使用する。
        /// </remarks>
        /// <param name="sourceElement">属性を取り出したい要素</param>
        /// <returns>属性名と属性値のペアリスト</returns>
        public static Dictionary <string, string> ExtractAttributes(HtmlElement sourceElement)
        {
            Dictionary <string, string> extractedAttributes = new Dictionary <string, string>();

            if (sourceElement == null)
            {
                throw new ArgumentNullException("nullが指定されています");
            }
            else if (sourceElement.TagName == "!" || sourceElement.TagName == "?")
            {
                // attributesコレクションを取り出せなくて例外が発生するため
                // 別途処理してしまう。
                return(extractedAttributes);
            }
            else
            {
                IHTMLElement2            domElement = (IHTMLElement2)sourceElement.DomElement;
                IHTMLDOMNode             node       = (IHTMLDOMNode)domElement;
                IHTMLAttributeCollection attributes = (IHTMLAttributeCollection)node.attributes;

                foreach (IHTMLDOMAttribute attribute in attributes)
                {
                    if (attribute.specified)
                    {
                        extractedAttributes.Add(attribute.nodeName.ToUpper(), attribute.nodeValue.ToString());
                    }
                }

                return(extractedAttributes);
            }
        }
        public static string GetFontFamily(IHTMLElement2 element2)
        {
            string fontFamily = element2.currentStyle.fontFamily;
            if (!String.IsNullOrEmpty(fontFamily))
                return fontFamily.Replace('\"', '\'');

            return fontFamily;
        }
Пример #12
0
 // private CTOR
 private HtmlEventProxy(string eventName, IHTMLElement2 htmlElement, EventHandler eventHandler)
 {
     this.eventName = eventName;
     this.htmlElement = htmlElement;
     this.sender = this;
     this.eventHandler = eventHandler;
     Type type = typeof(HtmlEventProxy);
     this.typeIReflectImplementation = type;
 }
 public static void UnsubscribeFrom(this IHTMLElement2 element, HtmlEvents eventType, HtmlEventObject eventObj)
 {
     try
     {
         element?.detachEvent(eventType.Name(), eventObj);
     }
     catch (RemotingException) { }
     catch (UnauthorizedAccessException) { }
 }
Пример #14
0
        public static HtmlEventProxy Create(string eventName, object htmlElement, EventHandler eventHandler)
        {
            IHTMLElement2 elem = (IHTMLElement2)htmlElement;

            HtmlEventProxy newProxy = new HtmlEventProxy(eventName, elem, eventHandler);

            elem.attachEvent(eventName, newProxy);
            return(newProxy);
        }
        private void SynchronizeElementRectangle()
        {
            IHTMLElement2 el = ((IHTMLElement2)HTMLElement);

            SetElementRectangle(new Rectangle(
                                    new Point(0, 0),
                                    new Size(el.clientWidth, el.clientHeight)
                                    ));
        }
 public static void UnsubscribeFrom(this IHTMLElement2 element, string @event, object pdisp)
 {
     try
     {
         element?.detachEvent(@event, pdisp);
     }
     catch (RemotingException) { }
     catch (UnauthorizedAccessException) { }
 }
Пример #17
0
        private static void RemoveDesignTimeBorder(IHTMLTable table, IHTMLElement2 tableElement)
        {
            IHTMLElement element = tableElement as IHTMLElement;

            tableElement.runtimeStyle.borderWidth = element.style.borderWidth;
            tableElement.runtimeStyle.borderColor = element.style.borderColor;
            tableElement.runtimeStyle.borderStyle = element.style.borderStyle;
            (tableElement.runtimeStyle as IHTMLStyle2).borderCollapse = (element.style as IHTMLStyle2).borderCollapse;
        }
 public static void UnsubscribeFrom(this IHTMLElement2 element, EventType eventType, IControlHtmlEvent handlerObj)
 {
     try
     {
         element?.detachEvent(eventType.Name(), handlerObj);
     }
     catch (RemotingException) { }
     catch (UnauthorizedAccessException) { }
 }
        public void DoCapture()
        {
            IHTMLDocument2 doc2  = (IHTMLDocument2)mWb.Document;
            IHTMLDocument3 doc3  = (IHTMLDocument3)mWb.Document;
            IHTMLElement2  body2 = (IHTMLElement2)doc2.body;
            IHTMLElement2  root2 = (IHTMLElement2)doc3.documentElement;

            // Determine dimensions for the image; we could add minWidth here
            // to ensure that we get closer to the minimal width (the width
            // computed might be a few pixels less than what we want).
            int width  = Math.Max(body2.scrollWidth, root2.scrollWidth);
            int height = Math.Max(root2.scrollHeight, body2.scrollHeight);

            // Resize the web browser control
            mWb.SetBounds(0, 0, width, height);

            // Do it a second time; in some cases the initial values are
            // off by quite a lot, for as yet unknown reasons. We could
            // also do this in a loop until the values stop changing with
            // some additional terminating condition like n attempts.
            width  = Math.Max(body2.scrollWidth, root2.scrollWidth);
            height = Math.Max(root2.scrollHeight, body2.scrollHeight);

            //@todo override with fixed values
            Rectangle resolution = System.Windows.Forms.Screen.PrimaryScreen.Bounds;

            width  = resolution.Width;
            height = resolution.Height;
            mWb.SetBounds(0, 0, width, height);

            Bitmap   image = new Bitmap(width, height);
            Graphics g     = Graphics.FromImage(image);

            _RECTL bounds;

            bounds.left   = 0;
            bounds.top    = 0;
            bounds.right  = width;
            bounds.bottom = height;

            IntPtr      hdc = g.GetHdc();
            IViewObject iv  = doc2 as IViewObject;

            // TODO: Write to Metafile instead if requested.

            iv.Draw(1, -1, (IntPtr)0, (IntPtr)0, (IntPtr)0,
                    (IntPtr)hdc, ref bounds, (IntPtr)0, (IntPtr)0, 0);

            g.ReleaseHdc(hdc);
            image.Save(mFile);
            image.Dispose();

            if (mImageDiff != null)
            {
                mImageDiff.run();
            }
        }
        /// <summary>
        /// Walks up the element's parent tree to find the color attached to the element.
        /// </summary>
        /// <param name="getter"></param>
        /// <param name="element"></param>
        /// <returns></returns>
        private static string LookupColor(GetColorDelegate getter, IHTMLElement2 element)
        {
            string color = getter(element);

            if (color == "transparent" && ((IHTMLElement)element).parentElement != null)
            {
                return(LookupColor(getter, (IHTMLElement2)((IHTMLElement)element).parentElement));
            }
            return(color);
        }
Пример #21
0
        // private CTOR
        private HtmlEventProxy(string eventName, IHTMLElement2 htmlElement, EventHandler eventHandler)
        {
            this.eventName    = eventName;
            this.htmlElement  = htmlElement;
            this.sender       = this;
            this.eventHandler = eventHandler;
            Type type = typeof(HtmlEventProxy);

            this.typeIReflectImplementation = type;
        }
        private static string _GetTextColorString(IHTMLElement2 element)
        {
            string color = element.currentStyle.color as string;

            if (color == null)
            {
                color = (string)(element as IHTMLElement).style.color;
            }
            return(color);
        }
Пример #23
0
        private string GetBackgroundColor(WebBrowser browser)
        {
            string color = "red";

            UIThreadHelper.Instance.Invoke(() => {
                IHTMLElement2 body = browser.Document.Body.DomElement as IHTMLElement2;
                color = body.currentStyle.backgroundColor as string;
            });
            return(color);
        }
        public static HtmlEventObject SubscribeTo(this IHTMLElement2 element, HtmlEvents eventType, HtmlEventObject handlerObj)
        {
            try
            {
                element?.attachEvent(eventType.Name(), handlerObj);
            }
            catch (RemotingException) { }
            catch (UnauthorizedAccessException) { }

            return(handlerObj);
        }
        private void _browserControl_DocumentComplete(object sender, BrowserDocumentEventArgs e)
        {
            Timer timer = null;

            try
            {
                // unsubscribe from the event
                _browserControl.DocumentComplete -= new BrowserDocumentEventHandler(_browserControl_DocumentComplete);

                // get the document
                IHTMLDocument2 document = _browserControl.Document as IHTMLDocument2;

                // eliminate borders, scroll bars, and margins
                IHTMLElement element = document.body;
                element.style.borderStyle = "none";
                IHTMLBodyElement body = element as IHTMLBodyElement;
                body.scroll       = "no";
                body.leftMargin   = 0;
                body.rightMargin  = 0;
                body.topMargin    = 0;
                body.bottomMargin = 0;

                // set the width and height of the browser control to the correct
                // values for the snapshot

                // width specified by the caller
                _browserControl.Width = _htmlScreenCaptureCore.ContentWidth;

                if (_htmlScreenCaptureCore.MaximumHeight > 0)
                {
                    _browserControl.Height = _htmlScreenCaptureCore.MaximumHeight;
                }
                else
                {
                    // height of the content calculated based on this width
                    IHTMLElement2 element2 = element as IHTMLElement2;
                    _browserControl.Height = element2.scrollHeight;
                }

                // release UI thread to load the video thumbnail on screen
                // (the Tick may need to fire more than once to allow enough
                // time and message processing for an embedded object to
                // be fully initialized)
                timer          = new Timer();
                timer.Interval = WAIT_INTERVAL;
                timer.Tick    += new EventHandler(timer_Tick);
                timer.Start();
            }
            catch (Exception ex)
            {
                _htmlScreenCaptureCore.SetException(ex);
                CleanupAndExit(timer);
            }
        }
Пример #26
0
 /// <summary>
 /// detach only once (thread safe)
 /// </summary>
 public void Detach()
 {
     lock (this) {
         if (this.htmlElement != null)
         {
             IHTMLElement2 elem = (IHTMLElement2)htmlElement;
             elem.detachEvent(this.eventName, this);
             this.htmlElement = null;
         }
     }
 }
Пример #27
0
        public MarginStyle GetMarginStyleFromHtml(IHTMLElement img)
        {
            IHTMLElement2 img2         = (IHTMLElement2)img;
            int           marginTop    = GetPixels(img2.currentStyle.marginTop as string);
            int           marginRight  = GetPixels(img2.currentStyle.marginRight as string);
            int           marginBottom = GetPixels(img2.currentStyle.marginBottom as string);
            int           marginLeft   = GetPixels(img2.currentStyle.marginLeft as string);
            MarginStyle   margin       = new MarginStyle(marginTop, marginRight, marginBottom, marginLeft, StyleSizeUnit.PX);

            return(margin);
        }
        public override void OnDraw(Graphics g, Rectangle drawBounds, RECT rcBounds, RECT rcUpdate, int lDrawFlags, IntPtr hdc, IntPtr pvDrawObject)
        {
            IHTMLElement2 element2 = HTMLElement as IHTMLElement2;
            //g.DrawRectangle(new Pen(Color.Red, 1), GetPaintRectangle(GetClientRectangle(ELEMENT_REGION.CONTENT), rcBounds));
            //g.DrawRectangle(new Pen(Color.Orange, 1), GetPaintRectangle(GetClientRectangle(ELEMENT_REGION.BORDER), rcBounds));
            //g.DrawRectangle(new Pen(Color.Blue, 1), GetPaintRectangle(GetClientRectangle(ELEMENT_REGION.PADDING), rcBounds));
            //g.DrawRectangle(new Pen(Color.Gold, 1), GetPaintRectangle(GetClientRectangle(ELEMENT_REGION.MARGIN), rcBounds));

            //highlight the line that the caret is currently placed on.
            //Rectangle lineRect = GetPaintRectangle(GetLineClientRectangle(EditorContext.SelectedMarkupRange.Start), rcBounds);
            //g.DrawRectangle(new Pen(Color.Violet, 1), lineRect);
        }
Пример #29
0
    public ElementAdapter( object element )
      : base( element )
    {

      _raw = element;

      _element = element as IHTMLElement;
      _element2 = element as IHTMLElement2;
      _element3 = element as IHTMLElement3;
      _element4 = element as IHTMLElement4;

    }
Пример #30
0
 /// <summary>
 /// detach only once (thread safe)
 /// </summary>
 public void Detach()
 {
     lock (this)
     {
         if (this.htmlElement != null)
         {
             IHTMLElement2 elem = (IHTMLElement2)htmlElement;
             elem.detachEvent(this.eventName, this);
             this.htmlElement = null;
         }
     }
 }
Пример #31
0
 /// <summary>
 /// detach only once (thread safe)
 /// </summary>
 public void Detach()
 {
     lock (this)
     {
         if (_htmlElement != null)
         {
             var elem = _htmlElement;
             elem.detachEvent(_eventName, this);
             _htmlElement = null;
         }
     }
 }
Пример #32
0
        private void InstalHTMLHookOnList(IElementList elemList, String evtName)
        {
            for (int i = 0; i < elemList.length; ++i)
            {
                IHTMLElement2 crntNativeElem2 = (IHTMLElement2)elemList[i].nativeElement;
                IHTMLElement  crntElem        = (IHTMLElement)crntNativeElem2;
                IHTMLWindow2  wnd             = ((IHTMLDocument2)crntElem.document).parentWindow;

                crntNativeElem2.attachEvent(evtName, new HtmlHandler(this.OnHtmlChange, wnd));
                crntElem.setAttribute(CatStudioConstants.HOOKED_BY_REC_ATTR, "1", 0);
            }
        }
Пример #33
0
        /// <summary>
        /// 指定ウィンドウハンドルのIEを制御する
        /// </summary>
        /// <param name="handle">ウィンドウハンドル</param>
        private void SetHandle(IntPtr handle)
        {
            // ウェブブラウザ情報を取得する
            this.webBrowser = GetWebBrowser(handle);
            if (this.webBrowser == null)
            {
                // HTMLDocument情報が取得できなかった
                throw new Exception("ウェブブラウザ情報の取得に失敗");
            }

            // IEのHTML文書を取得する
            var document2 = (IHTMLDocument2)this.webBrowser.Document;
            var document3 = (IHTMLDocument3)this.webBrowser.Document;
            var document6 = (IHTMLDocument6)this.webBrowser.Document;

            using (Disposable.Create(() => ReleaseComObject(document2)))
                using (Disposable.Create(() => ReleaseComObject(document3)))
                    using (Disposable.Create(() => ReleaseComObject(document6)))
                    {
                        // HTMLウィンドウと文書本体を取得
                        this.window = document2.parentWindow;
                        this.body   = (IHTMLElement2)document3.documentElement;
                        if (this.body.clientWidth == 0 && this.body.clientHeight == 0)
                        {
                            // クライアントサイズが0の場合はbodyを参照
                            this.ReleaseComObject(this.body);
                            this.body = (IHTMLElement2)document2.body;
                        }

                        // 文字サイズとズームを等倍にする
                        this.charSizeOriginal = GetCharSize();
                        this.zoomOriginal     = GetZoom();
                        this.SetCharSize(CharSizeMiddle);
                        this.SetZoom(ZoomActual);

                        // クライアント領域のオフセットを取得
                        this.Offset = GetMargin(document6.documentMode.ToString());
                        this.Client = new Rectangle(this.Offset.X, this.Offset.Y, this.body.clientWidth, this.body.clientHeight);

                        // 横スクロールバーが表示中かつ
                        // 「ウィンドウ高さ」と「クライアント高さ」の差分が「水平スクロールバーの高さ」より小さい場合
                        Rectangle wndRect = InteropHelper.GetWindowSize(handle);
                        if (this.IsVisibleScrollbarH && (wndRect.Height - this.Client.Height) < SystemInformation.HorizontalScrollBarHeight)
                        {
                            // ※暫定的にクライアント高さからスクロールバー分を引いて処理する
                            this.Client = new Rectangle(this.Client.X, this.Client.Y, this.Client.Width, this.Client.Height - SystemInformation.HorizontalScrollBarHeight);
                        }

                        // 最後にウィンドウハンドルを登録する
                        this.handle = handle;
                    }
        }
Пример #34
0
        private static void AttachDesignTimeBorder(IHTMLTable table, IHTMLElement2 tableElement)
        {
            // attach design time border
            tableElement.runtimeStyle.borderWidth = "1";
            tableElement.runtimeStyle.borderColor = "#BCBCBC";
            tableElement.runtimeStyle.borderStyle = "dotted";

            // collapse cells if there is no cellspacing
            if ((table.cellSpacing == null) || table.cellSpacing.ToString() != "0")
                (tableElement.runtimeStyle as IHTMLStyle2).borderCollapse = "separate";
            else
                (tableElement.runtimeStyle as IHTMLStyle2).borderCollapse = "collapse";
        }
Пример #35
0
        public static void UpdateDesignTimeBorders(IHTMLTable table, IHTMLElement2 tableElement)
        {
            // don't do anything if there is a css-based border on this element
            if ((tableElement as IHTMLElement).style.borderStyle != null)
                return;

            // don't attach if is there a standard table border
            if (table.border != null && table.border.ToString() != "0")
            {
                RemoveDesignTimeBorder(table, tableElement);
            }
            else
            {
                AttachDesignTimeBorder(table, tableElement);
            }
        }
Пример #36
0
        private object mOldHandler; // store any existing handler that was replace by this one

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Constructor fo object the OnHtmlElementEvent
        /// </summary>
        /// <param name="pHtmlEventHandler"></param>
        /// <param name="pElem">The mshtml.IHTMLElement we are handling the event on</param>
        /// <param name="pOldHandler">When you set an event, you replace any event that was already assigned. 
        /// You pass the current handler (value will be a COM Object type or System.DBNull) as the third 
        /// parameter of the OnHtmlElementEvent constructor so it can be called when an event occurs.</param>
        /// <param name="pEventType">The type of event that occured as a string. (onClick, onChange, etc.</param>
        public OnHtmlElementEvent(HtmlEventHandler pHtmlEventHandler, IHTMLElement2 pElem, object pOldHandler, string pEventType)
        {
            mElem = pElem as mshtml.IHTMLElement;
            mOldHandler = pOldHandler;
            mEventType = pEventType;
            mHandler = pHtmlEventHandler;
        }
 public static string GetComposeSettingsBackgroundColor(IHTMLElement2 element2)
 {
     return GetComposeSettingsColor(element2.currentStyle.backgroundColor);
 }
 public static string GetComposeSettingsForeColor(IHTMLElement2 element2)
 {
     return GetComposeSettingsColor(element2.currentStyle.color);
 }
 public static bool IsOverline(IHTMLElement2 element2)
 {
     return element2.currentStyle.textDecoration != null && element2.currentStyle.textDecoration.Contains("overline");
 }
 private void FocusElement(IHTMLElement2 element, bool selectAll)
 {
     if (element != null)
     {
         try
         {
             element.focus();
         }
         catch (Exception e)
         {
             //This can cause an exception under some weblog styles when some behaviors are attached.  Bug 407544.
             Trace.Fail("Unexpected exception while focusing element", e.ToString());
         }
         if (selectAll)
             SelectAll();
     }
 }
 public static bool IsItalic(IHTMLElement2 element2)
 {
     return element2.currentStyle.fontStyle == "italic" || element2.currentStyle.fontStyle == "oblique";
 }
Пример #42
0
 /// <summary>
 /// Returns the background color string associated with the element.
 /// </summary>
 /// <param name="element"></param>
 /// <returns></returns>
 public static string GetBackgroundColorString(IHTMLElement2 element)
 {
     return LookupColor(new GetColorDelegate(_GetBackgroundColorString), element);
 }
 public static bool IsBold(IHTMLElement2 element2)
 {
     return element2.currentStyle.fontWeight is int
                             ? (int)element2.currentStyle.fontWeight > 400
                             : element2.currentStyle.fontWeight.ToString() == "bold";
 }
Пример #44
0
 /// <summary>
 /// Walks up the element's parent tree to find the color attached to the element.
 /// </summary>
 /// <param name="getter"></param>
 /// <param name="element"></param>
 /// <returns></returns>
 private static string LookupColor(GetColorDelegate getter, IHTMLElement2 element)
 {
     string color = getter(element);
     if (color == "transparent" && ((IHTMLElement)element).parentElement != null)
     {
         return LookupColor(getter, (IHTMLElement2)((IHTMLElement)element).parentElement);
     }
     return color;
 }
Пример #45
0
 private static string _GetTextColorString(IHTMLElement2 element)
 {
     string color = element.currentStyle.color as string;
     if (color == null)
         color = (string)(element as IHTMLElement).style.color;
     return color;
 }
Пример #46
0
 private static void RemoveDesignTimeBorder(IHTMLTable table, IHTMLElement2 tableElement)
 {
     IHTMLElement element = tableElement as IHTMLElement;
     tableElement.runtimeStyle.borderWidth = element.style.borderWidth;
     tableElement.runtimeStyle.borderColor = element.style.borderColor;
     tableElement.runtimeStyle.borderStyle = element.style.borderStyle;
     (tableElement.runtimeStyle as IHTMLStyle2).borderCollapse = (element.style as IHTMLStyle2).borderCollapse;
 }
 public static bool IsStrikeThrough(IHTMLElement2 element2)
 {
     return element2.currentStyle.textDecoration != null && element2.currentStyle.textDecoration.Contains("line-through");
 }
 private void CopyAnchorAttributes(IHTMLElement2 source, IHTMLElement2 destination)
 {
     destination.runtimeStyle.backgroundAttachment = source.currentStyle.backgroundAttachment;
     destination.runtimeStyle.backgroundColor = source.currentStyle.backgroundColor;
     destination.runtimeStyle.backgroundImage = source.currentStyle.backgroundImage;
     destination.runtimeStyle.backgroundPositionX = source.currentStyle.backgroundPositionX;
     destination.runtimeStyle.backgroundPositionY = source.currentStyle.backgroundPositionY;
     destination.runtimeStyle.backgroundRepeat = source.currentStyle.backgroundRepeat;
     destination.runtimeStyle.borderBottomColor = source.currentStyle.borderBottomColor;
     destination.runtimeStyle.borderBottomStyle = source.currentStyle.borderBottomStyle;
     destination.runtimeStyle.borderBottomWidth = source.currentStyle.borderBottomWidth;
     destination.runtimeStyle.borderColor = source.currentStyle.borderColor;
     destination.runtimeStyle.borderLeftColor = source.currentStyle.borderLeftColor;
     destination.runtimeStyle.borderLeftStyle = source.currentStyle.borderLeftStyle;
     destination.runtimeStyle.borderLeftWidth = source.currentStyle.borderLeftWidth;
     destination.runtimeStyle.borderRightColor = source.currentStyle.borderRightColor;
     destination.runtimeStyle.borderRightStyle = source.currentStyle.borderRightStyle;
     destination.runtimeStyle.borderRightWidth = source.currentStyle.borderRightWidth;
     destination.runtimeStyle.borderStyle = source.currentStyle.borderStyle;
     destination.runtimeStyle.borderTopColor = source.currentStyle.borderTopColor;
     destination.runtimeStyle.borderTopStyle = source.currentStyle.borderTopStyle;
     destination.runtimeStyle.borderTopWidth = source.currentStyle.borderTopWidth;
     destination.runtimeStyle.borderWidth = source.currentStyle.borderWidth;
     destination.runtimeStyle.clear = source.currentStyle.clear;
     destination.runtimeStyle.color = source.currentStyle.color;
     destination.runtimeStyle.display = source.currentStyle.display;
     destination.runtimeStyle.fontFamily = source.currentStyle.fontFamily;
     destination.runtimeStyle.fontStyle = source.currentStyle.fontStyle;
     destination.runtimeStyle.fontVariant = source.currentStyle.fontVariant;
     destination.runtimeStyle.fontWeight = source.currentStyle.fontWeight.ToString();
     destination.runtimeStyle.height = source.currentStyle.height;
     destination.runtimeStyle.left = source.currentStyle.left;
     destination.runtimeStyle.letterSpacing = source.currentStyle.letterSpacing;
     destination.runtimeStyle.lineHeight = source.currentStyle.lineHeight;
     destination.runtimeStyle.listStyleImage = source.currentStyle.listStyleImage;
     destination.runtimeStyle.listStylePosition = source.currentStyle.listStylePosition;
     destination.runtimeStyle.listStyleType = source.currentStyle.listStyleType;
     destination.runtimeStyle.margin = source.currentStyle.margin;
     destination.runtimeStyle.marginBottom = source.currentStyle.marginBottom;
     destination.runtimeStyle.marginLeft = source.currentStyle.marginLeft;
     destination.runtimeStyle.marginRight = source.currentStyle.marginRight;
     destination.runtimeStyle.marginTop = source.currentStyle.marginTop;
     ((IHTMLStyle5)destination.runtimeStyle).maxHeight = ((IHTMLCurrentStyle4)(source.currentStyle)).maxHeight;
     ((IHTMLStyle5)destination.runtimeStyle).maxWidth = ((IHTMLCurrentStyle4)(source.currentStyle)).maxWidth;
     ((IHTMLStyle4)destination.runtimeStyle).minHeight = ((IHTMLCurrentStyle3)(source.currentStyle)).minHeight;
     ((IHTMLStyle5)destination.runtimeStyle).minWidth = ((IHTMLCurrentStyle4)(source.currentStyle)).minWidth;
     // IHTMLCurrentStyle5 and IHTMLStyle 6 are only available on IE8 or higher
     if ((source.currentStyle as IHTMLCurrentStyle5) != null && (destination.runtimeStyle as IHTMLStyle6) != null)
     {
         ((IHTMLStyle6)destination.runtimeStyle).outlineColor = ((IHTMLCurrentStyle5)(source.currentStyle)).outlineColor;
         ((IHTMLStyle6)destination.runtimeStyle).outlineStyle = ((IHTMLCurrentStyle5)(source.currentStyle)).outlineStyle;
         // Only available on IE8 or higher.
         // Attempting to query the outline-width directly may throw a COMException with HRESULT E_FAIL
         // If so we just leave it alone, rather than forcing the default value
         try
         {
             ((IHTMLStyle6)destination.runtimeStyle).outlineWidth = ((IHTMLCurrentStyle5)(source.currentStyle)).outlineWidth;
         }
         catch (COMException e)
         {
             // Known issue, just ignore the exception.
             if (e.ErrorCode != HRESULT.E_FAILED)
             {
                 throw;
             }
         }
     }
     destination.runtimeStyle.overflow = source.currentStyle.overflow;
     destination.runtimeStyle.padding = source.currentStyle.padding;
     destination.runtimeStyle.paddingBottom = source.currentStyle.paddingBottom;
     destination.runtimeStyle.paddingLeft = source.currentStyle.paddingLeft;
     destination.runtimeStyle.paddingRight = source.currentStyle.paddingRight;
     destination.runtimeStyle.paddingTop = source.currentStyle.paddingTop;
     destination.runtimeStyle.pageBreakAfter = source.currentStyle.pageBreakAfter;
     destination.runtimeStyle.pageBreakBefore = source.currentStyle.pageBreakBefore;
     ((IHTMLStyle2)destination.runtimeStyle).right = source.currentStyle.right;
     destination.runtimeStyle.styleFloat = source.currentStyle.styleFloat;
     destination.runtimeStyle.textAlign = source.currentStyle.textAlign;
     destination.runtimeStyle.textDecoration = source.currentStyle.textDecoration;
     destination.runtimeStyle.textIndent = source.currentStyle.textIndent;
     destination.runtimeStyle.textTransform = source.currentStyle.textTransform;
     destination.runtimeStyle.top = source.currentStyle.top;
     ((IHTMLStyle2)destination.runtimeStyle).unicodeBidi = source.currentStyle.unicodeBidi;
     destination.runtimeStyle.verticalAlign = source.currentStyle.verticalAlign;
     destination.runtimeStyle.visibility = source.currentStyle.visibility;
     destination.runtimeStyle.whiteSpace = ((IHTMLCurrentStyle3)(source.currentStyle)).whiteSpace;
     destination.runtimeStyle.width = source.currentStyle.width;
     destination.runtimeStyle.wordSpacing = ((IHTMLCurrentStyle3)(source.currentStyle)).wordSpacing;
     destination.runtimeStyle.zIndex = source.currentStyle.zIndex;
 }
Пример #49
0
 protected void ClickElement(IHTMLElement2 e) {
     MoveMouseToElement( e );
     UnsafeNativeMethods.ClickMouse(MouseButtons.Left);
     Application.DoEvents();
     WaitMin();
 }
Пример #50
0
 private static string _GetBackgroundColorString(IHTMLElement2 element)
 {
     return element.currentStyle.backgroundColor as string;
 }
Пример #51
0
 protected void MoveMouseToElement(IHTMLElement2 e2) {
     IHTMLRect       rect    = e2.getBoundingClientRect();
     MoveToPoint( (rect.left + rect.right)/2, (rect.top + rect.bottom)/2 );
     WaitMin();
 }
Пример #52
0
        protected void ClickAreaElement(IHTMLElement2 img, IHTMLElement2 area) {
            IHTMLRect rectImg = img.getBoundingClientRect();
            IHTMLRect rectArea = area.getBoundingClientRect();

            MoveToPoint(
                (rectArea.left + rectArea.right)/2 + img.clientLeft + rectImg.left,
                (rectArea.top + rectArea.bottom)/2 + img.clientTop + rectImg.top );
            WaitMin();
            UnsafeNativeMethods.ClickMouse(MouseButtons.Left);
            Application.DoEvents();
            WaitMin();
        }