diff options
author | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-25 19:16:01 +0000 |
---|---|---|
committer | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-25 19:16:01 +0000 |
commit | 54a37cdc60ec727d603e1073cc0c8259d6067cd9 (patch) | |
tree | 19ad69127b4df10c683710e44ffba5efd73e111e /ash/tooltips | |
parent | 4165df7a920d1649cb6c5c097da493f9539da986 (diff) | |
download | chromium_src-54a37cdc60ec727d603e1073cc0c8259d6067cd9.zip chromium_src-54a37cdc60ec727d603e1073cc0c8259d6067cd9.tar.gz chromium_src-54a37cdc60ec727d603e1073cc0c8259d6067cd9.tar.bz2 |
Create Tooltip object lazily so that it gets proper drop shadow AND the TooltipController can be added to all root windows.
BUG=138870
TEST=manual.
Review URL: https://chromiumcodereview.appspot.com/10828007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@148378 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash/tooltips')
-rw-r--r-- | ash/tooltips/tooltip_controller.cc | 39 | ||||
-rw-r--r-- | ash/tooltips/tooltip_controller.h | 4 |
2 files changed, 26 insertions, 17 deletions
diff --git a/ash/tooltips/tooltip_controller.cc b/ash/tooltips/tooltip_controller.cc index df4f862..937ebc7 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 diff --git a/ash/tooltips/tooltip_controller.h b/ash/tooltips/tooltip_controller.h index c20cf88..68ddd7f 100644 --- a/ash/tooltips/tooltip_controller.h +++ b/ash/tooltips/tooltip_controller.h @@ -84,6 +84,10 @@ class ASH_EXPORT TooltipController : public aura::client::TooltipClient, bool IsDragDropInProgress(); + // This lazily creates the Tooltip instance so that the tooltip window will + // be initialized with appropriate drop shadows. + Tooltip* GetTooltip(); + aura::client::DragDropClient* drag_drop_client_; aura::Window* tooltip_window_; |