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_STACKED_PANEL_COLLECTION_H_
      6 #define CHROME_BROWSER_UI_PANELS_STACKED_PANEL_COLLECTION_H_
      7 
      8 #include <list>
      9 #include <vector>
     10 #include "base/basictypes.h"
     11 #include "chrome/browser/ui/panels/native_panel_stack_window.h"
     12 #include "chrome/browser/ui/panels/panel_collection.h"
     13 #include "chrome/browser/ui/panels/panel_constants.h"
     14 #include "ui/gfx/rect.h"
     15 
     16 class PanelManager;
     17 namespace gfx {
     18 class Vector2d;
     19 }
     20 
     21 class StackedPanelCollection : public PanelCollection,
     22                                public NativePanelStackWindowDelegate {
     23  public:
     24   typedef std::list<Panel*> Panels;
     25 
     26   explicit StackedPanelCollection(PanelManager* panel_manager);
     27   virtual ~StackedPanelCollection();
     28 
     29   // PanelCollection OVERRIDES:
     30   virtual void OnDisplayChanged() OVERRIDE;
     31   virtual void RefreshLayout() OVERRIDE;
     32   virtual void AddPanel(Panel* panel,
     33                         PositioningMask positioning_mask) OVERRIDE;
     34   virtual void RemovePanel(Panel* panel, RemovalReason reason) OVERRIDE;
     35   virtual void CloseAll() OVERRIDE;
     36   virtual void ResizePanelWindow(
     37       Panel* panel,
     38       const gfx::Size& preferred_window_size) OVERRIDE;
     39   virtual panel::Resizability GetPanelResizability(
     40       const Panel* panel) const OVERRIDE;
     41   virtual void OnPanelResizedByMouse(Panel* panel,
     42                                      const gfx::Rect& new_bounds) OVERRIDE;
     43   virtual void OnPanelAttentionStateChanged(Panel* panel) OVERRIDE;
     44   virtual void OnPanelTitlebarClicked(Panel* panel,
     45                                       panel::ClickModifier modifier) OVERRIDE;
     46   virtual void ActivatePanel(Panel* panel) OVERRIDE;
     47   virtual void MinimizePanel(Panel* panel) OVERRIDE;
     48   virtual void RestorePanel(Panel* panel) OVERRIDE;
     49   virtual void OnMinimizeButtonClicked(Panel* panel,
     50                                        panel::ClickModifier modifier) OVERRIDE;
     51   virtual void OnRestoreButtonClicked(Panel* panel,
     52                                       panel::ClickModifier modifier) OVERRIDE;
     53   virtual bool CanShowMinimizeButton(const Panel* panel) const OVERRIDE;
     54   virtual bool CanShowRestoreButton(const Panel* panel) const OVERRIDE;
     55   virtual bool IsPanelMinimized(const Panel* panel) const OVERRIDE;
     56   virtual bool UsesAlwaysOnTopPanels() const OVERRIDE;
     57   virtual void SavePanelPlacement(Panel* panel) OVERRIDE;
     58   virtual void RestorePanelToSavedPlacement() OVERRIDE;
     59   virtual void DiscardSavedPanelPlacement()  OVERRIDE;
     60   virtual void UpdatePanelOnCollectionChange(Panel* panel) OVERRIDE;
     61   virtual void OnPanelExpansionStateChanged(Panel* panel) OVERRIDE;
     62   virtual void OnPanelActiveStateChanged(Panel* panel) OVERRIDE;
     63   virtual gfx::Rect GetInitialPanelBounds(
     64       const gfx::Rect& requested_bounds) const OVERRIDE;
     65 
     66   Panel* GetPanelAbove(Panel* panel) const;
     67   Panel* GetPanelBelow(Panel* panel) const;
     68   bool HasPanel(Panel* panel) const;
     69 
     70   void MoveAllDraggingPanelsInstantly(const gfx::Vector2d& delta_origin);
     71 
     72   bool IsMinimized() const;
     73   bool IsAnimatingPanelBounds(Panel* panel) const;
     74 
     75   // Returns the maximum available space from the bottom of the stack. The
     76   // maximum available space is defined as the distance between the bottom
     77   // of the stack and the bottom of the working area, assuming that all inactive
     78   // panels are collapsed.
     79   int GetMaximiumAvailableBottomSpace() const;
     80 
     81   int num_panels() const { return panels_.size(); }
     82   const Panels& panels() const { return panels_; }
     83   Panel* top_panel() const { return panels_.empty() ? NULL : panels_.front(); }
     84   Panel* bottom_panel() const {
     85     return panels_.empty() ? NULL : panels_.back();
     86   }
     87   Panel* most_recently_active_panel() const {
     88     return most_recently_active_panels_.empty() ?
     89         NULL : most_recently_active_panels_.front();
     90   }
     91 
     92  private:
     93   struct PanelPlacement {
     94     Panel* panel;
     95     gfx::Point position;
     96     // Used to remember the top panel, if different from |panel|, for use when
     97     // restoring it. When there're only 2 panels in the stack and the bottom
     98     // panel is being dragged out of the stack, both panels will be moved to
     99     // the detached collection. We need to track the top panel in order to
    100     // put it back to the same stack of the dragging panel.
    101     Panel* top_panel;
    102 
    103     PanelPlacement() : panel(NULL), top_panel(NULL) { }
    104   };
    105 
    106   // Overridden from PanelBoundsBatchUpdateObserver:
    107   virtual string16 GetTitle() const OVERRIDE;
    108   virtual void PanelBoundsBatchUpdateCompleted() OVERRIDE;
    109 
    110   // Returns the enclosing bounds that include all panels in the stack.
    111   gfx::Rect GetEnclosingBounds() const;
    112 
    113   // Returns the work area where the stack resides. If the stack spans across
    114   // multiple displays, return the work area of the display that most closely
    115   // intersects the stack.
    116   gfx::Rect GetWorkArea() const;
    117 
    118   // Refresh all panel layouts, with top panel poisitoned at |start_position|.
    119   // All panels should have same width as |common_width|.
    120   void RefreshLayoutWithTopPanelStartingAt(const gfx::Point& start_position,
    121                                            int common_width);
    122 
    123   // Tries to collapse panels in the least recently active order in order to get
    124   // enough bottom space for |needed_space|. Returns the current available space
    125   // so far if all panels that could be collapsed have been collapsed.
    126   int MinimizePanelsForSpace(int needed_space);
    127 
    128   // Returns the current available space above the top of the stack. The current
    129   // available space is defined as the distance between the top of the working
    130   // area and the top of the stack.
    131   int GetCurrentAvailableTopSpace() const;
    132 
    133   // Returns the current available space below the bottom of the stack. The
    134   // current available space is defined as the distance between the bottom
    135   // of the stack and the bottom of the working area.
    136   int GetCurrentAvailableBottomSpace() const;
    137 
    138   // Minimizes or restores all panels in the collection.
    139   void MinimizeAll();
    140   void RestoreAll(Panel* panel_clicked);
    141 
    142   void UpdatePanelCornerStyle(Panel* panel);
    143 
    144   NativePanelStackWindow* GetStackWindowForPanel(Panel* panel) const;
    145 
    146   PanelManager* panel_manager_;
    147 
    148   // Both stack window pointers are weak pointers and self owned. Once a stack
    149   // window is created, it will only be destructed by calling Close when it is
    150   // not longer needed as in RemovePanel and CloseAll.
    151 
    152   // The main background window that encloses all panels in the stack when
    153   // stacking is not occuring, or existing panels otherwise.
    154   // This window provides:
    155   // 1) the shadow around the the outer area of all panels.
    156   // 2) the consolidated taskbar icon and the consolidated preview
    157   //    (Windows only)
    158   NativePanelStackWindow* primary_stack_window_;
    159 
    160   // The additional background window that encloses those panels that are
    161   // being added to the stack when the stacking is occuring. Since those panels
    162   // have not been fully aligned with existing panels in the stack before the
    163   // stacking ends, we put those panels in a separate background window that
    164   // only provides the shadow around the outer area of those panels.
    165   NativePanelStackWindow* secondary_stack_window_;
    166 
    167   Panels panels_;  // The top panel is in the front of the list.
    168 
    169   // Keeps track of the panels in their active order. The most recently active
    170   // panel is in the front of the list.
    171   Panels most_recently_active_panels_;
    172 
    173   // Used to save the placement information for a panel.
    174   PanelPlacement saved_panel_placement_;
    175 
    176   bool minimizing_all_;  // True while minimizing all panels.
    177 
    178   DISALLOW_COPY_AND_ASSIGN(StackedPanelCollection);
    179 };
    180 
    181 #endif  // CHROME_BROWSER_UI_PANELS_STACKED_PANEL_COLLECTION_H_
    182