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"
9 DevToolsContentsResizingStrategy::DevToolsContentsResizingStrategy()
10 : hide_inspected_contents_(false) {
13 DevToolsContentsResizingStrategy::DevToolsContentsResizingStrategy(
14 const gfx::Rect
& bounds
)
16 hide_inspected_contents_(bounds_
.IsEmpty() && !bounds_
.x() &&
21 void DevToolsContentsResizingStrategy::CopyFrom(
22 const DevToolsContentsResizingStrategy
& strategy
) {
23 bounds_
= strategy
.bounds();
24 hide_inspected_contents_
= strategy
.hide_inspected_contents();
27 bool DevToolsContentsResizingStrategy::Equals(
28 const DevToolsContentsResizingStrategy
& strategy
) {
29 return bounds_
== strategy
.bounds() &&
30 hide_inspected_contents_
== strategy
.hide_inspected_contents();
33 void ApplyDevToolsContentsResizingStrategy(
34 const DevToolsContentsResizingStrategy
& strategy
,
35 const gfx::Size
& container_size
,
36 gfx::Rect
* new_devtools_bounds
,
37 gfx::Rect
* new_contents_bounds
) {
38 new_devtools_bounds
->SetRect(
39 0, 0, container_size
.width(), container_size
.height());
41 const gfx::Rect
& bounds
= strategy
.bounds();
42 if (bounds
.size().IsEmpty() && !strategy
.hide_inspected_contents()) {
43 new_contents_bounds
->SetRect(
44 0, 0, container_size
.width(), container_size
.height());
48 int left
= std::min(bounds
.x(), container_size
.width());
49 int top
= std::min(bounds
.y(), container_size
.height());
50 int width
= std::min(bounds
.width(), container_size
.width() - left
);
51 int height
= std::min(bounds
.height(), container_size
.height() - top
);
52 new_contents_bounds
->SetRect(left
, top
, width
, height
);