window_state.cc revision a1401311d1ab56c4ed0a474bd38c108f75cb0cd9
168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved. 268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)// found in the LICENSE file. 468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)#include "ash/wm/window_state.h" 668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 7a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "ash/ash_switches.h" 868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)#include "ash/root_window_controller.h" 95d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ash/screen_util.h" 1068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)#include "ash/shell_window_ids.h" 115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ash/wm/default_state.h" 12a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ash/wm/window_animations.h" 1368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)#include "ash/wm/window_properties.h" 141e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "ash/wm/window_state_delegate.h" 154e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "ash/wm/window_state_observer.h" 1668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)#include "ash/wm/window_util.h" 17a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ash/wm/wm_event.h" 18a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "base/auto_reset.h" 19a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "base/command_line.h" 2068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)#include "ui/aura/client/aura_constants.h" 215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/aura/layout_manager.h" 2268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)#include "ui/aura/window.h" 2368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)#include "ui/aura/window_delegate.h" 24a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ui/compositor/layer_tree_owner.h" 255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/compositor/scoped_layer_animation_settings.h" 2668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)#include "ui/gfx/display.h" 27a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ui/wm/core/window_util.h" 2868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 2968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)namespace ash { 3068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)namespace wm { 3168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)namespace { 335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// A tentative class to set the bounds on the window. 355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// TODO(oshima): Once all logic is cleaned up, move this to the real layout 365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// manager with proper friendship. 375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class BoundsSetter : public aura::LayoutManager { 385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) public: 395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) BoundsSetter() {} 405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) virtual ~BoundsSetter() {} 415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // aura::LayoutManager overrides: 435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) virtual void OnWindowResized() OVERRIDE {} 445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE {} 455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE {} 465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE {} 475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) virtual void OnChildWindowVisibilityChanged( 485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) aura::Window* child, bool visible) OVERRIDE {} 495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) virtual void SetChildBounds( 505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) aura::Window* child, const gfx::Rect& requested_bounds) OVERRIDE {} 515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void SetBounds(aura::Window* window, const gfx::Rect& bounds) { 535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) SetChildBoundsDirect(window, bounds); 545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) private: 575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(BoundsSetter); 585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}; 595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 60a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)WMEventType WMEventTypeFromShowState(ui::WindowShowState requested_show_state) { 615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) switch (requested_show_state) { 625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) case ui::SHOW_STATE_DEFAULT: 635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) case ui::SHOW_STATE_NORMAL: 64a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return WM_EVENT_NORMAL; 655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) case ui::SHOW_STATE_MINIMIZED: 66a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return WM_EVENT_MINIMIZE; 675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) case ui::SHOW_STATE_MAXIMIZED: 68a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return WM_EVENT_MAXIMIZE; 695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) case ui::SHOW_STATE_FULLSCREEN: 70a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return WM_EVENT_FULLSCREEN; 715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) case ui::SHOW_STATE_INACTIVE: 72a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return WM_EVENT_SHOW_INACTIVE; 735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) case ui::SHOW_STATE_DETACHED: 745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) case ui::SHOW_STATE_END: 75a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) NOTREACHED() << "No WMEvent defined for the show state:" 765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) << requested_show_state; 775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 78a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return WM_EVENT_NORMAL; 7968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)} 8068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} // namespace 825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 8368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)WindowState::WindowState(aura::Window* window) 8468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) : window_(window), 8568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) window_position_managed_(false), 8668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) bounds_changed_by_user_(false), 8768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) panel_attached_(true), 8868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) ignored_by_shelf_(false), 894e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) can_consume_system_keys_(false), 904e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) top_row_keys_are_function_keys_(false), 915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) unminimize_to_restore_bounds_(false), 921e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) hide_shelf_when_fullscreen_(true), 930f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) minimum_visibility_(false), 94a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) can_be_dragged_(true), 955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ignore_property_change_(false), 96a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) current_state_(new DefaultState(ToWindowStateType(GetShowState()))) { 974e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) window_->AddObserver(this); 9868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)} 9968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 10068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)WindowState::~WindowState() { 10168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)} 10268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 103a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)bool WindowState::HasDelegate() const { 104a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) return delegate_; 105a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)} 106a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 1071e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)void WindowState::SetDelegate(scoped_ptr<WindowStateDelegate> delegate) { 1081e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) DCHECK(!delegate_.get()); 1091e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) delegate_ = delegate.Pass(); 1101e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 1111e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 112a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)WindowStateType WindowState::GetStateType() const { 113a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return current_state_->GetType(); 11468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)} 11568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 11668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)bool WindowState::IsMinimized() const { 117a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return GetStateType() == WINDOW_STATE_TYPE_MINIMIZED; 11868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)} 11968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 12068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)bool WindowState::IsMaximized() const { 121a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return GetStateType() == WINDOW_STATE_TYPE_MAXIMIZED; 12268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)} 12368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 12468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)bool WindowState::IsFullscreen() const { 125a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return GetStateType() == WINDOW_STATE_TYPE_FULLSCREEN; 12668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)} 12768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 12868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)bool WindowState::IsMaximizedOrFullscreen() const { 129a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return GetStateType() == WINDOW_STATE_TYPE_FULLSCREEN || 130a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) GetStateType() == WINDOW_STATE_TYPE_MAXIMIZED; 131a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)} 132a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 133a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)bool WindowState::IsSnapped() const { 134a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return GetStateType() == WINDOW_STATE_TYPE_LEFT_SNAPPED || 135a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) GetStateType() == WINDOW_STATE_TYPE_RIGHT_SNAPPED; 13668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)} 13768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 138a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)bool WindowState::IsNormalStateType() const { 139a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return GetStateType() == WINDOW_STATE_TYPE_NORMAL || 140a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) GetStateType() == WINDOW_STATE_TYPE_DEFAULT; 14168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)} 14268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 143a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)bool WindowState::IsNormalOrSnapped() const { 144a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return IsNormalStateType() || IsSnapped(); 1455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 1465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 14768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)bool WindowState::IsActive() const { 14868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) return IsActiveWindow(window_); 14968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)} 15068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 1511e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)bool WindowState::IsDocked() const { 1521e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) return window_->parent() && 1531e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) window_->parent()->id() == internal::kShellWindowId_DockedContainer; 1541e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 1551e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 15668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)bool WindowState::CanMaximize() const { 15768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) return window_->GetProperty(aura::client::kCanMaximizeKey); 15868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)} 15968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 16068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)bool WindowState::CanMinimize() const { 16168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) internal::RootWindowController* controller = 16268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) internal::RootWindowController::ForWindow(window_); 16368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) if (!controller) 16468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) return false; 16568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) aura::Window* lockscreen = controller->GetContainer( 16668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) internal::kShellWindowId_LockScreenContainersContainer); 16768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) if (lockscreen->Contains(window_)) 16868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) return false; 16968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 17068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) return true; 17168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)} 17268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 17368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)bool WindowState::CanResize() const { 17468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) return window_->GetProperty(aura::client::kCanResizeKey); 17568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)} 17668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 17768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)bool WindowState::CanActivate() const { 178a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return ::wm::CanActivateWindow(window_); 17968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)} 18068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 18168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)bool WindowState::CanSnap() const { 1825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (!CanResize() || window_->type() == ui::wm::WINDOW_TYPE_PANEL || 183a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ::wm::GetTransientParent(window_)) 18468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) return false; 18568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // If a window has a maximum size defined, snapping may make it too big. 186a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // TODO(oshima): We probably should snap if possible. 18768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) return window_->delegate() ? window_->delegate()->GetMaximumSize().IsEmpty() : 18868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) true; 18968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)} 19068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 19168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)bool WindowState::HasRestoreBounds() const { 19268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) return window_->GetProperty(aura::client::kRestoreBoundsKey) != NULL; 19368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)} 19468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 19568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)void WindowState::Maximize() { 19668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); 19768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)} 19868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 19968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)void WindowState::Minimize() { 20068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED); 20168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)} 20268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 20368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)void WindowState::Unminimize() { 20468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) window_->SetProperty( 20568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) aura::client::kShowStateKey, 20668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) window_->GetProperty(aura::client::kRestoreShowStateKey)); 20768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) window_->ClearProperty(aura::client::kRestoreShowStateKey); 20868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)} 20968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 21068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)void WindowState::Activate() { 21168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) ActivateWindow(window_); 21268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)} 21368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 21468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)void WindowState::Deactivate() { 21568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) DeactivateWindow(window_); 21668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)} 21768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 21868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)void WindowState::Restore() { 219a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (!IsNormalStateType()) { 220a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) const WMEvent event(WM_EVENT_NORMAL); 221a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) OnWMEvent(&event); 222a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) } 22368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)} 22468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 225a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void WindowState::OnWMEvent(const WMEvent* event) { 2265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) current_state_->OnWMEvent(this, event); 2271e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 2281e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 22968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)void WindowState::SaveCurrentBoundsForRestore() { 23068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) gfx::Rect bounds_in_screen = 2315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ScreenUtil::ConvertRectToScreen(window_->parent(), 23268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) window_->bounds()); 23368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) SetRestoreBoundsInScreen(bounds_in_screen); 23468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)} 23568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 23668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)gfx::Rect WindowState::GetRestoreBoundsInScreen() const { 23768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) return *window_->GetProperty(aura::client::kRestoreBoundsKey); 23868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)} 23968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 24068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)gfx::Rect WindowState::GetRestoreBoundsInParent() const { 2415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return ScreenUtil::ConvertRectFromScreen(window_->parent(), 24268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) GetRestoreBoundsInScreen()); 24368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)} 24468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 24568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)void WindowState::SetRestoreBoundsInScreen(const gfx::Rect& bounds) { 24668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) window_->SetProperty(aura::client::kRestoreBoundsKey, new gfx::Rect(bounds)); 24768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)} 24868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 24968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)void WindowState::SetRestoreBoundsInParent(const gfx::Rect& bounds) { 25068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) SetRestoreBoundsInScreen( 2515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ScreenUtil::ConvertRectToScreen(window_->parent(), bounds)); 25268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)} 25368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 25468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)void WindowState::ClearRestoreBounds() { 25568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) window_->ClearProperty(aura::client::kRestoreBoundsKey); 25668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)} 25768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 25868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)void WindowState::SetPreAutoManageWindowBounds( 25968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) const gfx::Rect& bounds) { 26068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) pre_auto_manage_window_bounds_.reset(new gfx::Rect(bounds)); 26168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)} 26268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 2634e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)void WindowState::AddObserver(WindowStateObserver* observer) { 26468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) observer_list_.AddObserver(observer); 26568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)} 26668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 2674e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)void WindowState::RemoveObserver(WindowStateObserver* observer) { 26868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) observer_list_.RemoveObserver(observer); 26968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)} 27068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 2715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void WindowState::CreateDragDetails(aura::Window* window, 2725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const gfx::Point& point_in_parent, 2735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) int window_component, 2745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) aura::client::WindowMoveSource source) { 2755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) drag_details_.reset( 2765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) new DragDetails(window, point_in_parent, window_component, source)); 2775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 2785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void WindowState::DeleteDragDetails() { 2805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) drag_details_.reset(); 2815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 2825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void WindowState::SetAndClearRestoreBounds() { 2845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) DCHECK(HasRestoreBounds()); 2855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) SetBoundsInScreen(GetRestoreBoundsInScreen()); 2865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ClearRestoreBounds(); 2875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 2885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 289a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void WindowState::OnWindowPropertyChanged(aura::Window* window, 290a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) const void* key, 291a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) intptr_t old) { 292a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) DCHECK_EQ(window, window_); 293a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (key == aura::client::kShowStateKey && !ignore_property_change_) { 294a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) WMEvent event(WMEventTypeFromShowState(GetShowState())); 295a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) OnWMEvent(&event); 296a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) } 297a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)} 298a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 299a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void WindowState::SetBoundsInScreen( 300a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) const gfx::Rect& bounds_in_screen) { 301a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) gfx::Rect bounds_in_parent = 302a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ScreenUtil::ConvertRectFromScreen(window_->parent(), 303a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) bounds_in_screen); 304a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) window_->SetBounds(bounds_in_parent); 305a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)} 306a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 307a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)ui::WindowShowState WindowState::GetShowState() const { 308a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return window_->GetProperty(aura::client::kShowStateKey); 309a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)} 310a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 3115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void WindowState::AdjustSnappedBounds(gfx::Rect* bounds) { 3125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (is_dragged() || !IsSnapped()) 3135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return; 3145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) gfx::Rect maximized_bounds = ScreenUtil::GetMaximizedWindowBoundsInParent( 3155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) window_); 316a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (GetStateType() == WINDOW_STATE_TYPE_LEFT_SNAPPED) 3175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bounds->set_x(maximized_bounds.x()); 318a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) else if (GetStateType() == WINDOW_STATE_TYPE_RIGHT_SNAPPED) 3195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bounds->set_x(maximized_bounds.right() - bounds->width()); 3205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bounds->set_y(maximized_bounds.y()); 3215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bounds->set_height(maximized_bounds.height()); 3225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 3235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 324a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void WindowState::UpdateWindowShowStateFromStateType() { 325a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ui::WindowShowState new_window_state = 326a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ToWindowShowState(current_state_->GetType()); 3275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (new_window_state != GetShowState()) { 3285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::AutoReset<bool> resetter(&ignore_property_change_, true); 329a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) window_->SetProperty(aura::client::kShowStateKey, new_window_state); 330a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) } 3315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 3325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 333a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void WindowState::NotifyPreStateTypeChange( 334a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) WindowStateType old_window_state_type) { 3355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) FOR_EACH_OBSERVER(WindowStateObserver, observer_list_, 336a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) OnPreWindowStateTypeChange(this, old_window_state_type)); 3375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 3385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 339a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void WindowState::NotifyPostStateTypeChange( 340a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) WindowStateType old_window_state_type) { 3415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) FOR_EACH_OBSERVER(WindowStateObserver, observer_list_, 342a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) OnPostWindowStateTypeChange(this, old_window_state_type)); 3435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 3445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 3455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void WindowState::SetBoundsDirect(const gfx::Rect& bounds) { 3465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) BoundsSetter().SetBounds(window_, bounds); 3475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 3485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 349a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void WindowState::SetBoundsConstrained(const gfx::Rect& bounds) { 350a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) gfx::Rect work_area_in_parent = 351a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ScreenUtil::GetDisplayWorkAreaBoundsInParent(window_); 352a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) gfx::Rect child_bounds(bounds); 353a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) AdjustBoundsSmallerThan(work_area_in_parent.size(), &child_bounds); 354a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) SetBoundsDirect(child_bounds); 355a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)} 356a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 3575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void WindowState::SetBoundsDirectAnimated(const gfx::Rect& bounds) { 3585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const int kBoundsChangeSlideDurationMs = 120; 3595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 3605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ui::Layer* layer = window_->layer(); 3615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ui::ScopedLayerAnimationSettings slide_settings(layer->GetAnimator()); 3625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) slide_settings.SetPreemptionStrategy( 3635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); 3645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) slide_settings.SetTransitionDuration( 3655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::TimeDelta::FromMilliseconds(kBoundsChangeSlideDurationMs)); 3665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) SetBoundsDirect(bounds); 36768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)} 36868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 369a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void WindowState::SetBoundsDirectCrossFade(const gfx::Rect& new_bounds) { 370a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // Some test results in invoking CrossFadeToBounds when window is not visible. 371a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // No animation is necessary in that case, thus just change the bounds and 372a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // quit. 373a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (!window_->TargetVisibility()) { 374a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) SetBoundsConstrained(new_bounds); 375a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return; 376a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) } 377a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 378a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) const gfx::Rect old_bounds = window_->bounds(); 379a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 380a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // Create fresh layers for the window and all its children to paint into. 381a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // Takes ownership of the old layer and all its children, which will be 382a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // cleaned up after the animation completes. 383a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // Specify |set_bounds| to true here to keep the old bounds in the child 384a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // windows of |window|. 385a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) scoped_ptr<ui::LayerTreeOwner> old_layer_owner = 386a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ::wm::RecreateLayers(window_); 387a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ui::Layer* old_layer = old_layer_owner->root(); 388a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) DCHECK(old_layer); 389a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ui::Layer* new_layer = window_->layer(); 390a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 391a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // Resize the window to the new size, which will force a layout and paint. 392a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) SetBoundsDirect(new_bounds); 393a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 394a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // Ensure the higher-resolution layer is on top. 395a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) bool old_on_top = (old_bounds.width() > new_bounds.width()); 396a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (old_on_top) 397a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) old_layer->parent()->StackBelow(new_layer, old_layer); 398a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) else 399a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) old_layer->parent()->StackAbove(new_layer, old_layer); 400a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 401a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) CrossFadeAnimation(window_, old_layer_owner.Pass(), gfx::Tween::EASE_OUT); 402a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)} 403a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 40468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)WindowState* GetActiveWindowState() { 40568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) aura::Window* active = GetActiveWindow(); 40668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) return active ? GetWindowState(active) : NULL; 40768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)} 40868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 40968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)WindowState* GetWindowState(aura::Window* window) { 41068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) if (!window) 41168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) return NULL; 41268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) WindowState* settings = window->GetProperty(internal::kWindowStateKey); 41368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) if(!settings) { 41468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) settings = new WindowState(window); 41568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) window->SetProperty(internal::kWindowStateKey, settings); 41668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) } 41768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) return settings; 41868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)} 41968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 42068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)const WindowState* GetWindowState(const aura::Window* window) { 42168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) return GetWindowState(const_cast<aura::Window*>(window)); 42268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)} 42368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 42468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)} // namespace wm 42568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)} // namespace ash 426