Chromium Code Reviews| 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..a80eec8ac41512c0990c0df64289c9d4f5cd961e |
| --- /dev/null |
| +++ b/chrome/browser/ui/views/harmony/chrome_views_layout_delegate.cc |
| @@ -0,0 +1,167 @@ |
| +// 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() { |
| + DCHECK(!layout_delegate_); |
| + layout_delegate_ = this; |
| +} |
| + |
| +ChromeViewsLayoutDelegate::~ChromeViewsLayoutDelegate() { |
| + DCHECK_EQ(this, layout_delegate_); |
| + layout_delegate_ = nullptr; |
| +} |
| + |
| +// static |
| +ChromeViewsLayoutDelegate* ChromeViewsLayoutDelegate::Get() { |
| + return layout_delegate_; |
|
Peter Kasting
2017/03/24 22:51:13
It still seems like this could just be
return s
kylix_rd
2017/03/27 18:18:27
I was also trying to avoid an unsafe downcast.
Peter Kasting
2017/03/27 20:06:48
Right, that's what I was saying I didn't think was
kylix_rd
2017/03/29 18:56:04
Once I've verified that any calls to ChromeViewsLa
Peter Kasting
2017/04/04 02:08:50
Was this something you were going to do before lan
|
| +} |
| + |
| +// static |
| +std::unique_ptr<views::ViewsLayoutDelegate> |
| +ChromeViewsLayoutDelegate::CreateLayoutDelegate() { |
| + return ui::MaterialDesignController::IsSecondaryUiMaterial() |
| + ? 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_VERTICAL: |
| + return LayoutDelegate::Get()->GetMetric( |
| + LayoutDelegate::Metric::RELATED_CONTROL_VERTICAL_SPACING); |
| + 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)); |
| +} |