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

Side by Side Diff: chrome/browser/views/download_item_view.cc

Issue 2825018: Canvas refactoring part 3.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 6 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/views/download_item_view.h" 5 #include "chrome/browser/views/download_item_view.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "app/l10n_util.h" 9 #include "app/l10n_util.h"
10 #include "app/resource_bundle.h" 10 #include "app/resource_bundle.h"
11 #include "app/text_elider.h" 11 #include "app/text_elider.h"
12 #include "app/theme_provider.h" 12 #include "app/theme_provider.h"
13 #include "base/callback.h" 13 #include "base/callback.h"
14 #include "base/file_path.h" 14 #include "base/file_path.h"
15 #include "base/i18n/rtl.h" 15 #include "base/i18n/rtl.h"
16 #include "base/string_util.h" 16 #include "base/string_util.h"
17 #include "base/sys_string_conversions.h" 17 #include "base/sys_string_conversions.h"
18 #include "chrome/browser/browser_process.h" 18 #include "chrome/browser/browser_process.h"
19 #include "chrome/browser/browser_theme_provider.h" 19 #include "chrome/browser/browser_theme_provider.h"
20 #include "chrome/browser/download/download_item_model.h" 20 #include "chrome/browser/download/download_item_model.h"
21 #include "chrome/browser/download/download_util.h" 21 #include "chrome/browser/download/download_util.h"
22 #include "chrome/browser/views/download_shelf_view.h" 22 #include "chrome/browser/views/download_shelf_view.h"
23 #include "gfx/canvas.h" 23 #include "gfx/canvas_skia.h"
24 #include "gfx/color_utils.h" 24 #include "gfx/color_utils.h"
25 #include "grit/generated_resources.h" 25 #include "grit/generated_resources.h"
26 #include "grit/theme_resources.h" 26 #include "grit/theme_resources.h"
27 #include "views/controls/button/native_button.h" 27 #include "views/controls/button/native_button.h"
28 #include "views/controls/menu/menu_2.h" 28 #include "views/controls/menu/menu_2.h"
29 #include "views/widget/root_view.h" 29 #include "views/widget/root_view.h"
30 #include "views/widget/widget.h" 30 #include "views/widget/widget.h"
31 31
32 #if defined(OS_WIN) 32 #if defined(OS_WIN)
33 #include "app/win_util.h" 33 #include "app/win_util.h"
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 508
509 // Paint the background images. 509 // Paint the background images.
510 int x = kLeftPadding; 510 int x = kLeftPadding;
511 bool rtl_ui = base::i18n::IsRTL(); 511 bool rtl_ui = base::i18n::IsRTL();
512 if (rtl_ui) { 512 if (rtl_ui) {
513 // Since we do not have the mirrored images for 513 // Since we do not have the mirrored images for
514 // (hot_)body_image_set->top_left, (hot_)body_image_set->left, 514 // (hot_)body_image_set->top_left, (hot_)body_image_set->left,
515 // (hot_)body_image_set->bottom_left, and drop_down_image_set, 515 // (hot_)body_image_set->bottom_left, and drop_down_image_set,
516 // for RTL UI, we flip the canvas to draw those images mirrored. 516 // for RTL UI, we flip the canvas to draw those images mirrored.
517 // Consequently, we do not need to mirror the x-axis of those images. 517 // Consequently, we do not need to mirror the x-axis of those images.
518 canvas->save(); 518 canvas->AsCanvasSkia()->save();
519 canvas->TranslateInt(width(), 0); 519 canvas->TranslateInt(width(), 0);
520 canvas->ScaleInt(-1, 1); 520 canvas->ScaleInt(-1, 1);
521 } 521 }
522 PaintBitmaps(canvas, 522 PaintBitmaps(canvas,
523 body_image_set->top_left, body_image_set->left, 523 body_image_set->top_left, body_image_set->left,
524 body_image_set->bottom_left, 524 body_image_set->bottom_left,
525 x, box_y_, box_height_, body_image_set->top_left->width()); 525 x, box_y_, box_height_, body_image_set->top_left->width());
526 x += body_image_set->top_left->width(); 526 x += body_image_set->top_left->width();
527 PaintBitmaps(canvas, 527 PaintBitmaps(canvas,
528 body_image_set->top, body_image_set->center, 528 body_image_set->top, body_image_set->center,
529 body_image_set->bottom, 529 body_image_set->bottom,
530 x, box_y_, box_height_, center_width); 530 x, box_y_, box_height_, center_width);
531 x += center_width; 531 x += center_width;
532 PaintBitmaps(canvas, 532 PaintBitmaps(canvas,
533 body_image_set->top_right, body_image_set->right, 533 body_image_set->top_right, body_image_set->right,
534 body_image_set->bottom_right, 534 body_image_set->bottom_right,
535 x, box_y_, box_height_, body_image_set->top_right->width()); 535 x, box_y_, box_height_, body_image_set->top_right->width());
536 536
537 // Overlay our body hot state. 537 // Overlay our body hot state.
538 if (body_hover_animation_->GetCurrentValue() > 0) { 538 if (body_hover_animation_->GetCurrentValue() > 0) {
539 canvas->saveLayerAlpha(NULL, 539 canvas->AsCanvasSkia()->saveLayerAlpha(NULL,
540 static_cast<int>(body_hover_animation_->GetCurrentValue() * 255), 540 static_cast<int>(body_hover_animation_->GetCurrentValue() * 255),
541 SkCanvas::kARGB_NoClipLayer_SaveFlag); 541 SkCanvas::kARGB_NoClipLayer_SaveFlag);
542 canvas->drawARGB(0, 255, 255, 255, SkXfermode::kClear_Mode); 542 canvas->AsCanvasSkia()->drawARGB(0, 255, 255, 255, SkXfermode::kClear_Mode);
543 543
544 int x = kLeftPadding; 544 int x = kLeftPadding;
545 PaintBitmaps(canvas, 545 PaintBitmaps(canvas,
546 hot_body_image_set_.top_left, hot_body_image_set_.left, 546 hot_body_image_set_.top_left, hot_body_image_set_.left,
547 hot_body_image_set_.bottom_left, 547 hot_body_image_set_.bottom_left,
548 x, box_y_, box_height_, hot_body_image_set_.top_left->width()); 548 x, box_y_, box_height_, hot_body_image_set_.top_left->width());
549 x += body_image_set->top_left->width(); 549 x += body_image_set->top_left->width();
550 PaintBitmaps(canvas, 550 PaintBitmaps(canvas,
551 hot_body_image_set_.top, hot_body_image_set_.center, 551 hot_body_image_set_.top, hot_body_image_set_.center,
552 hot_body_image_set_.bottom, 552 hot_body_image_set_.bottom,
553 x, box_y_, box_height_, center_width); 553 x, box_y_, box_height_, center_width);
554 x += center_width; 554 x += center_width;
555 PaintBitmaps(canvas, 555 PaintBitmaps(canvas,
556 hot_body_image_set_.top_right, hot_body_image_set_.right, 556 hot_body_image_set_.top_right, hot_body_image_set_.right,
557 hot_body_image_set_.bottom_right, 557 hot_body_image_set_.bottom_right,
558 x, box_y_, box_height_, 558 x, box_y_, box_height_,
559 hot_body_image_set_.top_right->width()); 559 hot_body_image_set_.top_right->width());
560 canvas->restore(); 560 canvas->AsCanvasSkia()->restore();
561 if (rtl_ui) { 561 if (rtl_ui) {
562 canvas->restore(); 562 canvas->AsCanvasSkia()->restore();
563 canvas->save(); 563 canvas->AsCanvasSkia()->save();
564 // Flip it for drawing drop-down images for RTL locales. 564 // Flip it for drawing drop-down images for RTL locales.
565 canvas->TranslateInt(width(), 0); 565 canvas->TranslateInt(width(), 0);
566 canvas->ScaleInt(-1, 1); 566 canvas->ScaleInt(-1, 1);
567 } 567 }
568 } 568 }
569 569
570 x += body_image_set->top_right->width(); 570 x += body_image_set->top_right->width();
571 571
572 // Paint the drop-down. 572 // Paint the drop-down.
573 if (drop_down_image_set) { 573 if (drop_down_image_set) {
574 PaintBitmaps(canvas, 574 PaintBitmaps(canvas,
575 drop_down_image_set->top, drop_down_image_set->center, 575 drop_down_image_set->top, drop_down_image_set->center,
576 drop_down_image_set->bottom, 576 drop_down_image_set->bottom,
577 x, box_y_, box_height_, drop_down_image_set->top->width()); 577 x, box_y_, box_height_, drop_down_image_set->top->width());
578 578
579 // Overlay our drop-down hot state. 579 // Overlay our drop-down hot state.
580 if (drop_hover_animation_->GetCurrentValue() > 0) { 580 if (drop_hover_animation_->GetCurrentValue() > 0) {
581 canvas->saveLayerAlpha(NULL, 581 canvas->AsCanvasSkia()->saveLayerAlpha(
582 NULL,
582 static_cast<int>(drop_hover_animation_->GetCurrentValue() * 255), 583 static_cast<int>(drop_hover_animation_->GetCurrentValue() * 255),
583 SkCanvas::kARGB_NoClipLayer_SaveFlag); 584 SkCanvas::kARGB_NoClipLayer_SaveFlag);
584 canvas->drawARGB(0, 255, 255, 255, SkXfermode::kClear_Mode); 585 canvas->AsCanvasSkia()->drawARGB(0, 255, 255, 255,
586 SkXfermode::kClear_Mode);
585 587
586 PaintBitmaps(canvas, 588 PaintBitmaps(canvas,
587 drop_down_image_set->top, drop_down_image_set->center, 589 drop_down_image_set->top, drop_down_image_set->center,
588 drop_down_image_set->bottom, 590 drop_down_image_set->bottom,
589 x, box_y_, box_height_, drop_down_image_set->top->width()); 591 x, box_y_, box_height_, drop_down_image_set->top->width());
590 592
591 canvas->restore(); 593 canvas->AsCanvasSkia()->restore();
592 } 594 }
593 } 595 }
594 596
595 if (rtl_ui) { 597 if (rtl_ui) {
596 // Restore the canvas to avoid file name etc. text are drawn flipped. 598 // Restore the canvas to avoid file name etc. text are drawn flipped.
597 // Consequently, the x-axis of following canvas->DrawXXX() method should be 599 // Consequently, the x-axis of following canvas->DrawXXX() method should be
598 // mirrored so the text and images are down in the right positions. 600 // mirrored so the text and images are down in the right positions.
599 canvas->restore(); 601 canvas->AsCanvasSkia()->restore();
600 } 602 }
601 603
602 // Print the text, left aligned and always print the file extension. 604 // Print the text, left aligned and always print the file extension.
603 // Last value of x was the end of the right image, just before the button. 605 // Last value of x was the end of the right image, just before the button.
604 // Note that in dangerous mode we use a label (as the text is multi-line). 606 // Note that in dangerous mode we use a label (as the text is multi-line).
605 if (!IsDangerousMode()) { 607 if (!IsDangerousMode()) {
606 std::wstring filename; 608 std::wstring filename;
607 if (!disabled_while_opening_) { 609 if (!disabled_while_opening_) {
608 filename = gfx::ElideFilename(download_->GetFileName(), 610 filename = gfx::ElideFilename(download_->GetFileName(),
609 font_, kTextWidth); 611 font_, kTextWidth);
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after
1007 void DownloadItemView::Reenable() { 1009 void DownloadItemView::Reenable() {
1008 disabled_while_opening_ = false; 1010 disabled_while_opening_ = false;
1009 SetEnabled(true); // Triggers a repaint. 1011 SetEnabled(true); // Triggers a repaint.
1010 } 1012 }
1011 1013
1012 bool DownloadItemView::InDropDownButtonXCoordinateRange(int x) { 1014 bool DownloadItemView::InDropDownButtonXCoordinateRange(int x) {
1013 if (x > drop_down_x_left_ && x < drop_down_x_right_) 1015 if (x > drop_down_x_left_ && x < drop_down_x_right_)
1014 return true; 1016 return true;
1015 return false; 1017 return false;
1016 } 1018 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698