Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_LOCATION_BAR_LAYOUT_H_ | 5 #ifndef CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_LOCATION_BAR_LAYOUT_H_ |
| 6 #define CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_LOCATION_BAR_LAYOUT_H_ | 6 #define CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_LOCATION_BAR_LAYOUT_H_ |
| 7 | 7 |
| 8 #include "base/memory/scoped_vector.h" | 8 #include "base/memory/scoped_vector.h" |
| 9 | 9 |
| 10 namespace gfx { | 10 namespace gfx { |
| 11 class Rect; | 11 class Rect; |
| 12 } | 12 } |
| 13 | 13 |
| 14 namespace views { | 14 namespace views { |
| 15 class View; | 15 class View; |
| 16 } | 16 } |
| 17 | 17 |
| 18 struct LocationBarDecoration; | 18 struct LocationBarDecoration; |
| 19 | 19 |
| 20 // Helper class used to layout a list of decorations inside the omnibox. | 20 // Helper class used to layout a list of decorations inside the omnibox. |
| 21 class LocationBarLayout { | 21 class LocationBarLayout { |
| 22 | 22 |
| 23 public: | 23 public: |
| 24 enum Position { | 24 enum Position { |
| 25 LEFT_EDGE = 0, | 25 LEFT_EDGE = 0, |
| 26 RIGHT_EDGE, | 26 RIGHT_EDGE, |
| 27 }; | 27 }; |
| 28 | 28 |
| 29 enum Separator { | |
|
beaudoin
2013/01/09 20:36:52
Should probably be SeparatorPosition
kuan
2013/01/11 21:21:20
removed based on new design.
| |
| 30 SEPARATOR_NONE = 0, | |
| 31 // For LTR, separator is visually before decoration for LEFT_EDGE and after | |
| 32 // decoration for RIGHT_EDGE. | |
|
beaudoin
2013/01/09 20:36:52
I would rephrase the comment:
SEPARATOR_BEFORE pla
kuan
2013/01/11 21:21:20
ditto.
| |
| 33 SEPARATOR_BEFORE, | |
| 34 // For LTR, separator is visually after decoration for LEFT_EDGE and before | |
| 35 // decoration for RIGHT_EDGE. | |
|
beaudoin
2013/01/09 20:36:52
Same here.
kuan
2013/01/11 21:21:20
ditto.
| |
| 36 SEPARATOR_AFTER, | |
| 37 }; | |
| 38 | |
| 29 LocationBarLayout(Position position, | 39 LocationBarLayout(Position position, |
| 30 int item_edit_padding, | 40 int item_edit_padding, |
| 31 int edge_edit_padding); | 41 int edge_edit_padding); |
| 32 virtual ~LocationBarLayout(); | 42 virtual ~LocationBarLayout(); |
| 33 | 43 |
| 34 // Add a decoration, specifying: | 44 // Add a decoration, specifying: |
| 35 // - The |y| position inside its parent; | 45 // - The |y| position inside its parent; |
| 36 // - The |height| in pixel, 0 meaning the preferred height of the |view|; | 46 // - 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; | 47 // - 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 | 48 // - The |max_fraction| it can use within the omnibox, or 0 for non-resizable |
| 39 // decorations; | 49 // decorations; |
| 40 // - |edge_item_padding|, the padding between the omnibox edge and the item, | 50 // - |edge_item_padding|, the padding between the omnibox edge and the item, |
| 41 // if the item is the first one drawn; | 51 // if the item is the first one drawn; |
| 42 // - |item_padding|, the padding between the previous item and this one; | 52 // - |item_padding|, the padding between the previous item and this one; |
| 43 // - |builtin_padding|, any padding directly built into the item; | 53 // - |builtin_padding|, any padding directly built into the item; |
| 44 // - The |view| corresponding to this decoration, a weak pointer. | 54 // - 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. | 55 // Note that |auto_collapse| can be true if and only if |max_fraction| is 0. |
| 46 void AddDecoration(int y, | 56 void AddDecoration(int y, |
| 47 int height, | 57 int height, |
| 48 bool auto_collapse, | 58 bool auto_collapse, |
| 49 double max_fraction, | 59 double max_fraction, |
| 50 int edge_item_padding, | 60 int edge_item_padding, |
| 51 int item_padding, | 61 int item_padding, |
| 52 int builtin_padding, | 62 int builtin_padding, |
| 53 views::View* view); | 63 views::View* view); |
| 54 | 64 |
| 65 // Add a decoration with a separator, the parameters are identical to those | |
| 66 // for AddDecoration(), with extra specifications for: | |
| 67 // - The |separator| type; | |
| 68 // - The |separator_padding| to use between |view| and separator; | |
| 69 // - The |separator_height| to use for separator in pixel, 0 meaning final | |
| 70 // height used for |view|; | |
| 71 // - The |separator_view| corresponding to the separator for this decoration, | |
| 72 // a weak pointer. | |
| 73 void AddDecorationWithSeparator(int y, | |
| 74 int height, | |
| 75 bool auto_collapse, | |
| 76 double max_fraction, | |
| 77 int edge_item_padding, | |
| 78 int item_padding, | |
| 79 int builtin_padding, | |
| 80 Separator separator, | |
| 81 int separator_padding, | |
| 82 int separator_height, | |
| 83 views::View* view, | |
| 84 views::View* separator_view); | |
|
beaudoin
2013/01/09 20:36:52
I think it would be much simpler to replace the ab
kuan
2013/01/11 21:21:20
Done.
| |
| 85 | |
| 55 // Add a non-resizable decoration with standard padding. | 86 // Add a non-resizable decoration with standard padding. |
| 56 void AddDecoration(int height, int builtin_padding, views::View* view); | 87 void AddDecoration(int height, int builtin_padding, views::View* view); |
| 57 | 88 |
| 58 // First pass of decoration layout process. Pass the full width of the | 89 // 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 | 90 // location bar in |entry_width|. This pass will adjust it to account for |
| 60 // non-collapsible and non-resizable decorations. | 91 // non-collapsible and non-resizable decorations. |
| 61 void LayoutPass1(int* entry_width); | 92 void LayoutPass1(int* entry_width); |
| 62 | 93 |
| 63 // Second pass of decoration layout process. Pass the |entry_width| computed | 94 // 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 | 95 // by the first pass. This pass will adjust it to account for resizable |
| 65 // decorations. | 96 // decorations. |
| 66 void LayoutPass2(int* entry_width); | 97 void LayoutPass2(int* entry_width); |
| 67 | 98 |
| 68 // Third and final pass of decoration layout process. Pass the |bounds| | 99 // Third and final pass of decoration layout process. Pass the |bounds| |
| 69 // corresponding to the entire space available in the location bar. This pass | 100 // 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 | 101 // 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 | 102 // 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 | 103 // account. |decorations| must always be ordered from the edge of the location |
| 73 // bar towards the middle. | 104 // bar towards the middle. |
| 74 void LayoutPass3(gfx::Rect* bounds, int* available_width); | 105 void LayoutPass3(gfx::Rect* bounds, int* available_width); |
| 75 | 106 |
| 107 // Sets the padding between edit and the decoration beside it. | |
| 108 // This value must not be modified after LayoutPass1 has been called. | |
| 109 void set_item_edit_padding(int item_edit_padding) { | |
| 110 item_edit_padding_ = item_edit_padding; | |
| 111 } | |
| 112 | |
| 76 private: | 113 private: |
| 114 // Determine if separator of a decoration at |it| should be visible. | |
| 115 // |available_width| returns the updated remaining width if separator is | |
| 116 // visible. | |
| 117 void DetermineSeparatorVisibility( | |
| 118 ScopedVector<LocationBarDecoration>::iterator it, | |
| 119 bool first_visible, | |
| 120 int item_padding, | |
| 121 int* available_width); | |
| 122 | |
| 123 // Set bounds of separator is if it's visible, returns true if bounds is set. | |
|
beaudoin
2013/01/09 20:36:52
typo: if it is
kuan
2013/01/11 21:21:20
removed, based on new design.
| |
| 124 // |bounds| returns the updated remaining bounds. | |
| 125 bool SetSeparatorBounds( | |
| 126 ScopedVector<LocationBarDecoration>::iterator it, | |
| 127 int padding, | |
| 128 int item_height, | |
| 129 gfx::Rect* bounds); | |
| 130 | |
| 77 // LEFT_EDGE means decorations are added from left to right and stacked on | 131 // LEFT_EDGE means decorations are added from left to right and stacked on |
| 78 // the left of the omnibox, RIGHT_EDGE means the opposite. | 132 // the left of the omnibox, RIGHT_EDGE means the opposite. |
| 79 Position position_; | 133 Position position_; |
| 80 | 134 |
| 81 // The padding between the last decoration and the edit box. | 135 // The padding between the last decoration and the edit box. |
| 82 int item_edit_padding_; | 136 int item_edit_padding_; |
| 83 | 137 |
| 84 // The padding between the edge and the edit box, if there are no decorations. | 138 // The padding between the edge and the edit box, if there are no decorations. |
| 85 int edge_edit_padding_; | 139 int edge_edit_padding_; |
| 86 | 140 |
| 87 // The list of decorations to layout. | 141 // The list of decorations to layout. |
| 88 ScopedVector<LocationBarDecoration> decorations_; | 142 ScopedVector<LocationBarDecoration> decorations_; |
| 89 | 143 |
| 90 DISALLOW_COPY_AND_ASSIGN(LocationBarLayout); | 144 DISALLOW_COPY_AND_ASSIGN(LocationBarLayout); |
| 91 }; | 145 }; |
| 92 | 146 |
| 93 #endif // CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_LOCATION_BAR_LAYOUT_H_ | 147 #endif // CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_LOCATION_BAR_LAYOUT_H_ |
| OLD | NEW |