Chromium Code Reviews| 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_manager.h" | 5 #include "chrome/browser/ui/panels/panel_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
| 12 #include "chrome/browser/ui/window_sizer.h" | 12 #include "chrome/browser/ui/window_sizer.h" |
| 13 | 13 |
| 14 namespace { | 14 namespace { |
| 15 // Invalid panel index. | 15 // Invalid panel index. |
| 16 const size_t kInvalidPanelIndex = static_cast<size_t>(-1); | 16 const size_t kInvalidPanelIndex = static_cast<size_t>(-1); |
| 17 | 17 |
| 18 // Minimum width and height of a panel. | 18 // Minimum width and height of a panel. |
| 19 const int kPanelMinWidthPixels = 64; | 19 // Note: The minimum size of a widget (see widget.cc) is fixed to 100x100. |
|
Dmitry Titov
2011/08/05 19:02:20
We do have notifications today with smaller sizes,
jianli
2011/08/09 19:56:16
Done.
| |
| 20 const int kPanelMinHeightPixels = 24; | 20 const int kPanelMinWidthPixels = 100; |
| 21 const int kPanelMinHeightPixels = 100; | |
| 21 | 22 |
| 22 // Default width and height of a panel. | 23 // Default width and height of a panel. |
| 23 const int kPanelDefaultWidthPixels = 240; | 24 const int kPanelDefaultWidthPixels = 240; |
| 24 const int kPanelDefaultHeightPixels = 290; | 25 const int kPanelDefaultHeightPixels = 290; |
| 25 | 26 |
| 26 // Maxmium width and height of a panel based on the factor of the working | 27 // Maxmium width and height of a panel based on the factor of the working |
| 27 // area. | 28 // area. |
| 28 const double kPanelMaxWidthFactor = 1.0; | 29 const double kPanelMaxWidthFactor = 1.0; |
| 29 const double kPanelMaxHeightFactor = 0.5; | 30 const double kPanelMaxHeightFactor = 0.5; |
| 30 | 31 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 103 const Extension* extension = NULL; | 104 const Extension* extension = NULL; |
| 104 gfx::Rect bounds = browser->override_bounds(); | 105 gfx::Rect bounds = browser->override_bounds(); |
| 105 while (!ComputeBoundsForNextPanel(&bounds, true)) { | 106 while (!ComputeBoundsForNextPanel(&bounds, true)) { |
| 106 if (!extension) | 107 if (!extension) |
| 107 extension = Panel::GetExtension(browser); | 108 extension = Panel::GetExtension(browser); |
| 108 FindAndClosePanelOnOverflow(extension); | 109 FindAndClosePanelOnOverflow(extension); |
| 109 } | 110 } |
| 110 | 111 |
| 111 Panel* panel = new Panel(browser, bounds); | 112 Panel* panel = new Panel(browser, bounds); |
| 112 panels_.push_back(panel); | 113 panels_.push_back(panel); |
| 114 UpdateMaximumSizeForAllPanels(); | |
| 113 | 115 |
| 114 return panel; | 116 return panel; |
| 115 } | 117 } |
| 116 | 118 |
| 117 void PanelManager::Remove(Panel* panel) { | 119 void PanelManager::Remove(Panel* panel) { |
| 118 // If we're in the process of dragging, delay the removal. | 120 // If we're in the process of dragging, delay the removal. |
| 119 if (dragging_panel_index_ != kInvalidPanelIndex) { | 121 if (dragging_panel_index_ != kInvalidPanelIndex) { |
| 120 panels_pending_to_remove_.push_back(panel); | 122 panels_pending_to_remove_.push_back(panel); |
| 121 return; | 123 return; |
| 122 } | 124 } |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 264 } else { | 266 } else { |
| 265 panels_[dragging_panel_index_]->SetPanelBounds( | 267 panels_[dragging_panel_index_]->SetPanelBounds( |
| 266 dragging_panel_bounds_); | 268 dragging_panel_bounds_); |
| 267 } | 269 } |
| 268 | 270 |
| 269 dragging_panel_index_ = kInvalidPanelIndex; | 271 dragging_panel_index_ = kInvalidPanelIndex; |
| 270 | 272 |
| 271 DelayedRemove(); | 273 DelayedRemove(); |
| 272 } | 274 } |
| 273 | 275 |
| 276 void PanelManager::UpdatePreferredSize(Panel* panel, | |
| 277 const gfx::Size& pref_size) { | |
| 278 gfx::Size non_client_size = panel->GetNonClientAreaSize(); | |
| 279 | |
| 280 // We need to get and set the restored bounds since the preferred size change | |
| 281 // might be triggered when the panel is not expanded. | |
| 282 gfx::Rect bounds = panel->GetRestoredBounds(); | |
| 283 | |
| 284 // The panel width: | |
| 285 // * cannot grow more than the maximum width | |
| 286 // * cannot grow to take more than the available horizontal space | |
|
Dmitry Titov
2011/08/05 19:02:20
what is exactly 'available horizontal space'? Not
jianli
2011/08/09 19:56:16
Updated comment.
| |
| 287 // * cannot shrink to be smaller than the initial width | |
| 288 int new_panel_width = pref_size.width() + non_client_size.width(); | |
| 289 if (new_panel_width > max_width_) | |
| 290 new_panel_width = max_width_; | |
| 291 if (new_panel_width - bounds.width() > current_x_) | |
| 292 new_panel_width = bounds.width() + current_x_; | |
| 293 | |
| 294 if (new_panel_width > bounds.width() || | |
| 295 (new_panel_width < bounds.width() && | |
| 296 new_panel_width > panel->initial_size_.width())) { | |
| 297 int delta = bounds.width() - new_panel_width; | |
| 298 bounds.set_x(bounds.x() + delta); | |
| 299 bounds.set_width(new_panel_width); | |
| 300 | |
| 301 // Reposition all the panels on the left. | |
| 302 int panel_index = -1; | |
| 303 for (int i = 0; i < static_cast<int>(panels_.size()); ++i) { | |
| 304 if (panels_[i] == panel) { | |
| 305 panel_index = i; | |
| 306 break; | |
| 307 } | |
| 308 } | |
| 309 DCHECK(panel_index >= 0); | |
| 310 for (int i = static_cast<int>(panels_.size()) -1; i > panel_index; | |
| 311 --i) { | |
| 312 gfx::Rect this_bounds = panels_[i]->GetBounds(); | |
| 313 this_bounds.set_x(this_bounds.x() + delta); | |
| 314 panels_[i]->SetPanelBounds(this_bounds); | |
| 315 } | |
| 316 } | |
| 317 | |
| 318 // The panel height: | |
| 319 // * cannot grow more than the maximum height | |
| 320 // * cannot shrink to be smaller than the initial height | |
| 321 int new_panel_height = pref_size.height() + non_client_size.height(); | |
| 322 if (new_panel_height > max_height_) | |
| 323 new_panel_height = max_height_; | |
| 324 | |
| 325 if (new_panel_height > bounds.height() || | |
| 326 (new_panel_height < bounds.height() && | |
| 327 new_panel_height > panel->initial_size_.height())) { | |
| 328 bounds.set_y(bounds.y() - new_panel_height + bounds.height()); | |
| 329 bounds.set_height(new_panel_height); | |
| 330 } | |
| 331 | |
| 332 panel->SetRestoredBounds(bounds); | |
| 333 current_x_ = | |
| 334 panels_.back()->GetBounds().x() - kPanelsHorizontalSpacing; | |
| 335 | |
| 336 UpdateMaximumSizeForAllPanels(); | |
| 337 } | |
| 338 | |
| 274 bool PanelManager::ShouldBringUpTitleBarForAllMinimizedPanels( | 339 bool PanelManager::ShouldBringUpTitleBarForAllMinimizedPanels( |
| 275 int mouse_x, int mouse_y) const { | 340 int mouse_x, int mouse_y) const { |
| 276 for (Panels::const_iterator iter = panels_.begin(); | 341 for (Panels::const_iterator iter = panels_.begin(); |
| 277 iter != panels_.end(); ++iter) { | 342 iter != panels_.end(); ++iter) { |
| 278 if ((*iter)->ShouldBringUpTitleBar(mouse_x, mouse_y)) | 343 if ((*iter)->ShouldBringUpTitleBar(mouse_x, mouse_y)) |
| 279 return true; | 344 return true; |
| 280 } | 345 } |
| 281 return false; | 346 return false; |
| 282 } | 347 } |
| 283 | 348 |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 303 void PanelManager::Rearrange(Panels::iterator iter_to_start) { | 368 void PanelManager::Rearrange(Panels::iterator iter_to_start) { |
| 304 if (iter_to_start == panels_.end()) | 369 if (iter_to_start == panels_.end()) |
| 305 return; | 370 return; |
| 306 | 371 |
| 307 for (Panels::iterator iter = iter_to_start; iter != panels_.end(); ++iter) { | 372 for (Panels::iterator iter = iter_to_start; iter != panels_.end(); ++iter) { |
| 308 gfx::Rect new_bounds((*iter)->GetBounds()); | 373 gfx::Rect new_bounds((*iter)->GetBounds()); |
| 309 ComputeBoundsForNextPanel(&new_bounds, false); | 374 ComputeBoundsForNextPanel(&new_bounds, false); |
| 310 if (new_bounds != (*iter)->GetBounds()) | 375 if (new_bounds != (*iter)->GetBounds()) |
| 311 (*iter)->SetPanelBounds(new_bounds); | 376 (*iter)->SetPanelBounds(new_bounds); |
| 312 } | 377 } |
| 378 | |
| 379 UpdateMaximumSizeForAllPanels(); | |
| 313 } | 380 } |
| 314 | 381 |
| 315 bool PanelManager::ComputeBoundsForNextPanel(gfx::Rect* bounds, | 382 bool PanelManager::ComputeBoundsForNextPanel(gfx::Rect* bounds, |
| 316 bool allow_size_change) { | 383 bool allow_size_change) { |
| 317 int width = bounds->width(); | 384 int width = bounds->width(); |
| 318 int height = bounds->height(); | 385 int height = bounds->height(); |
| 319 | 386 |
| 320 // Update the width and/or height to fit into our constraint. | 387 // Update the width and/or height to fit into our constraint. |
| 321 if (allow_size_change) { | 388 if (allow_size_change) { |
| 322 if (width == 0 && height == 0) { | 389 if (width == 0 && height == 0) { |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 349 | 416 |
| 350 void PanelManager::RemoveAll() { | 417 void PanelManager::RemoveAll() { |
| 351 // This should not be called when we're in the process of dragging. | 418 // This should not be called when we're in the process of dragging. |
| 352 DCHECK(dragging_panel_index_ == kInvalidPanelIndex); | 419 DCHECK(dragging_panel_index_ == kInvalidPanelIndex); |
| 353 | 420 |
| 354 // Start from the bottom to avoid reshuffling. | 421 // Start from the bottom to avoid reshuffling. |
| 355 for (Panels::reverse_iterator iter = panels_.rbegin(); | 422 for (Panels::reverse_iterator iter = panels_.rbegin(); |
| 356 iter != panels_.rend(); ++iter) | 423 iter != panels_.rend(); ++iter) |
| 357 (*iter)->Close(); | 424 (*iter)->Close(); |
| 358 } | 425 } |
| 426 | |
| 427 void PanelManager::UpdateMaximumSizeForAllPanels() { | |
| 428 for (Panels::const_iterator iter = panels_.begin(); | |
| 429 iter != panels_.end(); ++iter) { | |
| 430 Panel* panel = *iter; | |
| 431 int width_can_grow_to = panel->GetBounds().width() + current_x_; | |
|
Dmitry Titov
2011/08/05 19:02:20
It is a bit unclear why we give the same area of t
jianli
2011/08/09 19:56:16
Added comment.
| |
| 432 panel->SetMaximumSize( | |
| 433 gfx::Size(std::min(width_can_grow_to, max_width_), max_height_)); | |
| 434 } | |
| 435 } | |
| OLD | NEW |