OLD | NEW |
---|---|
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/omnibox/omnibox_popup_model.h" | 5 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
44 } | 44 } |
45 | 45 |
46 // static | 46 // static |
47 void OmniboxPopupModel::ComputeMatchMaxWidths(int contents_width, | 47 void OmniboxPopupModel::ComputeMatchMaxWidths(int contents_width, |
48 int separator_width, | 48 int separator_width, |
49 int description_width, | 49 int description_width, |
50 int available_width, | 50 int available_width, |
51 bool allow_shrinking_contents, | 51 bool allow_shrinking_contents, |
52 int* contents_max_width, | 52 int* contents_max_width, |
53 int* description_max_width) { | 53 int* description_max_width) { |
54 if (available_width <= 0) { | 54 available_width = std::max(available_width, 0); |
55 *contents_max_width = 0; | 55 *contents_max_width = std::min(contents_width, available_width); |
Mark P
2015/04/22 18:29:12
This doesn't make sense; you immediately override
Peter Kasting
2015/04/22 23:08:06
Yes, this was a typo when splitting this change ou
| |
56 *description_max_width = 0; | |
57 return; | |
58 } | |
59 | 56 |
60 *contents_max_width = contents_width; | 57 *contents_max_width = contents_width; |
61 *description_max_width = description_width; | 58 *description_max_width = description_width; |
62 | 59 |
63 // If the description is empty, the contents can get the full width. | 60 // If the description is empty, the contents can get the full width. |
64 if (!description_width) | 61 if (!description_width) |
65 return; | 62 return; |
66 | 63 |
67 // If we want to display the description, we need to reserve enough space for | 64 // If we want to display the description, we need to reserve enough space for |
68 // the separator. | 65 // the separator. |
69 available_width -= separator_width; | 66 available_width -= separator_width; |
67 if (available_width < 0) { | |
68 *description_max_width = 0; | |
69 return; | |
70 } | |
70 | 71 |
71 if (contents_width + description_width > available_width) { | 72 if (contents_width + description_width > available_width) { |
72 if (allow_shrinking_contents) { | 73 if (allow_shrinking_contents) { |
73 // Try to split the available space fairly between contents and | 74 // Try to split the available space fairly between contents and |
74 // description (if one wants less than half, give it all it wants and | 75 // description (if one wants less than half, give it all it wants and |
75 // give the other the remaining space; otherwise, give each half). | 76 // give the other the remaining space; otherwise, give each half). |
76 // However, if this makes the contents too narrow to show a significant | 77 // However, if this makes the contents too narrow to show a significant |
77 // amount of information, give the contents more space. | 78 // amount of information, give the contents more space. |
78 *contents_max_width = std::max( | 79 *contents_max_width = std::max( |
79 (available_width + 1) / 2, available_width - description_width); | 80 (available_width + 1) / 2, available_width - description_width); |
80 | 81 |
81 const int kMinimumContentsWidth = 300; | 82 const int kMinimumContentsWidth = 300; |
82 *contents_max_width = std::min( | 83 *contents_max_width = std::min(std::min( |
83 std::max(*contents_max_width, kMinimumContentsWidth), contents_width); | 84 std::max(*contents_max_width, kMinimumContentsWidth), contents_width), |
85 available_width); | |
84 } | 86 } |
85 | 87 |
86 // Give the description the remaining space, unless this makes it too small | 88 // Give the description the remaining space, unless this makes it too small |
87 // to display anything meaningful, in which case just hide the description | 89 // to display anything meaningful, in which case just hide the description |
88 // and let the contents take up the whole width. | 90 // and let the contents take up the whole width. |
89 *description_max_width = available_width - *contents_max_width; | 91 *description_max_width = |
92 std::min(description_width, available_width - *contents_max_width); | |
90 const int kMinimumDescriptionWidth = 75; | 93 const int kMinimumDescriptionWidth = 75; |
91 if (*description_max_width < | 94 if (*description_max_width < |
92 std::min(description_width, kMinimumDescriptionWidth)) { | 95 std::min(description_width, kMinimumDescriptionWidth)) { |
93 *description_max_width = 0; | 96 *description_max_width = 0; |
94 *contents_max_width = contents_width; | 97 // Since we're not going to display the description, the contents can have |
98 // the space we reserved for the separator. | |
99 available_width += separator_width; | |
100 *contents_max_width = std::min(contents_width, available_width); | |
95 } | 101 } |
96 } | 102 } |
97 } | 103 } |
98 | 104 |
99 bool OmniboxPopupModel::IsOpen() const { | 105 bool OmniboxPopupModel::IsOpen() const { |
100 return view_->IsOpen(); | 106 return view_->IsOpen(); |
101 } | 107 } |
102 | 108 |
103 void OmniboxPopupModel::SetHoveredLine(size_t line) { | 109 void OmniboxPopupModel::SetHoveredLine(size_t line) { |
104 const bool is_disabling = (line == kNoMatch); | 110 const bool is_disabling = (line == kNoMatch); |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
290 } | 296 } |
291 } | 297 } |
292 | 298 |
293 void OmniboxPopupModel::AddObserver(OmniboxPopupModelObserver* observer) { | 299 void OmniboxPopupModel::AddObserver(OmniboxPopupModelObserver* observer) { |
294 observers_.AddObserver(observer); | 300 observers_.AddObserver(observer); |
295 } | 301 } |
296 | 302 |
297 void OmniboxPopupModel::RemoveObserver(OmniboxPopupModelObserver* observer) { | 303 void OmniboxPopupModel::RemoveObserver(OmniboxPopupModelObserver* observer) { |
298 observers_.RemoveObserver(observer); | 304 observers_.RemoveObserver(observer); |
299 } | 305 } |
OLD | NEW |