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 89
|
// Copyright 2013 The Chromium Authors
// 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 <memory>
#include <vector>
namespace gfx {
class Rect;
}
namespace views {
class View;
}
struct DecorationInfo;
// Helper class used to layout a list of decorations inside the omnibox.
class LocationBarLayout {
public:
enum class Position {
kLeftEdge,
kRightEdge,
};
LocationBarLayout(Position position, int item_edit_padding);
LocationBarLayout(const LocationBarLayout&) = delete;
LocationBarLayout& operator=(const LocationBarLayout&) = delete;
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;
// - |intra_item_padding|, the padding between the item and the previous item.
// Does not apply to the first item, which instead uses edge_item_padding.
// - |edge_item_padding|, the padding between the omnibox edge and the item,
// if the item is the first one drawn;
// - 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 intra_item_padding,
int edge_item_padding,
views::View* view);
// First pass of decoration layout process. Pass the full width of the
// location bar in `entry_width`. This pass will decrease it to account for
// non-collapsible and non-resizable decorations.
// `reserved_width` is the minimum necessary width required by the location
// bar excluding decorations. This used in preferred size calculations to
// ensure the available space constraint is calculated correctly.
void LayoutPass1(int* entry_width, int reserved_width);
// Second pass of decoration layout process. Pass the `entry_width` computed
// by the first pass. This pass will decrease 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:
// 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.
std::vector<std::unique_ptr<DecorationInfo>> decorations_;
};
#endif // CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_LOCATION_BAR_LAYOUT_H_
|