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/docked_panel_strip.h" | 5 #include "chrome/browser/ui/panels/docked_panel_strip.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 DCHECK(panel->initialized()); | 173 DCHECK(panel->initialized()); |
174 | 174 |
175 FitPanelWithWidth(panel->GetBounds().width()); | 175 FitPanelWithWidth(panel->GetBounds().width()); |
176 | 176 |
177 int x = panel->GetBounds().x(); | 177 int x = panel->GetBounds().x(); |
178 Panels::iterator iter = panels_.begin(); | 178 Panels::iterator iter = panels_.begin(); |
179 for (; iter != panels_.end(); ++iter) | 179 for (; iter != panels_.end(); ++iter) |
180 if (x > (*iter)->GetBounds().x()) | 180 if (x > (*iter)->GetBounds().x()) |
181 break; | 181 break; |
182 panels_.insert(iter, panel); | 182 panels_.insert(iter, panel); |
| 183 UpdateMinimizedPanelCount(); |
183 | 184 |
184 // This will automatically update all affected panels due to the insertion. | 185 // This will automatically update all affected panels due to the insertion. |
185 if (iter != panels_.end()) | 186 if (iter != panels_.end()) |
186 RefreshLayout(); | 187 RefreshLayout(); |
187 } | 188 } |
188 | 189 |
189 void DockedPanelStrip::InsertExistingPanelAtDefaultPosition( | 190 void DockedPanelStrip::InsertExistingPanelAtDefaultPosition( |
190 Panel* panel, bool update_bounds) { | 191 Panel* panel, bool update_bounds) { |
191 DCHECK(panel->initialized()); | 192 DCHECK(panel->initialized()); |
192 | 193 |
193 gfx::Size restored_size = panel->restored_size(); | 194 gfx::Size restored_size = panel->restored_size(); |
194 int height = restored_size.height(); | 195 int height = restored_size.height(); |
195 int width = restored_size.width(); | 196 int width = restored_size.width(); |
196 | 197 |
197 int x = FitPanelWithWidth(width); | 198 int x = FitPanelWithWidth(width); |
198 | |
199 if (update_bounds) { | 199 if (update_bounds) { |
200 Panel::ExpansionState expansion_state_to_restore; | 200 Panel::ExpansionState expansion_state_to_restore; |
201 if (panel->expansion_state() == Panel::EXPANDED) { | 201 if (panel->expansion_state() == Panel::EXPANDED) { |
202 expansion_state_to_restore = Panel::EXPANDED; | 202 expansion_state_to_restore = Panel::EXPANDED; |
203 } else { | 203 } else { |
204 if (are_titlebars_up_ || panel->IsDrawingAttention()) { | 204 if (are_titlebars_up_ || panel->IsDrawingAttention()) { |
205 expansion_state_to_restore = Panel::TITLE_ONLY; | 205 expansion_state_to_restore = Panel::TITLE_ONLY; |
206 height = panel->TitleOnlyHeight(); | 206 height = panel->TitleOnlyHeight(); |
207 } else { | 207 } else { |
208 expansion_state_to_restore = Panel::MINIMIZED; | 208 expansion_state_to_restore = Panel::MINIMIZED; |
209 height = Panel::kMinimizedPanelHeight; | 209 height = Panel::kMinimizedPanelHeight; |
210 } | 210 } |
211 IncrementMinimizedPanels(); | |
212 } | 211 } |
213 int y = | 212 int y = |
214 GetBottomPositionForExpansionState(expansion_state_to_restore) - height; | 213 GetBottomPositionForExpansionState(expansion_state_to_restore) - height; |
215 panel->SetPanelBounds(gfx::Rect(x, y, width, height)); | 214 panel->SetPanelBounds(gfx::Rect(x, y, width, height)); |
216 | 215 |
217 // Update the minimized state to reflect current titlebar mode. | 216 // Update the minimized state to reflect current titlebar mode. |
218 // Do this AFTER setting panel bounds to avoid an extra bounds change. | 217 // Do this AFTER setting panel bounds to avoid an extra bounds change. |
219 if (panel->expansion_state() != Panel::EXPANDED) | 218 if (panel->expansion_state() != Panel::EXPANDED) |
220 panel->SetExpansionState(expansion_state_to_restore); | 219 panel->SetExpansionState(expansion_state_to_restore); |
221 } | 220 } |
222 | 221 |
223 panels_.push_back(panel); | 222 panels_.push_back(panel); |
| 223 |
| 224 UpdateMinimizedPanelCount(); |
224 } | 225 } |
225 | 226 |
226 int DockedPanelStrip::GetMaxPanelWidth() const { | 227 int DockedPanelStrip::GetMaxPanelWidth() const { |
227 return static_cast<int>(display_area_.width() * kPanelMaxWidthFactor); | 228 return static_cast<int>(display_area_.width() * kPanelMaxWidthFactor); |
228 } | 229 } |
229 | 230 |
230 int DockedPanelStrip::GetMaxPanelHeight() const { | 231 int DockedPanelStrip::GetMaxPanelHeight() const { |
231 return display_area_.height(); | 232 return display_area_.height(); |
232 } | 233 } |
233 | 234 |
234 int DockedPanelStrip::StartingRightPosition() const { | 235 int DockedPanelStrip::StartingRightPosition() const { |
235 return display_area_.right(); | 236 return display_area_.right(); |
236 } | 237 } |
237 | 238 |
238 int DockedPanelStrip::GetRightMostAvailablePosition() const { | 239 int DockedPanelStrip::GetRightMostAvailablePosition() const { |
239 return panels_.empty() ? StartingRightPosition() : | 240 return panels_.empty() ? StartingRightPosition() : |
240 (panels_.back()->GetBounds().x() - kPanelsHorizontalSpacing); | 241 (panels_.back()->GetBounds().x() - kPanelsHorizontalSpacing); |
241 } | 242 } |
242 | 243 |
243 void DockedPanelStrip::RemovePanel(Panel* panel) { | 244 void DockedPanelStrip::RemovePanel(Panel* panel) { |
244 DCHECK_EQ(this, panel->panel_strip()); | 245 DCHECK_EQ(this, panel->panel_strip()); |
245 panel->SetPanelStrip(NULL); | 246 panel->SetPanelStrip(NULL); |
246 | 247 |
247 if (panel->expansion_state() != Panel::EXPANDED) | |
248 DecrementMinimizedPanels(); | |
249 | |
250 if (panel->has_temporary_layout()) { | 248 if (panel->has_temporary_layout()) { |
251 panels_in_temporary_layout_.erase(panel); | 249 panels_in_temporary_layout_.erase(panel); |
252 return; | 250 return; |
253 } | 251 } |
254 | 252 |
255 // Removing an element from the list will invalidate the iterator that refers | 253 // Removing an element from the list will invalidate the iterator that refers |
256 // to it. We need to update the iterator in that case. | 254 // to it. We need to update the iterator in that case. |
257 DCHECK(dragging_panel_current_iterator_ == panels_.end() || | 255 DCHECK(dragging_panel_current_iterator_ == panels_.end() || |
258 *dragging_panel_current_iterator_ != panel); | 256 *dragging_panel_current_iterator_ != panel); |
259 | 257 |
(...skipping 20 matching lines...) Expand all Loading... |
280 iter = panels_.erase(iter); | 278 iter = panels_.erase(iter); |
281 | 279 |
282 // Update the saved panel placement if needed. This is because we might remove | 280 // Update the saved panel placement if needed. This is because we might remove |
283 // |saved_panel_placement_.left_panel|. | 281 // |saved_panel_placement_.left_panel|. |
284 if (saved_panel_placement_.panel && | 282 if (saved_panel_placement_.panel && |
285 saved_panel_placement_.left_panel == panel) | 283 saved_panel_placement_.left_panel == panel) |
286 saved_panel_placement_.left_panel = *iter; | 284 saved_panel_placement_.left_panel = *iter; |
287 | 285 |
288 RefreshLayout(); | 286 RefreshLayout(); |
289 } | 287 } |
| 288 |
| 289 if (panel->expansion_state() != Panel::EXPANDED) |
| 290 UpdateMinimizedPanelCount(); |
290 } | 291 } |
291 | 292 |
292 bool DockedPanelStrip::CanShowPanelAsActive(const Panel* panel) const { | 293 bool DockedPanelStrip::CanShowPanelAsActive(const Panel* panel) const { |
293 // Panels with temporary layout cannot be shown as active. | 294 // Panels with temporary layout cannot be shown as active. |
294 return !panel->has_temporary_layout(); | 295 return !panel->has_temporary_layout(); |
295 } | 296 } |
296 | 297 |
297 void DockedPanelStrip::SavePanelPlacement(Panel* panel) { | 298 void DockedPanelStrip::SavePanelPlacement(Panel* panel) { |
298 DCHECK(!saved_panel_placement_.panel); | 299 DCHECK(!saved_panel_placement_.panel); |
299 | 300 |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
440 // aborted because either the drag enters other strip or the drag is | 441 // aborted because either the drag enters other strip or the drag is |
441 // cancelled. Either way, we don't need to do anything here and let the drag | 442 // cancelled. Either way, we don't need to do anything here and let the drag |
442 // controller handle the inter-strip transition or the drag cancellation. | 443 // controller handle the inter-strip transition or the drag cancellation. |
443 if (!aborted) | 444 if (!aborted) |
444 RefreshLayout(); | 445 RefreshLayout(); |
445 } | 446 } |
446 | 447 |
447 void DockedPanelStrip::OnPanelExpansionStateChanged(Panel* panel) { | 448 void DockedPanelStrip::OnPanelExpansionStateChanged(Panel* panel) { |
448 gfx::Size size = panel->restored_size(); | 449 gfx::Size size = panel->restored_size(); |
449 Panel::ExpansionState expansion_state = panel->expansion_state(); | 450 Panel::ExpansionState expansion_state = panel->expansion_state(); |
450 Panel::ExpansionState old_state = panel->old_expansion_state(); | |
451 switch (expansion_state) { | 451 switch (expansion_state) { |
452 case Panel::EXPANDED: | 452 case Panel::EXPANDED: |
453 if (old_state == Panel::TITLE_ONLY || old_state == Panel::MINIMIZED) | 453 |
454 DecrementMinimizedPanels(); | |
455 break; | 454 break; |
456 case Panel::TITLE_ONLY: | 455 case Panel::TITLE_ONLY: |
457 size.set_height(panel->TitleOnlyHeight()); | 456 size.set_height(panel->TitleOnlyHeight()); |
458 if (old_state == Panel::EXPANDED) | 457 |
459 IncrementMinimizedPanels(); | |
460 break; | 458 break; |
461 case Panel::MINIMIZED: | 459 case Panel::MINIMIZED: |
462 size.set_height(Panel::kMinimizedPanelHeight); | 460 size.set_height(Panel::kMinimizedPanelHeight); |
463 if (old_state == Panel::EXPANDED) | 461 |
464 IncrementMinimizedPanels(); | |
465 break; | 462 break; |
466 default: | 463 default: |
467 NOTREACHED(); | 464 NOTREACHED(); |
468 break; | 465 break; |
469 } | 466 } |
| 467 UpdateMinimizedPanelCount(); |
470 | 468 |
471 int bottom = GetBottomPositionForExpansionState(expansion_state); | 469 int bottom = GetBottomPositionForExpansionState(expansion_state); |
472 gfx::Rect bounds = panel->GetBounds(); | 470 gfx::Rect bounds = panel->GetBounds(); |
473 panel->SetPanelBounds( | 471 panel->SetPanelBounds( |
474 gfx::Rect(bounds.right() - size.width(), | 472 gfx::Rect(bounds.right() - size.width(), |
475 bottom - size.height(), | 473 bottom - size.height(), |
476 size.width(), | 474 size.width(), |
477 size.height())); | 475 size.height())); |
478 } | 476 } |
479 | 477 |
(...skipping 30 matching lines...) Expand all Loading... |
510 | 508 |
511 void DockedPanelStrip::RestorePanel(Panel* panel) { | 509 void DockedPanelStrip::RestorePanel(Panel* panel) { |
512 DCHECK_EQ(this, panel->panel_strip()); | 510 DCHECK_EQ(this, panel->panel_strip()); |
513 panel->SetExpansionState(Panel::EXPANDED); | 511 panel->SetExpansionState(Panel::EXPANDED); |
514 } | 512 } |
515 | 513 |
516 bool DockedPanelStrip::IsPanelMinimized(const Panel* panel) const { | 514 bool DockedPanelStrip::IsPanelMinimized(const Panel* panel) const { |
517 return panel->expansion_state() != Panel::EXPANDED; | 515 return panel->expansion_state() != Panel::EXPANDED; |
518 } | 516 } |
519 | 517 |
520 void DockedPanelStrip::IncrementMinimizedPanels() { | 518 void DockedPanelStrip::UpdateMinimizedPanelCount() { |
521 minimized_panel_count_++; | 519 int prev_minimized_panel_count = minimized_panel_count_; |
522 if (minimized_panel_count_ == 1) | 520 minimized_panel_count_ = 0; |
| 521 for (Panels::const_iterator panel_iter = panels_.begin(); |
| 522 panel_iter != panels_.end(); ++panel_iter) { |
| 523 if ((*panel_iter)->expansion_state() != Panel::EXPANDED) |
| 524 minimized_panel_count_++; |
| 525 } |
| 526 |
| 527 if (prev_minimized_panel_count == 0 && minimized_panel_count_ > 0) |
523 panel_manager_->mouse_watcher()->AddObserver(this); | 528 panel_manager_->mouse_watcher()->AddObserver(this); |
| 529 if (prev_minimized_panel_count > 0 && minimized_panel_count_ == 0) |
| 530 panel_manager_->mouse_watcher()->RemoveObserver(this); |
| 531 |
524 DCHECK_LE(minimized_panel_count_, num_panels()); | 532 DCHECK_LE(minimized_panel_count_, num_panels()); |
525 } | 533 } |
526 | 534 |
527 void DockedPanelStrip::DecrementMinimizedPanels() { | |
528 minimized_panel_count_--; | |
529 DCHECK_GE(minimized_panel_count_, 0); | |
530 if (minimized_panel_count_ == 0) | |
531 panel_manager_->mouse_watcher()->RemoveObserver(this); | |
532 } | |
533 | |
534 void DockedPanelStrip::ResizePanelWindow( | 535 void DockedPanelStrip::ResizePanelWindow( |
535 Panel* panel, | 536 Panel* panel, |
536 const gfx::Size& preferred_window_size) { | 537 const gfx::Size& preferred_window_size) { |
537 // The panel width: | 538 // The panel width: |
538 // * cannot grow or shrink to go beyond [min_width, max_width] | 539 // * cannot grow or shrink to go beyond [min_width, max_width] |
539 int new_width = preferred_window_size.width(); | 540 int new_width = preferred_window_size.width(); |
540 if (new_width > panel->max_size().width()) | 541 if (new_width > panel->max_size().width()) |
541 new_width = panel->max_size().width(); | 542 new_width = panel->max_size().width(); |
542 if (new_width < panel->min_size().width()) | 543 if (new_width < panel->min_size().width()) |
543 new_width = panel->min_size().width(); | 544 new_width = panel->min_size().width(); |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
838 DCHECK(panels_in_temporary_layout_.empty()); | 839 DCHECK(panels_in_temporary_layout_.empty()); |
839 | 840 |
840 // Make a copy of the iterator as closing panels can modify the vector. | 841 // Make a copy of the iterator as closing panels can modify the vector. |
841 Panels panels_copy = panels_; | 842 Panels panels_copy = panels_; |
842 | 843 |
843 // Start from the bottom to avoid reshuffling. | 844 // Start from the bottom to avoid reshuffling. |
844 for (Panels::reverse_iterator iter = panels_copy.rbegin(); | 845 for (Panels::reverse_iterator iter = panels_copy.rbegin(); |
845 iter != panels_copy.rend(); ++iter) | 846 iter != panels_copy.rend(); ++iter) |
846 (*iter)->Close(); | 847 (*iter)->Close(); |
847 } | 848 } |
OLD | NEW |