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

Unified Diff: ash/tooltips/tooltip_controller.cc

Issue 10832194: aura: Fix crash when the aura window hosting a tooltip is destroyed. We fix (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: patch Created 8 years, 4 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 | « no previous file | ash/tooltips/tooltip_controller_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ash/tooltips/tooltip_controller.cc
diff --git a/ash/tooltips/tooltip_controller.cc b/ash/tooltips/tooltip_controller.cc
index 470427101ddd3683fe70f9efa8095986cdd03b55..027451885b0f393878fe471451da2ff482c61795 100644
--- a/ash/tooltips/tooltip_controller.cc
+++ b/ash/tooltips/tooltip_controller.cc
@@ -28,6 +28,7 @@
#include "ui/views/border.h"
#include "ui/views/controls/label.h"
#include "ui/views/widget/widget.h"
+#include "ui/views/widget/widget_observer.h"
namespace {
@@ -81,7 +82,6 @@ views::Widget* CreateTooltip() {
params.type = views::Widget::InitParams::TYPE_TOOLTIP;
params.keep_on_top = true;
params.accept_events = false;
- params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
widget->Init(params);
return widget;
}
@@ -92,9 +92,9 @@ namespace ash {
namespace internal {
// Displays a widget with tooltip using a views::Label.
-class TooltipController::Tooltip {
+class TooltipController::Tooltip : public views::WidgetObserver {
public:
- Tooltip() {
+ Tooltip() : widget_(NULL) {
label_.set_background(
views::Background::CreateSolidBackground(kTooltipBackground));
if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAuraNoShadows)) {
@@ -103,12 +103,13 @@ class TooltipController::Tooltip {
kTooltipBorder));
}
label_.set_owned_by_client();
- widget_.reset(CreateTooltip());
- widget_->SetContentsView(&label_);
}
~Tooltip() {
- widget_->Close();
+ if (widget_) {
+ widget_->RemoveObserver(this);
+ widget_->Close();
+ }
}
// Updates the text on the tooltip and resizes to fit.
@@ -131,21 +132,28 @@ class TooltipController::Tooltip {
// Shows the tooltip.
void Show() {
- widget_->Show();
+ GetWidget()->Show();
}
// Hides the tooltip.
void Hide() {
- widget_->Hide();
+ if (widget_)
+ widget_->Hide();
}
bool IsVisible() {
- return widget_->IsVisible();
+ return widget_? widget_->IsVisible() : false;
+ }
+
+ // Overriden from views::WidgetObserver.
+ virtual void OnWidgetClosing(views::Widget* widget) OVERRIDE {
+ DCHECK_EQ(widget_, widget);
+ widget_ = NULL;
}
private:
views::Label label_;
- scoped_ptr<views::Widget> widget_;
+ views::Widget* widget_;
// Adjusts the bounds given by the arguments to fit inside the desktop
// and applies the adjusted bounds to the label_.
@@ -171,9 +179,17 @@ class TooltipController::Tooltip {
if (tooltip_rect.bottom() > display_bounds.bottom())
tooltip_rect.set_y(mouse_pos.y() - tooltip_height);
- widget_->SetBounds(tooltip_rect.AdjustToFit(display_bounds));
+ GetWidget()->SetBounds(tooltip_rect.AdjustToFit(display_bounds));
}
+ views::Widget* GetWidget() {
+ if (!widget_) {
+ widget_ = CreateTooltip();
+ widget_->SetContentsView(&label_);
+ widget_->AddObserver(this);
+ }
+ return widget_;
+ }
};
////////////////////////////////////////////////////////////////////////////////
« no previous file with comments | « no previous file | ash/tooltips/tooltip_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698