location_bar_layout.h revision 90dce4d38c5ff5333bea97d859d4e484e27edf0c
1// Copyright 2013 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_LOCATION_BAR_LOCATION_BAR_LAYOUT_H_
6#define CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_LOCATION_BAR_LAYOUT_H_
7
8#include "base/memory/scoped_vector.h"
9
10namespace gfx {
11class Rect;
12}
13
14namespace views {
15class View;
16}
17
18struct LocationBarDecoration;
19
20// Helper class used to layout a list of decorations inside the omnibox.
21class LocationBarLayout {
22
23 public:
24  enum Position {
25    LEFT_EDGE = 0,
26    RIGHT_EDGE,
27  };
28
29  LocationBarLayout(Position position,
30                    int item_edit_padding,
31                    int edge_edit_padding);
32  virtual ~LocationBarLayout();
33
34  // Add a decoration, specifying:
35  // - The |y| position inside its parent;
36  // - The |height| in pixel, 0 meaning the preferred height of the |view|;
37  // - Whether the decoration should |auto_collapse| if there is no room for it;
38  // - The |max_fraction| it can use within the omnibox, or 0 for non-resizable
39  //   decorations;
40  // - |edge_item_padding|, the padding between the omnibox edge and the item,
41  //   if the item is the first one drawn;
42  // - |item_padding|, the padding between the previous item and this one;
43  // - |builtin_padding|, any padding directly built into the item;
44  // - The |view| corresponding to this decoration, a weak pointer.
45  // Note that |auto_collapse| can be true if and only if |max_fraction| is 0.
46  void AddDecoration(int y,
47                     int height,
48                     bool auto_collapse,
49                     double max_fraction,
50                     int edge_item_padding,
51                     int item_padding,
52                     int builtin_padding,
53                     views::View* view);
54
55  // Add a non-resizable decoration with standard padding.
56  void AddDecoration(int y, int height, int builtin_padding, views::View* view);
57
58  void AddSeparator(int y,
59                    int height,
60                    int padding_from_previous_item,
61                    views::View* separator);
62
63  // First pass of decoration layout process. Pass the full width of the
64  // location bar in |entry_width|. This pass will adjust it to account for
65  // non-collapsible and non-resizable decorations.
66  void LayoutPass1(int* entry_width);
67
68  // Second pass of decoration layout process. Pass the |entry_width| computed
69  // by the first pass. This pass will adjust it to account for resizable
70  // decorations.
71  void LayoutPass2(int* entry_width);
72
73  // Third and final pass of decoration layout process. Pass the |bounds|
74  // corresponding to the entire space available in the location bar. This pass
75  // will update it as decorations are laid out. |available_width| measures the
76  // empty space within the location bar, taking the decorations and text into
77  // account. |decorations| must always be ordered from the edge of the location
78  // bar towards the middle.
79  void LayoutPass3(gfx::Rect* bounds, int* available_width);
80
81  // Sets the padding between edit and the decoration beside it.
82  // This value must not be modified after LayoutPass1 has been called.
83  void set_item_edit_padding(int item_edit_padding) {
84    item_edit_padding_ = item_edit_padding;
85  }
86
87 private:
88  typedef ScopedVector<LocationBarDecoration> Decorations;
89
90  void SetVisibilityForDecorations(int* available_width);
91  void HideUnneededSeparators(int* available_width);
92  void SetBoundsForDecorations(gfx::Rect* bounds);
93
94  // LEFT_EDGE means decorations are added from left to right and stacked on
95  // the left of the omnibox, RIGHT_EDGE means the opposite.
96  Position position_;
97
98  // The padding between the last decoration and the edit box.
99  int item_edit_padding_;
100
101  // The padding between the edge and the edit box, if there are no decorations.
102  int edge_edit_padding_;
103
104  // The list of decorations to layout.
105  Decorations decorations_;
106
107  DISALLOW_COPY_AND_ASSIGN(LocationBarLayout);
108};
109
110#endif  // CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_LOCATION_BAR_LAYOUT_H_
111