Chromium Code Reviews| 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/views/location_bar/selected_keyword_view.h" | 5 #include "chrome/browser/ui/views/location_bar/selected_keyword_view.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/browser/search_engines/template_url_service_factory.h" | 9 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 10 #include "chrome/browser/ui/location_bar/location_bar_util.h" | 10 #include "chrome/browser/ui/location_bar/location_bar_util.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 44 : ui::NativeTheme::kColorId_LinkEnabled); | 44 : ui::NativeTheme::kColorId_LinkEnabled); |
| 45 } | 45 } |
| 46 | 46 |
| 47 gfx::Size SelectedKeywordView::GetPreferredSize() const { | 47 gfx::Size SelectedKeywordView::GetPreferredSize() const { |
| 48 // Height will be ignored by the LocationBarView. | 48 // Height will be ignored by the LocationBarView. |
| 49 return GetSizeForLabelWidth(full_label_.GetPreferredSize().width()); | 49 return GetSizeForLabelWidth(full_label_.GetPreferredSize().width()); |
| 50 } | 50 } |
| 51 | 51 |
| 52 gfx::Size SelectedKeywordView::GetMinimumSize() const { | 52 gfx::Size SelectedKeywordView::GetMinimumSize() const { |
| 53 // Height will be ignored by the LocationBarView. | 53 // Height will be ignored by the LocationBarView. |
| 54 return GetSizeForLabelWidth(partial_label_.GetMinimumSize().width()); | 54 return GetSizeForLabelWidth(0); |
| 55 } | 55 } |
| 56 | 56 |
| 57 void SelectedKeywordView::Layout() { | 57 void SelectedKeywordView::Layout() { |
| 58 SetLabel(((width() == GetPreferredSize().width()) ? | 58 // Keep showing the full label as long as there's more than enough width for |
| 59 full_label_ : partial_label_).text()); | 59 // the partial label. Otherwise there will be empty space displayed next to |
| 60 // the partial label. | |
| 61 if (width() > | |
| 62 GetSizeForLabelWidth(partial_label_.GetPreferredSize().width()).width()) { | |
| 63 SetLabel(full_label_.text()); | |
| 64 } else { | |
| 65 SetLabel(partial_label_.text()); | |
| 66 } | |
| 67 | |
| 60 IconLabelBubbleView::Layout(); | 68 IconLabelBubbleView::Layout(); |
| 61 } | 69 } |
| 62 | 70 |
| 63 void SelectedKeywordView::SetKeyword(const base::string16& keyword) { | 71 void SelectedKeywordView::SetKeyword(const base::string16& keyword) { |
| 64 keyword_ = keyword; | 72 keyword_ = keyword; |
| 65 if (keyword.empty()) | 73 if (keyword.empty()) |
| 66 return; | 74 return; |
| 67 DCHECK(profile_); | 75 DCHECK(profile_); |
| 68 TemplateURLService* model = | 76 TemplateURLService* model = |
| 69 TemplateURLServiceFactory::GetForProfile(profile_); | 77 TemplateURLServiceFactory::GetForProfile(profile_); |
| 70 if (!model) | 78 if (!model) |
| 71 return; | 79 return; |
| 72 | 80 |
| 73 bool is_extension_keyword; | 81 bool is_extension_keyword; |
| 74 const base::string16 short_name = | 82 const base::string16 short_name = |
| 75 model->GetKeywordShortName(keyword, &is_extension_keyword); | 83 model->GetKeywordShortName(keyword, &is_extension_keyword); |
| 76 const base::string16 full_name = | 84 const base::string16 full_name = |
| 77 is_extension_keyword | 85 is_extension_keyword |
| 78 ? short_name | 86 ? short_name |
| 79 : l10n_util::GetStringFUTF16(IDS_OMNIBOX_KEYWORD_TEXT_MD, short_name); | 87 : l10n_util::GetStringFUTF16(IDS_OMNIBOX_KEYWORD_TEXT_MD, short_name); |
| 80 full_label_.SetText(full_name); | 88 full_label_.SetText(full_name); |
| 81 | 89 |
| 82 const base::string16 min_string( | 90 partial_label_.SetText(short_name); |
| 83 location_bar_util::CalculateMinString(short_name)); | |
|
Peter Kasting
2017/03/08 03:13:12
With the removal of this call, I think only the Ma
| |
| 84 const base::string16 partial_name = | |
| 85 is_extension_keyword | |
| 86 ? min_string | |
| 87 : l10n_util::GetStringFUTF16(IDS_OMNIBOX_KEYWORD_TEXT_MD, min_string); | |
| 88 partial_label_.SetText(min_string.empty() ? | |
| 89 full_label_.text() : partial_name); | |
| 90 | 91 |
| 91 // Update the label now so ShouldShowLabel() works correctly when the parent | 92 // Update the label now so ShouldShowLabel() works correctly when the parent |
| 92 // class is calculating the preferred size. It will be updated again in | 93 // class is calculating the preferred size. It will be updated again in |
| 93 // Layout(), taking into account how much space has actually been allotted. | 94 // Layout(), taking into account how much space has actually been allotted. |
| 94 SetLabel(full_name); | 95 SetLabel(full_name); |
| 95 } | 96 } |
| 96 | 97 |
| 97 const char* SelectedKeywordView::GetClassName() const { | 98 const char* SelectedKeywordView::GetClassName() const { |
| 98 return "SelectedKeywordView"; | 99 return "SelectedKeywordView"; |
| 99 } | 100 } |
| OLD | NEW |