diff options
-rw-r--r-- | chrome/browser/speech/speech_input_bubble_gtk.cc | 39 |
1 files changed, 32 insertions, 7 deletions
diff --git a/chrome/browser/speech/speech_input_bubble_gtk.cc b/chrome/browser/speech/speech_input_bubble_gtk.cc index 06bdbb0..0fab31d 100644 --- a/chrome/browser/speech/speech_input_bubble_gtk.cc +++ b/chrome/browser/speech/speech_input_bubble_gtk.cc @@ -64,6 +64,7 @@ class SpeechInputBubbleGtk GtkWidget* cancel_button_; GtkWidget* try_again_button_; GtkWidget* icon_; + GtkWidget* icon_container_; GtkWidget* mic_settings_; DISALLOW_COPY_AND_ASSIGN(SpeechInputBubbleGtk); @@ -81,6 +82,7 @@ SpeechInputBubbleGtk::SpeechInputBubbleGtk(TabContents* tab_contents, cancel_button_(NULL), try_again_button_(NULL), icon_(NULL), + icon_container_(NULL), mic_settings_(NULL) { } @@ -122,12 +124,10 @@ void SpeechInputBubbleGtk::Show() { GtkWidget* vbox = gtk_vbox_new(FALSE, 0); // The icon with a some padding on the left and right. - GtkWidget* icon_container = gtk_alignment_new(0, 0, 0, 0); - gtk_alignment_set_padding(GTK_ALIGNMENT(icon_container), 0, 0, - kIconHorizontalPadding, kIconHorizontalPadding); + icon_container_ = gtk_alignment_new(0, 0, 0, 0); icon_ = gtk_image_new(); - gtk_container_add(GTK_CONTAINER(icon_container), icon_); - gtk_box_pack_start(GTK_BOX(vbox), icon_container, FALSE, FALSE, + gtk_container_add(GTK_CONTAINER(icon_container_), icon_); + gtk_box_pack_start(GTK_BOX(vbox), icon_container_, FALSE, FALSE, kBubbleControlVerticalSpacing); label_ = gtk_label_new(NULL); @@ -205,9 +205,9 @@ void SpeechInputBubbleGtk::UpdateLayout() { } else { // Heading text, icon and cancel button are visible, hide the Try Again // button. + gtk_label_set_text(GTK_LABEL(label_), + l10n_util::GetStringUTF8(IDS_SPEECH_INPUT_BUBBLE_HEADING).c_str()); if (display_mode() == DISPLAY_MODE_RECORDING) { - gtk_label_set_text(GTK_LABEL(label_), - l10n_util::GetStringUTF8(IDS_SPEECH_INPUT_BUBBLE_HEADING).c_str()); gtk_widget_show(label_); } else { gtk_widget_hide(label_); @@ -219,7 +219,32 @@ void SpeechInputBubbleGtk::UpdateLayout() { gtk_widget_hide(mic_settings_); if (display_mode() == DISPLAY_MODE_WARM_UP) { gtk_widget_hide(cancel_button_); + + // The text label and cancel button are hidden in this mode, but we want + // the popup to appear the same size as it would once recording starts, + // so as to reduce UI jank when recording starts. So we calculate the + // difference in size between the two sets of controls and add that as + // padding around the icon here. + GtkRequisition cancel_size; + gtk_widget_get_child_requisition(cancel_button_, &cancel_size); + GtkRequisition label_size; + gtk_widget_get_child_requisition(label_, &label_size); + SkBitmap* volume = ResourceBundle::GetSharedInstance().GetBitmapNamed( + IDR_SPEECH_INPUT_MIC_EMPTY); + int desired_width = std::max(volume->width(), cancel_size.width) + + kIconHorizontalPadding * 2; + int desired_height = volume->height() + label_size.height + + cancel_size.height + + kBubbleControlVerticalSpacing * 2; + int diff_width = desired_width - icon_image().width(); + int diff_height = desired_height - icon_image().height(); + gtk_alignment_set_padding(GTK_ALIGNMENT(icon_container_), + diff_height / 2, diff_height - diff_height / 2, + diff_width / 2, diff_width - diff_width / 2); } else { + // Reset the padding done above. + gtk_alignment_set_padding(GTK_ALIGNMENT(icon_container_), 0, 0, + kIconHorizontalPadding, kIconHorizontalPadding); gtk_widget_show(cancel_button_); } } |