| 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/ui/gtk/extensions/media_galleries_dialog_gtk.h" | 5 #include "chrome/browser/ui/gtk/extensions/media_galleries_dialog_gtk.h" |
| 6 | 6 |
| 7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/browser/media_galleries/media_galleries_preferences.h" | 9 #include "chrome/browser/media_galleries/media_galleries_preferences.h" |
| 10 #include "chrome/browser/ui/gtk/gtk_util.h" | 10 #include "chrome/browser/ui/gtk/gtk_util.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 : controller_(controller), | 23 : controller_(controller), |
| 24 window_(NULL), | 24 window_(NULL), |
| 25 confirm_(NULL), | 25 confirm_(NULL), |
| 26 checkbox_container_(NULL), | 26 checkbox_container_(NULL), |
| 27 ignore_toggles_(false), | 27 ignore_toggles_(false), |
| 28 accepted_(false) { | 28 accepted_(false) { |
| 29 InitWidgets(); | 29 InitWidgets(); |
| 30 | 30 |
| 31 // May be NULL during tests. | 31 // May be NULL during tests. |
| 32 if (controller->web_contents()) { | 32 if (controller->web_contents()) { |
| 33 window_ = CreateWebContentsModalDialogGtk(controller->web_contents(), this); | 33 window_ = CreateWebContentsModalDialogGtk(controller->web_contents(), |
| 34 contents_.get(), |
| 35 confirm_); |
| 34 | 36 |
| 35 WebContentsModalDialogManager* web_contents_modal_dialog_manager = | 37 WebContentsModalDialogManager* web_contents_modal_dialog_manager = |
| 36 WebContentsModalDialogManager::FromWebContents( | 38 WebContentsModalDialogManager::FromWebContents( |
| 37 controller->web_contents()); | 39 controller->web_contents()); |
| 38 web_contents_modal_dialog_manager->ShowDialog(window_); | 40 web_contents_modal_dialog_manager->ShowDialog(window_); |
| 39 } | 41 } |
| 40 } | 42 } |
| 41 | 43 |
| 42 MediaGalleriesDialogGtk::~MediaGalleriesDialogGtk() { | 44 MediaGalleriesDialogGtk::~MediaGalleriesDialogGtk() { |
| 43 } | 45 } |
| 44 | 46 |
| 45 void MediaGalleriesDialogGtk::InitWidgets() { | 47 void MediaGalleriesDialogGtk::InitWidgets() { |
| 46 contents_.Own(gtk_vbox_new(FALSE, ui::kContentAreaSpacing)); | 48 contents_.Own(gtk_vbox_new(FALSE, ui::kContentAreaSpacing)); |
| 49 g_signal_connect(contents_.get(), |
| 50 "destroy", |
| 51 G_CALLBACK(OnDestroyThunk), |
| 52 this); |
| 47 | 53 |
| 48 GtkWidget* header = | 54 GtkWidget* header = |
| 49 gtk_util::CreateBoldLabel(UTF16ToUTF8(controller_->GetHeader())); | 55 gtk_util::CreateBoldLabel(UTF16ToUTF8(controller_->GetHeader())); |
| 50 gtk_box_pack_start(GTK_BOX(contents_.get()), header, FALSE, FALSE, 0); | 56 gtk_box_pack_start(GTK_BOX(contents_.get()), header, FALSE, FALSE, 0); |
| 51 | 57 |
| 52 GtkWidget* subtext = | 58 GtkWidget* subtext = |
| 53 gtk_label_new(UTF16ToUTF8(controller_->GetSubtext()).c_str()); | 59 gtk_label_new(UTF16ToUTF8(controller_->GetSubtext()).c_str()); |
| 54 gtk_label_set_line_wrap(GTK_LABEL(subtext), TRUE); | 60 gtk_label_set_line_wrap(GTK_LABEL(subtext), TRUE); |
| 55 gtk_widget_set_size_request(subtext, 500, -1); | 61 gtk_widget_set_size_request(subtext, 500, -1); |
| 56 gtk_box_pack_start(GTK_BOX(contents_.get()), subtext, FALSE, FALSE, 0); | 62 gtk_box_pack_start(GTK_BOX(contents_.get()), subtext, FALSE, FALSE, 0); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 const MediaGalleryPrefInfo* gallery) { | 134 const MediaGalleryPrefInfo* gallery) { |
| 129 CheckboxMap::iterator iter = checkbox_map_.find(gallery); | 135 CheckboxMap::iterator iter = checkbox_map_.find(gallery); |
| 130 if (iter == checkbox_map_.end()) | 136 if (iter == checkbox_map_.end()) |
| 131 return; | 137 return; |
| 132 | 138 |
| 133 base::AutoReset<bool> reset(&ignore_toggles_, true); | 139 base::AutoReset<bool> reset(&ignore_toggles_, true); |
| 134 gtk_widget_destroy(iter->second); | 140 gtk_widget_destroy(iter->second); |
| 135 checkbox_map_.erase(iter); | 141 checkbox_map_.erase(iter); |
| 136 } | 142 } |
| 137 | 143 |
| 138 GtkWidget* MediaGalleriesDialogGtk::GetWidgetRoot() { | |
| 139 return contents_.get(); | |
| 140 } | |
| 141 | |
| 142 GtkWidget* MediaGalleriesDialogGtk::GetFocusWidget() { | |
| 143 return confirm_; | |
| 144 } | |
| 145 | |
| 146 void MediaGalleriesDialogGtk::DeleteDelegate() { | |
| 147 controller_->DialogFinished(accepted_); | |
| 148 } | |
| 149 | |
| 150 void MediaGalleriesDialogGtk::OnToggled(GtkWidget* widget) { | 144 void MediaGalleriesDialogGtk::OnToggled(GtkWidget* widget) { |
| 151 if (confirm_) | 145 if (confirm_) |
| 152 gtk_widget_set_sensitive(confirm_, TRUE); | 146 gtk_widget_set_sensitive(confirm_, TRUE); |
| 153 | 147 |
| 154 if (ignore_toggles_) | 148 if (ignore_toggles_) |
| 155 return; | 149 return; |
| 156 | 150 |
| 157 for (CheckboxMap::const_iterator iter = checkbox_map_.begin(); | 151 for (CheckboxMap::const_iterator iter = checkbox_map_.begin(); |
| 158 iter != checkbox_map_.end(); ++iter) { | 152 iter != checkbox_map_.end(); ++iter) { |
| 159 if (iter->second == widget) { | 153 if (iter->second == widget) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 173 | 167 |
| 174 void MediaGalleriesDialogGtk::OnConfirm(GtkWidget* widget) { | 168 void MediaGalleriesDialogGtk::OnConfirm(GtkWidget* widget) { |
| 175 accepted_ = true; | 169 accepted_ = true; |
| 176 gtk_widget_destroy(window_); | 170 gtk_widget_destroy(window_); |
| 177 } | 171 } |
| 178 | 172 |
| 179 void MediaGalleriesDialogGtk::OnCancel(GtkWidget* widget) { | 173 void MediaGalleriesDialogGtk::OnCancel(GtkWidget* widget) { |
| 180 gtk_widget_destroy(window_); | 174 gtk_widget_destroy(window_); |
| 181 } | 175 } |
| 182 | 176 |
| 177 void MediaGalleriesDialogGtk::OnDestroy(GtkWidget* widget) { |
| 178 controller_->DialogFinished(accepted_); |
| 179 } |
| 180 |
| 183 // MediaGalleriesDialogController ---------------------------------------------- | 181 // MediaGalleriesDialogController ---------------------------------------------- |
| 184 | 182 |
| 185 // static | 183 // static |
| 186 MediaGalleriesDialog* MediaGalleriesDialog::Create( | 184 MediaGalleriesDialog* MediaGalleriesDialog::Create( |
| 187 MediaGalleriesDialogController* controller) { | 185 MediaGalleriesDialogController* controller) { |
| 188 return new MediaGalleriesDialogGtk(controller); | 186 return new MediaGalleriesDialogGtk(controller); |
| 189 } | 187 } |
| 190 | 188 |
| 191 } // namespace chrome | 189 } // namespace chrome |
| OLD | NEW |