| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_UI_PANELS_PANEL_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_UI_PANELS_PANEL_MANAGER_H_ |
| 6 #define CHROME_BROWSER_UI_PANELS_PANEL_MANAGER_H_ | 6 #define CHROME_BROWSER_UI_PANELS_PANEL_MANAGER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/memory/ref_counted.h" |
| 11 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/task.h" |
| 14 #include "chrome/browser/ui/panels/auto_hiding_desktop_bar.h" |
| 12 #include "chrome/browser/ui/panels/panel.h" | 15 #include "chrome/browser/ui/panels/panel.h" |
| 13 #include "ui/gfx/rect.h" | 16 #include "ui/gfx/rect.h" |
| 14 | 17 |
| 15 class Browser; | 18 class Browser; |
| 16 class Panel; | 19 class Panel; |
| 17 | 20 |
| 18 // This class manages a set of panels. | 21 // This class manages a set of panels. |
| 19 class PanelManager { | 22 // Note that the ref count is needed by using PostTask in the implementation. |
| 23 class PanelManager : public AutoHidingDesktopBar::Observer, |
| 24 public base::RefCounted<PanelManager> { |
| 20 public: | 25 public: |
| 26 typedef std::vector<Panel*> Panels; |
| 27 |
| 21 // Returns a single instance. | 28 // Returns a single instance. |
| 22 static PanelManager* GetInstance(); | 29 static PanelManager* GetInstance(); |
| 23 | 30 |
| 24 ~PanelManager(); | 31 virtual ~PanelManager(); |
| 25 | 32 |
| 26 // Called when the display is changed, i.e. work area is updated. | 33 // Called when the display is changed, i.e. work area is updated. |
| 27 void OnDisplayChanged(); | 34 void OnDisplayChanged(); |
| 28 | 35 |
| 29 // Creates a panel and returns it. The panel might be queued for display | 36 // Creates a panel and returns it. The panel might be queued for display |
| 30 // later. | 37 // later. |
| 31 Panel* CreatePanel(Browser* browser); | 38 Panel* CreatePanel(Browser* browser); |
| 32 | 39 |
| 33 void Remove(Panel* panel); | 40 void Remove(Panel* panel); |
| 34 void RemoveAll(); | 41 void RemoveAll(); |
| 35 | 42 |
| 36 // Drags the given panel. | 43 // Drags the given panel. |
| 37 void StartDragging(Panel* panel); | 44 void StartDragging(Panel* panel); |
| 38 void Drag(int delta_x); | 45 void Drag(int delta_x); |
| 39 void EndDragging(bool cancelled); | 46 void EndDragging(bool cancelled); |
| 40 | 47 |
| 41 // Should we bring up the titlebar, given the current mouse point? | 48 // Returns true if we should bring up the titlebars, given the current mouse |
| 42 bool ShouldBringUpTitlebarForAllMinimizedPanels(int mouse_x, | 49 // point. |
| 43 int mouse_y) const; | 50 bool ShouldBringUpTitlebars(int mouse_x, int mouse_y) const; |
| 44 | 51 |
| 45 // Brings up or down the title-bar for all minimized panels. | 52 // Brings up or down the titlebars for all minimized panels. |
| 46 void BringUpOrDownTitlebarForAllMinimizedPanels(bool bring_up); | 53 void BringUpOrDownTitlebars(bool bring_up); |
| 54 |
| 55 // Returns the bottom position for the panel per its expansion state. If auto- |
| 56 // hide bottom bar is present, we want to move the minimized panel to the |
| 57 // bottom of the screen, not the bottom of the work area. |
| 58 int GetBottomPositionForExpansionState( |
| 59 Panel::ExpansionState expansion_state) const; |
| 47 | 60 |
| 48 int num_panels() const { return panels_.size(); } | 61 int num_panels() const { return panels_.size(); } |
| 49 bool is_dragging_panel() const; | 62 bool is_dragging_panel() const; |
| 50 | 63 |
| 64 #ifdef UNIT_TEST |
| 65 const Panels& panels() const { return panels_; } |
| 66 static int horizontal_spacing() { return kPanelsHorizontalSpacing; } |
| 67 |
| 68 const gfx::Rect& work_area() const { |
| 69 return work_area_; |
| 70 } |
| 71 |
| 72 void set_auto_hiding_desktop_bar( |
| 73 AutoHidingDesktopBar* auto_hiding_desktop_bar) { |
| 74 auto_hiding_desktop_bar_ = auto_hiding_desktop_bar; |
| 75 } |
| 76 |
| 77 void SetWorkAreaForTesting(const gfx::Rect& work_area) { |
| 78 SetWorkArea(work_area); |
| 79 } |
| 80 #endif |
| 81 |
| 51 private: | 82 private: |
| 52 friend class PanelBrowserTest; | 83 enum TitlebarAction { |
| 53 | 84 NO_ACTION, |
| 54 typedef std::vector<Panel*> Panels; | 85 BRING_UP, |
| 86 BRING_DOWN |
| 87 }; |
| 55 | 88 |
| 56 PanelManager(); | 89 PanelManager(); |
| 57 | 90 |
| 58 #if UNIT_TEST | 91 // Overridden from AutoHidingDesktopBar::Observer: |
| 59 const Panels& panels() const { return panels_; } | 92 virtual void OnAutoHidingDesktopBarThicknessChanged() OVERRIDE; |
| 60 static int horizontal_spacing() { return kPanelsHorizontalSpacing; } | 93 virtual void OnAutoHidingDesktopBarVisibilityChanged( |
| 61 #endif | 94 AutoHidingDesktopBar::Alignment alignment, |
| 95 AutoHidingDesktopBar::Visibility visibility) OVERRIDE; |
| 62 | 96 |
| 63 // Applies the new work area. This is called by OnDisplayChanged and the test | 97 // Applies the new work area. This is called by OnDisplayChanged and the test |
| 64 // code. | 98 // code. |
| 65 void SetWorkArea(const gfx::Rect& work_area); | 99 void SetWorkArea(const gfx::Rect& work_area); |
| 66 | 100 |
| 101 // Adjusts the work area to exclude the influence of auto-hiding desktop bars. |
| 102 void AdjustWorkAreaForAutoHidingDesktopBars(); |
| 103 |
| 67 // Handles all the panels that're delayed to be removed. | 104 // Handles all the panels that're delayed to be removed. |
| 68 void DelayedRemove(); | 105 void DelayedRemove(); |
| 69 | 106 |
| 70 // Does the remove. Called from Remove and DelayedRemove. | 107 // Does the remove. Called from Remove and DelayedRemove. |
| 71 void DoRemove(Panel* panel); | 108 void DoRemove(Panel* panel); |
| 72 | 109 |
| 73 // Rearranges the positions of the panels starting from the given iterator. | 110 // Rearranges the positions of the panels starting from the given iterator. |
| 74 // This is called when the display space has been changed, i.e. working | 111 // This is called when the display space has been changed, i.e. working |
| 75 // area being changed or a panel being closed. | 112 // area being changed or a panel being closed. |
| 76 void Rearrange(Panels::iterator iter_to_start); | 113 void Rearrange(Panels::iterator iter_to_start, int rightmost_position); |
| 77 | |
| 78 // Computes the bounds for next panel. | |
| 79 // |allow_size_change| is used to indicate if the panel size can be changed to | |
| 80 // fall within the size constraint, e.g., when the panel is created. | |
| 81 // Returns true if computed bounds are within the displayable area. | |
| 82 bool ComputeBoundsForNextPanel(gfx::Rect* bounds, bool allow_size_change); | |
| 83 | 114 |
| 84 // Finds one panel to close so that we may have space for the new panel | 115 // Finds one panel to close so that we may have space for the new panel |
| 85 // created by |extension|. | 116 // created by |extension|. |
| 86 void FindAndClosePanelOnOverflow(const Extension* extension); | 117 void FindAndClosePanelOnOverflow(const Extension* extension); |
| 87 | 118 |
| 88 // Help functions to drag the given panel. | 119 // Help functions to drag the given panel. |
| 89 void DragLeft(); | 120 void DragLeft(); |
| 90 void DragRight(); | 121 void DragRight(); |
| 91 | 122 |
| 92 // Horizontal spacing between panels. Used for unit testing. | 123 // Checks if the titlebars have been brought up or down. If not, do not wait |
| 124 // for the notifications to trigger it any more, and start to bring them up or |
| 125 // down immediately. |
| 126 void DelayedBringUpOrDownTitlebarsCheck(); |
| 127 |
| 128 // Does the real job of bringing up or down the titlebars. |
| 129 void DoBringUpOrDownTitlebars(bool bring_up); |
| 130 |
| 131 int GetRightMostAvaialblePosition() const; |
| 93 | 132 |
| 94 Panels panels_; | 133 Panels panels_; |
| 95 | 134 |
| 96 // Stores the panels that are pending to remove. We want to delay the removal | 135 // Stores the panels that are pending to remove. We want to delay the removal |
| 97 // when we're in the process of the dragging. | 136 // when we're in the process of the dragging. |
| 98 Panels panels_pending_to_remove_; | 137 Panels panels_pending_to_remove_; |
| 99 | 138 |
| 100 // Current work area used in computing the panel bounds. | 139 // The maximum work area avaialble. This area does not include the area taken |
| 140 // by the always-visible (non-auto-hiding) desktop bars. |
| 101 gfx::Rect work_area_; | 141 gfx::Rect work_area_; |
| 102 | 142 |
| 103 // Used in computing the bounds of the next panel. | 143 // The useable work area for computing the panel bounds. This area excludes |
| 104 int max_width_; | 144 // the potential area that could be taken by the auto-hiding desktop |
| 105 int max_height_; | 145 // bars (we only consider those bars that are aligned to bottom, left, and |
| 106 int min_x_; | 146 // right of the screen edges) when they become fully visible. |
| 107 int current_x_; | 147 gfx::Rect adjusted_work_area_; |
| 108 int bottom_edge_y_; | |
| 109 | 148 |
| 110 // Panel to drag. | 149 // Panel to drag. |
| 111 size_t dragging_panel_index_; | 150 size_t dragging_panel_index_; |
| 112 | 151 |
| 113 // Original x coordinate of the panel to drag. This is used to get back to | 152 // Original x coordinate of the panel to drag. This is used to get back to |
| 114 // the original position when we cancel the dragging. | 153 // the original position when we cancel the dragging. |
| 115 int dragging_panel_original_x_; | 154 int dragging_panel_original_x_; |
| 116 | 155 |
| 117 // Bounds of the panel to drag. It is first set to the original bounds when | 156 // Bounds of the panel to drag. It is first set to the original bounds when |
| 118 // the dragging happens. Then it is updated to the position that will be set | 157 // the dragging happens. Then it is updated to the position that will be set |
| 119 // to when the dragging ends. | 158 // to when the dragging ends. |
| 120 gfx::Rect dragging_panel_bounds_; | 159 gfx::Rect dragging_panel_bounds_; |
| 121 | 160 |
| 161 scoped_refptr<AutoHidingDesktopBar> auto_hiding_desktop_bar_; |
| 162 |
| 163 TitlebarAction delayed_titlebar_action_; |
| 164 |
| 165 ScopedRunnableMethodFactory<PanelManager> method_factory_; |
| 166 |
| 122 static const int kPanelsHorizontalSpacing = 4; | 167 static const int kPanelsHorizontalSpacing = 4; |
| 123 | 168 |
| 124 DISALLOW_COPY_AND_ASSIGN(PanelManager); | 169 DISALLOW_COPY_AND_ASSIGN(PanelManager); |
| 125 }; | 170 }; |
| 126 | 171 |
| 127 #endif // CHROME_BROWSER_UI_PANELS_PANEL_MANAGER_H_ | 172 #endif // CHROME_BROWSER_UI_PANELS_PANEL_MANAGER_H_ |
| OLD | NEW |