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

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: Deleted LayoutDelegate and HarmonyLayoutDelegate. 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..a73d46a0b32dad2802387b816b637488600217c1
--- /dev/null
+++ b/chrome/browser/ui/views/harmony/chrome_views_layout_delegate.cc
@@ -0,0 +1,143 @@
+// 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/chrome_typography.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 {
+
Peter Kasting 2017/04/04 02:08:52 Nit: Remove blank line
+ChromeViewsLayoutDelegate* layout_delegate_ = nullptr;
Peter Kasting 2017/04/04 02:08:53 Nit: I'd name this |g_layout_delegate| since it's
+}
+
+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()
+ ? base::MakeUnique<HarmonyViewsLayoutDelegate>()
+ : base::MakeUnique<ChromeViewsLayoutDelegate>();
+}
+
+gfx::Insets ChromeViewsLayoutDelegate::GetInsetsMetric(
+ ChromeInsetsMetric metric) const {
+ switch (metric) {
+ case ChromeInsetsMetric::DIALOG_BUTTON:
+ case ChromeInsetsMetric::DIALOG_FRAME_VIEW:
+ case ChromeInsetsMetric::BUBBLE_DIALOG:
+ case ChromeInsetsMetric::VECTOR_IMAGE_BUTTON:
+ return views::ViewsLayoutDelegate::GetInsetsMetric(
+ static_cast<views::InsetsMetric>(metric));
Peter Kasting 2017/04/04 02:08:52 Nit: A blank line below this top group (in each of
+ case ChromeInsetsMetric::PANEL_LAYOUT:
+ return gfx::Insets(views::kPanelHorizMargin,
Peter Kasting 2017/04/04 02:08:53 Nit: Shouldn't this be kPanelVertMargin?
kylix_rd 2017/04/04 20:28:23 Maybe... however, this is copied from layout_utils
Peter Kasting 2017/04/05 19:30:10 kPanelVertMargin and kPanelHorizMargin had the sam
+ views::kButtonHEdgeMarginNew);
Peter Kasting 2017/04/04 02:08:53 Nit: Seems like these should use GetDistanceMetric
+ }
+ NOTREACHED();
+ return gfx::Insets();
+}
+
+int ChromeViewsLayoutDelegate::GetDistanceMetric(
+ ChromeDistanceMetric metric) const {
+ switch (metric) {
+ case ChromeDistanceMetric::BUTTON_HORIZONTAL_PADDING:
+ case ChromeDistanceMetric::CLOSE_BUTTON_MARGIN:
+ case ChromeDistanceMetric::DIALOG_BUTTON_MINIMUM_WIDTH:
+ case ChromeDistanceMetric::RELATED_BUTTON_HORIZONTAL:
+ case ChromeDistanceMetric::RELATED_CONTROL_HORIZONTAL:
+ case ChromeDistanceMetric::RELATED_CONTROL_VERTICAL:
+ return views::ViewsLayoutDelegate::GetDistanceMetric(
+ static_cast<views::DistanceMetric>(metric));
+ case ChromeDistanceMetric::RELATED_CONTROL_HORIZONTAL_SMALL:
+ return views::kRelatedControlSmallHorizontalSpacing;
+ case ChromeDistanceMetric::RELATED_CONTROL_VERTICAL_SMALL:
+ return views::kRelatedControlSmallVerticalSpacing;
+ case ChromeDistanceMetric::DIALOG_BUTTON_MARGIN:
+ return views::kButtonHEdgeMarginNew;
+ case ChromeDistanceMetric::DIALOG_BUTTON_TOP:
+ return 0;
+ case ChromeDistanceMetric::BUTTON_MAX_LINKABLE_WIDTH:
+ return 0;
+ case ChromeDistanceMetric::BUTTON_MINIMUM_WIDTH:
+ return views::kMinimumButtonWidth;
Peter Kasting 2017/04/04 02:08:53 I think after this patch this constant is only pre
kylix_rd 2017/04/04 20:28:23 Eventually, all the views::kXXXX constants will be
+ case ChromeDistanceMetric::RELATED_LABEL_HORIZONTAL:
+ return views::kItemLabelSpacing;
+ case ChromeDistanceMetric::SUBSECTION_HORIZONTAL_INDENT:
+ return views::kCheckboxIndent;
+ case ChromeDistanceMetric::PANEL_CONTENT_MARGIN:
+ return views::kPanelHorizMargin;
+ case ChromeDistanceMetric::UNRELATED_CONTROL_HORIZONTAL:
+ return views::kUnrelatedControlHorizontalSpacing;
+ case ChromeDistanceMetric::UNRELATED_CONTROL_HORIZONTAL_LARGE:
+ return views::kUnrelatedControlLargeHorizontalSpacing;
+ case ChromeDistanceMetric::UNRELATED_CONTROL_VERTICAL:
+ return views::kUnrelatedControlVerticalSpacing;
+ case ChromeDistanceMetric::UNRELATED_CONTROL_VERTICAL_LARGE:
+ return views::kUnrelatedControlLargeVerticalSpacing;
+ }
+ NOTREACHED();
+ return 0;
+}
+
+const views::TypographyProvider&
+ChromeViewsLayoutDelegate::GetTypographyProvider() const {
+ // This is not a data member because then HarmonyLayoutDelegate would inherit
+ // it, even when it provides its own.
+ CR_DEFINE_STATIC_LOCAL(LegacyTypographyProvider, legacy_provider, ());
+ return legacy_provider;
+}
+
+views::GridLayout::Alignment
+ChromeViewsLayoutDelegate::GetControlLabelGridAlignment() const {
+ return views::GridLayout::TRAILING;
+}
+
+bool ChromeViewsLayoutDelegate::UseExtraDialogPadding() const {
+ return true;
+}
+
+bool ChromeViewsLayoutDelegate::ShouldShowWindowIcon() const {
+ return true;
+}
+
+bool ChromeViewsLayoutDelegate::IsHarmonyMode() const {
+ return false;
+}
+
+int ChromeViewsLayoutDelegate::GetDialogPreferredWidth(
+ DialogWidth width) const {
+ return 0;
+}
+
+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