| OLD | NEW |
| (Empty) |
| 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_DOCKED_PANEL_COLLECTION_H_ | |
| 6 #define CHROME_BROWSER_UI_PANELS_DOCKED_PANEL_COLLECTION_H_ | |
| 7 | |
| 8 #include <list> | |
| 9 #include <set> | |
| 10 | |
| 11 #include "base/macros.h" | |
| 12 #include "base/memory/weak_ptr.h" | |
| 13 #include "chrome/browser/ui/panels/display_settings_provider.h" | |
| 14 #include "chrome/browser/ui/panels/panel.h" | |
| 15 #include "chrome/browser/ui/panels/panel_collection.h" | |
| 16 #include "chrome/browser/ui/panels/panel_mouse_watcher_observer.h" | |
| 17 #include "ui/gfx/geometry/rect.h" | |
| 18 | |
| 19 class PanelManager; | |
| 20 | |
| 21 // This class manages a group of panels that could be docked to the bottom of | |
| 22 // screen. | |
| 23 class DockedPanelCollection : | |
| 24 public PanelCollection, | |
| 25 public PanelMouseWatcherObserver, | |
| 26 public DisplaySettingsProvider::DesktopBarObserver { | |
| 27 public: | |
| 28 typedef std::list<Panel*> Panels; | |
| 29 | |
| 30 explicit DockedPanelCollection(PanelManager* panel_manager); | |
| 31 ~DockedPanelCollection() override; | |
| 32 | |
| 33 // PanelCollection OVERRIDES: | |
| 34 void OnDisplayChanged() override; | |
| 35 | |
| 36 // Rearranges the positions of the panels in the collection | |
| 37 // and reduces their width when there is not enough room. | |
| 38 // This is called when the display space has been changed, i.e. working | |
| 39 // area being changed or a panel being closed. | |
| 40 void RefreshLayout() override; | |
| 41 | |
| 42 // Adds a panel to the collection. The panel may be a newly created panel or | |
| 43 // one that is transitioning from another grouping of panels. | |
| 44 void AddPanel(Panel* panel, PositioningMask positioning_mask) override; | |
| 45 void RemovePanel(Panel* pane, RemovalReason reasonl) override; | |
| 46 void CloseAll() override; | |
| 47 void ResizePanelWindow(Panel* panel, | |
| 48 const gfx::Size& preferred_window_size) override; | |
| 49 panel::Resizability GetPanelResizability(const Panel* panel) const override; | |
| 50 void OnPanelResizedByMouse(Panel* panel, | |
| 51 const gfx::Rect& new_bounds) override; | |
| 52 void OnPanelAttentionStateChanged(Panel* panel) override; | |
| 53 void OnPanelTitlebarClicked(Panel* panel, | |
| 54 panel::ClickModifier modifier) override; | |
| 55 void ActivatePanel(Panel* panel) override; | |
| 56 void MinimizePanel(Panel* panel) override; | |
| 57 void RestorePanel(Panel* panel) override; | |
| 58 void OnMinimizeButtonClicked(Panel* panel, | |
| 59 panel::ClickModifier modifier) override; | |
| 60 void OnRestoreButtonClicked(Panel* panel, | |
| 61 panel::ClickModifier modifier) override; | |
| 62 bool CanShowMinimizeButton(const Panel* panel) const override; | |
| 63 bool CanShowRestoreButton(const Panel* panel) const override; | |
| 64 bool IsPanelMinimized(const Panel* panel) const override; | |
| 65 bool UsesAlwaysOnTopPanels() const override; | |
| 66 void SavePanelPlacement(Panel* panel) override; | |
| 67 void RestorePanelToSavedPlacement() override; | |
| 68 void DiscardSavedPanelPlacement() override; | |
| 69 void UpdatePanelOnCollectionChange(Panel* panel) override; | |
| 70 void OnPanelExpansionStateChanged(Panel* panel) override; | |
| 71 void OnPanelActiveStateChanged(Panel* panel) override; | |
| 72 gfx::Rect GetInitialPanelBounds( | |
| 73 const gfx::Rect& requested_bounds) const override; | |
| 74 | |
| 75 // Returns true if we should bring up the titlebars, given the current mouse | |
| 76 // point. | |
| 77 bool ShouldBringUpTitlebars(int mouse_x, int mouse_y) const; | |
| 78 | |
| 79 // Brings up or down the titlebars for all minimized panels. | |
| 80 void BringUpOrDownTitlebars(bool bring_up); | |
| 81 | |
| 82 // Returns the bottom position for the panel per its expansion state. If auto- | |
| 83 // hide bottom bar is present, we want to move the minimized panel to the | |
| 84 // bottom of the screen, not the bottom of the work area. | |
| 85 int GetBottomPositionForExpansionState( | |
| 86 Panel::ExpansionState expansion_state) const; | |
| 87 | |
| 88 // Returns panel width to be used, taking into account possible "squeezing" | |
| 89 // due to lack of space in the collection. | |
| 90 int WidthToDisplayPanelInCollection(bool is_for_active_panel, | |
| 91 double squeeze_factor, | |
| 92 int full_width) const; | |
| 93 | |
| 94 bool HasPanel(Panel* panel) const; | |
| 95 | |
| 96 // num_panels() and panels() only includes panels in the collection that | |
| 97 // do NOT have a temporary layout. | |
| 98 int num_panels() const { return panels_.size(); } | |
| 99 const Panels& panels() const { return panels_; } | |
| 100 Panel* last_panel() const { return panels_.empty() ? NULL : panels_.back(); } | |
| 101 | |
| 102 gfx::Rect work_area() const { return work_area_; } | |
| 103 | |
| 104 int StartingRightPosition() const; | |
| 105 | |
| 106 #ifdef UNIT_TEST | |
| 107 int minimized_panel_count() const {return minimized_panel_count_; } | |
| 108 #endif | |
| 109 | |
| 110 private: | |
| 111 friend class DockedPanelDragHandler; | |
| 112 | |
| 113 enum TitlebarAction { | |
| 114 NO_ACTION, | |
| 115 BRING_UP, | |
| 116 BRING_DOWN | |
| 117 }; | |
| 118 | |
| 119 struct PanelPlacement { | |
| 120 Panel* panel; | |
| 121 // Used to remember the panel to the left of |panel|, if any, for use when | |
| 122 // restoring the position of |panel|. | |
| 123 Panel* left_panel; | |
| 124 | |
| 125 PanelPlacement() : panel(NULL), left_panel(NULL) { } | |
| 126 }; | |
| 127 | |
| 128 // Overridden from PanelMouseWatcherObserver: | |
| 129 void OnMouseMove(const gfx::Point& mouse_position) override; | |
| 130 | |
| 131 // Overridden from DisplaySettingsProvider::DesktopBarObserver: | |
| 132 void OnAutoHidingDesktopBarVisibilityChanged( | |
| 133 DisplaySettingsProvider::DesktopBarAlignment alignment, | |
| 134 DisplaySettingsProvider::DesktopBarVisibility visibility) override; | |
| 135 void OnAutoHidingDesktopBarThicknessChanged( | |
| 136 DisplaySettingsProvider::DesktopBarAlignment alignment, | |
| 137 int thickness) override; | |
| 138 | |
| 139 // Schedules a layout refresh with a short delay to avoid too much flicker. | |
| 140 void ScheduleLayoutRefresh(); | |
| 141 | |
| 142 // Keep track of the minimized panels to control mouse watching. | |
| 143 void UpdateMinimizedPanelCount(); | |
| 144 | |
| 145 // Minimizes or restores all panels in the collection. | |
| 146 void MinimizeAll(); | |
| 147 void RestoreAll(); | |
| 148 | |
| 149 // Makes sure the panel's bounds reflect its expansion state and the | |
| 150 // panel is aligned at the bottom of the screen. Does not touch the x | |
| 151 // coordinate. | |
| 152 void AdjustPanelBoundsPerExpansionState(Panel* panel, | |
| 153 gfx::Rect* panel_bounds); | |
| 154 | |
| 155 // Does the real job of bringing up or down the titlebars. | |
| 156 void DoBringUpOrDownTitlebars(bool bring_up); | |
| 157 // The callback for a delyed task, checks if it still need to perform | |
| 158 // the delayed action. | |
| 159 void DelayedBringUpOrDownTitlebarsCheck(); | |
| 160 | |
| 161 // Compute default bounds for a panel of |full_size| that would be used | |
| 162 // when adding the panel to the collection. | |
| 163 gfx::Point GetDefaultPositionForPanel(const gfx::Size& full_size) const; | |
| 164 | |
| 165 int GetRightMostAvailablePosition() const; | |
| 166 | |
| 167 PanelManager* panel_manager_; // Weak, owns us. | |
| 168 | |
| 169 // All panels in the collection must fit within this area. | |
| 170 gfx::Rect work_area_; | |
| 171 | |
| 172 Panels panels_; | |
| 173 | |
| 174 int minimized_panel_count_; | |
| 175 bool are_titlebars_up_; | |
| 176 | |
| 177 bool minimizing_all_; // True while minimizing all panels. | |
| 178 | |
| 179 // Delayed transitions support. Sometimes transitions between minimized and | |
| 180 // title-only states are delayed, for better usability with Taskbars/Docks. | |
| 181 TitlebarAction delayed_titlebar_action_; | |
| 182 | |
| 183 // Used to save the placement information for a panel. | |
| 184 PanelPlacement saved_panel_placement_; | |
| 185 | |
| 186 static const int kPanelsHorizontalSpacing = 4; | |
| 187 | |
| 188 // Owned by MessageLoop after posting. | |
| 189 base::WeakPtrFactory<DockedPanelCollection> titlebar_action_factory_; | |
| 190 | |
| 191 // Owned by MessageLoop after posting. | |
| 192 base::WeakPtrFactory<DockedPanelCollection> refresh_action_factory_; | |
| 193 | |
| 194 DISALLOW_COPY_AND_ASSIGN(DockedPanelCollection); | |
| 195 }; | |
| 196 | |
| 197 #endif // CHROME_BROWSER_UI_PANELS_DOCKED_PANEL_COLLECTION_H_ | |
| OLD | NEW |