1 // Copyright 2016 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 #ifndef CHROME_BROWSER_UI_VIEWS_CHROME_LAYOUT_PROVIDER_H_
6 #define CHROME_BROWSER_UI_VIEWS_CHROME_LAYOUT_PROVIDER_H_
7 
8 #include <memory>
9 
10 #include "base/macros.h"
11 #include "chrome/browser/ui/views/chrome_typography_provider.h"
12 #include "ui/gfx/geometry/insets.h"
13 #include "ui/gfx/geometry/size.h"
14 #include "ui/views/layout/grid_layout.h"
15 #include "ui/views/layout/layout_provider.h"
16 
17 enum ChromeInsetsMetric {
18   // Padding around buttons on the bookmarks bar.
19   INSETS_BOOKMARKS_BAR_BUTTON = views::VIEWS_INSETS_END,
20   // Margins used by toasts.
21   INSETS_TOAST,
22   // Padding used in an omnibox pill button.
23   INSETS_OMNIBOX_PILL_BUTTON,
24 };
25 
26 enum ChromeDistanceMetric {
27   // Default minimum width of a button.
28   DISTANCE_BUTTON_MINIMUM_WIDTH = views::VIEWS_DISTANCE_END,
29   // Vertical spacing at the beginning and end of a content list (a vertical
30   // stack of composite views that behaves like a menu) containing one item.
31   DISTANCE_CONTENT_LIST_VERTICAL_SINGLE,
32   // Same as |DISTANCE_CONTENT_LIST_VERTICAL_SINGLE|, but used at the beginning
33   // and end of a multi-item content list.
34   DISTANCE_CONTENT_LIST_VERTICAL_MULTI,
35   // Vertical spacing between a list of multiple controls in one column.
36   DISTANCE_CONTROL_LIST_VERTICAL,
37   // Width of the space in a dropdown button between its label and down arrow.
38   DISTANCE_DROPDOWN_BUTTON_LABEL_ARROW_SPACING,
39   // Width of the horizontal padding in a dropdown button between the down arrow
40   // and the button's border.
41   DISTANCE_DROPDOWN_BUTTON_RIGHT_MARGIN,
42   // Smaller horizontal spacing between other controls that are logically
43   // related.
44   DISTANCE_RELATED_CONTROL_HORIZONTAL_SMALL,
45   // Smaller vertical spacing between controls that are logically related.
46   DISTANCE_RELATED_CONTROL_VERTICAL_SMALL,
47   // Horizontal spacing between an item and the related label, in the context of
48   // a row of such items. E.g. the bookmarks bar.
49   DISTANCE_RELATED_LABEL_HORIZONTAL_LIST,
50   // Horizontal indent of a subsection relative to related items above, e.g.
51   // checkboxes below explanatory text/headings.
52   DISTANCE_SUBSECTION_HORIZONTAL_INDENT,
53   // Vertical margin for controls in a toast.
54   DISTANCE_TOAST_CONTROL_VERTICAL,
55   // Vertical margin for labels in a toast.
56   DISTANCE_TOAST_LABEL_VERTICAL,
57   // Horizontal spacing between controls that are logically unrelated.
58   DISTANCE_UNRELATED_CONTROL_HORIZONTAL,
59   // Larger horizontal spacing between unrelated controls.
60   DISTANCE_UNRELATED_CONTROL_HORIZONTAL_LARGE,
61   // Larger vertical spacing between unrelated controls.
62   DISTANCE_UNRELATED_CONTROL_VERTICAL_LARGE,
63   // Width of larger modal dialogs that require extra width.
64   DISTANCE_LARGE_MODAL_DIALOG_PREFERRED_WIDTH,
65   // Width and height of a vector icon in a bubble's header (i.e. the one
66   // returned from GetWindowIcon).
67   DISTANCE_BUBBLE_HEADER_VECTOR_ICON_SIZE,
68   // Width of a bubble that appears mid-screen (like a standalone dialog)
69   // instead of being anchored.
70   DISTANCE_STANDALONE_BUBBLE_PREFERRED_WIDTH,
71   // Horizontal spacing between value and description in the row.
72   DISTANCE_BETWEEN_PRIMARY_AND_SECONDARY_LABELS_HORIZONTAL,
73   // Vertical padding at the top and bottom of the an omnibox match row.
74   DISTANCE_OMNIBOX_CELL_VERTICAL_PADDING,
75   // Vertical padding at the top and bottom of the an omnibox match row for two
76   // line layout.
77   DISTANCE_OMNIBOX_TWO_LINE_CELL_VERTICAL_PADDING,
78 };
79 
80 class ChromeLayoutProvider : public views::LayoutProvider {
81  public:
82   ChromeLayoutProvider();
83   ~ChromeLayoutProvider() override;
84 
85   static ChromeLayoutProvider* Get();
86   static std::unique_ptr<views::LayoutProvider> CreateLayoutProvider();
87 
88   // views::LayoutProvider:
89   gfx::Insets GetInsetsMetric(int metric) const override;
90   int GetDistanceMetric(int metric) const override;
91   int GetSnappedDialogWidth(int min_width) const override;
92   const views::TypographyProvider& GetTypographyProvider() const override;
93   gfx::ShadowValues MakeShadowValues(int elevation,
94                                      SkColor color) const override;
95 
96   // Returns the alignment used for control labels in a GridLayout; for example,
97   // in this GridLayout:
98   //   ---------------------------
99   //   | Label 1      Checkbox 1 |
100   //   | Label 2      Checkbox 2 |
101   //   ---------------------------
102   // This value controls the alignment used for "Label 1" and "Label 2".
103   virtual views::GridLayout::Alignment GetControlLabelGridAlignment() const;
104 
105   // Returns whether to show the icon next to the title text on a dialog.
106   virtual bool ShouldShowWindowIcon() const;
107 
108  private:
109   const ChromeTypographyProvider typography_provider_;
110 
111   DISALLOW_COPY_AND_ASSIGN(ChromeLayoutProvider);
112 };
113 
114 #endif  // CHROME_BROWSER_UI_VIEWS_CHROME_LAYOUT_PROVIDER_H_
115