OLD | NEW |
| (Empty) |
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 "extensions/browser/app_window/size_constraints.h" | |
6 | |
7 #include <algorithm> | |
8 | |
9 #include "ui/gfx/insets.h" | |
10 | |
11 namespace extensions { | |
12 | |
13 SizeConstraints::SizeConstraints() | |
14 : maximum_size_(kUnboundedSize, kUnboundedSize) {} | |
15 | |
16 SizeConstraints::SizeConstraints(const gfx::Size& min_size, | |
17 const gfx::Size& max_size) | |
18 : minimum_size_(min_size), maximum_size_(max_size) {} | |
19 | |
20 SizeConstraints::~SizeConstraints() {} | |
21 | |
22 // static | |
23 gfx::Size SizeConstraints::AddFrameToConstraints( | |
24 const gfx::Size& size_constraints, | |
25 const gfx::Insets& frame_insets) { | |
26 return gfx::Size( | |
27 size_constraints.width() == kUnboundedSize | |
28 ? kUnboundedSize | |
29 : size_constraints.width() + frame_insets.width(), | |
30 size_constraints.height() == kUnboundedSize | |
31 ? kUnboundedSize | |
32 : size_constraints.height() + frame_insets.height()); | |
33 } | |
34 | |
35 gfx::Size SizeConstraints::ClampSize(gfx::Size size) const { | |
36 const gfx::Size max_size = GetMaximumSize(); | |
37 if (max_size.width() != kUnboundedSize) | |
38 size.set_width(std::min(size.width(), max_size.width())); | |
39 if (max_size.height() != kUnboundedSize) | |
40 size.set_height(std::min(size.height(), max_size.height())); | |
41 size.SetToMax(GetMinimumSize()); | |
42 return size; | |
43 } | |
44 | |
45 bool SizeConstraints::HasMinimumSize() const { | |
46 const gfx::Size min_size = GetMinimumSize(); | |
47 return min_size.width() != kUnboundedSize || | |
48 min_size.height() != kUnboundedSize; | |
49 } | |
50 | |
51 bool SizeConstraints::HasMaximumSize() const { | |
52 const gfx::Size max_size = GetMaximumSize(); | |
53 return max_size.width() != kUnboundedSize || | |
54 max_size.height() != kUnboundedSize; | |
55 } | |
56 | |
57 bool SizeConstraints::HasFixedSize() const { | |
58 return !GetMinimumSize().IsEmpty() && GetMinimumSize() == GetMaximumSize(); | |
59 } | |
60 | |
61 gfx::Size SizeConstraints::GetMinimumSize() const { | |
62 return minimum_size_; | |
63 } | |
64 | |
65 gfx::Size SizeConstraints::GetMaximumSize() const { | |
66 return gfx::Size( | |
67 maximum_size_.width() == kUnboundedSize | |
68 ? kUnboundedSize | |
69 : std::max(maximum_size_.width(), minimum_size_.width()), | |
70 maximum_size_.height() == kUnboundedSize | |
71 ? kUnboundedSize | |
72 : std::max(maximum_size_.height(), minimum_size_.height())); | |
73 } | |
74 | |
75 void SizeConstraints::set_minimum_size(const gfx::Size& min_size) { | |
76 minimum_size_ = min_size; | |
77 } | |
78 | |
79 void SizeConstraints::set_maximum_size(const gfx::Size& max_size) { | |
80 maximum_size_ = max_size; | |
81 } | |
82 | |
83 } // namespace extensions | |
OLD | NEW |