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

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

Issue 8772029: Reunite PanelStrip::AddPanel and its internals. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: re-enable NoOverlapping test Created 9 years 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
« no previous file with comments | « chrome/browser/ui/panels/panel_strip.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 const int PanelStrip::kPanelMinHeight = 20; 50 const int PanelStrip::kPanelMinHeight = 20;
51 51
52 PanelStrip::PanelStrip(PanelManager* panel_manager) 52 PanelStrip::PanelStrip(PanelManager* panel_manager)
53 : panel_manager_(panel_manager), 53 : panel_manager_(panel_manager),
54 minimized_panel_count_(0), 54 minimized_panel_count_(0),
55 are_titlebars_up_(false), 55 are_titlebars_up_(false),
56 dragging_panel_index_(kInvalidPanelIndex), 56 dragging_panel_index_(kInvalidPanelIndex),
57 dragging_panel_original_x_(0), 57 dragging_panel_original_x_(0),
58 delayed_titlebar_action_(NO_ACTION), 58 delayed_titlebar_action_(NO_ACTION),
59 remove_delays_for_testing_(false), 59 remove_delays_for_testing_(false),
60 titlebar_action_factory_(this), 60 titlebar_action_factory_(this) {
61 overflow_action_factory_(this) {
62 } 61 }
63 62
64 PanelStrip::~PanelStrip() { 63 PanelStrip::~PanelStrip() {
65 DCHECK(panels_.empty()); 64 DCHECK(panels_.empty());
66 DCHECK(panels_pending_to_remove_.empty()); 65 DCHECK(panels_pending_to_remove_.empty());
67 DCHECK_EQ(0, minimized_panel_count_); 66 DCHECK_EQ(0, minimized_panel_count_);
68 } 67 }
69 68
70 void PanelStrip::SetDisplayArea(const gfx::Rect& new_area) { 69 void PanelStrip::SetDisplayArea(const gfx::Rect& new_area) {
71 if (display_area_ == new_area) 70 if (display_area_ == new_area)
72 return; 71 return;
73 72
74 gfx::Rect old_area = display_area_; 73 gfx::Rect old_area = display_area_;
75 display_area_ = new_area; 74 display_area_ = new_area;
76 75
77 if (panels_.empty() || new_area.width() == old_area.width()) 76 if (panels_.empty() || new_area.width() == old_area.width())
78 return; 77 return;
79 78
80 if (new_area.width() < old_area.width()) 79 if (new_area.width() < old_area.width())
81 Rearrange(); 80 Rearrange();
82 else 81 else
83 MovePanelsFromOverflowIfNeeded(); 82 MovePanelsFromOverflowIfNeeded();
84 } 83 }
85 84
86 void PanelStrip::AddPanel(Panel* panel) { 85 void PanelStrip::AddPanel(Panel* panel) {
87 if (panel->initialized()) 86 // Always update limits, even for exiting panels, in case the maximums changed
88 AddExistingPanel(panel); 87 // while panel was out of the strip.
89 else
90 AddNewPanel(panel);
91 panels_.push_back(panel);
92 }
93
94 void PanelStrip::AddNewPanel(Panel* panel) {
95 DCHECK(!panel->initialized());
96
97 int max_panel_width = GetMaxPanelWidth(); 88 int max_panel_width = GetMaxPanelWidth();
98 int max_panel_height = GetMaxPanelHeight(); 89 int max_panel_height = GetMaxPanelHeight();
99 panel->SetSizeRange(gfx::Size(kPanelMinWidth, kPanelMinHeight), 90 panel->SetSizeRange(gfx::Size(kPanelMinWidth, kPanelMinHeight),
100 gfx::Size(max_panel_width, max_panel_height)); 91 gfx::Size(max_panel_width, max_panel_height));
101 92
102 gfx::Size restored_size = panel->restored_size(); 93 gfx::Size restored_size = panel->restored_size();
103 int height = restored_size.height(); 94 int height = restored_size.height();
104 int width = restored_size.width(); 95 int width = restored_size.width();
105 96
106 if (height == 0 && width == 0) { 97 if (panel->initialized()) {
107 // Auto resizable is enabled only if no initial size is provided. 98 // Bump panels in the strip to make room for this panel.
108 panel->SetAutoResizable(true); 99 int x;
100 while ((x = GetRightMostAvailablePosition() - width) < display_area_.x()) {
101 DCHECK(!panels_.empty());
102 MovePanelToOverflow(panels_.back(), false);
103 }
104 int y = display_area_.bottom() - height;
105 panel->SetPanelBounds(gfx::Rect(x, y, width, height));
109 } else { 106 } else {
110 if (height == 0) 107 // Initialize the newly created panel. Does not bump any panels from strip.
111 height = width / kPanelDefaultWidthToHeightRatio; 108 if (height == 0 && width == 0) {
112 if (width == 0) 109 // Auto resizable is enabled only if no initial size is provided.
113 width = height * kPanelDefaultWidthToHeightRatio; 110 panel->SetAutoResizable(true);
111 } else {
112 if (height == 0)
113 height = width / kPanelDefaultWidthToHeightRatio;
114 if (width == 0)
115 width = height * kPanelDefaultWidthToHeightRatio;
116 }
117
118 // Constrain sizes to limits.
119 if (width < kPanelMinWidth)
120 width = kPanelMinWidth;
121 else if (width > max_panel_width)
122 width = max_panel_width;
123
124 if (height < kPanelMinHeight)
125 height = kPanelMinHeight;
126 else if (height > max_panel_height)
127 height = max_panel_height;
128
129 panel->set_restored_size(gfx::Size(width, height));
130 int x = GetRightMostAvailablePosition() - width;
131 int y = display_area_.bottom() - height;
132
133 // Keep panel visible in the strip even if overlap would occur.
134 // Panel is moved to overflow from the strip after a delay.
135 if (x < display_area_.x()) {
136 x = display_area_.x();
137 int delay_ms = remove_delays_for_testing_ ? 0 :
138 kMoveNewPanelToOverflowDelayMilliseconds;
139 MessageLoop::current()->PostDelayedTask(
140 FROM_HERE,
141 base::Bind(&PanelStrip::MovePanelToOverflow,
142 base::Unretained(this),
143 panel,
144 true), // new panel
145 delay_ms);
146 }
147 panel->Initialize(gfx::Rect(x, y, width, height));
114 } 148 }
115 149
116 // Constrain sizes to limits. 150 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 } 151 }
159 152
160 int PanelStrip::GetMaxPanelWidth() const { 153 int PanelStrip::GetMaxPanelWidth() const {
161 return static_cast<int>(display_area_.width() * kPanelMaxWidthFactor); 154 return static_cast<int>(display_area_.width() * kPanelMaxWidthFactor);
162 } 155 }
163 156
164 int PanelStrip::GetMaxPanelHeight() const { 157 int PanelStrip::GetMaxPanelHeight() const {
165 return display_area_.height(); 158 return display_area_.height();
166 } 159 }
167 160
(...skipping 30 matching lines...) Expand all
198 191
199 bool PanelStrip::DoRemove(Panel* panel) { 192 bool PanelStrip::DoRemove(Panel* panel) {
200 Panels::iterator iter = find(panels_.begin(), panels_.end(), panel); 193 Panels::iterator iter = find(panels_.begin(), panels_.end(), panel);
201 if (iter == panels_.end()) 194 if (iter == panels_.end())
202 return false; 195 return false;
203 196
204 if (panel->expansion_state() != Panel::EXPANDED) 197 if (panel->expansion_state() != Panel::EXPANDED)
205 DecrementMinimizedPanels(); 198 DecrementMinimizedPanels();
206 199
207 panels_.erase(iter); 200 panels_.erase(iter);
201 panel_manager_->OnPanelRemoved(panel);
208 return true; 202 return true;
209 } 203 }
210 204
211 void PanelStrip::StartDragging(Panel* panel) { 205 void PanelStrip::StartDragging(Panel* panel) {
212 for (size_t i = 0; i < panels_.size(); ++i) { 206 for (size_t i = 0; i < panels_.size(); ++i) {
213 if (panels_[i] == panel) { 207 if (panels_[i] == panel) {
214 dragging_panel_index_ = i; 208 dragging_panel_index_ = i;
215 dragging_panel_bounds_ = panel->GetBounds(); 209 dragging_panel_bounds_ = panel->GetBounds();
216 dragging_panel_original_x_ = dragging_panel_bounds_.x(); 210 dragging_panel_original_x_ = dragging_panel_bounds_.x();
217 break; 211 break;
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/panels/panel_strip.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698