Index: ash/wm/default_state.cc |
diff --git a/ash/wm/default_state.cc b/ash/wm/default_state.cc |
index b482dbc607add5e8523716e6d2815acc58e8bdb1..19ebae550549eb5cf47b6794a42aa2860a110a32 100644 |
--- a/ash/wm/default_state.cc |
+++ b/ash/wm/default_state.cc |
@@ -20,8 +20,10 @@ |
#include "ash/wm_window.h" |
#include "ui/aura/client/aura_constants.h" |
#include "ui/aura/window.h" |
+#include "ui/aura/window_delegate.h" |
#include "ui/display/display.h" |
#include "ui/display/screen.h" |
+#include "ui/wm/core/window_util.h" |
namespace ash { |
namespace wm { |
@@ -36,6 +38,11 @@ const float kMinimumPercentOnScreenArea = 0.3f; |
// This makes it easier to resize the window. |
const int kMaximizedWindowInset = 10; // DIPs. |
+gfx::Size GetWindowMaximumSize(aura::Window* window) { |
+ return window->delegate() ? window->delegate()->GetMaximumSize() |
+ : gfx::Size(); |
+} |
+ |
bool IsMinimizedWindowState(const WindowStateType state_type) { |
return state_type == WINDOW_STATE_TYPE_MINIMIZED; |
} |
@@ -51,8 +58,9 @@ void MoveToDisplayForRestore(WindowState* window_state) { |
// TODO(oshima): Restore information should contain the |
// work area information like WindowResizer does for the |
// last window location. |
- gfx::Rect display_area = |
- window_state->window()->GetDisplayNearestWindow().bounds(); |
+ gfx::Rect display_area = display::Screen::GetScreen() |
+ ->GetDisplayNearestWindow(window_state->window()) |
+ .bounds(); |
if (!display_area.Intersects(restore_bounds)) { |
const display::Display& display = |
@@ -60,11 +68,11 @@ void MoveToDisplayForRestore(WindowState* window_state) { |
RootWindowController* new_root_controller = |
Shell::Get()->GetRootWindowControllerWithDisplayId(display.id()); |
if (new_root_controller->GetRootWindow() != |
- window_state->window()->GetRootWindow()->aura_window()) { |
+ window_state->window()->GetRootWindow()) { |
aura::Window* new_container = |
new_root_controller->GetRootWindow()->GetChildById( |
- window_state->window()->GetParent()->aura_window()->id()); |
- new_container->AddChild(window_state->window()->aura_window()); |
+ window_state->window()->parent()->id()); |
+ new_container->AddChild(window_state->window()); |
} |
} |
} |
@@ -76,7 +84,7 @@ void CycleSnap(WindowState* window_state, WMEventType event) { |
if (window_state->CanSnap() && |
window_state->GetStateType() != desired_snap_state && |
- window_state->window()->GetType() != ui::wm::WINDOW_TYPE_PANEL) { |
+ window_state->window()->type() != ui::wm::WINDOW_TYPE_PANEL) { |
const wm::WMEvent event(desired_snap_state == |
wm::WINDOW_STATE_TYPE_LEFT_SNAPPED |
? wm::WM_EVENT_SNAP_LEFT |
@@ -89,7 +97,8 @@ void CycleSnap(WindowState* window_state, WMEventType event) { |
window_state->Restore(); |
return; |
} |
- window_state->window()->Animate(::wm::WINDOW_ANIMATION_TYPE_BOUNCE); |
+ ::wm::AnimateWindow(window_state->window(), |
+ ::wm::WINDOW_ANIMATION_TYPE_BOUNCE); |
} |
} // namespace |
@@ -170,7 +179,7 @@ void DefaultState::OnWMEvent(WindowState* window_state, const WMEvent* event) { |
} |
if (next_state_type == current_state_type && window_state->IsSnapped()) { |
- aura::Window* window = window_state->window()->aura_window(); |
+ aura::Window* window = window_state->window(); |
gfx::Rect snapped_bounds = |
event->type() == WM_EVENT_SNAP_LEFT |
? GetDefaultLeftSnappedWindowBoundsInParent(window) |
@@ -200,7 +209,8 @@ void DefaultState::AttachState(WindowState* window_state, |
// If the display has changed while in the another mode, |
// we need to let windows know the change. |
display::Display current_display = |
- window_state->window()->GetDisplayNearestWindow(); |
+ display::Screen::GetScreen()->GetDisplayNearestWindow( |
+ window_state->window()); |
if (stored_display_state_.bounds() != current_display.bounds()) { |
const WMEvent event(wm::WM_EVENT_DISPLAY_BOUNDS_CHANGED); |
window_state->OnWMEvent(&event); |
@@ -212,7 +222,7 @@ void DefaultState::AttachState(WindowState* window_state, |
void DefaultState::DetachState(WindowState* window_state) { |
stored_window_state_ = window_state; |
- stored_bounds_ = window_state->window()->GetBounds(); |
+ stored_bounds_ = window_state->window()->bounds(); |
stored_restore_bounds_ = window_state->HasRestoreBounds() |
? window_state->GetRestoreBoundsInParent() |
: gfx::Rect(); |
@@ -220,13 +230,14 @@ void DefaultState::DetachState(WindowState* window_state) { |
// while in the other mode, we can perform necessary action to |
// restore the window state to the proper state for the current |
// display. |
- stored_display_state_ = window_state->window()->GetDisplayNearestWindow(); |
+ stored_display_state_ = display::Screen::GetScreen()->GetDisplayNearestWindow( |
+ window_state->window()); |
} |
// static |
bool DefaultState::ProcessCompoundEvents(WindowState* window_state, |
const WMEvent* event) { |
- WmWindow* window = window_state->window(); |
+ aura::Window* window = window_state->window(); |
switch (event->type()) { |
case WM_EVENT_TOGGLE_MAXIMIZE_CAPTION: |
@@ -252,25 +263,25 @@ bool DefaultState::ProcessCompoundEvents(WindowState* window_state, |
return true; |
case WM_EVENT_TOGGLE_VERTICAL_MAXIMIZE: { |
gfx::Rect work_area = |
- ScreenUtil::GetDisplayWorkAreaBoundsInParent(window->aura_window()); |
+ ScreenUtil::GetDisplayWorkAreaBoundsInParent(window); |
// Maximize vertically if: |
// - The window does not have a max height defined. |
// - The window has the normal state type. Snapped windows are excluded |
// because they are already maximized vertically and reverting to the |
// restored bounds looks weird. |
- if (window->GetMaximumSize().height() != 0 || |
+ if (GetWindowMaximumSize(window).height() != 0 || |
!window_state->IsNormalStateType()) { |
return true; |
} |
if (window_state->HasRestoreBounds() && |
- (window->GetBounds().height() == work_area.height() && |
- window->GetBounds().y() == work_area.y())) { |
+ (window->bounds().height() == work_area.height() && |
+ window->bounds().y() == work_area.y())) { |
window_state->SetAndClearRestoreBounds(); |
} else { |
window_state->SaveCurrentBoundsForRestore(); |
- window->SetBounds(gfx::Rect(window->GetBounds().x(), work_area.y(), |
- window->GetBounds().width(), |
+ window->SetBounds(gfx::Rect(window->bounds().x(), work_area.y(), |
+ window->bounds().width(), |
work_area.height())); |
} |
return true; |
@@ -279,22 +290,22 @@ bool DefaultState::ProcessCompoundEvents(WindowState* window_state, |
// Maximize horizontally if: |
// - The window does not have a max width defined. |
// - The window is snapped or has the normal state type. |
- if (window->GetMaximumSize().width() != 0) |
+ if (GetWindowMaximumSize(window).width() != 0) |
return true; |
if (!window_state->IsNormalOrSnapped()) |
return true; |
gfx::Rect work_area = |
- ScreenUtil::GetDisplayWorkAreaBoundsInParent(window->aura_window()); |
+ ScreenUtil::GetDisplayWorkAreaBoundsInParent(window); |
if (window_state->IsNormalStateType() && |
window_state->HasRestoreBounds() && |
- (window->GetBounds().width() == work_area.width() && |
- window->GetBounds().x() == work_area.x())) { |
+ (window->bounds().width() == work_area.width() && |
+ window->bounds().x() == work_area.x())) { |
window_state->SetAndClearRestoreBounds(); |
} else { |
- gfx::Rect new_bounds(work_area.x(), window->GetBounds().y(), |
- work_area.width(), window->GetBounds().height()); |
+ gfx::Rect new_bounds(work_area.x(), window->bounds().y(), |
+ work_area.width(), window->bounds().height()); |
- gfx::Rect restore_bounds = window->GetBounds(); |
+ gfx::Rect restore_bounds = window->bounds(); |
if (window_state->IsSnapped()) { |
window_state->SetRestoreBoundsInParent(new_bounds); |
window_state->Restore(); |
@@ -354,8 +365,8 @@ bool DefaultState::ProcessWorkspaceEvents(WindowState* window_state, |
return true; |
} |
- WmWindow* window = window_state->window(); |
- gfx::Rect bounds = window->GetBounds(); |
+ aura::Window* window = window_state->window(); |
+ gfx::Rect bounds = window->bounds(); |
// Don't adjust window bounds if the bounds are empty as this |
// happens when a new views::Widget is created. |
@@ -372,14 +383,13 @@ bool DefaultState::ProcessWorkspaceEvents(WindowState* window_state, |
// Use entire display instead of workarea. The logic ensures 30% |
// visibility which should be enough to see where the window gets |
// moved. |
- gfx::Rect display_area = |
- ScreenUtil::GetDisplayBoundsInParent(window->aura_window()); |
+ gfx::Rect display_area = ScreenUtil::GetDisplayBoundsInParent(window); |
int min_width = bounds.width() * wm::kMinimumPercentOnScreenArea; |
int min_height = bounds.height() * wm::kMinimumPercentOnScreenArea; |
wm::AdjustBoundsToEnsureWindowVisibility(display_area, min_width, |
min_height, &bounds); |
window_state->AdjustSnappedBounds(&bounds); |
- if (window->GetBounds() != bounds) |
+ if (window->bounds() != bounds) |
window_state->SetBoundsConstrained(bounds); |
return true; |
} |
@@ -390,8 +400,7 @@ bool DefaultState::ProcessWorkspaceEvents(WindowState* window_state, |
return true; |
} |
gfx::Rect work_area_in_parent = |
- ScreenUtil::GetDisplayWorkAreaBoundsInParent( |
- window_state->window()->aura_window()); |
+ ScreenUtil::GetDisplayWorkAreaBoundsInParent(window_state->window()); |
gfx::Rect bounds = window_state->window()->GetTargetBounds(); |
// When display bounds has changed, make sure the entire window is fully |
// visible. |
@@ -405,8 +414,7 @@ bool DefaultState::ProcessWorkspaceEvents(WindowState* window_state, |
// Don't resize the maximized window when the desktop is covered |
// by fullscreen window. crbug.com/504299. |
bool in_fullscreen = |
- window_state->window() |
- ->GetRootWindowController() |
+ RootWindowController::ForWindow(window_state->window()) |
->GetWorkspaceWindowState() == WORKSPACE_WINDOW_STATE_FULL_SCREEN; |
if (in_fullscreen && window_state->IsMaximized()) |
return true; |
@@ -417,10 +425,9 @@ bool DefaultState::ProcessWorkspaceEvents(WindowState* window_state, |
return true; |
} |
gfx::Rect work_area_in_parent = |
- ScreenUtil::GetDisplayWorkAreaBoundsInParent( |
- window_state->window()->aura_window()); |
+ ScreenUtil::GetDisplayWorkAreaBoundsInParent(window_state->window()); |
gfx::Rect bounds = window_state->window()->GetTargetBounds(); |
- if (!window_state->window()->GetTransientParent()) { |
+ if (!::wm::GetTransientParent(window_state->window())) { |
wm::AdjustBoundsToEnsureMinimumWindowVisibility(work_area_in_parent, |
&bounds); |
} |
@@ -457,13 +464,13 @@ bool DefaultState::SetMaximizedOrFullscreenBounds(WindowState* window_state) { |
DCHECK(!window_state->is_dragged()); |
DCHECK(!window_state->allow_set_bounds_direct()); |
if (window_state->IsMaximized()) { |
- window_state->SetBoundsDirect(ScreenUtil::GetMaximizedWindowBoundsInParent( |
- window_state->window()->aura_window())); |
+ window_state->SetBoundsDirect( |
+ ScreenUtil::GetMaximizedWindowBoundsInParent(window_state->window())); |
return true; |
} |
if (window_state->IsFullscreen()) { |
- window_state->SetBoundsDirect(ScreenUtil::GetDisplayBoundsInParent( |
- window_state->window()->aura_window())); |
+ window_state->SetBoundsDirect( |
+ ScreenUtil::GetDisplayBoundsInParent(window_state->window())); |
return true; |
} |
return false; |
@@ -477,8 +484,7 @@ void DefaultState::SetBounds(WindowState* window_state, |
window_state->SetBoundsDirect(event->requested_bounds()); |
} else if (window_state->IsSnapped()) { |
gfx::Rect work_area_in_parent = |
- ScreenUtil::GetDisplayWorkAreaBoundsInParent( |
- window_state->window()->aura_window()); |
+ ScreenUtil::GetDisplayWorkAreaBoundsInParent(window_state->window()); |
gfx::Rect child_bounds(event->requested_bounds()); |
wm::AdjustBoundsSmallerThan(work_area_in_parent.size(), &child_bounds); |
window_state->AdjustSnappedBounds(&child_bounds); |
@@ -500,7 +506,7 @@ void DefaultState::EnterToNextState(WindowState* window_state, |
window_state->UpdateWindowPropertiesFromStateType(); |
window_state->NotifyPreStateTypeChange(previous_state_type); |
- if (window_state->window()->GetParent()) { |
+ if (window_state->window()->parent()) { |
if (!window_state->HasRestoreBounds() && |
(previous_state_type == WINDOW_STATE_TYPE_DEFAULT || |
previous_state_type == WINDOW_STATE_TYPE_NORMAL) && |
@@ -539,7 +545,7 @@ void DefaultState::EnterToNextState(WindowState* window_state, |
next_state_type == WINDOW_STATE_TYPE_TRUSTED_PINNED || |
previous_state_type == WINDOW_STATE_TYPE_TRUSTED_PINNED) { |
Shell::Get()->screen_pinning_controller()->SetPinnedWindow( |
- window_state->window()); |
+ WmWindow::Get(window_state->window())); |
} |
} |
@@ -585,7 +591,7 @@ void DefaultState::ReenterToCurrentState( |
void DefaultState::UpdateBoundsFromState(WindowState* window_state, |
WindowStateType previous_state_type) { |
- aura::Window* window = window_state->window()->aura_window(); |
+ aura::Window* window = window_state->window(); |
gfx::Rect bounds_in_parent; |
switch (state_type_) { |
case WINDOW_STATE_TYPE_LEFT_SNAPPED: |
@@ -688,19 +694,21 @@ void DefaultState::UpdateBoundsFromState(WindowState* window_state, |
void DefaultState::CenterWindow(WindowState* window_state) { |
if (!window_state->IsNormalOrSnapped()) |
return; |
- WmWindow* window = window_state->window(); |
+ aura::Window* window = window_state->window(); |
if (window_state->IsSnapped()) { |
- gfx::Rect center_in_screen = window->GetDisplayNearestWindow().work_area(); |
+ gfx::Rect center_in_screen = display::Screen::GetScreen() |
+ ->GetDisplayNearestWindow(window) |
+ .work_area(); |
gfx::Size size = window_state->HasRestoreBounds() |
? window_state->GetRestoreBoundsInScreen().size() |
- : window->GetBounds().size(); |
+ : window->bounds().size(); |
center_in_screen.ClampToCenteredSize(size); |
window_state->SetRestoreBoundsInScreen(center_in_screen); |
window_state->Restore(); |
} else { |
gfx::Rect center_in_parent = |
- ScreenUtil::GetDisplayWorkAreaBoundsInParent(window->aura_window()); |
- center_in_parent.ClampToCenteredSize(window->GetBounds().size()); |
+ ScreenUtil::GetDisplayWorkAreaBoundsInParent(window); |
+ center_in_parent.ClampToCenteredSize(window->bounds().size()); |
window_state->SetBoundsDirectAnimated(center_in_parent); |
} |
// Centering window is treated as if a user moved and resized the window. |