Chromium Code Reviews| 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_hide_bottom_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 AutoHideBottomBar::Observer, | |
| 24 public base::RefCountedThreadSafe<PanelManager> { | |
| 20 public: | 25 public: |
| 21 // Returns a single instance. | 26 // Returns a single instance. |
| 22 static PanelManager* GetInstance(); | 27 static PanelManager* GetInstance(); |
| 23 | 28 |
| 24 ~PanelManager(); | 29 virtual ~PanelManager(); |
| 25 | 30 |
| 26 // Called when the display is changed, i.e. work area is updated. | 31 // Called when the display is changed, i.e. work area is updated. |
| 27 void OnDisplayChanged(); | 32 void OnDisplayChanged(); |
| 28 | 33 |
| 29 // Creates a panel and returns it. The panel might be queued for display | 34 // Creates a panel and returns it. The panel might be queued for display |
| 30 // later. | 35 // later. |
| 31 Panel* CreatePanel(Browser* browser); | 36 Panel* CreatePanel(Browser* browser); |
| 32 | 37 |
| 33 void Remove(Panel* panel); | 38 void Remove(Panel* panel); |
| 34 void RemoveAll(); | 39 void RemoveAll(); |
| 35 | 40 |
| 36 // Drags the given panel. | 41 // Drags the given panel. |
| 37 void StartDragging(Panel* panel); | 42 void StartDragging(Panel* panel); |
| 38 void Drag(int delta_x); | 43 void Drag(int delta_x); |
| 39 void EndDragging(bool cancelled); | 44 void EndDragging(bool cancelled); |
| 40 | 45 |
| 41 // Should we bring up the titlebar, given the current mouse point? | 46 // Should we bring up the titlebar, given the current mouse point? |
|
jennb
2011/08/23 20:28:34
Nit: Change comment to "Returns true if we should
jianli
2011/08/26 00:18:16
Done.
| |
| 42 bool ShouldBringUpTitlebarForAllMinimizedPanels(int mouse_x, | 47 bool ShouldBringUpTitlebars(int mouse_x, int mouse_y) const; |
| 43 int mouse_y) const; | |
| 44 | 48 |
| 45 // Brings up or down the title-bar for all minimized panels. | 49 // Brings up or down the titlebars for all minimized panels. |
| 46 void BringUpOrDownTitlebarForAllMinimizedPanels(bool bring_up); | 50 void BringUpOrDownTitlebars(bool bring_up); |
| 51 | |
| 52 // Returns the bottom position for the panel per its expansion state. If auto- | |
| 53 // hide bottom bar is present, we want to move the minimized panel to the | |
| 54 // bottom of the screen, not the bottom of the work area. | |
| 55 int GetBottomPositionForExpansionState( | |
| 56 Panel::ExpansionState expansion_state) const; | |
| 47 | 57 |
| 48 int num_panels() const { return panels_.size(); } | 58 int num_panels() const { return panels_.size(); } |
| 49 bool is_dragging_panel() const; | 59 bool is_dragging_panel() const; |
| 50 | 60 |
| 61 #ifdef UNIT_TEST | |
| 62 // Creates a PanelManager instance with the specified work area and bottom | |
| 63 // bar handler, for the testing purpose. We cannot instantiate the default | |
|
jennb
2011/08/23 20:28:34
nit: s/for the testing purpose/for testing purpose
jianli
2011/08/26 00:18:16
Done.
| |
| 64 // PanelManager instance by calling PanelManager::GetInstance() in the test | |
|
jennb
2011/08/23 20:28:34
Must the PanelManager instance be instantiated in
jianli
2011/08/26 00:18:16
Done.
| |
| 65 // setup routine because the message loop needed by the default bottom bar | |
| 66 // handler has not yet been initialized. | |
| 67 static void CreateForTesting(const gfx::Rect& work_area, | |
| 68 AutoHideBottomBar* auto_hide_bottom_bar) { | |
| 69 CreateForTestingHelper(work_area, auto_hide_bottom_bar); | |
| 70 } | |
| 71 #endif | |
| 72 | |
| 51 private: | 73 private: |
| 52 friend class PanelBrowserTest; | 74 enum DelayedTitlebarAction { |
|
jennb
2011/08/23 20:28:34
Drop 'Delay' prefix. How you use it later brings a
jianli
2011/08/26 00:18:16
Done.
| |
| 75 NO_ACTION, | |
| 76 BRING_UP, | |
| 77 BRING_DOWN | |
| 78 }; | |
| 53 | 79 |
| 54 typedef std::vector<Panel*> Panels; | 80 typedef std::vector<Panel*> Panels; |
| 55 | 81 |
| 56 PanelManager(); | 82 PanelManager(); |
| 57 | 83 |
| 84 // This is only called from the default PanelManager creation logic. | |
| 85 void Init(); | |
| 86 | |
| 87 // Overridden from AutoHideBottomBar::Observer: | |
| 88 virtual void OnAutoHideBottomBarVisibilityChanged( | |
| 89 AutoHideBottomBar::Visibility visibility) OVERRIDE; | |
| 90 virtual void OnAutoHideBottomBarHeightChanged(int height) OVERRIDE; | |
| 91 | |
| 58 // Applies the new work area. This is called by OnDisplayChanged and the test | 92 // Applies the new work area. This is called by OnDisplayChanged and the test |
| 59 // code. | 93 // code. |
| 60 void SetWorkArea(const gfx::Rect& work_area); | 94 void SetWorkArea(const gfx::Rect& work_area); |
| 61 | 95 |
| 62 // Handles all the panels that're delayed to be removed. | 96 // Handles all the panels that're delayed to be removed. |
| 63 void DelayedRemove(); | 97 void DelayedRemove(); |
| 64 | 98 |
| 65 // Does the remove. Called from Remove and DelayedRemove. | 99 // Does the remove. Called from Remove and DelayedRemove. |
| 66 void DoRemove(Panel* panel); | 100 void DoRemove(Panel* panel); |
| 67 | 101 |
| 68 // Rearranges the positions of the panels starting from the given iterator. | 102 // Rearranges the positions of the panels starting from the given iterator. |
| 69 // This is called when the display space has been changed, i.e. working | 103 // This is called when the display space has been changed, i.e. working |
| 70 // area being changed or a panel being closed. | 104 // area being changed or a panel being closed. |
| 71 void Rearrange(Panels::iterator iter_to_start); | 105 void Rearrange(Panels::iterator iter_to_start); |
| 72 | 106 |
| 73 // Computes the bounds for next panel. | 107 // Computes the bounds for next panel. |
| 74 // |allow_size_change| is used to indicate if the panel size can be changed to | 108 // |allow_size_change| is used to indicate if the panel size can be changed to |
| 75 // fall within the size constraint, e.g., when the panel is created. | 109 // fall within the size constraint, e.g., when the panel is created. |
| 76 // Returns true if computed bounds are within the displayable area. | 110 // Returns true if computed bounds are within the displayable area. |
| 77 bool ComputeBoundsForNextPanel(gfx::Rect* bounds, bool allow_size_change); | 111 bool ComputeBoundsForNextPanel(gfx::Rect* bounds, bool allow_size_change); |
| 78 | 112 |
| 79 // Finds one panel to close so that we may have space for the new panel | 113 // Finds one panel to close so that we may have space for the new panel |
| 80 // created by |extension|. | 114 // created by |extension|. |
| 81 void FindAndClosePanelOnOverflow(const Extension* extension); | 115 void FindAndClosePanelOnOverflow(const Extension* extension); |
| 82 | 116 |
| 83 // Help functions to drag the given panel. | 117 // Help functions to drag the given panel. |
| 84 void DragLeft(); | 118 void DragLeft(); |
| 85 void DragRight(); | 119 void DragRight(); |
| 86 | 120 |
| 121 void DelayedBringUpOrDownTitlebarsCheck(); | |
|
jennb
2011/08/23 20:28:34
Comment? What is it checking?
jianli
2011/08/26 00:18:16
Done.
| |
| 122 void DoBringUpOrDownTitlebars(bool bring_up); | |
| 123 | |
| 124 // For testing only. | |
| 125 static void CreateForTestingHelper(const gfx::Rect& work_area, | |
|
jennb
2011/08/23 20:28:34
Why is a helper needed?
jianli
2011/08/26 00:18:16
Removed. Not needed any more.
| |
| 126 AutoHideBottomBar* auto_hide_bottom_bar); | |
| 127 | |
| 87 Panels panels_; | 128 Panels panels_; |
| 88 | 129 |
| 89 // Stores the panels that are pending to remove. We want to delay the removal | 130 // Stores the panels that are pending to remove. We want to delay the removal |
| 90 // when we're in the process of the dragging. | 131 // when we're in the process of the dragging. |
| 91 Panels panels_pending_to_remove_; | 132 Panels panels_pending_to_remove_; |
| 92 | 133 |
| 93 // Current work area used in computing the panel bounds. | 134 // Current work area used in computing the panel bounds. |
| 135 // If the always-on-top bottom bar, like Windows taskbar or MacOSX dock, is | |
| 136 // always visible, it should not be included in the work area. Otherwise, the | |
| 137 // work area includes the potential area that would be taken by the bottom | |
| 138 // bar when it becomes visible. | |
| 94 gfx::Rect work_area_; | 139 gfx::Rect work_area_; |
| 95 | 140 |
| 96 // Used in computing the bounds of the next panel. | 141 // Used in computing the bounds of the next panel. |
| 97 int max_width_; | 142 int max_width_; |
| 98 int max_height_; | 143 int max_height_; |
| 99 int min_x_; | |
| 100 int current_x_; | 144 int current_x_; |
| 101 int bottom_edge_y_; | |
| 102 | 145 |
| 103 // Panel to drag. | 146 // Panel to drag. |
| 104 size_t dragging_panel_index_; | 147 size_t dragging_panel_index_; |
| 105 | 148 |
| 106 // Original x coordinate of the panel to drag. This is used to get back to | 149 // Original x coordinate of the panel to drag. This is used to get back to |
| 107 // the original position when we cancel the dragging. | 150 // the original position when we cancel the dragging. |
| 108 int dragging_panel_original_x_; | 151 int dragging_panel_original_x_; |
| 109 | 152 |
| 110 // Bounds of the panel to drag. It is first set to the original bounds when | 153 // Bounds of the panel to drag. It is first set to the original bounds when |
| 111 // the dragging happens. Then it is updated to the position that will be set | 154 // the dragging happens. Then it is updated to the position that will be set |
| 112 // to when the dragging ends. | 155 // to when the dragging ends. |
| 113 gfx::Rect dragging_panel_bounds_; | 156 gfx::Rect dragging_panel_bounds_; |
| 114 | 157 |
| 158 scoped_refptr<AutoHideBottomBar> auto_hide_bottom_bar_; | |
| 159 | |
| 160 DelayedTitlebarAction delayed_titlebar_action_; | |
| 161 | |
| 162 ScopedRunnableMethodFactory<PanelManager> method_factory_; | |
| 163 | |
| 115 DISALLOW_COPY_AND_ASSIGN(PanelManager); | 164 DISALLOW_COPY_AND_ASSIGN(PanelManager); |
| 116 }; | 165 }; |
| 117 | 166 |
| 118 #endif // CHROME_BROWSER_UI_PANELS_PANEL_MANAGER_H_ | 167 #endif // CHROME_BROWSER_UI_PANELS_PANEL_MANAGER_H_ |
| OLD | NEW |