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

Unified Diff: chrome/browser/ui/omnibox/omnibox_popup_model.cc

Issue 1082833006: Compute the correct maximum contents width when eliding away the description in (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix bug and test Created 5 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/ui/omnibox/omnibox_popup_model_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/omnibox/omnibox_popup_model.cc
diff --git a/chrome/browser/ui/omnibox/omnibox_popup_model.cc b/chrome/browser/ui/omnibox/omnibox_popup_model.cc
index d20ee26531668abcd684dcc75f2c6c26578d6366..2284acc259a70bbd4b9218dbbc493f18b71c1d4f 100644
--- a/chrome/browser/ui/omnibox/omnibox_popup_model.cc
+++ b/chrome/browser/ui/omnibox/omnibox_popup_model.cc
@@ -51,13 +51,8 @@ void OmniboxPopupModel::ComputeMatchMaxWidths(int contents_width,
bool allow_shrinking_contents,
int* contents_max_width,
int* description_max_width) {
- if (available_width <= 0) {
- *contents_max_width = 0;
- *description_max_width = 0;
- return;
- }
-
- *contents_max_width = contents_width;
+ available_width = std::max(available_width, 0);
+ *contents_max_width = std::min(contents_width, available_width);
*description_max_width = description_width;
// If the description is empty, the contents can get the full width.
@@ -67,6 +62,10 @@ void OmniboxPopupModel::ComputeMatchMaxWidths(int contents_width,
// If we want to display the description, we need to reserve enough space for
// the separator.
available_width -= separator_width;
+ if (available_width < 0) {
+ *description_max_width = 0;
+ return;
+ }
if (contents_width + description_width > available_width) {
if (allow_shrinking_contents) {
@@ -79,19 +78,24 @@ void OmniboxPopupModel::ComputeMatchMaxWidths(int contents_width,
(available_width + 1) / 2, available_width - description_width);
const int kMinimumContentsWidth = 300;
- *contents_max_width = std::min(
- std::max(*contents_max_width, kMinimumContentsWidth), contents_width);
+ *contents_max_width = std::min(std::min(
+ std::max(*contents_max_width, kMinimumContentsWidth), contents_width),
+ available_width);
}
// Give the description the remaining space, unless this makes it too small
// to display anything meaningful, in which case just hide the description
// and let the contents take up the whole width.
- *description_max_width = available_width - *contents_max_width;
+ *description_max_width =
+ std::min(description_width, available_width - *contents_max_width);
const int kMinimumDescriptionWidth = 75;
if (*description_max_width <
std::min(description_width, kMinimumDescriptionWidth)) {
*description_max_width = 0;
- *contents_max_width = contents_width;
+ // Since we're not going to display the description, the contents can have
+ // the space we reserved for the separator.
+ available_width += separator_width;
+ *contents_max_width = std::min(contents_width, available_width);
}
}
}
« no previous file with comments | « no previous file | chrome/browser/ui/omnibox/omnibox_popup_model_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698