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

Unified Diff: chrome/browser/ui/views/harmony/chrome_views_layout_delegate.cc

Issue 2758323002: Broke out layout metric information from ViewsDelegate to LayoutProvider (Closed)
Patch Set: Fix various unit-tests Created 3 years, 9 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: chrome/browser/ui/views/harmony/chrome_views_layout_delegate.cc
diff --git a/chrome/browser/ui/views/harmony/chrome_views_layout_delegate.cc b/chrome/browser/ui/views/harmony/chrome_views_layout_delegate.cc
new file mode 100644
index 0000000000000000000000000000000000000000..6c8c25a873e8f3d423df95aa6946c2d2bbf0da7c
--- /dev/null
+++ b/chrome/browser/ui/views/harmony/chrome_views_layout_delegate.cc
@@ -0,0 +1,172 @@
+// 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 "chrome/browser/ui/views/harmony/chrome_views_layout_delegate.h"
+
+#include "base/logging.h"
+#include "base/memory/ptr_util.h"
+#include "chrome/browser/ui/views/harmony/layout_delegate.h"
+// #include "chrome/browser/ui/views/harmony/harmony_views_layout_delegate.h"
+#include "ui/base/material_design/material_design_controller.h"
+#include "ui/views/layout/layout_constants.h"
+
+namespace {
+
+ChromeViewsLayoutDelegate* layout_delegate_ = nullptr;
+}
+
+ChromeViewsLayoutDelegate::ChromeViewsLayoutDelegate() {
+ layout_delegate_ = this;
+}
+
+ChromeViewsLayoutDelegate::~ChromeViewsLayoutDelegate() {
+ if (this == layout_delegate_)
+ layout_delegate_ = nullptr;
+}
+
+// static
+ChromeViewsLayoutDelegate* ChromeViewsLayoutDelegate::Get() {
+ return layout_delegate_;
+}
+
+// static
+std::unique_ptr<views::ViewsLayoutDelegate>
+ChromeViewsLayoutDelegate::CreateLayoutDelegate() {
+ return ui::MaterialDesignController::IsSecondaryUiMaterial()
Peter Kasting 2017/03/30 00:49:04 It seems like this conditional shouldn't be here i
kylix_rd 2017/03/30 19:34:07 The plan is to eliminate the LayoutDelegate and in
Peter Kasting 2017/03/30 19:40:02 I'm OK with doing that in this CL if you want. I
+ ? base::MakeUnique<ChromeViewsLayoutDelegate>()
+ : base::MakeUnique<ChromeViewsLayoutDelegate>();
+}
+
+gfx::Insets ChromeViewsLayoutDelegate::GetInsetsMetric(
+ ChromeInsetsMetric metric) const {
+ const LayoutDelegate* layout_delegate = LayoutDelegate::Get();
+ switch (metric) {
+ case ChromeInsetsMetric::DIALOG_BUTTON: {
+ const int top = layout_delegate->GetMetric(
+ LayoutDelegate::Metric::DIALOG_BUTTON_TOP_SPACING);
+ const int margin = layout_delegate->GetMetric(
+ LayoutDelegate::Metric::DIALOG_BUTTON_MARGIN);
+ return gfx::Insets(top, margin, margin, margin);
+ }
+ case ChromeInsetsMetric::DIALOG_FRAME_VIEW: {
+ const int top = layout_delegate->GetMetric(
+ LayoutDelegate::Metric::PANEL_CONTENT_MARGIN);
+ const int side = layout_delegate->GetMetric(
+ LayoutDelegate::Metric::DIALOG_BUTTON_MARGIN);
+ // Titles are inset at the top and sides, but not at the bottom.
+ return gfx::Insets(top, side, 0, side);
+ }
+ case ChromeInsetsMetric::BUBBLE_DIALOG:
+ return gfx::Insets(layout_delegate->GetMetric(
+ LayoutDelegate::Metric::PANEL_CONTENT_MARGIN));
+ case ChromeInsetsMetric::PANEL_LAYOUT:
+ return gfx::Insets(
+ GetDistanceMetric(ChromeDistanceMetric::PANEL_CONTENT_MARGIN),
+ GetDistanceMetric(ChromeDistanceMetric::DIALOG_BUTTON_MARGIN));
+ }
+ NOTREACHED();
+ return gfx::Insets();
+}
+
+int ChromeViewsLayoutDelegate::GetDistanceMetric(
+ ChromeDistanceMetric metric) const {
+ switch (metric) {
+ case ChromeDistanceMetric::CLOSE_BUTTON_MARGIN:
+ return LayoutDelegate::Get()->GetMetric(
+ LayoutDelegate::Metric::DIALOG_CLOSE_BUTTON_MARGIN);
+ case ChromeDistanceMetric::RELATED_BUTTON_HORIZONTAL:
+ return LayoutDelegate::Get()->GetMetric(
+ LayoutDelegate::Metric::RELATED_BUTTON_HORIZONTAL_SPACING);
+ case ChromeDistanceMetric::RELATED_CONTROL_HORIZONTAL:
+ return LayoutDelegate::Get()->GetMetric(
+ LayoutDelegate::Metric::RELATED_CONTROL_HORIZONTAL_SPACING);
+ case ChromeDistanceMetric::RELATED_CONTROL_HORIZONTAL_SMALL:
+ return LayoutDelegate::Get()->GetMetric(
+ LayoutDelegate::Metric::RELATED_CONTROL_HORIZONTAL_SPACING_SMALL);
+ case ChromeDistanceMetric::RELATED_CONTROL_VERTICAL:
+ return LayoutDelegate::Get()->GetMetric(
+ LayoutDelegate::Metric::RELATED_CONTROL_VERTICAL_SPACING);
+ case ChromeDistanceMetric::RELATED_CONTROL_VERTICAL_SMALL:
+ return LayoutDelegate::Get()->GetMetric(
+ LayoutDelegate::Metric::RELATED_CONTROL_VERTICAL_SPACING_SMALL);
+ case ChromeDistanceMetric::DIALOG_BUTTON_MARGIN:
+ return LayoutDelegate::Get()->GetMetric(
+ LayoutDelegate::Metric::DIALOG_BUTTON_MARGIN);
+ case ChromeDistanceMetric::DIALOG_BUTTON_MINIMUM_WIDTH:
+ return LayoutDelegate::Get()->GetMetric(
+ LayoutDelegate::Metric::DIALOG_BUTTON_MINIMUM_WIDTH);
+ case ChromeDistanceMetric::BUTTON_HORIZONTAL_PADDING:
+ return LayoutDelegate::Get()->GetMetric(
+ LayoutDelegate::Metric::BUTTON_HORIZONTAL_PADDING);
+ case ChromeDistanceMetric::BUTTON_MAX_LINKABLE_WIDTH:
+ return LayoutDelegate::Get()->GetMetric(
+ LayoutDelegate::Metric::BUTTON_MAX_LINKABLE_WIDTH);
+ case ChromeDistanceMetric::BUTTON_MINIMUM_WIDTH:
+ return LayoutDelegate::Get()->GetMetric(
+ LayoutDelegate::Metric::BUTTON_MINIMUM_WIDTH);
+ case ChromeDistanceMetric::SUBSECTION_HORIZONTAL_INDENT:
+ return LayoutDelegate::Get()->GetMetric(
+ LayoutDelegate::Metric::SUBSECTION_HORIZONTAL_INDENT);
+ case ChromeDistanceMetric::PANEL_CONTENT_MARGIN:
+ return LayoutDelegate::Get()->GetMetric(
+ LayoutDelegate::Metric::PANEL_CONTENT_MARGIN);
+ case ChromeDistanceMetric::UNRELATED_CONTROL_HORIZONTAL:
+ return LayoutDelegate::Get()->GetMetric(
+ LayoutDelegate::Metric::UNRELATED_CONTROL_HORIZONTAL_SPACING);
+ case ChromeDistanceMetric::UNRELATED_CONTROL_HORIZONTAL_LARGE:
+ return LayoutDelegate::Get()->GetMetric(
+ LayoutDelegate::Metric::UNRELATED_CONTROL_HORIZONTAL_SPACING_LARGE);
+ case ChromeDistanceMetric::UNRELATED_CONTROL_VERTICAL:
+ return LayoutDelegate::Get()->GetMetric(
+ LayoutDelegate::Metric::UNRELATED_CONTROL_VERTICAL_SPACING);
+ case ChromeDistanceMetric::UNRELATED_CONTROL_VERTICAL_LARGE:
+ return LayoutDelegate::Get()->GetMetric(
+ LayoutDelegate::Metric::UNRELATED_CONTROL_VERTICAL_SPACING_LARGE);
+ }
+ NOTREACHED();
+ return 0;
+}
+
+const views::TypographyProvider&
+ChromeViewsLayoutDelegate::GetTypographyProvider() const {
+ return LayoutDelegate::Get()->GetTypographyProvider();
+}
+
+views::GridLayout::Alignment
+ChromeViewsLayoutDelegate::GetControlLabelGridAlignment() const {
+ return LayoutDelegate::Get()->GetControlLabelGridAlignment();
+}
+
+bool ChromeViewsLayoutDelegate::UseExtraDialogPadding() const {
+ return LayoutDelegate::Get()->UseExtraDialogPadding();
+}
+
+bool ChromeViewsLayoutDelegate::ShouldShowWindowIcon() const {
+ return LayoutDelegate::Get()->ShouldShowWindowIcon();
+}
+
+bool ChromeViewsLayoutDelegate::IsHarmonyMode() const {
+ return false;
+}
+
+int ChromeViewsLayoutDelegate::GetDialogPreferredWidth(
+ DialogWidth width) const {
+ return LayoutDelegate::Get()->GetDialogPreferredWidth(
+ static_cast<LayoutDelegate::DialogWidth>(width));
+}
+
+int ChromeViewsLayoutDelegate::GetDefaultDistanceMetric(
+ views::DistanceMetric metric) const {
+ return views::ViewsLayoutDelegate::GetDistanceMetric(metric);
+}
+
+gfx::Insets ChromeViewsLayoutDelegate::GetInsetsMetric(
+ views::InsetsMetric metric) const {
+ return GetInsetsMetric(static_cast<ChromeInsetsMetric>(metric));
+}
+
+int ChromeViewsLayoutDelegate::GetDistanceMetric(
+ views::DistanceMetric metric) const {
+ return GetDistanceMetric(static_cast<ChromeDistanceMetric>(metric));
+}

Powered by Google App Engine
This is Rietveld 408576698