Chromium Code Reviews| 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/chrome_to_mobile_bubble_gtk.h" | 5 #include "chrome/browser/ui/gtk/chrome_to_mobile_bubble_gtk.h" |
| 6 | 6 |
| 7 #include <gtk/gtk.h> | 7 #include <gtk/gtk.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 46 | 46 |
| 47 // The seconds to delay before automatically closing the bubble after sending. | 47 // The seconds to delay before automatically closing the bubble after sending. |
| 48 const int kAutoCloseDelay = 3; | 48 const int kAutoCloseDelay = 3; |
| 49 | 49 |
| 50 // The color of the error label. | 50 // The color of the error label. |
| 51 const GdkColor kErrorColor = GDK_COLOR_RGB(0xFF, 0x00, 0x00); | 51 const GdkColor kErrorColor = GDK_COLOR_RGB(0xFF, 0x00, 0x00); |
| 52 | 52 |
| 53 } // namespace | 53 } // namespace |
| 54 | 54 |
| 55 // static | 55 // static |
| 56 void ChromeToMobileBubbleGtk::Show(GtkImage* anchor_image, Browser* browser) { | 56 void ChromeToMobileBubbleGtk::Show(GtkWidget* anchor_widget, Browser* browser) { |
| 57 // Do not construct a new bubble if one is already being shown. | 57 // Do not construct a new bubble if one is already being shown. |
| 58 if (!g_bubble) | 58 if (!g_bubble) |
| 59 g_bubble = new ChromeToMobileBubbleGtk(anchor_image, browser); | 59 g_bubble = new ChromeToMobileBubbleGtk(anchor_widget, browser); |
| 60 } | 60 } |
| 61 | 61 |
| 62 void ChromeToMobileBubbleGtk::BubbleClosing(BubbleGtk* bubble, | 62 void ChromeToMobileBubbleGtk::BubbleClosing(BubbleGtk* bubble, |
| 63 bool closed_by_escape) { | 63 bool closed_by_escape) { |
| 64 DCHECK_EQ(bubble, bubble_); | 64 DCHECK_EQ(bubble, bubble_); |
| 65 | 65 |
| 66 // Instruct the service to delete the snapshot file. | 66 // Instruct the service to delete the snapshot file. |
| 67 service_->DeleteSnapshot(snapshot_path_); | 67 service_->DeleteSnapshot(snapshot_path_); |
| 68 | 68 |
| 69 // Restore the resting state mobile device icon. | 69 // TODO(msw): Restore the resting state action box icon. |
| 70 gtk_image_set_from_pixbuf(GTK_IMAGE(anchor_image_), | |
| 71 theme_service_->GetImageNamed(IDR_MOBILE)->ToGdkPixbuf()); | |
| 72 | 70 |
| 73 labels_.clear(); | 71 labels_.clear(); |
| 74 anchor_image_ = NULL; | 72 anchor_widget_ = NULL; |
| 75 send_copy_ = NULL; | 73 send_copy_ = NULL; |
| 76 cancel_ = NULL; | 74 cancel_ = NULL; |
| 77 send_ = NULL; | 75 send_ = NULL; |
| 78 error_ = NULL; | 76 error_ = NULL; |
| 79 bubble_ = NULL; | 77 bubble_ = NULL; |
| 80 progress_animation_.reset(); | 78 progress_animation_.reset(); |
| 81 } | 79 } |
| 82 | 80 |
| 83 void ChromeToMobileBubbleGtk::AnimationProgressed( | 81 void ChromeToMobileBubbleGtk::AnimationProgressed( |
| 84 const ui::Animation* animation) { | 82 const ui::Animation* animation) { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 135 base::Bind(&ChromeToMobileBubbleGtk::OnCancelClicked, | 133 base::Bind(&ChromeToMobileBubbleGtk::OnCancelClicked, |
| 136 weak_ptr_factory_.GetWeakPtr(), GTK_WIDGET(NULL)), | 134 weak_ptr_factory_.GetWeakPtr(), GTK_WIDGET(NULL)), |
| 137 base::TimeDelta::FromSeconds(kAutoCloseDelay)); | 135 base::TimeDelta::FromSeconds(kAutoCloseDelay)); |
| 138 } else { | 136 } else { |
| 139 gtk_button_set_label(GTK_BUTTON(send_), | 137 gtk_button_set_label(GTK_BUTTON(send_), |
| 140 l10n_util::GetStringUTF8(IDS_CHROME_TO_MOBILE_BUBBLE_ERROR).c_str()); | 138 l10n_util::GetStringUTF8(IDS_CHROME_TO_MOBILE_BUBBLE_ERROR).c_str()); |
| 141 gtk_widget_set_visible(error_, TRUE); | 139 gtk_widget_set_visible(error_, TRUE); |
| 142 } | 140 } |
| 143 } | 141 } |
| 144 | 142 |
| 145 ChromeToMobileBubbleGtk::ChromeToMobileBubbleGtk(GtkImage* anchor_image, | 143 ChromeToMobileBubbleGtk::ChromeToMobileBubbleGtk(GtkWidget* anchor_widget, |
| 146 Browser* browser) | 144 Browser* browser) |
| 147 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)), | 145 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)), |
| 148 browser_(browser), | 146 browser_(browser), |
| 149 service_(ChromeToMobileServiceFactory::GetForProfile(browser->profile())), | 147 service_(ChromeToMobileServiceFactory::GetForProfile(browser->profile())), |
| 150 theme_service_(GtkThemeService::GetFrom(browser->profile())), | 148 theme_service_(GtkThemeService::GetFrom(browser->profile())), |
| 151 anchor_image_(anchor_image), | 149 anchor_widget_(anchor_widget), |
| 152 send_copy_(NULL), | 150 send_copy_(NULL), |
| 153 cancel_(NULL), | 151 cancel_(NULL), |
| 154 send_(NULL), | 152 send_(NULL), |
| 155 error_(NULL), | 153 error_(NULL), |
| 156 bubble_(NULL) { | 154 bubble_(NULL) { |
| 157 DCHECK(service_->HasMobiles()); | 155 DCHECK(service_->HasMobiles()); |
| 158 service_->LogMetric(ChromeToMobileService::BUBBLE_SHOWN); | 156 service_->LogMetric(ChromeToMobileService::BUBBLE_SHOWN); |
| 159 | 157 |
| 160 // Generate the MHTML snapshot now to report its size in the bubble. | 158 // Generate the MHTML snapshot now to report its size in the bubble. |
| 161 service_->GenerateSnapshot(browser_, weak_ptr_factory_.GetWeakPtr()); | 159 service_->GenerateSnapshot(browser_, weak_ptr_factory_.GetWeakPtr()); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 247 gtk_misc_set_alignment(GTK_MISC(error_), 0, 1); | 245 gtk_misc_set_alignment(GTK_MISC(error_), 0, 1); |
| 248 gtk_util::SetLabelColor(error_, &kErrorColor); | 246 gtk_util::SetLabelColor(error_, &kErrorColor); |
| 249 gtk_box_pack_start(GTK_BOX(content), error_, FALSE, FALSE, 0); | 247 gtk_box_pack_start(GTK_BOX(content), error_, FALSE, FALSE, 0); |
| 250 gtk_widget_set_no_show_all(error_, TRUE); | 248 gtk_widget_set_no_show_all(error_, TRUE); |
| 251 | 249 |
| 252 // Initialize focus to the send button. | 250 // Initialize focus to the send button. |
| 253 gtk_container_set_focus_child(GTK_CONTAINER(content), send_); | 251 gtk_container_set_focus_child(GTK_CONTAINER(content), send_); |
| 254 | 252 |
| 255 BubbleGtk::ArrowLocationGtk arrow_location = base::i18n::IsRTL() ? | 253 BubbleGtk::ArrowLocationGtk arrow_location = base::i18n::IsRTL() ? |
| 256 BubbleGtk::ARROW_LOCATION_TOP_LEFT : BubbleGtk::ARROW_LOCATION_TOP_RIGHT; | 254 BubbleGtk::ARROW_LOCATION_TOP_LEFT : BubbleGtk::ARROW_LOCATION_TOP_RIGHT; |
| 257 bubble_ = BubbleGtk::Show(GTK_WIDGET(anchor_image_), | 255 const int attribute_flags = BubbleGtk::MATCH_SYSTEM_THEME | |
| 258 NULL, | 256 BubbleGtk::POPUP_WINDOW | BubbleGtk::GRAB_INPUT; |
| 259 content, | 257 bubble_ = BubbleGtk::Show(anchor_widget_, NULL, content, arrow_location, |
| 260 arrow_location, | 258 attribute_flags, theme_service_, this /*delegate*/); |
| 261 BubbleGtk::MATCH_SYSTEM_THEME | | |
| 262 BubbleGtk::POPUP_WINDOW | | |
| 263 BubbleGtk::GRAB_INPUT, | |
| 264 theme_service_, | |
| 265 this /*delegate*/); | |
| 266 if (!bubble_) { | 259 if (!bubble_) { |
| 267 NOTREACHED(); | 260 NOTREACHED(); |
| 268 return; | 261 return; |
| 269 } | 262 } |
| 270 | 263 |
| 271 g_signal_connect(content, "destroy", G_CALLBACK(&OnDestroyThunk), this); | 264 g_signal_connect(content, "destroy", G_CALLBACK(&OnDestroyThunk), this); |
| 272 g_signal_connect(learn_, "clicked", G_CALLBACK(&OnLearnClickedThunk), this); | 265 g_signal_connect(learn_, "clicked", G_CALLBACK(&OnLearnClickedThunk), this); |
| 273 g_signal_connect(cancel_, "clicked", G_CALLBACK(&OnCancelClickedThunk), this); | 266 g_signal_connect(cancel_, "clicked", G_CALLBACK(&OnCancelClickedThunk), this); |
| 274 g_signal_connect(send_, "clicked", G_CALLBACK(&OnSendClickedThunk), this); | 267 g_signal_connect(send_, "clicked", G_CALLBACK(&OnSendClickedThunk), this); |
| 275 | 268 |
| 276 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, | 269 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, |
| 277 content::Source<ThemeService>(theme_service_)); | 270 content::Source<ThemeService>(theme_service_)); |
| 278 theme_service_->InitThemesFor(this); | 271 theme_service_->InitThemesFor(this); |
| 279 | 272 |
| 280 gtk_image_set_from_pixbuf(GTK_IMAGE(anchor_image_), | 273 // TODO(msw): Show the lit mobile device icon during the bubble's lifetime. |
|
Evan Stade
2012/09/10 17:10:56
don't need two copies of this todo
msw
2012/09/10 18:03:48
Done.
| |
| 281 theme_service_->GetImageNamed(IDR_MOBILE_LIT)->ToGdkPixbuf()); | |
| 282 } | 274 } |
| 283 | 275 |
| 284 ChromeToMobileBubbleGtk::~ChromeToMobileBubbleGtk() { | 276 ChromeToMobileBubbleGtk::~ChromeToMobileBubbleGtk() { |
| 285 DCHECK(g_bubble); | 277 DCHECK(g_bubble); |
| 286 g_bubble = NULL; | 278 g_bubble = NULL; |
| 287 } | 279 } |
| 288 | 280 |
| 289 void ChromeToMobileBubbleGtk::OnDestroy(GtkWidget* widget) { | 281 void ChromeToMobileBubbleGtk::OnDestroy(GtkWidget* widget) { |
| 290 // We are self deleting, we have a destroy signal setup to catch when we | 282 // We are self deleting, we have a destroy signal setup to catch when we |
| 291 // destroyed (via the BubbleGtk being destroyed), and delete ourself. | 283 // destroyed (via the BubbleGtk being destroyed), and delete ourself. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 327 } | 319 } |
| 328 | 320 |
| 329 // Update the view's contents to show the "Sending..." progress animation. | 321 // Update the view's contents to show the "Sending..." progress animation. |
| 330 gtk_widget_set_sensitive(cancel_, FALSE); | 322 gtk_widget_set_sensitive(cancel_, FALSE); |
| 331 gtk_widget_set_sensitive(send_, FALSE); | 323 gtk_widget_set_sensitive(send_, FALSE); |
| 332 gtk_button_set_alignment(GTK_BUTTON(send_), 0, 0.5); | 324 gtk_button_set_alignment(GTK_BUTTON(send_), 0, 0.5); |
| 333 progress_animation_.reset(new ui::ThrobAnimation(this)); | 325 progress_animation_.reset(new ui::ThrobAnimation(this)); |
| 334 progress_animation_->SetDuration(kProgressThrobDurationMS); | 326 progress_animation_->SetDuration(kProgressThrobDurationMS); |
| 335 progress_animation_->StartThrobbing(-1); | 327 progress_animation_->StartThrobbing(-1); |
| 336 } | 328 } |
| OLD | NEW |