1ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch// Copyright (c) 2013 The Chromium Authors. All rights reserved. 27d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 37d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// found in the LICENSE file. 47d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 57d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#ifndef ASH_WM_DOCK_DOCKED_WINDOW_LAYOUT_MANAGER_H_ 67d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#define ASH_WM_DOCK_DOCKED_WINDOW_LAYOUT_MANAGER_H_ 77d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 87d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "ash/ash_export.h" 97d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "ash/shelf/shelf_layout_manager_observer.h" 107d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "ash/shell_observer.h" 115f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "ash/snap_to_pixel_layout_manager.h" 127d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "ash/wm/dock/dock_types.h" 134e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "ash/wm/dock/docked_window_layout_manager_observer.h" 144e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "ash/wm/window_state_observer.h" 157d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "base/basictypes.h" 167d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "base/compiler_specific.h" 17ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch#include "base/gtest_prod_util.h" 18bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch#include "base/memory/scoped_ptr.h" 19ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch#include "base/observer_list.h" 20f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "base/time/time.h" 218bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "ui/aura/window.h" 227d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "ui/aura/window_observer.h" 23ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch#include "ui/gfx/rect.h" 247d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "ui/keyboard/keyboard_controller_observer.h" 25effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#include "ui/wm/public/activation_change_observer.h" 267d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 277d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)namespace aura { 287d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)class Window; 297d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)} 307d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 317d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)namespace gfx { 327d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)class Point; 337d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)} 347d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 35bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdochnamespace views { 36bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdochclass Widget; 37bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch} 38bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch 397d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)namespace ash { 40a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)class DockedBackgroundWidget; 41ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdochclass DockedWindowLayoutManagerObserver; 42ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdochclass DockedWindowResizerTest; 43c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdochclass Shelf; 447d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)class ShelfLayoutManager; 454e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)class WorkspaceController; 467d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 478bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)struct WindowWithHeight { 488bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) explicit WindowWithHeight(aura::Window* window) : 498bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) window_(window), 508bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) height_(window->bounds().height()) { } 518bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) aura::Window* window() { return window_; } 528bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) const aura::Window* window() const { return window_; } 538bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) aura::Window* window_; 548bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) int height_; 558bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)}; 568bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 577d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// DockedWindowLayoutManager is responsible for organizing windows when they are 587d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// docked to the side of a screen. It is associated with a specific container 597d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// window (i.e. kShellWindowId_DockContainer) and controls the layout of any 607d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// windows added to that container. 617d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// 627d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// The constructor takes a |dock_container| argument which is expected to set 637d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// its layout manager to this instance, e.g.: 647d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// dock_container->SetLayoutManager( 657d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// new DockedWindowLayoutManager(dock_container)); 663551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// 673551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// TODO(varkha): extend BaseLayoutManager instead of LayoutManager to inherit 683551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// common functionality. 697d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)class ASH_EXPORT DockedWindowLayoutManager 705f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) : public SnapToPixelLayoutManager, 717d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) public ash::ShellObserver, 727d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) public aura::WindowObserver, 737d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) public aura::client::ActivationChangeObserver, 747d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) public keyboard::KeyboardControllerObserver, 75a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) public ShelfLayoutManagerObserver, 764e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) public wm::WindowStateObserver { 777d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) public: 78d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // Maximum width of the docked windows area. 79d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) static const int kMaxDockWidth; 80d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 818bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // Minimum width of the docked windows area. 828bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) static const int kMinDockWidth; 838bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 844e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) DockedWindowLayoutManager(aura::Window* dock_container, 854e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) WorkspaceController* workspace_controller); 867d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) virtual ~DockedWindowLayoutManager(); 877d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 88ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch // Disconnects observers before container windows get destroyed. 89ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch void Shutdown(); 90ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch 91ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch // Management of the observer list. 92ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch virtual void AddObserver(DockedWindowLayoutManagerObserver* observer); 93ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch virtual void RemoveObserver(DockedWindowLayoutManagerObserver* observer); 94ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch 957d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // Called by a DockedWindowResizer to update which window is being dragged. 963551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Starts observing the window unless it is a child. 977d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) void StartDragging(aura::Window* window); 987d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 993551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Called by a DockedWindowResizer when a dragged window is docked. 1003551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) void DockDraggedWindow(aura::Window* window); 1013551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 1023551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Called by a DockedWindowResizer when a dragged window is no longer docked. 1033551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) void UndockDraggedWindow(); 1043551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 1053551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Called by a DockedWindowResizer when a window is no longer being dragged. 1063551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Stops observing the window unless it is a child. 107f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Records |action| by |source| in UMA. 108f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) void FinishDragging(DockedAction action, DockedActionSource source); 1097d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 1105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Shelf* shelf() { return shelf_; } 1115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void SetShelf(Shelf* shelf); 1127d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 1133551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Calculates if a window is touching the screen edges and returns edge. 1143551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) DockedAlignment GetAlignmentOfWindow(const aura::Window* window) const; 1153551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 1167d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // Used to snap docked windows to the side of screen during drag. 117ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch DockedAlignment CalculateAlignment() const; 118ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch 119d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // Returns true when a window can be docked. Windows cannot be docked at the 1205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // edge used by the shelf or the edge opposite from existing dock. 121010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) bool CanDockWindow(aura::Window* window, DockedAlignment desired_alignment); 122d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 1233551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) aura::Window* dock_container() const { return dock_container_; } 1243551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 125ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch // Returns current bounding rectangle of docked windows area. 126ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch const gfx::Rect& docked_bounds() const { return docked_bounds_; } 1277d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 1283551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Returns last known coordinates of |dragged_window_| after Relayout. 1293551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) const gfx::Rect dragged_bounds() const { return dragged_bounds_;} 1307d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 131d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // Returns true if currently dragged window is docked at the screen edge. 132d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) bool is_dragged_window_docked() const { return is_dragged_window_docked_; } 133d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 1345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Updates docked layout when shelf bounds change. 135a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) void OnShelfBoundsChanged(); 136a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 1375f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // SnapLayoutManager: 1387d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) virtual void OnWindowResized() OVERRIDE; 1397d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE; 140ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE {} 1417d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE; 1427d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) virtual void OnChildWindowVisibilityChanged(aura::Window* child, 1437d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) bool visibile) OVERRIDE; 1447d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) virtual void SetChildBounds(aura::Window* child, 1457d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) const gfx::Rect& requested_bounds) OVERRIDE; 1467d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 1477d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // ash::ShellObserver: 1484e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) virtual void OnDisplayWorkAreaInsetsChanged() OVERRIDE; 1494e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) virtual void OnFullscreenStateChanged(bool is_fullscreen, 1501e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) aura::Window* root_window) OVERRIDE; 1511e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) virtual void OnShelfAlignmentChanged(aura::Window* root_window) OVERRIDE; 1527d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 153a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // ShelfLayoutManagerObserver: 154a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) virtual void OnBackgroundUpdated( 155a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ShelfBackgroundType background_type, 156a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) BackgroundAnimatorChangeType change_type) OVERRIDE; 157a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 1584e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // wm::WindowStateObserver: 159a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) virtual void OnPreWindowStateTypeChange( 160a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) wm::WindowState* window_state, 161a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) wm::WindowStateType old_type) OVERRIDE; 1624e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1637d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // aura::WindowObserver: 164bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch virtual void OnWindowBoundsChanged(aura::Window* window, 165bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch const gfx::Rect& old_bounds, 166bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch const gfx::Rect& new_bounds) OVERRIDE; 16768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) virtual void OnWindowVisibilityChanging(aura::Window* window, 16868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) bool visible) OVERRIDE; 169bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch virtual void OnWindowDestroying(aura::Window* window) OVERRIDE; 1707d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 1717d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // aura::client::ActivationChangeObserver: 1727d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) virtual void OnWindowActivated(aura::Window* gained_active, 1737d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) aura::Window* lost_active) OVERRIDE; 1747d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 1757d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) private: 176a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) class ShelfWindowObserver; 1777d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) friend class DockedWindowLayoutManagerTest; 1787d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) friend class DockedWindowResizerTest; 1797d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 180ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch // Width of the gap between the docked windows and a workspace. 181ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch static const int kMinDockGap; 182ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch 18368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // Ideal (starting) width of the dock. 18468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) static const int kIdealWidth; 18568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 18668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // Keep at most kMaxVisibleWindows visible in the dock and minimize the rest 18768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // (except for |child|). 18868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) void MaybeMinimizeChildrenExcept(aura::Window* child); 18968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 1907d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // Minimize / restore window and relayout. 1914e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) void MinimizeDockedWindow(wm::WindowState* window_state); 1924e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) void RestoreDockedWindow(wm::WindowState* window_state); 1937d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 194f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Record user-initiated |action| by |source| in UMA metrics. 195f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) void RecordUmaAction(DockedAction action, DockedActionSource source); 196f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 197f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Updates |docked_width_| and UMA histograms. 198f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) void UpdateDockedWidth(int width); 199f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 2003551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Updates docked layout state when a window gets inside the dock. 2018bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) void OnDraggedWindowDocked(aura::Window* window); 2023551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 2033551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Updates docked layout state when a window gets outside the dock. 2048bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) void OnDraggedWindowUndocked(); 2053551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 2063551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Returns true if there are any windows currently docked. 2073551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) bool IsAnyWindowDocked(); 208ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch 2095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Returns DOCKED_ALIGNMENT_LEFT if the |window|'s left edge is closer to 2105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // the |dock_container_|'s left edge than the |window|'s right edge to 2115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // the |dock_container_|'s right edge. Returns DOCKED_ALIGNMENT_RIGHT 2125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // otherwise. 2135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) DockedAlignment GetEdgeNearestWindow(const aura::Window* window) const; 2145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2157d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // Called whenever the window layout might change. 2167d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) void Relayout(); 2177d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 2188bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // Calculates target heights (and fills it in |visible_windows| array) such 2198bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // that the vertical space is fairly distributed among the windows taking 2208bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // into account their minimum and maximum size. Returns free vertical space 2218bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // (positive value) that remains after resizing all windows or deficit 2228bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // (negative value) if not all the windows fit. 2238bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) int CalculateWindowHeightsAndRemainingRoom( 2248bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) const gfx::Rect work_area, 2258bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) std::vector<WindowWithHeight>* visible_windows); 2268bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 2278bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // Calculate ideal width for the docked area. It will get used to adjust the 2288bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // dragged window or other windows as necessary. 2298bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) int CalculateIdealWidth(const std::vector<WindowWithHeight>& visible_windows); 2308bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 2318bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // Fan out windows evenly distributing the overlap or remaining free space. 2328bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // Adjust the widths of the windows trying to make them all same. If this 2338bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // is not possible, center the windows in the docked area. 2348bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) void FanOutChildren(const gfx::Rect& work_area, 2358bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) int ideal_docked_width, 2368bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) int available_room, 2378bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) std::vector<WindowWithHeight>* visible_windows); 2388bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 239ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch // Updates |docked_bounds_| and workspace insets when bounds of docked windows 2404e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // area change. Passing |reason| to observers allows selectively skipping 2414e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // notifications. 2424e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) void UpdateDockBounds(DockedWindowLayoutManagerObserver::Reason reason); 243ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch 2447d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // Called whenever the window stacking order needs to be updated (e.g. focus 2457d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // changes or a window is moved). 2467d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) void UpdateStacking(aura::Window* active_window); 2477d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 2487d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // keyboard::KeyboardControllerObserver: 2497d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) virtual void OnKeyboardBoundsChanging( 2507d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) const gfx::Rect& keyboard_bounds) OVERRIDE; 2517d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 2527d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // Parent window associated with this layout manager. 2537d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) aura::Window* dock_container_; 2547d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // Protect against recursive calls to Relayout(). 2557d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) bool in_layout_; 2563551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 2573551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // A window that is being dragged (whether docked or not). 2583551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Windows are tracked by docked layout manager only if they are docked; 2593551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // however we need to know if a window is being dragged in order to avoid 2603551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // positioning it or even considering it for layout. 2617d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) aura::Window* dragged_window_; 2623551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 2633551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // True if the window being dragged is currently docked. 2643551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) bool is_dragged_window_docked_; 2653551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 2663551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Previously docked windows use a more relaxed dragging sorting algorithm 2673551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // that uses assumption that a window starts being dragged out of position 2683551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // that was previously established in Relayout. This allows easier reordering. 2693551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) bool is_dragged_from_dock_; 2703551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 2715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // The shelf to respond to alignment changes. 2725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Shelf* shelf_; 273a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 2744e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // Workspace controller that can be checked for fullscreen mode. 2754e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) WorkspaceController* workspace_controller_; 2764e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // Tracks if any window in the same root window is in fullscreen mode. 2774e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) bool in_fullscreen_; 278ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch // Current width of the dock. 279ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch int docked_width_; 280ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch 281ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch // Last bounds that were sent to observers. 282ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch gfx::Rect docked_bounds_; 2837d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 2843551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Target bounds of a docked window being dragged. 2853551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) gfx::Rect dragged_bounds_; 2863551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 2877d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // Side of the screen that the dock is positioned at. 2887d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) DockedAlignment alignment_; 2897d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 290bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch // The last active window. Used to maintain stacking order even if no windows 291bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch // are currently focused. 292bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch aura::Window* last_active_window_; 293bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch 294f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Timestamp of the last user-initiated action that changed docked state. 295f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Used in UMA metrics. 296f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) base::Time last_action_time_; 297f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 2985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Observes shelf for bounds changes. 299a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) scoped_ptr<ShelfWindowObserver> shelf_observer_; 300a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 301bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch // Widget used to paint a background for the docked area. 302a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) scoped_ptr<DockedBackgroundWidget> background_widget_; 303bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch 304ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch // Observers of dock bounds changes. 305ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch ObserverList<DockedWindowLayoutManagerObserver> observer_list_; 306ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch 3077d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(DockedWindowLayoutManager); 3087d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)}; 3097d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 3107d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)} // namespace ash 3117d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 3127d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#endif // ASH_WM_DOCK_DOCKED_WINDOW_LAYOUT_MANAGER_H_ 313