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

Unified Diff: ui/views/layout/layout_provider.cc

Issue 2758323002: Broke out layout metric information from ViewsDelegate to LayoutProvider (Closed)
Patch Set: LayoutDelegate -> LayoutProvider Created 3 years, 8 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: ui/views/layout/layout_provider.cc
diff --git a/ui/views/layout/layout_provider.cc b/ui/views/layout/layout_provider.cc
new file mode 100644
index 0000000000000000000000000000000000000000..580a424922fa3db6ebeb47ee7a5830e675b53cfa
--- /dev/null
+++ b/ui/views/layout/layout_provider.cc
@@ -0,0 +1,77 @@
+// Copyright 2017 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 "ui/views/layout/layout_provider.h"
+
+#include "base/logging.h"
+#include "base/memory/ptr_util.h"
+#include "ui/base/material_design/material_design_controller.h"
+#include "ui/views/layout/layout_constants.h"
+#include "ui/views/views_delegate.h"
+
+namespace views {
+
+namespace {
+static LayoutProvider* g_layout_delegate = nullptr;
sky 2017/04/12 22:43:57 We generally don't use static in cases like this.
kylix_rd 2017/04/13 16:45:42 Done.
+}
+
+LayoutProvider::LayoutProvider() {
+ g_layout_delegate = this;
sky 2017/04/12 22:43:57 DCHECK(g_layout_delegate == nullptr)?
kylix_rd 2017/04/13 16:45:42 This cannot be done because there are cases where
+}
+
+LayoutProvider::~LayoutProvider() {
+ if (this == g_layout_delegate)
+ g_layout_delegate = nullptr;
+}
+
+// static
+LayoutProvider* LayoutProvider::Get() {
+ return g_layout_delegate;
+}
+
+gfx::Insets LayoutProvider::GetInsetsMetric(int metric) const {
+ DCHECK_LT(metric, VIEWS_INSETS_MAX);
+ switch (metric) {
+ case InsetsMetric::INSETS_DIALOG_BUTTON:
+ return gfx::Insets(0, kButtonHEdgeMarginNew, kButtonVEdgeMarginNew,
+ kButtonHEdgeMarginNew);
+ case InsetsMetric::INSETS_DIALOG_TITLE:
+ return gfx::Insets(kPanelVertMargin, kButtonHEdgeMarginNew, 0,
+ kButtonHEdgeMarginNew);
+ case InsetsMetric::INSETS_BUBBLE_CONTENTS:
+ return gfx::Insets(kPanelVertMargin, kPanelHorizMargin);
+ case InsetsMetric::INSETS_PANEL:
+ return gfx::Insets(kPanelVertMargin, kButtonHEdgeMarginNew);
+ case InsetsMetric::INSETS_VECTOR_IMAGE_BUTTON:
+ return gfx::Insets(kVectorButtonExtraTouchSize);
+ }
+ NOTREACHED();
+ return gfx::Insets();
+}
+
+int LayoutProvider::GetDistanceMetric(int metric) const {
+ DCHECK_GE(metric, VIEWS_INSETS_MAX);
+ switch (metric) {
+ case DistanceMetric::DISTANCE_CLOSE_BUTTON_MARGIN:
+ return kCloseButtonMargin;
+ case DistanceMetric::DISTANCE_RELATED_BUTTON_HORIZONTAL:
+ return kRelatedButtonHSpacing;
+ case DistanceMetric::DISTANCE_RELATED_CONTROL_HORIZONTAL:
+ return kRelatedControlHorizontalSpacing;
+ case DistanceMetric::DISTANCE_RELATED_CONTROL_VERTICAL:
+ return kRelatedControlVerticalSpacing;
+ case DistanceMetric::DISTANCE_DIALOG_BUTTON_MINIMUM_WIDTH:
+ return kDialogMinimumButtonWidth;
+ case DistanceMetric::DISTANCE_BUTTON_HORIZONTAL_PADDING:
+ return kButtonHorizontalPadding;
+ }
+ NOTREACHED();
+ return 0;
+}
+
+const TypographyProvider& LayoutProvider::GetTypographyProvider() const {
+ return typography_provider_;
+}
+
+} // namespace views

Powered by Google App Engine
This is Rietveld 408576698