Commit 6d544b2c authored by jackhou@chromium.org's avatar jackhou@chromium.org

Call OnNativeWindowChanged after maximizing and restoring.

OnNativeWindowChanged is normally called when a window's bounds change.
However, if an app maximizes via the AppWindow API, but its bounds are
the same as that of a maximized window, OnNativeWindowChanged does not
end up being called.

This CL ensures that OnNativeWindowChanged is called whenever the app
maximizes or restores.

BUG=395900

Review URL: https://codereview.chromium.org/434343004

Cr-Commit-Position: refs/heads/master@{#289246}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@289246 0039d316-1c4b-4281-b951-d872f2087c98
parent 35c11844
......@@ -157,6 +157,9 @@ void NativeWidgetAura::InitNativeWidget(const Widget::InitParams& params) {
window_, context->GetRootWindow(), window_bounds);
}
// Start observing property changes.
window_->AddObserver(this);
// Wait to set the bounds until we have a parent. That way we can know our
// true state/bounds (the LayoutManager may enforce a particular
// state/bounds).
......@@ -800,6 +803,7 @@ void NativeWidgetAura::OnDeviceScaleFactorChanged(float device_scale_factor) {
}
void NativeWidgetAura::OnWindowDestroying(aura::Window* window) {
window_->RemoveObserver(this);
delegate_->OnNativeWidgetDestroying();
// If the aura::Window is destroyed, we can no longer show tooltips.
......@@ -826,6 +830,16 @@ void NativeWidgetAura::GetHitTestMask(gfx::Path* mask) const {
delegate_->GetHitTestMask(mask);
}
////////////////////////////////////////////////////////////////////////////////
// NativeWidgetAura, aura::WindowObserver implementation:
void NativeWidgetAura::OnWindowPropertyChanged(aura::Window* window,
const void* key,
intptr_t old) {
if (key == aura::client::kShowStateKey)
delegate_->OnNativeWidgetWindowShowStateChanged();
}
////////////////////////////////////////////////////////////////////////////////
// NativeWidgetAura, ui::EventHandler implementation:
......
......@@ -9,6 +9,7 @@
#include "base/memory/weak_ptr.h"
#include "ui/aura/client/focus_change_observer.h"
#include "ui/aura/window_delegate.h"
#include "ui/aura/window_observer.h"
#include "ui/base/cursor/cursor.h"
#include "ui/events/event_constants.h"
#include "ui/views/ime/input_method_delegate.h"
......@@ -35,6 +36,7 @@ class VIEWS_EXPORT NativeWidgetAura
: public internal::NativeWidgetPrivate,
public internal::InputMethodDelegate,
public aura::WindowDelegate,
public aura::WindowObserver,
public aura::client::ActivationDelegate,
public aura::client::ActivationChangeObserver,
public aura::client::FocusChangeObserver,
......@@ -158,6 +160,11 @@ class VIEWS_EXPORT NativeWidgetAura
virtual bool HasHitTestMask() const OVERRIDE;
virtual void GetHitTestMask(gfx::Path* mask) const OVERRIDE;
// Overridden from aura::WindowObserver:
virtual void OnWindowPropertyChanged(aura::Window* window,
const void* key,
intptr_t old) OVERRIDE;
// Overridden from ui::EventHandler:
virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE;
virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE;
......
......@@ -89,8 +89,15 @@ class VIEWS_EXPORT NativeWidgetDelegate {
virtual void OnNativeWidgetMove() = 0;
// Called when the NativeWidget changed size to |new_size|.
// This may happen at the same time as OnNativeWidgetWindowShowStateChanged,
// e.g. maximize.
virtual void OnNativeWidgetSizeChanged(const gfx::Size& new_size) = 0;
// Called when the NativeWidget changes its window state.
// This may happen at the same time as OnNativeWidgetSizeChanged, e.g.
// maximize.
virtual void OnNativeWidgetWindowShowStateChanged() = 0;
// Called when the user begins/ends to change the bounds of the window.
virtual void OnNativeWidgetBeginUserBoundsChange() = 0;
virtual void OnNativeWidgetEndUserBoundsChange() = 0;
......
......@@ -1127,17 +1127,17 @@ void Widget::OnNativeWidgetSizeChanged(const gfx::Size& new_size) {
focused_view->GetInputMethod()->OnCaretBoundsChanged(focused_view);
}
}
// Size changed notifications can fire prior to full initialization
// i.e. during session restore. Avoid saving session state during these
// startup procedures.
if (native_widget_initialized_)
SaveWindowPlacement();
SaveWindowPlacementIfInitialized();
FOR_EACH_OBSERVER(WidgetObserver, observers_, OnWidgetBoundsChanged(
this,
GetWindowBoundsInScreen()));
}
void Widget::OnNativeWidgetWindowShowStateChanged() {
SaveWindowPlacementIfInitialized();
}
void Widget::OnNativeWidgetBeginUserBoundsChange() {
widget_delegate_->OnWindowBeginUserBoundsChange();
}
......@@ -1426,6 +1426,11 @@ void Widget::SaveWindowPlacement() {
widget_delegate_->SaveWindowPlacement(bounds, show_state);
}
void Widget::SaveWindowPlacementIfInitialized() {
if (native_widget_initialized_)
SaveWindowPlacement();
}
void Widget::SetInitialBounds(const gfx::Rect& bounds) {
if (!non_client_view_)
return;
......
......@@ -756,6 +756,7 @@ class VIEWS_EXPORT Widget : public internal::NativeWidgetDelegate,
virtual gfx::Size GetMaximumSize() const OVERRIDE;
virtual void OnNativeWidgetMove() OVERRIDE;
virtual void OnNativeWidgetSizeChanged(const gfx::Size& new_size) OVERRIDE;
virtual void OnNativeWidgetWindowShowStateChanged() OVERRIDE;
virtual void OnNativeWidgetBeginUserBoundsChange() OVERRIDE;
virtual void OnNativeWidgetEndUserBoundsChange() OVERRIDE;
virtual bool HasFocusManager() const OVERRIDE;
......@@ -817,6 +818,11 @@ class VIEWS_EXPORT Widget : public internal::NativeWidgetDelegate,
// window delegate.
void SaveWindowPlacement();
// Invokes SaveWindowPlacement() if the native widget has been initialized.
// This is called at times when the native widget may not have been
// initialized.
void SaveWindowPlacementIfInitialized();
// Sizes and positions the window just after it is created.
void SetInitialBounds(const gfx::Rect& bounds);
......
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