| Index: chrome/browser/ui/views/harmony/chrome_layout_delegate.cc
|
| diff --git a/chrome/browser/ui/views/harmony/chrome_layout_delegate.cc b/chrome/browser/ui/views/harmony/chrome_layout_delegate.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..6d68a644d3a74a992bf2ed340510cbd3a5ae6c2e
|
| --- /dev/null
|
| +++ b/chrome/browser/ui/views/harmony/chrome_layout_delegate.cc
|
| @@ -0,0 +1,125 @@
|
| +// 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_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_layout_delegate.h"
|
| +#include "ui/base/material_design/material_design_controller.h"
|
| +#include "ui/views/layout/layout_constants.h"
|
| +
|
| +namespace {
|
| +ChromeLayoutDelegate* layout_delegate_ = nullptr;
|
| +}
|
| +
|
| +ChromeLayoutDelegate::ChromeLayoutDelegate() {
|
| + layout_delegate_ = this;
|
| +}
|
| +
|
| +ChromeLayoutDelegate::~ChromeLayoutDelegate() {
|
| + if (this == layout_delegate_)
|
| + layout_delegate_ = nullptr;
|
| +}
|
| +
|
| +// static
|
| +ChromeLayoutDelegate* ChromeLayoutDelegate::Get() {
|
| + return layout_delegate_;
|
| +}
|
| +
|
| +// static
|
| +std::unique_ptr<views::LayoutDelegate>
|
| +ChromeLayoutDelegate::CreateLayoutDelegate() {
|
| + return ui::MaterialDesignController::IsSecondaryUiMaterial()
|
| + ? base::MakeUnique<HarmonyLayoutDelegate>()
|
| + : base::MakeUnique<ChromeLayoutDelegate>();
|
| +}
|
| +
|
| +gfx::Insets ChromeLayoutDelegate::GetInsetsMetric(
|
| + ChromeInsetsMetric metric) const {
|
| + return views::LayoutDelegate::GetInsetsMetric(
|
| + static_cast<views::InsetsMetric>(metric));
|
| +}
|
| +
|
| +int ChromeLayoutDelegate::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::LayoutDelegate::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;
|
| + 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& ChromeLayoutDelegate::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
|
| +ChromeLayoutDelegate::GetControlLabelGridAlignment() const {
|
| + return views::GridLayout::TRAILING;
|
| +}
|
| +
|
| +bool ChromeLayoutDelegate::UseExtraDialogPadding() const {
|
| + return true;
|
| +}
|
| +
|
| +bool ChromeLayoutDelegate::ShouldShowWindowIcon() const {
|
| + return true;
|
| +}
|
| +
|
| +bool ChromeLayoutDelegate::IsHarmonyMode() const {
|
| + return false;
|
| +}
|
| +
|
| +int ChromeLayoutDelegate::GetDialogPreferredWidth(DialogWidth width) const {
|
| + return 0;
|
| +}
|
| +
|
| +gfx::Insets ChromeLayoutDelegate::GetInsetsMetric(
|
| + views::InsetsMetric metric) const {
|
| + return GetInsetsMetric(static_cast<ChromeInsetsMetric>(metric));
|
| +}
|
| +
|
| +int ChromeLayoutDelegate::GetDistanceMetric(
|
| + views::DistanceMetric metric) const {
|
| + return GetDistanceMetric(static_cast<ChromeDistanceMetric>(metric));
|
| +}
|
|
|