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#include <algorithm> 8 9DevToolsContentsResizingStrategy::DevToolsContentsResizingStrategy() 10 : hide_inspected_contents_(false) { 11} 12 13DevToolsContentsResizingStrategy::DevToolsContentsResizingStrategy( 14 const gfx::Rect& bounds) 15 : bounds_(bounds), 16 hide_inspected_contents_(bounds_.IsEmpty() && !bounds_.x() && 17 !bounds_.y()) { 18} 19 20 21void DevToolsContentsResizingStrategy::CopyFrom( 22 const DevToolsContentsResizingStrategy& strategy) { 23 bounds_ = strategy.bounds(); 24 hide_inspected_contents_ = strategy.hide_inspected_contents(); 25} 26 27bool DevToolsContentsResizingStrategy::Equals( 28 const DevToolsContentsResizingStrategy& strategy) { 29 return bounds_ == strategy.bounds() && 30 hide_inspected_contents_ == strategy.hide_inspected_contents(); 31} 32 33void 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()); 40 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()); 45 return; 46 } 47 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); 53} 54