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

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

Issue 9699036: Fix handling of minimized panel count (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: comment Created 8 years, 9 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
« no previous file with comments | « chrome/browser/ui/panels/docked_panel_strip.h ('k') | chrome/browser/ui/panels/panel.h » ('j') | 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) 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"
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 DCHECK(panel->initialized()); 173 DCHECK(panel->initialized());
174 174
175 FitPanelWithWidth(panel->GetBounds().width()); 175 FitPanelWithWidth(panel->GetBounds().width());
176 176
177 int x = panel->GetBounds().x(); 177 int x = panel->GetBounds().x();
178 Panels::iterator iter = panels_.begin(); 178 Panels::iterator iter = panels_.begin();
179 for (; iter != panels_.end(); ++iter) 179 for (; iter != panels_.end(); ++iter)
180 if (x > (*iter)->GetBounds().x()) 180 if (x > (*iter)->GetBounds().x())
181 break; 181 break;
182 panels_.insert(iter, panel); 182 panels_.insert(iter, panel);
183 UpdateMinimizedPanelCount();
183 184
184 // This will automatically update all affected panels due to the insertion. 185 // This will automatically update all affected panels due to the insertion.
185 if (iter != panels_.end()) 186 if (iter != panels_.end())
186 RefreshLayout(); 187 RefreshLayout();
187 } 188 }
188 189
189 void DockedPanelStrip::InsertExistingPanelAtDefaultPosition( 190 void DockedPanelStrip::InsertExistingPanelAtDefaultPosition(
190 Panel* panel, bool update_bounds) { 191 Panel* panel, bool update_bounds) {
191 DCHECK(panel->initialized()); 192 DCHECK(panel->initialized());
192 193
193 gfx::Size restored_size = panel->restored_size(); 194 gfx::Size restored_size = panel->restored_size();
194 int height = restored_size.height(); 195 int height = restored_size.height();
195 int width = restored_size.width(); 196 int width = restored_size.width();
196 197
197 int x = FitPanelWithWidth(width); 198 int x = FitPanelWithWidth(width);
198
199 if (update_bounds) { 199 if (update_bounds) {
200 Panel::ExpansionState expansion_state_to_restore; 200 Panel::ExpansionState expansion_state_to_restore;
201 if (panel->expansion_state() == Panel::EXPANDED) { 201 if (panel->expansion_state() == Panel::EXPANDED) {
202 expansion_state_to_restore = Panel::EXPANDED; 202 expansion_state_to_restore = Panel::EXPANDED;
203 } else { 203 } else {
204 if (are_titlebars_up_ || panel->IsDrawingAttention()) { 204 if (are_titlebars_up_ || panel->IsDrawingAttention()) {
205 expansion_state_to_restore = Panel::TITLE_ONLY; 205 expansion_state_to_restore = Panel::TITLE_ONLY;
206 height = panel->TitleOnlyHeight(); 206 height = panel->TitleOnlyHeight();
207 } else { 207 } else {
208 expansion_state_to_restore = Panel::MINIMIZED; 208 expansion_state_to_restore = Panel::MINIMIZED;
209 height = Panel::kMinimizedPanelHeight; 209 height = Panel::kMinimizedPanelHeight;
210 } 210 }
211 IncrementMinimizedPanels();
212 } 211 }
213 int y = 212 int y =
214 GetBottomPositionForExpansionState(expansion_state_to_restore) - height; 213 GetBottomPositionForExpansionState(expansion_state_to_restore) - height;
215 panel->SetPanelBounds(gfx::Rect(x, y, width, height)); 214 panel->SetPanelBounds(gfx::Rect(x, y, width, height));
216 215
217 // Update the minimized state to reflect current titlebar mode. 216 // Update the minimized state to reflect current titlebar mode.
218 // Do this AFTER setting panel bounds to avoid an extra bounds change. 217 // Do this AFTER setting panel bounds to avoid an extra bounds change.
219 if (panel->expansion_state() != Panel::EXPANDED) 218 if (panel->expansion_state() != Panel::EXPANDED)
220 panel->SetExpansionState(expansion_state_to_restore); 219 panel->SetExpansionState(expansion_state_to_restore);
221 } 220 }
222 221
223 panels_.push_back(panel); 222 panels_.push_back(panel);
223 UpdateMinimizedPanelCount();
224 } 224 }
225 225
226 int DockedPanelStrip::GetMaxPanelWidth() const { 226 int DockedPanelStrip::GetMaxPanelWidth() const {
227 return static_cast<int>(display_area_.width() * kPanelMaxWidthFactor); 227 return static_cast<int>(display_area_.width() * kPanelMaxWidthFactor);
228 } 228 }
229 229
230 int DockedPanelStrip::GetMaxPanelHeight() const { 230 int DockedPanelStrip::GetMaxPanelHeight() const {
231 return display_area_.height(); 231 return display_area_.height();
232 } 232 }
233 233
234 int DockedPanelStrip::StartingRightPosition() const { 234 int DockedPanelStrip::StartingRightPosition() const {
235 return display_area_.right(); 235 return display_area_.right();
236 } 236 }
237 237
238 int DockedPanelStrip::GetRightMostAvailablePosition() const { 238 int DockedPanelStrip::GetRightMostAvailablePosition() const {
239 return panels_.empty() ? StartingRightPosition() : 239 return panels_.empty() ? StartingRightPosition() :
240 (panels_.back()->GetBounds().x() - kPanelsHorizontalSpacing); 240 (panels_.back()->GetBounds().x() - kPanelsHorizontalSpacing);
241 } 241 }
242 242
243 void DockedPanelStrip::RemovePanel(Panel* panel) { 243 void DockedPanelStrip::RemovePanel(Panel* panel) {
244 DCHECK_EQ(this, panel->panel_strip()); 244 DCHECK_EQ(this, panel->panel_strip());
245 panel->SetPanelStrip(NULL); 245 panel->SetPanelStrip(NULL);
246 246
247 if (panel->expansion_state() != Panel::EXPANDED)
248 DecrementMinimizedPanels();
249
250 if (panel->has_temporary_layout()) { 247 if (panel->has_temporary_layout()) {
251 panels_in_temporary_layout_.erase(panel); 248 panels_in_temporary_layout_.erase(panel);
252 return; 249 return;
253 } 250 }
254 251
255 // Removing an element from the list will invalidate the iterator that refers 252 // Removing an element from the list will invalidate the iterator that refers
256 // to it. We need to update the iterator in that case. 253 // to it. We need to update the iterator in that case.
257 DCHECK(dragging_panel_current_iterator_ == panels_.end() || 254 DCHECK(dragging_panel_current_iterator_ == panels_.end() ||
258 *dragging_panel_current_iterator_ != panel); 255 *dragging_panel_current_iterator_ != panel);
259 256
(...skipping 20 matching lines...) Expand all
280 iter = panels_.erase(iter); 277 iter = panels_.erase(iter);
281 278
282 // Update the saved panel placement if needed. This is because we might remove 279 // Update the saved panel placement if needed. This is because we might remove
283 // |saved_panel_placement_.left_panel|. 280 // |saved_panel_placement_.left_panel|.
284 if (saved_panel_placement_.panel && 281 if (saved_panel_placement_.panel &&
285 saved_panel_placement_.left_panel == panel) 282 saved_panel_placement_.left_panel == panel)
286 saved_panel_placement_.left_panel = *iter; 283 saved_panel_placement_.left_panel = *iter;
287 284
288 RefreshLayout(); 285 RefreshLayout();
289 } 286 }
287
288 if (panel->expansion_state() != Panel::EXPANDED)
289 UpdateMinimizedPanelCount();
290 } 290 }
291 291
292 bool DockedPanelStrip::CanShowPanelAsActive(const Panel* panel) const { 292 bool DockedPanelStrip::CanShowPanelAsActive(const Panel* panel) const {
293 // Panels with temporary layout cannot be shown as active. 293 // Panels with temporary layout cannot be shown as active.
294 return !panel->has_temporary_layout(); 294 return !panel->has_temporary_layout();
295 } 295 }
296 296
297 void DockedPanelStrip::SavePanelPlacement(Panel* panel) { 297 void DockedPanelStrip::SavePanelPlacement(Panel* panel) {
298 DCHECK(!saved_panel_placement_.panel); 298 DCHECK(!saved_panel_placement_.panel);
299 299
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 // aborted because either the drag enters other strip or the drag is 440 // aborted because either the drag enters other strip or the drag is
441 // cancelled. Either way, we don't need to do anything here and let the drag 441 // cancelled. Either way, we don't need to do anything here and let the drag
442 // controller handle the inter-strip transition or the drag cancellation. 442 // controller handle the inter-strip transition or the drag cancellation.
443 if (!aborted) 443 if (!aborted)
444 RefreshLayout(); 444 RefreshLayout();
445 } 445 }
446 446
447 void DockedPanelStrip::OnPanelExpansionStateChanged(Panel* panel) { 447 void DockedPanelStrip::OnPanelExpansionStateChanged(Panel* panel) {
448 gfx::Size size = panel->restored_size(); 448 gfx::Size size = panel->restored_size();
449 Panel::ExpansionState expansion_state = panel->expansion_state(); 449 Panel::ExpansionState expansion_state = panel->expansion_state();
450 Panel::ExpansionState old_state = panel->old_expansion_state();
451 switch (expansion_state) { 450 switch (expansion_state) {
452 case Panel::EXPANDED: 451 case Panel::EXPANDED:
453 if (old_state == Panel::TITLE_ONLY || old_state == Panel::MINIMIZED) 452
454 DecrementMinimizedPanels();
455 break; 453 break;
456 case Panel::TITLE_ONLY: 454 case Panel::TITLE_ONLY:
457 size.set_height(panel->TitleOnlyHeight()); 455 size.set_height(panel->TitleOnlyHeight());
458 if (old_state == Panel::EXPANDED) 456
459 IncrementMinimizedPanels();
460 break; 457 break;
461 case Panel::MINIMIZED: 458 case Panel::MINIMIZED:
462 size.set_height(Panel::kMinimizedPanelHeight); 459 size.set_height(Panel::kMinimizedPanelHeight);
463 if (old_state == Panel::EXPANDED) 460
464 IncrementMinimizedPanels();
465 break; 461 break;
466 default: 462 default:
467 NOTREACHED(); 463 NOTREACHED();
468 break; 464 break;
469 } 465 }
466 UpdateMinimizedPanelCount();
470 467
471 int bottom = GetBottomPositionForExpansionState(expansion_state); 468 int bottom = GetBottomPositionForExpansionState(expansion_state);
472 gfx::Rect bounds = panel->GetBounds(); 469 gfx::Rect bounds = panel->GetBounds();
473 panel->SetPanelBounds( 470 panel->SetPanelBounds(
474 gfx::Rect(bounds.right() - size.width(), 471 gfx::Rect(bounds.right() - size.width(),
475 bottom - size.height(), 472 bottom - size.height(),
476 size.width(), 473 size.width(),
477 size.height())); 474 size.height()));
478 } 475 }
479 476
(...skipping 30 matching lines...) Expand all
510 507
511 void DockedPanelStrip::RestorePanel(Panel* panel) { 508 void DockedPanelStrip::RestorePanel(Panel* panel) {
512 DCHECK_EQ(this, panel->panel_strip()); 509 DCHECK_EQ(this, panel->panel_strip());
513 panel->SetExpansionState(Panel::EXPANDED); 510 panel->SetExpansionState(Panel::EXPANDED);
514 } 511 }
515 512
516 bool DockedPanelStrip::IsPanelMinimized(const Panel* panel) const { 513 bool DockedPanelStrip::IsPanelMinimized(const Panel* panel) const {
517 return panel->expansion_state() != Panel::EXPANDED; 514 return panel->expansion_state() != Panel::EXPANDED;
518 } 515 }
519 516
520 void DockedPanelStrip::IncrementMinimizedPanels() { 517 void DockedPanelStrip::UpdateMinimizedPanelCount() {
521 minimized_panel_count_++; 518 int prev_minimized_panel_count = minimized_panel_count_;
522 if (minimized_panel_count_ == 1) 519 minimized_panel_count_ = 0;
520 for (Panels::const_iterator panel_iter = panels_.begin();
521 panel_iter != panels_.end(); ++panel_iter) {
522 if ((*panel_iter)->expansion_state() != Panel::EXPANDED)
523 minimized_panel_count_++;
524 }
525
526 if (prev_minimized_panel_count == 0 && minimized_panel_count_ > 0)
523 panel_manager_->mouse_watcher()->AddObserver(this); 527 panel_manager_->mouse_watcher()->AddObserver(this);
528 else if (prev_minimized_panel_count > 0 && minimized_panel_count_ == 0)
529 panel_manager_->mouse_watcher()->RemoveObserver(this);
530
524 DCHECK_LE(minimized_panel_count_, num_panels()); 531 DCHECK_LE(minimized_panel_count_, num_panels());
525 } 532 }
526 533
527 void DockedPanelStrip::DecrementMinimizedPanels() {
528 minimized_panel_count_--;
529 DCHECK_GE(minimized_panel_count_, 0);
530 if (minimized_panel_count_ == 0)
531 panel_manager_->mouse_watcher()->RemoveObserver(this);
532 }
533
534 void DockedPanelStrip::ResizePanelWindow( 534 void DockedPanelStrip::ResizePanelWindow(
535 Panel* panel, 535 Panel* panel,
536 const gfx::Size& preferred_window_size) { 536 const gfx::Size& preferred_window_size) {
537 // The panel width: 537 // The panel width:
538 // * cannot grow or shrink to go beyond [min_width, max_width] 538 // * cannot grow or shrink to go beyond [min_width, max_width]
539 int new_width = preferred_window_size.width(); 539 int new_width = preferred_window_size.width();
540 if (new_width > panel->max_size().width()) 540 if (new_width > panel->max_size().width())
541 new_width = panel->max_size().width(); 541 new_width = panel->max_size().width();
542 if (new_width < panel->min_size().width()) 542 if (new_width < panel->min_size().width())
543 new_width = panel->min_size().width(); 543 new_width = panel->min_size().width();
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
838 DCHECK(panels_in_temporary_layout_.empty()); 838 DCHECK(panels_in_temporary_layout_.empty());
839 839
840 // Make a copy of the iterator as closing panels can modify the vector. 840 // Make a copy of the iterator as closing panels can modify the vector.
841 Panels panels_copy = panels_; 841 Panels panels_copy = panels_;
842 842
843 // Start from the bottom to avoid reshuffling. 843 // Start from the bottom to avoid reshuffling.
844 for (Panels::reverse_iterator iter = panels_copy.rbegin(); 844 for (Panels::reverse_iterator iter = panels_copy.rbegin();
845 iter != panels_copy.rend(); ++iter) 845 iter != panels_copy.rend(); ++iter)
846 (*iter)->Close(); 846 (*iter)->Close();
847 } 847 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/panels/docked_panel_strip.h ('k') | chrome/browser/ui/panels/panel.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698