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_strip.h" | 5 #include "chrome/browser/ui/panels/panel_strip.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
74 gfx::Rect old_area = display_area_; | 74 gfx::Rect old_area = display_area_; |
75 display_area_ = new_area; | 75 display_area_ = new_area; |
76 | 76 |
77 if (panels_.empty()) | 77 if (panels_.empty()) |
78 return; | 78 return; |
79 | 79 |
80 Rearrange(); | 80 Rearrange(); |
81 } | 81 } |
82 | 82 |
83 void PanelStrip::AddPanel(Panel* panel) { | 83 void PanelStrip::AddPanel(Panel* panel) { |
84 DCHECK_NE(Panel::IN_OVERFLOW, panel->expansion_state()); | 84 DCHECK_NE(Panel::IN_OVERFLOW, panel->layout_state()); |
85 | 85 |
86 // Always update limits, even for exiting panels, in case the maximums changed | 86 // Always update limits, even for exiting panels, in case the maximums changed |
87 // while panel was out of the strip. | 87 // while panel was out of the strip. |
88 int max_panel_width = GetMaxPanelWidth(); | 88 int max_panel_width = GetMaxPanelWidth(); |
89 int max_panel_height = GetMaxPanelHeight(); | 89 int max_panel_height = GetMaxPanelHeight(); |
90 panel->SetSizeRange(gfx::Size(kPanelMinWidth, kPanelMinHeight), | 90 panel->SetSizeRange(gfx::Size(kPanelMinWidth, kPanelMinHeight), |
91 gfx::Size(max_panel_width, max_panel_height)); | 91 gfx::Size(max_panel_width, max_panel_height)); |
92 | 92 |
93 gfx::Size restored_size = panel->restored_size(); | 93 gfx::Size restored_size = panel->restored_size(); |
94 int height = restored_size.height(); | 94 int height = restored_size.height(); |
95 int width = restored_size.width(); | 95 int width = restored_size.width(); |
96 | 96 |
97 if (panel->initialized()) { | 97 if (panel->initialized()) { |
98 // Bump panels in the strip to make room for this panel. | 98 // Bump panels in the strip to make room for this panel. |
99 int x; | 99 int x; |
100 while ((x = GetRightMostAvailablePosition() - width) < display_area_.x()) { | 100 while ((x = GetRightMostAvailablePosition() - width) < display_area_.x()) { |
101 DCHECK(!panels_.empty()); | 101 DCHECK(!panels_.empty()); |
102 panels_.back()->SetExpansionState(Panel::IN_OVERFLOW); | 102 panels_.back()->SetLayoutState(Panel::IN_OVERFLOW); |
103 } | 103 } |
104 int y = display_area_.bottom() - height; | 104 int y = display_area_.bottom() - height; |
105 panel->SetPanelBounds(gfx::Rect(x, y, width, height)); | 105 panel->SetPanelBounds(gfx::Rect(x, y, width, height)); |
106 | |
107 if (panel->expansion_state() == Panel::TITLE_ONLY || | |
108 panel->expansion_state() == Panel::MINIMIZED) | |
109 IncrementMinimizedPanels(); | |
106 } else { | 110 } else { |
107 // Initialize the newly created panel. Does not bump any panels from strip. | 111 // Initialize the newly created panel. Does not bump any panels from strip. |
108 if (height == 0 && width == 0) { | 112 if (height == 0 && width == 0) { |
109 // Auto resizable is enabled only if no initial size is provided. | 113 // Auto resizable is enabled only if no initial size is provided. |
110 panel->SetAutoResizable(true); | 114 panel->SetAutoResizable(true); |
111 } else { | 115 } else { |
112 if (height == 0) | 116 if (height == 0) |
113 height = width / kPanelDefaultWidthToHeightRatio; | 117 height = width / kPanelDefaultWidthToHeightRatio; |
114 if (width == 0) | 118 if (width == 0) |
115 width = height * kPanelDefaultWidthToHeightRatio; | 119 width = height * kPanelDefaultWidthToHeightRatio; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
186 // If we're in the process of dragging, delay the removal. | 190 // If we're in the process of dragging, delay the removal. |
187 if (dragging_panel_index_ != kInvalidPanelIndex) { | 191 if (dragging_panel_index_ != kInvalidPanelIndex) { |
188 panels_pending_to_remove_.push_back(panel); | 192 panels_pending_to_remove_.push_back(panel); |
189 return true; | 193 return true; |
190 } | 194 } |
191 | 195 |
192 DoRemove(panel); | 196 DoRemove(panel); |
193 | 197 |
194 // Don't rearrange the strip if a panel is being moved from the panel strip | 198 // Don't rearrange the strip if a panel is being moved from the panel strip |
195 // to the overflow strip. | 199 // to the overflow strip. |
196 if (panel->expansion_state() != Panel::IN_OVERFLOW) | 200 if (panel->layout_state() == Panel::DOCKED) |
197 Rearrange(); | 201 Rearrange(); |
198 | 202 |
199 return true; | 203 return true; |
200 } | 204 } |
201 | 205 |
202 void PanelStrip::DelayedRemove() { | 206 void PanelStrip::DelayedRemove() { |
203 for (size_t i = 0; i < panels_pending_to_remove_.size(); ++i) | 207 for (size_t i = 0; i < panels_pending_to_remove_.size(); ++i) |
204 DoRemove(panels_pending_to_remove_[i]); | 208 DoRemove(panels_pending_to_remove_[i]); |
205 panels_pending_to_remove_.clear(); | 209 panels_pending_to_remove_.clear(); |
206 Rearrange(); | 210 Rearrange(); |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
344 } else { | 348 } else { |
345 panels_[dragging_panel_index_]->SetPanelBounds( | 349 panels_[dragging_panel_index_]->SetPanelBounds( |
346 dragging_panel_bounds_); | 350 dragging_panel_bounds_); |
347 } | 351 } |
348 | 352 |
349 dragging_panel_index_ = kInvalidPanelIndex; | 353 dragging_panel_index_ = kInvalidPanelIndex; |
350 | 354 |
351 DelayedRemove(); | 355 DelayedRemove(); |
352 } | 356 } |
353 | 357 |
354 void PanelStrip::OnPanelExpansionStateChanged(Panel* panel) { | 358 void PanelStrip::OnPanelLayoutStateChanged(Panel* panel, |
359 Panel::LayoutState old_state) { | |
360 Panel::LayoutState layout_state = panel->layout_state(); | |
361 switch (layout_state) { | |
362 case Panel::DOCKED: | |
363 if (old_state == Panel::IN_OVERFLOW) { | |
364 panel_manager_->panel_overflow_strip()->Remove(panel); | |
365 AddPanel(panel); | |
366 panel->SetAppIconVisibility(true); | |
367 panel->set_draggable(true); | |
368 UpdateBoundsPerExpansionState(panel); | |
369 } | |
370 break; | |
371 case Panel::DETACHED: | |
372 case Panel::IN_OVERFLOW: | |
373 DCHECK_EQ(Panel::DOCKED, old_state); | |
374 break; | |
375 default: | |
376 NOTREACHED(); | |
377 break; | |
378 } | |
379 } | |
380 | |
381 void PanelStrip::OnPanelExpansionStateChanged(Panel* panel, | |
382 Panel::ExpansionState old_state) { | |
383 DCHECK_EQ(Panel::DOCKED, panel->layout_state()); | |
384 | |
385 switch (panel->expansion_state()) { | |
386 case Panel::EXPANDED: | |
387 DecrementMinimizedPanels(); | |
388 break; | |
389 case Panel::TITLE_ONLY: | |
390 case Panel::MINIMIZED: | |
391 if (old_state == Panel::EXPANDED) | |
392 IncrementMinimizedPanels(); | |
393 break; | |
394 default: | |
395 NOTREACHED(); | |
396 break; | |
397 } | |
398 | |
399 UpdateBoundsPerExpansionState(panel); | |
400 } | |
401 | |
402 void PanelStrip::UpdateBoundsPerExpansionState(Panel* panel) { | |
355 gfx::Size size = panel->restored_size(); | 403 gfx::Size size = panel->restored_size(); |
356 Panel::ExpansionState expansion_state = panel->expansion_state(); | 404 Panel::ExpansionState expansion_state = panel->expansion_state(); |
357 Panel::ExpansionState old_state = panel->old_expansion_state(); | |
358 if (old_state == Panel::IN_OVERFLOW) { | |
359 panel_manager_->panel_overflow_strip()->Remove(panel); | |
360 AddPanel(panel); | |
361 panel->SetAppIconVisibility(true); | |
362 panel->set_draggable(true); | |
363 } | |
364 switch (expansion_state) { | 405 switch (expansion_state) { |
365 case Panel::EXPANDED: | 406 case Panel::EXPANDED: |
366 if (old_state == Panel::TITLE_ONLY || old_state == Panel::MINIMIZED) | |
367 DecrementMinimizedPanels(); | |
368 break; | 407 break; |
369 case Panel::TITLE_ONLY: | 408 case Panel::TITLE_ONLY: |
370 size.set_height(panel->TitleOnlyHeight()); | 409 size.set_height(panel->TitleOnlyHeight()); |
371 if (old_state == Panel::EXPANDED || old_state == Panel::IN_OVERFLOW) | |
372 IncrementMinimizedPanels(); | |
373 break; | 410 break; |
374 case Panel::MINIMIZED: | 411 case Panel::MINIMIZED: |
375 size.set_height(Panel::kMinimizedPanelHeight); | 412 size.set_height(Panel::kMinimizedPanelHeight); |
376 if (old_state == Panel::EXPANDED || old_state == Panel::IN_OVERFLOW) | |
377 IncrementMinimizedPanels(); | |
378 break; | |
379 case Panel::IN_OVERFLOW: | |
380 if (old_state == Panel::TITLE_ONLY || old_state == Panel::MINIMIZED) | |
381 DecrementMinimizedPanels(); | |
382 break; | 413 break; |
383 default: | 414 default: |
384 NOTREACHED(); | 415 NOTREACHED(); |
385 break; | 416 break; |
386 } | 417 } |
387 | 418 |
388 int bottom = GetBottomPositionForExpansionState(expansion_state); | 419 int bottom = GetBottomPositionForExpansionState(expansion_state); |
389 gfx::Rect bounds = panel->GetBounds(); | 420 gfx::Rect bounds = panel->GetBounds(); |
390 panel->SetPanelBounds( | 421 panel->SetPanelBounds( |
391 gfx::Rect(bounds.right() - size.width(), | 422 gfx::Rect(bounds.right() - size.width(), |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
424 if (new_height > panel->max_size().height()) | 455 if (new_height > panel->max_size().height()) |
425 new_height = panel->max_size().height(); | 456 new_height = panel->max_size().height(); |
426 if (new_height < panel->min_size().height()) | 457 if (new_height < panel->min_size().height()) |
427 new_height = panel->min_size().height(); | 458 new_height = panel->min_size().height(); |
428 | 459 |
429 // Update restored size. | 460 // Update restored size. |
430 gfx::Size new_size(new_width, new_height); | 461 gfx::Size new_size(new_width, new_height); |
431 if (new_size != panel->restored_size()) | 462 if (new_size != panel->restored_size()) |
432 panel->set_restored_size(new_size); | 463 panel->set_restored_size(new_size); |
433 | 464 |
434 // Only need to adjust bounds height when panel is expanded. | 465 Panel::LayoutState layout_state = panel->layout_state(); |
435 gfx::Rect bounds = panel->GetBounds(); | 466 gfx::Rect bounds = panel->GetBounds(); |
436 Panel::ExpansionState expansion_state = panel->expansion_state(); | 467 int delta_x = bounds.width() - new_width; |
437 if (new_height != bounds.height() && | 468 |
438 expansion_state == Panel::EXPANDED) { | 469 // Only need to update bounds when the panel is docked or detached. |
439 bounds.set_y(bounds.bottom() - new_height); | 470 if (layout_state != Panel::IN_OVERFLOW) { |
440 bounds.set_height(new_height); | 471 // Height is only affected when panel is expanded. |
472 if (new_height != bounds.height() && | |
473 panel->expansion_state() == Panel::EXPANDED) { | |
474 bounds.set_y(bounds.bottom() - new_height); | |
475 bounds.set_height(new_height); | |
476 } | |
477 | |
478 if (delta_x != 0) { | |
479 bounds.set_width(new_width); | |
480 bounds.set_x(bounds.x() + delta_x); | |
481 } | |
482 | |
483 if (bounds != panel->GetBounds()) | |
484 panel->SetPanelBounds(bounds); | |
441 } | 485 } |
442 | 486 |
443 // Only need to adjust width if panel is in the panel strip. | 487 // If the panel is docked, rearrange if panel's width is changed. |
444 int delta_x = bounds.width() - new_width; | 488 // If the panel is in overflow, rearrange if panel's width is smaller becuase |
jennb
2012/01/20 02:01:54
typo: becuase
jianli
2012/01/20 23:33:08
Done.
| |
445 if (delta_x != 0 && expansion_state != Panel::IN_OVERFLOW) { | 489 // we might have sufficient space in the docking area to fit the shrunken |
446 bounds.set_width(new_width); | 490 // overflow panel. |
447 bounds.set_x(bounds.x() + delta_x); | 491 if ((layout_state == Panel::DOCKED && delta_x != 0) || |
448 } | 492 (layout_state == Panel::IN_OVERFLOW && delta_x < 0)) |
449 | |
450 if (bounds != panel->GetBounds()) | |
451 panel->SetPanelBounds(bounds); | |
452 | |
453 // Only need to rearrange if panel's width changed. | |
454 if (delta_x != 0) | |
455 Rearrange(); | 493 Rearrange(); |
456 } | 494 } |
457 | 495 |
458 bool PanelStrip::ShouldBringUpTitlebars(int mouse_x, int mouse_y) const { | 496 bool PanelStrip::ShouldBringUpTitlebars(int mouse_x, int mouse_y) const { |
459 // We should always bring up the titlebar if the mouse is over the | 497 // We should always bring up the titlebar if the mouse is over the |
460 // visible auto-hiding bottom bar. | 498 // visible auto-hiding bottom bar. |
461 AutoHidingDesktopBar* desktop_bar = panel_manager_->auto_hiding_desktop_bar(); | 499 AutoHidingDesktopBar* desktop_bar = panel_manager_->auto_hiding_desktop_bar(); |
462 if (desktop_bar->IsEnabled(AutoHidingDesktopBar::ALIGN_BOTTOM) && | 500 if (desktop_bar->IsEnabled(AutoHidingDesktopBar::ALIGN_BOTTOM) && |
463 desktop_bar->GetVisibility(AutoHidingDesktopBar::ALIGN_BOTTOM) == | 501 desktop_bar->GetVisibility(AutoHidingDesktopBar::ALIGN_BOTTOM) == |
464 AutoHidingDesktopBar::VISIBLE && | 502 AutoHidingDesktopBar::VISIBLE && |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
650 | 688 |
651 // TODO(jianli): remove the guard when overflow support is enabled on other | 689 // TODO(jianli): remove the guard when overflow support is enabled on other |
652 // platforms. http://crbug.com/105073 | 690 // platforms. http://crbug.com/105073 |
653 #if defined(OS_WIN) | 691 #if defined(OS_WIN) |
654 // Add/remove panels from/to overflow. A change in work area or the | 692 // Add/remove panels from/to overflow. A change in work area or the |
655 // resize/removal of a panel may affect how many panels fit in the strip. | 693 // resize/removal of a panel may affect how many panels fit in the strip. |
656 if (panel_index < panels_.size()) { | 694 if (panel_index < panels_.size()) { |
657 // Move panels to overflow in reverse to maintain their order. | 695 // Move panels to overflow in reverse to maintain their order. |
658 for (size_t overflow_index = panels_.size() - 1; | 696 for (size_t overflow_index = panels_.size() - 1; |
659 overflow_index >= panel_index; --overflow_index) | 697 overflow_index >= panel_index; --overflow_index) |
660 panels_[overflow_index]->SetExpansionState(Panel::IN_OVERFLOW); | 698 panels_[overflow_index]->SetLayoutState(Panel::IN_OVERFLOW); |
661 } else { | 699 } else { |
662 // Attempt to add more panels from overflow to the strip. | 700 // Attempt to add more panels from overflow to the strip. |
663 PanelOverflowStrip* overflow_strip = panel_manager_->panel_overflow_strip(); | 701 PanelOverflowStrip* overflow_strip = panel_manager_->panel_overflow_strip(); |
664 Panel* overflow_panel; | 702 Panel* overflow_panel; |
665 while ((overflow_panel = overflow_strip->first_panel()) && | 703 while ((overflow_panel = overflow_strip->first_panel()) && |
666 GetRightMostAvailablePosition() >= | 704 GetRightMostAvailablePosition() >= |
667 display_area_.x() + overflow_panel->restored_size().width()) { | 705 display_area_.x() + overflow_panel->restored_size().width()) { |
668 // We need to get back to the previous expansion state. | 706 // We need to get back to the previous expansion state. |
669 Panel::ExpansionState expansion_state_to_restore = | 707 Panel::ExpansionState expansion_state_to_restore = |
670 overflow_panel->old_expansion_state(); | 708 overflow_panel->expansion_state(); |
671 if (expansion_state_to_restore == Panel::MINIMIZED || | 709 if (expansion_state_to_restore != Panel::EXPANDED) { |
672 expansion_state_to_restore == Panel::TITLE_ONLY) { | |
673 expansion_state_to_restore = are_titlebars_up_ ? Panel::TITLE_ONLY | 710 expansion_state_to_restore = are_titlebars_up_ ? Panel::TITLE_ONLY |
674 : Panel::MINIMIZED; | 711 : Panel::MINIMIZED; |
675 } | 712 } |
676 overflow_panel->SetExpansionState(expansion_state_to_restore); | 713 overflow_panel->SetExpansionState(expansion_state_to_restore); |
714 overflow_panel->SetLayoutState(Panel::DOCKED); | |
677 } | 715 } |
678 } | 716 } |
679 #endif | 717 #endif |
680 } | 718 } |
681 | 719 |
682 void PanelStrip::DelayedMovePanelToOverflow(Panel* panel) { | 720 void PanelStrip::DelayedMovePanelToOverflow(Panel* panel) { |
683 if (panels_in_temporary_layout_.erase(panel)) { | 721 if (panels_in_temporary_layout_.erase(panel)) { |
684 DCHECK(panel->has_temporary_layout()); | 722 DCHECK(panel->has_temporary_layout()); |
685 panel->SetExpansionState(Panel::IN_OVERFLOW); | 723 panel->SetLayoutState(Panel::IN_OVERFLOW); |
686 } | 724 } |
687 } | 725 } |
688 | 726 |
689 void PanelStrip::RemoveAll() { | 727 void PanelStrip::RemoveAll() { |
690 // This should only be called at the end of tests to clean up. | 728 // This should only be called at the end of tests to clean up. |
691 DCHECK(dragging_panel_index_ == kInvalidPanelIndex); | 729 DCHECK(dragging_panel_index_ == kInvalidPanelIndex); |
692 DCHECK(panels_in_temporary_layout_.empty()); | 730 DCHECK(panels_in_temporary_layout_.empty()); |
693 | 731 |
694 // Make a copy of the iterator as closing panels can modify the vector. | 732 // Make a copy of the iterator as closing panels can modify the vector. |
695 Panels panels_copy = panels_; | 733 Panels panels_copy = panels_; |
696 | 734 |
697 // Start from the bottom to avoid reshuffling. | 735 // Start from the bottom to avoid reshuffling. |
698 for (Panels::reverse_iterator iter = panels_copy.rbegin(); | 736 for (Panels::reverse_iterator iter = panels_copy.rbegin(); |
699 iter != panels_copy.rend(); ++iter) | 737 iter != panels_copy.rend(); ++iter) |
700 (*iter)->Close(); | 738 (*iter)->Close(); |
701 } | 739 } |
702 | 740 |
703 bool PanelStrip::is_dragging_panel() const { | 741 bool PanelStrip::is_dragging_panel() const { |
704 return dragging_panel_index_ != kInvalidPanelIndex; | 742 return dragging_panel_index_ != kInvalidPanelIndex; |
705 } | 743 } |
OLD | NEW |