Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chromeos/brightness_bubble.h" | 5 #include "chrome/browser/chromeos/brightness_bubble.h" |
| 6 | 6 |
| 7 #include "base/memory/singleton.h" | 7 #include "base/memory/singleton.h" |
| 8 #include "grit/theme_resources.h" | 8 #include "grit/theme_resources.h" |
| 9 #include "ui/base/resource/resource_bundle.h" | 9 #include "ui/base/resource/resource_bundle.h" |
| 10 #include "views/widget/widget.h" | |
| 10 | 11 |
| 11 namespace chromeos { | 12 namespace chromeos { |
| 12 | 13 |
| 13 BrightnessBubble::BrightnessBubble() | |
| 14 : SettingLevelBubble( | |
| 15 ResourceBundle::GetSharedInstance().GetBitmapNamed( | |
| 16 IDR_BRIGHTNESS_BUBBLE_ICON), | |
| 17 ResourceBundle::GetSharedInstance().GetBitmapNamed( | |
| 18 IDR_BRIGHTNESS_BUBBLE_ICON), | |
| 19 ResourceBundle::GetSharedInstance().GetBitmapNamed( | |
| 20 IDR_BRIGHTNESS_BUBBLE_ICON)) { | |
| 21 } | |
| 22 | |
| 23 // static | 14 // static |
| 24 BrightnessBubble* BrightnessBubble::GetInstance() { | 15 BrightnessBubble* BrightnessBubble::GetInstance() { |
| 25 return Singleton<BrightnessBubble>::get(); | 16 return Singleton<BrightnessBubble>::get(); |
| 26 } | 17 } |
| 27 | 18 |
| 19 void BrightnessBubble::OnWidgetClosing(views::Widget* widget) { | |
| 20 // Bubble faded out. | |
| 21 if (widget_ == widget) | |
| 22 widget_closed_ = true; | |
| 23 } | |
| 24 | |
| 25 void BrightnessBubble::ShowBubble(double percent, bool enabled) { | |
| 26 if (!widget_ || widget_closed_) { | |
|
Daniel Erat
2011/10/21 18:24:34
are you leaking widget_ in the closed case? if it
alicet1
2011/10/24 15:46:38
the latter, this bubble shouldnt need to delete. r
| |
| 27 widget_ = SettingLevelBubble::CreateBubble( | |
| 28 ResourceBundle::GetSharedInstance().GetBitmapNamed( | |
| 29 IDR_BRIGHTNESS_BUBBLE_ICON), | |
| 30 ResourceBundle::GetSharedInstance().GetBitmapNamed( | |
| 31 IDR_BRIGHTNESS_BUBBLE_ICON), | |
| 32 ResourceBundle::GetSharedInstance().GetBitmapNamed( | |
| 33 IDR_BRIGHTNESS_BUBBLE_ICON), | |
| 34 percent, | |
| 35 enabled); | |
| 36 widget_->AddObserver(this); | |
| 37 widget_closed_ = false; | |
| 38 } | |
| 39 if (!widget_closed_) { | |
|
Daniel Erat
2011/10/21 18:24:34
how can widget_closed_ ever be true here?
alicet1
2011/10/24 15:46:38
removed.
| |
| 40 SettingLevelBubble::ShowBubble(widget_, percent, enabled); | |
| 41 } | |
| 42 } | |
| 43 | |
| 44 void BrightnessBubble::UpdateWithoutShowingBubble(double percent, | |
| 45 bool enabled) { | |
| 46 if (widget_) | |
| 47 static_cast<SettingLevelBubble*>(widget_->widget_delegate()) | |
| 48 ->UpdateWithoutShowingBubble(percent, enabled); | |
| 49 } | |
| 50 | |
| 51 void BrightnessBubble::HideBubble() { | |
| 52 if (widget_) { | |
| 53 widget_->RemoveObserver(this); | |
| 54 widget_->Close(); | |
| 55 widget_closed_ = true; | |
| 56 } | |
| 57 } | |
| 58 | |
| 59 BrightnessBubble::BrightnessBubble() | |
| 60 : widget_(NULL), | |
| 61 widget_closed_(false) {} | |
| 62 | |
| 63 BrightnessBubble::~BrightnessBubble() { | |
| 64 if (widget_) { | |
| 65 widget_->RemoveObserver(this); | |
| 66 delete widget_; | |
|
msw
2011/10/22 00:44:48
Should |widget_| be closed first? I actually don't
alicet1
2011/10/24 15:46:38
actually, just need to set widget_ to null.
| |
| 67 widget_ = NULL; | |
| 68 } | |
| 69 } | |
| 70 | |
| 28 } // namespace chromeos | 71 } // namespace chromeos |
| OLD | NEW |