OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/gtk/download_item_gtk.h" | 5 #include "chrome/browser/gtk/download_item_gtk.h" |
6 | 6 |
7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
8 #include "app/gfx/canvas.h" | 8 #include "app/gfx/canvas.h" |
9 #include "app/gfx/font.h" | 9 #include "app/gfx/font.h" |
10 #include "app/gfx/text_elider.h" | 10 #include "app/gfx/text_elider.h" |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 UTF8ToUTF16(get_download()->original_name().value())); | 294 UTF8ToUTF16(get_download()->original_name().value())); |
295 gchar* label_markup = | 295 gchar* label_markup = |
296 g_markup_printf_escaped(kLabelColorMarkup, kFilenameColor, | 296 g_markup_printf_escaped(kLabelColorMarkup, kFilenameColor, |
297 dangerous_warning.c_str()); | 297 dangerous_warning.c_str()); |
298 GtkWidget* dangerous_label = gtk_label_new(NULL); | 298 GtkWidget* dangerous_label = gtk_label_new(NULL); |
299 // Until we switch to vector graphics, force the font size. | 299 // Until we switch to vector graphics, force the font size. |
300 // 13.4px == 10pt @ 96dpi | 300 // 13.4px == 10pt @ 96dpi |
301 gtk_util::ForceFontSizePixels(dangerous_label, 13.4); | 301 gtk_util::ForceFontSizePixels(dangerous_label, 13.4); |
302 gtk_label_set_markup(GTK_LABEL(dangerous_label), label_markup); | 302 gtk_label_set_markup(GTK_LABEL(dangerous_label), label_markup); |
303 gtk_label_set_line_wrap(GTK_LABEL(dangerous_label), TRUE); | 303 gtk_label_set_line_wrap(GTK_LABEL(dangerous_label), TRUE); |
| 304 // We pass TRUE, TRUE so that the label will condense to less than its |
| 305 // request when the animation is going on. |
304 gtk_box_pack_start(GTK_BOX(dangerous_hbox_), dangerous_label, | 306 gtk_box_pack_start(GTK_BOX(dangerous_hbox_), dangerous_label, |
305 FALSE, FALSE, 0); | 307 TRUE, TRUE, 0); |
306 g_free(label_markup); | 308 g_free(label_markup); |
307 | 309 |
308 // Create the ok button. | 310 // Create the ok button. |
309 GtkWidget* dangerous_accept = gtk_button_new_with_label( | 311 GtkWidget* dangerous_accept = gtk_button_new_with_label( |
310 l10n_util::GetStringUTF8(IDS_SAVE_DOWNLOAD).c_str()); | 312 l10n_util::GetStringUTF8(IDS_SAVE_DOWNLOAD).c_str()); |
311 g_signal_connect(dangerous_accept, "clicked", | 313 g_signal_connect(dangerous_accept, "clicked", |
312 G_CALLBACK(OnDangerousAccept), this); | 314 G_CALLBACK(OnDangerousAccept), this); |
313 gtk_util::CenterWidgetInHBox(dangerous_hbox_, dangerous_accept, false, 0); | 315 gtk_util::CenterWidgetInHBox(dangerous_hbox_, dangerous_accept, false, 0); |
314 | 316 |
315 // Create the nevermind button. | 317 // Create the nevermind button. |
316 GtkWidget* dangerous_decline = gtk_button_new_with_label( | 318 GtkWidget* dangerous_decline = gtk_button_new_with_label( |
317 l10n_util::GetStringUTF8(IDS_DISCARD_DOWNLOAD).c_str()); | 319 l10n_util::GetStringUTF8(IDS_DISCARD_DOWNLOAD).c_str()); |
318 g_signal_connect(dangerous_decline, "clicked", | 320 g_signal_connect(dangerous_decline, "clicked", |
319 G_CALLBACK(OnDangerousDecline), this); | 321 G_CALLBACK(OnDangerousDecline), this); |
320 gtk_util::CenterWidgetInHBox(dangerous_hbox_, dangerous_decline, false, 0); | 322 gtk_util::CenterWidgetInHBox(dangerous_hbox_, dangerous_decline, false, 0); |
321 | 323 |
322 // Put it in an alignment so that padding will be added on the left and | 324 // Put it in an alignment so that padding will be added on the left and |
323 // right, and an event box so that drawing will be clipped correctly. | 325 // right. |
324 dangerous_prompt_ = gtk_util::CreateGtkBorderBin(dangerous_hbox_, NULL, | 326 dangerous_prompt_ = gtk_alignment_new(0.0, 0.0, 1.0, 1.0); |
| 327 gtk_alignment_set_padding(GTK_ALIGNMENT(dangerous_prompt_), |
325 0, 0, kDangerousElementPadding, kDangerousElementPadding); | 328 0, 0, kDangerousElementPadding, kDangerousElementPadding); |
| 329 gtk_container_add(GTK_CONTAINER(dangerous_prompt_), dangerous_hbox_); |
326 gtk_box_pack_start(GTK_BOX(hbox_), dangerous_prompt_, FALSE, FALSE, 0); | 330 gtk_box_pack_start(GTK_BOX(hbox_), dangerous_prompt_, FALSE, FALSE, 0); |
327 gtk_widget_set_app_paintable(dangerous_prompt_, TRUE); | 331 gtk_widget_set_app_paintable(dangerous_prompt_, TRUE); |
328 g_signal_connect(dangerous_prompt_, "expose-event", | 332 g_signal_connect(dangerous_prompt_, "expose-event", |
329 G_CALLBACK(OnDangerousPromptExpose), this); | 333 G_CALLBACK(OnDangerousPromptExpose), this); |
330 gtk_widget_show_all(dangerous_prompt_); | 334 gtk_widget_show_all(dangerous_prompt_); |
331 | 335 |
332 // The full width will depend on the text. | 336 // The width will depend on the text. |
333 GtkRequisition req; | 337 GtkRequisition req; |
334 gtk_widget_size_request(dangerous_hbox_, &req); | 338 gtk_widget_size_request(dangerous_hbox_, &req); |
335 dangerous_hbox_full_width_ = req.width; | 339 dangerous_hbox_full_width_ = req.width; |
| 340 gtk_widget_size_request(dangerous_label, &req); |
| 341 dangerous_hbox_start_width_ = dangerous_hbox_full_width_ - req.width; |
336 } | 342 } |
337 | 343 |
338 new_item_animation_->Show(); | 344 new_item_animation_->Show(); |
339 } | 345 } |
340 | 346 |
341 DownloadItemGtk::~DownloadItemGtk() { | 347 DownloadItemGtk::~DownloadItemGtk() { |
342 StopDownloadProgress(); | 348 StopDownloadProgress(); |
343 g_signal_handler_disconnect(parent_shelf_->GetHBox(), resize_handler_id_); | 349 g_signal_handler_disconnect(parent_shelf_->GetHBox(), resize_handler_id_); |
344 gtk_widget_destroy(hbox_); | 350 gtk_widget_destroy(hbox_); |
345 get_download()->RemoveObserver(this); | 351 get_download()->RemoveObserver(this); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 WideToUTF8(status_text).c_str()); | 403 WideToUTF8(status_text).c_str()); |
398 gtk_label_set_markup(GTK_LABEL(status_label_), label_markup); | 404 gtk_label_set_markup(GTK_LABEL(status_label_), label_markup); |
399 g_free(label_markup); | 405 g_free(label_markup); |
400 } | 406 } |
401 | 407 |
402 void DownloadItemGtk::AnimationProgressed(const Animation* animation) { | 408 void DownloadItemGtk::AnimationProgressed(const Animation* animation) { |
403 if (animation == complete_animation_.get()) { | 409 if (animation == complete_animation_.get()) { |
404 gtk_widget_queue_draw(progress_area_); | 410 gtk_widget_queue_draw(progress_area_); |
405 } else { | 411 } else { |
406 if (IsDangerous()) { | 412 if (IsDangerous()) { |
407 int showing_width = std::max(kMinDangerousDownloadWidth, | 413 int progress = (dangerous_hbox_full_width_ - |
408 static_cast<int>(dangerous_hbox_full_width_ * | 414 dangerous_hbox_start_width_) * |
409 new_item_animation_->GetCurrentValue())); | 415 new_item_animation_->GetCurrentValue(); |
| 416 int showing_width = dangerous_hbox_start_width_ + progress; |
| 417 showing_width = std::max(kMinDangerousDownloadWidth, showing_width); |
410 gtk_widget_set_size_request(dangerous_hbox_, showing_width, -1); | 418 gtk_widget_set_size_request(dangerous_hbox_, showing_width, -1); |
411 } else { | 419 } else { |
412 DCHECK(animation == new_item_animation_.get()); | 420 DCHECK(animation == new_item_animation_.get()); |
413 // See above TODO for explanation of the extra 50. | 421 // See above TODO for explanation of the extra 50. |
414 int showing_width = std::max(kMinDownloadItemWidth, | 422 int showing_width = std::max(kMinDownloadItemWidth, |
415 static_cast<int>((kTextWidth + 50 + | 423 static_cast<int>((kTextWidth + 50 + |
416 download_util::kSmallProgressIconSize) * | 424 download_util::kSmallProgressIconSize) * |
417 new_item_animation_->GetCurrentValue())); | 425 new_item_animation_->GetCurrentValue())); |
418 showing_width = std::max(showing_width, kMinDownloadItemWidth); | 426 showing_width = std::max(showing_width, kMinDownloadItemWidth); |
419 gtk_widget_set_size_request(body_, showing_width, -1); | 427 gtk_widget_set_size_request(body_, showing_width, -1); |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
655 item->get_download()); | 663 item->get_download()); |
656 } | 664 } |
657 | 665 |
658 // static | 666 // static |
659 void DownloadItemGtk::OnDangerousDecline(GtkWidget* button, | 667 void DownloadItemGtk::OnDangerousDecline(GtkWidget* button, |
660 DownloadItemGtk* item) { | 668 DownloadItemGtk* item) { |
661 if (item->get_download()->state() == DownloadItem::IN_PROGRESS) | 669 if (item->get_download()->state() == DownloadItem::IN_PROGRESS) |
662 item->get_download()->Cancel(true); | 670 item->get_download()->Cancel(true); |
663 item->get_download()->Remove(true); | 671 item->get_download()->Remove(true); |
664 } | 672 } |
OLD | NEW |