Commit ea24fe81 authored by dschuyler's avatar dschuyler Committed by Commit bot

[AiS] Added option to put a space between answer values

The answers in suggest doesn't put a space between, for example
+ the degrees Fahrenheit and the day of the week
+ the stock price and the stock delta (+/- value)

This CL puts a space between those values, which is more readable for the user.

BUG=

Review URL: https://codereview.chromium.org/1023993003

Cr-Commit-Position: refs/heads/master@{#322071}
parent 961324d2
...@@ -197,8 +197,8 @@ struct TextStyle { ...@@ -197,8 +197,8 @@ struct TextStyle {
gfx::NORMAL_BASELINE}, gfx::NORMAL_BASELINE},
}; };
const TextStyle& GetTextStyle(size_t type) { const TextStyle& GetTextStyle(int type) {
if (type > arraysize(kTextStyles)) if (type < 1 || static_cast<size_t>(type) > arraysize(kTextStyles))
type = 1; type = 1;
// Subtract one because the types are one based (not zero based). // Subtract one because the types are one based (not zero based).
return kTextStyles[type - 1]; return kTextStyles[type - 1];
...@@ -699,13 +699,16 @@ void OmniboxResultView::OnPaint(gfx::Canvas* canvas) { ...@@ -699,13 +699,16 @@ void OmniboxResultView::OnPaint(gfx::Canvas* canvas) {
if (match_.answer) { if (match_.answer) {
base::string16 text; base::string16 text;
description_rendertext_ = CreateRenderText(text); description_rendertext_ = CreateRenderText(text);
for (const SuggestionAnswer::TextField& textfield : for (const SuggestionAnswer::TextField& text_field :
match_.answer->second_line().text_fields()) match_.answer->second_line().text_fields())
AppendAnswerText(textfield); AppendAnswerText(text_field.text(), text_field.type());
if (match_.answer->second_line().additional_text()) const base::char16 space(' ');
AppendAnswerText(*match_.answer->second_line().additional_text()); const auto* text_field = match_.answer->second_line().additional_text();
if (match_.answer->second_line().status_text()) if (text_field)
AppendAnswerText(*match_.answer->second_line().status_text()); AppendAnswerText(space + text_field->text(), text_field->type());
text_field = match_.answer->second_line().status_text();
if (text_field)
AppendAnswerText(space + text_field->text(), text_field->type());
} else if (!match_.description.empty()) { } else if (!match_.description.empty()) {
description_rendertext_ = CreateClassifiedRenderText( description_rendertext_ = CreateClassifiedRenderText(
match_.description, match_.description_class, true); match_.description, match_.description_class, true);
...@@ -755,12 +758,12 @@ int OmniboxResultView::GetContentLineHeight() const { ...@@ -755,12 +758,12 @@ int OmniboxResultView::GetContentLineHeight() const {
GetTextHeight() + (kMinimumTextVerticalPadding * 2)); GetTextHeight() + (kMinimumTextVerticalPadding * 2));
} }
void OmniboxResultView::AppendAnswerText( void OmniboxResultView::AppendAnswerText(const base::string16& text,
const SuggestionAnswer::TextField& text_field) { int text_type) {
int offset = description_rendertext_->text().length(); int offset = description_rendertext_->text().length();
gfx::Range range(offset, offset + text_field.text().length()); gfx::Range range(offset, offset + text.length());
description_rendertext_->AppendText(text_field.text()); description_rendertext_->AppendText(text);
const TextStyle& text_style = GetTextStyle(text_field.type()); const TextStyle& text_style = GetTextStyle(text_type);
// TODO(dschuyler): follow up on the problem of different font sizes within // TODO(dschuyler): follow up on the problem of different font sizes within
// one RenderText. // one RenderText.
description_rendertext_->SetFontList( description_rendertext_->SetFontList(
......
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
#include "base/gtest_prod_util.h" #include "base/gtest_prod_util.h"
#include "chrome/browser/bitmap_fetcher/bitmap_fetcher_service.h" #include "chrome/browser/bitmap_fetcher/bitmap_fetcher_service.h"
#include "components/omnibox/autocomplete_match.h" #include "components/omnibox/autocomplete_match.h"
#include "components/omnibox/suggestion_answer.h"
#include "third_party/skia/include/core/SkColor.h" #include "third_party/skia/include/core/SkColor.h"
#include "ui/gfx/animation/animation_delegate.h" #include "ui/gfx/animation/animation_delegate.h"
#include "ui/gfx/animation/slide_animation.h" #include "ui/gfx/animation/slide_animation.h"
...@@ -160,7 +159,11 @@ class OmniboxResultView : public views::View, ...@@ -160,7 +159,11 @@ class OmniboxResultView : public views::View,
int GetAnswerLineHeight() const; int GetAnswerLineHeight() const;
int GetContentLineHeight() const; int GetContentLineHeight() const;
void AppendAnswerText(const SuggestionAnswer::TextField& text_field); // Adds |text| to |description_rendertext_|. |text_type| is an index into the
// kTextStyles constant defined in the .cc file and is used to style the text,
// including setting the font size, color, and baseline style. See the
// TextStyle struct in the .cc file for more.
void AppendAnswerText(const base::string16& text, int text_type);
static int default_icon_size_; static int default_icon_size_;
......
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