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

Unified Diff: views/layout/center_layout.cc

Issue 7610011: Update Sad Tab help text and link. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix message centering. Created 9 years, 4 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 side-by-side diff with in-line comments
Download patch
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..16c5a11d4abfd33e93212ebcd5ae66a685034b9b
--- /dev/null
+++ b/views/layout/center_layout.cc
@@ -0,0 +1,56 @@
+// 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());
+ 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));
+}
+
+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

Powered by Google App Engine
This is Rietveld 408576698