Exclude one flaky test from Valgrind runs
[chromium-blink-merge.git] / apps / size_constraints.cc
blobbf7729a1c2a16ef5f6b4a5b7886669a07fc70eac
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"
7 #include <algorithm>
9 namespace apps {
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());
27 return size;
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 {
46 return minimum_size_;
49 gfx::Size SizeConstraints::GetMaximumSize() const {
50 return gfx::Size(
51 maximum_size_.width() == kUnboundedSize
52 ? kUnboundedSize
53 : std::max(maximum_size_.width(), minimum_size_.width()),
54 maximum_size_.height() == kUnboundedSize
55 ? 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;
67 } // namespace apps