Chromium Code Reviews| Index: apps/shell_window.cc |
| diff --git a/apps/shell_window.cc b/apps/shell_window.cc |
| index 691bff8d947aaa19dc33249435b81464fc39e65f..b435376f997b8923f69d36339d5ac5d17ebd79eb 100644 |
| --- a/apps/shell_window.cc |
| +++ b/apps/shell_window.cc |
| @@ -56,6 +56,56 @@ const int kDefaultHeight = 384; |
| namespace apps { |
| +ShellWindow::SizeConstraints::SizeConstraints() |
| + : max_size_(kUnboundedSize, kUnboundedSize) { |
| +} |
| + |
| +ShellWindow::SizeConstraints::SizeConstraints(const gfx::Size& min_size, |
| + const gfx::Size& max_size) |
| + : min_size_(min_size), |
| + max_size_(max_size) { |
| +} |
| + |
| +ShellWindow::SizeConstraints::~SizeConstraints() {} |
| + |
| +gfx::Rect ShellWindow::SizeConstraints::ClampBounds( |
| + const gfx::Rect& bounds) const { |
| + gfx::Rect result(bounds); |
| + if (maximum_size().width() != kUnboundedSize) |
| + result.set_width(std::min(result.width(), maximum_size().width())); |
| + if (maximum_size().height() != kUnboundedSize) |
| + result.set_height(std::min(result.height(), maximum_size().height())); |
| + result.set_width(std::max(result.width(), minimum_size().width())); |
|
tapted
2013/10/14 03:17:10
I think this and the next line is just `result.Set
jackhou1
2013/10/14 04:13:06
SetToMax is in gfx::Size but not gfx::Rect.
tapted
2013/10/14 05:13:43
Ah. Drat. But... what about changing the function
jackhou1
2013/10/14 23:45:32
Done.
|
| + result.set_height(std::max(result.height(), minimum_size().height())); |
| + return result; |
| +} |
| + |
| +bool ShellWindow::SizeConstraints::HasMinimumSize() const { |
| + return minimum_size().width() != kUnboundedSize || |
| + minimum_size().height() != kUnboundedSize; |
|
tapted
2013/10/14 03:17:10
nit(I think): only 4 spaces of indent for these
jackhou1
2013/10/14 04:13:06
Done.
|
| +} |
| + |
| +bool ShellWindow::SizeConstraints::HasMaximumSize() const { |
| + return maximum_size().width() != kUnboundedSize || |
| + maximum_size().height() != kUnboundedSize; |
| +} |
| + |
| +bool ShellWindow::SizeConstraints::MinAndMaxEqual() const { |
| + return !minimum_size().IsEmpty() && minimum_size() == maximum_size(); |
| +} |
| + |
| +gfx::Size ShellWindow::SizeConstraints::minimum_size() const { |
| + return min_size_; |
| +} |
| + |
| +gfx::Size ShellWindow::SizeConstraints::maximum_size() const { |
| + return gfx::Size( |
| + max_size_.width() == kUnboundedSize ? |
| + kUnboundedSize : std::max(max_size_.width(), min_size_.width()), |
| + max_size_.height() == kUnboundedSize ? |
| + kUnboundedSize : std::max(max_size_.height(), min_size_.height())); |
| +} |
| + |
| ShellWindow::CreateParams::CreateParams() |
| : window_type(ShellWindow::WINDOW_TYPE_DEFAULT), |
| frame(ShellWindow::FRAME_CHROME), |
| @@ -140,27 +190,10 @@ void ShellWindow::Init(const GURL& url, |
| } |
| } |
| - gfx::Size& minimum_size = new_params.minimum_size; |
| - gfx::Size& maximum_size = new_params.maximum_size; |
| - |
| - // In the case that minimum size > maximum size, we consider the minimum |
| - // size to be more important. |
| - if (maximum_size.width() && maximum_size.width() < minimum_size.width()) |
| - maximum_size.set_width(minimum_size.width()); |
| - if (maximum_size.height() && maximum_size.height() < minimum_size.height()) |
| - maximum_size.set_height(minimum_size.height()); |
| - |
| - if (maximum_size.width() && bounds.width() > maximum_size.width()) |
| - bounds.set_width(maximum_size.width()); |
| - if (bounds.width() != INT_MIN && bounds.width() < minimum_size.width()) |
| - bounds.set_width(minimum_size.width()); |
| - |
| - if (maximum_size.height() && bounds.height() > maximum_size.height()) |
| - bounds.set_height(maximum_size.height()); |
| - if (bounds.height() != INT_MIN && bounds.height() < minimum_size.height()) |
| - bounds.set_height(minimum_size.height()); |
| - |
| - new_params.bounds = bounds; |
| + size_constraints_ = SizeConstraints(params.minimum_size, params.maximum_size); |
| + new_params.bounds = size_constraints_.ClampBounds(bounds); |
| + new_params.minimum_size = size_constraints_.minimum_size(); |
| + new_params.minimum_size = size_constraints_.maximum_size(); |
| native_app_window_.reset(delegate_->CreateNativeAppWindow(this, new_params)); |