Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(193)

Side by Side Diff: apps/size_constraints.cc

Issue 186343002: Create windows for new app window bounds API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed nit Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « apps/size_constraints.h ('k') | apps/ui/native_app_window.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "ui/gfx/insets.h"
10
9 namespace apps { 11 namespace apps {
10 12
11 SizeConstraints::SizeConstraints() 13 SizeConstraints::SizeConstraints()
12 : maximum_size_(kUnboundedSize, kUnboundedSize) {} 14 : maximum_size_(kUnboundedSize, kUnboundedSize) {}
13 15
14 SizeConstraints::SizeConstraints(const gfx::Size& min_size, 16 SizeConstraints::SizeConstraints(const gfx::Size& min_size,
15 const gfx::Size& max_size) 17 const gfx::Size& max_size)
16 : minimum_size_(min_size), maximum_size_(max_size) {} 18 : minimum_size_(min_size), maximum_size_(max_size) {}
17 19
18 SizeConstraints::~SizeConstraints() {} 20 SizeConstraints::~SizeConstraints() {}
19 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
20 gfx::Size SizeConstraints::ClampSize(gfx::Size size) const { 35 gfx::Size SizeConstraints::ClampSize(gfx::Size size) const {
21 const gfx::Size max_size = GetMaximumSize(); 36 const gfx::Size max_size = GetMaximumSize();
22 if (max_size.width() != kUnboundedSize) 37 if (max_size.width() != kUnboundedSize)
23 size.set_width(std::min(size.width(), GetMaximumSize().width())); 38 size.set_width(std::min(size.width(), max_size.width()));
24 if (max_size.height() != kUnboundedSize) 39 if (max_size.height() != kUnboundedSize)
25 size.set_height(std::min(size.height(), GetMaximumSize().height())); 40 size.set_height(std::min(size.height(), max_size.height()));
26 size.SetToMax(GetMinimumSize()); 41 size.SetToMax(GetMinimumSize());
27 return size; 42 return size;
28 } 43 }
29 44
30 bool SizeConstraints::HasMinimumSize() const { 45 bool SizeConstraints::HasMinimumSize() const {
31 return GetMinimumSize().width() != kUnboundedSize || 46 const gfx::Size min_size = GetMinimumSize();
32 GetMinimumSize().height() != kUnboundedSize; 47 return min_size.width() != kUnboundedSize ||
48 min_size.height() != kUnboundedSize;
33 } 49 }
34 50
35 bool SizeConstraints::HasMaximumSize() const { 51 bool SizeConstraints::HasMaximumSize() const {
36 const gfx::Size max_size = GetMaximumSize(); 52 const gfx::Size max_size = GetMaximumSize();
37 return max_size.width() != kUnboundedSize || 53 return max_size.width() != kUnboundedSize ||
38 max_size.height() != kUnboundedSize; 54 max_size.height() != kUnboundedSize;
39 } 55 }
40 56
41 bool SizeConstraints::HasFixedSize() const { 57 bool SizeConstraints::HasFixedSize() const {
42 return !GetMinimumSize().IsEmpty() && GetMinimumSize() == GetMaximumSize(); 58 return !GetMinimumSize().IsEmpty() && GetMinimumSize() == GetMaximumSize();
(...skipping 15 matching lines...) Expand all
58 74
59 void SizeConstraints::set_minimum_size(const gfx::Size& min_size) { 75 void SizeConstraints::set_minimum_size(const gfx::Size& min_size) {
60 minimum_size_ = min_size; 76 minimum_size_ = min_size;
61 } 77 }
62 78
63 void SizeConstraints::set_maximum_size(const gfx::Size& max_size) { 79 void SizeConstraints::set_maximum_size(const gfx::Size& max_size) {
64 maximum_size_ = max_size; 80 maximum_size_ = max_size;
65 } 81 }
66 82
67 } // namespace apps 83 } // namespace apps
OLDNEW
« no previous file with comments | « apps/size_constraints.h ('k') | apps/ui/native_app_window.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698