Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(245)

Side by Side Diff: chrome/browser/ui/views/location_bar/location_bar_layout.cc

Issue 2713253002: Adjust ellision strategy for omnibox search chip. (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include "chrome/browser/ui/views/location_bar/location_bar_layout.h" 5 #include "chrome/browser/ui/views/location_bar/location_bar_layout.h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "chrome/browser/themes/theme_properties.h" 8 #include "chrome/browser/themes/theme_properties.h"
9 #include "ui/gfx/geometry/rect.h" 9 #include "ui/gfx/geometry/rect.h"
10 #include "ui/views/view.h" 10 #include "ui/views/view.h"
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 if (decoration->max_fraction > 0.0) { 121 if (decoration->max_fraction > 0.0) {
122 int max_width = static_cast<int>(*entry_width * decoration->max_fraction); 122 int max_width = static_cast<int>(*entry_width * decoration->max_fraction);
123 decoration->computed_width = std::min( 123 decoration->computed_width = std::min(
124 decoration->view->GetPreferredSize().width(), 124 decoration->view->GetPreferredSize().width(),
125 std::max(decoration->view->GetMinimumSize().width(), max_width)); 125 std::max(decoration->view->GetMinimumSize().width(), max_width));
126 *entry_width -= decoration->computed_width; 126 *entry_width -= decoration->computed_width;
127 } 127 }
128 } 128 }
129 } 129 }
130 130
131 void LocationBarLayout::LayoutPass3(gfx::Rect* bounds, int* available_width) { 131 void LocationBarLayout::LayoutPass3(gfx::Rect* bounds,
132 int* available_width,
133 bool allow_collapse) {
132 bool first_visible = true; 134 bool first_visible = true;
133 for (const auto& decoration : decorations_) { 135 for (const auto& decoration : decorations_) {
134 // Collapse decorations if needed. 136 // Collapse decorations if needed.
135 if (decoration->auto_collapse) { 137 if (decoration->auto_collapse) {
136 int padding = (first_visible ? decoration->edge_item_padding 138 int padding = (first_visible ? decoration->edge_item_padding
137 : decoration->item_padding); 139 : decoration->item_padding);
138 // Try preferred size, if it fails try minimum size, if it fails collapse. 140 // Try preferred size and if it fails try minimum size.
139 decoration->computed_width = decoration->view->GetPreferredSize().width(); 141 decoration->computed_width = decoration->view->GetPreferredSize().width();
140 if (decoration->computed_width + padding > *available_width) 142 if (decoration->computed_width + padding > *available_width)
141 decoration->computed_width = decoration->view->GetMinimumSize().width(); 143 decoration->computed_width = decoration->view->GetMinimumSize().width();
142 if (decoration->computed_width + padding > *available_width) { 144 // If there's insufficient room for the minimum size of the decoration and
145 // we are allowed to collapse, hide the decoration.
146 if (allow_collapse &&
147 decoration->computed_width + padding > *available_width) {
143 decoration->computed_width = 0; 148 decoration->computed_width = 0;
144 decoration->view->SetVisible(false); 149 decoration->view->SetVisible(false);
145 } else { 150 } else {
146 decoration->view->SetVisible(true); 151 decoration->view->SetVisible(true);
147 (*available_width) -= decoration->computed_width + padding; 152 (*available_width) -= decoration->computed_width + padding;
148 } 153 }
149 } else { 154 } else {
150 decoration->view->SetVisible(true); 155 decoration->view->SetVisible(true);
151 } 156 }
152 157
153 // Layout visible decorations. 158 // Layout visible decorations.
154 if (!decoration->view->visible()) 159 if (!decoration->view->visible())
155 continue; 160 continue;
156 int padding = (first_visible ? decoration->edge_item_padding 161 int padding = (first_visible ? decoration->edge_item_padding
157 : decoration->item_padding); 162 : decoration->item_padding);
158 first_visible = false; 163 first_visible = false;
159 int x = (position_ == LEFT_EDGE) 164 int x = (position_ == LEFT_EDGE)
160 ? (bounds->x() + padding) 165 ? (bounds->x() + padding)
161 : (bounds->right() - padding - decoration->computed_width); 166 : (bounds->right() - padding - decoration->computed_width);
162 decoration->view->SetBounds(x, decoration->y, decoration->computed_width, 167 decoration->view->SetBounds(x, decoration->y, decoration->computed_width,
163 decoration->height); 168 decoration->height);
164 bounds->set_width(bounds->width() - padding - decoration->computed_width); 169 bounds->set_width(bounds->width() - padding - decoration->computed_width);
165 if (position_ == LEFT_EDGE) 170 if (position_ == LEFT_EDGE)
166 bounds->set_x(bounds->x() + padding + decoration->computed_width); 171 bounds->set_x(bounds->x() + padding + decoration->computed_width);
167 } 172 }
168 bounds->set_width(bounds->width() - item_edit_padding_); 173 bounds->set_width(bounds->width() - item_edit_padding_);
169 if (position_ == LEFT_EDGE) 174 if (position_ == LEFT_EDGE)
170 bounds->set_x(bounds->x() + item_edit_padding_); 175 bounds->set_x(bounds->x() + item_edit_padding_);
171 } 176 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698