• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2011 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_PANEL_MANAGER_H_
6 #define CHROME_BROWSER_UI_PANELS_PANEL_MANAGER_H_
7 #pragma once
8 
9 #include <deque>
10 #include <vector>
11 #include "base/basictypes.h"
12 #include "base/scoped_ptr.h"
13 #include "ui/gfx/rect.h"
14 
15 class Browser;
16 class Panel;
17 
18 // This class manages a set of panels.
19 class PanelManager {
20  public:
21   // Returns a single instance.
22   static PanelManager* GetInstance();
23 
24   ~PanelManager();
25 
26   // Called when the display is changed, i.e. work area is updated.
27   void OnDisplayChanged();
28 
29   // Creates a panel and returns it. The panel might be queued for display
30   // later.
31   Panel* CreatePanel(Browser* browser);
32 
33   // Removes the given panel. Both active and pending panel lists are checked.
34   // If an active panel is removed, pending panels could put on display if we
35   // have spaces.
36   void Remove(Panel* panel);
37 
38   // Minimizes all panels. This only applies to active panels since only them
39   // are visible.
40   void MinimizeAll();
41 
42   // Restores all panels. This only applies to active panels since only them
43   // are visible.
44   void RestoreAll();
45 
46   // Removes all active panels. Pending panels will be processed for display.
47   void RemoveAllActive();
48 
49   // Returns true if all active panels are in minimized state.
50   bool AreAllMinimized() const;
51 
52   // Drags the given active panel.
53   void StartDragging(Panel* panel);
54   void Drag(int delta_x);
55   void EndDragging(bool cancelled);
56 
57   // Returns the number of active panels.
active_count()58   int active_count() const { return active_panels_.size(); }
59 
60  private:
61   typedef std::vector<Panel*> ActivePanels;
62   typedef std::deque<Panel*> PendingPanels;
63 
64   PanelManager();
65 
66   // Handles all the panels that're delayed to be removed.
67   void DelayedRemove();
68 
69   // Does the remove. Called from Remove and DelayedRemove.
70   void DoRemove(Panel* panel);
71 
72   // Rearranges the positions of the panels starting from the given iterator.
73   // This is called when the display space has been changed, i.e. working
74   // area being changed or a panel being closed.
75   void Rearrange(ActivePanels::iterator iter_to_start);
76 
77   // Checks the pending panels to see if we show them when we have more space.
78   void ProcessPending();
79 
80   // Computes the bounds for next panel.
81   // |allow_size_change| is used to indicate if the panel size can be changed to
82   // fall within the size constraint, e.g., when the panel is created.
83   // Returns true if computed bounds are within the displayable area.
84   bool ComputeBoundsForNextPanel(gfx::Rect* bounds, bool allow_size_change);
85 
86   // Help functions to drag the given panel.
87   void DragNegative(int delta_x);
88   void DragPositive(int delta_x);
89 
90   // Stores the active panels.
91   ActivePanels active_panels_;
92 
93   // Stores the panels that are pending to show.
94   PendingPanels pending_panels_;
95 
96   // Stores the panels that are pending to remove. We want to delay the removal
97   // when we're in the process of the dragging.
98   std::vector<Panel*> panels_pending_to_remove_;
99 
100   // Used in computing the bounds of the next panel.
101   int max_width_;
102   int max_height_;
103   int min_x_;
104   int current_x_;
105   int bottom_edge_y_;
106 
107   // Panel to drag.
108   size_t dragging_panel_index_;
109 
110   // Original x coordinate of the panel to drag. This is used to get back to
111   // the original position when we cancel the dragging.
112   int dragging_panel_original_x_;
113 
114   // Bounds of the panel to drag. It is first set to the original bounds when
115   // the dragging happens. Then it is updated to the position that will be set
116   // to when the dragging ends.
117   gfx::Rect dragging_panel_bounds_;
118 
119   DISALLOW_COPY_AND_ASSIGN(PanelManager);
120 };
121 
122 #endif  // CHROME_BROWSER_UI_PANELS_PANEL_MANAGER_H_
123