Enable Enterprise enrollment on desktop builds.
[chromium-blink-merge.git] / chrome / browser / devtools / devtools_contents_resizing_strategy.cc
blob519278b6590c7a4e870b3b5daa36bd14733bdab7
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.
5 #include "chrome/browser/devtools/devtools_contents_resizing_strategy.h"
7 #include <algorithm>
9 DevToolsContentsResizingStrategy::DevToolsContentsResizingStrategy() {
12 DevToolsContentsResizingStrategy::DevToolsContentsResizingStrategy(
13 const gfx::Insets& insets, const gfx::Size& min_size)
14 : insets_(insets),
15 min_size_(min_size) {
18 void DevToolsContentsResizingStrategy::CopyFrom(
19 const DevToolsContentsResizingStrategy& strategy) {
20 insets_ = strategy.insets();
21 min_size_ = strategy.min_size();
24 bool DevToolsContentsResizingStrategy::Equals(
25 const DevToolsContentsResizingStrategy& strategy) {
26 return insets_ == strategy.insets() && min_size_ == strategy.min_size();
29 void ApplyDevToolsContentsResizingStrategy(
30 const DevToolsContentsResizingStrategy& strategy,
31 const gfx::Size& container_size,
32 const gfx::Rect& old_devtools_bounds,
33 const gfx::Rect& old_contents_bounds,
34 gfx::Rect* new_devtools_bounds,
35 gfx::Rect* new_contents_bounds) {
36 new_devtools_bounds->SetRect(
37 0, 0, container_size.width(), container_size.height());
39 const gfx::Insets& insets = strategy.insets();
40 const gfx::Size& min_size = strategy.min_size();
42 int width = std::max(0, container_size.width() - insets.width());
43 int left = insets.left();
44 if (width < min_size.width() && insets.width() > 0) {
45 int min_width = std::min(min_size.width(), container_size.width());
46 int insets_width = container_size.width() - min_width;
47 int insets_decrease = insets.width() - insets_width;
48 // Decrease both left and right insets proportionally.
49 left -= insets_decrease * insets.left() / insets.width();
50 width = min_width;
52 left = std::max(0, std::min(container_size.width(), left));
54 int height = std::max(0, container_size.height() - insets.height());
55 int top = insets.top();
56 if (height < min_size.height() && insets.height() > 0) {
57 int min_height = std::min(min_size.height(), container_size.height());
58 int insets_height = container_size.height() - min_height;
59 int insets_decrease = insets.height() - insets_height;
60 // Decrease both top and bottom insets proportionally.
61 top -= insets_decrease * insets.top() / insets.height();
62 height = min_height;
64 top = std::max(0, std::min(container_size.height(), top));
66 new_contents_bounds->SetRect(left, top, width, height);