Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/ui/views/harmony/chrome_views_layout_delegate.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "base/memory/ptr_util.h" | |
| 9 #include "chrome/browser/ui/views/harmony/layout_delegate.h" | |
| 10 // #include "chrome/browser/ui/views/harmony/harmony_views_layout_delegate.h" | |
| 11 #include "ui/base/material_design/material_design_controller.h" | |
| 12 #include "ui/views/layout/layout_constants.h" | |
| 13 | |
| 14 namespace { | |
| 15 | |
| 16 ChromeViewsLayoutDelegate* layout_delegate_ = nullptr; | |
| 17 } | |
| 18 | |
| 19 ChromeViewsLayoutDelegate::ChromeViewsLayoutDelegate() { | |
| 20 DCHECK(!layout_delegate_); | |
| 21 layout_delegate_ = this; | |
| 22 } | |
| 23 | |
| 24 ChromeViewsLayoutDelegate::~ChromeViewsLayoutDelegate() { | |
| 25 DCHECK_EQ(this, layout_delegate_); | |
| 26 layout_delegate_ = nullptr; | |
| 27 } | |
| 28 | |
| 29 // static | |
| 30 ChromeViewsLayoutDelegate* ChromeViewsLayoutDelegate::Get() { | |
| 31 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
| |
| 32 } | |
| 33 | |
| 34 // static | |
| 35 std::unique_ptr<views::ViewsLayoutDelegate> | |
| 36 ChromeViewsLayoutDelegate::CreateLayoutDelegate() { | |
| 37 return ui::MaterialDesignController::IsSecondaryUiMaterial() | |
| 38 ? base::MakeUnique<ChromeViewsLayoutDelegate>() | |
| 39 : base::MakeUnique<ChromeViewsLayoutDelegate>(); | |
| 40 } | |
| 41 | |
| 42 gfx::Insets ChromeViewsLayoutDelegate::GetInsetsMetric( | |
| 43 ChromeInsetsMetric metric) const { | |
| 44 const LayoutDelegate* layout_delegate = LayoutDelegate::Get(); | |
| 45 switch (metric) { | |
| 46 case ChromeInsetsMetric::DIALOG_BUTTON: { | |
| 47 const int top = layout_delegate->GetMetric( | |
| 48 LayoutDelegate::Metric::DIALOG_BUTTON_TOP_SPACING); | |
| 49 const int margin = layout_delegate->GetMetric( | |
| 50 LayoutDelegate::Metric::DIALOG_BUTTON_MARGIN); | |
| 51 return gfx::Insets(top, margin, margin, margin); | |
| 52 } | |
| 53 case ChromeInsetsMetric::DIALOG_FRAME_VIEW: { | |
| 54 const int top = layout_delegate->GetMetric( | |
| 55 LayoutDelegate::Metric::PANEL_CONTENT_MARGIN); | |
| 56 const int side = layout_delegate->GetMetric( | |
| 57 LayoutDelegate::Metric::DIALOG_BUTTON_MARGIN); | |
| 58 // Titles are inset at the top and sides, but not at the bottom. | |
| 59 return gfx::Insets(top, side, 0, side); | |
| 60 } | |
| 61 case ChromeInsetsMetric::BUBBLE_DIALOG: | |
| 62 return gfx::Insets(layout_delegate->GetMetric( | |
| 63 LayoutDelegate::Metric::PANEL_CONTENT_MARGIN)); | |
| 64 case ChromeInsetsMetric::PANEL_LAYOUT: | |
| 65 return gfx::Insets( | |
| 66 GetDistanceMetric(ChromeDistanceMetric::PANEL_CONTENT_MARGIN), | |
| 67 GetDistanceMetric(ChromeDistanceMetric::DIALOG_BUTTON_MARGIN)); | |
| 68 } | |
| 69 NOTREACHED(); | |
| 70 return gfx::Insets(); | |
| 71 } | |
| 72 | |
| 73 int ChromeViewsLayoutDelegate::GetDistanceMetric( | |
| 74 ChromeDistanceMetric metric) const { | |
| 75 switch (metric) { | |
| 76 case ChromeDistanceMetric::CLOSE_BUTTON_MARGIN: | |
| 77 return LayoutDelegate::Get()->GetMetric( | |
| 78 LayoutDelegate::Metric::DIALOG_CLOSE_BUTTON_MARGIN); | |
| 79 case ChromeDistanceMetric::RELATED_BUTTON_HORIZONTAL: | |
| 80 return LayoutDelegate::Get()->GetMetric( | |
| 81 LayoutDelegate::Metric::RELATED_BUTTON_HORIZONTAL_SPACING); | |
| 82 case ChromeDistanceMetric::RELATED_CONTROL_HORIZONTAL: | |
| 83 return LayoutDelegate::Get()->GetMetric( | |
| 84 LayoutDelegate::Metric::RELATED_CONTROL_HORIZONTAL_SPACING); | |
| 85 case ChromeDistanceMetric::RELATED_CONTROL_VERTICAL: | |
| 86 return LayoutDelegate::Get()->GetMetric( | |
| 87 LayoutDelegate::Metric::RELATED_CONTROL_VERTICAL_SPACING); | |
| 88 case ChromeDistanceMetric::DIALOG_BUTTON_MARGIN: | |
| 89 return LayoutDelegate::Get()->GetMetric( | |
| 90 LayoutDelegate::Metric::DIALOG_BUTTON_MARGIN); | |
| 91 case ChromeDistanceMetric::DIALOG_BUTTON_MINIMUM_WIDTH: | |
| 92 return LayoutDelegate::Get()->GetMetric( | |
| 93 LayoutDelegate::Metric::DIALOG_BUTTON_MINIMUM_WIDTH); | |
| 94 case ChromeDistanceMetric::BUTTON_HORIZONTAL_PADDING: | |
| 95 return LayoutDelegate::Get()->GetMetric( | |
| 96 LayoutDelegate::Metric::BUTTON_HORIZONTAL_PADDING); | |
| 97 case ChromeDistanceMetric::BUTTON_MAX_LINKABLE_WIDTH: | |
| 98 return LayoutDelegate::Get()->GetMetric( | |
| 99 LayoutDelegate::Metric::BUTTON_MAX_LINKABLE_WIDTH); | |
| 100 case ChromeDistanceMetric::BUTTON_MINIMUM_WIDTH: | |
| 101 return LayoutDelegate::Get()->GetMetric( | |
| 102 LayoutDelegate::Metric::BUTTON_MINIMUM_WIDTH); | |
| 103 case ChromeDistanceMetric::SUBSECTION_HORIZONTAL_INDENT: | |
| 104 return LayoutDelegate::Get()->GetMetric( | |
| 105 LayoutDelegate::Metric::SUBSECTION_HORIZONTAL_INDENT); | |
| 106 case ChromeDistanceMetric::PANEL_CONTENT_MARGIN: | |
| 107 return LayoutDelegate::Get()->GetMetric( | |
| 108 LayoutDelegate::Metric::PANEL_CONTENT_MARGIN); | |
| 109 case ChromeDistanceMetric::UNRELATED_CONTROL_HORIZONTAL: | |
| 110 return LayoutDelegate::Get()->GetMetric( | |
| 111 LayoutDelegate::Metric::UNRELATED_CONTROL_HORIZONTAL_SPACING); | |
| 112 case ChromeDistanceMetric::UNRELATED_CONTROL_HORIZONTAL_LARGE: | |
| 113 return LayoutDelegate::Get()->GetMetric( | |
| 114 LayoutDelegate::Metric::UNRELATED_CONTROL_HORIZONTAL_SPACING_LARGE); | |
| 115 case ChromeDistanceMetric::UNRELATED_CONTROL_VERTICAL: | |
| 116 return LayoutDelegate::Get()->GetMetric( | |
| 117 LayoutDelegate::Metric::UNRELATED_CONTROL_VERTICAL_SPACING); | |
| 118 case ChromeDistanceMetric::UNRELATED_CONTROL_VERTICAL_LARGE: | |
| 119 return LayoutDelegate::Get()->GetMetric( | |
| 120 LayoutDelegate::Metric::UNRELATED_CONTROL_VERTICAL_SPACING_LARGE); | |
| 121 } | |
| 122 NOTREACHED(); | |
| 123 return 0; | |
| 124 } | |
| 125 | |
| 126 const views::TypographyProvider& | |
| 127 ChromeViewsLayoutDelegate::GetTypographyProvider() const { | |
| 128 return LayoutDelegate::Get()->GetTypographyProvider(); | |
| 129 } | |
| 130 | |
| 131 views::GridLayout::Alignment | |
| 132 ChromeViewsLayoutDelegate::GetControlLabelGridAlignment() const { | |
| 133 return LayoutDelegate::Get()->GetControlLabelGridAlignment(); | |
| 134 } | |
| 135 | |
| 136 bool ChromeViewsLayoutDelegate::UseExtraDialogPadding() const { | |
| 137 return LayoutDelegate::Get()->UseExtraDialogPadding(); | |
| 138 } | |
| 139 | |
| 140 bool ChromeViewsLayoutDelegate::ShouldShowWindowIcon() const { | |
| 141 return LayoutDelegate::Get()->ShouldShowWindowIcon(); | |
| 142 } | |
| 143 | |
| 144 bool ChromeViewsLayoutDelegate::IsHarmonyMode() const { | |
| 145 return false; | |
| 146 } | |
| 147 | |
| 148 int ChromeViewsLayoutDelegate::GetDialogPreferredWidth( | |
| 149 DialogWidth width) const { | |
| 150 return LayoutDelegate::Get()->GetDialogPreferredWidth( | |
| 151 static_cast<LayoutDelegate::DialogWidth>(width)); | |
| 152 } | |
| 153 | |
| 154 int ChromeViewsLayoutDelegate::GetDefaultDistanceMetric( | |
| 155 views::DistanceMetric metric) const { | |
| 156 return views::ViewsLayoutDelegate::GetDistanceMetric(metric); | |
| 157 } | |
| 158 | |
| 159 gfx::Insets ChromeViewsLayoutDelegate::GetInsetsMetric( | |
| 160 views::InsetsMetric metric) const { | |
| 161 return GetInsetsMetric(static_cast<ChromeInsetsMetric>(metric)); | |
| 162 } | |
| 163 | |
| 164 int ChromeViewsLayoutDelegate::GetDistanceMetric( | |
| 165 views::DistanceMetric metric) const { | |
| 166 return GetDistanceMetric(static_cast<ChromeDistanceMetric>(metric)); | |
| 167 } | |
| OLD | NEW |