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 #include "chrome/browser/ui/panels/panel_manager.h" | 5 #include "chrome/browser/ui/panels/panel_manager.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
10 #include "chrome/browser/ui/browser_list.h" | 10 #include "chrome/browser/ui/browser_list.h" |
11 #include "chrome/browser/ui/panels/panel_mouse_watcher.h" | 11 #include "chrome/browser/ui/panels/panel_mouse_watcher.h" |
12 #include "chrome/browser/ui/panels/panel_overflow_strip.h" | |
12 #include "chrome/browser/ui/panels/panel_strip.h" | 13 #include "chrome/browser/ui/panels/panel_strip.h" |
13 #include "chrome/browser/ui/window_sizer.h" | 14 #include "chrome/browser/ui/window_sizer.h" |
14 #include "chrome/common/chrome_notification_types.h" | 15 #include "chrome/common/chrome_notification_types.h" |
15 #include "content/public/browser/notification_service.h" | 16 #include "content/public/browser/notification_service.h" |
16 #include "content/public/browser/notification_source.h" | 17 #include "content/public/browser/notification_source.h" |
17 | 18 |
18 namespace { | 19 namespace { |
19 const int kOverflowStripThickness = 24; | 20 const int kOverflowStripThickness = 24; |
20 | 21 |
21 // Width of spacing around panel strip and the left/right edges of the screen. | 22 // Width of spacing around panel strip and the left/right edges of the screen. |
22 const int kPanelStripLeftMargin = kOverflowStripThickness + 6; | 23 const int kPanelStripLeftMargin = kOverflowStripThickness + 6; |
23 const int kPanelStripRightMargin = 24; | 24 const int kPanelStripRightMargin = 24; |
24 | 25 |
25 // Height of panel strip is based on the factor of the working area. | 26 // Height of panel strip is based on the factor of the working area. |
26 const double kPanelStripHeightFactor = 0.5; | 27 const double kPanelStripHeightFactor = 0.5; |
27 | 28 |
28 } // namespace | 29 } // namespace |
29 | 30 |
30 // static | 31 // static |
31 PanelManager* PanelManager::GetInstance() { | 32 PanelManager* PanelManager::GetInstance() { |
32 static base::LazyInstance<PanelManager> instance = LAZY_INSTANCE_INITIALIZER; | 33 static base::LazyInstance<PanelManager> instance = LAZY_INSTANCE_INITIALIZER; |
33 return instance.Pointer(); | 34 return instance.Pointer(); |
34 } | 35 } |
35 | 36 |
36 PanelManager::PanelManager() | 37 PanelManager::PanelManager() |
37 : panel_mouse_watcher_(PanelMouseWatcher::Create()), | 38 : panel_mouse_watcher_(PanelMouseWatcher::Create()), |
38 auto_sizing_enabled_(true) { | 39 auto_sizing_enabled_(true) { |
39 panel_strip_.reset(new PanelStrip(this)); | 40 panel_strip_.reset(new PanelStrip(this)); |
41 panel_overflow_strip_.reset(new PanelOverflowStrip(this)); | |
40 auto_hiding_desktop_bar_ = AutoHidingDesktopBar::Create(this); | 42 auto_hiding_desktop_bar_ = AutoHidingDesktopBar::Create(this); |
41 OnDisplayChanged(); | 43 OnDisplayChanged(); |
42 } | 44 } |
43 | 45 |
44 PanelManager::~PanelManager() { | 46 PanelManager::~PanelManager() { |
45 } | 47 } |
46 | 48 |
47 void PanelManager::OnDisplayChanged() { | 49 void PanelManager::OnDisplayChanged() { |
48 scoped_ptr<WindowSizer::MonitorInfoProvider> info_provider( | 50 scoped_ptr<WindowSizer::MonitorInfoProvider> info_provider( |
49 WindowSizer::CreateDefaultMonitorInfoProvider()); | 51 WindowSizer::CreateDefaultMonitorInfoProvider()); |
(...skipping 20 matching lines...) Expand all Loading... | |
70 void PanelManager::Layout() { | 72 void PanelManager::Layout() { |
71 int height = | 73 int height = |
72 static_cast<int>(adjusted_work_area_.height() * kPanelStripHeightFactor); | 74 static_cast<int>(adjusted_work_area_.height() * kPanelStripHeightFactor); |
73 gfx::Rect panel_strip_bounds; | 75 gfx::Rect panel_strip_bounds; |
74 panel_strip_bounds.set_x(adjusted_work_area_.x() + kPanelStripLeftMargin); | 76 panel_strip_bounds.set_x(adjusted_work_area_.x() + kPanelStripLeftMargin); |
75 panel_strip_bounds.set_y(adjusted_work_area_.bottom() - height); | 77 panel_strip_bounds.set_y(adjusted_work_area_.bottom() - height); |
76 panel_strip_bounds.set_width(adjusted_work_area_.width() - | 78 panel_strip_bounds.set_width(adjusted_work_area_.width() - |
77 kPanelStripLeftMargin - kPanelStripRightMargin); | 79 kPanelStripLeftMargin - kPanelStripRightMargin); |
78 panel_strip_bounds.set_height(height); | 80 panel_strip_bounds.set_height(height); |
79 panel_strip_->SetDisplayArea(panel_strip_bounds); | 81 panel_strip_->SetDisplayArea(panel_strip_bounds); |
82 | |
83 gfx::Rect overflow_area(adjusted_work_area_); | |
jennb
2011/12/02 19:15:00
Does overflow strip allow for any margins at the t
jianli
2011/12/02 23:23:46
No per the mocks.
| |
84 overflow_area.set_width(kOverflowStripThickness); | |
85 panel_overflow_strip_->SetDisplayArea(overflow_area); | |
80 } | 86 } |
81 | 87 |
82 Panel* PanelManager::CreatePanel(Browser* browser) { | 88 Panel* PanelManager::CreatePanel(Browser* browser) { |
83 int width = browser->override_bounds().width(); | 89 int width = browser->override_bounds().width(); |
84 int height = browser->override_bounds().height(); | 90 int height = browser->override_bounds().height(); |
85 Panel* panel = new Panel(browser, gfx::Size(width, height)); | 91 Panel* panel = new Panel(browser, gfx::Size(width, height)); |
86 panel_strip_->AddPanel(panel); | 92 panel_strip_->AddPanel(panel); |
87 | 93 |
88 content::NotificationService::current()->Notify( | 94 content::NotificationService::current()->Notify( |
89 chrome::NOTIFICATION_PANEL_ADDED, | 95 chrome::NOTIFICATION_PANEL_ADDED, |
90 content::Source<Panel>(panel), | 96 content::Source<Panel>(panel), |
91 content::NotificationService::NoDetails()); | 97 content::NotificationService::NoDetails()); |
92 | 98 |
93 return panel; | 99 return panel; |
94 } | 100 } |
95 | 101 |
96 int PanelManager::StartingRightPosition() const { | 102 int PanelManager::StartingRightPosition() const { |
97 return panel_strip_->StartingRightPosition(); | 103 return panel_strip_->StartingRightPosition(); |
98 } | 104 } |
99 | 105 |
100 void PanelManager::Remove(Panel* panel) { | 106 void PanelManager::Remove(Panel* panel) { |
101 if (panel_strip_->Remove(panel)) | 107 if (panel_strip_->Remove(panel)) |
102 return; | 108 return; |
103 // TODO(jianli): else try removing from overflow strip | 109 panel_overflow_strip_->Remove(panel); |
jennb
2011/12/02 21:16:58
nit: DCHECK this returns true?
jianli
2011/12/02 23:23:46
Done.
| |
104 } | 110 } |
105 | 111 |
106 void PanelManager::OnPanelRemoved(Panel* panel) { | 112 void PanelManager::OnPanelRemoved(Panel* panel) { |
107 content::NotificationService::current()->Notify( | 113 content::NotificationService::current()->Notify( |
108 chrome::NOTIFICATION_PANEL_REMOVED, | 114 chrome::NOTIFICATION_PANEL_REMOVED, |
109 content::Source<Panel>(panel), | 115 content::Source<Panel>(panel), |
110 content::NotificationService::NoDetails()); | 116 content::NotificationService::NoDetails()); |
111 } | 117 } |
112 | 118 |
113 void PanelManager::StartDragging(Panel* panel) { | 119 void PanelManager::StartDragging(Panel* panel) { |
114 panel_strip_->StartDragging(panel); | 120 panel_strip_->StartDragging(panel); |
115 } | 121 } |
116 | 122 |
117 void PanelManager::Drag(int delta_x) { | 123 void PanelManager::Drag(int delta_x) { |
118 panel_strip_->Drag(delta_x); | 124 panel_strip_->Drag(delta_x); |
119 } | 125 } |
120 | 126 |
121 void PanelManager::EndDragging(bool cancelled) { | 127 void PanelManager::EndDragging(bool cancelled) { |
122 panel_strip_->EndDragging(cancelled); | 128 panel_strip_->EndDragging(cancelled); |
123 } | 129 } |
124 | 130 |
125 void PanelManager::OnPanelExpansionStateChanged( | 131 void PanelManager::OnPanelExpansionStateChanged( |
126 Panel::ExpansionState old_state, Panel::ExpansionState new_state) { | 132 Panel* panel, Panel::ExpansionState old_state) { |
127 panel_strip_->OnPanelExpansionStateChanged(old_state, new_state); | 133 if (panel->expansion_state() == Panel::IN_OVERFLOW) |
134 panel_overflow_strip_->OnPanelExpansionStateChanged(panel, old_state); | |
135 else | |
136 panel_strip_->OnPanelExpansionStateChanged(panel, old_state); | |
128 } | 137 } |
129 | 138 |
130 void PanelManager::OnPreferredWindowSizeChanged( | 139 void PanelManager::OnPreferredWindowSizeChanged( |
131 Panel* panel, const gfx::Size& preferred_window_size) { | 140 Panel* panel, const gfx::Size& preferred_window_size) { |
132 if (!auto_sizing_enabled_) | 141 if (!auto_sizing_enabled_) |
133 return; | 142 return; |
134 panel_strip_->OnPreferredWindowSizeChanged(panel, preferred_window_size); | 143 panel_strip_->OnPreferredWindowSizeChanged(panel, preferred_window_size); |
135 } | 144 } |
136 | 145 |
137 bool PanelManager::ShouldBringUpTitlebars(int mouse_x, int mouse_y) const { | 146 bool PanelManager::ShouldBringUpTitlebars(int mouse_x, int mouse_y) const { |
(...skipping 14 matching lines...) Expand all Loading... | |
152 adjusted_work_area_.set_x(adjusted_work_area_.x() + space); | 161 adjusted_work_area_.set_x(adjusted_work_area_.x() + space); |
153 adjusted_work_area_.set_width(adjusted_work_area_.width() - space); | 162 adjusted_work_area_.set_width(adjusted_work_area_.width() - space); |
154 } | 163 } |
155 if (auto_hiding_desktop_bar_->IsEnabled(AutoHidingDesktopBar::ALIGN_RIGHT)) { | 164 if (auto_hiding_desktop_bar_->IsEnabled(AutoHidingDesktopBar::ALIGN_RIGHT)) { |
156 int space = auto_hiding_desktop_bar_->GetThickness( | 165 int space = auto_hiding_desktop_bar_->GetThickness( |
157 AutoHidingDesktopBar::ALIGN_RIGHT); | 166 AutoHidingDesktopBar::ALIGN_RIGHT); |
158 adjusted_work_area_.set_width(adjusted_work_area_.width() - space); | 167 adjusted_work_area_.set_width(adjusted_work_area_.width() - space); |
159 } | 168 } |
160 } | 169 } |
161 | 170 |
162 int PanelManager::GetBottomPositionForExpansionState( | |
163 Panel::ExpansionState expansion_state) const { | |
164 return panel_strip_->GetBottomPositionForExpansionState(expansion_state); | |
165 } | |
166 | |
167 BrowserWindow* PanelManager::GetNextBrowserWindowToActivate( | 171 BrowserWindow* PanelManager::GetNextBrowserWindowToActivate( |
168 Panel* panel) const { | 172 Panel* panel) const { |
169 // Find the last active browser window that is not minimized. | 173 // Find the last active browser window that is not minimized. |
170 BrowserList::const_reverse_iterator iter = BrowserList::begin_last_active(); | 174 BrowserList::const_reverse_iterator iter = BrowserList::begin_last_active(); |
171 BrowserList::const_reverse_iterator end = BrowserList::end_last_active(); | 175 BrowserList::const_reverse_iterator end = BrowserList::end_last_active(); |
172 for (; (iter != end); ++iter) { | 176 for (; (iter != end); ++iter) { |
173 Browser* browser = *iter; | 177 Browser* browser = *iter; |
174 if (panel->browser() != browser && !browser->window()->IsMinimized()) | 178 if (panel->browser() != browser && !browser->window()->IsMinimized()) |
175 return browser->window(); | 179 return browser->window(); |
176 } | 180 } |
177 | 181 |
178 return NULL; | 182 return NULL; |
179 } | 183 } |
180 | 184 |
181 void PanelManager::MoveToOverflowStrip(Panel* panel, bool is_new) { | |
182 // TODO(jianli) - implement. | |
183 } | |
184 | |
185 void PanelManager::OnAutoHidingDesktopBarThicknessChanged() { | 185 void PanelManager::OnAutoHidingDesktopBarThicknessChanged() { |
186 AdjustWorkAreaForAutoHidingDesktopBars(); | 186 AdjustWorkAreaForAutoHidingDesktopBars(); |
187 Layout(); | 187 Layout(); |
188 } | 188 } |
189 | 189 |
190 void PanelManager::OnAutoHidingDesktopBarVisibilityChanged( | 190 void PanelManager::OnAutoHidingDesktopBarVisibilityChanged( |
191 AutoHidingDesktopBar::Alignment alignment, | 191 AutoHidingDesktopBar::Alignment alignment, |
192 AutoHidingDesktopBar::Visibility visibility) { | 192 AutoHidingDesktopBar::Visibility visibility) { |
193 panel_strip_->OnAutoHidingDesktopBarVisibilityChanged(alignment, visibility); | 193 panel_strip_->OnAutoHidingDesktopBarVisibilityChanged(alignment, visibility); |
194 } | 194 } |
195 | 195 |
196 void PanelManager::RemoveAll() { | 196 void PanelManager::RemoveAll() { |
197 panel_strip_->RemoveAll(); | 197 panel_strip_->RemoveAll(); |
198 // TODO(jianli): overflow_strip_->RemoveAll(); | 198 panel_overflow_strip_->RemoveAll(); |
199 } | 199 } |
200 | 200 |
201 int PanelManager::num_panels() const { | 201 int PanelManager::num_panels() const { |
202 return panel_strip_->num_panels(); | 202 return panel_strip_->num_panels()+ panel_overflow_strip_->num_panels(); |
jennb
2011/12/02 19:15:00
space before +
jianli
2011/12/02 23:23:46
Done.
| |
203 // TODO(jianli): + overflow_strip_->num_panels(); | |
204 } | 203 } |
205 | 204 |
206 bool PanelManager::is_dragging_panel() const { | 205 bool PanelManager::is_dragging_panel() const { |
207 return panel_strip_->is_dragging_panel(); | 206 return panel_strip_->is_dragging_panel(); |
208 } | 207 } |
209 | 208 |
210 const PanelManager::Panels& PanelManager::panels() const { | 209 const PanelManager::Panels& PanelManager::panels() const { |
211 return panel_strip_->panels(); | 210 return panel_strip_->panels(); |
212 } | 211 } |
OLD | NEW |