DCEF3如何使铬背景透明

时间:2016-01-08 05:04:51

标签: transparent chromium

我试图将铬背景变成透明的。屏幕外没有其他方法可以转变透明背景。

1 个答案:

答案 0 :(得分:0)

我正在为此目的开发一个解决方案,我在Windows 10中实现的是一个镀铬窗口透明覆盖层。理论上这应该适用于Vista和Windows 7,但如果它适用于Windows,我不会感到害羞8 / 8.1。请注意,这不是渲染到纹理(屏幕外渲染),是一个可以放在所需位置的HWND,而windows compositor是谁进行混合。

Chromium with alpha overlay in windows

这是Chromium 50.0.2661.102的补丁

diff --git a/third_party/WebKit/Source/web/WebViewImpl.cpp b/third_party/WebKit/Source/web/WebViewImpl.cpp
index fe91784..250483b 100644
--- a/third_party/WebKit/Source/web/WebViewImpl.cpp
+++ b/third_party/WebKit/Source/web/WebViewImpl.cpp
@@ -426,7 +426,7 @@ WebViewImpl::WebViewImpl(WebViewClient* client)
     , m_operationsAllowed(WebDragOperationNone)
     , m_dragOperation(WebDragOperationNone)
     , m_devToolsEmulator(nullptr)
-    , m_isTransparent(false)
+    , m_isTransparent(true)
     , m_tabsToLinks(false)
     , m_layerTreeView(nullptr)
     , m_rootLayer(nullptr)

warning: LF will be replaced by CRLF in third_party/WebKit/Source/web/WebViewImpl.cpp.
The file will have its original line endings in your working directory.
diff --git a/ui/views/widget/widget.cc b/ui/views/widget/widget.cc
index bcbb0f5..377afcd 100644
--- a/ui/views/widget/widget.cc
+++ b/ui/views/widget/widget.cc
@@ -117,7 +117,7 @@ Widget::InitParams::InitParams(Type type)
     : type(type),
       delegate(nullptr),
       child(false),
-      opacity(INFER_OPACITY),
+      opacity(TRANSLUCENT_WINDOW),
       accept_events(true),
       activatable(ACTIVATABLE_DEFAULT),
       keep_on_top(type == TYPE_MENU || type == TYPE_DRAG),

warning: LF will be replaced by CRLF in ui/views/widget/widget.cc.
The file will have its original line endings in your working directory.
diff --git a/ui/views/win/hwnd_message_handler.cc b/ui/views/win/hwnd_message_handler.cc
index 3575e62..541d1ea 100644
--- a/ui/views/win/hwnd_message_handler.cc
+++ b/ui/views/win/hwnd_message_handler.cc
@@ -1311,9 +1311,42 @@ void HWNDMessageHandler::OnCommand(UINT notification_code,
     SetMsgHandled(FALSE);
 }

+struct AccentPolicy
+{
+   int AccentState;
+   int AccentFlags;
+   int GradientColor;
+   int AnimationId;
+};
+
+struct WINCOMPATTRDATA
+{
+   DWORD attribute;
+   PVOID pData;
+   ULONG dataSize;
+};
+
 LRESULT HWNDMessageHandler::OnCreate(CREATESTRUCT* create_struct) {
   if (window_ex_style() &  WS_EX_COMPOSITED) {
-    if (base::win::GetVersion() >= base::win::VERSION_VISTA) {
+    if (base::win::GetVersion() >= base::win::VERSION_WIN8) {
+       typedef BOOL(WINAPI*pfnGWA)(HWND, WINCOMPATTRDATA*);
+       HMODULE hMod = LoadLibrary(L"user32.dll");
+       pfnGWA setWindowAttribute = (pfnGWA)GetProcAddress(hMod, "SetWindowCompositionAttribute");
+       AccentPolicy accentPolicy = {
+           2,  //ACCENT_ENABLE_TRANSPARENTGRADIENT, 3 - Blur
+           2,
+           0,  // 0x ARGB
+           0
+       };
+
+       WINCOMPATTRDATA data = {
+           19, // WCA_ACCENT_POLICY
+           &accentPolicy,
+           sizeof(accentPolicy)
+       };
+       setWindowAttribute(hwnd(), &data);
+   }
+    else if (base::win::GetVersion() >= base::win::VERSION_VISTA) {
       // This is part of the magic to emulate layered windows with Aura
       // see the explanation elsewere when we set WS_EX_COMPOSITED style.
       MARGINS margins = {-1,-1,-1,-1};