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" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
13 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
14 #include "chrome/browser/ui/panels/overflow_panel_strip.h" | |
15 #include "chrome/browser/ui/panels/panel_drag_controller.h" | |
14 #include "chrome/browser/ui/panels/panel_manager.h" | 16 #include "chrome/browser/ui/panels/panel_manager.h" |
15 #include "chrome/browser/ui/panels/panel_mouse_watcher.h" | 17 #include "chrome/browser/ui/panels/panel_mouse_watcher.h" |
16 #include "chrome/common/chrome_notification_types.h" | 18 #include "chrome/common/chrome_notification_types.h" |
17 #include "content/public/browser/notification_service.h" | 19 #include "content/public/browser/notification_service.h" |
18 #include "content/public/browser/notification_source.h" | 20 #include "content/public/browser/notification_source.h" |
19 | 21 |
20 namespace { | 22 namespace { |
21 // Width to height ratio is used to compute the default width or height | 23 // Width to height ratio is used to compute the default width or height |
22 // when only one value is provided. | 24 // when only one value is provided. |
23 const double kPanelDefaultWidthToHeightRatio = 1.62; // golden ratio | 25 const double kPanelDefaultWidthToHeightRatio = 1.62; // golden ratio |
(...skipping 29 matching lines...) Expand all Loading... | |
53 const int DockedPanelStrip::kPanelMinWidth = 100; | 55 const int DockedPanelStrip::kPanelMinWidth = 100; |
54 const int DockedPanelStrip::kPanelMinHeight = 20; | 56 const int DockedPanelStrip::kPanelMinHeight = 20; |
55 | 57 |
56 DockedPanelStrip::DockedPanelStrip(PanelManager* panel_manager) | 58 DockedPanelStrip::DockedPanelStrip(PanelManager* panel_manager) |
57 : PanelStrip(PanelStrip::DOCKED), | 59 : PanelStrip(PanelStrip::DOCKED), |
58 panel_manager_(panel_manager), | 60 panel_manager_(panel_manager), |
59 minimized_panel_count_(0), | 61 minimized_panel_count_(0), |
60 are_titlebars_up_(false), | 62 are_titlebars_up_(false), |
61 delayed_titlebar_action_(NO_ACTION), | 63 delayed_titlebar_action_(NO_ACTION), |
62 titlebar_action_factory_(this) { | 64 titlebar_action_factory_(this) { |
63 dragging_panel_current_iterator_ = dragging_panel_original_iterator_ = | 65 dragging_panel_current_iterator_ = panels_.end(); |
64 panels_.end(); | |
65 } | 66 } |
66 | 67 |
67 DockedPanelStrip::~DockedPanelStrip() { | 68 DockedPanelStrip::~DockedPanelStrip() { |
68 DCHECK(panels_.empty()); | 69 DCHECK(panels_.empty()); |
69 DCHECK(panels_in_temporary_layout_.empty()); | 70 DCHECK(panels_in_temporary_layout_.empty()); |
70 DCHECK_EQ(0, minimized_panel_count_); | 71 DCHECK_EQ(0, minimized_panel_count_); |
71 } | 72 } |
72 | 73 |
73 void DockedPanelStrip::SetDisplayArea(const gfx::Rect& display_area) { | 74 void DockedPanelStrip::SetDisplayArea(const gfx::Rect& display_area) { |
74 if (display_area_ == display_area) | 75 if (display_area_ == display_area) |
75 return; | 76 return; |
76 | 77 |
77 gfx::Rect old_area = display_area_; | 78 gfx::Rect old_area = display_area_; |
78 display_area_ = display_area; | 79 display_area_ = display_area; |
79 | 80 |
80 if (panels_.empty()) | 81 if (panels_.empty()) |
81 return; | 82 return; |
82 | 83 |
83 RefreshLayout(); | 84 RefreshLayout(); |
84 } | 85 } |
85 | 86 |
86 void DockedPanelStrip::AddPanel(Panel* panel) { | 87 void DockedPanelStrip::AddPanel(Panel* panel) { |
87 DCHECK_NE(this, panel->panel_strip()); | 88 DCHECK_NE(this, panel->panel_strip()); |
88 panel->set_panel_strip(this); | 89 panel->set_panel_strip(this); |
89 | 90 |
91 if (panel->initialized()) { | |
jennb
2012/03/08 23:41:09
if (panel !initialized)
insert newly created
els
jianli
2012/03/09 21:48:58
Done.
| |
92 if (panel->in_preview_mode()) | |
93 InsertPreviewedPanel(panel); | |
94 else | |
95 InsertExistingPanel(panel); | |
96 } else { | |
97 InsertNewlyCreatedPanel(panel); | |
98 } | |
99 | |
90 // Always update limits, even on existing panels, in case the limits changed | 100 // Always update limits, even on existing panels, in case the limits changed |
91 // while panel was out of the strip. | 101 // while panel was out of the strip. |
92 int max_panel_width = GetMaxPanelWidth(); | 102 int max_panel_width = GetMaxPanelWidth(); |
93 int max_panel_height = GetMaxPanelHeight(); | 103 int max_panel_height = GetMaxPanelHeight(); |
94 panel->SetSizeRange(gfx::Size(kPanelMinWidth, kPanelMinHeight), | 104 panel->SetSizeRange(gfx::Size(kPanelMinWidth, kPanelMinHeight), |
95 gfx::Size(max_panel_width, max_panel_height)); | 105 gfx::Size(max_panel_width, max_panel_height)); |
96 | 106 |
107 panel->SetAppIconVisibility(true); | |
108 panel->SetAlwaysOnTop(true); | |
109 } | |
110 | |
111 | |
jennb
2012/03/08 23:41:09
Extra blank line.
jianli
2012/03/09 21:48:58
Done.
| |
112 void DockedPanelStrip::InsertPreviewedPanel(Panel* panel) { | |
113 DCHECK(panel->initialized() && panel->in_preview_mode()); | |
114 | |
115 FitPanelWithWidth(panel->GetBounds().width()); | |
116 | |
117 int x = panel->GetBounds().x(); | |
118 Panels::iterator iter = panels_.begin(); | |
119 for (; iter != panels_.end(); ++iter) | |
120 if (x > (*iter)->GetBounds().x()) | |
121 break; | |
122 panels_.insert(iter, panel); | |
123 | |
124 // This will automatically update all affected panels due to the insertion. | |
125 if (iter != panels_.end()) | |
126 RefreshLayout(); | |
127 } | |
128 | |
129 void DockedPanelStrip::InsertExistingPanel(Panel* panel) { | |
130 DCHECK(panel->initialized() && !panel->in_preview_mode()); | |
131 | |
97 gfx::Size restored_size = panel->restored_size(); | 132 gfx::Size restored_size = panel->restored_size(); |
98 int height = restored_size.height(); | 133 int height = restored_size.height(); |
99 int width = restored_size.width(); | 134 int width = restored_size.width(); |
100 | 135 |
101 if (panel->initialized()) { | 136 int x = FitPanelWithWidth(width); |
102 int x = FitPanelWithWidth(width); | |
103 | 137 |
104 Panel::ExpansionState expansion_state_to_restore; | 138 Panel::ExpansionState expansion_state_to_restore; |
105 if (panel->expansion_state() == Panel::EXPANDED) { | 139 if (panel->expansion_state() == Panel::EXPANDED) { |
106 expansion_state_to_restore = Panel::EXPANDED; | 140 expansion_state_to_restore = Panel::EXPANDED; |
141 } else { | |
142 if (are_titlebars_up_ || panel->IsDrawingAttention()) { | |
143 expansion_state_to_restore = Panel::TITLE_ONLY; | |
144 height = panel->TitleOnlyHeight(); | |
107 } else { | 145 } else { |
108 if (are_titlebars_up_ || panel->IsDrawingAttention()) { | 146 expansion_state_to_restore = Panel::MINIMIZED; |
109 expansion_state_to_restore = Panel::TITLE_ONLY; | 147 height = Panel::kMinimizedPanelHeight; |
110 height = panel->TitleOnlyHeight(); | |
111 } else { | |
112 expansion_state_to_restore = Panel::MINIMIZED; | |
113 height = Panel::kMinimizedPanelHeight; | |
114 } | |
115 IncrementMinimizedPanels(); | |
116 } | 148 } |
117 int y = | 149 IncrementMinimizedPanels(); |
118 GetBottomPositionForExpansionState(expansion_state_to_restore) - height; | 150 } |
119 panel->SetPanelBounds(gfx::Rect(x, y, width, height)); | 151 int y = |
152 GetBottomPositionForExpansionState(expansion_state_to_restore) - height; | |
153 panel->SetPanelBounds(gfx::Rect(x, y, width, height)); | |
120 | 154 |
121 // Update the minimized state to reflect current titlebar mode. | 155 // Update the minimized state to reflect current titlebar mode. |
122 // Do this AFTER setting panel bounds to avoid an extra bounds change. | 156 // Do this AFTER setting panel bounds to avoid an extra bounds change. |
123 if (panel->expansion_state() != Panel::EXPANDED) | 157 if (panel->expansion_state() != Panel::EXPANDED) |
124 panel->SetExpansionState(expansion_state_to_restore); | 158 panel->SetExpansionState(expansion_state_to_restore); |
125 | 159 |
160 panels_.push_back(panel); | |
161 } | |
162 | |
163 void DockedPanelStrip::InsertNewlyCreatedPanel(Panel* panel) { | |
164 DCHECK(!panel->initialized()); | |
165 | |
166 int max_panel_width = GetMaxPanelWidth(); | |
167 int max_panel_height = GetMaxPanelHeight(); | |
168 gfx::Size restored_size = panel->restored_size(); | |
169 int height = restored_size.height(); | |
170 int width = restored_size.width(); | |
171 | |
172 // Initialize the newly created panel. Does not bump any panels from strip. | |
173 if (height == 0 && width == 0 && panel_manager_->auto_sizing_enabled()) { | |
174 // Auto resizable is enabled only if no initial size is provided. | |
175 panel->SetAutoResizable(true); | |
126 } else { | 176 } else { |
127 // Initialize the newly created panel. Does not bump any panels from strip. | 177 if (height == 0) |
128 if (height == 0 && width == 0 && panel_manager_->auto_sizing_enabled()) { | 178 height = width / kPanelDefaultWidthToHeightRatio; |
129 // Auto resizable is enabled only if no initial size is provided. | 179 if (width == 0) |
130 panel->SetAutoResizable(true); | 180 width = height * kPanelDefaultWidthToHeightRatio; |
131 } else { | |
132 if (height == 0) | |
133 height = width / kPanelDefaultWidthToHeightRatio; | |
134 if (width == 0) | |
135 width = height * kPanelDefaultWidthToHeightRatio; | |
136 } | |
137 | |
138 // Constrain sizes to limits. | |
139 if (width < kPanelMinWidth) | |
140 width = kPanelMinWidth; | |
141 else if (width > max_panel_width) | |
142 width = max_panel_width; | |
143 | |
144 if (height < kPanelMinHeight) | |
145 height = kPanelMinHeight; | |
146 else if (height > max_panel_height) | |
147 height = max_panel_height; | |
148 | |
149 panel->set_restored_size(gfx::Size(width, height)); | |
150 int x = GetRightMostAvailablePosition() - width; | |
151 int y = display_area_.bottom() - height; | |
152 | |
153 // Keep panel visible in the strip even if overlap would occur. | |
154 // Panel is moved to overflow from the strip after a delay. | |
155 if (x < display_area_.x()) { | |
156 x = display_area_.x(); | |
157 panel->set_has_temporary_layout(true); | |
158 MessageLoop::current()->PostDelayedTask( | |
159 FROM_HERE, | |
160 base::Bind(&DockedPanelStrip::DelayedMovePanelToOverflow, | |
161 base::Unretained(this), | |
162 panel), | |
163 base::TimeDelta::FromMilliseconds(PanelManager::AdjustTimeInterval( | |
164 kMoveNewPanelToOverflowDelayMs))); | |
165 } | |
166 panel->Initialize(gfx::Rect(x, y, width, height)); | |
167 } | 181 } |
168 | 182 |
169 // Set panel properties for this strip. | 183 // Constrain sizes to limits. |
170 panel->SetAppIconVisibility(true); | 184 if (width < kPanelMinWidth) |
185 width = kPanelMinWidth; | |
186 else if (width > max_panel_width) | |
187 width = max_panel_width; | |
188 | |
189 if (height < kPanelMinHeight) | |
190 height = kPanelMinHeight; | |
191 else if (height > max_panel_height) | |
192 height = max_panel_height; | |
193 | |
194 panel->set_restored_size(gfx::Size(width, height)); | |
195 int x = GetRightMostAvailablePosition() - width; | |
196 int y = display_area_.bottom() - height; | |
197 | |
198 // Keep panel visible in the strip even if overlap would occur. | |
199 // Panel is moved to overflow from the strip after a delay. | |
200 if (x < display_area_.x()) { | |
201 x = display_area_.x(); | |
202 panel->set_has_temporary_layout(true); | |
203 MessageLoop::current()->PostDelayedTask( | |
204 FROM_HERE, | |
205 base::Bind(&DockedPanelStrip::DelayedMovePanelToOverflow, | |
206 base::Unretained(this), | |
207 panel), | |
208 base::TimeDelta::FromMilliseconds(PanelManager::AdjustTimeInterval( | |
209 kMoveNewPanelToOverflowDelayMs))); | |
210 } | |
211 panel->Initialize(gfx::Rect(x, y, width, height)); | |
171 | 212 |
172 if (panel->has_temporary_layout()) | 213 if (panel->has_temporary_layout()) |
173 panels_in_temporary_layout_.insert(panel); | 214 panels_in_temporary_layout_.insert(panel); |
174 else | 215 else |
175 panels_.push_back(panel); | 216 panels_.push_back(panel); |
176 } | 217 } |
177 | 218 |
178 int DockedPanelStrip::GetMaxPanelWidth() const { | 219 int DockedPanelStrip::GetMaxPanelWidth() const { |
179 return static_cast<int>(display_area_.width() * kPanelMaxWidthFactor); | 220 return static_cast<int>(display_area_.width() * kPanelMaxWidthFactor); |
180 } | 221 } |
(...skipping 20 matching lines...) Expand all Loading... | |
201 | 242 |
202 if (panel->has_temporary_layout()) { | 243 if (panel->has_temporary_layout()) { |
203 panels_in_temporary_layout_.erase(panel); | 244 panels_in_temporary_layout_.erase(panel); |
204 return; | 245 return; |
205 } | 246 } |
206 | 247 |
207 // Removing an element from the list will invalidate the iterator that refers | 248 // Removing an element from the list will invalidate the iterator that refers |
208 // to it. We need to update the iterator in that case. | 249 // to it. We need to update the iterator in that case. |
209 DCHECK(dragging_panel_current_iterator_ == panels_.end() || | 250 DCHECK(dragging_panel_current_iterator_ == panels_.end() || |
210 *dragging_panel_current_iterator_ != panel); | 251 *dragging_panel_current_iterator_ != panel); |
211 bool update_iterator_after_erase = | |
212 (dragging_panel_original_iterator_ != panels_.end() && | |
213 *dragging_panel_original_iterator_ == panel); | |
214 | 252 |
215 // Optimize for the common case of removing the last panel. | 253 // Optimize for the common case of removing the last panel. |
216 DCHECK(!panels_.empty()); | 254 DCHECK(!panels_.empty()); |
217 if (panels_.back() == panel) { | 255 if (panels_.back() == panel) { |
218 panels_.pop_back(); | 256 panels_.pop_back(); |
219 if (update_iterator_after_erase) | 257 |
220 dragging_panel_original_iterator_ = panels_.end(); | 258 // Update the saved panel placement if needed. This is because we might remove |
259 // |saved_panel_placement_.left_panel_|. | |
260 // Note: if |left_panel_| moves to overflow and then comes back, it is OK to | |
261 // restore the panel to the end of list since we do not want to deal with | |
262 // this case specially. | |
263 if (saved_panel_placement_.panel && | |
264 saved_panel_placement_.left_panel_ == panel) | |
265 saved_panel_placement_.left_panel_ = NULL; | |
266 | |
221 // No need to refresh layout as the remaining panels are unaffected. | 267 // No need to refresh layout as the remaining panels are unaffected. |
222 // Just check if other panels can now fit in the freed up space. | 268 // Just check if other panels can now fit in the freed up space. |
223 panel_manager_->MovePanelsOutOfOverflowIfCanFit(); | 269 panel_manager_->MovePanelsOutOfOverflowIfCanFit(); |
224 } else { | 270 } else { |
225 Panels::iterator iter = find(panels_.begin(), panels_.end(), panel); | 271 Panels::iterator iter = find(panels_.begin(), panels_.end(), panel); |
226 DCHECK(iter != panels_.end()); | 272 DCHECK(iter != panels_.end()); |
227 iter = panels_.erase(iter); | 273 iter = panels_.erase(iter); |
228 if (update_iterator_after_erase) | 274 |
229 dragging_panel_original_iterator_ = iter; | 275 // Update the saved panel placement if needed. This is because we might remove |
276 // |saved_panel_placement_.left_panel_|. | |
277 if (saved_panel_placement_.panel && | |
278 saved_panel_placement_.left_panel_ == panel) | |
279 saved_panel_placement_.left_panel_ = *iter; | |
280 | |
230 RefreshLayout(); | 281 RefreshLayout(); |
231 } | 282 } |
232 } | 283 } |
233 | 284 |
234 bool DockedPanelStrip::CanShowPanelAsActive(const Panel* panel) const { | 285 bool DockedPanelStrip::CanShowPanelAsActive(const Panel* panel) const { |
235 // Panels with temporary layout cannot be shown as active. | 286 // Panels with temporary layout cannot be shown as active. |
236 return !panel->has_temporary_layout(); | 287 return !panel->has_temporary_layout(); |
237 } | 288 } |
238 | 289 |
290 void DockedPanelStrip::SavePanelPlacement(Panel* panel) { | |
291 DCHECK(!saved_panel_placement_.panel); | |
292 | |
293 saved_panel_placement_.panel = panel; | |
294 | |
295 // To recover panel to its original placement, we only need to track the panel | |
296 // that is placed after it. | |
297 Panels::iterator iter = find(panels_.begin(), panels_.end(), panel); | |
298 DCHECK(iter != panels_.end()); | |
299 ++iter; | |
300 saved_panel_placement_.left_panel_ = | |
301 (iter == panels_.end()) ? NULL : *iter; | |
302 } | |
303 | |
304 void DockedPanelStrip::RestorePanelToSavedPlacement() { | |
305 DCHECK(saved_panel_placement_.panel); | |
306 | |
307 Panel* panel = saved_panel_placement_.panel; | |
308 | |
309 // Find next panel after this panel. | |
310 Panels::iterator iter = std::find(panels_.begin(), panels_.end(), panel); | |
311 DCHECK(iter != panels_.end()); | |
312 Panels::iterator next_iter = iter; | |
313 next_iter++; | |
314 Panel* next_panel = (next_iter == panels_.end()) ? NULL : *iter; | |
315 | |
316 // If this panel is already in the right position, nothing to do. | |
jennb
2012/03/08 23:41:09
nit: rephrase the if-comment to match the if-condi
jianli
2012/03/09 21:48:58
Done.
| |
317 if (next_panel != saved_panel_placement_.left_panel_) { | |
318 // Remove this panel from its current position. | |
319 panels_.erase(iter); | |
320 | |
321 // Insert this panel into its previous position. | |
322 if (saved_panel_placement_.left_panel_) { | |
323 Panels::iterator iter_to_insert_before = std::find(panels_.begin(), | |
324 panels_.end(), saved_panel_placement_.left_panel_); | |
325 DCHECK(iter_to_insert_before != panels_.end()); | |
326 panels_.insert(iter_to_insert_before, panel); | |
327 } else { | |
328 panels_.push_back(panel); | |
329 } | |
330 } | |
331 | |
332 RefreshLayout(); | |
333 | |
334 DiscardSavedPanelPlacement(); | |
335 } | |
336 | |
337 void DockedPanelStrip::DiscardSavedPanelPlacement() { | |
338 DCHECK(saved_panel_placement_.panel); | |
339 saved_panel_placement_.panel = NULL; | |
jennb
2012/03/08 23:41:09
Should clear out saved pointer to left_panel too.
jianli
2012/03/09 21:48:58
Done.
| |
340 } | |
341 | |
239 bool DockedPanelStrip::CanDragPanel(const Panel* panel) const { | 342 bool DockedPanelStrip::CanDragPanel(const Panel* panel) const { |
240 // Only the panels having temporary layout can't be dragged. | 343 // Only the panels having temporary layout can't be dragged. |
241 return !panel->has_temporary_layout(); | 344 return !panel->has_temporary_layout(); |
242 } | 345 } |
243 | 346 |
244 Panel* DockedPanelStrip::dragging_panel() const { | 347 void DockedPanelStrip::StartDraggingPanelWithinStrip(Panel* panel) { |
245 return dragging_panel_current_iterator_ == panels_.end() ? NULL : | |
246 *dragging_panel_current_iterator_; | |
247 } | |
248 | |
249 void DockedPanelStrip::StartDraggingPanel(Panel* panel) { | |
250 dragging_panel_current_iterator_ = | 348 dragging_panel_current_iterator_ = |
251 find(panels_.begin(), panels_.end(), panel); | 349 find(panels_.begin(), panels_.end(), panel); |
252 DCHECK(dragging_panel_current_iterator_ != panels_.end()); | 350 DCHECK(dragging_panel_current_iterator_ != panels_.end()); |
253 dragging_panel_original_iterator_ = dragging_panel_current_iterator_; | |
254 } | 351 } |
255 | 352 |
256 void DockedPanelStrip::DragPanel(Panel* panel, int delta_x, int delta_y) { | 353 void DockedPanelStrip::DragPanelWithinStrip(Panel* panel, |
354 int delta_x, | |
355 int delta_y) { | |
257 if (!delta_x) | 356 if (!delta_x) |
258 return; | 357 return; |
259 | 358 |
260 // Moves this panel to the dragging position. | 359 // Moves this panel to the dragging position. |
261 gfx::Rect new_bounds(panel->GetBounds()); | 360 gfx::Rect new_bounds(panel->GetBounds()); |
262 new_bounds.set_x(new_bounds.x() + delta_x); | 361 new_bounds.set_x(new_bounds.x() + delta_x); |
263 panel->SetPanelBounds(new_bounds); | 362 panel->SetPanelBounds(new_bounds); |
264 | 363 |
265 // Checks and processes other affected panels. | 364 // Checks and processes other affected panels. |
266 if (delta_x > 0) | 365 if (delta_x > 0) |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
319 break; | 418 break; |
320 | 419 |
321 // Swaps the contents and makes |dragging_panel_current_iterator_| refers | 420 // Swaps the contents and makes |dragging_panel_current_iterator_| refers |
322 // to the new position. | 421 // to the new position. |
323 *dragging_panel_current_iterator_ = current_panel; | 422 *dragging_panel_current_iterator_ = current_panel; |
324 *current_panel_iterator = dragging_panel; | 423 *current_panel_iterator = dragging_panel; |
325 dragging_panel_current_iterator_ = current_panel_iterator; | 424 dragging_panel_current_iterator_ = current_panel_iterator; |
326 } | 425 } |
327 } | 426 } |
328 | 427 |
329 void DockedPanelStrip::EndDraggingPanel(Panel* panel, bool cancelled) { | 428 void DockedPanelStrip::EndDraggingPanelWithinStrip(Panel* panel, bool aborted) { |
330 if (cancelled) { | 429 dragging_panel_current_iterator_ = panels_.end(); |
jennb
2012/03/08 23:41:09
Shame that you lose this iterator right before you
jianli
2012/03/09 21:48:58
Not sure I understand this comment. I want to sepa
| |
331 if (dragging_panel_current_iterator_ != dragging_panel_original_iterator_) { | |
332 // Find out if the dragging panel should be moved toward the end/beginning | |
333 // of the list. | |
334 bool move_towards_end_of_list = true; | |
335 for (Panels::iterator iter = dragging_panel_original_iterator_; | |
336 iter != panels_.end(); ++iter) { | |
337 if (iter == dragging_panel_current_iterator_) { | |
338 move_towards_end_of_list = false; | |
339 break; | |
340 } | |
341 } | |
342 | 430 |
343 // Move the dragging panel back to its original position by swapping it | 431 // Calls RefreshLayout to update the dragging panel to its final position |
344 // with its adjacent element until it reach its original position. | 432 // when the drag ends normally. Otherwise, the drag within this strip is |
345 while (dragging_panel_current_iterator_ != | 433 // aborted because either the drag enters other strip or the drag is |
346 dragging_panel_original_iterator_) { | 434 // cancelled. Either way, we don't need to do anything here and let the drag |
347 Panels::iterator next_iter = dragging_panel_current_iterator_; | 435 // controller handle the inter-strip transition or the drag cancellation. |
348 if (move_towards_end_of_list) | 436 if (!aborted) |
349 ++next_iter; | 437 RefreshLayout(); |
350 else | |
351 --next_iter; | |
352 iter_swap(dragging_panel_current_iterator_, next_iter); | |
353 dragging_panel_current_iterator_ = next_iter; | |
354 } | |
355 } | |
356 } | |
357 | |
358 dragging_panel_current_iterator_ = dragging_panel_original_iterator_ = | |
359 panels_.end(); | |
360 | |
361 RefreshLayout(); | |
362 } | 438 } |
363 | 439 |
364 void DockedPanelStrip::OnPanelExpansionStateChanged(Panel* panel) { | 440 void DockedPanelStrip::OnPanelExpansionStateChanged(Panel* panel) { |
365 gfx::Size size = panel->restored_size(); | 441 gfx::Size size = panel->restored_size(); |
366 Panel::ExpansionState expansion_state = panel->expansion_state(); | 442 Panel::ExpansionState expansion_state = panel->expansion_state(); |
367 Panel::ExpansionState old_state = panel->old_expansion_state(); | 443 Panel::ExpansionState old_state = panel->old_expansion_state(); |
368 switch (expansion_state) { | 444 switch (expansion_state) { |
369 case Panel::EXPANDED: | 445 case Panel::EXPANDED: |
370 if (old_state == Panel::TITLE_ONLY || old_state == Panel::MINIMIZED) | 446 if (old_state == Panel::TITLE_ONLY || old_state == Panel::MINIMIZED) |
371 DecrementMinimizedPanels(); | 447 DecrementMinimizedPanels(); |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
517 for (Panels::const_iterator iter = panels_.begin(); | 593 for (Panels::const_iterator iter = panels_.begin(); |
518 iter != panels_.end(); ++iter) { | 594 iter != panels_.end(); ++iter) { |
519 Panel* panel = *iter; | 595 Panel* panel = *iter; |
520 Panel::ExpansionState state = panel->expansion_state(); | 596 Panel::ExpansionState state = panel->expansion_state(); |
521 // Skip the expanded panel. | 597 // Skip the expanded panel. |
522 if (state == Panel::EXPANDED) | 598 if (state == Panel::EXPANDED) |
523 continue; | 599 continue; |
524 | 600 |
525 // If the panel is showing titlebar only, we want to keep it up when it is | 601 // If the panel is showing titlebar only, we want to keep it up when it is |
526 // being dragged. | 602 // being dragged. |
527 if (state == Panel::TITLE_ONLY && panel == dragging_panel()) | 603 if (state == Panel::TITLE_ONLY && panel->in_preview_mode()) |
jennb
2012/03/08 23:41:09
Keep old code here? It's obvious you want to leave
jianli
2012/03/09 21:48:58
Done.
| |
528 return true; | 604 return true; |
529 | 605 |
530 // We do not want to bring up other minimized panels if the mouse is over | 606 // We do not want to bring up other minimized panels if the mouse is over |
531 // the panel that pops up the titlebar to attract attention. | 607 // the panel that pops up the titlebar to attract attention. |
532 if (panel->IsDrawingAttention()) | 608 if (panel->IsDrawingAttention()) |
533 continue; | 609 continue; |
534 | 610 |
535 gfx::Rect bounds = panel->GetBounds(); | 611 gfx::Rect bounds = panel->GetBounds(); |
536 if (bounds.x() <= mouse_x && mouse_x <= bounds.right() && | 612 if (bounds.x() <= mouse_x && mouse_x <= bounds.right() && |
537 mouse_y >= bounds.y()) | 613 mouse_y >= bounds.y()) |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
710 | 786 |
711 Panels::const_iterator panel_iter = panels_.begin(); | 787 Panels::const_iterator panel_iter = panels_.begin(); |
712 for (; panel_iter != panels_.end(); ++panel_iter) { | 788 for (; panel_iter != panels_.end(); ++panel_iter) { |
713 Panel* panel = *panel_iter; | 789 Panel* panel = *panel_iter; |
714 gfx::Rect new_bounds(panel->GetBounds()); | 790 gfx::Rect new_bounds(panel->GetBounds()); |
715 int x = rightmost_position - new_bounds.width(); | 791 int x = rightmost_position - new_bounds.width(); |
716 | 792 |
717 if (x < display_area_.x()) | 793 if (x < display_area_.x()) |
718 break; | 794 break; |
719 | 795 |
720 // Don't update the docked panel that is currently dragged. | 796 // Don't update the docked panel that is in preview mode. |
721 if (panel != dragging_panel()) { | 797 if (!panel->in_preview_mode()) { |
722 new_bounds.set_x(x); | 798 new_bounds.set_x(x); |
723 new_bounds.set_y( | 799 new_bounds.set_y( |
724 GetBottomPositionForExpansionState(panel->expansion_state()) - | 800 GetBottomPositionForExpansionState(panel->expansion_state()) - |
725 new_bounds.height()); | 801 new_bounds.height()); |
726 panel->SetPanelBounds(new_bounds); | 802 panel->SetPanelBounds(new_bounds); |
727 } | 803 } |
728 | 804 |
729 rightmost_position = x - kPanelsHorizontalSpacing; | 805 rightmost_position = x - kPanelsHorizontalSpacing; |
730 } | 806 } |
731 | 807 |
732 // Add/remove panels from/to overflow. A change in work area or the | 808 // Add/remove panels from/to overflow. A change in work area or the |
733 // resize/removal of a panel may affect how many panels fit in the strip. | 809 // resize/removal of a panel may affect how many panels fit in the strip. |
810 // TODO(jianli): Need to handle the case that panel in preview mode could be | |
jennb
2012/03/08 23:41:09
crbug this and reference bug # here pls.
jianli
2012/03/09 21:48:58
Done.
| |
811 // moved to overflow. | |
734 if (panel_iter != panels_.end()) | 812 if (panel_iter != panels_.end()) |
735 panel_manager_->MovePanelsToOverflow(*panel_iter); | 813 panel_manager_->MovePanelsToOverflow(*panel_iter); |
736 else | 814 else |
737 panel_manager_->MovePanelsOutOfOverflowIfCanFit(); | 815 panel_manager_->MovePanelsOutOfOverflowIfCanFit(); |
738 } | 816 } |
739 | 817 |
740 void DockedPanelStrip::DelayedMovePanelToOverflow(Panel* panel) { | 818 void DockedPanelStrip::DelayedMovePanelToOverflow(Panel* panel) { |
741 if (panels_in_temporary_layout_.erase(panel)) { | 819 if (panels_in_temporary_layout_.erase(panel)) { |
742 DCHECK(panel->has_temporary_layout()); | 820 DCHECK(panel->has_temporary_layout()); |
743 panel_manager_->MovePanelToStrip(panel, PanelStrip::IN_OVERFLOW); | 821 panel_manager_->MovePanelToStrip(panel, PanelStrip::IN_OVERFLOW); |
744 } | 822 } |
745 } | 823 } |
746 | 824 |
747 void DockedPanelStrip::CloseAll() { | 825 void DockedPanelStrip::CloseAll() { |
748 // This should only be called at the end of tests to clean up. | 826 // This should only be called at the end of tests to clean up. |
749 DCHECK(panels_in_temporary_layout_.empty()); | 827 DCHECK(panels_in_temporary_layout_.empty()); |
750 | 828 |
751 // Make a copy of the iterator as closing panels can modify the vector. | 829 // Make a copy of the iterator as closing panels can modify the vector. |
752 Panels panels_copy = panels_; | 830 Panels panels_copy = panels_; |
753 | 831 |
754 // Start from the bottom to avoid reshuffling. | 832 // Start from the bottom to avoid reshuffling. |
755 for (Panels::reverse_iterator iter = panels_copy.rbegin(); | 833 for (Panels::reverse_iterator iter = panels_copy.rbegin(); |
756 iter != panels_copy.rend(); ++iter) | 834 iter != panels_copy.rend(); ++iter) |
757 (*iter)->Close(); | 835 (*iter)->Close(); |
758 } | 836 } |
OLD | NEW |