OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "chrome/browser/fullscreen.h" | 10 #include "chrome/browser/fullscreen.h" |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
110 | 110 |
111 gfx::Rect overflow_area(adjusted_work_area_); | 111 gfx::Rect overflow_area(adjusted_work_area_); |
112 overflow_area.set_width(kOverflowStripThickness); | 112 overflow_area.set_width(kOverflowStripThickness); |
113 overflow_strip_->SetDisplayArea(overflow_area); | 113 overflow_strip_->SetDisplayArea(overflow_area); |
114 } | 114 } |
115 | 115 |
116 Panel* PanelManager::CreatePanel(Browser* browser) { | 116 Panel* PanelManager::CreatePanel(Browser* browser) { |
117 int width = browser->override_bounds().width(); | 117 int width = browser->override_bounds().width(); |
118 int height = browser->override_bounds().height(); | 118 int height = browser->override_bounds().height(); |
119 Panel* panel = new Panel(browser, gfx::Size(width, height)); | 119 Panel* panel = new Panel(browser, gfx::Size(width, height)); |
120 panel->MoveToStrip(docked_strip_.get()); | 120 docked_strip_->AddPanel(panel); |
121 | 121 |
122 content::NotificationService::current()->Notify( | 122 content::NotificationService::current()->Notify( |
123 chrome::NOTIFICATION_PANEL_ADDED, | 123 chrome::NOTIFICATION_PANEL_ADDED, |
124 content::Source<Panel>(panel), | 124 content::Source<Panel>(panel), |
125 content::NotificationService::NoDetails()); | 125 content::NotificationService::NoDetails()); |
126 | 126 |
127 if (num_panels() == 1) { | 127 if (num_panels() == 1) { |
128 full_screen_mode_timer_.Start(FROM_HERE, | 128 full_screen_mode_timer_.Start(FROM_HERE, |
129 base::TimeDelta::FromMilliseconds(kFullScreenModeCheckIntervalMs), | 129 base::TimeDelta::FromMilliseconds(kFullScreenModeCheckIntervalMs), |
130 this, &PanelManager::CheckFullScreenMode); | 130 this, &PanelManager::CheckFullScreenMode); |
131 } | 131 } |
132 | 132 |
133 return panel; | 133 return panel; |
134 } | 134 } |
135 | 135 |
136 int PanelManager::StartingRightPosition() const { | 136 int PanelManager::StartingRightPosition() const { |
137 return docked_strip_->StartingRightPosition(); | 137 return docked_strip_->StartingRightPosition(); |
138 } | 138 } |
139 | 139 |
140 void PanelManager::CheckFullScreenMode() { | 140 void PanelManager::CheckFullScreenMode() { |
141 bool is_full_screen_new = IsFullScreenMode(); | 141 bool is_full_screen_new = IsFullScreenMode(); |
142 if (is_full_screen_ == is_full_screen_new) | 142 if (is_full_screen_ == is_full_screen_new) |
143 return; | 143 return; |
144 is_full_screen_ = is_full_screen_new; | 144 is_full_screen_ = is_full_screen_new; |
145 docked_strip_->OnFullScreenModeChanged(is_full_screen_); | 145 docked_strip_->OnFullScreenModeChanged(is_full_screen_); |
146 overflow_strip_->OnFullScreenModeChanged(is_full_screen_); | 146 overflow_strip_->OnFullScreenModeChanged(is_full_screen_); |
147 } | 147 } |
148 | 148 |
149 void PanelManager::OnPanelClosed(Panel* panel) { | 149 void PanelManager::OnPanelClosed(Panel* panel) { |
150 if (num_panels() == 0) | 150 if (num_panels() == 1) |
151 full_screen_mode_timer_.Stop(); | 151 full_screen_mode_timer_.Stop(); |
152 | 152 |
153 drag_controller_->OnPanelClosed(panel); | 153 drag_controller_->OnPanelClosed(panel); |
154 panel->panel_strip()->RemovePanel(panel); | |
154 | 155 |
155 content::NotificationService::current()->Notify( | 156 content::NotificationService::current()->Notify( |
156 chrome::NOTIFICATION_PANEL_CLOSED, | 157 chrome::NOTIFICATION_PANEL_CLOSED, |
157 content::Source<Panel>(panel), | 158 content::Source<Panel>(panel), |
158 content::NotificationService::NoDetails()); | 159 content::NotificationService::NoDetails()); |
159 } | 160 } |
160 | 161 |
161 void PanelManager::StartDragging(Panel* panel) { | 162 void PanelManager::StartDragging(Panel* panel) { |
162 drag_controller_->StartDragging(panel); | 163 drag_controller_->StartDragging(panel); |
163 } | 164 } |
(...skipping 21 matching lines...) Expand all Loading... | |
185 | 186 |
186 void PanelManager::ResizePanel(Panel* panel, const gfx::Size& new_size) { | 187 void PanelManager::ResizePanel(Panel* panel, const gfx::Size& new_size) { |
187 // Explicit resizing is not allowed for auto-resizable panels for now. | 188 // Explicit resizing is not allowed for auto-resizable panels for now. |
188 // http://crbug.com/109343 | 189 // http://crbug.com/109343 |
189 if (panel->auto_resizable()) | 190 if (panel->auto_resizable()) |
190 return; | 191 return; |
191 | 192 |
192 docked_strip_->ResizePanelWindow(panel, new_size); | 193 docked_strip_->ResizePanelWindow(panel, new_size); |
193 } | 194 } |
194 | 195 |
196 void PanelManager::MovePanelToStrip(Panel* panel, | |
197 PanelStrip::Type new_layout) { | |
198 DCHECK(panel); | |
199 PanelStrip* current_strip = panel->panel_strip(); | |
200 DCHECK(current_strip); | |
201 DCHECK_NE(current_strip->type(), new_layout); | |
202 current_strip->RemovePanel(panel); | |
203 | |
204 PanelStrip* target_strip = NULL; | |
205 switch (new_layout) { | |
206 case PanelStrip::DETACHED: | |
207 target_strip = detached_strip_.get(); | |
208 break; | |
209 case PanelStrip::DOCKED: | |
210 EnsurePanelFitsInDock(panel); | |
211 target_strip = docked_strip_.get(); | |
212 break; | |
213 case PanelStrip::IN_OVERFLOW: | |
214 target_strip = overflow_strip_.get(); | |
215 break; | |
216 default: | |
217 NOTREACHED(); | |
218 } | |
219 | |
220 target_strip->AddPanel(panel); | |
221 | |
222 content::NotificationService::current()->Notify( | |
223 chrome::NOTIFICATION_PANEL_CHANGED_LAYOUT_MODE, | |
224 content::Source<Panel>(panel), | |
225 content::NotificationService::NoDetails()); | |
226 } | |
227 | |
228 void PanelManager::EnsurePanelFitsInDock(Panel* panel) { | |
jianli
2012/03/02 02:26:09
nit: EnsurePanelFitsInDockedStrip?
| |
229 // Prevent layout refreshes while adjusting panels. | |
230 docked_strip_->enable_layout_refresh(false); | |
231 while (!docked_strip_->CanFitPanel(panel)) | |
232 MovePanelToStrip(docked_strip_->last_panel(), PanelStrip::IN_OVERFLOW); | |
jianli
2012/03/02 02:26:09
We know that we start from last docked panel and m
| |
233 docked_strip_->enable_layout_refresh(true); // Re-enable. | |
234 } | |
235 | |
236 void PanelManager::MovePanelsToOverflow(Panel* last_panel_to_move) { | |
237 // Prevent layout refreshes while adjusting panels. | |
238 docked_strip_->enable_layout_refresh(false); | |
239 | |
240 // Move panels to overflow in reverse to maintain their order. | |
241 Panel* bumped_panel; | |
242 while ((bumped_panel = docked_strip_->last_panel())) { | |
243 MovePanelToStrip(bumped_panel, PanelStrip::IN_OVERFLOW); | |
jianli
2012/03/02 02:26:09
ditto.
| |
244 if (bumped_panel == last_panel_to_move) | |
245 break; | |
246 } | |
247 DCHECK(!docked_strip_->panels().empty()); | |
248 | |
249 docked_strip_->enable_layout_refresh(true); // Re-enable. | |
250 } | |
251 | |
252 void PanelManager::MovePanelsOutOfOverflowIfCanFit() { | |
253 // Prevent layout refreshes while adjusting panels. | |
254 docked_strip_->enable_layout_refresh(false); | |
255 | |
256 Panel* overflow_panel; | |
257 while ((overflow_panel = overflow_strip_->first_panel()) && | |
258 docked_strip_->CanFitPanel(overflow_panel)) | |
259 MovePanelToStrip(overflow_panel, PanelStrip::DOCKED); | |
260 | |
261 docked_strip_->enable_layout_refresh(true); // Re-enable. | |
262 } | |
263 | |
195 bool PanelManager::ShouldBringUpTitlebars(int mouse_x, int mouse_y) const { | 264 bool PanelManager::ShouldBringUpTitlebars(int mouse_x, int mouse_y) const { |
196 return docked_strip_->ShouldBringUpTitlebars(mouse_x, mouse_y); | 265 return docked_strip_->ShouldBringUpTitlebars(mouse_x, mouse_y); |
197 } | 266 } |
198 | 267 |
199 void PanelManager::BringUpOrDownTitlebars(bool bring_up) { | 268 void PanelManager::BringUpOrDownTitlebars(bool bring_up) { |
200 docked_strip_->BringUpOrDownTitlebars(bring_up); | 269 docked_strip_->BringUpOrDownTitlebars(bring_up); |
201 } | 270 } |
202 | 271 |
203 void PanelManager::AdjustWorkAreaForAutoHidingDesktopBars() { | 272 void PanelManager::AdjustWorkAreaForAutoHidingDesktopBars() { |
204 // Note that we do not care about the desktop bar aligned to the top edge | 273 // Note that we do not care about the desktop bar aligned to the top edge |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
273 return panels; | 342 return panels; |
274 } | 343 } |
275 | 344 |
276 int PanelManager::overflow_strip_width() const { | 345 int PanelManager::overflow_strip_width() const { |
277 return kOverflowStripThickness; | 346 return kOverflowStripThickness; |
278 } | 347 } |
279 | 348 |
280 void PanelManager::SetMouseWatcher(PanelMouseWatcher* watcher) { | 349 void PanelManager::SetMouseWatcher(PanelMouseWatcher* watcher) { |
281 panel_mouse_watcher_.reset(watcher); | 350 panel_mouse_watcher_.reset(watcher); |
282 } | 351 } |
OLD | NEW |