Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/ui/gtk/infobars/media_stream_infobar_gtk.h" | |
| 6 | |
| 7 #include <string> | |
| 8 | |
| 9 #include "base/utf_string_conversions.h" | |
| 10 #include "chrome/browser/ui/gtk/gtk_util.h" | |
| 11 #include "chrome/browser/ui/gtk/infobars/media_stream_infobar_gtk.h" | |
| 12 #include "chrome/browser/ui/media_stream_infobar_delegate.h" | |
| 13 #include "grit/generated_resources.h" | |
| 14 #include "ui/base/gtk/gtk_hig_constants.h" | |
| 15 #include "ui/base/gtk/gtk_signal_registrar.h" | |
| 16 #include "ui/base/l10n/l10n_util.h" | |
| 17 | |
| 18 InfoBar* MediaStreamInfoBarDelegate::CreateInfoBar(InfoBarTabHelper* owner) { | |
| 19 DCHECK(owner); | |
| 20 return new MediaStreamInfoBarGtk(owner, this); | |
| 21 } | |
| 22 | |
| 23 MediaStreamInfoBarGtk::MediaStreamInfoBarGtk( | |
| 24 InfoBarTabHelper* owner, | |
| 25 MediaStreamInfoBarDelegate* delegate) | |
| 26 : InfoBarGtk(owner, delegate), | |
| 27 delegate_(delegate) { | |
| 28 devices_menu_model_ = new MediaStreamDevicesMenuModel(delegate_); | |
| 29 Init(); | |
| 30 } | |
| 31 | |
| 32 MediaStreamInfoBarGtk::~MediaStreamInfoBarGtk() { | |
| 33 } | |
| 34 | |
| 35 void MediaStreamInfoBarGtk::Init() { | |
| 36 GtkWidget* hbox = gtk_hbox_new(FALSE, ui::kControlSpacing); | |
| 37 gtk_util::CenterWidgetInHBox(hbox_, hbox, false, 0); | |
| 38 size_t offset = 0; | |
| 39 | |
| 40 int message_id = IDS_MEDIA_CAPTURE_MIC_AND_VIDEO; | |
| 41 if (!delegate_->has_audio()) { | |
|
Evan Stade
2012/03/01 17:53:46
no curlies.
| |
| 42 message_id = IDS_MEDIA_CAPTURE_VIDEO_ONLY; | |
| 43 } else if (!delegate_->has_video()) { | |
| 44 message_id = IDS_MEDIA_CAPTURE_MIC_ONLY; | |
| 45 } | |
| 46 string16 security_origin = UTF8ToUTF16(delegate_->GetSecurityOrigin()); | |
| 47 string16 text(l10n_util::GetStringFUTF16(message_id, | |
| 48 security_origin, &offset)); | |
| 49 | |
| 50 gtk_box_pack_start(GTK_BOX(hbox), CreateLabel(UTF16ToUTF8(text)), | |
| 51 FALSE, FALSE, 0); | |
| 52 | |
| 53 GtkWidget* button = gtk_button_new_with_label( | |
| 54 l10n_util::GetStringUTF8(IDS_MEDIA_CAPTURE_ALLOW).c_str()); | |
| 55 Signals()->Connect(button, "clicked", | |
| 56 G_CALLBACK(&OnAllowButtonThunk), this); | |
| 57 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
| 58 | |
| 59 button = gtk_button_new_with_label( | |
| 60 l10n_util::GetStringUTF8(IDS_MEDIA_CAPTURE_DENY).c_str()); | |
| 61 Signals()->Connect(button, "clicked", | |
| 62 G_CALLBACK(&OnDenyButtonThunk), this); | |
| 63 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
| 64 | |
| 65 // The devices button | |
|
Evan Stade
2012/03/01 17:53:46
. at end of comment.
| |
| 66 GtkWidget* devices_menu_button = BuildDevicesMenuButton(); | |
| 67 Signals()->Connect(devices_menu_button, "clicked", | |
| 68 G_CALLBACK(&OnDevicesClickedThunk), this); | |
|
Evan Stade
2012/03/01 17:53:46
indent.
| |
| 69 gtk_widget_show_all(devices_menu_button); | |
| 70 gtk_util::CenterWidgetInHBox(hbox_, devices_menu_button, true, 0); | |
| 71 } | |
| 72 | |
| 73 // static | |
| 74 GtkWidget* MediaStreamInfoBarGtk::BuildDevicesMenuButton() { | |
| 75 GtkWidget* button = gtk_button_new(); | |
| 76 GtkWidget* former_child = gtk_bin_get_child(GTK_BIN(button)); | |
| 77 if (former_child) | |
| 78 gtk_container_remove(GTK_CONTAINER(button), former_child); | |
| 79 | |
| 80 GtkWidget* hbox = gtk_hbox_new(FALSE, 0); | |
| 81 | |
| 82 GtkWidget* label = gtk_label_new( | |
| 83 l10n_util::GetStringUTF8(IDS_MEDIA_CAPTURE_DEVICES_MENU_TITLE).c_str()); | |
| 84 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
| 85 | |
| 86 GtkWidget* arrow = gtk_arrow_new(GTK_ARROW_DOWN, GTK_SHADOW_NONE); | |
|
Evan Stade
2012/03/01 17:53:46
I applaud the GTK integration here, but shouldn't
| |
| 87 gtk_box_pack_start(GTK_BOX(hbox), arrow, FALSE, FALSE, 0); | |
| 88 | |
| 89 gtk_container_add(GTK_CONTAINER(button), hbox); | |
| 90 | |
| 91 return button; | |
| 92 } | |
| 93 | |
| 94 void MediaStreamInfoBarGtk::OnDevicesClicked(GtkWidget* sender) { | |
| 95 ShowMenuWithModel(sender, NULL, devices_menu_model_); | |
| 96 } | |
| 97 | |
| 98 void MediaStreamInfoBarGtk::OnAllowButton(GtkWidget* widget) { | |
| 99 std::string audio_id, video_id; | |
| 100 devices_menu_model_->GetSelectedDeviceId( | |
| 101 content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, &audio_id); | |
| 102 devices_menu_model_->GetSelectedDeviceId( | |
| 103 content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE, &video_id); | |
| 104 delegate_->Accept(audio_id, video_id); | |
| 105 RemoveSelf(); | |
| 106 } | |
| 107 | |
| 108 void MediaStreamInfoBarGtk::OnDenyButton(GtkWidget* widget) { | |
| 109 delegate_->Deny(); | |
| 110 RemoveSelf(); | |
| 111 } | |
| OLD | NEW |