Skip to content

Commit e837e00

Browse files
committed
[Transparency][WIN/Linux] rebase for the new chrome (+1 squashed commits)
Squashed commits: [393645c] [Transparency][Win] add d3dcompiler_46 when packaging, fix the marginVal for compatibility (+1 squashed commits) Squashed commits: [26d1c7e] [Transparency][WIN] implement the windowsversion, changing the style, and background
1 parent e7ff868 commit e837e00

File tree

2 files changed

+86
-0
lines changed

2 files changed

+86
-0
lines changed

src/browser/native_window_aura.cc

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@
2222

2323
#if defined(OS_WIN)
2424
#include <shobjidl.h>
25+
#include <dwmapi.h>
2526
#endif
2627

2728
#include "base/strings/utf_string_conversions.h"
2829
#include "base/values.h"
30+
#include "base/command_line.h"
2931

3032
#if defined(OS_WIN)
3133
#include "base/win/scoped_comptr.h"
@@ -44,6 +46,7 @@
4446
#include "content/public/browser/render_view_host.h"
4547
#include "content/public/browser/render_widget_host_view.h"
4648
#include "content/public/browser/web_contents.h"
49+
#include "content/public/common/content_switches.h"
4750
#include "extensions/common/draggable_region.h"
4851
#include "third_party/skia/include/core/SkPaint.h"
4952
#include "ui/base/hit_test.h"
@@ -58,9 +61,11 @@
5861
#include "ui/gfx/font_list.h"
5962
#include "ui/gfx/platform_font.h"
6063
#include "ui/gfx/image/image_skia_operations.h"
64+
#include "ui/views/background.h"
6165
#include "ui/views/controls/webview/webview.h"
6266
#include "ui/views/layout/box_layout.h"
6367
#include "ui/views/views_delegate.h"
68+
#include "ui/views/views_switches.h"
6469
#include "ui/views/widget/widget.h"
6570
#include "ui/views/window/native_frame_view.h"
6671
#include "ui/views/widget/native_widget_private.h"
@@ -291,6 +296,7 @@ NativeWindowAura::NativeWindowAura(const base::WeakPtr<content::Shell>& shell,
291296
params.delegate = this;
292297
params.remove_standard_frame = !has_frame();
293298
params.use_system_default_icon = true;
299+
if (transparent_) params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
294300
if (is_fullscreen_)
295301
params.show_state = ui::SHOW_STATE_FULLSCREEN;
296302

@@ -389,6 +395,85 @@ bool NativeWindowAura::IsFullscreen() {
389395
return is_fullscreen_;
390396
}
391397

398+
void NativeWindowAura::SetTransparent(bool transparent) {
399+
#if defined(OS_WIN)
400+
// Check for Windows Vista or higher, transparency isn't supported in
401+
// anything lower.
402+
if (base::win::GetVersion() < base::win::VERSION_VISTA) {
403+
NOTREACHED() << "The operating system does not support transparency.";
404+
transparent_ = false;
405+
return;
406+
}
407+
408+
// Check to see if composition is disabled, if so we have to throw an
409+
// error, there's no graceful recovery, yet. TODO: Graceful recovery.
410+
BOOL enabled = FALSE;
411+
HRESULT result = ::DwmIsCompositionEnabled(&enabled);
412+
if (!enabled || !SUCCEEDED(result)) {
413+
NOTREACHED() << "Windows DWM composition is not enabled, transparency is not supported.";
414+
transparent_ = false;
415+
return;
416+
}
417+
418+
HWND hWnd = views::HWNDForWidget(window_);
419+
420+
const int marginVal = transparent ? -1 : 0;
421+
MARGINS mgMarInset = { marginVal, marginVal, marginVal, marginVal };
422+
if (DwmExtendFrameIntoClientArea(hWnd, &mgMarInset) != S_OK) {
423+
NOTREACHED() << "Windows DWM extending to client area failed, transparency is not supported.";
424+
transparent_ = false;
425+
return;
426+
}
427+
428+
// this is needed, or transparency will fail if it defined on startup
429+
bool change_window_style = false;
430+
431+
if (!has_frame_) {
432+
const LONG lastStyle = GetWindowLong(hWnd, GWL_STYLE);
433+
const LONG style = WS_CAPTION;
434+
const LONG newStyle = transparent ? lastStyle | style : lastStyle & ~style;
435+
SetWindowLong(hWnd, GWL_STYLE, newStyle);
436+
change_window_style |= lastStyle != newStyle;
437+
}
438+
439+
const LONG lastExStyle = GetWindowLong(hWnd, GWL_EXSTYLE);
440+
const LONG exStyle = WS_EX_COMPOSITED;
441+
const LONG newExStyle = transparent ? lastExStyle | exStyle : lastExStyle & ~exStyle;
442+
SetWindowLong(hWnd, GWL_EXSTYLE, newExStyle);
443+
change_window_style |= lastExStyle != newExStyle;
444+
445+
if (change_window_style) {
446+
window_->FrameTypeChanged();
447+
}
448+
#elif defined(USE_X11) && !defined(OS_CHROMEOS)
449+
450+
static char cachedRes = -1;
451+
if ( cachedRes<0 ) {
452+
const CommandLine& command_line = *CommandLine::ForCurrentProcess();
453+
cachedRes = !command_line.HasSwitch(switches::kDisableGpu) ||
454+
!command_line.HasSwitch(views::switches::kEnableTransparentVisuals);
455+
}
456+
457+
if (cachedRes && transparent) {
458+
LOG(INFO) << "if transparency does not work, try with --enable-transparent-visuals --disable-gpu";
459+
}
460+
461+
#endif
462+
463+
if (toolbar_) {
464+
toolbar_->set_background(transparent ? views::Background::CreateSolidBackground(SK_ColorTRANSPARENT) :
465+
views::Background::CreateStandardPanelBackground());
466+
toolbar_->SchedulePaint();
467+
}
468+
469+
content::RenderWidgetHostView* rwhv = shell_->web_contents()->GetRenderWidgetHostView();
470+
if (rwhv) {
471+
rwhv->SetBackgroundOpaque(!transparent);
472+
}
473+
474+
transparent_ = transparent;
475+
}
476+
392477
void NativeWindowAura::SetSize(const gfx::Size& size) {
393478
window_->SetSize(size);
394479
}

tools/package_binaries.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ def generate_target_nw(platform_name, arch, version):
125125
]
126126
elif platform_name == 'win':
127127
target['input'] = [
128+
'd3dcompiler_46.dll',
128129
'ffmpegsumo.dll',
129130
'icudtl.dat',
130131
'libEGL.dll',

0 commit comments

Comments
 (0)