| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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/devtools/devtools_contents_resizing_strategy.h" | 5 #include "chrome/browser/devtools/devtools_contents_resizing_strategy.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 DevToolsContentsResizingStrategy::DevToolsContentsResizingStrategy() { | 9 DevToolsContentsResizingStrategy::DevToolsContentsResizingStrategy() { |
| 10 } | 10 } |
| 11 | 11 |
| 12 DevToolsContentsResizingStrategy::DevToolsContentsResizingStrategy( | 12 DevToolsContentsResizingStrategy::DevToolsContentsResizingStrategy( |
| 13 const gfx::Insets& insets, const gfx::Size& min_size) | 13 const gfx::Insets& insets, const gfx::Size& min_size) |
| 14 : insets_(insets), | 14 : insets_(insets), |
| 15 min_size_(min_size) { | 15 min_size_(min_size) { |
| 16 } | 16 } |
| 17 | 17 |
| 18 DevToolsContentsResizingStrategy::DevToolsContentsResizingStrategy( |
| 19 const gfx::Rect& bounds) |
| 20 : bounds_(bounds) { |
| 21 } |
| 22 |
| 23 |
| 18 void DevToolsContentsResizingStrategy::CopyFrom( | 24 void DevToolsContentsResizingStrategy::CopyFrom( |
| 19 const DevToolsContentsResizingStrategy& strategy) { | 25 const DevToolsContentsResizingStrategy& strategy) { |
| 20 insets_ = strategy.insets(); | 26 insets_ = strategy.insets(); |
| 21 min_size_ = strategy.min_size(); | 27 min_size_ = strategy.min_size(); |
| 28 bounds_ = strategy.bounds(); |
| 22 } | 29 } |
| 23 | 30 |
| 24 bool DevToolsContentsResizingStrategy::Equals( | 31 bool DevToolsContentsResizingStrategy::Equals( |
| 25 const DevToolsContentsResizingStrategy& strategy) { | 32 const DevToolsContentsResizingStrategy& strategy) { |
| 26 return insets_ == strategy.insets() && min_size_ == strategy.min_size(); | 33 return insets_ == strategy.insets() && min_size_ == strategy.min_size() && |
| 34 bounds_ == strategy.bounds(); |
| 27 } | 35 } |
| 28 | 36 |
| 29 void ApplyDevToolsContentsResizingStrategy( | 37 void ApplyDevToolsContentsResizingStrategy( |
| 30 const DevToolsContentsResizingStrategy& strategy, | 38 const DevToolsContentsResizingStrategy& strategy, |
| 31 const gfx::Size& container_size, | 39 const gfx::Size& container_size, |
| 32 const gfx::Rect& old_devtools_bounds, | 40 const gfx::Rect& old_devtools_bounds, |
| 33 const gfx::Rect& old_contents_bounds, | 41 const gfx::Rect& old_contents_bounds, |
| 34 gfx::Rect* new_devtools_bounds, | 42 gfx::Rect* new_devtools_bounds, |
| 35 gfx::Rect* new_contents_bounds) { | 43 gfx::Rect* new_contents_bounds) { |
| 36 new_devtools_bounds->SetRect( | 44 new_devtools_bounds->SetRect( |
| 37 0, 0, container_size.width(), container_size.height()); | 45 0, 0, container_size.width(), container_size.height()); |
| 38 | 46 |
| 39 const gfx::Insets& insets = strategy.insets(); | 47 const gfx::Insets& insets = strategy.insets(); |
| 40 const gfx::Size& min_size = strategy.min_size(); | 48 const gfx::Size& min_size = strategy.min_size(); |
| 49 const gfx::Rect& bounds = strategy.bounds(); |
| 50 |
| 51 if (!bounds.size().IsEmpty()) { |
| 52 int left = std::min(bounds.x(), container_size.width()); |
| 53 int top = std::min(bounds.y(), container_size.height()); |
| 54 int width = std::min(bounds.width(), container_size.width() - left); |
| 55 int height = std::min(bounds.height(), container_size.height() - top); |
| 56 new_contents_bounds->SetRect(left, top, width, height); |
| 57 return; |
| 58 } |
| 41 | 59 |
| 42 int width = std::max(0, container_size.width() - insets.width()); | 60 int width = std::max(0, container_size.width() - insets.width()); |
| 43 int left = insets.left(); | 61 int left = insets.left(); |
| 44 if (width < min_size.width() && insets.width() > 0) { | 62 if (width < min_size.width() && insets.width() > 0) { |
| 45 int min_width = std::min(min_size.width(), container_size.width()); | 63 int min_width = std::min(min_size.width(), container_size.width()); |
| 46 int insets_width = container_size.width() - min_width; | 64 int insets_width = container_size.width() - min_width; |
| 47 int insets_decrease = insets.width() - insets_width; | 65 int insets_decrease = insets.width() - insets_width; |
| 48 // Decrease both left and right insets proportionally. | 66 // Decrease both left and right insets proportionally. |
| 49 left -= insets_decrease * insets.left() / insets.width(); | 67 left -= insets_decrease * insets.left() / insets.width(); |
| 50 width = min_width; | 68 width = min_width; |
| 51 } | 69 } |
| 52 left = std::max(0, std::min(container_size.width(), left)); | 70 left = std::max(0, std::min(container_size.width(), left)); |
| 53 | 71 |
| 54 int height = std::max(0, container_size.height() - insets.height()); | 72 int height = std::max(0, container_size.height() - insets.height()); |
| 55 int top = insets.top(); | 73 int top = insets.top(); |
| 56 if (height < min_size.height() && insets.height() > 0) { | 74 if (height < min_size.height() && insets.height() > 0) { |
| 57 int min_height = std::min(min_size.height(), container_size.height()); | 75 int min_height = std::min(min_size.height(), container_size.height()); |
| 58 int insets_height = container_size.height() - min_height; | 76 int insets_height = container_size.height() - min_height; |
| 59 int insets_decrease = insets.height() - insets_height; | 77 int insets_decrease = insets.height() - insets_height; |
| 60 // Decrease both top and bottom insets proportionally. | 78 // Decrease both top and bottom insets proportionally. |
| 61 top -= insets_decrease * insets.top() / insets.height(); | 79 top -= insets_decrease * insets.top() / insets.height(); |
| 62 height = min_height; | 80 height = min_height; |
| 63 } | 81 } |
| 64 top = std::max(0, std::min(container_size.height(), top)); | 82 top = std::max(0, std::min(container_size.height(), top)); |
| 65 | 83 |
| 66 new_contents_bounds->SetRect(left, top, width, height); | 84 new_contents_bounds->SetRect(left, top, width, height); |
| 67 } | 85 } |
| OLD | NEW |