summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/views/location_bar/location_bar_layout.h
blob: 35f084404b93d64709ec6f5a53ce477c3fed4efb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_LOCATION_BAR_LAYOUT_H_
#define CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_LOCATION_BAR_LAYOUT_H_

#include "base/memory/scoped_vector.h"

namespace gfx {
class Rect;
}

namespace views {
class View;
}

struct LocationBarDecoration;

// Helper class used to layout a list of decorations inside the omnibox.
class LocationBarLayout {

 public:
  enum Position {
    LEFT_EDGE = 0,
    RIGHT_EDGE,
  };

  LocationBarLayout(Position position, int item_edit_padding);
  virtual ~LocationBarLayout();

  // Add a decoration, specifying:
  // - The |y| position inside its parent;
  // - The |height| in pixel, 0 meaning the preferred height of the |view|;
  // - Whether the decoration should |auto_collapse| if there is no room for it;
  // - The |max_fraction| it can use within the omnibox, or 0 for non-resizable
  //   decorations;
  // - |edge_item_padding|, the padding between the omnibox edge and the item,
  //   if the item is the first one drawn;
  // - |item_padding|, the padding between the previous item and this one;
  // - The |view| corresponding to this decoration, a weak pointer.
  // Note that |auto_collapse| can be true if and only if |max_fraction| is 0.
  void AddDecoration(int y,
                     int height,
                     bool auto_collapse,
                     double max_fraction,
                     int edge_item_padding,
                     int item_padding,
                     views::View* view);

  // Add a non-resizable decoration with standard padding.
  void AddDecoration(int y, int height, views::View* view);

  // First pass of decoration layout process. Pass the full width of the
  // location bar in |entry_width|. This pass will adjust it to account for
  // non-collapsible and non-resizable decorations.
  void LayoutPass1(int* entry_width);

  // Second pass of decoration layout process. Pass the |entry_width| computed
  // by the first pass. This pass will adjust it to account for resizable
  // decorations.
  void LayoutPass2(int* entry_width);

  // Third and final pass of decoration layout process. Pass the |bounds|
  // corresponding to the entire space available in the location bar. This pass
  // will update it as decorations are laid out. |available_width| measures the
  // empty space within the location bar, taking the decorations and text into
  // account. |decorations| must always be ordered from the edge of the location
  // bar towards the middle.
  void LayoutPass3(gfx::Rect* bounds, int* available_width);

 private:
  typedef ScopedVector<LocationBarDecoration> Decorations;

  // LEFT_EDGE means decorations are added from left to right and stacked on
  // the left of the omnibox, RIGHT_EDGE means the opposite.
  Position position_;

  // The padding between the last decoration and the edit box.
  int item_edit_padding_;

  // The list of decorations to layout.
  Decorations decorations_;

  DISALLOW_COPY_AND_ASSIGN(LocationBarLayout);
};

#endif  // CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_LOCATION_BAR_LAYOUT_H_