示例#1
0
        private void Init()
        {
            if (_isInitialized)
            {
                return;
            }

            _isInitialized = true;
            var proxy = (mozIDOMWindowProxy)Xpcom.QueryInterface(_webNav.Instance, typeof(mozIDOMWindowProxy).GUID);

            GeckoDomDocument doc = _webNav.Instance.GetDocumentAttribute()
                                   .Wrap(proxy, GeckoDomDocument.CreateDomDocumentWraper);
            GeckoElement rootElement = doc.DocumentElement;

            while (rootElement.FirstChild != null)
            {
                rootElement.RemoveChild(rootElement.FirstChild);
            }

            // Use of the canvas technique was inspired by: the abduction! firefox plugin by Rowan Lewis
            // https://addons.mozilla.org/en-US/firefox/addon/abduction/

            uint flags = /*nsIDOMCanvasRenderingContext2DConsts.DRAWWINDOW_DO_NOT_FLUSH*/ 2
                         //| nsIDOMCanvasRenderingContext2DConsts.DRAWWINDOW_DRAW_VIEW 4
                         | /*nsIDOMCanvasRenderingContext2DConsts.DRAWWINDOW_ASYNC_DECODE_IMAGES*/ 16
                         | /*nsIDOMCanvasRenderingContext2DConsts.DRAWWINDOW_USE_WIDGET_LAYERS*/ 8;

            string func = @"
function drawWindow(window, document, x, y, w, h, canvas)
{
	try {
		canvas = document.createElement('canvas');
		canvas.width = w;
		canvas.height = h;
		ctx = canvas.getContext('2d');
		ctx.drawWindow(window, x, y, w, h, 'rgb(255,255,255)', "         + flags + @");
        return canvas.toDataURL('image/png');
	} catch(e) {
		return e + '' + 'window = ' + window + ' x = ' + x;
	}
}
";

            var button = doc.CreateElement("button");

            button.SetAttribute("onclick",
                                func +
                                @"this.dataset.drawResult = drawWindow(this.sourceWin, this.ownerDocument, this.x, this.y, this.w, this.h)");
            rootElement.AppendChild(button);

            _command = Xpcom.QueryInterface <nsIDOMElement>(button.DOMElement).AsComPtr();
        }
        private void Init()
        {
            if (!_isInitialized)
            {
                _isInitialized = true;
                GeckoDomDocument doc = webNav.Instance.GetDocumentAttribute()
                                       .Wrap(GeckoDocument.CreateDomDocumentWraper);
                GeckoElement rootElement = doc.DocumentElement;
                while (rootElement.FirstChild != null)
                {
                    rootElement.RemoveChild(rootElement.FirstChild);
                }


                // Use of the canvas technique was inspired by: the abduction! firefox plugin by Rowan Lewis
                // https://addons.mozilla.org/en-US/firefox/addon/abduction/

                uint flags = (uint)(nsIDOMCanvasRenderingContext2DConsts.DRAWWINDOW_DO_NOT_FLUSH
                                    //| nsIDOMCanvasRenderingContext2DConsts.DRAWWINDOW_DRAW_VIEW
                                    | nsIDOMCanvasRenderingContext2DConsts.DRAWWINDOW_ASYNC_DECODE_IMAGES
                                    | nsIDOMCanvasRenderingContext2DConsts.DRAWWINDOW_USE_WIDGET_LAYERS);

                string func = @"
function drawWindow(window, x, y, w, h, canvas, ctx)
{
	try {
		canvas = window.document.createElement('canvas');
		canvas.width = w;
		canvas.height = h;
		ctx = canvas.getContext('2d');
		ctx.drawWindow(window, x, y, w, h, 'rgb(255,255,255)', "         + flags.ToString() + @");
		return canvas.toDataURL('image/png');
	} catch(e) {
		return e + ''
	}
}
";

                var button = doc.CreateElement("button");
                button.SetAttribute("oncommand",
                                    func +
                                    @"this.setUserData('drawResult', drawWindow(this.getUserData('window'), this.getUserData('x'), this.getUserData('y'), this.getUserData('w'), this.getUserData('h')), null)");
                rootElement.AppendChild(button);

                command = Xpcom.QueryInterface <nsIDOMXULElement>(button.DOMElement).AsComPtr();
            }
        }