Commit 05e37a7a authored by David Black's avatar David Black Committed by Commit Bot

Fix DCHECK crash.

Previously, we failed this DCHECK:
https://cs.chromium.org/chromium/src/ui/views/controls/styled_label.cc?dr=CSs&q=styled_label&g=0&l=156

This occurred when we had an empty query string.

Bug: b:112773506
Change-Id: I12f2418a7c0a058fe52ffff6c3507c844c607276
Reviewed-on: https://chromium-review.googlesource.com/1180523
Commit-Queue: David Black <dmblack@google.com>
Reviewed-by: default avatarXiaohui Chen <xiaohuic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#584278}
parent 4215e8b4
...@@ -98,32 +98,31 @@ void AssistantQueryView::SetQuery(const AssistantQuery& query) { ...@@ -98,32 +98,31 @@ void AssistantQueryView::SetQuery(const AssistantQuery& query) {
void AssistantQueryView::SetText(const std::string& high_confidence_text, void AssistantQueryView::SetText(const std::string& high_confidence_text,
const std::string& low_confidence_text) { const std::string& low_confidence_text) {
// High confidence text and low confidence text are displayed in different if (high_confidence_text.empty() && low_confidence_text.empty()) {
// colors for visual emphasis. label_->SetText(base::string16());
const base::string16& high_confidence_text_16 =
base::UTF8ToUTF16(high_confidence_text);
if (low_confidence_text.empty()) {
label_->SetText(high_confidence_text_16);
label_->AddStyleRange(gfx::Range(0, high_confidence_text_16.length()),
CreateStyleInfo(kTextColorPrimary));
} else { } else {
const base::string16& high_confidence_text_16 =
base::UTF8ToUTF16(high_confidence_text);
const base::string16& low_confidence_text_16 = const base::string16& low_confidence_text_16 =
base::UTF8ToUTF16(low_confidence_text); base::UTF8ToUTF16(low_confidence_text);
label_->SetText(high_confidence_text_16 + low_confidence_text_16); label_->SetText(high_confidence_text_16 + low_confidence_text_16);
// High confidence text styling. // Style high confidence text.
label_->AddStyleRange(gfx::Range(0, high_confidence_text_16.length()), if (!high_confidence_text_16.empty()) {
CreateStyleInfo(kTextColorPrimary)); label_->AddStyleRange(gfx::Range(0, high_confidence_text_16.length()),
CreateStyleInfo(kTextColorPrimary));
}
// Low confidence text styling. // Style low confidence text.
label_->AddStyleRange(gfx::Range(high_confidence_text_16.length(), if (!low_confidence_text_16.empty()) {
high_confidence_text_16.length() + label_->AddStyleRange(gfx::Range(high_confidence_text_16.length(),
low_confidence_text_16.length()), high_confidence_text_16.length() +
CreateStyleInfo(kTextColorHint)); low_confidence_text_16.length()),
CreateStyleInfo(kTextColorHint));
}
} }
label_->SizeToFit(width()); label_->SizeToFit(width());
PreferredSizeChanged(); PreferredSizeChanged();
} }
......
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