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