Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(391)

Side by Side Diff: chrome/browser/ui/panels/panel_strip.cc

Issue 9195003: Move IN_OVERFLOW from Panel::ExpansionState to new enum. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix per feedback Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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
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());
jennb 2012/01/19 23:44:09 This dcheck may fail. I saw code that called SetEx
jianli 2012/01/20 01:16:07 It will not fail since PanelManager::OnPanelExpans
jennb 2012/01/20 02:01:54 Updating the expansion state (a piece of layout da
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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 // Only need to adjust bounds height when panel is expanded.
435 gfx::Rect bounds = panel->GetBounds(); 466 gfx::Rect bounds = panel->GetBounds();
436 Panel::ExpansionState expansion_state = panel->expansion_state();
437 if (new_height != bounds.height() && 467 if (new_height != bounds.height() &&
438 expansion_state == Panel::EXPANDED) { 468 panel->layout_state() == Panel::DOCKED &&
jennb 2012/01/19 23:44:09 Instead of adding DOCKED checks in this and the ne
jianli 2012/01/20 01:16:07 We also need to call Rearrange if an overflow pane
469 panel->expansion_state() == Panel::EXPANDED) {
439 bounds.set_y(bounds.bottom() - new_height); 470 bounds.set_y(bounds.bottom() - new_height);
440 bounds.set_height(new_height); 471 bounds.set_height(new_height);
441 } 472 }
442 473
443 // Only need to adjust width if panel is in the panel strip. 474 // Only need to adjust width if panel is in the panel strip.
444 int delta_x = bounds.width() - new_width; 475 int delta_x = bounds.width() - new_width;
445 if (delta_x != 0 && expansion_state != Panel::IN_OVERFLOW) { 476 if (delta_x != 0 && panel->layout_state() == Panel::DOCKED) {
446 bounds.set_width(new_width); 477 bounds.set_width(new_width);
447 bounds.set_x(bounds.x() + delta_x); 478 bounds.set_x(bounds.x() + delta_x);
448 } 479 }
449 480
450 if (bounds != panel->GetBounds()) 481 if (bounds != panel->GetBounds())
451 panel->SetPanelBounds(bounds); 482 panel->SetPanelBounds(bounds);
452 483
453 // Only need to rearrange if panel's width changed. 484 // Only need to rearrange if panel's width changed.
454 if (delta_x != 0) 485 if (delta_x != 0)
455 Rearrange(); 486 Rearrange();
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
650 681
651 // TODO(jianli): remove the guard when overflow support is enabled on other 682 // TODO(jianli): remove the guard when overflow support is enabled on other
652 // platforms. http://crbug.com/105073 683 // platforms. http://crbug.com/105073
653 #if defined(OS_WIN) 684 #if defined(OS_WIN)
654 // Add/remove panels from/to overflow. A change in work area or the 685 // 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. 686 // resize/removal of a panel may affect how many panels fit in the strip.
656 if (panel_index < panels_.size()) { 687 if (panel_index < panels_.size()) {
657 // Move panels to overflow in reverse to maintain their order. 688 // Move panels to overflow in reverse to maintain their order.
658 for (size_t overflow_index = panels_.size() - 1; 689 for (size_t overflow_index = panels_.size() - 1;
659 overflow_index >= panel_index; --overflow_index) 690 overflow_index >= panel_index; --overflow_index)
660 panels_[overflow_index]->SetExpansionState(Panel::IN_OVERFLOW); 691 panels_[overflow_index]->SetLayoutState(Panel::IN_OVERFLOW);
661 } else { 692 } else {
662 // Attempt to add more panels from overflow to the strip. 693 // Attempt to add more panels from overflow to the strip.
663 PanelOverflowStrip* overflow_strip = panel_manager_->panel_overflow_strip(); 694 PanelOverflowStrip* overflow_strip = panel_manager_->panel_overflow_strip();
664 Panel* overflow_panel; 695 Panel* overflow_panel;
665 while ((overflow_panel = overflow_strip->first_panel()) && 696 while ((overflow_panel = overflow_strip->first_panel()) &&
666 GetRightMostAvailablePosition() >= 697 GetRightMostAvailablePosition() >=
667 display_area_.x() + overflow_panel->restored_size().width()) { 698 display_area_.x() + overflow_panel->restored_size().width()) {
668 // We need to get back to the previous expansion state. 699 // We need to get back to the previous expansion state.
669 Panel::ExpansionState expansion_state_to_restore = 700 Panel::ExpansionState expansion_state_to_restore =
670 overflow_panel->old_expansion_state(); 701 overflow_panel->expansion_state();
671 if (expansion_state_to_restore == Panel::MINIMIZED || 702 if (expansion_state_to_restore == Panel::MINIMIZED ||
jennb 2012/01/19 23:44:09 Change this to !EXPANDED? Then we don't need two c
jianli 2012/01/20 01:16:07 Done.
672 expansion_state_to_restore == Panel::TITLE_ONLY) { 703 expansion_state_to_restore == Panel::TITLE_ONLY) {
673 expansion_state_to_restore = are_titlebars_up_ ? Panel::TITLE_ONLY 704 expansion_state_to_restore = are_titlebars_up_ ? Panel::TITLE_ONLY
674 : Panel::MINIMIZED; 705 : Panel::MINIMIZED;
675 } 706 }
676 overflow_panel->SetExpansionState(expansion_state_to_restore); 707 overflow_panel->SetExpansionState(expansion_state_to_restore);
708 overflow_panel->SetLayoutState(Panel::DOCKED);
677 } 709 }
678 } 710 }
679 #endif 711 #endif
680 } 712 }
681 713
682 void PanelStrip::DelayedMovePanelToOverflow(Panel* panel) { 714 void PanelStrip::DelayedMovePanelToOverflow(Panel* panel) {
683 if (panels_in_temporary_layout_.erase(panel)) { 715 if (panels_in_temporary_layout_.erase(panel)) {
684 DCHECK(panel->has_temporary_layout()); 716 DCHECK(panel->has_temporary_layout());
685 panel->SetExpansionState(Panel::IN_OVERFLOW); 717 panel->SetLayoutState(Panel::IN_OVERFLOW);
686 } 718 }
687 } 719 }
688 720
689 void PanelStrip::RemoveAll() { 721 void PanelStrip::RemoveAll() {
690 // This should only be called at the end of tests to clean up. 722 // This should only be called at the end of tests to clean up.
691 DCHECK(dragging_panel_index_ == kInvalidPanelIndex); 723 DCHECK(dragging_panel_index_ == kInvalidPanelIndex);
692 DCHECK(panels_in_temporary_layout_.empty()); 724 DCHECK(panels_in_temporary_layout_.empty());
693 725
694 // Make a copy of the iterator as closing panels can modify the vector. 726 // Make a copy of the iterator as closing panels can modify the vector.
695 Panels panels_copy = panels_; 727 Panels panels_copy = panels_;
696 728
697 // Start from the bottom to avoid reshuffling. 729 // Start from the bottom to avoid reshuffling.
698 for (Panels::reverse_iterator iter = panels_copy.rbegin(); 730 for (Panels::reverse_iterator iter = panels_copy.rbegin();
699 iter != panels_copy.rend(); ++iter) 731 iter != panels_copy.rend(); ++iter)
700 (*iter)->Close(); 732 (*iter)->Close();
701 } 733 }
702 734
703 bool PanelStrip::is_dragging_panel() const { 735 bool PanelStrip::is_dragging_panel() const {
704 return dragging_panel_index_ != kInvalidPanelIndex; 736 return dragging_panel_index_ != kInvalidPanelIndex;
705 } 737 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698