Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / ui / panels / docked_panel_collection.h
blob8398728a34ac0438e9115507ce8dda118fc2e4ed
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_DOCKED_PANEL_COLLECTION_H_
6 #define CHROME_BROWSER_UI_PANELS_DOCKED_PANEL_COLLECTION_H_
8 #include <list>
9 #include <set>
10 #include "base/basictypes.h"
11 #include "base/memory/weak_ptr.h"
12 #include "chrome/browser/ui/panels/display_settings_provider.h"
13 #include "chrome/browser/ui/panels/panel.h"
14 #include "chrome/browser/ui/panels/panel_collection.h"
15 #include "chrome/browser/ui/panels/panel_mouse_watcher_observer.h"
16 #include "ui/gfx/geometry/rect.h"
18 class PanelManager;
20 // This class manages a group of panels that could be docked to the bottom of
21 // screen.
22 class DockedPanelCollection :
23 public PanelCollection,
24 public PanelMouseWatcherObserver,
25 public DisplaySettingsProvider::DesktopBarObserver {
26 public:
27 typedef std::list<Panel*> Panels;
29 explicit DockedPanelCollection(PanelManager* panel_manager);
30 ~DockedPanelCollection() override;
32 // PanelCollection OVERRIDES:
33 void OnDisplayChanged() override;
35 // Rearranges the positions of the panels in the collection
36 // and reduces their width when there is not enough room.
37 // This is called when the display space has been changed, i.e. working
38 // area being changed or a panel being closed.
39 void RefreshLayout() override;
41 // Adds a panel to the collection. The panel may be a newly created panel or
42 // one that is transitioning from another grouping of panels.
43 void AddPanel(Panel* panel, PositioningMask positioning_mask) override;
44 void RemovePanel(Panel* pane, RemovalReason reasonl) override;
45 void CloseAll() override;
46 void ResizePanelWindow(Panel* panel,
47 const gfx::Size& preferred_window_size) override;
48 panel::Resizability GetPanelResizability(const Panel* panel) const override;
49 void OnPanelResizedByMouse(Panel* panel,
50 const gfx::Rect& new_bounds) override;
51 void OnPanelAttentionStateChanged(Panel* panel) override;
52 void OnPanelTitlebarClicked(Panel* panel,
53 panel::ClickModifier modifier) override;
54 void ActivatePanel(Panel* panel) override;
55 void MinimizePanel(Panel* panel) override;
56 void RestorePanel(Panel* panel) override;
57 void OnMinimizeButtonClicked(Panel* panel,
58 panel::ClickModifier modifier) override;
59 void OnRestoreButtonClicked(Panel* panel,
60 panel::ClickModifier modifier) override;
61 bool CanShowMinimizeButton(const Panel* panel) const override;
62 bool CanShowRestoreButton(const Panel* panel) const override;
63 bool IsPanelMinimized(const Panel* panel) const override;
64 bool UsesAlwaysOnTopPanels() const override;
65 void SavePanelPlacement(Panel* panel) override;
66 void RestorePanelToSavedPlacement() override;
67 void DiscardSavedPanelPlacement() override;
68 void UpdatePanelOnCollectionChange(Panel* panel) override;
69 void OnPanelExpansionStateChanged(Panel* panel) override;
70 void OnPanelActiveStateChanged(Panel* panel) override;
71 gfx::Rect GetInitialPanelBounds(
72 const gfx::Rect& requested_bounds) const override;
74 // Returns true if we should bring up the titlebars, given the current mouse
75 // point.
76 bool ShouldBringUpTitlebars(int mouse_x, int mouse_y) const;
78 // Brings up or down the titlebars for all minimized panels.
79 void BringUpOrDownTitlebars(bool bring_up);
81 // Returns the bottom position for the panel per its expansion state. If auto-
82 // hide bottom bar is present, we want to move the minimized panel to the
83 // bottom of the screen, not the bottom of the work area.
84 int GetBottomPositionForExpansionState(
85 Panel::ExpansionState expansion_state) const;
87 // Returns panel width to be used, taking into account possible "squeezing"
88 // due to lack of space in the collection.
89 int WidthToDisplayPanelInCollection(bool is_for_active_panel,
90 double squeeze_factor,
91 int full_width) const;
93 bool HasPanel(Panel* panel) const;
95 // num_panels() and panels() only includes panels in the collection that
96 // do NOT have a temporary layout.
97 int num_panels() const { return panels_.size(); }
98 const Panels& panels() const { return panels_; }
99 Panel* last_panel() const { return panels_.empty() ? NULL : panels_.back(); }
101 gfx::Rect work_area() const { return work_area_; }
103 int StartingRightPosition() const;
105 #ifdef UNIT_TEST
106 int minimized_panel_count() const {return minimized_panel_count_; }
107 #endif
109 private:
110 friend class DockedPanelDragHandler;
112 enum TitlebarAction {
113 NO_ACTION,
114 BRING_UP,
115 BRING_DOWN
118 struct PanelPlacement {
119 Panel* panel;
120 // Used to remember the panel to the left of |panel|, if any, for use when
121 // restoring the position of |panel|.
122 Panel* left_panel;
124 PanelPlacement() : panel(NULL), left_panel(NULL) { }
127 // Overridden from PanelMouseWatcherObserver:
128 void OnMouseMove(const gfx::Point& mouse_position) override;
130 // Overridden from DisplaySettingsProvider::DesktopBarObserver:
131 void OnAutoHidingDesktopBarVisibilityChanged(
132 DisplaySettingsProvider::DesktopBarAlignment alignment,
133 DisplaySettingsProvider::DesktopBarVisibility visibility) override;
134 void OnAutoHidingDesktopBarThicknessChanged(
135 DisplaySettingsProvider::DesktopBarAlignment alignment,
136 int thickness) override;
138 // Schedules a layout refresh with a short delay to avoid too much flicker.
139 void ScheduleLayoutRefresh();
141 // Keep track of the minimized panels to control mouse watching.
142 void UpdateMinimizedPanelCount();
144 // Minimizes or restores all panels in the collection.
145 void MinimizeAll();
146 void RestoreAll();
148 // Makes sure the panel's bounds reflect its expansion state and the
149 // panel is aligned at the bottom of the screen. Does not touch the x
150 // coordinate.
151 void AdjustPanelBoundsPerExpansionState(Panel* panel,
152 gfx::Rect* panel_bounds);
154 // Does the real job of bringing up or down the titlebars.
155 void DoBringUpOrDownTitlebars(bool bring_up);
156 // The callback for a delyed task, checks if it still need to perform
157 // the delayed action.
158 void DelayedBringUpOrDownTitlebarsCheck();
160 // Compute default bounds for a panel of |full_size| that would be used
161 // when adding the panel to the collection.
162 gfx::Point GetDefaultPositionForPanel(const gfx::Size& full_size) const;
164 int GetRightMostAvailablePosition() const;
166 PanelManager* panel_manager_; // Weak, owns us.
168 // All panels in the collection must fit within this area.
169 gfx::Rect work_area_;
171 Panels panels_;
173 int minimized_panel_count_;
174 bool are_titlebars_up_;
176 bool minimizing_all_; // True while minimizing all panels.
178 // Delayed transitions support. Sometimes transitions between minimized and
179 // title-only states are delayed, for better usability with Taskbars/Docks.
180 TitlebarAction delayed_titlebar_action_;
182 // Used to save the placement information for a panel.
183 PanelPlacement saved_panel_placement_;
185 static const int kPanelsHorizontalSpacing = 4;
187 // Owned by MessageLoop after posting.
188 base::WeakPtrFactory<DockedPanelCollection> titlebar_action_factory_;
190 // Owned by MessageLoop after posting.
191 base::WeakPtrFactory<DockedPanelCollection> refresh_action_factory_;
193 DISALLOW_COPY_AND_ASSIGN(DockedPanelCollection);
196 #endif // CHROME_BROWSER_UI_PANELS_DOCKED_PANEL_COLLECTION_H_