Commit 44122289 authored by Kevin Bailey's avatar Kevin Bailey Committed by Commit Bot

[omnibox] Use two line format for tab switch suggestions

A result looks crowded with a tab switch button. The spec asks that
we use the two line format if the tab switch button is present.

This CL also expands the button to 32px, per spec.

Bug: 780835
Change-Id: I372cb24646bdd448497f0bcf456d383a04a8a55b
Reviewed-on: https://chromium-review.googlesource.com/1087754
Commit-Queue: Justin Donnelly <jdonnelly@chromium.org>
Reviewed-by: default avatarJustin Donnelly <jdonnelly@chromium.org>
Reviewed-by: default avatarDave Schuyler <dschuyler@chromium.org>
Cr-Commit-Position: refs/heads/master@{#567280}
parent ce77e4b6
......@@ -233,7 +233,7 @@ OmniboxMatchCellView::~OmniboxMatchCellView() = default;
gfx::Size OmniboxMatchCellView::CalculatePreferredSize() const {
int height = 0;
if (is_rich_suggestion_) {
if (is_rich_suggestion_ || has_tab_match_) {
height = content_view_->GetLineHeight() +
description_view_->GetHeightForWidth(width() - kTextIndent);
} else if (is_old_style_answer_) {
......@@ -272,6 +272,7 @@ void OmniboxMatchCellView::OnMatchUpdate(const OmniboxResultView* result_view,
(base::FeatureList::IsEnabled(omnibox::kOmniboxRichEntitySuggestions) &&
!match.image_url.empty());
is_search_type_ = AutocompleteMatch::IsSearchType(match.type);
has_tab_match_ = match.has_tab_match;
// Set up the small icon.
if (is_rich_suggestion_) {
......@@ -281,7 +282,7 @@ void OmniboxMatchCellView::OnMatchUpdate(const OmniboxResultView* result_view,
}
// Set up the separator.
if (is_old_style_answer_ || is_rich_suggestion_) {
if (is_old_style_answer_ || is_rich_suggestion_ || has_tab_match_) {
separator_view_->SetSize(gfx::Size());
} else {
separator_view_->SetSize(separator_view_->CalculatePreferredSize());
......@@ -352,8 +353,8 @@ void OmniboxMatchCellView::Layout() {
insets.bottom(), insets.right()));
// Layout children *after* updating the margins.
views::View::Layout();
if (is_rich_suggestion_) {
LayoutRichSuggestion();
if (is_rich_suggestion_ || has_tab_match_) {
LayoutNewStyleTwoLineSuggestion();
} else if (is_old_style_answer_) {
LayoutOldStyleAnswer();
} else if (ui::MaterialDesignController::IsRefreshUi()) {
......@@ -390,11 +391,17 @@ void OmniboxMatchCellView::LayoutOldStyleAnswer() {
description_view_->GetHeightForWidth(description_width));
}
void OmniboxMatchCellView::LayoutRichSuggestion() {
void OmniboxMatchCellView::LayoutNewStyleTwoLineSuggestion() {
gfx::Rect child_area = GetContentsBounds();
int x = child_area.x();
int y = child_area.y();
image_view_->SetBounds(x, y, kRefreshImageBoxSize, child_area.height());
views::ImageView* image_view;
if (has_tab_match_) {
image_view = icon_view_;
} else {
image_view = image_view_;
}
image_view->SetBounds(x, y, kRefreshImageBoxSize, child_area.height());
const int text_width = child_area.width() - kTextIndent;
const int text_height = content_view_->GetLineHeight();
content_view_->SetBounds(x + kTextIndent, y, text_width, text_height);
......
......@@ -43,12 +43,13 @@ class OmniboxMatchCellView : public views::View {
const char* GetClassName() const override;
void LayoutOldStyleAnswer();
void LayoutRichSuggestion();
void LayoutNewStyleTwoLineSuggestion();
void LayoutSplit(int text_indent);
bool is_old_style_answer_;
bool is_rich_suggestion_;
bool is_search_type_;
bool has_tab_match_ = false;
// Weak pointers for easy reference.
views::ImageView* icon_view_; // An icon representing the type or content.
......
......@@ -90,8 +90,8 @@ void OmniboxResultView::SetMatch(const AutocompleteMatch& match) {
// Set up 'switch to tab' button.
if (match.has_tab_match && !match_.associated_keyword.get()) {
suggestion_tab_switch_button_ = std::make_unique<OmniboxTabSwitchButton>(
model_, this, suggestion_view_->content()->GetLineHeight());
suggestion_tab_switch_button_ =
std::make_unique<OmniboxTabSwitchButton>(model_, this);
suggestion_tab_switch_button_->set_owned_by_client();
AddChildView(suggestion_tab_switch_button_.get());
} else {
......
......@@ -23,10 +23,8 @@ size_t OmniboxTabSwitchButton::short_text_width_;
size_t OmniboxTabSwitchButton::full_text_width_;
OmniboxTabSwitchButton::OmniboxTabSwitchButton(OmniboxPopupContentsView* model,
OmniboxResultView* result_view,
int text_height)
OmniboxResultView* result_view)
: MdTextButton(result_view, views::style::CONTEXT_BUTTON_MD),
text_height_(text_height),
model_(model),
result_view_(result_view),
initialized_(false),
......@@ -62,8 +60,7 @@ OmniboxTabSwitchButton::~OmniboxTabSwitchButton() = default;
gfx::Size OmniboxTabSwitchButton::CalculatePreferredSize() const {
gfx::Size size = MdTextButton::CalculatePreferredSize();
// Bump height if odd.
size.set_height(text_height_ + (text_height_ & 1) + 2 * kVerticalPadding);
size.set_height(kButtonHeight);
int current_width = animation_->CurrentValueBetween(
static_cast<int>(start_width_), static_cast<int>(goal_width_));
size.set_width(current_width);
......
......@@ -17,8 +17,7 @@ class SlideAnimation;
class OmniboxTabSwitchButton : public views::MdTextButton {
public:
OmniboxTabSwitchButton(OmniboxPopupContentsView* model,
OmniboxResultView* result_view,
int text_height);
OmniboxResultView* result_view);
~OmniboxTabSwitchButton() override;
......@@ -57,8 +56,7 @@ class OmniboxTabSwitchButton : public views::MdTextButton {
// pass back the text at that width.
size_t CalculateGoalWidth(size_t parent_width, base::string16* goal_text);
static constexpr int kVerticalPadding = 3;
const int text_height_;
static constexpr int kButtonHeight = 32;
OmniboxPopupContentsView* model_;
OmniboxResultView* result_view_;
......
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