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() { ...@@ -501,32 +501,28 @@ bool ShellSurface::OnPreWidgetCommit() {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// ShellSurface, private: // ShellSurface, private:
void ShellSurface::SetParentWindow(aura::Window* parent) { void ShellSurface::SetParentWindow(aura::Window* new_parent) {
if (parent_) { if (parent()) {
parent_->RemoveObserver(this); parent()->RemoveObserver(this);
if (widget_) { if (widget_) {
aura::Window* child_window = widget_->GetNativeWindow(); aura::Window* child_window = widget_->GetNativeWindow();
wm::TransientWindowManager::GetOrCreate(child_window) wm::TransientWindowManager::GetOrCreate(child_window)
->set_parent_controls_visibility(false); ->set_parent_controls_visibility(false);
wm::RemoveTransientChild(parent_, child_window); wm::RemoveTransientChild(parent(), child_window);
} }
} }
parent_ = parent; SetParentInternal(new_parent);
if (parent_) { if (parent()) {
parent_->AddObserver(this); parent()->AddObserver(this);
MaybeMakeTransient(); MaybeMakeTransient();
} }
// If |parent_| is set effects the ability to maximize the window.
if (widget_)
widget_->OnSizeConstraintsChanged();
} }
void ShellSurface::MaybeMakeTransient() { void ShellSurface::MaybeMakeTransient() {
if (!parent_ || !widget_) if (!parent() || !widget_)
return; return;
aura::Window* child_window = widget_->GetNativeWindow(); 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 // In the case of activatable non-popups, we also want the parent to control
// the child's visibility. // the child's visibility.
if (!widget_->is_top_level() || !widget_->CanActivate()) if (!widget_->is_top_level() || !widget_->CanActivate())
......
...@@ -323,6 +323,9 @@ ShellSurfaceBase::ShellSurfaceBase(Surface* surface, ...@@ -323,6 +323,9 @@ ShellSurfaceBase::ShellSurfaceBase(Surface* surface,
host_window()->Show(); host_window()->Show();
set_owned_by_client(); set_owned_by_client();
SetCanMinimize(can_minimize_);
SetCanMaximize(ash::desks_util::IsDeskContainerId(container_));
SetCanResize(true);
SetShowTitle(false); SetShowTitle(false);
} }
...@@ -483,8 +486,7 @@ void ShellSurfaceBase::SetActivatable(bool activatable) { ...@@ -483,8 +486,7 @@ void ShellSurfaceBase::SetActivatable(bool activatable) {
void ShellSurfaceBase::SetContainer(int container) { void ShellSurfaceBase::SetContainer(int container) {
TRACE_EVENT1("exo", "ShellSurfaceBase::SetContainer", "container", container); TRACE_EVENT1("exo", "ShellSurfaceBase::SetContainer", "container", container);
SetContainerInternal(container);
container_ = container;
} }
void ShellSurfaceBase::SetMaximumSize(const gfx::Size& size) { void ShellSurfaceBase::SetMaximumSize(const gfx::Size& size) {
...@@ -513,10 +515,12 @@ void ShellSurfaceBase::SetCanMinimize(bool can_minimize) { ...@@ -513,10 +515,12 @@ void ShellSurfaceBase::SetCanMinimize(bool can_minimize) {
can_minimize); can_minimize);
can_minimize_ = can_minimize; can_minimize_ = can_minimize;
WidgetDelegate::SetCanMinimize(!parent_ && can_minimize_);
} }
void ShellSurfaceBase::DisableMovement() { void ShellSurfaceBase::DisableMovement() {
movement_disabled_ = true; movement_disabled_ = true;
SetCanResize(false);
if (widget_) if (widget_)
widget_->set_movement_disabled(true); widget_->set_movement_disabled(true);
...@@ -677,28 +681,6 @@ void ShellSurfaceBase::OnSurfaceDestroying(Surface* surface) { ...@@ -677,28 +681,6 @@ void ShellSurfaceBase::OnSurfaceDestroying(Surface* surface) {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// views::WidgetDelegate overrides: // 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( bool ShellSurfaceBase::OnCloseRequested(
views::Widget::ClosedReason close_reason) { views::Widget::ClosedReason close_reason) {
if (!pre_close_callback_.is_null()) if (!pre_close_callback_.is_null())
...@@ -834,12 +816,8 @@ void ShellSurfaceBase::GetAccessibleNodeData(ui::AXNodeData* node_data) { ...@@ -834,12 +816,8 @@ void ShellSurfaceBase::GetAccessibleNodeData(ui::AXNodeData* node_data) {
// aura::WindowObserver overrides: // aura::WindowObserver overrides:
void ShellSurfaceBase::OnWindowDestroying(aura::Window* window) { void ShellSurfaceBase::OnWindowDestroying(aura::Window* window) {
if (window == parent_) { if (window == parent_)
parent_ = nullptr; SetParentInternal(nullptr);
// |parent_| being set to null effects the ability to maximize the window.
if (widget_)
widget_->OnSizeConstraintsChanged();
}
window->RemoveObserver(this); window->RemoveObserver(this);
} }
...@@ -903,7 +881,7 @@ void ShellSurfaceBase::CreateShellSurfaceWidget( ...@@ -903,7 +881,7 @@ void ShellSurfaceBase::CreateShellSurfaceWidget(
// override redirect is used for menu, tooltips etc, which should be placed // override redirect is used for menu, tooltips etc, which should be placed
// above normal windows, but below lock screen. Specify the container here // above normal windows, but below lock screen. Specify the container here
// to avoid using parent_ in params.parent. // to avoid using parent_ in params.parent.
container_ = ash::kShellWindowId_ShelfBubbleContainer; SetContainerInternal(ash::kShellWindowId_ShelfBubbleContainer);
// X11 override redirect should not be activatable. // X11 override redirect should not be activatable.
activatable_ = false; activatable_ = false;
DisableMovement(); DisableMovement();
...@@ -1140,6 +1118,23 @@ void ShellSurfaceBase::OnPostWidgetCommit() { ...@@ -1140,6 +1118,23 @@ void ShellSurfaceBase::OnPostWidgetCommit() {
shadow_bounds_changed_ = false; 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() { void ShellSurfaceBase::CommitWidget() {
// Apply new window geometry. // Apply new window geometry.
geometry_ = pending_geometry_; geometry_ = pending_geometry_;
...@@ -1150,6 +1145,8 @@ void ShellSurfaceBase::CommitWidget() { ...@@ -1150,6 +1145,8 @@ void ShellSurfaceBase::CommitWidget() {
maximum_size_ != pending_maximum_size_; maximum_size_ != pending_maximum_size_;
minimum_size_ = pending_minimum_size_; minimum_size_ = pending_minimum_size_;
maximum_size_ = pending_maximum_size_; maximum_size_ = pending_maximum_size_;
SetCanResize(!movement_disabled_ &&
(minimum_size_.IsEmpty() || minimum_size_ != maximum_size_));
if (!widget_) if (!widget_)
return; return;
......
...@@ -156,9 +156,6 @@ class ShellSurfaceBase : public SurfaceTreeHost, ...@@ -156,9 +156,6 @@ class ShellSurfaceBase : public SurfaceTreeHost,
aura::Window* gained_capture) override; aura::Window* gained_capture) override;
// views::WidgetDelegate: // views::WidgetDelegate:
bool CanResize() const override;
bool CanMaximize() const override;
bool CanMinimize() const override;
bool OnCloseRequested(views::Widget::ClosedReason close_reason) override; bool OnCloseRequested(views::Widget::ClosedReason close_reason) override;
void WindowClosing() override; void WindowClosing() override;
views::Widget* GetWidget() override; views::Widget* GetWidget() override;
...@@ -242,6 +239,7 @@ class ShellSurfaceBase : public SurfaceTreeHost, ...@@ -242,6 +239,7 @@ class ShellSurfaceBase : public SurfaceTreeHost,
void StartCapture(); void StartCapture();
const gfx::Rect& geometry() const { return geometry_; } const gfx::Rect& geometry() const { return geometry_; }
aura::Window* parent() const { return parent_; }
// Install custom window targeter. Used to restore window targeter. // Install custom window targeter. Used to restore window targeter.
void InstallCustomWindowTargeter(); void InstallCustomWindowTargeter();
...@@ -253,8 +251,10 @@ class ShellSurfaceBase : public SurfaceTreeHost, ...@@ -253,8 +251,10 @@ class ShellSurfaceBase : public SurfaceTreeHost,
virtual void OnPostWidgetCommit(); virtual void OnPostWidgetCommit();
void SetParentInternal(aura::Window* window);
void SetContainerInternal(int container);
views::Widget* widget_ = nullptr; views::Widget* widget_ = nullptr;
aura::Window* parent_ = nullptr;
bool movement_disabled_ = false; bool movement_disabled_ = false;
gfx::Point origin_; gfx::Point origin_;
...@@ -291,6 +291,7 @@ class ShellSurfaceBase : public SurfaceTreeHost, ...@@ -291,6 +291,7 @@ class ShellSurfaceBase : public SurfaceTreeHost,
void CommitWidget(); void CommitWidget();
aura::Window* parent_ = nullptr;
bool activatable_ = true; bool activatable_ = true;
bool can_minimize_ = true; bool can_minimize_ = true;
bool has_frame_colors_ = false; 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