Support SizeClassIdiom on iOS7.
[chromium-blink-merge.git] / chrome / browser / ui / panels / stacked_panel_collection.h
bloba6f9df691829f0aca67c32836ae02142b71362ea
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.
5 #ifndef CHROME_BROWSER_UI_PANELS_STACKED_PANEL_COLLECTION_H_
6 #define CHROME_BROWSER_UI_PANELS_STACKED_PANEL_COLLECTION_H_
8 #include <list>
9 #include <vector>
10 #include "base/basictypes.h"
11 #include "chrome/browser/ui/panels/native_panel_stack_window.h"
12 #include "chrome/browser/ui/panels/panel_collection.h"
13 #include "chrome/browser/ui/panels/panel_constants.h"
14 #include "ui/gfx/geometry/rect.h"
16 class PanelManager;
17 namespace gfx {
18 class Vector2d;
21 class StackedPanelCollection : public PanelCollection,
22 public NativePanelStackWindowDelegate {
23 public:
24 typedef std::list<Panel*> Panels;
26 explicit StackedPanelCollection(PanelManager* panel_manager);
27 ~StackedPanelCollection() override;
29 // PanelCollection OVERRIDES:
30 void OnDisplayChanged() override;
31 void RefreshLayout() override;
32 void AddPanel(Panel* panel, PositioningMask positioning_mask) override;
33 void RemovePanel(Panel* panel, RemovalReason reason) override;
34 void CloseAll() override;
35 void ResizePanelWindow(Panel* panel,
36 const gfx::Size& preferred_window_size) override;
37 panel::Resizability GetPanelResizability(const Panel* panel) const override;
38 void OnPanelResizedByMouse(Panel* panel,
39 const gfx::Rect& new_bounds) override;
40 void OnPanelAttentionStateChanged(Panel* panel) override;
41 void OnPanelTitlebarClicked(Panel* panel,
42 panel::ClickModifier modifier) override;
43 void ActivatePanel(Panel* panel) override;
44 void MinimizePanel(Panel* panel) override;
45 void RestorePanel(Panel* panel) override;
46 void OnMinimizeButtonClicked(Panel* panel,
47 panel::ClickModifier modifier) override;
48 void OnRestoreButtonClicked(Panel* panel,
49 panel::ClickModifier modifier) override;
50 bool CanShowMinimizeButton(const Panel* panel) const override;
51 bool CanShowRestoreButton(const Panel* panel) const override;
52 bool IsPanelMinimized(const Panel* panel) const override;
53 bool UsesAlwaysOnTopPanels() const override;
54 void SavePanelPlacement(Panel* panel) override;
55 void RestorePanelToSavedPlacement() override;
56 void DiscardSavedPanelPlacement() override;
57 void UpdatePanelOnCollectionChange(Panel* panel) override;
58 void OnPanelExpansionStateChanged(Panel* panel) override;
59 void OnPanelActiveStateChanged(Panel* panel) override;
60 gfx::Rect GetInitialPanelBounds(
61 const gfx::Rect& requested_bounds) const override;
63 Panel* GetPanelAbove(Panel* panel) const;
64 Panel* GetPanelBelow(Panel* panel) const;
65 bool HasPanel(Panel* panel) const;
67 void MoveAllDraggingPanelsInstantly(const gfx::Vector2d& delta_origin);
69 bool IsMinimized() const;
70 bool IsAnimatingPanelBounds(Panel* panel) const;
72 // Returns the maximum available space from the bottom of the stack. The
73 // maximum available space is defined as the distance between the bottom
74 // of the stack and the bottom of the working area, assuming that all inactive
75 // panels are collapsed.
76 int GetMaximiumAvailableBottomSpace() const;
78 int num_panels() const { return panels_.size(); }
79 const Panels& panels() const { return panels_; }
80 Panel* top_panel() const { return panels_.empty() ? NULL : panels_.front(); }
81 Panel* bottom_panel() const {
82 return panels_.empty() ? NULL : panels_.back();
84 Panel* most_recently_active_panel() const {
85 return most_recently_active_panels_.empty() ?
86 NULL : most_recently_active_panels_.front();
89 private:
90 struct PanelPlacement {
91 Panel* panel;
92 gfx::Point position;
93 // Used to remember the top panel, if different from |panel|, for use when
94 // restoring it. When there're only 2 panels in the stack and the bottom
95 // panel is being dragged out of the stack, both panels will be moved to
96 // the detached collection. We need to track the top panel in order to
97 // put it back to the same stack of the dragging panel.
98 Panel* top_panel;
100 PanelPlacement() : panel(NULL), top_panel(NULL) { }
103 // Overridden from PanelBoundsBatchUpdateObserver:
104 base::string16 GetTitle() const override;
105 gfx::Image GetIcon() const override;
106 void PanelBoundsBatchUpdateCompleted() override;
108 // Returns the enclosing bounds that include all panels in the stack.
109 gfx::Rect GetEnclosingBounds() const;
111 // Returns the work area where the stack resides. If the stack spans across
112 // multiple displays, return the work area of the display that most closely
113 // intersects the stack.
114 gfx::Rect GetWorkArea() const;
116 // Refresh all panel layouts, with top panel poisitoned at |start_position|.
117 // All panels should have same width as |common_width|.
118 void RefreshLayoutWithTopPanelStartingAt(const gfx::Point& start_position,
119 int common_width);
121 // Tries to collapse panels in the least recently active order in order to get
122 // enough bottom space for |needed_space|. Returns the current available space
123 // so far if all panels that could be collapsed have been collapsed.
124 int MinimizePanelsForSpace(int needed_space);
126 // Returns the current available space above the top of the stack. The current
127 // available space is defined as the distance between the top of the working
128 // area and the top of the stack.
129 int GetCurrentAvailableTopSpace() const;
131 // Returns the current available space below the bottom of the stack. The
132 // current available space is defined as the distance between the bottom
133 // of the stack and the bottom of the working area.
134 int GetCurrentAvailableBottomSpace() const;
136 // Minimizes or restores all panels in the collection.
137 void MinimizeAll();
138 void RestoreAll(Panel* panel_clicked);
140 void UpdatePanelCornerStyle(Panel* panel);
142 NativePanelStackWindow* GetStackWindowForPanel(Panel* panel) const;
144 PanelManager* panel_manager_;
146 // Both stack window pointers are weak pointers and self owned. Once a stack
147 // window is created, it will only be destructed by calling Close when it is
148 // not longer needed as in RemovePanel and CloseAll.
150 // The main background window that encloses all panels in the stack when
151 // stacking is not occuring, or existing panels otherwise.
152 // This window provides:
153 // 1) the shadow around the the outer area of all panels.
154 // 2) the consolidated taskbar icon and the consolidated preview
155 // (Windows only)
156 NativePanelStackWindow* primary_stack_window_;
158 // The additional background window that encloses those panels that are
159 // being added to the stack when the stacking is occuring. Since those panels
160 // have not been fully aligned with existing panels in the stack before the
161 // stacking ends, we put those panels in a separate background window that
162 // only provides the shadow around the outer area of those panels.
163 NativePanelStackWindow* secondary_stack_window_;
165 Panels panels_; // The top panel is in the front of the list.
167 // Keeps track of the panels in their active order. The most recently active
168 // panel is in the front of the list.
169 Panels most_recently_active_panels_;
171 // Used to save the placement information for a panel.
172 PanelPlacement saved_panel_placement_;
174 bool minimizing_all_; // True while minimizing all panels.
176 DISALLOW_COPY_AND_ASSIGN(StackedPanelCollection);
179 #endif // CHROME_BROWSER_UI_PANELS_STACKED_PANEL_COLLECTION_H_