如何在Awesomium中隐藏光标

时间:2014-07-29 11:40:32

标签: awesomium

我试过了:

<awe:WebControl x:Name="webBrowser" Cursor="None" Source="http://example.com/"/>

但光标仍显示。

我想我可以通过添加以下行来改变页面的CSS:

*{
    cursor: none;
}

但是,当我无法访问我正在展示的实际页面时,是否有解决方案?

1 个答案:

答案 0 :(得分:2)

您可以使用ResouceInterceptor并动态操作页面以插入自定义CSS。

编辑:

以下实施应该完成这项工作。 (它假设有一个text.css文件)

class ManipulatingResourceInterceptor : IResourceInterceptor
{
    public ResourceResponse OnRequest(ResourceRequest request)
    {
        Stream stream = null;

        //do stream manipulation
        if (request.Url.ToString() == "http://your.web.url/test.css")
        {
            WebRequest myRequest;
            myRequest = WebRequest.Create(request.Url);
            Stream webStream = myRequest.GetResponse().GetResponseStream();
            StreamReader webStreamReader = new StreamReader(webStream);
            string webStreamContent = webStreamReader.ReadToEnd();

            stream = webStream;

            string extraContent = "*{cursor: none;}";

            webStreamContent += extraContent;
            byte[] responseBuffer = Encoding.UTF8.GetBytes(webStreamContent);

            // Initialize unmanaged memory to hold the array.
            int responseSize = Marshal.SizeOf(responseBuffer[0]) * responseBuffer.Length;
            IntPtr pointer = Marshal.AllocHGlobal(responseSize);
            try
            {
                // Copy the array to unmanaged memory.
                Marshal.Copy(responseBuffer, 0, pointer, responseBuffer.Length);
                return ResourceResponse.Create((uint)responseBuffer.Length, pointer, "text/css");
            }
            finally
            {
                // Data is not owned by the ResourceResponse. A copy is made 
                // of the supplied buffer. We can safely free the unmanaged memory.
                Marshal.FreeHGlobal(pointer);
                stream.Close();
            }
        }
        return null;
    }

    public bool OnFilterNavigation(NavigationRequest request)
    {
        return false;
    }
}