| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/speech/speech_recognition_bubble.h" | 5 #include "chrome/browser/speech/speech_recognition_bubble.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 public views::ButtonListener, | 44 public views::ButtonListener, |
| 45 public views::LinkListener { | 45 public views::LinkListener { |
| 46 public: | 46 public: |
| 47 SpeechRecognitionBubbleView(SpeechRecognitionBubbleDelegate* delegate, | 47 SpeechRecognitionBubbleView(SpeechRecognitionBubbleDelegate* delegate, |
| 48 views::View* anchor_view, | 48 views::View* anchor_view, |
| 49 const gfx::Rect& element_rect, | 49 const gfx::Rect& element_rect, |
| 50 WebContents* web_contents); | 50 WebContents* web_contents); |
| 51 | 51 |
| 52 void UpdateLayout(SpeechRecognitionBubbleBase::DisplayMode mode, | 52 void UpdateLayout(SpeechRecognitionBubbleBase::DisplayMode mode, |
| 53 const string16& message_text, | 53 const string16& message_text, |
| 54 const SkBitmap& image); | 54 const gfx::ImageSkia& image); |
| 55 void SetImage(const SkBitmap& image); | 55 void SetImage(const gfx::ImageSkia& image); |
| 56 | 56 |
| 57 // views::BubbleDelegateView methods. | 57 // views::BubbleDelegateView methods. |
| 58 virtual void OnWidgetActivationChanged(views::Widget* widget, | 58 virtual void OnWidgetActivationChanged(views::Widget* widget, |
| 59 bool active) OVERRIDE; | 59 bool active) OVERRIDE; |
| 60 virtual gfx::Rect GetAnchorRect() OVERRIDE; | 60 virtual gfx::Rect GetAnchorRect() OVERRIDE; |
| 61 virtual void Init() OVERRIDE; | 61 virtual void Init() OVERRIDE; |
| 62 | 62 |
| 63 // views::ButtonListener methods. | 63 // views::ButtonListener methods. |
| 64 virtual void ButtonPressed(views::Button* source, | 64 virtual void ButtonPressed(views::Button* source, |
| 65 const views::Event& event) OVERRIDE; | 65 const views::Event& event) OVERRIDE; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 element_rect_(element_rect), | 102 element_rect_(element_rect), |
| 103 web_contents_(web_contents), | 103 web_contents_(web_contents), |
| 104 notify_delegate_on_activation_change_(true), | 104 notify_delegate_on_activation_change_(true), |
| 105 icon_(NULL), | 105 icon_(NULL), |
| 106 heading_(NULL), | 106 heading_(NULL), |
| 107 message_(NULL), | 107 message_(NULL), |
| 108 try_again_(NULL), | 108 try_again_(NULL), |
| 109 cancel_(NULL), | 109 cancel_(NULL), |
| 110 mic_settings_(NULL), | 110 mic_settings_(NULL), |
| 111 display_mode_(SpeechRecognitionBubbleBase::DISPLAY_MODE_WARM_UP), | 111 display_mode_(SpeechRecognitionBubbleBase::DISPLAY_MODE_WARM_UP), |
| 112 kIconLayoutMinWidth(ResourceBundle::GetSharedInstance().GetBitmapNamed( | 112 kIconLayoutMinWidth(ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| 113 IDR_SPEECH_INPUT_MIC_EMPTY)->width()) { | 113 IDR_SPEECH_INPUT_MIC_EMPTY)->width()) { |
| 114 // The bubble lifetime is managed by its controller; closing on escape or | 114 // The bubble lifetime is managed by its controller; closing on escape or |
| 115 // explicitly closing on deactivation will cause unexpected behavior. | 115 // explicitly closing on deactivation will cause unexpected behavior. |
| 116 set_close_on_esc(false); | 116 set_close_on_esc(false); |
| 117 set_close_on_deactivate(false); | 117 set_close_on_deactivate(false); |
| 118 } | 118 } |
| 119 | 119 |
| 120 void SpeechRecognitionBubbleView::OnWidgetActivationChanged( | 120 void SpeechRecognitionBubbleView::OnWidgetActivationChanged( |
| 121 views::Widget* widget, bool active) { | 121 views::Widget* widget, bool active) { |
| 122 if (widget == GetWidget() && !active && notify_delegate_on_activation_change_) | 122 if (widget == GetWidget() && !active && notify_delegate_on_activation_change_) |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 | 168 |
| 169 mic_settings_ = new views::Link( | 169 mic_settings_ = new views::Link( |
| 170 l10n_util::GetStringUTF16(IDS_SPEECH_INPUT_MIC_SETTINGS)); | 170 l10n_util::GetStringUTF16(IDS_SPEECH_INPUT_MIC_SETTINGS)); |
| 171 mic_settings_->set_listener(this); | 171 mic_settings_->set_listener(this); |
| 172 AddChildView(mic_settings_); | 172 AddChildView(mic_settings_); |
| 173 } | 173 } |
| 174 | 174 |
| 175 void SpeechRecognitionBubbleView::UpdateLayout( | 175 void SpeechRecognitionBubbleView::UpdateLayout( |
| 176 SpeechRecognitionBubbleBase::DisplayMode mode, | 176 SpeechRecognitionBubbleBase::DisplayMode mode, |
| 177 const string16& message_text, | 177 const string16& message_text, |
| 178 const SkBitmap& image) { | 178 const gfx::ImageSkia& image) { |
| 179 display_mode_ = mode; | 179 display_mode_ = mode; |
| 180 bool is_message = (mode == SpeechRecognitionBubbleBase::DISPLAY_MODE_MESSAGE); | 180 bool is_message = (mode == SpeechRecognitionBubbleBase::DISPLAY_MODE_MESSAGE); |
| 181 icon_->SetVisible(!is_message); | 181 icon_->SetVisible(!is_message); |
| 182 message_->SetVisible(is_message); | 182 message_->SetVisible(is_message); |
| 183 mic_settings_->SetVisible(is_message); | 183 mic_settings_->SetVisible(is_message); |
| 184 try_again_->SetVisible(is_message); | 184 try_again_->SetVisible(is_message); |
| 185 cancel_->SetVisible( | 185 cancel_->SetVisible( |
| 186 mode != SpeechRecognitionBubbleBase::DISPLAY_MODE_WARM_UP); | 186 mode != SpeechRecognitionBubbleBase::DISPLAY_MODE_WARM_UP); |
| 187 heading_->SetVisible( | 187 heading_->SetVisible( |
| 188 mode == SpeechRecognitionBubbleBase::DISPLAY_MODE_RECORDING); | 188 mode == SpeechRecognitionBubbleBase::DISPLAY_MODE_RECORDING); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 203 | 203 |
| 204 // When moving from warming up to recording state, the size of the content | 204 // When moving from warming up to recording state, the size of the content |
| 205 // stays the same. So we wouldn't get a resize/layout call from the view | 205 // stays the same. So we wouldn't get a resize/layout call from the view |
| 206 // system and we do it ourselves. | 206 // system and we do it ourselves. |
| 207 if (GetPreferredSize() == size()) // |size()| here is the current size. | 207 if (GetPreferredSize() == size()) // |size()| here is the current size. |
| 208 Layout(); | 208 Layout(); |
| 209 | 209 |
| 210 SizeToContents(); | 210 SizeToContents(); |
| 211 } | 211 } |
| 212 | 212 |
| 213 void SpeechRecognitionBubbleView::SetImage(const SkBitmap& image) { | 213 void SpeechRecognitionBubbleView::SetImage(const gfx::ImageSkia& image) { |
| 214 icon_->SetImage(image); | 214 icon_->SetImage(image); |
| 215 } | 215 } |
| 216 | 216 |
| 217 void SpeechRecognitionBubbleView::ButtonPressed(views::Button* source, | 217 void SpeechRecognitionBubbleView::ButtonPressed(views::Button* source, |
| 218 const views::Event& event) { | 218 const views::Event& event) { |
| 219 if (source == cancel_) { | 219 if (source == cancel_) { |
| 220 delegate_->InfoBubbleButtonClicked(SpeechRecognitionBubble::BUTTON_CANCEL); | 220 delegate_->InfoBubbleButtonClicked(SpeechRecognitionBubble::BUTTON_CANCEL); |
| 221 } else if (source == try_again_) { | 221 } else if (source == try_again_) { |
| 222 delegate_->InfoBubbleButtonClicked( | 222 delegate_->InfoBubbleButtonClicked( |
| 223 SpeechRecognitionBubble::BUTTON_TRY_AGAIN); | 223 SpeechRecognitionBubble::BUTTON_TRY_AGAIN); |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 } | 388 } |
| 389 | 389 |
| 390 } // namespace | 390 } // namespace |
| 391 | 391 |
| 392 SpeechRecognitionBubble* SpeechRecognitionBubble::CreateNativeBubble( | 392 SpeechRecognitionBubble* SpeechRecognitionBubble::CreateNativeBubble( |
| 393 WebContents* web_contents, | 393 WebContents* web_contents, |
| 394 SpeechRecognitionBubble::Delegate* delegate, | 394 SpeechRecognitionBubble::Delegate* delegate, |
| 395 const gfx::Rect& element_rect) { | 395 const gfx::Rect& element_rect) { |
| 396 return new SpeechRecognitionBubbleImpl(web_contents, delegate, element_rect); | 396 return new SpeechRecognitionBubbleImpl(web_contents, delegate, element_rect); |
| 397 } | 397 } |
| OLD | NEW |