mirror of
https://github.com/greenshot/greenshot
synced 2025-08-14 02:37:03 -07:00
Merge remote-tracking branch 'remotes/origin/master' into release/1.2.9
This commit is contained in:
commit
0323705513
276 changed files with 5382 additions and 3666 deletions
|
@ -26,33 +26,31 @@ using System.Runtime.InteropServices;
|
|||
|
||||
using GreenshotPlugin.Core;
|
||||
using Greenshot.Interop.IE;
|
||||
using Greenshot.IniFile;
|
||||
using log4net;
|
||||
using IServiceProvider = Greenshot.Interop.IServiceProvider;
|
||||
|
||||
namespace Greenshot.Helpers.IEInterop {
|
||||
public class DocumentContainer {
|
||||
private static ILog LOG = LogManager.GetLogger(typeof(DocumentContainer));
|
||||
private static CoreConfiguration configuration = IniConfig.GetIniSection<CoreConfiguration>();
|
||||
private static readonly ILog LOG = LogManager.GetLogger(typeof(DocumentContainer));
|
||||
private const int E_ACCESSDENIED = unchecked((int)0x80070005L);
|
||||
private static readonly Guid IID_IWebBrowserApp = new Guid("0002DF05-0000-0000-C000-000000000046");
|
||||
private static readonly Guid IID_IWebBrowser2 = new Guid("D30C1661-CDAF-11D0-8A3E-00C04FC9E26E");
|
||||
private static int counter = 0;
|
||||
private int id = counter++;
|
||||
private IHTMLDocument2 document2;
|
||||
private IHTMLDocument3 document3;
|
||||
private Point sourceLocation;
|
||||
private Point destinationLocation;
|
||||
private Point startLocation = Point.Empty;
|
||||
private Rectangle viewportRectangle = Rectangle.Empty;
|
||||
private string name = null;
|
||||
private string url;
|
||||
private bool isDTD;
|
||||
private DocumentContainer parent;
|
||||
private WindowDetails contentWindow;
|
||||
private double zoomLevelX = 1;
|
||||
private double zoomLevelY = 1;
|
||||
private List<DocumentContainer> frames = new List<DocumentContainer>();
|
||||
private static int _counter;
|
||||
private readonly int _id = _counter++;
|
||||
private IHTMLDocument2 _document2;
|
||||
private IHTMLDocument3 _document3;
|
||||
private Point _sourceLocation;
|
||||
private Point _destinationLocation;
|
||||
private Point _startLocation = Point.Empty;
|
||||
private Rectangle _viewportRectangle = Rectangle.Empty;
|
||||
private string _name;
|
||||
private string _url;
|
||||
private bool _isDtd;
|
||||
private DocumentContainer _parent;
|
||||
private WindowDetails _contentWindow;
|
||||
private double _zoomLevelX = 1;
|
||||
private double _zoomLevelY = 1;
|
||||
private readonly IList<DocumentContainer> _frames = new List<DocumentContainer>();
|
||||
|
||||
private DocumentContainer(IHTMLWindow2 frameWindow, WindowDetails contentWindow, DocumentContainer parent) {
|
||||
//IWebBrowser2 webBrowser2 = frame as IWebBrowser2;
|
||||
|
@ -60,22 +58,22 @@ namespace Greenshot.Helpers.IEInterop {
|
|||
IHTMLDocument2 document2 = GetDocumentFromWindow(frameWindow);
|
||||
try {
|
||||
LOG.DebugFormat("frameWindow.name {0}", frameWindow.name);
|
||||
name = frameWindow.name;
|
||||
_name = frameWindow.name;
|
||||
} catch {
|
||||
|
||||
// Ignore
|
||||
}
|
||||
try {
|
||||
LOG.DebugFormat("document2.url {0}",document2.url);
|
||||
} catch {
|
||||
|
||||
// Ignore
|
||||
}
|
||||
try {
|
||||
LOG.DebugFormat("document2.title {0}", document2.title);
|
||||
} catch {
|
||||
|
||||
// Ignore
|
||||
}
|
||||
|
||||
this.parent = parent;
|
||||
_parent = parent;
|
||||
// Calculate startLocation for the frames
|
||||
IHTMLWindow2 window2 = document2.parentWindow;
|
||||
IHTMLWindow3 window3 = (IHTMLWindow3)window2;
|
||||
|
@ -87,13 +85,13 @@ namespace Greenshot.Helpers.IEInterop {
|
|||
releaseCom(window2);
|
||||
releaseCom(window3);
|
||||
|
||||
startLocation = new Point(x, y);
|
||||
_startLocation = new Point(x, y);
|
||||
Init(document2, contentWindow);
|
||||
}
|
||||
|
||||
public DocumentContainer(IHTMLDocument2 document2, WindowDetails contentWindow) {
|
||||
Init(document2, contentWindow);
|
||||
LOG.DebugFormat("Creating DocumentContainer for Document {0} found in window with rectangle {1}", name, SourceRectangle);
|
||||
LOG.DebugFormat("Creating DocumentContainer for Document {0} found in window with rectangle {1}", _name, SourceRectangle);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -112,17 +110,17 @@ namespace Greenshot.Helpers.IEInterop {
|
|||
/// <param name="document2">IHTMLDocument2</param>
|
||||
/// <param name="contentWindow">WindowDetails</param>
|
||||
private void Init(IHTMLDocument2 document2, WindowDetails contentWindow) {
|
||||
this.document2 = document2;
|
||||
this.contentWindow = contentWindow;
|
||||
document3 = document2 as IHTMLDocument3;
|
||||
_document2 = document2;
|
||||
_contentWindow = contentWindow;
|
||||
_document3 = document2 as IHTMLDocument3;
|
||||
// Check what access method is needed for the document
|
||||
IHTMLDocument5 document5 = (IHTMLDocument5)document2;
|
||||
|
||||
//compatibility mode affects how height is computed
|
||||
isDTD = false;
|
||||
_isDtd = false;
|
||||
try {
|
||||
if ((document3.documentElement != null) && (!document5.compatMode.Equals("BackCompat"))) {
|
||||
isDTD = true;
|
||||
if (_document3 != null && (_document3.documentElement != null) && !document5.compatMode.Equals("BackCompat")) {
|
||||
_isDtd = true;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
LOG.Error("Error checking the compatibility mode:");
|
||||
|
@ -133,21 +131,21 @@ namespace Greenshot.Helpers.IEInterop {
|
|||
|
||||
Rectangle clientRectangle = contentWindow.WindowRectangle;
|
||||
try {
|
||||
IHTMLWindow2 window2 = (IHTMLWindow2)document2.parentWindow;
|
||||
IHTMLWindow2 window2 = document2.parentWindow;
|
||||
//IHTMLWindow3 window3 = (IHTMLWindow3)document2.parentWindow;
|
||||
IHTMLScreen screen = window2.screen;
|
||||
IHTMLScreen2 screen2 = (IHTMLScreen2)screen;
|
||||
if (parent != null) {
|
||||
if (_parent != null) {
|
||||
// Copy parent values
|
||||
zoomLevelX = parent.zoomLevelX;
|
||||
zoomLevelY = parent.zoomLevelY;
|
||||
viewportRectangle = parent.viewportRectangle;
|
||||
_zoomLevelX = _parent._zoomLevelX;
|
||||
_zoomLevelY = _parent._zoomLevelY;
|
||||
_viewportRectangle = _parent._viewportRectangle;
|
||||
} else {
|
||||
//DisableScrollbars(document2);
|
||||
|
||||
// Calculate zoom level
|
||||
zoomLevelX = (double)screen2.deviceXDPI/(double)screen2.logicalXDPI;
|
||||
zoomLevelY = (double)screen2.deviceYDPI/(double)screen2.logicalYDPI;
|
||||
_zoomLevelX = screen2.deviceXDPI/(double)screen2.logicalXDPI;
|
||||
_zoomLevelY = screen2.deviceYDPI/(double)screen2.logicalYDPI;
|
||||
|
||||
|
||||
// Calculate the viewport rectangle, needed if there is a frame around the html window
|
||||
|
@ -162,11 +160,11 @@ namespace Greenshot.Helpers.IEInterop {
|
|||
if ((diffX == 4 || diffX >= 20) && (diffY == 4 || diffY >= 20)) {
|
||||
Point viewportOffset = new Point(2, 2);
|
||||
Size viewportSize = new Size(ClientWidth, ClientHeight);
|
||||
viewportRectangle = new Rectangle(viewportOffset, viewportSize);
|
||||
LOG.DebugFormat("viewportRect {0}", viewportRectangle);
|
||||
_viewportRectangle = new Rectangle(viewportOffset, viewportSize);
|
||||
LOG.DebugFormat("viewportRect {0}", _viewportRectangle);
|
||||
}
|
||||
}
|
||||
LOG.DebugFormat("Zoomlevel {0}, {1}", zoomLevelX, zoomLevelY);
|
||||
LOG.DebugFormat("Zoomlevel {0}, {1}", _zoomLevelX, _zoomLevelY);
|
||||
// Release com objects
|
||||
releaseCom(window2);
|
||||
releaseCom(screen);
|
||||
|
@ -177,23 +175,23 @@ namespace Greenshot.Helpers.IEInterop {
|
|||
|
||||
|
||||
try {
|
||||
LOG.DebugFormat("Calculated location {0} for {1}", startLocation, document2.title);
|
||||
if (name == null) {
|
||||
name = document2.title;
|
||||
LOG.DebugFormat("Calculated location {0} for {1}", _startLocation, document2.title);
|
||||
if (_name == null) {
|
||||
_name = document2.title;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOG.Warn("Problem while trying to get document title!", e);
|
||||
}
|
||||
|
||||
try {
|
||||
url = document2.url;
|
||||
_url = document2.url;
|
||||
} catch (Exception e) {
|
||||
LOG.Warn("Problem while trying to get document url!", e);
|
||||
}
|
||||
sourceLocation = new Point(ScaleX((int)startLocation.X), ScaleY((int)startLocation.Y));
|
||||
destinationLocation = new Point(ScaleX((int)startLocation.X), ScaleY((int)startLocation.Y));
|
||||
_sourceLocation = new Point(ScaleX(_startLocation.X), ScaleY(_startLocation.Y));
|
||||
_destinationLocation = new Point(ScaleX(_startLocation.X), ScaleY(_startLocation.Y));
|
||||
|
||||
if (parent != null) {
|
||||
if (_parent != null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
|
@ -203,9 +201,9 @@ namespace Greenshot.Helpers.IEInterop {
|
|||
IHTMLWindow2 frameWindow = frameCollection.item(frame);
|
||||
DocumentContainer frameData = new DocumentContainer(frameWindow, contentWindow, this);
|
||||
// check if frame is hidden
|
||||
if (!frameData.isHidden) {
|
||||
LOG.DebugFormat("Creating DocumentContainer for Frame {0} found in window with rectangle {1}", frameData.name, frameData.SourceRectangle);
|
||||
frames.Add(frameData);
|
||||
if (!frameData.IsHidden) {
|
||||
LOG.DebugFormat("Creating DocumentContainer for Frame {0} found in window with rectangle {1}", frameData._name, frameData.SourceRectangle);
|
||||
_frames.Add(frameData);
|
||||
} else {
|
||||
LOG.DebugFormat("Skipping frame {0}", frameData.Name);
|
||||
}
|
||||
|
@ -223,7 +221,7 @@ namespace Greenshot.Helpers.IEInterop {
|
|||
|
||||
try {
|
||||
// Correct iframe locations
|
||||
foreach (IHTMLElement frameElement in document3.getElementsByTagName("IFRAME")) {
|
||||
foreach (IHTMLElement frameElement in _document3.getElementsByTagName("IFRAME")) {
|
||||
try {
|
||||
CorrectFrameLocations(frameElement);
|
||||
// Clean up frameElement
|
||||
|
@ -264,7 +262,7 @@ namespace Greenshot.Helpers.IEInterop {
|
|||
// Release IHTMLRect
|
||||
releaseCom(rec);
|
||||
LOG.DebugFormat("Looking for iframe to correct at {0}", elementBoundingLocation);
|
||||
foreach(DocumentContainer foundFrame in frames) {
|
||||
foreach(DocumentContainer foundFrame in _frames) {
|
||||
Point frameLocation = foundFrame.SourceLocation;
|
||||
if (frameLocation.Equals(elementBoundingLocation)) {
|
||||
// Match found, correcting location
|
||||
|
@ -313,13 +311,13 @@ namespace Greenshot.Helpers.IEInterop {
|
|||
IServiceProvider sp = (IServiceProvider)htmlWindow;
|
||||
|
||||
// Use IServiceProvider.QueryService to get IWebBrowser2 object.
|
||||
Object brws = null;
|
||||
object brws;
|
||||
Guid webBrowserApp = IID_IWebBrowserApp;
|
||||
Guid webBrowser2 = IID_IWebBrowser2;
|
||||
sp.QueryService(ref webBrowserApp, ref webBrowser2, out brws);
|
||||
|
||||
// Get the document from IWebBrowser2.
|
||||
IWebBrowser2 browser = (IWebBrowser2)(brws);
|
||||
IWebBrowser2 browser = (IWebBrowser2)brws;
|
||||
|
||||
return (IHTMLDocument2)browser.Document;
|
||||
} catch (Exception ex2) {
|
||||
|
@ -331,9 +329,9 @@ namespace Greenshot.Helpers.IEInterop {
|
|||
public Color BackgroundColor {
|
||||
get {
|
||||
try {
|
||||
string bgColor = (string)document2.bgColor;
|
||||
string bgColor = (string)_document2.bgColor;
|
||||
if (bgColor != null) {
|
||||
int rgbInt = Int32.Parse(bgColor.Substring(1), NumberStyles.HexNumber);
|
||||
int rgbInt = int.Parse(bgColor.Substring(1), NumberStyles.HexNumber);
|
||||
return Color.FromArgb(rgbInt >> 16, (rgbInt >> 8) & 255, rgbInt & 255);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
|
@ -345,46 +343,46 @@ namespace Greenshot.Helpers.IEInterop {
|
|||
|
||||
public Rectangle ViewportRectangle {
|
||||
get {
|
||||
return viewportRectangle;
|
||||
return _viewportRectangle;
|
||||
}
|
||||
}
|
||||
|
||||
public WindowDetails ContentWindow {
|
||||
get {
|
||||
return contentWindow;
|
||||
return _contentWindow;
|
||||
}
|
||||
}
|
||||
|
||||
public DocumentContainer Parent {
|
||||
get {
|
||||
return parent;
|
||||
return _parent;
|
||||
}
|
||||
set {
|
||||
parent = value;
|
||||
_parent = value;
|
||||
}
|
||||
}
|
||||
|
||||
private int ScaleX(int physicalValue) {
|
||||
return (int)Math.Round(physicalValue * zoomLevelX, MidpointRounding.AwayFromZero);
|
||||
return (int)Math.Round(physicalValue * _zoomLevelX, MidpointRounding.AwayFromZero);
|
||||
}
|
||||
|
||||
private int ScaleY(int physicalValue) {
|
||||
return (int)Math.Round(physicalValue * zoomLevelY, MidpointRounding.AwayFromZero);
|
||||
return (int)Math.Round(physicalValue * _zoomLevelY, MidpointRounding.AwayFromZero);
|
||||
}
|
||||
|
||||
private int UnscaleX(int physicalValue) {
|
||||
return (int)Math.Round(physicalValue / zoomLevelX, MidpointRounding.AwayFromZero);
|
||||
return (int)Math.Round(physicalValue / _zoomLevelX, MidpointRounding.AwayFromZero);
|
||||
}
|
||||
|
||||
private int UnscaleY(int physicalValue) {
|
||||
return (int)Math.Round(physicalValue / zoomLevelY, MidpointRounding.AwayFromZero);
|
||||
return (int)Math.Round(physicalValue / _zoomLevelY, MidpointRounding.AwayFromZero);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set/change an int attribute on a document
|
||||
/// </summary>
|
||||
public void setAttribute(string attribute, int value) {
|
||||
setAttribute(attribute, value.ToString());
|
||||
public void SetAttribute(string attribute, int value) {
|
||||
SetAttribute(attribute, value.ToString());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -392,14 +390,12 @@ namespace Greenshot.Helpers.IEInterop {
|
|||
/// </summary>
|
||||
/// <param name="attribute">Attribute to set</param>
|
||||
/// <param name="value">Value to set</param>
|
||||
/// <param name="document2">The IHTMLDocument2</param>
|
||||
/// <param name="document3">The IHTMLDocument3</param>
|
||||
public void setAttribute(string attribute, string value) {
|
||||
public void SetAttribute(string attribute, string value) {
|
||||
IHTMLElement element = null;
|
||||
if (!isDTD) {
|
||||
element = document2.body;
|
||||
if (!_isDtd) {
|
||||
element = _document2.body;
|
||||
} else {
|
||||
element = document3.documentElement;
|
||||
element = _document3.documentElement;
|
||||
}
|
||||
element.setAttribute(attribute, value, 1);
|
||||
// Release IHTMLElement com object
|
||||
|
@ -410,18 +406,15 @@ namespace Greenshot.Helpers.IEInterop {
|
|||
/// Get the attribute from a document
|
||||
/// </summary>
|
||||
/// <param name="attribute">Attribute to get</param>
|
||||
/// <param name="document2">The IHTMLDocument2</param>
|
||||
/// <param name="document3">The IHTMLDocument3</param>
|
||||
/// <returns>object with the attribute value</returns>
|
||||
public object getAttribute(string attribute) {
|
||||
IHTMLElement element = null;
|
||||
object retVal = 0;
|
||||
if (!isDTD) {
|
||||
element = document2.body;
|
||||
public object GetAttribute(string attribute) {
|
||||
IHTMLElement element;
|
||||
if (!_isDtd) {
|
||||
element = _document2.body;
|
||||
} else {
|
||||
element = document3.documentElement;
|
||||
element = _document3.documentElement;
|
||||
}
|
||||
retVal = element.getAttribute(attribute, 1);
|
||||
var retVal = element.getAttribute(attribute, 1);
|
||||
// Release IHTMLElement com object
|
||||
releaseCom(element);
|
||||
return retVal;
|
||||
|
@ -430,30 +423,30 @@ namespace Greenshot.Helpers.IEInterop {
|
|||
/// <summary>
|
||||
/// Get the attribute as int from a document
|
||||
/// </summary>
|
||||
public int getAttributeAsInt(string attribute) {
|
||||
int retVal = (int)getAttribute(attribute);
|
||||
public int GetAttributeAsInt(string attribute) {
|
||||
int retVal = (int)GetAttribute(attribute);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
public int ID {
|
||||
get {
|
||||
return id;
|
||||
return _id;
|
||||
}
|
||||
}
|
||||
|
||||
public string Name {
|
||||
get {
|
||||
return name;
|
||||
return _name;
|
||||
}
|
||||
}
|
||||
|
||||
public string Url {
|
||||
get {
|
||||
return url;
|
||||
return _url;
|
||||
}
|
||||
}
|
||||
|
||||
public bool isHidden {
|
||||
public bool IsHidden {
|
||||
get {
|
||||
return ClientWidth == 0 || ClientHeight == 0;
|
||||
}
|
||||
|
@ -461,34 +454,34 @@ namespace Greenshot.Helpers.IEInterop {
|
|||
|
||||
public int ClientWidth {
|
||||
get {
|
||||
return ScaleX(getAttributeAsInt("clientWidth"));
|
||||
return ScaleX(GetAttributeAsInt("clientWidth"));
|
||||
}
|
||||
}
|
||||
|
||||
public int ClientHeight {
|
||||
get {
|
||||
return ScaleY(getAttributeAsInt("clientHeight"));
|
||||
return ScaleY(GetAttributeAsInt("clientHeight"));
|
||||
}
|
||||
}
|
||||
|
||||
public int ScrollWidth {
|
||||
get {
|
||||
return ScaleX(getAttributeAsInt("scrollWidth"));
|
||||
return ScaleX(GetAttributeAsInt("scrollWidth"));
|
||||
}
|
||||
}
|
||||
|
||||
public int ScrollHeight {
|
||||
get {
|
||||
return ScaleY(getAttributeAsInt("scrollHeight"));
|
||||
return ScaleY(GetAttributeAsInt("scrollHeight"));
|
||||
}
|
||||
}
|
||||
|
||||
public Point SourceLocation {
|
||||
get {
|
||||
return sourceLocation;
|
||||
return _sourceLocation;
|
||||
}
|
||||
set {
|
||||
sourceLocation = value;
|
||||
_sourceLocation = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -506,34 +499,34 @@ namespace Greenshot.Helpers.IEInterop {
|
|||
|
||||
public int SourceLeft {
|
||||
get {
|
||||
return sourceLocation.X;
|
||||
return _sourceLocation.X;
|
||||
}
|
||||
}
|
||||
|
||||
public int SourceTop {
|
||||
get {
|
||||
return sourceLocation.Y;
|
||||
return _sourceLocation.Y;
|
||||
}
|
||||
}
|
||||
|
||||
public int SourceRight {
|
||||
get {
|
||||
return sourceLocation.X + ClientWidth;
|
||||
return _sourceLocation.X + ClientWidth;
|
||||
}
|
||||
}
|
||||
|
||||
public int SourceBottom {
|
||||
get {
|
||||
return sourceLocation.Y + ClientHeight;
|
||||
return _sourceLocation.Y + ClientHeight;
|
||||
}
|
||||
}
|
||||
|
||||
public Point DestinationLocation {
|
||||
get {
|
||||
return destinationLocation;
|
||||
return _destinationLocation;
|
||||
}
|
||||
set {
|
||||
destinationLocation = value;
|
||||
_destinationLocation = value;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -552,55 +545,55 @@ namespace Greenshot.Helpers.IEInterop {
|
|||
|
||||
public int DestinationLeft {
|
||||
get {
|
||||
return destinationLocation.X;
|
||||
return _destinationLocation.X;
|
||||
}
|
||||
set {
|
||||
destinationLocation.X = value;
|
||||
_destinationLocation.X = value;
|
||||
}
|
||||
}
|
||||
|
||||
public int DestinationTop {
|
||||
get {
|
||||
return destinationLocation.Y;
|
||||
return _destinationLocation.Y;
|
||||
}
|
||||
set {
|
||||
destinationLocation.Y = value;
|
||||
_destinationLocation.Y = value;
|
||||
}
|
||||
}
|
||||
|
||||
public int DestinationRight {
|
||||
get {
|
||||
return destinationLocation.X + ScrollWidth;
|
||||
return _destinationLocation.X + ScrollWidth;
|
||||
}
|
||||
}
|
||||
|
||||
public int DestinationBottom {
|
||||
get {
|
||||
return destinationLocation.Y + ScrollHeight;
|
||||
return _destinationLocation.Y + ScrollHeight;
|
||||
}
|
||||
}
|
||||
|
||||
public int ScrollLeft {
|
||||
get{
|
||||
return ScaleX(getAttributeAsInt("scrollLeft"));
|
||||
return ScaleX(GetAttributeAsInt("scrollLeft"));
|
||||
}
|
||||
set {
|
||||
setAttribute("scrollLeft", UnscaleX(value));
|
||||
SetAttribute("scrollLeft", UnscaleX(value));
|
||||
}
|
||||
}
|
||||
|
||||
public int ScrollTop {
|
||||
get{
|
||||
return ScaleY(getAttributeAsInt("scrollTop"));
|
||||
return ScaleY(GetAttributeAsInt("scrollTop"));
|
||||
}
|
||||
set {
|
||||
setAttribute("scrollTop", UnscaleY(value));
|
||||
SetAttribute("scrollTop", UnscaleY(value));
|
||||
}
|
||||
}
|
||||
|
||||
public List<DocumentContainer> Frames {
|
||||
public IList<DocumentContainer> Frames {
|
||||
get {
|
||||
return frames;
|
||||
return _frames;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue