Commit c04b1b17 authored by Scott Violet's avatar Scott Violet Committed by Commit Bot

views: minor cleanup of DesktopWindowTreeHost

Changes Init() not to pass in the content_window_, and changes
implementations not to cache it. There is no reason for each DWTH to
cache the content_window_ when it can get it from the
DesktopNativeWidgetAura.

BUG=none
TEST=none

Change-Id: I7e89b81606079e5e291fd528d275c8a47ada1c8e
Reviewed-on: https://chromium-review.googlesource.com/986930
Commit-Queue: Scott Violet <sky@chromium.org>
Reviewed-by: default avatarMichael Wasserman <msw@chromium.org>
Cr-Commit-Position: refs/heads/master@{#547088}
parent 53dab253
......@@ -53,9 +53,8 @@ bool BrowserDesktopWindowTreeHostX11::UsesNativeSystemMenu() const {
// views::DesktopWindowTreeHostX11 implementation:
void BrowserDesktopWindowTreeHostX11::Init(
aura::Window* content_window,
const views::Widget::InitParams& params) {
views::DesktopWindowTreeHostX11::Init(content_window, params);
views::DesktopWindowTreeHostX11::Init(params);
// We have now created our backing X11 window. We now need to (possibly)
// alert Unity that there's a menu bar attached to it.
......
......@@ -35,8 +35,7 @@ class BrowserDesktopWindowTreeHostX11
bool UsesNativeSystemMenu() const override;
// Overridden from views::DesktopWindowTreeHostX11:
void Init(aura::Window* content_window,
const views::Widget::InitParams& params) override;
void Init(const views::Widget::InitParams& params) override;
void CloseNow() override;
void OnMaximizedStateChanged() override;
void OnFullscreenStateChanged() override;
......
......@@ -211,7 +211,7 @@ DesktopWindowTreeHostMus::DesktopWindowTreeHostMus(
MusClient::Get()->AddObserver(this);
MusClient::Get()->window_tree_client()->focus_synchronizer()->AddObserver(
this);
desktop_native_widget_aura_->content_window()->AddObserver(this);
content_window()->AddObserver(this);
// DesktopNativeWidgetAura registers the association between |content_window_|
// and Widget, but code may also want to go from the root (window()) to the
// Widget. This call enables that.
......@@ -226,7 +226,7 @@ DesktopWindowTreeHostMus::~DesktopWindowTreeHostMus() {
// the cursor-client needs to be unset on the root-window before
// |cursor_manager_| is destroyed.
aura::client::SetCursorClient(window(), nullptr);
desktop_native_widget_aura_->content_window()->RemoveObserver(this);
content_window()->RemoveObserver(this);
MusClient::Get()->RemoveObserver(this);
MusClient::Get()->window_tree_client()->focus_synchronizer()->RemoveObserver(
this);
......@@ -293,8 +293,7 @@ bool DesktopWindowTreeHostMus::ShouldSendClientAreaToServer() const {
return type == WIP::TYPE_WINDOW || type == WIP::TYPE_PANEL;
}
void DesktopWindowTreeHostMus::Init(aura::Window* content_window,
const Widget::InitParams& params) {
void DesktopWindowTreeHostMus::Init(const Widget::InitParams& params) {
// |TYPE_WINDOW| and |TYPE_PANEL| are forced to transparent as otherwise the
// window is opaque and the client decorations drawn by the window manager
// would not be seen.
......@@ -302,7 +301,7 @@ void DesktopWindowTreeHostMus::Init(aura::Window* content_window,
params.opacity == Widget::InitParams::TRANSLUCENT_WINDOW ||
params.type == Widget::InitParams::TYPE_WINDOW ||
params.type == Widget::InitParams::TYPE_PANEL;
content_window->SetTransparent(transparent);
content_window()->SetTransparent(transparent);
window()->SetTransparent(transparent);
window()->SetProperty(aura::client::kShowStateKey, params.show_state);
......@@ -325,18 +324,16 @@ void DesktopWindowTreeHostMus::Init(aura::Window* content_window,
params.parent->GetHost()->window(), window());
}
if (!params.accept_events) {
if (!params.accept_events)
window()->SetEventTargetingPolicy(ui::mojom::EventTargetingPolicy::NONE);
} else {
aura::WindowPortMus::Get(content_window)->SetCanAcceptDrops(true);
}
else
aura::WindowPortMus::Get(content_window())->SetCanAcceptDrops(true);
}
void DesktopWindowTreeHostMus::OnNativeWidgetCreated(
const Widget::InitParams& params) {
window()->SetName(params.name);
desktop_native_widget_aura_->content_window()->SetName(
"DesktopNativeWidgetAura - content window");
content_window()->SetName("DesktopNativeWidgetAura - content window");
if (params.parent && params.parent->GetHost()) {
parent_ = static_cast<DesktopWindowTreeHostMus*>(params.parent->GetHost());
parent_->children_.insert(this);
......@@ -495,10 +492,9 @@ void DesktopWindowTreeHostMus::CenterWindow(const gfx::Size& size) {
gfx::Rect bounds_to_center_in = GetWorkAreaBoundsInScreen();
// If there is a transient parent and it fits |size|, then center over it.
aura::Window* content_window = desktop_native_widget_aura_->content_window();
if (wm::GetTransientParent(content_window)) {
if (wm::GetTransientParent(content_window())) {
gfx::Rect transient_parent_bounds =
wm::GetTransientParent(content_window)->GetBoundsInScreen();
wm::GetTransientParent(content_window())->GetBoundsInScreen();
if (transient_parent_bounds.height() >= size.height() &&
transient_parent_bounds.width() >= size.width()) {
bounds_to_center_in = transient_parent_bounds;
......@@ -792,7 +788,7 @@ void DesktopWindowTreeHostMus::OnActiveFocusClientChanged(
void DesktopWindowTreeHostMus::OnWindowPropertyChanged(aura::Window* window,
const void* key,
intptr_t old) {
DCHECK_EQ(window, desktop_native_widget_aura_->content_window());
DCHECK_EQ(window, content_window());
DCHECK(!window->GetRootWindow() || this->window() == window->GetRootWindow());
if (!this->window())
return;
......@@ -851,4 +847,8 @@ void DesktopWindowTreeHostMus::SetBoundsInPixels(
}
}
aura::Window* DesktopWindowTreeHostMus::content_window() {
return desktop_native_widget_aura_->content_window();
}
} // namespace views
......@@ -61,8 +61,7 @@ class VIEWS_MUS_EXPORT DesktopWindowTreeHostMus
bool ShouldSendClientAreaToServer() const;
// DesktopWindowTreeHost:
void Init(aura::Window* content_window,
const Widget::InitParams& params) override;
void Init(const Widget::InitParams& params) override;
void OnNativeWidgetCreated(const Widget::InitParams& params) override;
void OnActiveWindowChanged(bool active) override;
void OnWidgetInitDone() override;
......@@ -143,6 +142,9 @@ class VIEWS_MUS_EXPORT DesktopWindowTreeHostMus
void HideImpl() override;
void SetBoundsInPixels(const gfx::Rect& bounds_in_pixels) override;
// Accessor for DesktopNativeWidgetAura::content_window().
aura::Window* content_window();
internal::NativeWidgetDelegate* native_widget_delegate_;
DesktopNativeWidgetAura* desktop_native_widget_aura_;
......
......@@ -433,7 +433,7 @@ void DesktopNativeWidgetAura::InitNativeWidget(
}
host_.reset(desktop_window_tree_host_->AsWindowTreeHost());
}
desktop_window_tree_host_->Init(content_window_, params);
desktop_window_tree_host_->Init(params);
host_->window()->AddChild(content_window_);
host_->window()->SetProperty(kDesktopNativeWidgetAuraKey, this);
......
......@@ -48,8 +48,7 @@ class VIEWS_EXPORT DesktopWindowTreeHost {
// Sets up resources needed before the WindowEventDispatcher has been created.
// It is expected this calls InitHost() on the WindowTreeHost.
virtual void Init(aura::Window* content_window,
const Widget::InitParams& params) = 0;
virtual void Init(const Widget::InitParams& params) = 0;
// Invoked once the DesktopNativeWidgetAura has been created.
virtual void OnNativeWidgetCreated(const Widget::InitParams& params) = 0;
......
......@@ -81,7 +81,6 @@ DesktopWindowTreeHostWin::DesktopWindowTreeHostWin(
: message_handler_(new HWNDMessageHandler(this)),
native_widget_delegate_(native_widget_delegate),
desktop_native_widget_aura_(desktop_native_widget_aura),
content_window_(NULL),
drag_drop_client_(NULL),
should_animate_window_close_(false),
pending_close_(false),
......@@ -90,7 +89,6 @@ DesktopWindowTreeHostWin::DesktopWindowTreeHostWin(
}
DesktopWindowTreeHostWin::~DesktopWindowTreeHostWin() {
// WARNING: |content_window_| has been destroyed by the time we get here.
desktop_native_widget_aura_->OnDesktopWindowTreeHostDestroyed(this);
DestroyDispatcher();
}
......@@ -108,16 +106,13 @@ aura::Window* DesktopWindowTreeHostWin::GetContentWindowForHWND(HWND hwnd) {
////////////////////////////////////////////////////////////////////////////////
// DesktopWindowTreeHostWin, DesktopWindowTreeHost implementation:
void DesktopWindowTreeHostWin::Init(aura::Window* content_window,
const Widget::InitParams& params) {
// TODO(beng): SetInitParams().
content_window_ = content_window;
void DesktopWindowTreeHostWin::Init(const Widget::InitParams& params) {
wants_mouse_events_when_inactive_ = params.wants_mouse_events_when_inactive;
wm::SetAnimationHost(content_window_, this);
wm::SetAnimationHost(content_window(), this);
if (params.type == Widget::InitParams::TYPE_WINDOW &&
!params.remove_standard_frame)
content_window_->SetProperty(aura::client::kAnimationsDisabledKey, true);
content_window()->SetProperty(aura::client::kAnimationsDisabledKey, true);
ConfigureWindowStyles(message_handler_.get(), params,
GetWidget()->widget_delegate(),
......@@ -148,12 +143,12 @@ void DesktopWindowTreeHostWin::OnNativeWidgetCreated(
if (cursor_client)
is_cursor_visible_ = cursor_client->IsCursorVisible();
window()->SetProperty(kContentWindowForRootWindow, content_window_);
window()->SetProperty(kContentWindowForRootWindow, content_window());
window()->SetProperty(kDesktopWindowTreeHostKey, this);
should_animate_window_close_ =
content_window_->type() != aura::client::WINDOW_TYPE_NORMAL &&
!wm::WindowAnimationsDisabled(content_window_);
content_window()->type() != aura::client::WINDOW_TYPE_NORMAL &&
!wm::WindowAnimationsDisabled(content_window());
// TODO this is not invoked *after* Init(), but should be ok.
SetWindowTransparency();
......@@ -181,7 +176,7 @@ void DesktopWindowTreeHostWin::Close() {
if (should_animate_window_close_) {
pending_close_ = true;
const bool is_animating =
content_window_->layer()->GetAnimator()->IsAnimatingProperty(
content_window()->layer()->GetAnimator()->IsAnimatingProperty(
ui::LayerAnimationElement::VISIBILITY);
// Animation may not start for a number of reasons.
if (!is_animating)
......@@ -401,7 +396,7 @@ void DesktopWindowTreeHostWin::EndMoveLoop() {
void DesktopWindowTreeHostWin::SetVisibilityChangedAnimationsEnabled(
bool value) {
message_handler_->SetVisibilityChangedAnimationsEnabled(value);
content_window_->SetProperty(aura::client::kAnimationsDisabledKey, !value);
content_window()->SetProperty(aura::client::kAnimationsDisabledKey, !value);
}
NonClientFrameView* DesktopWindowTreeHostWin::CreateNonClientFrameView() {
......@@ -434,10 +429,10 @@ void DesktopWindowTreeHostWin::SetFullscreen(bool fullscreen) {
// TODO(sky): workaround for ScopedFullscreenVisibility showing window
// directly. Instead of this should listen for visibility changes and then
// update window.
if (message_handler_->IsVisible() && !content_window_->TargetVisibility()) {
if (message_handler_->IsVisible() && !content_window()->TargetVisibility()) {
if (compositor())
compositor()->SetVisible(true);
content_window_->Show();
content_window()->Show();
}
SetWindowTransparency();
}
......@@ -447,7 +442,7 @@ bool DesktopWindowTreeHostWin::IsFullscreen() const {
}
void DesktopWindowTreeHostWin::SetOpacity(float opacity) {
content_window_->layer()->SetOpacity(opacity);
content_window()->layer()->SetOpacity(opacity);
}
void DesktopWindowTreeHostWin::SetWindowIcons(
......@@ -1014,7 +1009,7 @@ void DesktopWindowTreeHostWin::SetWindowTransparency() {
compositor()->SetBackgroundColor(transparent ? SK_ColorTRANSPARENT
: SK_ColorWHITE);
window()->SetTransparent(transparent);
content_window_->SetTransparent(transparent);
content_window()->SetTransparent(transparent);
}
bool DesktopWindowTreeHostWin::IsModalWindowActive() const {
......@@ -1043,6 +1038,10 @@ void DesktopWindowTreeHostWin::CheckForMonitorChange() {
OnHostDisplayChanged();
}
aura::Window* DesktopWindowTreeHostWin::content_window() {
return desktop_native_widget_aura_->content_window();
}
////////////////////////////////////////////////////////////////////////////////
// DesktopWindowTreeHost, public:
......
......@@ -56,8 +56,7 @@ class VIEWS_EXPORT DesktopWindowTreeHostWin
protected:
// Overridden from DesktopWindowTreeHost:
void Init(aura::Window* content_window,
const Widget::InitParams& params) override;
void Init(const Widget::InitParams& params) override;
void OnNativeWidgetCreated(const Widget::InitParams& params) override;
void OnActiveWindowChanged(bool active) override;
void OnWidgetInitDone() override;
......@@ -233,6 +232,9 @@ class VIEWS_EXPORT DesktopWindowTreeHostWin
// has changed, and, if so, inform the aura::WindowTreeHost.
void CheckForMonitorChange();
// Accessor for DesktopNativeWidgetAura::content_window().
aura::Window* content_window();
HMONITOR last_monitor_from_window_ = nullptr;
std::unique_ptr<HWNDMessageHandler> message_handler_;
......@@ -244,8 +246,6 @@ class VIEWS_EXPORT DesktopWindowTreeHostWin
DesktopNativeWidgetAura* desktop_native_widget_aura_;
aura::Window* content_window_;
// Owned by DesktopNativeWidgetAura.
DesktopDragDropClientWin* drag_drop_client_;
......
......@@ -148,7 +148,6 @@ DesktopWindowTreeHostX11::DesktopWindowTreeHostX11(
drag_drop_client_(NULL),
native_widget_delegate_(native_widget_delegate),
desktop_native_widget_aura_(desktop_native_widget_aura),
content_window_(NULL),
window_parent_(NULL),
custom_window_shape_(false),
urgency_hint_set_(false),
......@@ -388,13 +387,11 @@ void DesktopWindowTreeHostX11::CleanUpWindowList(
////////////////////////////////////////////////////////////////////////////////
// DesktopWindowTreeHostX11, DesktopWindowTreeHost implementation:
void DesktopWindowTreeHostX11::Init(aura::Window* content_window,
const Widget::InitParams& params) {
content_window_ = content_window;
void DesktopWindowTreeHostX11::Init(const Widget::InitParams& params) {
activatable_ = (params.activatable == Widget::InitParams::ACTIVATABLE_YES);
if (params.type == Widget::InitParams::TYPE_WINDOW)
content_window_->SetProperty(aura::client::kAnimationsDisabledKey, true);
content_window()->SetProperty(aura::client::kAnimationsDisabledKey, true);
// TODO(erg): Check whether we *should* be building a WindowTreeHost here, or
// whether we should be proxying requests to another DRWHL.
......@@ -414,7 +411,7 @@ void DesktopWindowTreeHostX11::Init(aura::Window* content_window,
void DesktopWindowTreeHostX11::OnNativeWidgetCreated(
const Widget::InitParams& params) {
window()->SetProperty(kViewsWindowForRootWindow, content_window_);
window()->SetProperty(kViewsWindowForRootWindow, content_window());
window()->SetProperty(kHostForRootWindow, this);
// Ensure that the X11DesktopHandler exists so that it tracks create/destroy
......@@ -605,9 +602,9 @@ void DesktopWindowTreeHostX11::CenterWindow(const gfx::Size& size) {
// If |window_|'s transient parent bounds are big enough to contain |size|,
// use them instead.
if (wm::GetTransientParent(content_window_)) {
if (wm::GetTransientParent(content_window())) {
gfx::Rect transient_parent_rect =
wm::GetTransientParent(content_window_)->GetBoundsInScreen();
wm::GetTransientParent(content_window())->GetBoundsInScreen();
if (transient_parent_rect.height() >= size.height() &&
transient_parent_rect.width() >= size.width()) {
parent_bounds_in_pixels = ToPixelRect(transient_parent_rect);
......@@ -939,12 +936,13 @@ bool DesktopWindowTreeHostX11::SetWindowTitle(const base::string16& title) {
void DesktopWindowTreeHostX11::ClearNativeFocus() {
// This method is weird and misnamed. Instead of clearing the native focus,
// it sets the focus to our |content_window_|, which will trigger a cascade
// it sets the focus to our content_window(), which will trigger a cascade
// of focus changes into views.
if (content_window_ && aura::client::GetFocusClient(content_window_) &&
content_window_->Contains(
aura::client::GetFocusClient(content_window_)->GetFocusedWindow())) {
aura::client::GetFocusClient(content_window_)->FocusWindow(content_window_);
if (content_window() && aura::client::GetFocusClient(content_window()) &&
content_window()->Contains(
aura::client::GetFocusClient(content_window())->GetFocusedWindow())) {
aura::client::GetFocusClient(content_window())
->FocusWindow(content_window());
}
}
......@@ -955,7 +953,7 @@ Widget::MoveLoopResult DesktopWindowTreeHostX11::RunMoveLoop(
wm::WindowMoveSource window_move_source =
source == Widget::MOVE_LOOP_SOURCE_MOUSE ? wm::WINDOW_MOVE_SOURCE_MOUSE
: wm::WINDOW_MOVE_SOURCE_TOUCH;
if (x11_window_move_client_->RunMoveLoop(content_window_, drag_offset,
if (x11_window_move_client_->RunMoveLoop(content_window(), drag_offset,
window_move_source) ==
wm::MOVE_SUCCESSFUL)
return Widget::MOVE_LOOP_SUCCESSFUL;
......@@ -1635,9 +1633,9 @@ void DesktopWindowTreeHostX11::OnWMStateUpdated() {
if (is_minimized != was_minimized) {
if (is_minimized) {
SetVisible(false);
content_window_->Hide();
content_window()->Hide();
} else {
content_window_->Show();
content_window()->Show();
SetVisible(true);
}
}
......@@ -1765,10 +1763,10 @@ void DesktopWindowTreeHostX11::DispatchMouseEvent(ui::MouseEvent* event) {
// events on the ash desktop are clicking in what Windows considers to be a
// non client area.) Likewise, we won't want to do the following in any
// WindowTreeHost that hosts ash.
if (content_window_ && content_window_->delegate()) {
if (content_window() && content_window()->delegate()) {
int flags = event->flags();
int hit_test_code =
content_window_->delegate()->GetNonClientComponent(event->location());
content_window()->delegate()->GetNonClientComponent(event->location());
if (hit_test_code != HTCLIENT && hit_test_code != HTNOWHERE)
flags |= ui::EF_IS_NON_CLIENT;
event->set_flags(flags);
......@@ -1933,7 +1931,7 @@ void DesktopWindowTreeHostX11::SetWindowTransparency() {
compositor()->SetBackgroundColor(use_argb_visual_ ? SK_ColorTRANSPARENT
: SK_ColorWHITE);
window()->SetTransparent(use_argb_visual_);
content_window_->SetTransparent(use_argb_visual_);
content_window()->SetTransparent(use_argb_visual_);
}
void DesktopWindowTreeHostX11::Relayout() {
......@@ -2344,6 +2342,10 @@ void DesktopWindowTreeHostX11::RestartDelayedResizeTask() {
FROM_HERE, delayed_resize_task_.callback());
}
aura::Window* DesktopWindowTreeHostX11::content_window() {
return desktop_native_widget_aura_->content_window();
}
////////////////////////////////////////////////////////////////////////////////
// DesktopWindowTreeHost, public:
......
......@@ -51,7 +51,8 @@ class VIEWS_EXPORT DesktopWindowTreeHostX11
DesktopNativeWidgetAura* desktop_native_widget_aura);
~DesktopWindowTreeHostX11() override;
// A way of converting an X11 |xid| host window into a |content_window_|.
// A way of converting an X11 |xid| host window into the content_window()
// of the associated DesktopNativeWidgetAura.
static aura::Window* GetContentWindowForXID(XID xid);
// A way of converting an X11 |xid| host window into this object.
......@@ -88,8 +89,7 @@ class VIEWS_EXPORT DesktopWindowTreeHostX11
protected:
// Overridden from DesktopWindowTreeHost:
void Init(aura::Window* content_window,
const Widget::InitParams& params) override;
void Init(const Widget::InitParams& params) override;
void OnNativeWidgetCreated(const Widget::InitParams& params) override;
void OnWidgetInitDone() override;
void OnActiveWindowChanged(bool active) override;
......@@ -188,7 +188,7 @@ class VIEWS_EXPORT DesktopWindowTreeHostX11
// initialization related to talking to the X11 server.
void InitX11Window(const Widget::InitParams& params);
// Creates an aura::WindowEventDispatcher to contain the |content_window|,
// Creates an aura::WindowEventDispatcher to contain the content_window()
// along with all aura client objects that direct behavior.
aura::WindowEventDispatcher* InitDispatcher(const Widget::InitParams& params);
......@@ -285,6 +285,9 @@ class VIEWS_EXPORT DesktopWindowTreeHostX11
// Set visibility and fire OnNativeWidgetVisibilityChanged() if it changed.
void SetVisible(bool visible);
// Accessor for DesktopNativeWidgetAura::content_window().
aura::Window* content_window();
// X11 things
// The display and the native X window hosting the root window.
XDisplay* xdisplay_;
......@@ -355,8 +358,6 @@ class VIEWS_EXPORT DesktopWindowTreeHostX11
DesktopNativeWidgetAura* desktop_native_widget_aura_;
aura::Window* content_window_;
// We can optionally have a parent which can order us to close, or own
// children who we're responsible for closing when we CloseNow().
DesktopWindowTreeHostX11* window_parent_;
......
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