Chromium Code Reviews| Index: views/layout/center_layout.cc |
| diff --git a/views/layout/center_layout.cc b/views/layout/center_layout.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f110f5dea81d8641114e387983df27a8a3b70856 |
| --- /dev/null |
| +++ b/views/layout/center_layout.cc |
| @@ -0,0 +1,59 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "views/layout/center_layout.h" |
| + |
| +#include "base/logging.h" |
| + |
| +namespace views { |
| + |
| +//////////////////////////////////////////////////////////////////////////////// |
| +// CenterLayout, public: |
| + |
| +CenterLayout::CenterLayout() { |
| +} |
| + |
| +CenterLayout::~CenterLayout() { |
| +} |
| + |
| +//////////////////////////////////////////////////////////////////////////////// |
| +// CenterLayout, LayoutManager implementation: |
| + |
| +void CenterLayout::Layout(View* host) { |
| + if (!host->has_children()) |
| + return; |
| + |
| + DCHECK_EQ(1, host->child_count()); |
| + View* child = host->child_at(0); |
| + gfx::Size size(child->GetPreferredSize()); |
| + gfx::Rect child_area(host->GetLocalBounds()); |
| + child_area.Inset(host->GetInsets()); |
| + LOG(INFO) << "Child Area: " << child_area; |
|
Peter Kasting
2011/08/30 19:58:12
Nit: Are these LOGs still necessary? If so, use V
msw
2011/08/31 00:54:23
Removed.
|
| + size.set_width(std::min(size.width(), child_area.width())); |
| + int child_height = child->GetHeightForWidth(size.width()); |
| + size.set_height(std::min(child_height, child_area.height())); |
| + gfx::Point origin((child_area.width() - size.width()) / 2, |
| + (child_area.height() - size.height()) / 2); |
| + child->SetBoundsRect(gfx::Rect(origin, size)); |
| + LOG(INFO) << "POsition: " << child->x() << ", " << child->y(); |
| + LOG(INFO) << "Size: " << child->width() << ", " << child->height(); |
| +} |
| + |
| +gfx::Size CenterLayout::GetPreferredSize(View* host) { |
| + if (!host->has_children()) |
| + return gfx::Size(); |
| + |
| + DCHECK_EQ(1, host->child_count()); |
| + return host->child_at(0)->GetPreferredSize(); |
| +} |
| + |
| +int CenterLayout::GetPreferredHeightForWidth(View* host, int width) { |
| + if (!host->has_children()) |
| + LayoutManager::GetPreferredHeightForWidth(host, width); |
| + |
| + DCHECK_EQ(1, host->child_count()); |
| + return host->child_at(0)->GetHeightForWidth(width); |
| +} |
| + |
| +} // namespace views |