OLD | NEW |
(Empty) | |
| 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 |
| 10 namespace gfx { |
| 11 class Rect; |
| 12 } |
| 13 |
| 14 namespace views { |
| 15 class View; |
| 16 } |
| 17 |
| 18 struct LocationBarDecoration; |
| 19 |
| 20 // Helper class used to layout a list of decorations inside the omnibox. |
| 21 class 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 height, int builtin_padding, views::View* view); |
| 57 |
| 58 // First pass of decoration layout process. Pass the full width of the |
| 59 // location bar in |entry_width|. This pass will adjust it to account for |
| 60 // non-collapsible and non-resizable decorations. |
| 61 void LayoutPass1(int* entry_width); |
| 62 |
| 63 // Second pass of decoration layout process. Pass the |entry_width| computed |
| 64 // by the first pass. This pass will adjust it to account for resizable |
| 65 // decorations. |
| 66 void LayoutPass2(int* entry_width); |
| 67 |
| 68 // Third and final pass of decoration layout process. Pass the |bounds| |
| 69 // corresponding to the entire space available in the location bar. This pass |
| 70 // will update it as decorations are laid out. |available_width| measures the |
| 71 // empty space within the location bar, taking the decorations and text into |
| 72 // account. |decorations| must always be ordered from the edge of the location |
| 73 // bar towards the middle. |
| 74 void LayoutPass3(gfx::Rect* bounds, int* available_width); |
| 75 |
| 76 private: |
| 77 // LEFT_EDGE means decorations are added from left to right and stacked on |
| 78 // the left of the omnibox, RIGHT_EDGE means the opposite. |
| 79 Position position_; |
| 80 |
| 81 // The padding between the last decoration and the edit box. |
| 82 int item_edit_padding_; |
| 83 |
| 84 // The padding between the edge and the edit box, if there are no decorations. |
| 85 int edge_edit_padding_; |
| 86 |
| 87 // The list of decorations to layout. |
| 88 ScopedVector<LocationBarDecoration> decorations_; |
| 89 |
| 90 DISALLOW_COPY_AND_ASSIGN(LocationBarLayout); |
| 91 }; |
| 92 |
| 93 #endif // CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_LOCATION_BAR_LAYOUT_H_ |
OLD | NEW |