Chromium Code Reviews| Index: ash/tooltips/tooltip_controller.cc |
| diff --git a/ash/tooltips/tooltip_controller.cc b/ash/tooltips/tooltip_controller.cc |
| index df4f86291ed1a90c87e4690896d0116276292481..9b52d9213a153c23e8e867c73712db2f55ab5bcd 100644 |
| --- a/ash/tooltips/tooltip_controller.cc |
| +++ b/ash/tooltips/tooltip_controller.cc |
| @@ -185,7 +185,6 @@ 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, |
| base::TimeDelta::FromMilliseconds(kTooltipTimeoutMs), |
| @@ -198,9 +197,15 @@ TooltipController::~TooltipController() { |
| tooltip_window_->RemoveObserver(this); |
| } |
| +TooltipController::Tooltip* TooltipController::GetTooltip() { |
|
sky
2012/07/25 15:02:43
Make position match header.
oshima
2012/07/25 15:17:26
Done.
|
| + if (!tooltip_.get()) |
| + tooltip_.reset(new Tooltip); |
| + return tooltip_.get(); |
| +} |
| + |
| void TooltipController::UpdateTooltip(aura::Window* target) { |
| // If tooltip is visible, we may want to hide it. If it is not, we are ok. |
| - if (tooltip_window_ == target && tooltip_->IsVisible()) |
| + if (tooltip_window_ == target && GetTooltip()->IsVisible()) |
| UpdateIfRequired(); |
| // If we had stopped the tooltip timer for some reason, we must restart it if |
| @@ -251,7 +256,7 @@ bool TooltipController::PreHandleMouseEvent(aura::Window* target, |
| // 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_) |
| + if (GetTooltip()->IsVisible() || tooltip_window_at_mouse_press_) |
| UpdateIfRequired(); |
| break; |
| case ui::ET_MOUSE_PRESSED: |
| @@ -259,7 +264,7 @@ bool TooltipController::PreHandleMouseEvent(aura::Window* target, |
| tooltip_window_at_mouse_press_ = target; |
| if (target) |
| tooltip_text_at_mouse_press_ = aura::client::GetTooltipText(target); |
| - tooltip_->Hide(); |
| + GetTooltip()->Hide(); |
| break; |
| case ui::ET_MOUSE_RELEASED: |
| mouse_pressed_ = false; |
| @@ -269,8 +274,8 @@ bool TooltipController::PreHandleMouseEvent(aura::Window* target, |
| mouse_pressed_ = false; |
| case ui::ET_MOUSEWHEEL: |
| // Hide the tooltip for click, release, drag, wheel events. |
| - if (tooltip_->IsVisible()) |
| - tooltip_->Hide(); |
| + if (GetTooltip()->IsVisible()) |
| + GetTooltip()->Hide(); |
| break; |
| default: |
| break; |
| @@ -284,8 +289,8 @@ ui::TouchStatus TooltipController::PreHandleTouchEvent( |
| // TODO(varunjain): need to properly implement tooltips for |
| // touch events. |
| // Hide the tooltip for touch events. |
| - if (tooltip_->IsVisible()) |
| - tooltip_->Hide(); |
| + if (GetTooltip()->IsVisible()) |
| + GetTooltip()->Hide(); |
| if (tooltip_window_) |
| tooltip_window_->RemoveObserver(this); |
| tooltip_window_ = NULL; |
| @@ -394,7 +399,7 @@ void TooltipController::TooltipTimerFired() { |
| } |
| void TooltipController::TooltipShownTimerFired() { |
| - tooltip_->Hide(); |
| + GetTooltip()->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 |
| @@ -405,7 +410,7 @@ void TooltipController::TooltipShownTimerFired() { |
| void TooltipController::UpdateIfRequired() { |
| if (!tooltips_enabled_ || mouse_pressed_ || IsDragDropInProgress() || |
| !aura::Env::GetInstance()->cursor_manager()->cursor_visible()) { |
| - tooltip_->Hide(); |
| + GetTooltip()->Hide(); |
| return; |
| } |
| @@ -418,29 +423,29 @@ void TooltipController::UpdateIfRequired() { |
| if (tooltip_window_at_mouse_press_) { |
| if (tooltip_window_ == tooltip_window_at_mouse_press_ && |
| tooltip_text == tooltip_text_at_mouse_press_) { |
| - tooltip_->Hide(); |
| + GetTooltip()->Hide(); |
| return; |
| } |
| tooltip_window_at_mouse_press_ = NULL; |
| } |
| - // We add the !tooltip_->IsVisible() below because when we come here from |
| + // We add the !GetTooltip()->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()) { |
| + if (tooltip_text_ != tooltip_text || !GetTooltip()->IsVisible()) { |
| tooltip_shown_timer_.Stop(); |
| tooltip_text_ = tooltip_text; |
| if (tooltip_text_.empty()) { |
| - tooltip_->Hide(); |
| + GetTooltip()->Hide(); |
| } else { |
| string16 tooltip_text(tooltip_text_); |
| gfx::Point widget_loc = curr_mouse_loc_; |
| widget_loc = widget_loc.Add( |
| tooltip_window_->GetBoundsInScreen().origin()); |
| - tooltip_->SetText(tooltip_text, widget_loc); |
| - tooltip_->Show(); |
| + GetTooltip()->SetText(tooltip_text, widget_loc); |
| + GetTooltip()->Show(); |
| tooltip_shown_timer_.Start(FROM_HERE, |
| base::TimeDelta::FromMilliseconds(kTooltipShownTimeoutMs), |
| this, &TooltipController::TooltipShownTimerFired); |
| @@ -449,7 +454,7 @@ void TooltipController::UpdateIfRequired() { |
| } |
| bool TooltipController::IsTooltipVisible() { |
| - return tooltip_->IsVisible(); |
| + return GetTooltip()->IsVisible(); |
| } |
| bool TooltipController::IsDragDropInProgress() { |