From 310c492da120d4afa128555f7c0eda09a868a030 Mon Sep 17 00:00:00 2001 From: RKrom Date: Wed, 15 Aug 2012 10:32:25 +0000 Subject: [PATCH] Small IE capture stability fixes, still most likely no solution to #3557520 and #3557508. In general the code need to be tested with IE9!!! git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@1988 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4 --- Greenshot/Helpers/IECaptureHelper.cs | 18 ++++++++++++++---- Greenshot/Helpers/IEInterop/IEContainer.cs | 19 +++++++++++-------- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/Greenshot/Helpers/IECaptureHelper.cs b/Greenshot/Helpers/IECaptureHelper.cs index 5aeac1047..d840d5bd1 100644 --- a/Greenshot/Helpers/IECaptureHelper.cs +++ b/Greenshot/Helpers/IECaptureHelper.cs @@ -250,8 +250,8 @@ namespace Greenshot.Helpers { } } } catch (Exception e) { + LOG.ErrorFormat("Major problem: Problem retrieving Document from {0}", ieWindow.Text); LOG.Error(e); - LOG.DebugFormat("Major problem: Problem retrieving Document from {0}", ieWindow.Text); } } @@ -262,7 +262,12 @@ namespace Greenshot.Helpers { returnWindow.GetParent(); // Create the container - returnDocumentContainer = new DocumentContainer(returnDocument2, returnWindow); + try { + returnDocumentContainer = new DocumentContainer(returnDocument2, returnWindow); + } catch (Exception e) { + LOG.Error("Major problem: Problem retrieving Document."); + LOG.Error(e); + } } if (returnDocumentContainer == null && alternativeReturnDocument2 != null) { @@ -270,7 +275,12 @@ namespace Greenshot.Helpers { alternativeReturnWindow.Restore(); alternativeReturnWindow.GetParent(); // Create the container - returnDocumentContainer = new DocumentContainer(alternativeReturnDocument2, alternativeReturnWindow); + try { + returnDocumentContainer = new DocumentContainer(alternativeReturnDocument2, alternativeReturnWindow); + } catch (Exception e) { + LOG.Error("Major problem: Problem retrieving Document."); + LOG.Error(e); + } } return returnDocumentContainer; } @@ -291,7 +301,7 @@ namespace Greenshot.Helpers { /// ICapture with the content (if any) public static ICapture CaptureIE(ICapture capture, WindowDetails windowToCapture) { if (windowToCapture == null) { - return CaptureIE(capture, WindowDetails.GetActiveWindow()); + windowToCapture = WindowDetails.GetActiveWindow(); } // Show backgroundform after retrieving the active window.. BackgroundForm backgroundForm = new BackgroundForm(Language.GetString(LangKey.contextmenu_captureie), Language.GetString(LangKey.wait_ie_capture)); diff --git a/Greenshot/Helpers/IEInterop/IEContainer.cs b/Greenshot/Helpers/IEInterop/IEContainer.cs index b7910df96..0f9c06b86 100644 --- a/Greenshot/Helpers/IEInterop/IEContainer.cs +++ b/Greenshot/Helpers/IEInterop/IEContainer.cs @@ -142,10 +142,14 @@ namespace Greenshot.Helpers.IEInterop { // Check what access method is needed for the document IHTMLDocument5 document5 = (IHTMLDocument5)document2; //compatibility mode affects how height is computed - if ((document3.documentElement != null) && (!document5.compatMode.Equals("BackCompat"))) { - isDTD = true; - } else { - isDTD = false; + isDTD = false; + try { + if ((document3.documentElement != null) && (!document5.compatMode.Equals("BackCompat"))) { + isDTD = true; + } + } catch (Exception ex) { + LOG.Error("Error checking the compatibility mode:"); + LOG.Error(ex); } Rectangle clientRectangle = contentWindow.WindowRectangle; try { @@ -183,17 +187,14 @@ namespace Greenshot.Helpers.IEInterop { } } LOG.DebugFormat("Zoomlevel {0}, {1}", zoomLevelX, zoomLevelY); - } catch (Exception e) { LOG.Warn("Can't get certain properties for documents, using default. due to: ", e); } - LOG.DebugFormat("Calculated location {0} for {1}", startLocation, document2.title); - sourceLocation = new Point(ScaleX((int)startLocation.X), ScaleY((int)startLocation.Y)); - destinationLocation = new Point(ScaleX((int)startLocation.X), ScaleY((int)startLocation.Y)); try { + LOG.DebugFormat("Calculated location {0} for {1}", startLocation, document2.title); if (name == null) { name = document2.title; } @@ -203,6 +204,8 @@ namespace Greenshot.Helpers.IEInterop { url = document2.url; } catch { } + sourceLocation = new Point(ScaleX((int)startLocation.X), ScaleY((int)startLocation.Y)); + destinationLocation = new Point(ScaleX((int)startLocation.X), ScaleY((int)startLocation.Y)); if (parent != null) { return;