Commit d2a60e0f authored by Dave Schuyler's avatar Dave Schuyler Committed by Commit Bot

[Omnibox] make clearer where the old style answers are specified

This CL renames references to answer layout to old-style layout to be
clearer about what refers to the old style answer layout. Some uses of
old-style answer formatting in entities were also cleaned up.

Bug: None
Change-Id: I6812c7d005cb9c945b8a36e89668d062cda4558a
Reviewed-on: https://chromium-review.googlesource.com/1040538Reviewed-by: default avatarJustin Donnelly <jdonnelly@chromium.org>
Commit-Queue: Dave Schuyler <dschuyler@chromium.org>
Cr-Commit-Position: refs/heads/master@{#555518}
parent 05b038c9
...@@ -51,9 +51,9 @@ int GetIconAlignmentOffset() { ...@@ -51,9 +51,9 @@ int GetIconAlignmentOffset() {
} }
// Returns the margins that should appear at the top and bottom of the result. // Returns the margins that should appear at the top and bottom of the result.
// |match_is_answer| indicates whether the vertical margin is for a omnibox // |is_old_style_answer| indicates whether the vertical margin is for a omnibox
// result displaying an answer to the query. // result displaying an answer to the query.
gfx::Insets GetVerticalInsets(int text_height, bool match_is_answer) { gfx::Insets GetVerticalInsets(int text_height, bool is_old_style_answer) {
// Regardless of the text size, we ensure a minimum size for the content line // Regardless of the text size, we ensure a minimum size for the content line
// here. This minimum is larger for hybrid mouse/touch devices to ensure an // here. This minimum is larger for hybrid mouse/touch devices to ensure an
// adequately sized touch target. // adequately sized touch target.
...@@ -72,7 +72,7 @@ gfx::Insets GetVerticalInsets(int text_height, bool match_is_answer) { ...@@ -72,7 +72,7 @@ gfx::Insets GetVerticalInsets(int text_height, bool match_is_answer) {
if (Md::IsTouchOptimizedUiEnabled()) { if (Md::IsTouchOptimizedUiEnabled()) {
min_height = std::max( min_height = std::max(
min_height, RoundedOmniboxResultsFrame::GetNonResultSectionHeight()); min_height, RoundedOmniboxResultsFrame::GetNonResultSectionHeight());
if (match_is_answer) { if (is_old_style_answer) {
// Answer matches apply the normal margin at the top and the minimum // Answer matches apply the normal margin at the top and the minimum
// allowable margin at the bottom. // allowable margin at the bottom.
const int top_margin = gfx::ToCeiledInt((min_height - text_height) / 2.f); const int top_margin = gfx::ToCeiledInt((min_height - text_height) / 2.f);
...@@ -109,7 +109,7 @@ class OmniboxImageView : public views::ImageView { ...@@ -109,7 +109,7 @@ class OmniboxImageView : public views::ImageView {
OmniboxMatchCellView::OmniboxMatchCellView(OmniboxResultView* result_view, OmniboxMatchCellView::OmniboxMatchCellView(OmniboxResultView* result_view,
const gfx::FontList& font_list, const gfx::FontList& font_list,
int text_height) int text_height)
: is_answer_(false), : is_old_style_answer_(false),
is_entity_(false), is_entity_(false),
is_search_type_(false), is_search_type_(false),
text_height_(text_height) { text_height_(text_height) {
...@@ -127,17 +127,19 @@ OmniboxMatchCellView::OmniboxMatchCellView(OmniboxResultView* result_view, ...@@ -127,17 +127,19 @@ OmniboxMatchCellView::OmniboxMatchCellView(OmniboxResultView* result_view,
OmniboxMatchCellView::~OmniboxMatchCellView() = default; OmniboxMatchCellView::~OmniboxMatchCellView() = default;
gfx::Size OmniboxMatchCellView::CalculatePreferredSize() const { gfx::Size OmniboxMatchCellView::CalculatePreferredSize() const {
int height = int height = text_height_ +
text_height_ + GetVerticalInsets(text_height_, is_answer_).height(); GetVerticalInsets(text_height_, is_old_style_answer_).height();
if (is_answer_ || is_entity_) if (is_old_style_answer_)
height += GetAnswerHeight(); height += GetOldStyleAnswerHeight();
if (is_entity_)
height += text_height_;
return gfx::Size(0, height); return gfx::Size(0, height);
} }
bool OmniboxMatchCellView::CanProcessEventsWithinSubtree() const { bool OmniboxMatchCellView::CanProcessEventsWithinSubtree() const {
return false; return false;
} }
int OmniboxMatchCellView::GetAnswerHeight() const { int OmniboxMatchCellView::GetOldStyleAnswerHeight() const {
int icon_width = icon_view_->width(); int icon_width = icon_view_->width();
int answer_icon_size = image_view_->visible() int answer_icon_size = image_view_->visible()
? image_view_->height() + kAnswerIconToTextPadding ? image_view_->height() + kAnswerIconToTextPadding
...@@ -152,12 +154,12 @@ int OmniboxMatchCellView::GetAnswerHeight() const { ...@@ -152,12 +154,12 @@ int OmniboxMatchCellView::GetAnswerHeight() const {
} }
void OmniboxMatchCellView::OnMatchUpdate(const AutocompleteMatch& match) { void OmniboxMatchCellView::OnMatchUpdate(const AutocompleteMatch& match) {
is_answer_ = !!match.answer; is_old_style_answer_ = !!match.answer;
if (base::FeatureList::IsEnabled(omnibox::kOmniboxRichEntitySuggestions)) { if (base::FeatureList::IsEnabled(omnibox::kOmniboxRichEntitySuggestions)) {
is_entity_ = !match.image_url.empty(); is_entity_ = !match.image_url.empty();
} }
is_search_type_ = AutocompleteMatch::IsSearchType(match.type); is_search_type_ = AutocompleteMatch::IsSearchType(match.type);
if (is_answer_ || is_entity_) { if (is_old_style_answer_ || is_entity_) {
separator_view_->SetSize(gfx::Size()); separator_view_->SetSize(gfx::Size());
} }
if (is_entity_) { if (is_entity_) {
...@@ -171,19 +173,19 @@ const char* OmniboxMatchCellView::GetClassName() const { ...@@ -171,19 +173,19 @@ const char* OmniboxMatchCellView::GetClassName() const {
void OmniboxMatchCellView::Layout() { void OmniboxMatchCellView::Layout() {
views::View::Layout(); views::View::Layout();
if (is_answer_) { if (is_entity_) {
LayoutAnswer();
} else if (is_entity_) {
LayoutEntity(); LayoutEntity();
} else if (is_old_style_answer_) {
LayoutOldStyleAnswer();
} else { } else {
LayoutSplit(); LayoutSplit();
} }
} }
void OmniboxMatchCellView::LayoutAnswer() { void OmniboxMatchCellView::LayoutOldStyleAnswer() {
const int start_x = GetIconAlignmentOffset() + HorizontalPadding(); const int start_x = GetIconAlignmentOffset() + HorizontalPadding();
int x = start_x + LocationBarView::GetBorderThicknessDip(); int x = start_x + LocationBarView::GetBorderThicknessDip();
int y = GetVerticalInsets(text_height_, is_answer_).top(); int y = GetVerticalInsets(text_height_, /*is_old_style_answer=*/true).top();
icon_view_->SetSize(icon_view_->CalculatePreferredSize()); icon_view_->SetSize(icon_view_->CalculatePreferredSize());
icon_view_->SetPosition( icon_view_->SetPosition(
gfx::Point(x, y + (text_height_ - icon_view_->height()) / 2)); gfx::Point(x, y + (text_height_ - icon_view_->height()) / 2));
...@@ -210,7 +212,7 @@ void OmniboxMatchCellView::LayoutAnswer() { ...@@ -210,7 +212,7 @@ void OmniboxMatchCellView::LayoutAnswer() {
void OmniboxMatchCellView::LayoutEntity() { void OmniboxMatchCellView::LayoutEntity() {
int x = GetIconAlignmentOffset() + HorizontalPadding() + int x = GetIconAlignmentOffset() + HorizontalPadding() +
LocationBarView::GetBorderThicknessDip(); LocationBarView::GetBorderThicknessDip();
int y = GetVerticalInsets(text_height_, is_answer_).top(); int y = GetVerticalInsets(text_height_, /*is_old_style_answer=*/false).top();
int image_edge_length = text_height_ * 2; int image_edge_length = text_height_ * 2;
image_view_->SetImageSize(gfx::Size(image_edge_length, image_edge_length)); image_view_->SetImageSize(gfx::Size(image_edge_length, image_edge_length));
image_view_->SetBounds(x, y, image_edge_length, image_edge_length); image_view_->SetBounds(x, y, image_edge_length, image_edge_length);
...@@ -224,7 +226,7 @@ void OmniboxMatchCellView::LayoutSplit() { ...@@ -224,7 +226,7 @@ void OmniboxMatchCellView::LayoutSplit() {
int x = GetIconAlignmentOffset() + HorizontalPadding() + int x = GetIconAlignmentOffset() + HorizontalPadding() +
LocationBarView::GetBorderThicknessDip(); LocationBarView::GetBorderThicknessDip();
icon_view_->SetSize(icon_view_->CalculatePreferredSize()); icon_view_->SetSize(icon_view_->CalculatePreferredSize());
int y = GetVerticalInsets(text_height_, is_answer_).top(); int y = GetVerticalInsets(text_height_, /*is_old_style_answer=*/false).top();
icon_view_->SetPosition( icon_view_->SetPosition(
gfx::Point(x, y + (text_height_ - icon_view_->height()) / 2)); gfx::Point(x, y + (text_height_ - icon_view_->height()) / 2));
x += icon_view_->width() + HorizontalPadding(); x += icon_view_->width() + HorizontalPadding();
......
...@@ -44,13 +44,13 @@ class OmniboxMatchCellView : public views::View { ...@@ -44,13 +44,13 @@ class OmniboxMatchCellView : public views::View {
const char* GetClassName() const override; const char* GetClassName() const override;
// Returns the height of the the description section of answer suggestions. // Returns the height of the the description section of answer suggestions.
int GetAnswerHeight() const; int GetOldStyleAnswerHeight() const;
void LayoutAnswer(); void LayoutOldStyleAnswer();
void LayoutEntity(); void LayoutEntity();
void LayoutSplit(); void LayoutSplit();
bool is_answer_; bool is_old_style_answer_;
bool is_entity_; bool is_entity_;
bool is_search_type_; bool is_search_type_;
int text_height_; int text_height_;
......
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