NaCl: Update revision in DEPS, r12770 -> r12773
[chromium-blink-merge.git] / chrome / browser / ui / panels / docked_panel_collection.h
blobacdd3de1e02a4d422760542cddabdcaf8c413d8d
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/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 virtual ~DockedPanelCollection();
32 // PanelCollection OVERRIDES:
33 virtual 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 virtual 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 virtual void AddPanel(Panel* panel,
44 PositioningMask positioning_mask) OVERRIDE;
45 virtual void RemovePanel(Panel* pane, RemovalReason reasonl) OVERRIDE;
46 virtual void CloseAll() OVERRIDE;
47 virtual void ResizePanelWindow(
48 Panel* panel,
49 const gfx::Size& preferred_window_size) OVERRIDE;
50 virtual panel::Resizability GetPanelResizability(
51 const Panel* panel) const OVERRIDE;
52 virtual void OnPanelResizedByMouse(Panel* panel,
53 const gfx::Rect& new_bounds) OVERRIDE;
54 virtual void OnPanelAttentionStateChanged(Panel* panel) OVERRIDE;
55 virtual void OnPanelTitlebarClicked(Panel* panel,
56 panel::ClickModifier modifier) OVERRIDE;
57 virtual void ActivatePanel(Panel* panel) OVERRIDE;
58 virtual void MinimizePanel(Panel* panel) OVERRIDE;
59 virtual void RestorePanel(Panel* panel) OVERRIDE;
60 virtual void OnMinimizeButtonClicked(Panel* panel,
61 panel::ClickModifier modifier) OVERRIDE;
62 virtual void OnRestoreButtonClicked(Panel* panel,
63 panel::ClickModifier modifier) OVERRIDE;
64 virtual bool CanShowMinimizeButton(const Panel* panel) const OVERRIDE;
65 virtual bool CanShowRestoreButton(const Panel* panel) const OVERRIDE;
66 virtual bool IsPanelMinimized(const Panel* panel) const OVERRIDE;
67 virtual bool UsesAlwaysOnTopPanels() const OVERRIDE;
68 virtual void SavePanelPlacement(Panel* panel) OVERRIDE;
69 virtual void RestorePanelToSavedPlacement() OVERRIDE;
70 virtual void DiscardSavedPanelPlacement() OVERRIDE;
71 virtual void UpdatePanelOnCollectionChange(Panel* panel) OVERRIDE;
72 virtual void OnPanelExpansionStateChanged(Panel* panel) OVERRIDE;
73 virtual void OnPanelActiveStateChanged(Panel* panel) OVERRIDE;
74 virtual gfx::Rect GetInitialPanelBounds(
75 const gfx::Rect& requested_bounds) const OVERRIDE;
77 // Returns true if we should bring up the titlebars, given the current mouse
78 // point.
79 bool ShouldBringUpTitlebars(int mouse_x, int mouse_y) const;
81 // Brings up or down the titlebars for all minimized panels.
82 void BringUpOrDownTitlebars(bool bring_up);
84 // Returns the bottom position for the panel per its expansion state. If auto-
85 // hide bottom bar is present, we want to move the minimized panel to the
86 // bottom of the screen, not the bottom of the work area.
87 int GetBottomPositionForExpansionState(
88 Panel::ExpansionState expansion_state) const;
90 // Returns panel width to be used, taking into account possible "squeezing"
91 // due to lack of space in the collection.
92 int WidthToDisplayPanelInCollection(bool is_for_active_panel,
93 double squeeze_factor,
94 int full_width) const;
96 bool HasPanel(Panel* panel) const;
98 // num_panels() and panels() only includes panels in the collection that
99 // do NOT have a temporary layout.
100 int num_panels() const { return panels_.size(); }
101 const Panels& panels() const { return panels_; }
102 Panel* last_panel() const { return panels_.empty() ? NULL : panels_.back(); }
104 gfx::Rect work_area() const { return work_area_; }
106 int StartingRightPosition() const;
108 #ifdef UNIT_TEST
109 int minimized_panel_count() const {return minimized_panel_count_; }
110 #endif
112 private:
113 friend class DockedPanelDragHandler;
115 enum TitlebarAction {
116 NO_ACTION,
117 BRING_UP,
118 BRING_DOWN
121 struct PanelPlacement {
122 Panel* panel;
123 // Used to remember the panel to the left of |panel|, if any, for use when
124 // restoring the position of |panel|.
125 Panel* left_panel;
127 PanelPlacement() : panel(NULL), left_panel(NULL) { }
130 // Overridden from PanelMouseWatcherObserver:
131 virtual void OnMouseMove(const gfx::Point& mouse_position) OVERRIDE;
133 // Overridden from DisplaySettingsProvider::DesktopBarObserver:
134 virtual void OnAutoHidingDesktopBarVisibilityChanged(
135 DisplaySettingsProvider::DesktopBarAlignment alignment,
136 DisplaySettingsProvider::DesktopBarVisibility visibility) OVERRIDE;
137 virtual void OnAutoHidingDesktopBarThicknessChanged(
138 DisplaySettingsProvider::DesktopBarAlignment alignment,
139 int thickness) OVERRIDE;
141 // Schedules a layout refresh with a short delay to avoid too much flicker.
142 void ScheduleLayoutRefresh();
144 // Keep track of the minimized panels to control mouse watching.
145 void UpdateMinimizedPanelCount();
147 // Minimizes or restores all panels in the collection.
148 void MinimizeAll();
149 void RestoreAll();
151 // Makes sure the panel's bounds reflect its expansion state and the
152 // panel is aligned at the bottom of the screen. Does not touch the x
153 // coordinate.
154 void AdjustPanelBoundsPerExpansionState(Panel* panel,
155 gfx::Rect* panel_bounds);
157 // Does the real job of bringing up or down the titlebars.
158 void DoBringUpOrDownTitlebars(bool bring_up);
159 // The callback for a delyed task, checks if it still need to perform
160 // the delayed action.
161 void DelayedBringUpOrDownTitlebarsCheck();
163 // Compute default bounds for a panel of |full_size| that would be used
164 // when adding the panel to the collection.
165 gfx::Point GetDefaultPositionForPanel(const gfx::Size& full_size) const;
167 int GetRightMostAvailablePosition() const;
169 PanelManager* panel_manager_; // Weak, owns us.
171 // All panels in the collection must fit within this area.
172 gfx::Rect work_area_;
174 Panels panels_;
176 int minimized_panel_count_;
177 bool are_titlebars_up_;
179 bool minimizing_all_; // True while minimizing all panels.
181 // Delayed transitions support. Sometimes transitions between minimized and
182 // title-only states are delayed, for better usability with Taskbars/Docks.
183 TitlebarAction delayed_titlebar_action_;
185 // Used to save the placement information for a panel.
186 PanelPlacement saved_panel_placement_;
188 static const int kPanelsHorizontalSpacing = 4;
190 // Owned by MessageLoop after posting.
191 base::WeakPtrFactory<DockedPanelCollection> titlebar_action_factory_;
193 // Owned by MessageLoop after posting.
194 base::WeakPtrFactory<DockedPanelCollection> refresh_action_factory_;
196 DISALLOW_COPY_AND_ASSIGN(DockedPanelCollection);
199 #endif // CHROME_BROWSER_UI_PANELS_DOCKED_PANEL_COLLECTION_H_