Commit 0eb8a0a8 authored by Tommy Li's avatar Tommy Li Committed by Commit Bot

[omnibox] Remove context menu for suggestions in OmniboxResultView

We're proceeding with a button-based remove interface instead of the
context menu.

We may add this back later for some other reason, but we don't need it
currently, so this CL rips it out.

Bug: 1205, 929477
Change-Id: I87a6b9b283e6d16656fe263c5271f51192d74adb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1834895Reviewed-by: default avatarmanuk hovanesian <manukh@chromium.org>
Commit-Queue: Tommy Li <tommycli@chromium.org>
Cr-Commit-Position: refs/heads/master@{#702202}
parent 7920cf55
......@@ -37,8 +37,6 @@
#include "ui/events/event.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/views/controls/button/image_button_factory.h"
#include "ui/views/controls/menu/menu_runner.h"
#if defined(OS_WIN)
#include "base/win/atl.h"
#endif
......@@ -68,15 +66,6 @@ OmniboxResultView::OmniboxResultView(
omnibox::kKeywordSearchIcon, GetLayoutConstant(LOCATION_BAR_ICON_SIZE),
GetColor(OmniboxPart::RESULTS_ICON)));
keyword_view_->icon()->SizeToPreferredSize();
if (base::FeatureList::IsEnabled(
omnibox::kOmniboxSuggestionTransparencyOptions)) {
context_menu_contents_.AddItemWithStringId(IDS_OMNIBOX_WHY_THIS_SUGGESTION,
IDS_OMNIBOX_WHY_THIS_SUGGESTION);
context_menu_contents_.AddItemWithStringId(IDS_OMNIBOX_REMOVE_SUGGESTION,
IDS_OMNIBOX_REMOVE_SUGGESTION);
set_context_menu_controller(this);
}
}
OmniboxResultView::~OmniboxResultView() {}
......@@ -444,64 +433,6 @@ void OmniboxResultView::OnThemeChanged() {
SchedulePaint();
}
void OmniboxResultView::ShowContextMenuForViewImpl(
views::View* source,
const gfx::Point& point,
ui::MenuSourceType source_type) {
// Deferred unhover of the result until the context menu is closed.
// If the mouse is still over the result when the context menu is closed, the
// View will receive an OnMouseMoved call anyways, which sets hover to true.
base::RepeatingClosure set_hovered_false = base::BindRepeating(
&OmniboxResultView::SetHovered, weak_factory_.GetWeakPtr(), false);
context_menu_runner_ = std::make_unique<views::MenuRunner>(
&context_menu_contents_,
views::MenuRunner::HAS_MNEMONICS | views::MenuRunner::CONTEXT_MENU,
set_hovered_false);
context_menu_runner_->RunMenuAt(
GetWidget(), nullptr, gfx::Rect(point, gfx::Size()),
views::MenuAnchorPosition::kTopLeft, source_type);
// Opening the context menu unsets the hover state, but we still want the
// result 'hovered' as long as the context menu is open.
SetHovered(true);
}
// ui::SimpleMenuModel::Delegate overrides:
bool OmniboxResultView::IsCommandIdVisible(int command_id) const {
if (command_id == IDS_OMNIBOX_REMOVE_SUGGESTION)
return match_.SupportsDeletion();
DCHECK(command_id == IDS_OMNIBOX_WHY_THIS_SUGGESTION);
return true;
}
void OmniboxResultView::ExecuteCommand(int command_id, int event_flags) {
// Temporarily inhibit the popup closing on blur while we open the remove
// suggestion confirmation bubble.
popup_contents_view_->model()->set_popup_closes_on_blur(false);
// TODO(tommycli): We re-fetch the original match from the popup model,
// because |match_| already has its contents and description swapped by this
// class, and we don't want that for the bubble. We should improve this.
AutocompleteMatch raw_match =
popup_contents_view_->model()->result().match_at(model_index_);
if (command_id == IDS_OMNIBOX_REMOVE_SUGGESTION) {
TemplateURLService* template_url_service = popup_contents_view_->model()
->edit_model()
->client()
->GetTemplateURLService();
ShowRemoveSuggestion(template_url_service, this, raw_match,
base::BindOnce(&OmniboxResultView::RemoveSuggestion,
weak_factory_.GetWeakPtr()));
} else if (command_id == IDS_OMNIBOX_WHY_THIS_SUGGESTION) {
ShowWhyThisSuggestion(this, raw_match);
}
popup_contents_view_->model()->set_popup_closes_on_blur(true);
}
void OmniboxResultView::ProvideButtonFocusHint() {
suggestion_tab_switch_button_->ProvideFocusHint();
}
......
......@@ -14,13 +14,11 @@
#include "components/omnibox/browser/autocomplete_match.h"
#include "components/omnibox/browser/suggestion_answer.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/base/models/simple_menu_model.h"
#include "ui/base/window_open_disposition.h"
#include "ui/gfx/animation/slide_animation.h"
#include "ui/gfx/font_list.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/views/animation/animation_delegate_views.h"
#include "ui/views/context_menu_controller.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/controls/button/image_button.h"
#include "ui/views/controls/image_view.h"
......@@ -40,15 +38,9 @@ namespace ui {
class ThemeProvider;
}
namespace views {
class MenuRunner;
}
class OmniboxResultView : public views::View,
public views::AnimationDelegateViews,
public views::ButtonListener,
public views::ContextMenuController,
public ui::SimpleMenuModel::Delegate {
public views::ButtonListener {
public:
OmniboxResultView(OmniboxPopupContentsView* popup_contents_view,
int model_index,
......@@ -107,15 +99,6 @@ class OmniboxResultView : public views::View,
gfx::Size CalculatePreferredSize() const override;
void OnThemeChanged() override;
// views::ContextMenuController:
void ShowContextMenuForViewImpl(views::View* source,
const gfx::Point& point,
ui::MenuSourceType source_type) override;
// ui::SimpleMenuModel::Delegate overrides:
bool IsCommandIdVisible(int command_id) const override;
void ExecuteCommand(int command_id, int event_flags) override;
private:
// Returns the height of the text portion of the result view.
int GetTextHeight() const;
......@@ -158,10 +141,6 @@ class OmniboxResultView : public views::View,
// For sliding in the keyword search.
std::unique_ptr<gfx::SlideAnimation> animation_;
// Context menu related members.
ui::SimpleMenuModel context_menu_contents_{this};
std::unique_ptr<views::MenuRunner> context_menu_runner_;
// Weak pointers for easy reference.
OmniboxMatchCellView* suggestion_view_; // The leading (or left) view.
OmniboxMatchCellView* keyword_view_; // The trailing (or right) view.
......
......@@ -113,8 +113,3 @@ void ShowRemoveSuggestion(TemplateURLService* template_url_service,
template_url_service, anchor_view, match, std::move(remove_closure)))
->Show();
}
void ShowWhyThisSuggestion(views::View* anchor_view,
const AutocompleteMatch& match) {
// TODO(tommycli): Implement this.
}
......@@ -22,8 +22,4 @@ void ShowRemoveSuggestion(TemplateURLService* template_url_service,
const AutocompleteMatch& match,
base::OnceClosure remove_closure);
// Shows a simple "Why this suggestion" info bubble for |match|.
void ShowWhyThisSuggestion(views::View* anchor_view,
const AutocompleteMatch& match);
#endif // CHROME_BROWSER_UI_VIEWS_OMNIBOX_REMOVE_SUGGESTION_BUBBLE_H_
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