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

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

Issue 2615993002: Remove unnecessary spin in ToolTipController (Closed)
Patch Set: Address comments. 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 cd1792ffa29d03692804fa4162d8a450adcb171c..299a039ec42c7102218378b7672ccae94c19a066 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,11 +129,7 @@ TooltipController::TooltipController(std::unique_ptr<Tooltip> tooltip)
tooltip_id_(NULL),
tooltip_window_at_mouse_press_(NULL),
tooltip_(std::move(tooltip)),
- tooltips_enabled_(true) {
- tooltip_timer_.Start(FROM_HERE,
- base::TimeDelta::FromMilliseconds(kTooltipTimeoutMs),
- this, &TooltipController::TooltipTimerFired);
-}
+ tooltips_enabled_(true) {}
TooltipController::~TooltipController() {
if (tooltip_window_)
@@ -150,9 +146,7 @@ void TooltipController::UpdateTooltip(aura::Window* target) {
UpdateIfRequired();
// Reset |tooltip_window_at_mouse_press_| if the moving within the same window
- // 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.
+ // but over a region that has different 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_ &&
@@ -160,17 +154,6 @@ void TooltipController::UpdateTooltip(aura::Window* target) {
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);
- }
- }
}
void TooltipController::SetTooltipShownTimeout(aura::Window* target,
@@ -211,10 +194,10 @@ void TooltipController::OnMouseEvent(ui::MouseEvent* event) {
target = GetTooltipTarget(*event, &curr_mouse_loc_);
}
SetTooltipWindow(target);
- if (tooltip_timer_.IsRunning())
- tooltip_timer_.Reset();
- if (tooltip_->IsVisible())
+ if (tooltip_->IsVisible() ||
+ (tooltip_window_ &&
+ tooltip_text_ != aura::client::GetTooltipText(tooltip_window_)))
UpdateIfRequired();
break;
}
@@ -232,10 +215,6 @@ void TooltipController::OnMouseEvent(ui::MouseEvent* event) {
// 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;
@@ -255,6 +234,10 @@ void TooltipController::OnCancelMode(ui::CancelModeEvent* event) {
SetTooltipWindow(NULL);
}
+void TooltipController::OnCursorVisibilityChanged(bool is_visible) {
+ UpdateIfRequired();
+}
+
void TooltipController::OnWindowDestroyed(aura::Window* window) {
if (tooltip_window_ == window) {
tooltip_->Hide();
@@ -263,20 +246,22 @@ void TooltipController::OnWindowDestroyed(aura::Window* window) {
}
}
+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() {
@@ -309,9 +294,6 @@ void TooltipController::UpdateIfRequired() {
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