Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "apps/size_constraints.h" | 5 #include "apps/size_constraints.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 namespace apps { | 9 namespace apps { |
| 10 | 10 |
| 11 SizeConstraints::SizeConstraints() | 11 SizeConstraints::SizeConstraints() |
| 12 : maximum_size_(kUnboundedSize, kUnboundedSize) {} | 12 : maximum_size_(kUnboundedSize, kUnboundedSize) {} |
| 13 | 13 |
| 14 SizeConstraints::SizeConstraints(const gfx::Size& min_size, | 14 SizeConstraints::SizeConstraints(const gfx::Size& min_size, |
| 15 const gfx::Size& max_size) | 15 const gfx::Size& max_size) |
| 16 : minimum_size_(min_size), maximum_size_(max_size) {} | 16 : minimum_size_(min_size), maximum_size_(max_size) {} |
| 17 | 17 |
| 18 SizeConstraints::~SizeConstraints() {} | 18 SizeConstraints::~SizeConstraints() {} |
| 19 | 19 |
| 20 // static | |
| 21 gfx::Size SizeConstraints::InsetConstraints(const gfx::Size& size_constraints, | |
| 22 const gfx::Insets& frame_insets) { | |
| 23 return gfx::Size( | |
| 24 size_constraints.width() == kUnboundedSize | |
| 25 ? kUnboundedSize | |
| 26 : size_constraints.width() - frame_insets.width(), | |
|
tapted
2014/03/05 03:14:03
Do we need to worry about this going negative? Or
tmdiep
2014/03/05 04:29:06
Hmm good point. This is really just used to add in
| |
| 27 size_constraints.height() == kUnboundedSize | |
| 28 ? kUnboundedSize | |
| 29 : size_constraints.height() - frame_insets.height()); | |
| 30 } | |
| 31 | |
| 20 gfx::Size SizeConstraints::ClampSize(gfx::Size size) const { | 32 gfx::Size SizeConstraints::ClampSize(gfx::Size size) const { |
| 21 const gfx::Size max_size = GetMaximumSize(); | 33 const gfx::Size max_size = GetMaximumSize(); |
| 22 if (max_size.width() != kUnboundedSize) | 34 if (max_size.width() != kUnboundedSize) |
| 23 size.set_width(std::min(size.width(), GetMaximumSize().width())); | 35 size.set_width(std::min(size.width(), max_size.width())); |
| 24 if (max_size.height() != kUnboundedSize) | 36 if (max_size.height() != kUnboundedSize) |
| 25 size.set_height(std::min(size.height(), GetMaximumSize().height())); | 37 size.set_height(std::min(size.height(), max_size.height())); |
| 26 size.SetToMax(GetMinimumSize()); | 38 size.SetToMax(GetMinimumSize()); |
| 27 return size; | 39 return size; |
| 28 } | 40 } |
| 29 | 41 |
| 30 bool SizeConstraints::HasMinimumSize() const { | 42 bool SizeConstraints::HasMinimumSize() const { |
| 31 return GetMinimumSize().width() != kUnboundedSize || | 43 const gfx::Size min_size = GetMinimumSize(); |
| 32 GetMinimumSize().height() != kUnboundedSize; | 44 return min_size.width() != kUnboundedSize || |
| 45 min_size.height() != kUnboundedSize; | |
| 33 } | 46 } |
| 34 | 47 |
| 35 bool SizeConstraints::HasMaximumSize() const { | 48 bool SizeConstraints::HasMaximumSize() const { |
| 36 const gfx::Size max_size = GetMaximumSize(); | 49 const gfx::Size max_size = GetMaximumSize(); |
| 37 return max_size.width() != kUnboundedSize || | 50 return max_size.width() != kUnboundedSize || |
| 38 max_size.height() != kUnboundedSize; | 51 max_size.height() != kUnboundedSize; |
| 39 } | 52 } |
| 40 | 53 |
| 41 bool SizeConstraints::HasFixedSize() const { | 54 bool SizeConstraints::HasFixedSize() const { |
| 42 return !GetMinimumSize().IsEmpty() && GetMinimumSize() == GetMaximumSize(); | 55 return !GetMinimumSize().IsEmpty() && GetMinimumSize() == GetMaximumSize(); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 58 | 71 |
| 59 void SizeConstraints::set_minimum_size(const gfx::Size& min_size) { | 72 void SizeConstraints::set_minimum_size(const gfx::Size& min_size) { |
| 60 minimum_size_ = min_size; | 73 minimum_size_ = min_size; |
| 61 } | 74 } |
| 62 | 75 |
| 63 void SizeConstraints::set_maximum_size(const gfx::Size& max_size) { | 76 void SizeConstraints::set_maximum_size(const gfx::Size& max_size) { |
| 64 maximum_size_ = max_size; | 77 maximum_size_ = max_size; |
| 65 } | 78 } |
| 66 | 79 |
| 67 } // namespace apps | 80 } // namespace apps |
| OLD | NEW |