Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(235)

Unified Diff: ui/views/corewm/tooltip_controller.cc

Issue 2643973002: Revert of Remove unnecessary spin in ToolTipController (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/views/corewm/tooltip_controller.h ('k') | ui/views/corewm/tooltip_controller_test_helper.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/corewm/tooltip_controller.cc
diff --git a/ui/views/corewm/tooltip_controller.cc b/ui/views/corewm/tooltip_controller.cc
index 299a039ec42c7102218378b7672ccae94c19a066..cd1792ffa29d03692804fa4162d8a450adcb171c 100644
--- a/ui/views/corewm/tooltip_controller.cc
+++ b/ui/views/corewm/tooltip_controller.cc
@@ -25,12 +25,12 @@
#include "ui/gfx/text_elider.h"
#include "ui/views/corewm/tooltip.h"
#include "ui/views/widget/tooltip_manager.h"
-#include "ui/wm/public/tooltip_client.h"
namespace views {
namespace corewm {
namespace {
+const int kTooltipTimeoutMs = 500;
const int kDefaultTooltipShownTimeoutMs = 10000;
#if defined(OS_WIN)
// Drawing a long word in tooltip is very slow on Windows. crbug.com/513693
@@ -129,7 +129,11 @@
tooltip_id_(NULL),
tooltip_window_at_mouse_press_(NULL),
tooltip_(std::move(tooltip)),
- tooltips_enabled_(true) {}
+ tooltips_enabled_(true) {
+ tooltip_timer_.Start(FROM_HERE,
+ base::TimeDelta::FromMilliseconds(kTooltipTimeoutMs),
+ this, &TooltipController::TooltipTimerFired);
+}
TooltipController::~TooltipController() {
if (tooltip_window_)
@@ -146,13 +150,26 @@
UpdateIfRequired();
// Reset |tooltip_window_at_mouse_press_| if the moving within the same window
- // but over a region that has different tooltip text.
+ // but over a region that has different tooltip text. By resetting
+ // |tooltip_window_at_mouse_press_| we ensure the next time the timer fires
+ // we'll requery for the tooltip text.
// This handles the case of clicking on a view, moving within the same window
// but over a different view, than back to the original.
if (tooltip_window_at_mouse_press_ &&
target == tooltip_window_at_mouse_press_ &&
aura::client::GetTooltipText(target) != tooltip_text_at_mouse_press_) {
tooltip_window_at_mouse_press_ = NULL;
+ }
+
+ // If we had stopped the tooltip timer for some reason, we must restart it if
+ // there is a change in the tooltip.
+ if (!tooltip_timer_.IsRunning()) {
+ if (tooltip_window_ != target || (tooltip_window_ &&
+ tooltip_text_ != aura::client::GetTooltipText(tooltip_window_))) {
+ tooltip_timer_.Start(FROM_HERE,
+ base::TimeDelta::FromMilliseconds(kTooltipTimeoutMs),
+ this, &TooltipController::TooltipTimerFired);
+ }
}
}
@@ -194,10 +211,10 @@
target = GetTooltipTarget(*event, &curr_mouse_loc_);
}
SetTooltipWindow(target);
-
- if (tooltip_->IsVisible() ||
- (tooltip_window_ &&
- tooltip_text_ != aura::client::GetTooltipText(tooltip_window_)))
+ if (tooltip_timer_.IsRunning())
+ tooltip_timer_.Reset();
+
+ if (tooltip_->IsVisible())
UpdateIfRequired();
break;
}
@@ -215,6 +232,10 @@
// Hide the tooltip for click, release, drag, wheel events.
if (tooltip_->IsVisible())
tooltip_->Hide();
+
+ // Don't reshow the tooltip during scroll.
+ if (tooltip_timer_.IsRunning())
+ tooltip_timer_.Reset();
break;
default:
break;
@@ -234,10 +255,6 @@
SetTooltipWindow(NULL);
}
-void TooltipController::OnCursorVisibilityChanged(bool is_visible) {
- UpdateIfRequired();
-}
-
void TooltipController::OnWindowDestroyed(aura::Window* window) {
if (tooltip_window_ == window) {
tooltip_->Hide();
@@ -246,22 +263,20 @@
}
}
-void TooltipController::OnWindowPropertyChanged(aura::Window* window,
- const void* key,
- intptr_t old) {
- if ((key == aura::client::kTooltipIdKey ||
- key == aura::client::kTooltipTextKey) &&
- aura::client::GetTooltipText(window) != base::string16() &&
- (tooltip_text_ != aura::client::GetTooltipText(window) ||
- tooltip_id_ != aura::client::GetTooltipId(window)))
- UpdateIfRequired();
-}
-
////////////////////////////////////////////////////////////////////////////////
// TooltipController private:
+void TooltipController::TooltipTimerFired() {
+ UpdateIfRequired();
+}
+
void TooltipController::TooltipShownTimerFired() {
tooltip_->Hide();
+
+ // Since the user presumably no longer needs the tooltip, we also stop the
+ // tooltip timer so that tooltip does not pop back up. We will restart this
+ // timer if the tooltip changes (see UpdateTooltip()).
+ tooltip_timer_.Stop();
}
void TooltipController::UpdateIfRequired() {
@@ -294,6 +309,9 @@
ids_differ = tooltip_id_ != tooltip_id;
tooltip_id_ = tooltip_id;
+ // We add the !tooltip_->IsVisible() below because when we come here from
+ // TooltipTimerFired(), the tooltip_text may not have changed but we still
+ // want to update the tooltip because the timer has fired.
// If we come here from UpdateTooltip(), we have already checked for tooltip
// visibility and this check below will have no effect.
if (tooltip_text_ != tooltip_text || !tooltip_->IsVisible() || ids_differ) {
« no previous file with comments | « ui/views/corewm/tooltip_controller.h ('k') | ui/views/corewm/tooltip_controller_test_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698