Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011 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 "views/layout/center_layout.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 | |
| 9 namespace views { | |
| 10 | |
| 11 //////////////////////////////////////////////////////////////////////////////// | |
| 12 // CenterLayout, public: | |
| 13 | |
| 14 CenterLayout::CenterLayout() { | |
| 15 } | |
| 16 | |
| 17 CenterLayout::~CenterLayout() { | |
| 18 } | |
| 19 | |
| 20 //////////////////////////////////////////////////////////////////////////////// | |
| 21 // CenterLayout, LayoutManager implementation: | |
| 22 | |
| 23 void CenterLayout::Layout(View* host) { | |
| 24 if (!host->has_children()) | |
| 25 return; | |
| 26 | |
| 27 DCHECK_EQ(1, host->child_count()); | |
| 28 View* child = host->child_at(0); | |
| 29 gfx::Size size(child->GetPreferredSize()); | |
| 30 gfx::Rect child_area(host->GetLocalBounds()); | |
| 31 child_area.Inset(host->GetInsets()); | |
| 32 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.
| |
| 33 size.set_width(std::min(size.width(), child_area.width())); | |
| 34 int child_height = child->GetHeightForWidth(size.width()); | |
| 35 size.set_height(std::min(child_height, child_area.height())); | |
| 36 gfx::Point origin((child_area.width() - size.width()) / 2, | |
| 37 (child_area.height() - size.height()) / 2); | |
| 38 child->SetBoundsRect(gfx::Rect(origin, size)); | |
| 39 LOG(INFO) << "POsition: " << child->x() << ", " << child->y(); | |
| 40 LOG(INFO) << "Size: " << child->width() << ", " << child->height(); | |
| 41 } | |
| 42 | |
| 43 gfx::Size CenterLayout::GetPreferredSize(View* host) { | |
| 44 if (!host->has_children()) | |
| 45 return gfx::Size(); | |
| 46 | |
| 47 DCHECK_EQ(1, host->child_count()); | |
| 48 return host->child_at(0)->GetPreferredSize(); | |
| 49 } | |
| 50 | |
| 51 int CenterLayout::GetPreferredHeightForWidth(View* host, int width) { | |
| 52 if (!host->has_children()) | |
| 53 LayoutManager::GetPreferredHeightForWidth(host, width); | |
| 54 | |
| 55 DCHECK_EQ(1, host->child_count()); | |
| 56 return host->child_at(0)->GetHeightForWidth(width); | |
| 57 } | |
| 58 | |
| 59 } // namespace views | |
| OLD | NEW |