1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_UI_PANELS_PANEL_COLLECTION_H_ 6 #define CHROME_BROWSER_UI_PANELS_PANEL_COLLECTION_H_ 7 8 #include "chrome/browser/ui/panels/panel_constants.h" 9 #include "ui/gfx/point.h" 10 #include "ui/gfx/rect.h" 11 12 class Panel; 13 14 // Common base class for a collection of panels. Subclasses manage 15 // various layouts for displaying panels in the collection. 16 class PanelCollection { 17 public: 18 // Types of layout for the panel collections. 19 enum Type { 20 DETACHED, // free-floating panels 21 DOCKED, // panels are 'docked' along the window's edge 22 STACKED, // panels are stacked together 23 }; 24 25 // Masks that control how the panel is added and positioned. 26 enum PositioningMask { 27 // The panel is added and placed at default position that is decided by the 28 // collection. 29 DEFAULT_POSITION = 0x0, 30 // The panel is being added based on its current known position. 31 KNOWN_POSITION = 0x1, 32 // The panel is added and placed at top position (currently only used by 33 // stacked collection) 34 TOP_POSITION = 0x2, 35 // Do not update panel bounds. Only valid with DEFAULT_POSIITON. 36 DO_NOT_UPDATE_BOUNDS = 0x4, 37 // Wait for a brief delay before refreshing layout of the collection after 38 // adding panel to the collection. If not set, the collection will refresh 39 // its layout immediately. 40 DELAY_LAYOUT_REFRESH = 0x8, 41 // Do not refresh layout. Used by stacking. 42 NO_LAYOUT_REFRESH = 0x10, 43 // Collapse other inactive stacked panels such the tha new panel can fit 44 // within the working area. Used by stacking. 45 COLLAPSE_TO_FIT = 0x20 46 }; 47 48 enum RemovalReason { 49 PANEL_CLOSED, 50 PANEL_CHANGED_COLLECTION 51 }; 52 type()53 Type type() const { return type_; } 54 55 // Called when the display area is changed. 56 virtual void OnDisplayChanged() = 0; 57 58 // Updates the positioning of all panels in the collection, usually as 59 // a result of removing or resizing a panel in collection. 60 virtual void RefreshLayout() = 0; 61 62 // Adds |panel| to the collection of panels. 63 // |positioning_mask| indicates how |panel| should be added and positioned. 64 virtual void AddPanel(Panel* panel, PositioningMask positioning_mask) = 0; 65 66 // Removes |panel| from the collection of panels. Invoked asynchronously 67 // after a panel has been closed. 68 // |reason| denotes why the panel is removed from the collection. 69 virtual void RemovePanel(Panel* panel, RemovalReason reason) = 0; 70 71 // Closes all panels in the collection. Panels will be removed after closing. 72 virtual void CloseAll() = 0; 73 74 // Resizes the |panel| to the |preferred_window_size| and updates the layout 75 // of other panels in the collection accordingly. 76 // |preferred_window_size| is the outer dimensions of the window, not 77 // the content area, and is in screen coordinates. 78 // The preferred size may be adjusted to fit layout constraints. 79 virtual void ResizePanelWindow(Panel* panel, 80 const gfx::Size& preferred_window_size) = 0; 81 82 // Returns the sides from which |panel| can be resized by the user 83 // if |panel| is resizable in this collection. 84 virtual panel::Resizability GetPanelResizability( 85 const Panel* panel) const = 0; 86 87 // Change panel's bounds and take care of all possible side effects 88 // in ths collection as a result of the panel being resized by the user. 89 // TODO (AndreiB) Add a parameter telling what how to approach animation 90 // (no animation, continue existing, or start new). 91 virtual void OnPanelResizedByMouse(Panel* panel, 92 const gfx::Rect& new_bounds) = 0; 93 94 // Invoked when the draw attention state of the panel has changed. 95 // Subclass should update the display of the panel to match the new 96 // draw attention state. 97 virtual void OnPanelAttentionStateChanged(Panel* panel) = 0; 98 99 // Invoked when the titlebar of a |panel| in the collection has been clicked. 100 // Click behavior may be modified as indicated by |modifier|. 101 virtual void OnPanelTitlebarClicked(Panel* panel, 102 panel::ClickModifier modifier) = 0; 103 104 // Called when a panel's expansion state changes. 105 virtual void OnPanelExpansionStateChanged(Panel* panel) = 0; 106 107 // Called when a panel in the collection becomes active or inactive. 108 virtual void OnPanelActiveStateChanged(Panel* panel) = 0; 109 110 // Updates the display to show |panel| as active. 111 virtual void ActivatePanel(Panel* panel) = 0; 112 113 // Updates the display to show |panel| as minimized/restored. 114 virtual void MinimizePanel(Panel* panel) = 0; 115 virtual void RestorePanel(Panel* panel) = 0; 116 117 // Called when a panel's minimize/restore button is clicked. 118 // The behavior might be modified as indicated by |modifier|. 119 virtual void OnMinimizeButtonClicked(Panel* panel, 120 panel::ClickModifier modifier) = 0; 121 virtual void OnRestoreButtonClicked(Panel* panel, 122 panel::ClickModifier modifier) = 0; 123 124 // Returns true if minimize or restore button can be shown on the panel's 125 // titlebar. 126 virtual bool CanShowMinimizeButton(const Panel* panel) const = 0; 127 virtual bool CanShowRestoreButton(const Panel* panel) const = 0; 128 129 virtual bool IsPanelMinimized(const Panel* panel) const = 0; 130 131 virtual bool UsesAlwaysOnTopPanels() const = 0; 132 133 // Saves/restores/discards the placement information of |panel|. This is 134 // useful in bringing back the dragging panel to its original positioning 135 // when the drag is cancelled. After the placement information is saved, 136 // the caller should only call one of RestorePanelToSavedPlacement or 137 // DiscardSavedPanelPlacement. 138 virtual void SavePanelPlacement(Panel* panel) = 0; 139 virtual void RestorePanelToSavedPlacement() = 0; 140 virtual void DiscardSavedPanelPlacement() = 0; 141 142 // When a panel is added to this collection, some modifications to its visual 143 // style or underlying implementation may be in order. Each collection decides 144 // what properties should be applied to a newly-added panel. 145 virtual void UpdatePanelOnCollectionChange(Panel* panel) = 0; 146 147 // Returns the initial bounds to show the panel based on the requested bounds. 148 virtual gfx::Rect GetInitialPanelBounds( 149 const gfx::Rect& requested_bounds) const = 0; 150 151 protected: 152 explicit PanelCollection(Type type); 153 virtual ~PanelCollection(); 154 155 const Type type_; // Type of this panel collection. 156 }; 157 158 #endif // CHROME_BROWSER_UI_PANELS_PANEL_COLLECTION_H_ 159