Commit 5387de11 authored by David Black's avatar David Black Committed by Commit Bot

Don't auto-close proactive suggestions view when hovered over.

Per guidelines from UX, when the view is un-hovered, the auto-close
timer should resume with whatever time is left remaining.

Bug: b:140645793
Change-Id: I0370d2ac6f534a9e0b3ac8dd4486d6298fe48ce2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1797344
Commit-Queue: David Black <dmblack@google.com>
Reviewed-by: default avatarXiaohui Chen <xiaohuic@chromium.org>
Reviewed-by: default avatarTao Wu <wutao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#696106}
parent 928c5e7f
...@@ -298,6 +298,34 @@ void AssistantUiController::OnProactiveSuggestionsCloseButtonPressed() { ...@@ -298,6 +298,34 @@ void AssistantUiController::OnProactiveSuggestionsCloseButtonPressed() {
DCHECK(!proactive_suggestions_view_); DCHECK(!proactive_suggestions_view_);
} }
void AssistantUiController::OnProactiveSuggestionsViewHoverChanged(
bool is_hovering) {
if (!is_hovering) {
// When the user is no longer hovering over the proactive suggestions view
// we need to reset the timer so that it will auto-close appropriately.
auto_close_proactive_suggestions_timer_.Reset();
return;
}
const base::TimeDelta remaining_time =
auto_close_proactive_suggestions_timer_.desired_run_time() -
base::TimeTicks::Now();
// The user is now hovering over the proactive suggestions view so we need to
// pause the auto-close timer until we are no longer in a hovering state. Once
// we leave hovering state, we will resume the auto-close timer with whatever
// |remaining_time| is left on the timer. To accomplish this, we schedule the
// auto-close timer to fire in the future...
auto_close_proactive_suggestions_timer_.Start(
FROM_HERE, remaining_time,
auto_close_proactive_suggestions_timer_.user_task());
// ...but immediately stop it so that when we reset the auto-close timer upon
// leaving hovering state, the timer will appriopriately fire only after the
// |remaining_time| has elapsed.
auto_close_proactive_suggestions_timer_.Stop();
}
void AssistantUiController::OnProactiveSuggestionsViewPressed() { void AssistantUiController::OnProactiveSuggestionsViewPressed() {
ResetProactiveSuggestionsView( ResetProactiveSuggestionsView(
assistant_controller_->suggestions_controller() assistant_controller_->suggestions_controller()
......
...@@ -108,6 +108,7 @@ class ASH_EXPORT AssistantUiController ...@@ -108,6 +108,7 @@ class ASH_EXPORT AssistantUiController
void OnDialogPlateButtonPressed(AssistantButtonId id) override; void OnDialogPlateButtonPressed(AssistantButtonId id) override;
void OnMiniViewPressed() override; void OnMiniViewPressed() override;
void OnProactiveSuggestionsCloseButtonPressed() override; void OnProactiveSuggestionsCloseButtonPressed() override;
void OnProactiveSuggestionsViewHoverChanged(bool is_hovering) override;
void OnProactiveSuggestionsViewPressed() override; void OnProactiveSuggestionsViewPressed() override;
// HighlighterController::Observer: // HighlighterController::Observer:
...@@ -197,7 +198,7 @@ class ASH_EXPORT AssistantUiController ...@@ -197,7 +198,7 @@ class ASH_EXPORT AssistantUiController
// When shown, the proactive suggestions widget will automatically be closed // When shown, the proactive suggestions widget will automatically be closed
// if the user doesn't interact with it within a fixed interval. // if the user doesn't interact with it within a fixed interval.
base::OneShotTimer auto_close_proactive_suggestions_timer_; base::RetainingOneShotTimer auto_close_proactive_suggestions_timer_;
// Whether the UI controller is observing changes to the usable work area. // Whether the UI controller is observing changes to the usable work area.
bool is_observing_usable_work_area_ = false; bool is_observing_usable_work_area_ = false;
......
...@@ -154,6 +154,12 @@ void AssistantViewDelegateImpl::OnProactiveSuggestionsCloseButtonPressed() { ...@@ -154,6 +154,12 @@ void AssistantViewDelegateImpl::OnProactiveSuggestionsCloseButtonPressed() {
observer.OnProactiveSuggestionsCloseButtonPressed(); observer.OnProactiveSuggestionsCloseButtonPressed();
} }
void AssistantViewDelegateImpl::OnProactiveSuggestionsViewHoverChanged(
bool is_hovering) {
for (auto& observer : view_delegate_observers_)
observer.OnProactiveSuggestionsViewHoverChanged(is_hovering);
}
void AssistantViewDelegateImpl::OnProactiveSuggestionsViewPressed() { void AssistantViewDelegateImpl::OnProactiveSuggestionsViewPressed() {
for (auto& observer : view_delegate_observers_) for (auto& observer : view_delegate_observers_)
observer.OnProactiveSuggestionsViewPressed(); observer.OnProactiveSuggestionsViewPressed();
......
...@@ -60,6 +60,7 @@ class AssistantViewDelegateImpl : public AssistantViewDelegate { ...@@ -60,6 +60,7 @@ class AssistantViewDelegateImpl : public AssistantViewDelegate {
int notification_button_index) override; int notification_button_index) override;
void OnOptInButtonPressed() override; void OnOptInButtonPressed() override;
void OnProactiveSuggestionsCloseButtonPressed() override; void OnProactiveSuggestionsCloseButtonPressed() override;
void OnProactiveSuggestionsViewHoverChanged(bool is_hovering) override;
void OnProactiveSuggestionsViewPressed() override; void OnProactiveSuggestionsViewPressed() override;
void OnSuggestionChipPressed(const AssistantSuggestion* suggestion) override; void OnSuggestionChipPressed(const AssistantSuggestion* suggestion) override;
void OpenUrlFromView(const GURL& url) override; void OpenUrlFromView(const GURL& url) override;
......
...@@ -63,6 +63,9 @@ class COMPONENT_EXPORT(ASSISTANT_UI) AssistantViewDelegateObserver ...@@ -63,6 +63,9 @@ class COMPONENT_EXPORT(ASSISTANT_UI) AssistantViewDelegateObserver
// Invoked when the proactive suggestions close button is pressed. // Invoked when the proactive suggestions close button is pressed.
virtual void OnProactiveSuggestionsCloseButtonPressed() {} virtual void OnProactiveSuggestionsCloseButtonPressed() {}
// Invoked when the hover state of the proactive suggestions view is changed.
virtual void OnProactiveSuggestionsViewHoverChanged(bool is_hovering) {}
// Invoked when the proactive suggestions view is pressed. // Invoked when the proactive suggestions view is pressed.
virtual void OnProactiveSuggestionsViewPressed() {} virtual void OnProactiveSuggestionsViewPressed() {}
...@@ -164,6 +167,9 @@ class COMPONENT_EXPORT(ASSISTANT_UI) AssistantViewDelegate { ...@@ -164,6 +167,9 @@ class COMPONENT_EXPORT(ASSISTANT_UI) AssistantViewDelegate {
// Invoked when the proactive suggestions close button is pressed. // Invoked when the proactive suggestions close button is pressed.
virtual void OnProactiveSuggestionsCloseButtonPressed() {} virtual void OnProactiveSuggestionsCloseButtonPressed() {}
// Invoked when the hover state of the proactive suggestions view is changed.
virtual void OnProactiveSuggestionsViewHoverChanged(bool is_hovering) {}
// Invoked when the proactive suggestions view is pressed. // Invoked when the proactive suggestions view is pressed.
virtual void OnProactiveSuggestionsViewPressed() {} virtual void OnProactiveSuggestionsViewPressed() {}
......
...@@ -84,6 +84,32 @@ void ProactiveSuggestionsView::OnPaintBackground(gfx::Canvas* canvas) { ...@@ -84,6 +84,32 @@ void ProactiveSuggestionsView::OnPaintBackground(gfx::Canvas* canvas) {
canvas->DrawRoundRect(GetLocalBounds(), radius, flags); canvas->DrawRoundRect(GetLocalBounds(), radius, flags);
} }
void ProactiveSuggestionsView::OnMouseEntered(const ui::MouseEvent& event) {
views::Button::OnMouseEntered(event);
delegate_->OnProactiveSuggestionsViewHoverChanged(/*is_hovering=*/true);
}
void ProactiveSuggestionsView::OnMouseExited(const ui::MouseEvent& event) {
views::Button::OnMouseExited(event);
delegate_->OnProactiveSuggestionsViewHoverChanged(/*is_hovering=*/false);
}
void ProactiveSuggestionsView::OnGestureEvent(ui::GestureEvent* event) {
views::Button::OnGestureEvent(event);
switch (event->type()) {
case ui::ET_GESTURE_TAP:
case ui::ET_GESTURE_TAP_CANCEL:
delegate_->OnProactiveSuggestionsViewHoverChanged(/*is_hovering=*/false);
break;
case ui::ET_GESTURE_TAP_DOWN:
delegate_->OnProactiveSuggestionsViewHoverChanged(/*is_hovering=*/true);
break;
default:
// No action necessary.
break;
}
}
void ProactiveSuggestionsView::ButtonPressed(views::Button* sender, void ProactiveSuggestionsView::ButtonPressed(views::Button* sender,
const ui::Event& event) { const ui::Event& event) {
// There are two possible |senders|, the close button... // There are two possible |senders|, the close button...
......
...@@ -32,6 +32,9 @@ class COMPONENT_EXPORT(ASSISTANT_UI) ProactiveSuggestionsView ...@@ -32,6 +32,9 @@ class COMPONENT_EXPORT(ASSISTANT_UI) ProactiveSuggestionsView
gfx::Size CalculatePreferredSize() const override; gfx::Size CalculatePreferredSize() const override;
int GetHeightForWidth(int width) const override; int GetHeightForWidth(int width) const override;
void OnPaintBackground(gfx::Canvas* canvas) override; void OnPaintBackground(gfx::Canvas* canvas) override;
void OnGestureEvent(ui::GestureEvent* event) override;
void OnMouseEntered(const ui::MouseEvent& event) override;
void OnMouseExited(const ui::MouseEvent& event) override;
// views::ButtonListener: // views::ButtonListener:
void ButtonPressed(views::Button* sender, const ui::Event& event) override; void ButtonPressed(views::Button* sender, const ui::Event& event) override;
......
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