Commit 023d8009 authored by Dave Schuyler's avatar Dave Schuyler Committed by Commit Bot

[Omnibox] Pretend that Calculator results are a rich response

This CL fabricates a rich suggestion/new answer layout for calculator
responses by creating a mimicking a suggestiondetails entry.

Change-Id: I5fdc83b2f31d703e0ed8421e9be65233c9be2cb1
Reviewed-on: https://chromium-review.googlesource.com/1111460
Commit-Queue: Dave Schuyler <dschuyler@chromium.org>
Reviewed-by: default avatarJustin Donnelly <jdonnelly@chromium.org>
Reviewed-by: default avatarMitsuru Oshima (OOO 6/27) <oshima@chromium.org>
Cr-Commit-Position: refs/heads/master@{#571332}
parent ce241814
......@@ -220,7 +220,10 @@
<structure type="chrome_scaled_image" name="IDR_NOTIFICATION_EASYUNLOCK_ENABLED" file="cros/notification_easyunlock_enabled.png" />
<structure type="chrome_scaled_image" name="IDR_NOTIFICATION_EASYUNLOCK_PROMO" file="cros/notification_easyunlock_promo.png" />
</if>
<structure type="chrome_scaled_image" name="IDR_OMNIBOX_TRANSLATION_ROUND" file="chromium/translate_round_32.png" />
<if expr="not is_android">
<structure type="chrome_scaled_image" name="IDR_OMNIBOX_CALCULATOR_ROUND" file="chromium/calculator_round_24.png" />
<structure type="chrome_scaled_image" name="IDR_OMNIBOX_TRANSLATION_ROUND" file="chromium/translate_round_32.png" />
</if>
<if expr="is_macosx">
<structure type="chrome_scaled_image" name="IDR_OVERLAY_DROP_SHADOW" file="mac/overlay_drop_shadow.png" />
<structure type="chrome_scaled_image" name="IDR_OMNIBOX_KEYWORD_HINT_TAB" file="mac/omnibox_keyword_hint_tab.png" />
......
......@@ -270,7 +270,8 @@ void OmniboxMatchCellView::OnMatchUpdate(const OmniboxResultView* result_view,
const AutocompleteMatch& match) {
is_old_style_answer_ = !!match.answer;
is_rich_suggestion_ =
(OmniboxFieldTrial::IsNewAnswerLayoutEnabled() && !!match.answer) ||
(OmniboxFieldTrial::IsNewAnswerLayoutEnabled() &&
(!!match.answer || match.type == AutocompleteMatchType::CALCULATOR)) ||
(OmniboxFieldTrial::IsRichEntitySuggestionsEnabled() &&
!match.image_url.empty());
is_search_type_ = AutocompleteMatch::IsSearchType(match.type);
......@@ -290,7 +291,14 @@ void OmniboxMatchCellView::OnMatchUpdate(const OmniboxResultView* result_view,
separator_view_->SetSize(separator_view_->CalculatePreferredSize());
}
if (!is_rich_suggestion_) {
if (OmniboxFieldTrial::IsNewAnswerLayoutEnabled() &&
match.type == AutocompleteMatchType::CALCULATOR) {
image_view_->SetImage(
ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
IDR_OMNIBOX_CALCULATOR_ROUND));
image_view_->SetImageSize(
gfx::Size(kNewAnswerImageSize, kNewAnswerImageSize));
} else if (!is_rich_suggestion_) {
// An entry with |is_old_style_answer_| may use the image_view_. But it's
// set when the image arrives (later).
image_view_->SetImage(gfx::ImageSkia());
......
......@@ -40,6 +40,7 @@
#include "components/search_engines/template_url.h"
#include "components/search_engines/template_url_service.h"
#include "components/strings/grit/components_strings.h"
#include "ui/base/device_form_factor.h"
#include "ui/base/l10n/l10n_util.h"
#if !defined(OS_IOS)
......@@ -182,8 +183,13 @@ bool IsTrivialAutocompletion(const AutocompleteMatch& match) {
// Whether this autocomplete match type supports custom descriptions.
bool AutocompleteMatchHasCustomDescription(const AutocompleteMatch& match) {
if (ui::GetDeviceFormFactor() == ui::DEVICE_FORM_FACTOR_DESKTOP &&
OmniboxFieldTrial::IsNewAnswerLayoutEnabled() &&
match.type == AutocompleteMatchType::CALCULATOR) {
return true;
}
return match.type == AutocompleteMatchType::SEARCH_SUGGEST_ENTITY ||
match.type == AutocompleteMatchType::SEARCH_SUGGEST_PROFILE;
match.type == AutocompleteMatchType::SEARCH_SUGGEST_PROFILE;
}
} // namespace
......
......@@ -23,6 +23,7 @@
#include "base/values.h"
#include "components/omnibox/browser/autocomplete_i18n.h"
#include "components/omnibox/browser/autocomplete_input.h"
#include "components/omnibox/browser/omnibox_field_trial.h"
#include "components/omnibox/browser/url_prefix.h"
#include "components/url_formatter/url_fixer.h"
#include "components/url_formatter/url_formatter.h"
......@@ -30,6 +31,7 @@
#include "services/network/public/cpp/resource_response.h"
#include "services/network/public/cpp/simple_url_loader.h"
#include "ui/base/device_form_factor.h"
#include "ui/base/material_design/material_design_controller.h"
#include "url/url_constants.h"
namespace {
......@@ -531,21 +533,27 @@ bool SearchSuggestionParser::ParseSuggestResults(
input.text()));
}
} else {
base::string16 annotation;
base::string16 match_contents = suggestion;
if ((match_type == AutocompleteMatchType::CALCULATOR) &&
!suggestion.compare(0, 2, base::UTF8ToUTF16("= "))) {
// Calculator results include a "= " prefix but we don't want to include
// this in the search terms.
suggestion.erase(0, 2);
// Additionally, on larger (non-phone) form factors, we don't want to
// display it in the suggestion contents either, because those devices
// display a suggestion type icon that looks like a '='.
if (ui::GetDeviceFormFactor() != ui::DEVICE_FORM_FACTOR_PHONE)
match_contents.erase(0, 2);
if (match_type == AutocompleteMatchType::CALCULATOR) {
if (!suggestion.compare(0, 2, base::UTF8ToUTF16("= "))) {
// Calculator results include a "= " prefix but we don't want to
// include this in the search terms.
suggestion.erase(0, 2);
// Additionally, on larger (non-phone) form factors, we don't want to
// display it in the suggestion contents either, because those devices
// display a suggestion type icon that looks like a '='.
if (ui::GetDeviceFormFactor() != ui::DEVICE_FORM_FACTOR_PHONE)
match_contents.erase(0, 2);
}
if (ui::GetDeviceFormFactor() == ui::DEVICE_FORM_FACTOR_DESKTOP &&
OmniboxFieldTrial::IsNewAnswerLayoutEnabled()) {
annotation = match_contents;
match_contents = query;
}
}
base::string16 match_contents_prefix;
base::string16 annotation;
base::string16 answer_contents;
base::string16 answer_type_str;
std::unique_ptr<SuggestionAnswer> answer;
......
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