Commit 33ad0cec authored by pkasting@chromium.org's avatar pkasting@chromium.org

Several cleanup items, and one visible change:

* Eliminte the distinction between "item to item padding" and "item to edge
  padding" because the two values are always equal.
* Don't bother supporting "height 0 = use preferred height" in
  location_bar_layout.*, since only one caller uses it at this point and it's
  easier to understand the code by just making it explicit.
* Switch to using a views::Painter for the popup mode background as well,
  instead of explicitly drawing the images.  This will make it easy to switch
  both modes to ninebox painting in the future.
* Try to reorder code in order to declare variables as close to their use as
  possible, and in the order that they're accessed.
* Visible change: Instead of assuming the edit always has 1 px. of "internal
  space", calculate the correct conditions for which that's true.  This results
  in the OmniboxViewViews text moving right by 1 px. in the LTR case.

BUG=231005,239902
TEST=With "views textfield" on, address bar text moves 1 px. right
R=sky@chromium.org

Review URL: https://codereview.chromium.org/16025004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@202916 0039d316-1c4b-4281-b951-d872f2087c98
parent 70f4ac25
...@@ -18,12 +18,10 @@ namespace { ...@@ -18,12 +18,10 @@ namespace {
// Amount of padding at the edges of the bubble. // Amount of padding at the edges of the bubble.
// //
// This can't be statically initialized because // This can't be statically initialized because
// LocationBarView::GetEdgeItemPadding() depends on whether we are // LocationBarView::GetItemPadding() depends on whether we are using desktop or
// using desktop or touch layout, and this in turn depends on the // touch layout, and this in turn depends on the command line.
// command line.
int GetBubbleOuterPadding() { int GetBubbleOuterPadding() {
return LocationBarView::GetEdgeItemPadding() - return LocationBarView::GetItemPadding() - LocationBarView::kBubblePadding;
LocationBarView::kBubblePadding;
} }
} // namespace } // namespace
......
...@@ -44,7 +44,7 @@ struct LocationBarDecoration { ...@@ -44,7 +44,7 @@ struct LocationBarDecoration {
// The y position of the view inside its parent. // The y position of the view inside its parent.
int y; int y;
// If 0, will use the preferred height of the view. // The height of the view.
int height; int height;
// Used for resizeable decorations, indicates the maximum fraction of the // Used for resizeable decorations, indicates the maximum fraction of the
...@@ -85,22 +85,16 @@ LocationBarDecoration::LocationBarDecoration(DecorationType type, ...@@ -85,22 +85,16 @@ LocationBarDecoration::LocationBarDecoration(DecorationType type,
builtin_padding(builtin_padding), builtin_padding(builtin_padding),
view(view), view(view),
computed_width(0) { computed_width(0) {
if (type == NORMAL) { DCHECK((max_fraction == 0.0) || ((type == NORMAL) && (max_fraction > 0.0)));
DCHECK_GE(max_fraction, 0.0);
} else {
DCHECK_EQ(0.0, max_fraction);
}
} }
// LocationBarLayout --------------------------------------------------------- // LocationBarLayout ---------------------------------------------------------
LocationBarLayout::LocationBarLayout(Position position, LocationBarLayout::LocationBarLayout(Position position, int item_edit_padding)
int item_edit_padding,
int edge_edit_padding)
: position_(position), : position_(position),
item_edit_padding_(item_edit_padding), item_edit_padding_(item_edit_padding) {
edge_edit_padding_(edge_edit_padding) {} }
LocationBarLayout::~LocationBarLayout() { LocationBarLayout::~LocationBarLayout() {
...@@ -124,7 +118,7 @@ void LocationBarLayout::AddDecoration(int y, ...@@ -124,7 +118,7 @@ void LocationBarLayout::AddDecoration(int y,
int builtin_padding, int builtin_padding,
views::View* view) { views::View* view) {
decorations_.push_back(new LocationBarDecoration( decorations_.push_back(new LocationBarDecoration(
NORMAL, y, height, 0, LocationBarView::GetEdgeItemPadding(), NORMAL, y, height, 0, LocationBarView::GetItemPadding(),
LocationBarView::GetItemPadding(), builtin_padding, view)); LocationBarView::GetItemPadding(), builtin_padding, view));
} }
...@@ -140,12 +134,10 @@ void LocationBarLayout::AddSeparator(int y, ...@@ -140,12 +134,10 @@ void LocationBarLayout::AddSeparator(int y,
void LocationBarLayout::LayoutPass1(int* entry_width) { void LocationBarLayout::LayoutPass1(int* entry_width) {
bool first_item = true; bool first_item = true;
bool at_least_one_visible = false;
for (Decorations::iterator it(decorations_.begin()); it != decorations_.end(); for (Decorations::iterator it(decorations_.begin()); it != decorations_.end();
++it) { ++it) {
// Autocollapsing decorations are ignored in this pass. // Autocollapsing decorations are ignored in this pass.
if ((*it)->type != AUTO_COLLAPSE) { if ((*it)->type != AUTO_COLLAPSE) {
at_least_one_visible = true;
*entry_width -= -2 * (*it)->builtin_padding + *entry_width -= -2 * (*it)->builtin_padding +
(first_item ? (*it)->edge_item_padding : (*it)->item_padding); (first_item ? (*it)->edge_item_padding : (*it)->item_padding);
} }
...@@ -156,8 +148,7 @@ void LocationBarLayout::LayoutPass1(int* entry_width) { ...@@ -156,8 +148,7 @@ void LocationBarLayout::LayoutPass1(int* entry_width) {
*entry_width -= (*it)->computed_width; *entry_width -= (*it)->computed_width;
} }
} }
*entry_width -= at_least_one_visible ? item_edit_padding_ : *entry_width -= item_edit_padding_;
edge_edit_padding_;
} }
void LocationBarLayout::LayoutPass2(int *entry_width) { void LocationBarLayout::LayoutPass2(int *entry_width) {
...@@ -248,9 +239,7 @@ void LocationBarLayout::SetBoundsForDecorations(gfx::Rect* bounds) { ...@@ -248,9 +239,7 @@ void LocationBarLayout::SetBoundsForDecorations(gfx::Rect* bounds) {
first_visible = false; first_visible = false;
int x = (position_ == LEFT_EDGE) ? (bounds->x() + padding) : int x = (position_ == LEFT_EDGE) ? (bounds->x() + padding) :
(bounds->right() - padding - curr->computed_width); (bounds->right() - padding - curr->computed_width);
int height = curr->height == 0 ? curr->view->SetBounds(x, curr->y, curr->computed_width, curr->height);
curr->view->GetPreferredSize().height() : curr->height;
curr->view->SetBounds(x, curr->y, curr->computed_width, height);
bounds->set_width(bounds->width() - padding - curr->computed_width + bounds->set_width(bounds->width() - padding - curr->computed_width +
curr->builtin_padding); curr->builtin_padding);
if (position_ == LEFT_EDGE) { if (position_ == LEFT_EDGE) {
...@@ -258,8 +247,7 @@ void LocationBarLayout::SetBoundsForDecorations(gfx::Rect* bounds) { ...@@ -258,8 +247,7 @@ void LocationBarLayout::SetBoundsForDecorations(gfx::Rect* bounds) {
bounds->x() + padding + curr->computed_width - curr->builtin_padding); bounds->x() + padding + curr->computed_width - curr->builtin_padding);
} }
} }
int final_padding = first_visible ? edge_edit_padding_ : item_edit_padding_; bounds->set_width(bounds->width() - item_edit_padding_);
bounds->set_width(bounds->width() - final_padding);
if (position_ == LEFT_EDGE) if (position_ == LEFT_EDGE)
bounds->set_x(bounds->x() + final_padding); bounds->set_x(bounds->x() + item_edit_padding_);
} }
...@@ -26,9 +26,7 @@ class LocationBarLayout { ...@@ -26,9 +26,7 @@ class LocationBarLayout {
RIGHT_EDGE, RIGHT_EDGE,
}; };
LocationBarLayout(Position position, LocationBarLayout(Position position, int item_edit_padding);
int item_edit_padding,
int edge_edit_padding);
virtual ~LocationBarLayout(); virtual ~LocationBarLayout();
// Add a decoration, specifying: // Add a decoration, specifying:
...@@ -98,9 +96,6 @@ class LocationBarLayout { ...@@ -98,9 +96,6 @@ class LocationBarLayout {
// The padding between the last decoration and the edit box. // The padding between the last decoration and the edit box.
int item_edit_padding_; int item_edit_padding_;
// The padding between the edge and the edit box, if there are no decorations.
int edge_edit_padding_;
// The list of decorations to layout. // The list of decorations to layout.
Decorations decorations_; Decorations decorations_;
......
...@@ -315,12 +315,10 @@ class LocationBarView : public LocationBar, ...@@ -315,12 +315,10 @@ class LocationBarView : public LocationBar,
// otherwise it will be the current height. // otherwise it will be the current height.
int GetInternalHeight(bool use_preferred_size); int GetInternalHeight(bool use_preferred_size);
// Space between items in the location bar. // Space between items in the location bar, as well as between items and the
// edges.
static int GetItemPadding(); static int GetItemPadding();
// Space between the edges and the items next to them.
static int GetEdgeItemPadding();
// Thickness of the left and right edges of the omnibox, in normal mode. // Thickness of the left and right edges of the omnibox, in normal mode.
static const int kNormalHorizontalEdgeThickness; static const int kNormalHorizontalEdgeThickness;
// The same, but for popup mode. // The same, but for popup mode.
......
...@@ -18,12 +18,14 @@ OmniboxViewViews* GetOmniboxViewViews(OmniboxView* view) { ...@@ -18,12 +18,14 @@ OmniboxViewViews* GetOmniboxViewViews(OmniboxView* view) {
static_cast<OmniboxViewViews*>(view) : NULL; static_cast<OmniboxViewViews*>(view) : NULL;
} }
#if defined(OS_WIN) && !defined(USE_AURA)
OmniboxViewWin* GetOmniboxViewWin(OmniboxView* view) { OmniboxViewWin* GetOmniboxViewWin(OmniboxView* view) {
#if defined(OS_WIN) && !defined(USE_AURA)
return views::Textfield::IsViewsTextfieldEnabled() ? return views::Textfield::IsViewsTextfieldEnabled() ?
NULL : static_cast<OmniboxViewWin*>(view); NULL : static_cast<OmniboxViewWin*>(view);
} #else
return NULL;
#endif #endif
}
OmniboxView* CreateOmniboxView(OmniboxEditController* controller, OmniboxView* CreateOmniboxView(OmniboxEditController* controller,
ToolbarModel* toolbar_model, ToolbarModel* toolbar_model,
......
...@@ -25,10 +25,8 @@ class View; ...@@ -25,10 +25,8 @@ class View;
// Return |view| as an OmniboxViewViews, or NULL if it is of a different type. // Return |view| as an OmniboxViewViews, or NULL if it is of a different type.
OmniboxViewViews* GetOmniboxViewViews(OmniboxView* view); OmniboxViewViews* GetOmniboxViewViews(OmniboxView* view);
#if defined(OS_WIN) && !defined(USE_AURA)
// Return |view| as an OmniboxViewWin, or NULL if it is of a different type. // Return |view| as an OmniboxViewWin, or NULL if it is of a different type.
OmniboxViewWin* GetOmniboxViewWin(OmniboxView* view); OmniboxViewWin* GetOmniboxViewWin(OmniboxView* view);
#endif
// Creates an OmniboxView of the appropriate type; Views or Win. // Creates an OmniboxView of the appropriate type; Views or Win.
OmniboxView* CreateOmniboxView(OmniboxEditController* controller, OmniboxView* CreateOmniboxView(OmniboxEditController* controller,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment