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_layout_delegate.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "base/memory/ptr_util.h" | |
| 9 #include "chrome/browser/ui/views/harmony/chrome_typography.h" | |
| 10 #include "chrome/browser/ui/views/harmony/harmony_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 ChromeLayoutDelegate* layout_delegate_ = nullptr; | |
|
Peter Kasting
2017/04/06 08:13:36
You didn't answer my previous question about wheth
kylix_rd
2017/04/06 16:48:19
Sorry 'bout that. Lots of comments and things to w
| |
| 16 } | |
| 17 | |
| 18 ChromeLayoutDelegate::ChromeLayoutDelegate() { | |
| 19 layout_delegate_ = this; | |
| 20 } | |
| 21 | |
| 22 ChromeLayoutDelegate::~ChromeLayoutDelegate() { | |
| 23 if (this == layout_delegate_) | |
| 24 layout_delegate_ = nullptr; | |
| 25 } | |
| 26 | |
| 27 // static | |
| 28 ChromeLayoutDelegate* ChromeLayoutDelegate::Get() { | |
| 29 return layout_delegate_; | |
| 30 } | |
| 31 | |
| 32 // static | |
| 33 std::unique_ptr<views::LayoutDelegate> | |
| 34 ChromeLayoutDelegate::CreateLayoutDelegate() { | |
| 35 return ui::MaterialDesignController::IsSecondaryUiMaterial() | |
| 36 ? base::MakeUnique<HarmonyLayoutDelegate>() | |
| 37 : base::MakeUnique<ChromeLayoutDelegate>(); | |
| 38 } | |
| 39 | |
| 40 gfx::Insets ChromeLayoutDelegate::GetInsetsMetric( | |
| 41 ChromeInsetsMetric metric) const { | |
| 42 return views::LayoutDelegate::GetInsetsMetric( | |
| 43 static_cast<views::InsetsMetric>(metric)); | |
| 44 } | |
| 45 | |
| 46 int ChromeLayoutDelegate::GetDistanceMetric(ChromeDistanceMetric metric) const { | |
| 47 switch (metric) { | |
| 48 case ChromeDistanceMetric::BUTTON_HORIZONTAL_PADDING: | |
| 49 case ChromeDistanceMetric::CLOSE_BUTTON_MARGIN: | |
| 50 case ChromeDistanceMetric::DIALOG_BUTTON_MINIMUM_WIDTH: | |
| 51 case ChromeDistanceMetric::RELATED_BUTTON_HORIZONTAL: | |
| 52 case ChromeDistanceMetric::RELATED_CONTROL_HORIZONTAL: | |
| 53 case ChromeDistanceMetric::RELATED_CONTROL_VERTICAL: | |
| 54 return views::LayoutDelegate::GetDistanceMetric( | |
| 55 static_cast<views::DistanceMetric>(metric)); | |
| 56 | |
| 57 case ChromeDistanceMetric::RELATED_CONTROL_HORIZONTAL_SMALL: | |
| 58 return views::kRelatedControlSmallHorizontalSpacing; | |
| 59 case ChromeDistanceMetric::RELATED_CONTROL_VERTICAL_SMALL: | |
| 60 return views::kRelatedControlSmallVerticalSpacing; | |
| 61 case ChromeDistanceMetric::DIALOG_BUTTON_MARGIN: | |
| 62 return views::kButtonHEdgeMarginNew; | |
| 63 case ChromeDistanceMetric::DIALOG_BUTTON_TOP: | |
| 64 return 0; | |
| 65 case ChromeDistanceMetric::BUTTON_MAX_LINKABLE_WIDTH: | |
| 66 return 0; | |
| 67 case ChromeDistanceMetric::BUTTON_MINIMUM_WIDTH: | |
| 68 return views::kMinimumButtonWidth; | |
| 69 case ChromeDistanceMetric::RELATED_LABEL_HORIZONTAL: | |
| 70 return views::kItemLabelSpacing; | |
| 71 case ChromeDistanceMetric::SUBSECTION_HORIZONTAL_INDENT: | |
| 72 return views::kCheckboxIndent; | |
| 73 case ChromeDistanceMetric::PANEL_CONTENT_MARGIN: | |
| 74 return views::kPanelHorizMargin; | |
| 75 case ChromeDistanceMetric::UNRELATED_CONTROL_HORIZONTAL: | |
| 76 return views::kUnrelatedControlHorizontalSpacing; | |
| 77 case ChromeDistanceMetric::UNRELATED_CONTROL_HORIZONTAL_LARGE: | |
| 78 return views::kUnrelatedControlLargeHorizontalSpacing; | |
| 79 case ChromeDistanceMetric::UNRELATED_CONTROL_VERTICAL: | |
| 80 return views::kUnrelatedControlVerticalSpacing; | |
| 81 case ChromeDistanceMetric::UNRELATED_CONTROL_VERTICAL_LARGE: | |
| 82 return views::kUnrelatedControlLargeVerticalSpacing; | |
| 83 } | |
| 84 NOTREACHED(); | |
| 85 return 0; | |
| 86 } | |
| 87 | |
| 88 const views::TypographyProvider& ChromeLayoutDelegate::GetTypographyProvider() | |
| 89 const { | |
| 90 // This is not a data member because then HarmonyLayoutDelegate would inherit | |
| 91 // it, even when it provides its own. | |
| 92 CR_DEFINE_STATIC_LOCAL(LegacyTypographyProvider, legacy_provider, ()); | |
| 93 return legacy_provider; | |
| 94 } | |
| 95 | |
| 96 views::GridLayout::Alignment | |
| 97 ChromeLayoutDelegate::GetControlLabelGridAlignment() const { | |
| 98 return views::GridLayout::TRAILING; | |
| 99 } | |
| 100 | |
| 101 bool ChromeLayoutDelegate::UseExtraDialogPadding() const { | |
| 102 return true; | |
| 103 } | |
| 104 | |
| 105 bool ChromeLayoutDelegate::ShouldShowWindowIcon() const { | |
| 106 return true; | |
| 107 } | |
| 108 | |
| 109 bool ChromeLayoutDelegate::IsHarmonyMode() const { | |
| 110 return false; | |
| 111 } | |
| 112 | |
| 113 int ChromeLayoutDelegate::GetDialogPreferredWidth(DialogWidth width) const { | |
| 114 return 0; | |
| 115 } | |
| 116 | |
| 117 gfx::Insets ChromeLayoutDelegate::GetInsetsMetric( | |
| 118 views::InsetsMetric metric) const { | |
| 119 return GetInsetsMetric(static_cast<ChromeInsetsMetric>(metric)); | |
| 120 } | |
| 121 | |
| 122 int ChromeLayoutDelegate::GetDistanceMetric( | |
| 123 views::DistanceMetric metric) const { | |
| 124 return GetDistanceMetric(static_cast<ChromeDistanceMetric>(metric)); | |
| 125 } | |
| OLD | NEW |