Commit 757b89a9 authored by Maksim Sisov's avatar Maksim Sisov Committed by Commit Bot

X11 and Ozone: Move setting transparency to DNWA

This functionality seems to be platform independent, so
the PlatformWindow interface got new method:
ShouldWindowContentsBeTransparent. It is now implemented
for both X11 and Windows platforms (the last one was taken
from DWTHWin).

Now, the DesktopNativeWidgetAura::UpdateWindowTransparency
sets the transparency based on the value returned from
ShouldWindowContentsBeTransparent.

In addition to it, the interface has default implementation
and returns false as DWTHPlatform used to be doing before.
The platforms that are interested in providing different
values must override and implement that method.

Also, setting native frame has been moved as long as
OnNativeWidgetCreate call is passed all the way down
from DWTHX11 to DWTHLinux to DWTHPlatform.

Bug: 990756
Change-Id: I7069609a2abe068b3553039d2e03ab98c3babd98
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1789222
Commit-Queue: Maksim Sisov <msisov@igalia.com>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarThomas Anderson <thomasanderson@chromium.org>
Cr-Commit-Position: refs/heads/master@{#698843}
parent 311527e5
......@@ -525,6 +525,11 @@ gfx::Rect WaylandWindow::GetRestoredBoundsInPixels() const {
return restored_bounds_px_;
}
bool WaylandWindow::ShouldWindowContentsBeTransparent() const {
NOTIMPLEMENTED_LOG_ONCE();
return false;
}
bool WaylandWindow::CanDispatchEvent(const PlatformEvent& event) {
// This window is a nested popup window, all the events must be forwarded
// to the main popup window.
......
......@@ -136,6 +136,7 @@ class WaylandWindow : public PlatformWindow,
void ConfineCursorToBounds(const gfx::Rect& bounds) override;
void SetRestoredBoundsInPixels(const gfx::Rect& bounds) override;
gfx::Rect GetRestoredBoundsInPixels() const override;
bool ShouldWindowContentsBeTransparent() const override;
// PlatformEventDispatcher
bool CanDispatchEvent(const PlatformEvent& event) override;
......
......@@ -10,6 +10,10 @@ PlatformWindow::PlatformWindow() = default;
PlatformWindow::~PlatformWindow() = default;
bool PlatformWindow::ShouldWindowContentsBeTransparent() const {
return false;
}
void PlatformWindow::SetZOrderLevel(ZOrderLevel order) {}
ZOrderLevel PlatformWindow::GetZOrderLevel() const {
......
......@@ -78,6 +78,10 @@ class PlatformWindow : public PropertyHandler {
virtual void SetRestoredBoundsInPixels(const gfx::Rect& bounds) = 0;
virtual gfx::Rect GetRestoredBoundsInPixels() const = 0;
// Tells if the content of the platform window should be transparent. By
// default returns false.
virtual bool ShouldWindowContentsBeTransparent() const;
// Sets and gets ZOrderLevel of the PlatformWindow. Such platforms that do not
// support ordering, should not implement these methods as the default
// implementation always returns ZOrderLevel::kNormal value.
......
......@@ -10,6 +10,7 @@ jumbo_component("win") {
deps = [
"//base",
"//skia",
"//ui/base",
"//ui/events",
"//ui/gfx",
"//ui/gfx/geometry",
......
......@@ -8,6 +8,7 @@
#include <memory>
#include "base/strings/string16.h"
#include "ui/base/win/shell.h"
#include "ui/events/event.h"
#include "ui/events/event_utils.h"
#include "ui/gfx/win/msg_util.h"
......@@ -149,6 +150,16 @@ gfx::Rect WinWindow::GetRestoredBoundsInPixels() const {
return gfx::Rect();
}
bool WinWindow::ShouldWindowContentsBeTransparent() const {
// The window contents need to be transparent when the titlebar area is drawn
// by the DWM rather than Chrome, so that area can show through. This
// function does not describe the transparency of the whole window appearance,
// but merely of the content Chrome draws, so even when the system titlebars
// appear opaque (Win 8+), the content above them needs to be transparent, or
// they'll be covered by a black (undrawn) region.
return ui::win::IsAeroGlassEnabled() && !IsFullscreen();
}
void WinWindow::SetZOrderLevel(ZOrderLevel order) {
NOTIMPLEMENTED_LOG_ONCE();
}
......@@ -166,6 +177,10 @@ void WinWindow::StackAtTop() {
NOTIMPLEMENTED_LOG_ONCE();
}
bool WinWindow::IsFullscreen() const {
return GetPlatformWindowState() == PlatformWindowState::kFullScreen;
}
LRESULT WinWindow::OnMouseRange(UINT message, WPARAM w_param, LPARAM l_param) {
MSG msg = {hwnd(),
message,
......
......@@ -50,11 +50,14 @@ class WIN_WINDOW_EXPORT WinWindow : public PlatformWindow,
void ConfineCursorToBounds(const gfx::Rect& bounds) override;
void SetRestoredBoundsInPixels(const gfx::Rect& bounds) override;
gfx::Rect GetRestoredBoundsInPixels() const override;
bool ShouldWindowContentsBeTransparent() const override;
void SetZOrderLevel(ZOrderLevel order) override;
ZOrderLevel GetZOrderLevel() const override;
void StackAbove(gfx::AcceleratedWidget widget) override;
void StackAtTop() override;
bool IsFullscreen() const;
CR_BEGIN_MSG_MAP_EX(WinWindow)
CR_MESSAGE_RANGE_HANDLER_EX(WM_MOUSEFIRST, WM_MOUSELAST, OnMouseRange)
CR_MESSAGE_RANGE_HANDLER_EX(WM_NCMOUSEMOVE, WM_NCXBUTTONDBLCLK,
......
......@@ -217,6 +217,10 @@ gfx::Rect X11Window::GetRestoredBoundsInPixels() const {
return gfx::Rect();
}
bool X11Window::ShouldWindowContentsBeTransparent() const {
return XWindow::has_alpha();
}
void X11Window::SetZOrderLevel(ZOrderLevel order) {
z_order_ = order;
......
......@@ -69,6 +69,7 @@ class X11_WINDOW_EXPORT X11Window : public PlatformWindow,
void ConfineCursorToBounds(const gfx::Rect& bounds) override;
void SetRestoredBoundsInPixels(const gfx::Rect& bounds) override;
gfx::Rect GetRestoredBoundsInPixels() const override;
bool ShouldWindowContentsBeTransparent() const override;
void SetZOrderLevel(ZOrderLevel order) override;
ZOrderLevel GetZOrderLevel() const override;
void StackAbove(gfx::AcceleratedWidget widget) override;
......
......@@ -11,6 +11,7 @@
#include "base/macros.h"
#include "base/trace_event/trace_event.h"
#include "build/build_config.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/accessibility/ax_enums.mojom.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/client/cursor_client.h"
......@@ -437,6 +438,25 @@ gfx::NativeWindow DesktopNativeWidgetAura::GetNativeWindow() const {
return content_window_;
}
void DesktopNativeWidgetAura::UpdateWindowTransparency() {
if (!desktop_window_tree_host_->ShouldUpdateWindowTransparency())
return;
const bool transparent =
desktop_window_tree_host_->ShouldWindowContentsBeTransparent();
auto* window_tree_host = desktop_window_tree_host_->AsWindowTreeHost();
window_tree_host->compositor()->SetBackgroundColor(
transparent ? SK_ColorTRANSPARENT : SK_ColorWHITE);
window_tree_host->window()->SetTransparent(transparent);
content_window_->SetTransparent(transparent);
// Regardless of transparency or not, this root content window will always
// fill its bounds completely, so set this flag to true to avoid an
// unecessary clear before update.
content_window_->SetFillsBoundsCompletely(true);
}
////////////////////////////////////////////////////////////////////////////////
// DesktopNativeWidgetAura, internal::NativeWidgetPrivate implementation:
......@@ -1251,18 +1271,6 @@ void DesktopNativeWidgetAura::OnHostMovedInPixels(
////////////////////////////////////////////////////////////////////////////////
// DesktopNativeWidgetAura, private:
void DesktopNativeWidgetAura::UpdateWindowTransparency() {
if (!desktop_window_tree_host_->ShouldUpdateWindowTransparency())
return;
content_window_->SetTransparent(
desktop_window_tree_host_->ShouldWindowContentsBeTransparent());
// Regardless of transparency or not, this root content window will always
// fill its bounds completely, so set this flag to true to avoid an
// unecessary clear before update.
content_window_->SetFillsBoundsCompletely(true);
}
void DesktopNativeWidgetAura::RootWindowDestroyed() {
cursor_reference_count_--;
if (cursor_reference_count_ == 0) {
......
......@@ -102,6 +102,10 @@ class VIEWS_EXPORT DesktopNativeWidgetAura
// Overridden from internal::NativeWidgetPrivate:
gfx::NativeWindow GetNativeWindow() const override;
// Configures the appropriate aura::Windows based on the
// DesktopWindowTreeHost's transparency.
void UpdateWindowTransparency();
protected:
// Overridden from internal::NativeWidgetPrivate:
void InitNativeWidget(Widget::InitParams params) override;
......@@ -250,10 +254,6 @@ class VIEWS_EXPORT DesktopNativeWidgetAura
private:
friend class RootWindowDestructionObserver;
// To save a clear on platforms where the window is never transparent, the
// window is only set as transparent when the glass frame is in use.
void UpdateWindowTransparency();
void RootWindowDestroyed();
// Notify the root view of our widget of a native accessibility event.
......
......@@ -481,7 +481,7 @@ bool DesktopWindowTreeHostPlatform::ShouldUseNativeFrame() const {
}
bool DesktopWindowTreeHostPlatform::ShouldWindowContentsBeTransparent() const {
return false;
return platform_window()->ShouldWindowContentsBeTransparent();
}
void DesktopWindowTreeHostPlatform::FrameTypeChanged() {
......@@ -558,7 +558,7 @@ void DesktopWindowTreeHostPlatform::SizeConstraintsChanged() {
}
bool DesktopWindowTreeHostPlatform::ShouldUpdateWindowTransparency() const {
return false;
return true;
}
bool DesktopWindowTreeHostPlatform::ShouldUseDesktopNativeCursorManager()
......
......@@ -156,9 +156,6 @@ void DesktopWindowTreeHostWin::OnNativeWidgetCreated(
should_animate_window_close_ =
content_window()->type() != aura::client::WINDOW_TYPE_NORMAL &&
!wm::WindowAnimationsDisabled(content_window());
// TODO this is not invoked *after* Init(), but should be ok.
SetWindowTransparency();
}
void DesktopWindowTreeHostWin::OnActiveWindowChanged(bool active) {}
......@@ -439,7 +436,6 @@ bool DesktopWindowTreeHostWin::ShouldWindowContentsBeTransparent() const {
void DesktopWindowTreeHostWin::FrameTypeChanged() {
message_handler_->FrameTypeChanged();
SetWindowTransparency();
}
void DesktopWindowTreeHostWin::SetFullscreen(bool fullscreen) {
......@@ -452,7 +448,7 @@ void DesktopWindowTreeHostWin::SetFullscreen(bool fullscreen) {
compositor()->SetVisible(true);
content_window()->Show();
}
SetWindowTransparency();
desktop_native_widget_aura_->UpdateWindowTransparency();
}
bool DesktopWindowTreeHostWin::IsFullscreen() const {
......@@ -885,7 +881,7 @@ void DesktopWindowTreeHostWin::HandleClientSizeChanged(
void DesktopWindowTreeHostWin::HandleFrameChanged() {
CheckForMonitorChange();
SetWindowTransparency();
desktop_native_widget_aura_->UpdateWindowTransparency();
// Replace the frame and layout the contents.
if (GetWidget()->non_client_view())
GetWidget()->non_client_view()->UpdateFrame();
......@@ -1062,14 +1058,6 @@ HWND DesktopWindowTreeHostWin::GetHWND() const {
return message_handler_->hwnd();
}
void DesktopWindowTreeHostWin::SetWindowTransparency() {
bool transparent = ShouldWindowContentsBeTransparent();
compositor()->SetBackgroundColor(transparent ? SK_ColorTRANSPARENT
: SK_ColorWHITE);
window()->SetTransparent(transparent);
content_window()->SetTransparent(transparent);
}
bool DesktopWindowTreeHostWin::IsModalWindowActive() const {
// This function can get called during window creation which occurs before
// dispatcher() has been created.
......
......@@ -226,8 +226,6 @@ class VIEWS_EXPORT DesktopWindowTreeHostWin
private:
friend class ::views::test::DesktopWindowTreeHostWinTestApi;
void SetWindowTransparency();
// Returns true if a modal window is active in the current root window chain.
bool IsModalWindowActive() const;
......
......@@ -235,8 +235,6 @@ void DesktopWindowTreeHostX11::OnNativeWidgetCreated(
x11_window_move_client_ = std::make_unique<X11DesktopWindowMoveClient>();
wm::SetWindowMoveClient(window(), x11_window_move_client_.get());
SetWindowTransparency();
DesktopWindowTreeHostLinux::OnNativeWidgetCreated(params);
}
......@@ -461,10 +459,6 @@ bool DesktopWindowTreeHostX11::ShouldUseNativeFrame() const {
return GetXWindow()->use_native_frame();
}
bool DesktopWindowTreeHostX11::ShouldWindowContentsBeTransparent() const {
return GetXWindow()->has_alpha();
}
void DesktopWindowTreeHostX11::FrameTypeChanged() {
Widget::FrameType new_type =
native_widget_delegate()->AsWidget()->frame_type();
......@@ -582,10 +576,6 @@ void DesktopWindowTreeHostX11::SizeConstraintsChanged() {
GetXWindow()->UpdateMinAndMaxSize();
}
bool DesktopWindowTreeHostX11::ShouldUpdateWindowTransparency() const {
return true;
}
bool DesktopWindowTreeHostX11::ShouldUseDesktopNativeCursorManager() const {
return true;
}
......@@ -773,14 +763,6 @@ void DesktopWindowTreeHostX11::MapWindow(ui::WindowShowState show_state) {
GetXWindow()->Map(inactive);
}
void DesktopWindowTreeHostX11::SetWindowTransparency() {
bool has_alpha = GetXWindow()->has_alpha();
compositor()->SetBackgroundColor(has_alpha ? SK_ColorTRANSPARENT
: SK_ColorWHITE);
window()->SetTransparent(has_alpha);
content_window()->SetTransparent(has_alpha);
}
void DesktopWindowTreeHostX11::Relayout() {
Widget* widget = native_widget_delegate()->AsWidget();
NonClientView* non_client_view = widget->non_client_view();
......
......@@ -119,7 +119,6 @@ class VIEWS_EXPORT DesktopWindowTreeHostX11 : public DesktopWindowTreeHostLinux,
void EndMoveLoop() override;
void SetVisibilityChangedAnimationsEnabled(bool value) override;
bool ShouldUseNativeFrame() const override;
bool ShouldWindowContentsBeTransparent() const override;
void FrameTypeChanged() override;
void SetFullscreen(bool fullscreen) override;
bool IsFullscreen() const override;
......@@ -132,7 +131,6 @@ class VIEWS_EXPORT DesktopWindowTreeHostX11 : public DesktopWindowTreeHostLinux,
bool IsAnimatingClosed() const override;
bool IsTranslucentWindowOpacitySupported() const override;
void SizeConstraintsChanged() override;
bool ShouldUpdateWindowTransparency() const override;
bool ShouldUseDesktopNativeCursorManager() const override;
bool ShouldCreateVisibilityController() const override;
......@@ -175,8 +173,6 @@ class VIEWS_EXPORT DesktopWindowTreeHostX11 : public DesktopWindowTreeHostLinux,
// Map the window (shows it) taking into account the given |show_state|.
void MapWindow(ui::WindowShowState show_state);
void SetWindowTransparency();
// Relayout the widget's client and non-client views.
void Relayout();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment