Commit e723d21d authored by Stephen Sigwart's avatar Stephen Sigwart Committed by Commit Bot

[omnibox] Fix focus state when not focused

If you hover over the remove X, then quickly off the X and row,
OnMouseEntered and OnMouseExited are not called on the row. This causes
the row to display as focused and the X to show. You can also duplicate
it by quickly sliding moving the mouse over the rows where the X button
displays.

Bug: 1109473
Change-Id: Ie5621f6e1d780d80ff46c34846856b3476f566f4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2333393
Commit-Queue: Justin Donnelly <jdonnelly@chromium.org>
Reviewed-by: default avatarJustin Donnelly <jdonnelly@chromium.org>
Reviewed-by: default avatarRobert Liao <robliao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#800165}
parent 48af586a
......@@ -73,6 +73,9 @@ OmniboxResultView::OmniboxResultView(
// accessibility node data for removable suggestions.
remove_suggestion_button_ =
AddChildView(views::CreateVectorImageButton(this));
// The remove suggestion button may receive mouse enter/exit events with very
// quick mouse movements. Monitor the button to update our state.
update_on_mouse_enter_exit_.emplace(this, remove_suggestion_button_);
views::InstallCircleHighlightPathGenerator(remove_suggestion_button_);
remove_suggestion_button_->SetTooltipText(
l10n_util::GetStringUTF16(IDS_OMNIBOX_REMOVE_SUGGESTION));
......@@ -519,6 +522,26 @@ void OmniboxResultView::EmitTextChangedAccessiblityEvent() {
////////////////////////////////////////////////////////////////////////////////
// OmniboxResultView, private:
OmniboxResultView::UpdateOnMouseEnterExit::UpdateOnMouseEnterExit(
OmniboxResultView* omnibox_result_view,
View* target)
: omnibox_result_view_(omnibox_result_view), target_(target) {
target_->AddPreTargetHandler(this);
}
OmniboxResultView::UpdateOnMouseEnterExit::~UpdateOnMouseEnterExit() {
target_->RemovePreTargetHandler(this);
}
void OmniboxResultView::UpdateOnMouseEnterExit::OnMouseEvent(
ui::MouseEvent* event) {
auto event_type = event->type();
if (event_type != ui::ET_MOUSE_ENTERED && event_type != ui::ET_MOUSE_EXITED)
return;
omnibox_result_view_->UpdateHoverState();
}
gfx::Image OmniboxResultView::GetIcon() const {
return popup_contents_view_->GetMatchIcon(
match_, GetColor(OmniboxPart::RESULTS_ICON));
......
......@@ -11,10 +11,12 @@
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/optional.h"
#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/window_open_disposition.h"
#include "ui/events/event_handler.h"
#include "ui/gfx/animation/slide_animation.h"
#include "ui/gfx/font_list.h"
#include "ui/gfx/geometry/rect.h"
......@@ -105,6 +107,22 @@ class OmniboxResultView : public views::View,
void OnThemeChanged() override;
private:
// Calls UpdateHoverState() when a target receives a mouse enter/exit.
class UpdateOnMouseEnterExit : public ui::EventHandler {
public:
UpdateOnMouseEnterExit(OmniboxResultView* omnibox_result_view,
View* target);
UpdateOnMouseEnterExit(const UpdateOnMouseEnterExit&) = delete;
UpdateOnMouseEnterExit& operator=(const UpdateOnMouseEnterExit&) = delete;
~UpdateOnMouseEnterExit() override;
private:
void OnMouseEvent(ui::MouseEvent* event) override;
OmniboxResultView* const omnibox_result_view_;
View* const target_;
};
// Returns the height of the text portion of the result view.
int GetTextHeight() const;
......@@ -159,6 +177,7 @@ class OmniboxResultView : public views::View,
// The "X" button at the end of the match cell, used to remove suggestions.
views::ImageButton* remove_suggestion_button_;
views::FocusRing* remove_suggestion_focus_ring_ = nullptr;
base::Optional<UpdateOnMouseEnterExit> update_on_mouse_enter_exit_;
base::WeakPtrFactory<OmniboxResultView> weak_factory_{this};
......
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