diff options
author | varunjain@chromium.org <varunjain@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-16 02:55:48 +0000 |
---|---|---|
committer | varunjain@chromium.org <varunjain@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-16 02:55:48 +0000 |
commit | 8b0f2cc2f919bcc0f5f445a3de0a2f3eb868e0e4 (patch) | |
tree | d5d9a3953238cc97bdc71952cb62a8764ac31d27 /ash/tooltips | |
parent | 4aae97d0c88fa0f5d0e7aa5a7dd6185c153bcf3c (diff) | |
download | chromium_src-8b0f2cc2f919bcc0f5f445a3de0a2f3eb868e0e4.zip chromium_src-8b0f2cc2f919bcc0f5f445a3de0a2f3eb868e0e4.tar.gz chromium_src-8b0f2cc2f919bcc0f5f445a3de0a2f3eb868e0e4.tar.bz2 |
aura: Tooltips need to disappear if the user clicks a button and not show up until
there is a change.
BUG=117999,117603
TEST=manual
Review URL: http://codereview.chromium.org/9704034
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@127092 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash/tooltips')
-rw-r--r-- | ash/tooltips/tooltip_controller.cc | 44 | ||||
-rw-r--r-- | ash/tooltips/tooltip_controller.h | 8 |
2 files changed, 48 insertions, 4 deletions
diff --git a/ash/tooltips/tooltip_controller.cc b/ash/tooltips/tooltip_controller.cc index b23d227..52049e7 100644 --- a/ash/tooltips/tooltip_controller.cc +++ b/ash/tooltips/tooltip_controller.cc @@ -12,7 +12,9 @@ #include "base/location.h" #include "base/string_split.h" #include "base/time.h" +#include "ui/aura/client/drag_drop_client.h" #include "ui/aura/event.h" +#include "ui/aura/root_window.h" #include "ui/aura/window.h" #include "ui/base/resource/resource_bundle.h" #include "ui/base/text/text_elider.h" @@ -214,6 +216,8 @@ class TooltipController::Tooltip { TooltipController::TooltipController() : tooltip_window_(NULL), + tooltip_window_at_mouse_press_(NULL), + mouse_pressed_(false), tooltip_(new Tooltip), tooltips_enabled_(true) { tooltip_timer_.Start(FROM_HERE, @@ -249,6 +253,7 @@ bool TooltipController::PreHandleMouseEvent(aura::Window* target, aura::MouseEvent* event) { switch (event->type()) { case ui::ET_MOUSE_MOVED: + case ui::ET_MOUSE_DRAGGED: if (tooltip_window_ != target) { if (tooltip_window_) tooltip_window_->RemoveObserver(this); @@ -259,14 +264,25 @@ bool TooltipController::PreHandleMouseEvent(aura::Window* target, if (tooltip_timer_.IsRunning()) tooltip_timer_.Reset(); - if (tooltip_->IsVisible()) + // We update the tooltip if it is visible, or if we force-hid it due to a + // mouse press. + if (tooltip_->IsVisible() || tooltip_window_at_mouse_press_) UpdateIfRequired(); break; case ui::ET_MOUSE_PRESSED: + mouse_pressed_ = true; + tooltip_window_at_mouse_press_ = target; + if (target) + tooltip_text_at_mouse_press_ = aura::client::GetTooltipText(target); + tooltip_->Hide(); + break; case ui::ET_MOUSE_RELEASED: - case ui::ET_MOUSE_DRAGGED: - case ui::ET_MOUSEWHEEL: + mouse_pressed_ = false; + break; case ui::ET_MOUSE_CAPTURE_CHANGED: + // We will not received a mouse release, so reset mouse pressed state. + mouse_pressed_ = false; + case ui::ET_MOUSEWHEEL: // Hide the tooltip for click, release, drag, wheel events. if (tooltip_->IsVisible()) tooltip_->Hide(); @@ -309,14 +325,26 @@ void TooltipController::TooltipTimerFired() { } void TooltipController::UpdateIfRequired() { - if (!tooltips_enabled_) { + if (!tooltips_enabled_ || mouse_pressed_ || IsDragDropInProgress()) { tooltip_->Hide(); return; } + string16 tooltip_text; if (tooltip_window_) tooltip_text = aura::client::GetTooltipText(tooltip_window_); + // If the user pressed a mouse button. We will hide the tooltip and not show + // it until there is a change in the tooltip. + if (tooltip_window_at_mouse_press_) { + if (tooltip_window_ == tooltip_window_at_mouse_press_ && + tooltip_text == tooltip_text_at_mouse_press_) { + tooltip_->Hide(); + return; + } + tooltip_window_at_mouse_press_ = NULL; + } + // 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. @@ -340,5 +368,13 @@ bool TooltipController::IsTooltipVisible() { return tooltip_->IsVisible(); } +bool TooltipController::IsDragDropInProgress() { + aura::client::DragDropClient* client = aura::client::GetDragDropClient( + Shell::GetRootWindow()); + if (client) + return client->IsDragDropInProgress(); + return false; +} + } // namespace internal } // namespace ash diff --git a/ash/tooltips/tooltip_controller.h b/ash/tooltips/tooltip_controller.h index 9de5cee..e2b8ed6 100644 --- a/ash/tooltips/tooltip_controller.h +++ b/ash/tooltips/tooltip_controller.h @@ -69,8 +69,16 @@ class ASH_EXPORT TooltipController : public aura::client::TooltipClient, // Only used in tests. bool IsTooltipVisible(); + bool IsDragDropInProgress(); + aura::Window* tooltip_window_; string16 tooltip_text_; + + // These fields are for tracking state when the user presses a mouse button. + aura::Window* tooltip_window_at_mouse_press_; + string16 tooltip_text_at_mouse_press_; + bool mouse_pressed_; + scoped_ptr<Tooltip> tooltip_; base::RepeatingTimer<TooltipController> tooltip_timer_; |