Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(237)

Side by Side Diff: chrome/browser/ui/gtk/download/download_item_gtk.cc

Issue 11673004: No need to pass DownloadItemModel ownership. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: DownloadShelfContextMenu class cleanup and require GetMenuModel() to return non-NULL Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/download/download_item_gtk.h" 5 #include "chrome/browser/ui/gtk/download/download_item_gtk.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/debug/trace_event.h" 9 #include "base/debug/trace_event.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 97
98 NineBox* DownloadItemGtk::menu_nine_box_normal_ = NULL; 98 NineBox* DownloadItemGtk::menu_nine_box_normal_ = NULL;
99 NineBox* DownloadItemGtk::menu_nine_box_prelight_ = NULL; 99 NineBox* DownloadItemGtk::menu_nine_box_prelight_ = NULL;
100 NineBox* DownloadItemGtk::menu_nine_box_active_ = NULL; 100 NineBox* DownloadItemGtk::menu_nine_box_active_ = NULL;
101 101
102 NineBox* DownloadItemGtk::dangerous_nine_box_ = NULL; 102 NineBox* DownloadItemGtk::dangerous_nine_box_ = NULL;
103 103
104 using content::DownloadItem; 104 using content::DownloadItem;
105 105
106 DownloadItemGtk::DownloadItemGtk(DownloadShelfGtk* parent_shelf, 106 DownloadItemGtk::DownloadItemGtk(DownloadShelfGtk* parent_shelf,
107 DownloadItemModel* download_model) 107 DownloadItem* download_item)
108 : parent_shelf_(parent_shelf), 108 : parent_shelf_(parent_shelf),
109 arrow_(NULL), 109 arrow_(NULL),
110 menu_showing_(false), 110 menu_showing_(false),
111 theme_service_( 111 theme_service_(
112 GtkThemeService::GetFrom(parent_shelf->browser()->profile())), 112 GtkThemeService::GetFrom(parent_shelf->browser()->profile())),
113 progress_angle_(download_util::kStartAngleDegrees), 113 progress_angle_(download_util::kStartAngleDegrees),
114 download_model_(download_model), 114 download_model_(download_item),
115 dangerous_prompt_(NULL), 115 dangerous_prompt_(NULL),
116 dangerous_label_(NULL), 116 dangerous_label_(NULL),
117 complete_animation_(this), 117 complete_animation_(this),
118 icon_small_(NULL), 118 icon_small_(NULL),
119 icon_large_(NULL), 119 icon_large_(NULL),
120 creation_time_(base::Time::Now()), 120 creation_time_(base::Time::Now()),
121 download_complete_(false), 121 download_complete_(false),
122 disabled_while_opening_(false), 122 disabled_while_opening_(false),
123 weak_ptr_factory_(this) { 123 weak_ptr_factory_(this) {
124 LoadIcon(); 124 LoadIcon();
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 GtkWidget* shelf_hbox = parent_shelf->GetHBox(); 186 GtkWidget* shelf_hbox = parent_shelf->GetHBox();
187 hbox_.Own(gtk_hbox_new(FALSE, 0)); 187 hbox_.Own(gtk_hbox_new(FALSE, 0));
188 g_signal_connect(hbox_.get(), "expose-event", 188 g_signal_connect(hbox_.get(), "expose-event",
189 G_CALLBACK(OnHboxExposeThunk), this); 189 G_CALLBACK(OnHboxExposeThunk), this);
190 gtk_box_pack_start(GTK_BOX(hbox_.get()), body_.get(), FALSE, FALSE, 0); 190 gtk_box_pack_start(GTK_BOX(hbox_.get()), body_.get(), FALSE, FALSE, 0);
191 gtk_box_pack_start(GTK_BOX(hbox_.get()), menu_button_, FALSE, FALSE, 0); 191 gtk_box_pack_start(GTK_BOX(hbox_.get()), menu_button_, FALSE, FALSE, 0);
192 gtk_box_pack_start(GTK_BOX(shelf_hbox), hbox_.get(), FALSE, FALSE, 0); 192 gtk_box_pack_start(GTK_BOX(shelf_hbox), hbox_.get(), FALSE, FALSE, 0);
193 // Insert as the leftmost item. 193 // Insert as the leftmost item.
194 gtk_box_reorder_child(GTK_BOX(shelf_hbox), hbox_.get(), 0); 194 gtk_box_reorder_child(GTK_BOX(shelf_hbox), hbox_.get(), 0);
195 195
196 get_download()->AddObserver(this); 196 download()->AddObserver(this);
197 197
198 new_item_animation_.reset(new ui::SlideAnimation(this)); 198 new_item_animation_.reset(new ui::SlideAnimation(this));
199 new_item_animation_->SetSlideDuration(kNewItemAnimationDurationMs); 199 new_item_animation_->SetSlideDuration(kNewItemAnimationDurationMs);
200 gtk_widget_show_all(hbox_.get()); 200 gtk_widget_show_all(hbox_.get());
201 201
202 if (download_model_->IsDangerous()) { 202 if (download_model_.IsDangerous()) {
203 // Hide the download item components for now. 203 // Hide the download item components for now.
204 gtk_widget_set_no_show_all(body_.get(), TRUE); 204 gtk_widget_set_no_show_all(body_.get(), TRUE);
205 gtk_widget_set_no_show_all(menu_button_, TRUE); 205 gtk_widget_set_no_show_all(menu_button_, TRUE);
206 gtk_widget_hide(body_.get()); 206 gtk_widget_hide(body_.get());
207 gtk_widget_hide(menu_button_); 207 gtk_widget_hide(menu_button_);
208 208
209 // Create an hbox to hold it all. 209 // Create an hbox to hold it all.
210 dangerous_hbox_.Own(gtk_hbox_new(FALSE, kDangerousElementPadding)); 210 dangerous_hbox_.Own(gtk_hbox_new(FALSE, kDangerousElementPadding));
211 211
212 // Add padding at the beginning and end. The hbox will add padding between 212 // Add padding at the beginning and end. The hbox will add padding between
(...skipping 19 matching lines...) Expand all
232 // Create the nevermind button. 232 // Create the nevermind button.
233 GtkWidget* dangerous_decline = gtk_button_new_with_label( 233 GtkWidget* dangerous_decline = gtk_button_new_with_label(
234 l10n_util::GetStringUTF8(IDS_DISCARD_DOWNLOAD).c_str()); 234 l10n_util::GetStringUTF8(IDS_DISCARD_DOWNLOAD).c_str());
235 g_signal_connect(dangerous_decline, "clicked", 235 g_signal_connect(dangerous_decline, "clicked",
236 G_CALLBACK(OnDangerousDeclineThunk), this); 236 G_CALLBACK(OnDangerousDeclineThunk), this);
237 gtk_util::CenterWidgetInHBox(dangerous_hbox_.get(), dangerous_decline, 237 gtk_util::CenterWidgetInHBox(dangerous_hbox_.get(), dangerous_decline,
238 false, 0); 238 false, 0);
239 239
240 // Create the ok button. 240 // Create the ok button.
241 GtkWidget* dangerous_accept = gtk_button_new_with_label( 241 GtkWidget* dangerous_accept = gtk_button_new_with_label(
242 UTF16ToUTF8(download_model_->GetWarningConfirmButtonText()).c_str()); 242 UTF16ToUTF8(download_model_.GetWarningConfirmButtonText()).c_str());
243 g_signal_connect(dangerous_accept, "clicked", 243 g_signal_connect(dangerous_accept, "clicked",
244 G_CALLBACK(OnDangerousAcceptThunk), this); 244 G_CALLBACK(OnDangerousAcceptThunk), this);
245 gtk_util::CenterWidgetInHBox(dangerous_hbox_.get(), dangerous_accept, false, 245 gtk_util::CenterWidgetInHBox(dangerous_hbox_.get(), dangerous_accept, false,
246 0); 246 0);
247 247
248 // Put it in an alignment so that padding will be added on the left and 248 // Put it in an alignment so that padding will be added on the left and
249 // right. 249 // right.
250 dangerous_prompt_ = gtk_alignment_new(0.0, 0.0, 1.0, 1.0); 250 dangerous_prompt_ = gtk_alignment_new(0.0, 0.0, 1.0, 1.0);
251 gtk_alignment_set_padding(GTK_ALIGNMENT(dangerous_prompt_), 251 gtk_alignment_set_padding(GTK_ALIGNMENT(dangerous_prompt_),
252 0, 0, kDangerousElementPadding, kDangerousElementPadding); 252 0, 0, kDangerousElementPadding, kDangerousElementPadding);
253 gtk_container_add(GTK_CONTAINER(dangerous_prompt_), dangerous_hbox_.get()); 253 gtk_container_add(GTK_CONTAINER(dangerous_prompt_), dangerous_hbox_.get());
254 gtk_box_pack_start(GTK_BOX(hbox_.get()), dangerous_prompt_, FALSE, FALSE, 254 gtk_box_pack_start(GTK_BOX(hbox_.get()), dangerous_prompt_, FALSE, FALSE,
255 0); 255 0);
256 gtk_widget_set_app_paintable(dangerous_prompt_, TRUE); 256 gtk_widget_set_app_paintable(dangerous_prompt_, TRUE);
257 gtk_widget_set_redraw_on_allocate(dangerous_prompt_, TRUE); 257 gtk_widget_set_redraw_on_allocate(dangerous_prompt_, TRUE);
258 g_signal_connect(dangerous_prompt_, "expose-event", 258 g_signal_connect(dangerous_prompt_, "expose-event",
259 G_CALLBACK(OnDangerousPromptExposeThunk), this); 259 G_CALLBACK(OnDangerousPromptExposeThunk), this);
260 gtk_widget_show_all(dangerous_prompt_); 260 gtk_widget_show_all(dangerous_prompt_);
261 } 261 }
262 262
263 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, 263 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED,
264 content::Source<ThemeService>(theme_service_)); 264 content::Source<ThemeService>(theme_service_));
265 theme_service_->InitThemesFor(this); 265 theme_service_->InitThemesFor(this);
266 266
267 // Set the initial width of the widget to be animated. 267 // Set the initial width of the widget to be animated.
268 if (download_model_->IsDangerous()) { 268 if (download_model_.IsDangerous()) {
269 gtk_widget_set_size_request(dangerous_hbox_.get(), 269 gtk_widget_set_size_request(dangerous_hbox_.get(),
270 dangerous_hbox_start_width_, -1); 270 dangerous_hbox_start_width_, -1);
271 } else { 271 } else {
272 gtk_widget_set_size_request(body_.get(), kMinDownloadItemWidth, -1); 272 gtk_widget_set_size_request(body_.get(), kMinDownloadItemWidth, -1);
273 } 273 }
274 274
275 new_item_animation_->Show(); 275 new_item_animation_->Show();
276 276
277 complete_animation_.SetTweenType(ui::Tween::LINEAR); 277 complete_animation_.SetTweenType(ui::Tween::LINEAR);
278 complete_animation_.SetSlideDuration(kCompleteAnimationDurationMs); 278 complete_animation_.SetSlideDuration(kCompleteAnimationDurationMs);
279 279
280 // Update the status text and animation state. 280 // Update the status text and animation state.
281 OnDownloadUpdated(get_download()); 281 OnDownloadUpdated(download());
282 } 282 }
283 283
284 DownloadItemGtk::~DownloadItemGtk() { 284 DownloadItemGtk::~DownloadItemGtk() {
285 // First close the menu and then destroy the GtkWidgets. Bug#97724 285 // First close the menu and then destroy the GtkWidgets. Bug#97724
286 if (menu_.get()) 286 if (menu_.get())
287 menu_.reset(); 287 menu_.reset();
288 288
289 StopDownloadProgress(); 289 StopDownloadProgress();
290 get_download()->RemoveObserver(this); 290 download()->RemoveObserver(this);
291 291
292 // We may free some shelf space for showing more download items. 292 // We may free some shelf space for showing more download items.
293 parent_shelf_->MaybeShowMoreDownloadItems(); 293 parent_shelf_->MaybeShowMoreDownloadItems();
294 294
295 hbox_.Destroy(); 295 hbox_.Destroy();
296 progress_area_.Destroy(); 296 progress_area_.Destroy();
297 body_.Destroy(); 297 body_.Destroy();
298 dangerous_hbox_.Destroy(); 298 dangerous_hbox_.Destroy();
299 299
300 // Make sure this widget has been destroyed and the pointer we hold to it 300 // Make sure this widget has been destroyed and the pointer we hold to it
301 // NULLed. 301 // NULLed.
302 DCHECK(!status_label_); 302 DCHECK(!status_label_);
303 } 303 }
304 304
305 void DownloadItemGtk::OnDownloadUpdated(DownloadItem* download) { 305 void DownloadItemGtk::OnDownloadUpdated(DownloadItem* download_item) {
306 DCHECK_EQ(download, get_download()); 306 DCHECK_EQ(download(), download_item);
307 307
308 if (dangerous_prompt_ != NULL && !download_model_->IsDangerous()) { 308 if (dangerous_prompt_ != NULL && !download_model_.IsDangerous()) {
309 // We have been approved. 309 // We have been approved.
310 gtk_widget_set_no_show_all(body_.get(), FALSE); 310 gtk_widget_set_no_show_all(body_.get(), FALSE);
311 gtk_widget_set_no_show_all(menu_button_, FALSE); 311 gtk_widget_set_no_show_all(menu_button_, FALSE);
312 gtk_widget_show_all(hbox_.get()); 312 gtk_widget_show_all(hbox_.get());
313 gtk_widget_destroy(dangerous_prompt_); 313 gtk_widget_destroy(dangerous_prompt_);
314 gtk_widget_set_size_request(body_.get(), kBodyWidth, -1); 314 gtk_widget_set_size_request(body_.get(), kBodyWidth, -1);
315 dangerous_prompt_ = NULL; 315 dangerous_prompt_ = NULL;
316 316
317 // We may free some shelf space for showing more download items. 317 // We may free some shelf space for showing more download items.
318 parent_shelf_->MaybeShowMoreDownloadItems(); 318 parent_shelf_->MaybeShowMoreDownloadItems();
319 } 319 }
320 320
321 if (download->GetUserVerifiedFilePath() != icon_filepath_) { 321 if (download()->GetUserVerifiedFilePath() != icon_filepath_) {
322 // Turns out the file path is "Unconfirmed %d.crdownload" for dangerous 322 // Turns out the file path is "Unconfirmed %d.crdownload" for dangerous
323 // downloads. When the download is confirmed, the file is renamed on 323 // downloads. When the download is confirmed, the file is renamed on
324 // another thread, so reload the icon if the download filename changes. 324 // another thread, so reload the icon if the download filename changes.
325 LoadIcon(); 325 LoadIcon();
326 326
327 UpdateTooltip(); 327 UpdateTooltip();
328 } 328 }
329 329
330 switch (download->GetState()) { 330 switch (download()->GetState()) {
331 case DownloadItem::CANCELLED: 331 case DownloadItem::CANCELLED:
332 StopDownloadProgress(); 332 StopDownloadProgress();
333 gtk_widget_queue_draw(progress_area_.get()); 333 gtk_widget_queue_draw(progress_area_.get());
334 break; 334 break;
335 case DownloadItem::INTERRUPTED: 335 case DownloadItem::INTERRUPTED:
336 StopDownloadProgress(); 336 StopDownloadProgress();
337 UpdateTooltip(); 337 UpdateTooltip();
338 338
339 complete_animation_.Show(); 339 complete_animation_.Show();
340 break; 340 break;
341 case DownloadItem::COMPLETE: 341 case DownloadItem::COMPLETE:
342 // GetAutoOpened() may change after the download's initial transition to 342 // GetAutoOpened() may change after the download's initial transition to
343 // COMPLETE, so we check it before the idemopotency shield below. 343 // COMPLETE, so we check it before the idemopotency shield below.
344 if (download->GetAutoOpened()) { 344 if (download()->GetAutoOpened()) {
345 parent_shelf_->RemoveDownloadItem(this); // This will delete us! 345 parent_shelf_->RemoveDownloadItem(this); // This will delete us!
346 return; 346 return;
347 } 347 }
348 348
349 // We've already handled the completion specific actions; skip 349 // We've already handled the completion specific actions; skip
350 // doing the non-idempotent ones again. 350 // doing the non-idempotent ones again.
351 if (download_complete_) 351 if (download_complete_)
352 break; 352 break;
353 353
354 StopDownloadProgress(); 354 StopDownloadProgress();
355 355
356 // Set up the widget as a drag source. 356 // Set up the widget as a drag source.
357 DownloadItemDrag::SetSource(body_.get(), get_download(), icon_large_); 357 DownloadItemDrag::SetSource(body_.get(), download(), icon_large_);
358 358
359 complete_animation_.Show(); 359 complete_animation_.Show();
360 download_complete_ = true; 360 download_complete_ = true;
361 break; 361 break;
362 case DownloadItem::IN_PROGRESS: 362 case DownloadItem::IN_PROGRESS:
363 get_download()->IsPaused() ? 363 download()->IsPaused() ?
364 StopDownloadProgress() : StartDownloadProgress(); 364 StopDownloadProgress() : StartDownloadProgress();
365 break; 365 break;
366 default: 366 default:
367 NOTREACHED(); 367 NOTREACHED();
368 } 368 }
369 369
370 status_text_ = UTF16ToUTF8(download_model_->GetStatusText()); 370 status_text_ = UTF16ToUTF8(download_model_.GetStatusText());
371 UpdateStatusLabel(status_text_); 371 UpdateStatusLabel(status_text_);
372 } 372 }
373 373
374 void DownloadItemGtk::OnDownloadDestroyed(DownloadItem* download) { 374 void DownloadItemGtk::OnDownloadDestroyed(DownloadItem* download_item) {
375 DCHECK_EQ(download(), download_item);
375 parent_shelf_->RemoveDownloadItem(this); 376 parent_shelf_->RemoveDownloadItem(this);
376 // This will delete us! 377 // This will delete us!
377 } 378 }
378 379
379 void DownloadItemGtk::AnimationProgressed(const ui::Animation* animation) { 380 void DownloadItemGtk::AnimationProgressed(const ui::Animation* animation) {
380 if (animation == &complete_animation_) { 381 if (animation == &complete_animation_) {
381 gtk_widget_queue_draw(progress_area_.get()); 382 gtk_widget_queue_draw(progress_area_.get());
382 } else { 383 } else {
383 DCHECK(animation == new_item_animation_.get()); 384 DCHECK(animation == new_item_animation_.get());
384 if (download_model_->IsDangerous()) { 385 if (download_model_.IsDangerous()) {
385 int progress = static_cast<int>((dangerous_hbox_full_width_ - 386 int progress = static_cast<int>((dangerous_hbox_full_width_ -
386 dangerous_hbox_start_width_) * 387 dangerous_hbox_start_width_) *
387 animation->GetCurrentValue()); 388 animation->GetCurrentValue());
388 int showing_width = dangerous_hbox_start_width_ + progress; 389 int showing_width = dangerous_hbox_start_width_ + progress;
389 gtk_widget_set_size_request(dangerous_hbox_.get(), showing_width, -1); 390 gtk_widget_set_size_request(dangerous_hbox_.get(), showing_width, -1);
390 } else { 391 } else {
391 int showing_width = std::max(kMinDownloadItemWidth, 392 int showing_width = std::max(kMinDownloadItemWidth,
392 static_cast<int>(kBodyWidth * animation->GetCurrentValue())); 393 static_cast<int>(kBodyWidth * animation->GetCurrentValue()));
393 gtk_widget_set_size_request(body_.get(), showing_width, -1); 394 gtk_widget_set_size_request(body_.get(), showing_width, -1);
394 } 395 }
(...skipping 25 matching lines...) Expand all
420 if (arrow_) 421 if (arrow_)
421 gtk_widget_hide(arrow_); 422 gtk_widget_hide(arrow_);
422 } 423 }
423 424
424 UpdateNameLabel(); 425 UpdateNameLabel();
425 UpdateStatusLabel(status_text_); 426 UpdateStatusLabel(status_text_);
426 UpdateDangerWarning(); 427 UpdateDangerWarning();
427 } 428 }
428 } 429 }
429 430
430 DownloadItem* DownloadItemGtk::get_download() {
431 return download_model_->download();
432 }
433
434 // Download progress animation functions. 431 // Download progress animation functions.
435 432
436 void DownloadItemGtk::UpdateDownloadProgress() { 433 void DownloadItemGtk::UpdateDownloadProgress() {
437 progress_angle_ = (progress_angle_ + 434 progress_angle_ = (progress_angle_ +
438 download_util::kUnknownIncrementDegrees) % 435 download_util::kUnknownIncrementDegrees) %
439 download_util::kMaxDegrees; 436 download_util::kMaxDegrees;
440 gtk_widget_queue_draw(progress_area_.get()); 437 gtk_widget_queue_draw(progress_area_.get());
441 } 438 }
442 439
443 void DownloadItemGtk::StartDownloadProgress() { 440 void DownloadItemGtk::StartDownloadProgress() {
(...skipping 10 matching lines...) Expand all
454 451
455 // Icon loading functions. 452 // Icon loading functions.
456 453
457 void DownloadItemGtk::OnLoadSmallIconComplete(gfx::Image* image) { 454 void DownloadItemGtk::OnLoadSmallIconComplete(gfx::Image* image) {
458 icon_small_ = image; 455 icon_small_ = image;
459 gtk_widget_queue_draw(progress_area_.get()); 456 gtk_widget_queue_draw(progress_area_.get());
460 } 457 }
461 458
462 void DownloadItemGtk::OnLoadLargeIconComplete(gfx::Image* image) { 459 void DownloadItemGtk::OnLoadLargeIconComplete(gfx::Image* image) {
463 icon_large_ = image; 460 icon_large_ = image;
464 DownloadItemDrag::SetSource(body_.get(), get_download(), icon_large_); 461 DownloadItemDrag::SetSource(body_.get(), download(), icon_large_);
465 } 462 }
466 463
467 void DownloadItemGtk::LoadIcon() { 464 void DownloadItemGtk::LoadIcon() {
468 cancelable_task_tracker_.TryCancelAll(); 465 cancelable_task_tracker_.TryCancelAll();
469 IconManager* im = g_browser_process->icon_manager(); 466 IconManager* im = g_browser_process->icon_manager();
470 icon_filepath_ = get_download()->GetUserVerifiedFilePath(); 467 icon_filepath_ = download()->GetUserVerifiedFilePath();
471 im->LoadIcon(icon_filepath_, 468 im->LoadIcon(icon_filepath_,
472 IconLoader::SMALL, 469 IconLoader::SMALL,
473 base::Bind(&DownloadItemGtk::OnLoadSmallIconComplete, 470 base::Bind(&DownloadItemGtk::OnLoadSmallIconComplete,
474 base::Unretained(this)), 471 base::Unretained(this)),
475 &cancelable_task_tracker_); 472 &cancelable_task_tracker_);
476 im->LoadIcon(icon_filepath_, 473 im->LoadIcon(icon_filepath_,
477 IconLoader::LARGE, 474 IconLoader::LARGE,
478 base::Bind(&DownloadItemGtk::OnLoadLargeIconComplete, 475 base::Bind(&DownloadItemGtk::OnLoadLargeIconComplete,
479 base::Unretained(this)), 476 base::Unretained(this)),
480 &cancelable_task_tracker_); 477 &cancelable_task_tracker_);
481 } 478 }
482 479
483 void DownloadItemGtk::UpdateTooltip() { 480 void DownloadItemGtk::UpdateTooltip() {
484 string16 tooltip_text = 481 string16 tooltip_text =
485 download_model_->GetTooltipText(gfx::Font(), kTooltipMaxWidth); 482 download_model_.GetTooltipText(gfx::Font(), kTooltipMaxWidth);
486 gtk_widget_set_tooltip_text(body_.get(), UTF16ToUTF8(tooltip_text).c_str()); 483 gtk_widget_set_tooltip_text(body_.get(), UTF16ToUTF8(tooltip_text).c_str());
487 } 484 }
488 485
489 void DownloadItemGtk::UpdateNameLabel() { 486 void DownloadItemGtk::UpdateNameLabel() {
490 // TODO(estade): This is at best an educated guess, since we don't actually 487 // TODO(estade): This is at best an educated guess, since we don't actually
491 // use gfx::Font() to draw the text. This is why we need to add so 488 // use gfx::Font() to draw the text. This is why we need to add so
492 // much padding when we set the size request. We need to either use gfx::Font 489 // much padding when we set the size request. We need to either use gfx::Font
493 // or somehow extend TextElider. 490 // or somehow extend TextElider.
494 gfx::Font font = gfx::Font(); 491 gfx::Font font = gfx::Font();
495 string16 filename; 492 string16 filename;
496 if (!disabled_while_opening_) { 493 if (!disabled_while_opening_) {
497 filename = ui::ElideFilename( 494 filename = ui::ElideFilename(
498 get_download()->GetFileNameToReportUser(), font, kTextWidth); 495 download()->GetFileNameToReportUser(), font, kTextWidth);
499 } else { 496 } else {
500 // First, Calculate the download status opening string width. 497 // First, Calculate the download status opening string width.
501 string16 status_string = 498 string16 status_string =
502 l10n_util::GetStringFUTF16(IDS_DOWNLOAD_STATUS_OPENING, string16()); 499 l10n_util::GetStringFUTF16(IDS_DOWNLOAD_STATUS_OPENING, string16());
503 int status_string_width = font.GetStringWidth(status_string); 500 int status_string_width = font.GetStringWidth(status_string);
504 // Then, elide the file name. 501 // Then, elide the file name.
505 string16 filename_string = 502 string16 filename_string =
506 ui::ElideFilename(get_download()->GetFileNameToReportUser(), font, 503 ui::ElideFilename(download()->GetFileNameToReportUser(), font,
507 kTextWidth - status_string_width); 504 kTextWidth - status_string_width);
508 // Last, concat the whole string. 505 // Last, concat the whole string.
509 filename = l10n_util::GetStringFUTF16(IDS_DOWNLOAD_STATUS_OPENING, 506 filename = l10n_util::GetStringFUTF16(IDS_DOWNLOAD_STATUS_OPENING,
510 filename_string); 507 filename_string);
511 } 508 }
512 509
513 GdkColor color = theme_service_->GetGdkColor( 510 GdkColor color = theme_service_->GetGdkColor(
514 ThemeService::COLOR_BOOKMARK_TEXT); 511 ThemeService::COLOR_BOOKMARK_TEXT);
515 gtk_util::SetLabelColor( 512 gtk_util::SetLabelColor(
516 name_label_, 513 name_label_,
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 gtk_label_set_text(GTK_LABEL(status_label_), status_text.c_str()); 572 gtk_label_set_text(GTK_LABEL(status_label_), status_text.c_str());
576 } 573 }
577 574
578 void DownloadItemGtk::UpdateDangerWarning() { 575 void DownloadItemGtk::UpdateDangerWarning() {
579 if (dangerous_prompt_) { 576 if (dangerous_prompt_) {
580 UpdateDangerIcon(); 577 UpdateDangerIcon();
581 578
582 // We create |dangerous_warning| as a wide string so we can more easily 579 // We create |dangerous_warning| as a wide string so we can more easily
583 // calculate its length in characters. 580 // calculate its length in characters.
584 string16 dangerous_warning = 581 string16 dangerous_warning =
585 download_model_->GetWarningText(gfx::Font(), kTextWidth); 582 download_model_.GetWarningText(gfx::Font(), kTextWidth);
586 if (theme_service_->UsingNativeTheme()) { 583 if (theme_service_->UsingNativeTheme()) {
587 gtk_util::SetLabelColor(dangerous_label_, NULL); 584 gtk_util::SetLabelColor(dangerous_label_, NULL);
588 } else { 585 } else {
589 GdkColor color = theme_service_->GetGdkColor( 586 GdkColor color = theme_service_->GetGdkColor(
590 ThemeService::COLOR_BOOKMARK_TEXT); 587 ThemeService::COLOR_BOOKMARK_TEXT);
591 gtk_util::SetLabelColor(dangerous_label_, &color); 588 gtk_util::SetLabelColor(dangerous_label_, &color);
592 } 589 }
593 590
594 gtk_label_set_text(GTK_LABEL(dangerous_label_), 591 gtk_label_set_text(GTK_LABEL(dangerous_label_),
595 UTF16ToUTF8(dangerous_warning).c_str()); 592 UTF16ToUTF8(dangerous_warning).c_str());
(...skipping 26 matching lines...) Expand all
622 // The width will depend on the text. We must do this each time we possibly 619 // The width will depend on the text. We must do this each time we possibly
623 // change the label above. 620 // change the label above.
624 gtk_widget_size_request(dangerous_hbox_.get(), &req); 621 gtk_widget_size_request(dangerous_hbox_.get(), &req);
625 dangerous_hbox_full_width_ = req.width; 622 dangerous_hbox_full_width_ = req.width;
626 dangerous_hbox_start_width_ = dangerous_hbox_full_width_ - label_width; 623 dangerous_hbox_start_width_ = dangerous_hbox_full_width_ - label_width;
627 } 624 }
628 } 625 }
629 626
630 void DownloadItemGtk::UpdateDangerIcon() { 627 void DownloadItemGtk::UpdateDangerIcon() {
631 if (theme_service_->UsingNativeTheme()) { 628 if (theme_service_->UsingNativeTheme()) {
632 const char* stock = download_model_->IsMalicious() ? 629 const char* stock = download_model_.IsMalicious() ?
633 GTK_STOCK_DIALOG_ERROR : GTK_STOCK_DIALOG_WARNING; 630 GTK_STOCK_DIALOG_ERROR : GTK_STOCK_DIALOG_WARNING;
634 gtk_image_set_from_stock( 631 gtk_image_set_from_stock(
635 GTK_IMAGE(dangerous_image_), stock, GTK_ICON_SIZE_SMALL_TOOLBAR); 632 GTK_IMAGE(dangerous_image_), stock, GTK_ICON_SIZE_SMALL_TOOLBAR);
636 } else { 633 } else {
637 // Set the warning icon. 634 // Set the warning icon.
638 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 635 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
639 int pixbuf_id = download_model_->IsMalicious() ? IDR_SAFEBROWSING_WARNING 636 int pixbuf_id = download_model_.IsMalicious() ? IDR_SAFEBROWSING_WARNING
640 : IDR_WARNING; 637 : IDR_WARNING;
641 gtk_image_set_from_pixbuf(GTK_IMAGE(dangerous_image_), 638 gtk_image_set_from_pixbuf(GTK_IMAGE(dangerous_image_),
642 rb.GetNativeImageNamed(pixbuf_id).ToGdkPixbuf()); 639 rb.GetNativeImageNamed(pixbuf_id).ToGdkPixbuf());
643 } 640 }
644 } 641 }
645 642
646 // static 643 // static
647 void DownloadItemGtk::InitNineBoxes() { 644 void DownloadItemGtk::InitNineBoxes() {
648 if (body_nine_box_normal_) 645 if (body_nine_box_normal_)
649 return; 646 return;
650 647
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
712 TRACE_EVENT0("ui::gtk", "DownloadItemGtk::OnHboxExpose"); 709 TRACE_EVENT0("ui::gtk", "DownloadItemGtk::OnHboxExpose");
713 if (theme_service_->UsingNativeTheme()) { 710 if (theme_service_->UsingNativeTheme()) {
714 GtkAllocation allocation; 711 GtkAllocation allocation;
715 gtk_widget_get_allocation(widget, &allocation); 712 gtk_widget_get_allocation(widget, &allocation);
716 int border_width = gtk_container_get_border_width(GTK_CONTAINER(widget)); 713 int border_width = gtk_container_get_border_width(GTK_CONTAINER(widget));
717 int x = allocation.x + border_width; 714 int x = allocation.x + border_width;
718 int y = allocation.y + border_width; 715 int y = allocation.y + border_width;
719 int width = allocation.width - border_width * 2; 716 int width = allocation.width - border_width * 2;
720 int height = allocation.height - border_width * 2; 717 int height = allocation.height - border_width * 2;
721 718
722 if (download_model_->IsDangerous()) { 719 if (download_model_.IsDangerous()) {
723 // Draw a simple frame around the area when we're displaying the warning. 720 // Draw a simple frame around the area when we're displaying the warning.
724 gtk_paint_shadow(gtk_widget_get_style(widget), 721 gtk_paint_shadow(gtk_widget_get_style(widget),
725 gtk_widget_get_window(widget), 722 gtk_widget_get_window(widget),
726 gtk_widget_get_state(widget), 723 gtk_widget_get_state(widget),
727 static_cast<GtkShadowType>(GTK_SHADOW_OUT), 724 static_cast<GtkShadowType>(GTK_SHADOW_OUT),
728 &e->area, widget, "frame", 725 &e->area, widget, "frame",
729 x, y, width, height); 726 x, y, width, height);
730 } else { 727 } else {
731 // Manually draw the GTK button border around the download item. We draw 728 // Manually draw the GTK button border around the download item. We draw
732 // the left part of the button (the file), a divider, and then the right 729 // the left part of the button (the file), a divider, and then the right
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
823 base::Bind(&DownloadItemGtk::ReenableHbox, 820 base::Bind(&DownloadItemGtk::ReenableHbox,
824 weak_ptr_factory_.GetWeakPtr()), 821 weak_ptr_factory_.GetWeakPtr()),
825 base::TimeDelta::FromMilliseconds(kDisabledOnOpenDurationMs)); 822 base::TimeDelta::FromMilliseconds(kDisabledOnOpenDurationMs));
826 UpdateNameLabel(); 823 UpdateNameLabel();
827 parent_shelf_->ItemOpened(); 824 parent_shelf_->ItemOpened();
828 } 825 }
829 826
830 void DownloadItemGtk::OnClick(GtkWidget* widget) { 827 void DownloadItemGtk::OnClick(GtkWidget* widget) {
831 UMA_HISTOGRAM_LONG_TIMES("clickjacking.open_download", 828 UMA_HISTOGRAM_LONG_TIMES("clickjacking.open_download",
832 base::Time::Now() - creation_time_); 829 base::Time::Now() - creation_time_);
833 get_download()->OpenDownload(); 830 download()->OpenDownload();
834 } 831 }
835 832
836 gboolean DownloadItemGtk::OnButtonPress(GtkWidget* button, 833 gboolean DownloadItemGtk::OnButtonPress(GtkWidget* button,
837 GdkEventButton* event) { 834 GdkEventButton* event) {
838 if (event->type == GDK_BUTTON_PRESS && event->button == 3) { 835 if (event->type == GDK_BUTTON_PRESS && event->button == 3) {
839 ShowPopupMenu(NULL, event); 836 ShowPopupMenu(NULL, event);
840 return TRUE; 837 return TRUE;
841 } 838 }
842 return FALSE; 839 return FALSE;
843 } 840 }
844 841
845 gboolean DownloadItemGtk::OnProgressAreaExpose(GtkWidget* widget, 842 gboolean DownloadItemGtk::OnProgressAreaExpose(GtkWidget* widget,
846 GdkEventExpose* event) { 843 GdkEventExpose* event) {
847 TRACE_EVENT0("ui::gtk", "DownloadItemGtk::OnProgressAreaExpose"); 844 TRACE_EVENT0("ui::gtk", "DownloadItemGtk::OnProgressAreaExpose");
848 845
849 GtkAllocation allocation; 846 GtkAllocation allocation;
850 gtk_widget_get_allocation(widget, &allocation); 847 gtk_widget_get_allocation(widget, &allocation);
851 848
852 // Create a transparent canvas. 849 // Create a transparent canvas.
853 gfx::CanvasSkiaPaint canvas(event, false); 850 gfx::CanvasSkiaPaint canvas(event, false);
854 if (complete_animation_.is_animating()) { 851 if (complete_animation_.is_animating()) {
855 if (get_download()->IsInterrupted()) { 852 if (download()->IsInterrupted()) {
856 download_util::PaintDownloadInterrupted(&canvas, 853 download_util::PaintDownloadInterrupted(&canvas,
857 allocation.x, allocation.y, 854 allocation.x, allocation.y,
858 complete_animation_.GetCurrentValue(), 855 complete_animation_.GetCurrentValue(),
859 download_util::SMALL); 856 download_util::SMALL);
860 } else { 857 } else {
861 download_util::PaintDownloadComplete(&canvas, 858 download_util::PaintDownloadComplete(&canvas,
862 allocation.x, allocation.y, 859 allocation.x, allocation.y,
863 complete_animation_.GetCurrentValue(), 860 complete_animation_.GetCurrentValue(),
864 download_util::SMALL); 861 download_util::SMALL);
865 } 862 }
866 } else if (get_download()->IsInProgress()) { 863 } else if (download()->IsInProgress()) {
867 download_util::PaintDownloadProgress(&canvas, 864 download_util::PaintDownloadProgress(&canvas,
868 allocation.x, allocation.y, 865 allocation.x, allocation.y,
869 progress_angle_, 866 progress_angle_,
870 download_model_->PercentComplete(), 867 download_model_.PercentComplete(),
871 download_util::SMALL); 868 download_util::SMALL);
872 } 869 }
873 870
874 // |icon_small_| may be NULL if it is still loading. If the file is an 871 // |icon_small_| may be NULL if it is still loading. If the file is an
875 // unrecognized type then we will get back a generic system icon. Hence 872 // unrecognized type then we will get back a generic system icon. Hence
876 // there is no need to use the chromium-specific default download item icon. 873 // there is no need to use the chromium-specific default download item icon.
877 if (icon_small_) { 874 if (icon_small_) {
878 const int offset = download_util::kSmallProgressIconOffset; 875 const int offset = download_util::kSmallProgressIconOffset;
879 canvas.DrawImageInt(icon_small_->AsImageSkia(), 876 canvas.DrawImageInt(icon_small_->AsImageSkia(),
880 allocation.x + offset, allocation.y + offset); 877 allocation.x + offset, allocation.y + offset);
(...skipping 13 matching lines...) Expand all
894 return FALSE; 891 return FALSE;
895 } 892 }
896 893
897 void DownloadItemGtk::ShowPopupMenu(GtkWidget* button, 894 void DownloadItemGtk::ShowPopupMenu(GtkWidget* button,
898 GdkEventButton* event) { 895 GdkEventButton* event) {
899 // Stop any completion animation. 896 // Stop any completion animation.
900 if (complete_animation_.is_animating()) 897 if (complete_animation_.is_animating())
901 complete_animation_.End(); 898 complete_animation_.End();
902 899
903 if (!menu_.get()) { 900 if (!menu_.get()) {
904 menu_.reset(new DownloadShelfContextMenuGtk(download_model_.get(), 901 menu_.reset(new DownloadShelfContextMenuGtk(this,
905 this,
906 parent_shelf_->GetNavigator())); 902 parent_shelf_->GetNavigator()));
907 } 903 }
908 menu_->Popup(button, event); 904 menu_->Popup(button, event);
909 } 905 }
910 906
911 gboolean DownloadItemGtk::OnDangerousPromptExpose(GtkWidget* widget, 907 gboolean DownloadItemGtk::OnDangerousPromptExpose(GtkWidget* widget,
912 GdkEventExpose* event) { 908 GdkEventExpose* event) {
913 TRACE_EVENT0("ui::gtk", "DownloadItemGtk::OnDangerousPromptExpose"); 909 TRACE_EVENT0("ui::gtk", "DownloadItemGtk::OnDangerousPromptExpose");
914 if (!theme_service_->UsingNativeTheme()) { 910 if (!theme_service_->UsingNativeTheme()) {
915 // The hbox renderer will take care of the border when in GTK mode. 911 // The hbox renderer will take care of the border when in GTK mode.
916 dangerous_nine_box_->RenderToWidget(widget); 912 dangerous_nine_box_->RenderToWidget(widget);
917 } 913 }
918 return FALSE; // Continue propagation. 914 return FALSE; // Continue propagation.
919 } 915 }
920 916
921 void DownloadItemGtk::OnDangerousAccept(GtkWidget* button) { 917 void DownloadItemGtk::OnDangerousAccept(GtkWidget* button) {
922 UMA_HISTOGRAM_LONG_TIMES("clickjacking.save_download", 918 UMA_HISTOGRAM_LONG_TIMES("clickjacking.save_download",
923 base::Time::Now() - creation_time_); 919 base::Time::Now() - creation_time_);
924 get_download()->DangerousDownloadValidated(); 920 download()->DangerousDownloadValidated();
925 } 921 }
926 922
927 void DownloadItemGtk::OnDangerousDecline(GtkWidget* button) { 923 void DownloadItemGtk::OnDangerousDecline(GtkWidget* button) {
928 UMA_HISTOGRAM_LONG_TIMES("clickjacking.discard_download", 924 UMA_HISTOGRAM_LONG_TIMES("clickjacking.discard_download",
929 base::Time::Now() - creation_time_); 925 base::Time::Now() - creation_time_);
930 if (get_download()->IsPartialDownload()) 926 if (download()->IsPartialDownload())
931 get_download()->Cancel(true); 927 download()->Cancel(true);
932 get_download()->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD); 928 download()->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD);
933 } 929 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/gtk/download/download_item_gtk.h ('k') | chrome/browser/ui/gtk/download/download_shelf_context_menu_gtk.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698