Index: ash/tooltips/tooltip_controller.cc |
diff --git a/ash/tooltips/tooltip_controller.cc b/ash/tooltips/tooltip_controller.cc |
index df4f86291ed1a90c87e4690896d0116276292481..937ebc7a75008745362b71dc9d4f2a1af7709e8b 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), |
@@ -200,7 +199,7 @@ TooltipController::~TooltipController() { |
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 +250,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 +258,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 +268,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 +283,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 +393,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 +404,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 +417,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,12 +448,18 @@ void TooltipController::UpdateIfRequired() { |
} |
bool TooltipController::IsTooltipVisible() { |
- return tooltip_->IsVisible(); |
+ return GetTooltip()->IsVisible(); |
} |
bool TooltipController::IsDragDropInProgress() { |
return drag_drop_client_->IsDragDropInProgress(); |
} |
+TooltipController::Tooltip* TooltipController::GetTooltip() { |
+ if (!tooltip_.get()) |
+ tooltip_.reset(new Tooltip); |
+ return tooltip_.get(); |
+} |
+ |
} // namespace internal |
} // namespace ash |