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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 int x = GetRightMostAvailablePosition() - width; | 117 int x = GetRightMostAvailablePosition() - width; |
118 panel->Initialize(gfx::Rect(x, y, width, height)); | 118 panel->Initialize(gfx::Rect(x, y, width, height)); |
119 } | 119 } |
120 | 120 |
121 void PanelStrip::AddExistingPanel(Panel* panel) { | 121 void PanelStrip::AddExistingPanel(Panel* panel) { |
122 gfx::Size restored_size = panel->restored_size(); | 122 gfx::Size restored_size = panel->restored_size(); |
123 int height = restored_size.height(); | 123 int height = restored_size.height(); |
124 int width = restored_size.width(); | 124 int width = restored_size.width(); |
125 int x = GetRightMostAvailablePosition() - width; | 125 int x = GetRightMostAvailablePosition() - width; |
126 int y = strip_bounds_.bottom() - height; | 126 int y = strip_bounds_.bottom() - height; |
127 panel->SetPanelBounds(gfx::Rect(x, y, width, height)); | 127 panel->SetPanelBounds(gfx::Rect(x, y, width, height), |
| 128 true); // use animation. |
128 } | 129 } |
129 | 130 |
130 int PanelStrip::GetMaxPanelWidth() const { | 131 int PanelStrip::GetMaxPanelWidth() const { |
131 return static_cast<int>(strip_bounds_.width() * kPanelMaxWidthFactor); | 132 return static_cast<int>(strip_bounds_.width() * kPanelMaxWidthFactor); |
132 } | 133 } |
133 | 134 |
134 int PanelStrip::GetMaxPanelHeight() const { | 135 int PanelStrip::GetMaxPanelHeight() const { |
135 return strip_bounds_.height(); | 136 return strip_bounds_.height(); |
136 } | 137 } |
137 | 138 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 void PanelStrip::Drag(int delta_x) { | 192 void PanelStrip::Drag(int delta_x) { |
192 DCHECK(dragging_panel_index_ != kInvalidPanelIndex); | 193 DCHECK(dragging_panel_index_ != kInvalidPanelIndex); |
193 | 194 |
194 if (!delta_x) | 195 if (!delta_x) |
195 return; | 196 return; |
196 | 197 |
197 // Moves this panel to the dragging position. | 198 // Moves this panel to the dragging position. |
198 Panel* dragging_panel = panels_[dragging_panel_index_]; | 199 Panel* dragging_panel = panels_[dragging_panel_index_]; |
199 gfx::Rect new_bounds(dragging_panel->GetBounds()); | 200 gfx::Rect new_bounds(dragging_panel->GetBounds()); |
200 new_bounds.set_x(new_bounds.x() + delta_x); | 201 new_bounds.set_x(new_bounds.x() + delta_x); |
201 dragging_panel->SetPanelBounds(new_bounds); | 202 dragging_panel->SetPanelBounds(new_bounds, true); // use animation. |
202 | 203 |
203 // Checks and processes other affected panels. | 204 // Checks and processes other affected panels. |
204 if (delta_x > 0) | 205 if (delta_x > 0) |
205 DragRight(); | 206 DragRight(); |
206 else | 207 else |
207 DragLeft(); | 208 DragLeft(); |
208 } | 209 } |
209 | 210 |
210 void PanelStrip::DragLeft() { | 211 void PanelStrip::DragLeft() { |
211 Panel* dragging_panel = panels_[dragging_panel_index_]; | 212 Panel* dragging_panel = panels_[dragging_panel_index_]; |
(...skipping 14 matching lines...) Expand all Loading... |
226 // Current panel will only be affected if the left corner of dragging | 227 // Current panel will only be affected if the left corner of dragging |
227 // panel goes beyond the middle position of the current panel. | 228 // panel goes beyond the middle position of the current panel. |
228 if (dragging_panel_left_boundary > current_panel->GetBounds().x() + | 229 if (dragging_panel_left_boundary > current_panel->GetBounds().x() + |
229 current_panel->GetBounds().width() / 2) | 230 current_panel->GetBounds().width() / 2) |
230 break; | 231 break; |
231 | 232 |
232 // Moves current panel to the new position. | 233 // Moves current panel to the new position. |
233 gfx::Rect bounds(current_panel->GetBounds()); | 234 gfx::Rect bounds(current_panel->GetBounds()); |
234 bounds.set_x(current_panel_right_boundary - bounds.width()); | 235 bounds.set_x(current_panel_right_boundary - bounds.width()); |
235 current_panel_right_boundary -= bounds.width() + kPanelsHorizontalSpacing; | 236 current_panel_right_boundary -= bounds.width() + kPanelsHorizontalSpacing; |
236 current_panel->SetPanelBounds(bounds); | 237 current_panel->SetPanelBounds(bounds, true); // use animation. |
237 | 238 |
238 // Updates the index of current panel since it has been moved to the | 239 // Updates the index of current panel since it has been moved to the |
239 // position of previous panel. | 240 // position of previous panel. |
240 panels_[current_panel_index - 1] = current_panel; | 241 panels_[current_panel_index - 1] = current_panel; |
241 } | 242 } |
242 | 243 |
243 // Updates the position and index of dragging panel as the result of moving | 244 // Updates the position and index of dragging panel as the result of moving |
244 // other affected panels. | 245 // other affected panels. |
245 if (current_panel_index != dragging_panel_index_ + 1) { | 246 if (current_panel_index != dragging_panel_index_ + 1) { |
246 dragging_panel_bounds_.set_x(current_panel_right_boundary - | 247 dragging_panel_bounds_.set_x(current_panel_right_boundary - |
(...skipping 22 matching lines...) Expand all Loading... |
269 // Current panel will only be affected if the right corner of dragging | 270 // Current panel will only be affected if the right corner of dragging |
270 // panel goes beyond the middle position of the current panel. | 271 // panel goes beyond the middle position of the current panel. |
271 if (dragging_panel_right_boundary < current_panel->GetBounds().x() + | 272 if (dragging_panel_right_boundary < current_panel->GetBounds().x() + |
272 current_panel->GetBounds().width() / 2) | 273 current_panel->GetBounds().width() / 2) |
273 break; | 274 break; |
274 | 275 |
275 // Moves current panel to the new position. | 276 // Moves current panel to the new position. |
276 gfx::Rect bounds(current_panel->GetBounds()); | 277 gfx::Rect bounds(current_panel->GetBounds()); |
277 bounds.set_x(current_panel_left_boundary); | 278 bounds.set_x(current_panel_left_boundary); |
278 current_panel_left_boundary += bounds.width() + kPanelsHorizontalSpacing; | 279 current_panel_left_boundary += bounds.width() + kPanelsHorizontalSpacing; |
279 current_panel->SetPanelBounds(bounds); | 280 current_panel->SetPanelBounds(bounds, true); // use animation. |
280 | 281 |
281 // Updates the index of current panel since it has been moved to the | 282 // Updates the index of current panel since it has been moved to the |
282 // position of previous panel. | 283 // position of previous panel. |
283 panels_[current_panel_index + 1] = current_panel; | 284 panels_[current_panel_index + 1] = current_panel; |
284 } | 285 } |
285 | 286 |
286 // Updates the position and index of dragging panel as the result of moving | 287 // Updates the position and index of dragging panel as the result of moving |
287 // other affected panels. | 288 // other affected panels. |
288 if (current_panel_index != static_cast<int>(dragging_panel_index_) - 1) { | 289 if (current_panel_index != static_cast<int>(dragging_panel_index_) - 1) { |
289 dragging_panel_bounds_.set_x(current_panel_left_boundary); | 290 dragging_panel_bounds_.set_x(current_panel_left_boundary); |
290 dragging_panel_index_ = current_panel_index + 1; | 291 dragging_panel_index_ = current_panel_index + 1; |
291 panels_[dragging_panel_index_] = dragging_panel; | 292 panels_[dragging_panel_index_] = dragging_panel; |
292 } | 293 } |
293 } | 294 } |
294 | 295 |
295 void PanelStrip::EndDragging(bool cancelled) { | 296 void PanelStrip::EndDragging(bool cancelled) { |
296 DCHECK(dragging_panel_index_ != kInvalidPanelIndex); | 297 DCHECK(dragging_panel_index_ != kInvalidPanelIndex); |
297 | 298 |
298 if (cancelled) { | 299 if (cancelled) { |
299 Drag(dragging_panel_original_x_ - | 300 Drag(dragging_panel_original_x_ - |
300 panels_[dragging_panel_index_]->GetBounds().x()); | 301 panels_[dragging_panel_index_]->GetBounds().x()); |
301 } else { | 302 } else { |
302 panels_[dragging_panel_index_]->SetPanelBounds( | 303 panels_[dragging_panel_index_]->SetPanelBounds( |
303 dragging_panel_bounds_); | 304 dragging_panel_bounds_, true); // use animation. |
304 } | 305 } |
305 | 306 |
306 dragging_panel_index_ = kInvalidPanelIndex; | 307 dragging_panel_index_ = kInvalidPanelIndex; |
307 | 308 |
308 DelayedRemove(); | 309 DelayedRemove(); |
309 } | 310 } |
310 | 311 |
311 void PanelStrip::OnPanelExpansionStateChanged( | 312 void PanelStrip::OnPanelExpansionStateChanged( |
312 Panel::ExpansionState old_state, Panel::ExpansionState new_state) { | 313 Panel::ExpansionState old_state, Panel::ExpansionState new_state) { |
313 DCHECK_NE(new_state, old_state); | 314 DCHECK_NE(new_state, old_state); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 if (panels_[i] == panel) { | 363 if (panels_[i] == panel) { |
363 panel_index = i; | 364 panel_index = i; |
364 break; | 365 break; |
365 } | 366 } |
366 } | 367 } |
367 DCHECK(panel_index >= 0); | 368 DCHECK(panel_index >= 0); |
368 for (int i = static_cast<int>(panels_.size()) -1; i > panel_index; | 369 for (int i = static_cast<int>(panels_.size()) -1; i > panel_index; |
369 --i) { | 370 --i) { |
370 gfx::Rect this_bounds = panels_[i]->GetBounds(); | 371 gfx::Rect this_bounds = panels_[i]->GetBounds(); |
371 this_bounds.set_x(this_bounds.x() + delta); | 372 this_bounds.set_x(this_bounds.x() + delta); |
372 panels_[i]->SetPanelBounds(this_bounds); | 373 panels_[i]->SetPanelBounds(this_bounds, true); // use animation. |
373 } | 374 } |
374 } | 375 } |
375 | 376 |
376 // The panel height: | 377 // The panel height: |
377 // * cannot grow or shrink to go beyond [min_height, max_height] | 378 // * cannot grow or shrink to go beyond [min_height, max_height] |
378 int new_height = preferred_window_size.height(); | 379 int new_height = preferred_window_size.height(); |
379 if (new_height > panel->max_size().height()) | 380 if (new_height > panel->max_size().height()) |
380 new_height = panel->max_size().height(); | 381 new_height = panel->max_size().height(); |
381 if (new_height < panel->min_size().height()) | 382 if (new_height < panel->min_size().height()) |
382 new_height = panel->min_size().height(); | 383 new_height = panel->min_size().height(); |
383 | 384 |
384 // Only need to adjust bounds height when panel is expanded. | 385 // Only need to adjust bounds height when panel is expanded. |
385 gfx::Size restored_size = panel->restored_size(); | 386 gfx::Size restored_size = panel->restored_size(); |
386 if (new_height != restored_size.height() && | 387 if (new_height != restored_size.height() && |
387 panel->expansion_state() == Panel::EXPANDED) { | 388 panel->expansion_state() == Panel::EXPANDED) { |
388 bounds.set_y(bounds.y() - new_height + bounds.height()); | 389 bounds.set_y(bounds.y() - new_height + bounds.height()); |
389 bounds.set_height(new_height); | 390 bounds.set_height(new_height); |
390 } | 391 } |
391 | 392 |
392 gfx::Size new_size = gfx::Size(new_width, new_height); | 393 gfx::Size new_size = gfx::Size(new_width, new_height); |
393 if (new_size != restored_size) | 394 if (new_size != restored_size) |
394 panel->set_restored_size(new_size); | 395 panel->set_restored_size(new_size); |
395 | 396 |
396 panel->SetPanelBounds(bounds); | 397 panel->SetPanelBounds(bounds, true); // use animation. |
397 } | 398 } |
398 | 399 |
399 bool PanelStrip::ShouldBringUpTitlebars(int mouse_x, int mouse_y) const { | 400 bool PanelStrip::ShouldBringUpTitlebars(int mouse_x, int mouse_y) const { |
400 // We should always bring up the titlebar if the mouse is over the | 401 // We should always bring up the titlebar if the mouse is over the |
401 // visible auto-hiding bottom bar. | 402 // visible auto-hiding bottom bar. |
402 AutoHidingDesktopBar* desktop_bar = panel_manager_->auto_hiding_desktop_bar(); | 403 AutoHidingDesktopBar* desktop_bar = panel_manager_->auto_hiding_desktop_bar(); |
403 if (desktop_bar->IsEnabled(AutoHidingDesktopBar::ALIGN_BOTTOM) && | 404 if (desktop_bar->IsEnabled(AutoHidingDesktopBar::ALIGN_BOTTOM) && |
404 desktop_bar->GetVisibility(AutoHidingDesktopBar::ALIGN_BOTTOM) == | 405 desktop_bar->GetVisibility(AutoHidingDesktopBar::ALIGN_BOTTOM) == |
405 AutoHidingDesktopBar::VISIBLE && | 406 AutoHidingDesktopBar::VISIBLE && |
406 mouse_y >= strip_bounds_.bottom()) | 407 mouse_y >= strip_bounds_.bottom()) |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
547 | 548 |
548 void PanelStrip::Rearrange(Panels::iterator iter_to_start, | 549 void PanelStrip::Rearrange(Panels::iterator iter_to_start, |
549 int rightmost_position) { | 550 int rightmost_position) { |
550 for (Panels::iterator iter = iter_to_start; iter != panels_.end(); ++iter) { | 551 for (Panels::iterator iter = iter_to_start; iter != panels_.end(); ++iter) { |
551 Panel* panel = *iter; | 552 Panel* panel = *iter; |
552 gfx::Rect new_bounds(panel->GetBounds()); | 553 gfx::Rect new_bounds(panel->GetBounds()); |
553 new_bounds.set_x(rightmost_position - new_bounds.width()); | 554 new_bounds.set_x(rightmost_position - new_bounds.width()); |
554 new_bounds.set_y( | 555 new_bounds.set_y( |
555 GetBottomPositionForExpansionState(panel->expansion_state()) - | 556 GetBottomPositionForExpansionState(panel->expansion_state()) - |
556 new_bounds.height()); | 557 new_bounds.height()); |
557 panel->SetPanelBounds(new_bounds); | 558 panel->SetPanelBounds(new_bounds, true); // use animation. |
558 | 559 |
559 rightmost_position = new_bounds.x() - kPanelsHorizontalSpacing; | 560 rightmost_position = new_bounds.x() - kPanelsHorizontalSpacing; |
560 } | 561 } |
561 } | 562 } |
562 | 563 |
563 void PanelStrip::RemoveAll() { | 564 void PanelStrip::RemoveAll() { |
564 // This should not be called when we're in the process of dragging. | 565 // This should not be called when we're in the process of dragging. |
565 DCHECK(dragging_panel_index_ == kInvalidPanelIndex); | 566 DCHECK(dragging_panel_index_ == kInvalidPanelIndex); |
566 | 567 |
567 // Make a copy of the iterator as closing panels can modify the vector. | 568 // Make a copy of the iterator as closing panels can modify the vector. |
568 Panels panels_copy = panels_; | 569 Panels panels_copy = panels_; |
569 | 570 |
570 // Start from the bottom to avoid reshuffling. | 571 // Start from the bottom to avoid reshuffling. |
571 for (Panels::reverse_iterator iter = panels_copy.rbegin(); | 572 for (Panels::reverse_iterator iter = panels_copy.rbegin(); |
572 iter != panels_copy.rend(); ++iter) | 573 iter != panels_copy.rend(); ++iter) |
573 (*iter)->Close(); | 574 (*iter)->Close(); |
574 } | 575 } |
575 | 576 |
576 bool PanelStrip::is_dragging_panel() const { | 577 bool PanelStrip::is_dragging_panel() const { |
577 return dragging_panel_index_ != kInvalidPanelIndex; | 578 return dragging_panel_index_ != kInvalidPanelIndex; |
578 } | 579 } |
OLD | NEW |