Chromium Code Reviews| Index: chrome/browser/ui/views/speech_recognition_bubble_views.cc |
| diff --git a/chrome/browser/ui/views/speech_recognition_bubble_views.cc b/chrome/browser/ui/views/speech_recognition_bubble_views.cc |
| index d22da84f82a2928294e5428cfcf33a346bd665bf..84d167c841b56ccea8ce1c10c08a6373805aef4a 100644 |
| --- a/chrome/browser/ui/views/speech_recognition_bubble_views.cc |
| +++ b/chrome/browser/ui/views/speech_recognition_bubble_views.cc |
| @@ -31,6 +31,11 @@ using content::WebContents; |
| namespace { |
| +class SpeechRecognitionBubbleViewLifeTimeObserver { |
| + public: |
| + virtual void BubbleViewGoingAway() = 0; |
| +}; |
| + |
| const int kBubbleHorizMargin = 6; |
| const int kBubbleVertMargin = 4; |
| const int kBubbleHeadingVertMargin = 6; |
| @@ -45,6 +50,11 @@ class SpeechRecognitionBubbleView : public views::BubbleDelegateView, |
| const gfx::Rect& element_rect, |
| WebContents* web_contents); |
| + void SetLifeTImeObserver( |
|
tommi (sloooow) - chröme
2014/03/26 17:01:43
SetLifeTimeObserver
(lowercase i)
Tommy Widenflycht
2014/03/27 12:50:44
Done.
|
| + SpeechRecognitionBubbleViewLifeTimeObserver* life_time_observer) { |
| + life_time_observer_ = life_time_observer; |
|
tommi (sloooow) - chröme
2014/03/26 17:01:43
fix indent
Tommy Widenflycht
2014/03/27 12:50:44
Done.
|
| + } |
| + |
| void UpdateLayout(SpeechRecognitionBubbleBase::DisplayMode mode, |
| const base::string16& message_text, |
| const gfx::ImageSkia& image); |
| @@ -53,6 +63,7 @@ class SpeechRecognitionBubbleView : public views::BubbleDelegateView, |
| // views::BubbleDelegateView methods. |
| virtual void OnWidgetActivationChanged(views::Widget* widget, |
| bool active) OVERRIDE; |
| + virtual void OnWidgetDestroyed(views::Widget* widget) OVERRIDE; |
| virtual gfx::Rect GetAnchorRect() OVERRIDE; |
| virtual void Init() OVERRIDE; |
| @@ -85,6 +96,7 @@ class SpeechRecognitionBubbleView : public views::BubbleDelegateView, |
| views::Link* mic_settings_; |
| SpeechRecognitionBubbleBase::DisplayMode display_mode_; |
| const int kIconLayoutMinWidth; |
| + SpeechRecognitionBubbleViewLifeTimeObserver* life_time_observer_; |
| DISALLOW_COPY_AND_ASSIGN(SpeechRecognitionBubbleView); |
| }; |
| @@ -119,6 +131,12 @@ SpeechRecognitionBubbleView::SpeechRecognitionBubbleView( |
| set_move_with_anchor(true); |
| } |
| +void SpeechRecognitionBubbleView::OnWidgetDestroyed(views::Widget* widget) { |
| + BubbleDelegateView::OnWidgetDestroyed(widget); |
|
tommi (sloooow) - chröme
2014/03/26 17:01:43
fix indent
Tommy Widenflycht
2014/03/27 12:50:44
Done.
|
| + if (life_time_observer_) |
| + life_time_observer_->BubbleViewGoingAway(); |
| +} |
| + |
| void SpeechRecognitionBubbleView::OnWidgetActivationChanged( |
| views::Widget* widget, bool active) { |
| if (widget == GetWidget() && !active && notify_delegate_on_activation_change_) |
| @@ -327,7 +345,9 @@ void SpeechRecognitionBubbleView::Layout() { |
| } |
| // Implementation of SpeechRecognitionBubble. |
| -class SpeechRecognitionBubbleImpl : public SpeechRecognitionBubbleBase { |
| +class SpeechRecognitionBubbleImpl |
| + : public SpeechRecognitionBubbleBase, |
| + public SpeechRecognitionBubbleViewLifeTimeObserver { |
| public: |
| SpeechRecognitionBubbleImpl(int render_process_id, int render_view_id, |
| Delegate* delegate, |
| @@ -342,6 +362,9 @@ class SpeechRecognitionBubbleImpl : public SpeechRecognitionBubbleBase { |
| virtual void UpdateLayout() OVERRIDE; |
| virtual void UpdateImage() OVERRIDE; |
| + // SpeechRecognitionBubbleViewLifeTimeObserver methods. |
| + virtual void BubbleViewGoingAway() OVERRIDE; |
| + |
| private: |
| Delegate* delegate_; |
| SpeechRecognitionBubbleView* bubble_; |
| @@ -361,11 +384,16 @@ SpeechRecognitionBubbleImpl::SpeechRecognitionBubbleImpl( |
| SpeechRecognitionBubbleImpl::~SpeechRecognitionBubbleImpl() { |
| if (bubble_) { |
| + bubble_->SetLifeTImeObserver(NULL); |
| bubble_->set_notify_delegate_on_activation_change(false); |
| bubble_->GetWidget()->Close(); |
| } |
| } |
| +void SpeechRecognitionBubbleImpl::BubbleViewGoingAway() { |
| + bubble_ = NULL; |
| +} |
| + |
| void SpeechRecognitionBubbleImpl::Show() { |
| WebContents* web_contents = GetWebContents(); |
| if (!web_contents) |
| @@ -385,6 +413,7 @@ void SpeechRecognitionBubbleImpl::Show() { |
| bubble_ = new SpeechRecognitionBubbleView(delegate_, icon, element_rect_, |
| web_contents); |
| + bubble_->SetLifeTImeObserver(this); |
| if (!icon) { |
| // We dont't have an icon to attach to. Manually specify the web contents |