| 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_collection.h" | 5 #include "chrome/browser/ui/panels/docked_panel_collection.h" |
| 6 | 6 |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 } else { | 106 } else { |
| 107 DCHECK(update_bounds); | 107 DCHECK(update_bounds); |
| 108 int x = panel->GetBounds().x(); | 108 int x = panel->GetBounds().x(); |
| 109 Panels::iterator iter = panels_.begin(); | 109 Panels::iterator iter = panels_.begin(); |
| 110 for (; iter != panels_.end(); ++iter) | 110 for (; iter != panels_.end(); ++iter) |
| 111 if (x > (*iter)->GetBounds().x()) | 111 if (x > (*iter)->GetBounds().x()) |
| 112 break; | 112 break; |
| 113 panels_.insert(iter, panel); | 113 panels_.insert(iter, panel); |
| 114 } | 114 } |
| 115 | 115 |
| 116 if (update_bounds) { | 116 if (update_bounds) |
| 117 if ((positioning_mask & DELAY_LAYOUT_REFRESH) != 0) | 117 RefreshLayout(); |
| 118 ScheduleLayoutRefresh(); | |
| 119 else | |
| 120 RefreshLayout(); | |
| 121 } | |
| 122 } | 118 } |
| 123 | 119 |
| 124 gfx::Point DockedPanelCollection::GetDefaultPositionForPanel( | 120 gfx::Point DockedPanelCollection::GetDefaultPositionForPanel( |
| 125 const gfx::Size& full_size) const { | 121 const gfx::Size& full_size) const { |
| 126 int x = 0; | 122 int x = 0; |
| 127 if (!panels_.empty() && | 123 if (!panels_.empty() && |
| 128 panels_.back()->GetBounds().x() < work_area_.x()) { | 124 panels_.back()->GetBounds().x() < work_area_.x()) { |
| 129 // Panels go off screen. Make sure the default position will place | 125 // Panels go off screen. Make sure the default position will place |
| 130 // the panel in view. | 126 // the panel in view. |
| 131 Panels::const_reverse_iterator iter = panels_.rbegin(); | 127 Panels::const_reverse_iterator iter = panels_.rbegin(); |
| (...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 759 } | 755 } |
| 760 | 756 |
| 761 void DockedPanelCollection::UpdatePanelOnCollectionChange(Panel* panel) { | 757 void DockedPanelCollection::UpdatePanelOnCollectionChange(Panel* panel) { |
| 762 panel->set_attention_mode(Panel::USE_PANEL_ATTENTION); | 758 panel->set_attention_mode(Panel::USE_PANEL_ATTENTION); |
| 763 panel->SetAlwaysOnTop(true); | 759 panel->SetAlwaysOnTop(true); |
| 764 panel->EnableResizeByMouse(true); | 760 panel->EnableResizeByMouse(true); |
| 765 panel->UpdateMinimizeRestoreButtonVisibility(); | 761 panel->UpdateMinimizeRestoreButtonVisibility(); |
| 766 panel->SetWindowCornerStyle(panel::TOP_ROUNDED); | 762 panel->SetWindowCornerStyle(panel::TOP_ROUNDED); |
| 767 } | 763 } |
| 768 | 764 |
| 769 void DockedPanelCollection::ScheduleLayoutRefresh() { | |
| 770 refresh_action_factory_.InvalidateWeakPtrs(); | |
| 771 MessageLoop::current()->PostDelayedTask(FROM_HERE, | |
| 772 base::Bind(&DockedPanelCollection::RefreshLayout, | |
| 773 refresh_action_factory_.GetWeakPtr()), | |
| 774 base::TimeDelta::FromMilliseconds(PanelManager::AdjustTimeInterval( | |
| 775 kRefreshLayoutAfterActivePanelChangeDelayMs))); | |
| 776 } | |
| 777 | |
| 778 void DockedPanelCollection::OnPanelActiveStateChanged(Panel* panel) { | 765 void DockedPanelCollection::OnPanelActiveStateChanged(Panel* panel) { |
| 779 // Refresh layout, but wait till active states settle. | 766 RefreshLayout(); |
| 780 // This lets us avoid refreshing too many times when one panel loses | |
| 781 // focus and another gains it. | |
| 782 ScheduleLayoutRefresh(); | |
| 783 } | 767 } |
| 784 | 768 |
| 785 bool DockedPanelCollection::HasPanel(Panel* panel) const { | 769 bool DockedPanelCollection::HasPanel(Panel* panel) const { |
| 786 return find(panels_.begin(), panels_.end(), panel) != panels_.end(); | 770 return find(panels_.begin(), panels_.end(), panel) != panels_.end(); |
| 787 } | 771 } |
| OLD | NEW |