Commit 429647d3 authored by Elly Fong-Jones's avatar Elly Fong-Jones Committed by Commit Bot

exo: stop overriding WidgetDelegate window control methods

This involves a bit of restructuring. This change:
1) Introduces ShellSurface::Set{Parent,Container}Internal, which ensure
   that the minimize/maximize/resize state is correctly updated when
   these properties change;
2) Makes ShellSurface::parent_ private instead of protected so subclasses
   can't accidentally change it without using the new internal setter;
3) Has these internal setters and the ShellSurface constructor set the
   state of CanMaximize/CanMinimize/CanResize

Bug: 1075649
Change-Id: I019ce03248eef3aea6ac16c509f2e5d3312fb940
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2472615Reviewed-by: default avatarMitsuru Oshima <oshima@chromium.org>
Commit-Queue: Elly Fong-Jones <ellyjones@chromium.org>
Cr-Commit-Position: refs/heads/master@{#817269}
parent 34aa9ea3
......@@ -501,32 +501,28 @@ bool ShellSurface::OnPreWidgetCommit() {
////////////////////////////////////////////////////////////////////////////////
// ShellSurface, private:
void ShellSurface::SetParentWindow(aura::Window* parent) {
if (parent_) {
parent_->RemoveObserver(this);
void ShellSurface::SetParentWindow(aura::Window* new_parent) {
if (parent()) {
parent()->RemoveObserver(this);
if (widget_) {
aura::Window* child_window = widget_->GetNativeWindow();
wm::TransientWindowManager::GetOrCreate(child_window)
->set_parent_controls_visibility(false);
wm::RemoveTransientChild(parent_, child_window);
wm::RemoveTransientChild(parent(), child_window);
}
}
parent_ = parent;
if (parent_) {
parent_->AddObserver(this);
SetParentInternal(new_parent);
if (parent()) {
parent()->AddObserver(this);
MaybeMakeTransient();
}
// If |parent_| is set effects the ability to maximize the window.
if (widget_)
widget_->OnSizeConstraintsChanged();
}
void ShellSurface::MaybeMakeTransient() {
if (!parent_ || !widget_)
if (!parent() || !widget_)
return;
aura::Window* child_window = widget_->GetNativeWindow();
wm::AddTransientChild(parent_, child_window);
wm::AddTransientChild(parent(), child_window);
// In the case of activatable non-popups, we also want the parent to control
// the child's visibility.
if (!widget_->is_top_level() || !widget_->CanActivate())
......
......@@ -323,6 +323,9 @@ ShellSurfaceBase::ShellSurfaceBase(Surface* surface,
host_window()->Show();
set_owned_by_client();
SetCanMinimize(can_minimize_);
SetCanMaximize(ash::desks_util::IsDeskContainerId(container_));
SetCanResize(true);
SetShowTitle(false);
}
......@@ -483,8 +486,7 @@ void ShellSurfaceBase::SetActivatable(bool activatable) {
void ShellSurfaceBase::SetContainer(int container) {
TRACE_EVENT1("exo", "ShellSurfaceBase::SetContainer", "container", container);
container_ = container;
SetContainerInternal(container);
}
void ShellSurfaceBase::SetMaximumSize(const gfx::Size& size) {
......@@ -513,10 +515,12 @@ void ShellSurfaceBase::SetCanMinimize(bool can_minimize) {
can_minimize);
can_minimize_ = can_minimize;
WidgetDelegate::SetCanMinimize(!parent_ && can_minimize_);
}
void ShellSurfaceBase::DisableMovement() {
movement_disabled_ = true;
SetCanResize(false);
if (widget_)
widget_->set_movement_disabled(true);
......@@ -677,28 +681,6 @@ void ShellSurfaceBase::OnSurfaceDestroying(Surface* surface) {
////////////////////////////////////////////////////////////////////////////////
// views::WidgetDelegate overrides:
bool ShellSurfaceBase::CanResize() const {
if (movement_disabled_)
return false;
// The shell surface is resizable by default when min/max size is empty,
// othersize it's resizable when min size != max size.
return minimum_size_.IsEmpty() || minimum_size_ != maximum_size_;
}
bool ShellSurfaceBase::CanMaximize() const {
// Shell surfaces in system modal container cannot be maximized.
if (!ash::desks_util::IsDeskContainerId(container_))
return false;
// Non-transient shell surfaces can be maximized.
return !parent_;
}
bool ShellSurfaceBase::CanMinimize() const {
// Non-transient shell surfaces can be minimized.
return !parent_ && can_minimize_;
}
bool ShellSurfaceBase::OnCloseRequested(
views::Widget::ClosedReason close_reason) {
if (!pre_close_callback_.is_null())
......@@ -834,12 +816,8 @@ void ShellSurfaceBase::GetAccessibleNodeData(ui::AXNodeData* node_data) {
// aura::WindowObserver overrides:
void ShellSurfaceBase::OnWindowDestroying(aura::Window* window) {
if (window == parent_) {
parent_ = nullptr;
// |parent_| being set to null effects the ability to maximize the window.
if (widget_)
widget_->OnSizeConstraintsChanged();
}
if (window == parent_)
SetParentInternal(nullptr);
window->RemoveObserver(this);
}
......@@ -903,7 +881,7 @@ void ShellSurfaceBase::CreateShellSurfaceWidget(
// override redirect is used for menu, tooltips etc, which should be placed
// above normal windows, but below lock screen. Specify the container here
// to avoid using parent_ in params.parent.
container_ = ash::kShellWindowId_ShelfBubbleContainer;
SetContainerInternal(ash::kShellWindowId_ShelfBubbleContainer);
// X11 override redirect should not be activatable.
activatable_ = false;
DisableMovement();
......@@ -1140,6 +1118,23 @@ void ShellSurfaceBase::OnPostWidgetCommit() {
shadow_bounds_changed_ = false;
}
void ShellSurfaceBase::SetContainerInternal(int container) {
container_ = container;
WidgetDelegate::SetCanMaximize(
!parent_ && ash::desks_util::IsDeskContainerId(container_));
if (widget_)
widget_->OnSizeConstraintsChanged();
}
void ShellSurfaceBase::SetParentInternal(aura::Window* parent) {
parent_ = parent;
WidgetDelegate::SetCanMinimize(!parent_ && can_minimize_);
WidgetDelegate::SetCanMaximize(
!parent_ && ash::desks_util::IsDeskContainerId(container_));
if (widget_)
widget_->OnSizeConstraintsChanged();
}
void ShellSurfaceBase::CommitWidget() {
// Apply new window geometry.
geometry_ = pending_geometry_;
......@@ -1150,6 +1145,8 @@ void ShellSurfaceBase::CommitWidget() {
maximum_size_ != pending_maximum_size_;
minimum_size_ = pending_minimum_size_;
maximum_size_ = pending_maximum_size_;
SetCanResize(!movement_disabled_ &&
(minimum_size_.IsEmpty() || minimum_size_ != maximum_size_));
if (!widget_)
return;
......
......@@ -156,9 +156,6 @@ class ShellSurfaceBase : public SurfaceTreeHost,
aura::Window* gained_capture) override;
// views::WidgetDelegate:
bool CanResize() const override;
bool CanMaximize() const override;
bool CanMinimize() const override;
bool OnCloseRequested(views::Widget::ClosedReason close_reason) override;
void WindowClosing() override;
views::Widget* GetWidget() override;
......@@ -242,6 +239,7 @@ class ShellSurfaceBase : public SurfaceTreeHost,
void StartCapture();
const gfx::Rect& geometry() const { return geometry_; }
aura::Window* parent() const { return parent_; }
// Install custom window targeter. Used to restore window targeter.
void InstallCustomWindowTargeter();
......@@ -253,8 +251,10 @@ class ShellSurfaceBase : public SurfaceTreeHost,
virtual void OnPostWidgetCommit();
void SetParentInternal(aura::Window* window);
void SetContainerInternal(int container);
views::Widget* widget_ = nullptr;
aura::Window* parent_ = nullptr;
bool movement_disabled_ = false;
gfx::Point origin_;
......@@ -291,6 +291,7 @@ class ShellSurfaceBase : public SurfaceTreeHost,
void CommitWidget();
aura::Window* parent_ = nullptr;
bool activatable_ = true;
bool can_minimize_ = true;
bool has_frame_colors_ = false;
......
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