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 |
| 7 DevToolsContentsResizingStrategy::DevToolsContentsResizingStrategy() { |
| 8 } |
| 9 |
| 10 DevToolsContentsResizingStrategy::DevToolsContentsResizingStrategy( |
| 11 const gfx::Insets& insets, const gfx::Size& min_size) |
| 12 : insets_(insets), |
| 13 min_size_(min_size) { |
| 14 } |
| 15 |
| 16 void DevToolsContentsResizingStrategy::CopyFrom( |
| 17 const DevToolsContentsResizingStrategy& strategy) { |
| 18 insets_ = strategy.insets(); |
| 19 min_size_ = strategy.min_size(); |
| 20 } |
| 21 |
| 22 bool DevToolsContentsResizingStrategy::Equals( |
| 23 const DevToolsContentsResizingStrategy& strategy) { |
| 24 return insets_ == strategy.insets() && min_size_ == strategy.min_size(); |
| 25 } |
| 26 |
| 27 void ApplyDevToolsContentsResizingStrategy( |
| 28 const DevToolsContentsResizingStrategy& strategy, |
| 29 const gfx::Size& container_size, |
| 30 const gfx::Rect& old_devtools_bounds, |
| 31 const gfx::Rect& old_contents_bounds, |
| 32 gfx::Rect* new_devtools_bounds, |
| 33 gfx::Rect* new_contents_bounds) { |
| 34 new_devtools_bounds->SetRect( |
| 35 0, 0, container_size.width(), container_size.height()); |
| 36 |
| 37 const gfx::Insets& insets = strategy.insets(); |
| 38 const gfx::Size& min_size = strategy.min_size(); |
| 39 |
| 40 int width = std::max(0, container_size.width() - insets.width()); |
| 41 int left = insets.left(); |
| 42 if (width < min_size.width() && insets.width() > 0) { |
| 43 int min_width = std::min(min_size.width(), container_size.width()); |
| 44 int insets_width = container_size.width() - min_width; |
| 45 int insets_decrease = insets.width() - insets_width; |
| 46 // Decrease both left and right insets proportionally. |
| 47 left -= insets_decrease * insets.left() / insets.width(); |
| 48 width = min_width; |
| 49 } |
| 50 left = std::max(0, std::min(container_size.width(), left)); |
| 51 |
| 52 int height = std::max(0, container_size.height() - insets.height()); |
| 53 int top = insets.top(); |
| 54 if (height < min_size.height() && insets.height() > 0) { |
| 55 int min_height = std::min(min_size.height(), container_size.height()); |
| 56 int insets_height = container_size.height() - min_height; |
| 57 int insets_decrease = insets.height() - insets_height; |
| 58 // Decrease both top and bottom insets proportionally. |
| 59 top -= insets_decrease * insets.top() / insets.height(); |
| 60 height = min_height; |
| 61 } |
| 62 top = std::max(0, std::min(container_size.height(), top)); |
| 63 |
| 64 new_contents_bounds->SetRect(left, top, width, height); |
| 65 } |
OLD | NEW |