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_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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
77 if (panels_.empty() || new_area.width() == old_area.width()) | 77 if (panels_.empty() || new_area.width() == old_area.width()) |
78 return; | 78 return; |
79 | 79 |
80 if (new_area.width() < old_area.width()) | 80 if (new_area.width() < old_area.width()) |
81 Rearrange(); | 81 Rearrange(); |
82 else | 82 else |
83 MovePanelsFromOverflowIfNeeded(); | 83 MovePanelsFromOverflowIfNeeded(); |
84 } | 84 } |
85 | 85 |
86 void PanelStrip::AddPanel(Panel* panel) { | 86 void PanelStrip::AddPanel(Panel* panel) { |
87 if (panel->initialized()) | 87 DCHECK_EQ(Panel::EXPANDED, panel->expansion_state()); |
jianli
2011/12/02 01:56:38
This might not be true if |panel| is overflow pane
jennb
2011/12/02 02:20:37
Removed check for now as your patch will have logi
| |
88 AddExistingPanel(panel); | |
89 else | |
90 AddNewPanel(panel); | |
91 panels_.push_back(panel); | |
92 } | |
93 | 88 |
94 void PanelStrip::AddNewPanel(Panel* panel) { | 89 // Always update limits, even for exiting panels, in case the maximums changed |
95 DCHECK(!panel->initialized()); | 90 // while panel was out of the strip. |
96 | |
97 int max_panel_width = GetMaxPanelWidth(); | 91 int max_panel_width = GetMaxPanelWidth(); |
98 int max_panel_height = GetMaxPanelHeight(); | 92 int max_panel_height = GetMaxPanelHeight(); |
99 panel->SetSizeRange(gfx::Size(kPanelMinWidth, kPanelMinHeight), | 93 panel->SetSizeRange(gfx::Size(kPanelMinWidth, kPanelMinHeight), |
100 gfx::Size(max_panel_width, max_panel_height)); | 94 gfx::Size(max_panel_width, max_panel_height)); |
101 | 95 |
102 gfx::Size restored_size = panel->restored_size(); | 96 gfx::Size restored_size = panel->restored_size(); |
103 int height = restored_size.height(); | 97 int height = restored_size.height(); |
104 int width = restored_size.width(); | 98 int width = restored_size.width(); |
105 | 99 |
106 if (height == 0 && width == 0) { | 100 if (panel->initialized()) { |
107 // Auto resizable is enabled only if no initial size is provided. | 101 // Bump panels in the strip to make room for this panel. |
108 panel->SetAutoResizable(true); | 102 int x; |
103 while ((x = GetRightMostAvailablePosition() - width) < display_area_.x()) { | |
104 DCHECK(!panels_.empty()); | |
105 MovePanelToOverflow(panels_.back(), false); | |
106 } | |
107 int y = display_area_.bottom() - height; | |
108 panel->SetPanelBounds(gfx::Rect(x, y, width, height)); | |
109 } else { | 109 } else { |
110 if (height == 0) | 110 // Initialize the newly created panel. Does not bump any panels from strip. |
111 height = width / kPanelDefaultWidthToHeightRatio; | 111 if (height == 0 && width == 0) { |
112 if (width == 0) | 112 // Auto resizable is enabled only if no initial size is provided. |
113 width = height * kPanelDefaultWidthToHeightRatio; | 113 panel->SetAutoResizable(true); |
114 } else { | |
115 if (height == 0) | |
116 height = width / kPanelDefaultWidthToHeightRatio; | |
117 if (width == 0) | |
118 width = height * kPanelDefaultWidthToHeightRatio; | |
119 } | |
120 | |
121 // Constrain sizes to limits. | |
122 if (width < kPanelMinWidth) | |
123 width = kPanelMinWidth; | |
124 else if (width > max_panel_width) | |
125 width = max_panel_width; | |
126 | |
127 if (height < kPanelMinHeight) | |
128 height = kPanelMinHeight; | |
129 else if (height > max_panel_height) | |
130 height = max_panel_height; | |
131 | |
132 panel->set_restored_size(gfx::Size(width, height)); | |
133 int x = GetRightMostAvailablePosition() - width; | |
134 int y = display_area_.bottom() - height; | |
135 | |
136 // Keep panel visible in the strip even if overlap would occur. | |
137 // Panel is moved to overflow from the strip after a delay. | |
138 if (x < display_area_.x()) { | |
139 x = display_area_.x(); | |
140 MessageLoop::current()->PostDelayedTask( | |
141 FROM_HERE, | |
142 base::Bind(&PanelStrip::MovePanelToOverflow, | |
143 overflow_action_factory_.GetWeakPtr(), | |
dcheng
2011/12/02 01:29:20
It may be better to remove the WeakPtrFactory for
jennb
2011/12/02 02:20:37
Done.
| |
144 panel, | |
145 true), // new panel | |
146 kMoveNewPanelToOverflowDelayMilliseconds); | |
jianli
2011/12/02 01:56:38
Can you check remove_delays_for_testing_ here and
jennb
2011/12/02 02:20:37
Done.
| |
147 } | |
148 panel->Initialize(gfx::Rect(x, y, width, height)); | |
114 } | 149 } |
115 | 150 |
116 // Constrain sizes to limits. | 151 panels_.push_back(panel); |
117 if (width < kPanelMinWidth) | |
118 width = kPanelMinWidth; | |
119 else if (width > max_panel_width) | |
120 width = max_panel_width; | |
121 | |
122 if (height < kPanelMinHeight) | |
123 height = kPanelMinHeight; | |
124 else if (height > max_panel_height) | |
125 height = max_panel_height; | |
126 panel->set_restored_size(gfx::Size(width, height)); | |
127 | |
128 // Layout the new panel. | |
129 int y = display_area_.bottom() - height; | |
130 int x = GetRightMostAvailablePosition() - width; | |
131 | |
132 // Keep panel visible in the strip even if overlap would occur. | |
133 // Panel is moved to overflow from the strip after a delay. | |
134 if (x < display_area_.x()) { | |
135 x = display_area_.x(); | |
136 MessageLoop::current()->PostDelayedTask( | |
137 FROM_HERE, | |
138 base::Bind(&PanelStrip::MovePanelToOverflow, | |
139 overflow_action_factory_.GetWeakPtr(), | |
140 panel, | |
141 true), // new panel | |
142 kMoveNewPanelToOverflowDelayMilliseconds); | |
143 } | |
144 panel->Initialize(gfx::Rect(x, y, width, height)); | |
145 } | |
146 | |
147 void PanelStrip::AddExistingPanel(Panel* panel) { | |
148 gfx::Size restored_size = panel->restored_size(); | |
149 int height = restored_size.height(); | |
150 int width = restored_size.width(); | |
151 int x; | |
152 while ((x = GetRightMostAvailablePosition() - width) < display_area_.x()) { | |
153 DCHECK(!panels_.empty()); | |
154 MovePanelToOverflow(panels_.back(), false); | |
155 } | |
156 int y = display_area_.bottom() - height; | |
157 panel->SetPanelBounds(gfx::Rect(x, y, width, height)); | |
158 } | 152 } |
159 | 153 |
160 int PanelStrip::GetMaxPanelWidth() const { | 154 int PanelStrip::GetMaxPanelWidth() const { |
161 return static_cast<int>(display_area_.width() * kPanelMaxWidthFactor); | 155 return static_cast<int>(display_area_.width() * kPanelMaxWidthFactor); |
162 } | 156 } |
163 | 157 |
164 int PanelStrip::GetMaxPanelHeight() const { | 158 int PanelStrip::GetMaxPanelHeight() const { |
165 return display_area_.height(); | 159 return display_area_.height(); |
166 } | 160 } |
167 | 161 |
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
628 | 622 |
629 // Start from the bottom to avoid reshuffling. | 623 // Start from the bottom to avoid reshuffling. |
630 for (Panels::reverse_iterator iter = panels_copy.rbegin(); | 624 for (Panels::reverse_iterator iter = panels_copy.rbegin(); |
631 iter != panels_copy.rend(); ++iter) | 625 iter != panels_copy.rend(); ++iter) |
632 (*iter)->Close(); | 626 (*iter)->Close(); |
633 } | 627 } |
634 | 628 |
635 bool PanelStrip::is_dragging_panel() const { | 629 bool PanelStrip::is_dragging_panel() const { |
636 return dragging_panel_index_ != kInvalidPanelIndex; | 630 return dragging_panel_index_ != kInvalidPanelIndex; |
637 } | 631 } |
OLD | NEW |