Commit 9f7342bf authored by Kevin Bailey's avatar Kevin Bailey Committed by Commit Bot

[omnibox] Recreating tab switch button on appropriate set match

The tab switch button won't show background changes after being hidden
and re-shown. This is to work-around that, by recreating it on each set
match that needs it. (Creating it is needed if the match type is a tab
switch and the tab switch button behavior was enabled.) This change
also restores the strategy of not creating a tab switch button unless
and until needed.

Bug: 825372
Change-Id: I0b808969ee5e9b91e3ca292fa929447da148d75c
Reviewed-on: https://chromium-review.googlesource.com/992356
Commit-Queue: Kevin Bailey <krb@chromium.org>
Reviewed-by: default avatarJustin Donnelly <jdonnelly@chromium.org>
Cr-Commit-Position: refs/heads/master@{#547834}
parent 0fd5eef3
...@@ -226,12 +226,6 @@ OmniboxResultView::OmniboxResultView(OmniboxPopupContentsView* model, ...@@ -226,12 +226,6 @@ OmniboxResultView::OmniboxResultView(OmniboxPopupContentsView* model,
omnibox::kKeywordSearchIcon, GetLayoutConstant(LOCATION_BAR_ICON_SIZE), omnibox::kKeywordSearchIcon, GetLayoutConstant(LOCATION_BAR_ICON_SIZE),
GetColor(OmniboxPart::RESULTS_ICON))); GetColor(OmniboxPart::RESULTS_ICON)));
keyword_icon_view_->SizeToPreferredSize(); keyword_icon_view_->SizeToPreferredSize();
if (OmniboxFieldTrial::InTabSwitchSuggestionWithButtonTrial()) {
suggestion_tab_switch_button_ =
std::make_unique<OmniboxTabSwitchButton>(this, GetTextHeight());
suggestion_tab_switch_button_->set_owned_by_client();
}
} }
OmniboxResultView::~OmniboxResultView() {} OmniboxResultView::~OmniboxResultView() {}
...@@ -249,15 +243,16 @@ void OmniboxResultView::SetMatch(const AutocompleteMatch& match) { ...@@ -249,15 +243,16 @@ void OmniboxResultView::SetMatch(const AutocompleteMatch& match) {
suggestion_image_view_->SetVisible(false); // Until SetAnswerImage is called. suggestion_image_view_->SetVisible(false); // Until SetAnswerImage is called.
keyword_icon_view_->SetVisible(match_.associated_keyword.get()); keyword_icon_view_->SetVisible(match_.associated_keyword.get());
if (suggestion_tab_switch_button_) {
if (match.type == AutocompleteMatchType::TAB_SEARCH && if (OmniboxFieldTrial::InTabSwitchSuggestionWithButtonTrial() &&
!keyword_icon_view_->visible()) { match.type == AutocompleteMatchType::TAB_SEARCH &&
if (!suggestion_tab_switch_button_->parent()) { !keyword_icon_view_->visible()) {
AddChildView(suggestion_tab_switch_button_.get()); suggestion_tab_switch_button_ =
} std::make_unique<OmniboxTabSwitchButton>(this, GetTextHeight());
} else if (suggestion_tab_switch_button_->parent()) { suggestion_tab_switch_button_->set_owned_by_client();
RemoveChildView(suggestion_tab_switch_button_.get()); AddChildView(suggestion_tab_switch_button_.get());
} } else {
suggestion_tab_switch_button_.reset();
} }
Invalidate(); Invalidate();
if (GetWidget()) if (GetWidget())
...@@ -379,8 +374,7 @@ bool OmniboxResultView::OnMouseDragged(const ui::MouseEvent& event) { ...@@ -379,8 +374,7 @@ bool OmniboxResultView::OnMouseDragged(const ui::MouseEvent& event) {
if (event.IsOnlyLeftMouseButton()) { if (event.IsOnlyLeftMouseButton()) {
if (!IsSelected()) if (!IsSelected())
model_->SetSelectedLine(model_index_); model_->SetSelectedLine(model_index_);
if (suggestion_tab_switch_button_ && if (suggestion_tab_switch_button_) {
suggestion_tab_switch_button_->parent()) {
gfx::Point point_in_child_coords(event.location()); gfx::Point point_in_child_coords(event.location());
View::ConvertPointToTarget(this, suggestion_tab_switch_button_.get(), View::ConvertPointToTarget(this, suggestion_tab_switch_button_.get(),
&point_in_child_coords); &point_in_child_coords);
...@@ -594,8 +588,7 @@ void OmniboxResultView::Layout() { ...@@ -594,8 +588,7 @@ void OmniboxResultView::Layout() {
suggestion_icon_view_->SetBounds( suggestion_icon_view_->SetBounds(
start_x, icon_y, std::min(end_x, icon.Width()), icon.Height()); start_x, icon_y, std::min(end_x, icon.Width()), icon.Height());
if (suggestion_tab_switch_button_ && if (suggestion_tab_switch_button_) {
match_.type == AutocompleteMatchType::TAB_SEARCH) {
const gfx::Size ts_button_size = const gfx::Size ts_button_size =
suggestion_tab_switch_button_->GetPreferredSize(); suggestion_tab_switch_button_->GetPreferredSize();
suggestion_tab_switch_button_->SetSize(ts_button_size); suggestion_tab_switch_button_->SetSize(ts_button_size);
......
...@@ -56,7 +56,7 @@ void OmniboxTabSwitchButton::StateChanged(ButtonState old_state) { ...@@ -56,7 +56,7 @@ void OmniboxTabSwitchButton::StateChanged(ButtonState old_state) {
} }
if (state() == STATE_PRESSED) if (state() == STATE_PRESSED)
SetPressed(); SetPressed();
LabelButton::StateChanged(old_state); MdTextButton::StateChanged(old_state);
} }
SkColor OmniboxTabSwitchButton::GetBackgroundColor() const { SkColor OmniboxTabSwitchButton::GetBackgroundColor() const {
......
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