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 "apps/size_constraints.h"
11 SizeConstraints::SizeConstraints()
12 : maximum_size_(kUnboundedSize
, kUnboundedSize
) {}
14 SizeConstraints::SizeConstraints(const gfx::Size
& min_size
,
15 const gfx::Size
& max_size
)
16 : minimum_size_(min_size
), maximum_size_(max_size
) {}
18 SizeConstraints::~SizeConstraints() {}
20 gfx::Size
SizeConstraints::ClampSize(gfx::Size size
) const {
21 const gfx::Size max_size
= GetMaximumSize();
22 if (max_size
.width() != kUnboundedSize
)
23 size
.set_width(std::min(size
.width(), GetMaximumSize().width()));
24 if (max_size
.height() != kUnboundedSize
)
25 size
.set_height(std::min(size
.height(), GetMaximumSize().height()));
26 size
.SetToMax(GetMinimumSize());
30 bool SizeConstraints::HasMinimumSize() const {
31 return GetMinimumSize().width() != kUnboundedSize
||
32 GetMinimumSize().height() != kUnboundedSize
;
35 bool SizeConstraints::HasMaximumSize() const {
36 const gfx::Size max_size
= GetMaximumSize();
37 return max_size
.width() != kUnboundedSize
||
38 max_size
.height() != kUnboundedSize
;
41 bool SizeConstraints::HasFixedSize() const {
42 return !GetMinimumSize().IsEmpty() && GetMinimumSize() == GetMaximumSize();
45 gfx::Size
SizeConstraints::GetMinimumSize() const {
49 gfx::Size
SizeConstraints::GetMaximumSize() const {
51 maximum_size_
.width() == kUnboundedSize
53 : std::max(maximum_size_
.width(), minimum_size_
.width()),
54 maximum_size_
.height() == kUnboundedSize
56 : std::max(maximum_size_
.height(), minimum_size_
.height()));
59 void SizeConstraints::set_minimum_size(const gfx::Size
& min_size
) {
60 minimum_size_
= min_size
;
63 void SizeConstraints::set_maximum_size(const gfx::Size
& max_size
) {
64 maximum_size_
= max_size
;