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