| 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 "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
| 10 #include "chrome/browser/ui/browser_finder.h" | 10 #include "chrome/browser/ui/browser_finder.h" |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 | 245 |
| 246 // The text label and cancel button are hidden in this mode, but we want | 246 // The text label and cancel button are hidden in this mode, but we want |
| 247 // the popup to appear the same size as it would once recording starts, | 247 // the popup to appear the same size as it would once recording starts, |
| 248 // so as to reduce UI jank when recording starts. So we calculate the | 248 // so as to reduce UI jank when recording starts. So we calculate the |
| 249 // difference in size between the two sets of controls and add that as | 249 // difference in size between the two sets of controls and add that as |
| 250 // padding around the icon here. | 250 // padding around the icon here. |
| 251 GtkRequisition cancel_size; | 251 GtkRequisition cancel_size; |
| 252 gtk_widget_get_child_requisition(cancel_button_, &cancel_size); | 252 gtk_widget_get_child_requisition(cancel_button_, &cancel_size); |
| 253 GtkRequisition label_size; | 253 GtkRequisition label_size; |
| 254 gtk_widget_get_child_requisition(label_, &label_size); | 254 gtk_widget_get_child_requisition(label_, &label_size); |
| 255 SkBitmap* volume = ResourceBundle::GetSharedInstance().GetBitmapNamed( | 255 gfx::ImageSkia* volume = ResourceBundle::GetSharedInstance(). |
| 256 IDR_SPEECH_INPUT_MIC_EMPTY); | 256 GetImageSkiaNamed(IDR_SPEECH_INPUT_MIC_EMPTY); |
| 257 int desired_width = std::max(volume->width(), cancel_size.width) + | 257 int desired_width = std::max(volume->width(), cancel_size.width) + |
| 258 kIconHorizontalPadding * 2; | 258 kIconHorizontalPadding * 2; |
| 259 int desired_height = volume->height() + label_size.height + | 259 int desired_height = volume->height() + label_size.height + |
| 260 cancel_size.height + | 260 cancel_size.height + |
| 261 kBubbleControlVerticalSpacing * 2; | 261 kBubbleControlVerticalSpacing * 2; |
| 262 int diff_width = desired_width - icon_image().width(); | 262 int diff_width = desired_width - icon_image().width(); |
| 263 int diff_height = desired_height - icon_image().height(); | 263 int diff_height = desired_height - icon_image().height(); |
| 264 gtk_alignment_set_padding(GTK_ALIGNMENT(icon_container_), | 264 gtk_alignment_set_padding(GTK_ALIGNMENT(icon_container_), |
| 265 diff_height / 2, diff_height - diff_height / 2, | 265 diff_height / 2, diff_height - diff_height / 2, |
| 266 diff_width / 2, diff_width - diff_width / 2); | 266 diff_width / 2, diff_width - diff_width / 2); |
| 267 } else { | 267 } else { |
| 268 // Reset the padding done above. | 268 // Reset the padding done above. |
| 269 gtk_alignment_set_padding(GTK_ALIGNMENT(icon_container_), 0, 0, | 269 gtk_alignment_set_padding(GTK_ALIGNMENT(icon_container_), 0, 0, |
| 270 kIconHorizontalPadding, kIconHorizontalPadding); | 270 kIconHorizontalPadding, kIconHorizontalPadding); |
| 271 gtk_widget_show(cancel_button_); | 271 gtk_widget_show(cancel_button_); |
| 272 } | 272 } |
| 273 } | 273 } |
| 274 } | 274 } |
| 275 | 275 |
| 276 void SpeechRecognitionBubbleGtk::UpdateImage() { | 276 void SpeechRecognitionBubbleGtk::UpdateImage() { |
| 277 SkBitmap image = icon_image(); | 277 gfx::ImageSkia image = icon_image(); |
| 278 if (image.isNull() || !bubble_) | 278 if (image.isNull() || !bubble_) |
| 279 return; | 279 return; |
| 280 | 280 |
| 281 GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(image); | 281 GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(image); |
| 282 gtk_image_set_from_pixbuf(GTK_IMAGE(icon_), pixbuf); | 282 gtk_image_set_from_pixbuf(GTK_IMAGE(icon_), pixbuf); |
| 283 g_object_unref(pixbuf); | 283 g_object_unref(pixbuf); |
| 284 } | 284 } |
| 285 | 285 |
| 286 void SpeechRecognitionBubbleGtk::BubbleClosing(BubbleGtk* bubble, | 286 void SpeechRecognitionBubbleGtk::BubbleClosing(BubbleGtk* bubble, |
| 287 bool closed_by_escape) { | 287 bool closed_by_escape) { |
| 288 bubble_ = NULL; | 288 bubble_ = NULL; |
| 289 if (!did_invoke_close_) | 289 if (!did_invoke_close_) |
| 290 delegate_->InfoBubbleFocusChanged(); | 290 delegate_->InfoBubbleFocusChanged(); |
| 291 } | 291 } |
| 292 | 292 |
| 293 } // namespace | 293 } // namespace |
| 294 | 294 |
| 295 SpeechRecognitionBubble* SpeechRecognitionBubble::CreateNativeBubble( | 295 SpeechRecognitionBubble* SpeechRecognitionBubble::CreateNativeBubble( |
| 296 WebContents* web_contents, | 296 WebContents* web_contents, |
| 297 Delegate* delegate, | 297 Delegate* delegate, |
| 298 const gfx::Rect& element_rect) { | 298 const gfx::Rect& element_rect) { |
| 299 return new SpeechRecognitionBubbleGtk(web_contents, delegate, element_rect); | 299 return new SpeechRecognitionBubbleGtk(web_contents, delegate, element_rect); |
| 300 } | 300 } |
| OLD | NEW |