Chromium Code Reviews| Index: chrome/browser/devtools/devtools_contents_resizing_strategy.cc |
| diff --git a/chrome/browser/devtools/devtools_contents_resizing_strategy.cc b/chrome/browser/devtools/devtools_contents_resizing_strategy.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..acedf5a2a1ad5c6985f6f3ff3f5ff4d2a41fb188 |
| --- /dev/null |
| +++ b/chrome/browser/devtools/devtools_contents_resizing_strategy.cc |
| @@ -0,0 +1,51 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/devtools/devtools_contents_resizing_strategy.h" |
| +#include <cstdio> |
|
sky
2014/02/03 22:17:29
nit: newline between 5 and 6.
dgozman
2014/02/04 13:08:48
Removed line 6.
|
| + |
| +DevToolsContentsResizingStrategy::DevToolsContentsResizingStrategy() { |
| +} |
| + |
| +DevToolsContentsResizingStrategy::DevToolsContentsResizingStrategy( |
| + gfx::Insets insets, gfx::Size min_size) |
| + : insets_(insets), |
| + min_size_(min_size) { |
| +} |
| + |
| +void DevToolsContentsResizingStrategy::Apply( |
|
sky
2014/02/03 22:17:29
How about some unit tests for this?
dgozman
2014/02/04 13:08:48
Done.
|
| + const gfx::Size& container_size, |
| + const gfx::Rect& old_devtools_bounds, |
| + const gfx::Rect& old_contents_bounds, |
| + gfx::Rect* new_devtools_bounds, |
| + gfx::Rect* new_contents_bounds) const { |
| + new_devtools_bounds->SetRect( |
| + 0, 0, container_size.width(), container_size.height()); |
| + |
| + int width = std::max(0, container_size.width() - insets_.width()); |
| + int left = insets_.left(); |
| + if (width < min_size_.width() && insets_.width() > 0) { |
| + int min_width = std::min(min_size_.width(), container_size.width()); |
| + int insets_width = container_size.width() - min_width; |
| + int insets_decrease = insets_.width() - insets_width; |
| + // Decrease both left and right insets proportionally. |
| + left -= insets_decrease * insets_.left() / insets_.width(); |
| + width = min_width; |
| + } |
| + left = std::max(0, std::min(container_size.width(), left)); |
| + |
| + int height = std::max(0, container_size.height() - insets_.height()); |
| + int top = insets_.top(); |
| + if (height < min_size_.height() && insets_.height() > 0) { |
| + int min_height = std::min(min_size_.height(), container_size.height()); |
| + int insets_height = container_size.height() - min_height; |
| + int insets_decrease = insets_.height() - insets_height; |
| + // Decrease both top and bottom insets proportionally. |
| + top -= insets_decrease * insets_.top() / insets_.height(); |
| + height = min_height; |
| + } |
| + top = std::max(0, std::min(container_size.height(), top)); |
| + |
| + new_contents_bounds->SetRect(left, top, width, height); |
| +} |