location_bar_layout.h revision 868fa2fe829687343ffae624259930155e16dbd8
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, int item_edit_padding); 30 virtual ~LocationBarLayout(); 31 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 // - |builtin_padding|, any padding directly built into the item; 42 // - The |view| corresponding to this decoration, a weak pointer. 43 // Note that |auto_collapse| can be true if and only if |max_fraction| is 0. 44 void AddDecoration(int y, 45 int height, 46 bool auto_collapse, 47 double max_fraction, 48 int edge_item_padding, 49 int item_padding, 50 int builtin_padding, 51 views::View* view); 52 53 // Add a non-resizable decoration with standard padding. 54 void AddDecoration(int y, int height, int builtin_padding, views::View* view); 55 56 void AddSeparator(int y, 57 int height, 58 int padding_from_previous_item, 59 views::View* separator); 60 61 // First pass of decoration layout process. Pass the full width of the 62 // location bar in |entry_width|. This pass will adjust it to account for 63 // non-collapsible and non-resizable decorations. 64 void LayoutPass1(int* entry_width); 65 66 // Second pass of decoration layout process. Pass the |entry_width| computed 67 // by the first pass. This pass will adjust it to account for resizable 68 // decorations. 69 void LayoutPass2(int* entry_width); 70 71 // Third and final pass of decoration layout process. Pass the |bounds| 72 // corresponding to the entire space available in the location bar. This pass 73 // will update it as decorations are laid out. |available_width| measures the 74 // empty space within the location bar, taking the decorations and text into 75 // account. |decorations| must always be ordered from the edge of the location 76 // bar towards the middle. 77 void LayoutPass3(gfx::Rect* bounds, int* available_width); 78 79 // Sets the padding between edit and the decoration beside it. 80 // This value must not be modified after LayoutPass1 has been called. 81 void set_item_edit_padding(int item_edit_padding) { 82 item_edit_padding_ = item_edit_padding; 83 } 84 85 private: 86 typedef ScopedVector<LocationBarDecoration> Decorations; 87 88 void SetVisibilityForDecorations(int* available_width); 89 void HideUnneededSeparators(int* available_width); 90 void SetBoundsForDecorations(gfx::Rect* bounds); 91 92 // LEFT_EDGE means decorations are added from left to right and stacked on 93 // the left of the omnibox, RIGHT_EDGE means the opposite. 94 Position position_; 95 96 // The padding between the last decoration and the edit box. 97 int item_edit_padding_; 98 99 // The list of decorations to layout. 100 Decorations decorations_; 101 102 DISALLOW_COPY_AND_ASSIGN(LocationBarLayout); 103}; 104 105#endif // CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_LOCATION_BAR_LAYOUT_H_ 106