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_DETACHED_PANEL_COLLECTION_H_
6 #define CHROME_BROWSER_UI_PANELS_DETACHED_PANEL_COLLECTION_H_
9 #include "base/basictypes.h"
10 #include "chrome/browser/ui/panels/panel.h"
11 #include "chrome/browser/ui/panels/panel_collection.h"
12 #include "ui/gfx/geometry/point.h"
13 #include "ui/gfx/geometry/rect.h"
17 // This class manages a group of free-floating panels.
18 class DetachedPanelCollection
: public PanelCollection
{
20 typedef std::list
<Panel
*> Panels
;
21 typedef bool (*PanelsComparer
)(Panel
* panel1
, Panel
* panel2
);
23 explicit DetachedPanelCollection(PanelManager
* panel_manager
);
24 ~DetachedPanelCollection() override
;
26 // PanelCollection OVERRIDES:
27 void OnDisplayChanged() override
;
28 void RefreshLayout() override
;
29 void AddPanel(Panel
* panel
, PositioningMask positioning_mask
) override
;
30 void RemovePanel(Panel
* panel
, RemovalReason reason
) override
;
31 void CloseAll() override
;
32 void ResizePanelWindow(Panel
* panel
,
33 const gfx::Size
& preferred_window_size
) override
;
34 panel::Resizability
GetPanelResizability(const Panel
* panel
) const override
;
35 void OnPanelResizedByMouse(Panel
* panel
,
36 const gfx::Rect
& new_bounds
) override
;
37 void OnPanelAttentionStateChanged(Panel
* panel
) override
;
38 void OnPanelTitlebarClicked(Panel
* panel
,
39 panel::ClickModifier modifier
) override
;
40 void ActivatePanel(Panel
* panel
) override
;
41 void MinimizePanel(Panel
* panel
) override
;
42 void RestorePanel(Panel
* panel
) override
;
43 void OnMinimizeButtonClicked(Panel
* panel
,
44 panel::ClickModifier modifier
) override
;
45 void OnRestoreButtonClicked(Panel
* panel
,
46 panel::ClickModifier modifier
) override
;
47 bool CanShowMinimizeButton(const Panel
* panel
) const override
;
48 bool CanShowRestoreButton(const Panel
* panel
) const override
;
49 bool IsPanelMinimized(const Panel
* panel
) const override
;
50 bool UsesAlwaysOnTopPanels() const override
;
51 void SavePanelPlacement(Panel
* panel
) override
;
52 void RestorePanelToSavedPlacement() override
;
53 void DiscardSavedPanelPlacement() override
;
54 void UpdatePanelOnCollectionChange(Panel
* panel
) override
;
55 void OnPanelExpansionStateChanged(Panel
* panel
) override
;
56 void OnPanelActiveStateChanged(Panel
* panel
) override
;
57 gfx::Rect
GetInitialPanelBounds(
58 const gfx::Rect
& requested_bounds
) const override
;
60 bool HasPanel(Panel
* panel
) const;
62 void SortPanels(PanelsComparer comparer
);
64 int num_panels() const { return panels_
.size(); }
65 const Panels
& panels() const { return panels_
; }
67 // Returns default top-left to use for a detached panel whose position is
68 // not specified during panel creation.
69 gfx::Point
GetDefaultPanelOrigin();
72 // Offset the default panel top-left position by kPanelTilePixels. Wrap
73 // around to initial position if position goes beyond display area.
74 void ComputeNextDefaultPanelOrigin();
76 struct PanelPlacement
{
80 PanelPlacement() : panel(NULL
) { }
83 PanelManager
* panel_manager_
; // Weak, owns us.
85 // Collection of all panels.
88 // Used to save the placement information for a panel.
89 PanelPlacement saved_panel_placement_
;
91 // Default top-left position to use for next detached panel if position is
92 // unspecified by panel creator.
93 gfx::Point default_panel_origin_
;
95 DISALLOW_COPY_AND_ASSIGN(DetachedPanelCollection
);
98 #endif // CHROME_BROWSER_UI_PANELS_DETACHED_PANEL_COLLECTION_H_