Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / ui / views / location_bar / location_bar_layout.h
blobdd008fb227901b13933b305c39ab0614203a900f
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.
5 #ifndef CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_LOCATION_BAR_LAYOUT_H_
6 #define CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_LOCATION_BAR_LAYOUT_H_
8 #include "base/memory/scoped_vector.h"
10 namespace gfx {
11 class Rect;
14 namespace views {
15 class View;
18 struct LocationBarDecoration;
20 // Helper class used to layout a list of decorations inside the omnibox.
21 class LocationBarLayout {
23 public:
24 enum Position {
25 LEFT_EDGE = 0,
26 RIGHT_EDGE,
29 LocationBarLayout(Position position, int item_padding, int item_edit_padding);
30 virtual ~LocationBarLayout();
32 // Add a decoration, specifying:
33 // - The |y| position inside its parent;
34 // - The |height| in pixel, 0 meaning the preferred height of the |view|;
35 // - Whether the decoration should |auto_collapse| if there is no room for it;
36 // - The |max_fraction| it can use within the omnibox, or 0 for non-resizable
37 // decorations;
38 // - |edge_item_padding|, the padding between the omnibox edge and the item,
39 // if the item is the first one drawn;
40 // - |item_padding|, the padding between the previous item and this one;
41 // - The |view| corresponding to this decoration, a weak pointer.
42 // Note that |auto_collapse| can be true if and only if |max_fraction| is 0.
43 void AddDecoration(int y,
44 int height,
45 bool auto_collapse,
46 double max_fraction,
47 int edge_item_padding,
48 int item_padding,
49 views::View* view);
51 // Add a non-resizable decoration with standard padding.
52 void AddDecoration(int y, int height, views::View* view);
54 // First pass of decoration layout process. Pass the full width of the
55 // location bar in |entry_width|. This pass will adjust it to account for
56 // non-collapsible and non-resizable decorations.
57 void LayoutPass1(int* entry_width);
59 // Second pass of decoration layout process. Pass the |entry_width| computed
60 // by the first pass. This pass will adjust it to account for resizable
61 // decorations.
62 void LayoutPass2(int* entry_width);
64 // Third and final pass of decoration layout process. Pass the |bounds|
65 // corresponding to the entire space available in the location bar. This pass
66 // will update it as decorations are laid out. |available_width| measures the
67 // empty space within the location bar, taking the decorations and text into
68 // account. |decorations| must always be ordered from the edge of the location
69 // bar towards the middle.
70 void LayoutPass3(gfx::Rect* bounds, int* available_width);
72 private:
73 typedef ScopedVector<LocationBarDecoration> Decorations;
75 // LEFT_EDGE means decorations are added from left to right and stacked on
76 // the left of the omnibox, RIGHT_EDGE means the opposite.
77 Position position_;
79 // The default padding between items.
80 int item_padding_;
82 // The padding between the last decoration and the edit box.
83 int item_edit_padding_;
85 // The list of decorations to layout.
86 Decorations decorations_;
88 DISALLOW_COPY_AND_ASSIGN(LocationBarLayout);
91 #endif // CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_LOCATION_BAR_LAYOUT_H_