OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/devtools/devtools_contents_resizing_strategy.h" | |
6 #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.
| |
7 | |
8 DevToolsContentsResizingStrategy::DevToolsContentsResizingStrategy() { | |
9 } | |
10 | |
11 DevToolsContentsResizingStrategy::DevToolsContentsResizingStrategy( | |
12 gfx::Insets insets, gfx::Size min_size) | |
13 : insets_(insets), | |
14 min_size_(min_size) { | |
15 } | |
16 | |
17 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.
| |
18 const gfx::Size& container_size, | |
19 const gfx::Rect& old_devtools_bounds, | |
20 const gfx::Rect& old_contents_bounds, | |
21 gfx::Rect* new_devtools_bounds, | |
22 gfx::Rect* new_contents_bounds) const { | |
23 new_devtools_bounds->SetRect( | |
24 0, 0, container_size.width(), container_size.height()); | |
25 | |
26 int width = std::max(0, container_size.width() - insets_.width()); | |
27 int left = insets_.left(); | |
28 if (width < min_size_.width() && insets_.width() > 0) { | |
29 int min_width = std::min(min_size_.width(), container_size.width()); | |
30 int insets_width = container_size.width() - min_width; | |
31 int insets_decrease = insets_.width() - insets_width; | |
32 // Decrease both left and right insets proportionally. | |
33 left -= insets_decrease * insets_.left() / insets_.width(); | |
34 width = min_width; | |
35 } | |
36 left = std::max(0, std::min(container_size.width(), left)); | |
37 | |
38 int height = std::max(0, container_size.height() - insets_.height()); | |
39 int top = insets_.top(); | |
40 if (height < min_size_.height() && insets_.height() > 0) { | |
41 int min_height = std::min(min_size_.height(), container_size.height()); | |
42 int insets_height = container_size.height() - min_height; | |
43 int insets_decrease = insets_.height() - insets_height; | |
44 // Decrease both top and bottom insets proportionally. | |
45 top -= insets_decrease * insets_.top() / insets_.height(); | |
46 height = min_height; | |
47 } | |
48 top = std::max(0, std::min(container_size.height(), top)); | |
49 | |
50 new_contents_bounds->SetRect(left, top, width, height); | |
51 } | |
OLD | NEW |