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

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

Issue 2261593002: Use ScopedRTLFlipCanvas more pervasively for RTL flipping. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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
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/views/download/download_item_view.h" 5 #include "chrome/browser/ui/views/download/download_item_view.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <vector> 10 #include <vector>
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 #include "third_party/icu/source/common/unicode/uchar.h" 45 #include "third_party/icu/source/common/unicode/uchar.h"
46 #include "ui/accessibility/ax_view_state.h" 46 #include "ui/accessibility/ax_view_state.h"
47 #include "ui/base/l10n/l10n_util.h" 47 #include "ui/base/l10n/l10n_util.h"
48 #include "ui/base/resource/resource_bundle.h" 48 #include "ui/base/resource/resource_bundle.h"
49 #include "ui/base/theme_provider.h" 49 #include "ui/base/theme_provider.h"
50 #include "ui/events/event.h" 50 #include "ui/events/event.h"
51 #include "ui/gfx/animation/slide_animation.h" 51 #include "ui/gfx/animation/slide_animation.h"
52 #include "ui/gfx/canvas.h" 52 #include "ui/gfx/canvas.h"
53 #include "ui/gfx/color_utils.h" 53 #include "ui/gfx/color_utils.h"
54 #include "ui/gfx/image/image.h" 54 #include "ui/gfx/image/image.h"
55 #include "ui/gfx/scoped_canvas.h"
55 #include "ui/gfx/text_elider.h" 56 #include "ui/gfx/text_elider.h"
56 #include "ui/gfx/text_utils.h" 57 #include "ui/gfx/text_utils.h"
57 #include "ui/views/controls/button/label_button.h" 58 #include "ui/views/controls/button/label_button.h"
58 #include "ui/views/controls/label.h" 59 #include "ui/views/controls/label.h"
59 #include "ui/views/mouse_constants.h" 60 #include "ui/views/mouse_constants.h"
60 #include "ui/views/widget/root_view.h" 61 #include "ui/views/widget/root_view.h"
61 #include "ui/views/widget/widget.h" 62 #include "ui/views/widget/widget.h"
62 63
63 using content::DownloadItem; 64 using content::DownloadItem;
64 using extensions::ExperienceSamplingEvent; 65 using extensions::ExperienceSamplingEvent;
(...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after
696 file_name_color = 697 file_name_color =
697 color_utils::AlphaBlend(SK_ColorBLACK, file_name_color, 255 / 5); 698 color_utils::AlphaBlend(SK_ColorBLACK, file_name_color, 255 / 5);
698 } 699 }
699 canvas->DrawStringRect(status_text_, font_list_, file_name_color, 700 canvas->DrawStringRect(status_text_, font_list_, file_name_color,
700 gfx::Rect(mirrored_x, y, kTextWidth, 701 gfx::Rect(mirrored_x, y, kTextWidth,
701 font_list_.GetHeight())); 702 font_list_.GetHeight()));
702 } 703 }
703 } 704 }
704 705
705 // Paint the background images. 706 // Paint the background images.
706 int x = kLeftPadding; 707 {
707 canvas->Save(); 708 gfx::ScopedRTLFlipCanvas scoped_canvas(canvas, width());
Peter Kasting 2016/08/18 23:40:41 This file looks as if it's changed a lot, but it's
708 if (base::i18n::IsRTL()) {
709 // Since we do not have the mirrored images for
710 // (hot_)body_image_set->top_left, (hot_)body_image_set->left,
711 // (hot_)body_image_set->bottom_left, and drop_down_image_set,
712 // for RTL UI, we flip the canvas to draw those images mirrored.
713 // Consequently, we do not need to mirror the x-axis of those images.
714 canvas->Translate(gfx::Vector2d(width(), 0));
715 canvas->Scale(-1, 1);
716 }
717 PaintImages(canvas,
718 body_image_set->top_left, body_image_set->left,
719 body_image_set->bottom_left,
720 x, box_y_, box_height_, body_image_set->top_left->width());
721 x += body_image_set->top_left->width();
722 PaintImages(canvas,
723 body_image_set->top, body_image_set->center,
724 body_image_set->bottom,
725 x, box_y_, box_height_, center_width);
726 x += center_width;
727 PaintImages(canvas,
728 body_image_set->top_right, body_image_set->right,
729 body_image_set->bottom_right,
730 x, box_y_, box_height_, body_image_set->top_right->width());
731
732 // Overlay our body hot state. Warning dialogs don't display body a hot state.
733 if (!IsShowingWarningDialog() &&
734 body_hover_animation_->GetCurrentValue() > 0) {
735 canvas->SaveLayerAlpha(
736 static_cast<int>(body_hover_animation_->GetCurrentValue() * 255));
737 709
738 int x = kLeftPadding; 710 int x = kLeftPadding;
739 PaintImages(canvas, 711 PaintImages(canvas,
740 hot_body_image_set_.top_left, hot_body_image_set_.left, 712 body_image_set->top_left, body_image_set->left,
741 hot_body_image_set_.bottom_left, 713 body_image_set->bottom_left,
742 x, box_y_, box_height_, hot_body_image_set_.top_left->width()); 714 x, box_y_, box_height_, body_image_set->top_left->width());
743 x += body_image_set->top_left->width(); 715 x += body_image_set->top_left->width();
744 PaintImages(canvas, 716 PaintImages(canvas,
745 hot_body_image_set_.top, hot_body_image_set_.center, 717 body_image_set->top, body_image_set->center,
746 hot_body_image_set_.bottom, 718 body_image_set->bottom,
747 x, box_y_, box_height_, center_width); 719 x, box_y_, box_height_, center_width);
748 x += center_width; 720 x += center_width;
749 PaintImages(canvas, 721 PaintImages(canvas,
750 hot_body_image_set_.top_right, hot_body_image_set_.right, 722 body_image_set->top_right, body_image_set->right,
751 hot_body_image_set_.bottom_right, 723 body_image_set->bottom_right,
752 x, box_y_, box_height_, 724 x, box_y_, box_height_, body_image_set->top_right->width());
753 hot_body_image_set_.top_right->width());
754 canvas->Restore();
755 }
756 725
757 x += body_image_set->top_right->width(); 726 // Overlay our body hot state. Warning dialogs don't display body a hot
727 // state.
728 if (!IsShowingWarningDialog() &&
729 body_hover_animation_->GetCurrentValue() > 0) {
730 canvas->SaveLayerAlpha(
731 static_cast<int>(body_hover_animation_->GetCurrentValue() * 255));
758 732
759 // Paint the drop-down. 733 int x = kLeftPadding;
760 if (drop_down_image_set) { 734 PaintImages(canvas,
761 PaintImages(canvas, 735 hot_body_image_set_.top_left, hot_body_image_set_.left,
762 drop_down_image_set->top, drop_down_image_set->center, 736 hot_body_image_set_.bottom_left,
763 drop_down_image_set->bottom, 737 x, box_y_, box_height_,
764 x, box_y_, box_height_, drop_down_image_set->top->width()); 738 hot_body_image_set_.top_left->width());
739 x += body_image_set->top_left->width();
740 PaintImages(canvas,
741 hot_body_image_set_.top, hot_body_image_set_.center,
742 hot_body_image_set_.bottom,
743 x, box_y_, box_height_, center_width);
744 x += center_width;
745 PaintImages(canvas,
746 hot_body_image_set_.top_right, hot_body_image_set_.right,
747 hot_body_image_set_.bottom_right,
748 x, box_y_, box_height_,
749 hot_body_image_set_.top_right->width());
750 canvas->Restore();
751 }
765 752
766 // Overlay our drop-down hot state. 753 x += body_image_set->top_right->width();
767 if (drop_hover_animation_->GetCurrentValue() > 0) {
768 canvas->SaveLayerAlpha(
769 static_cast<int>(drop_hover_animation_->GetCurrentValue() * 255));
770 754
755 // Paint the drop-down.
756 if (drop_down_image_set) {
771 PaintImages(canvas, 757 PaintImages(canvas,
772 drop_down_image_set->top, drop_down_image_set->center, 758 drop_down_image_set->top, drop_down_image_set->center,
773 drop_down_image_set->bottom, 759 drop_down_image_set->bottom,
774 x, box_y_, box_height_, drop_down_image_set->top->width()); 760 x, box_y_, box_height_, drop_down_image_set->top->width());
775 761
776 canvas->Restore(); 762 // Overlay our drop-down hot state.
763 if (drop_hover_animation_->GetCurrentValue() > 0) {
764 canvas->SaveLayerAlpha(
765 static_cast<int>(drop_hover_animation_->GetCurrentValue() * 255));
766
767 PaintImages(canvas,
768 drop_down_image_set->top, drop_down_image_set->center,
769 drop_down_image_set->bottom,
770 x, box_y_, box_height_, drop_down_image_set->top->width());
771
772 canvas->Restore();
773 }
777 } 774 }
778 } 775 }
779 776
780 // Restore the canvas to avoid file name etc. text are drawn flipped.
781 // Consequently, the x-axis of following canvas->DrawXXX() method should be
782 // mirrored so the text and images are down in the right positions.
783 canvas->Restore();
784
785 // Print the text, left aligned and always print the file extension. 777 // Print the text, left aligned and always print the file extension.
786 // Last value of x was the end of the right image, just before the button. 778 // Last value of x was the end of the right image, just before the button.
787 // Note that in dangerous mode we use a label (as the text is multi-line). 779 // Note that in dangerous mode we use a label (as the text is multi-line).
788 if (!IsShowingWarningDialog()) { 780 if (!IsShowingWarningDialog()) {
789 base::string16 filename; 781 base::string16 filename;
790 if (!disabled_while_opening_) { 782 if (!disabled_while_opening_) {
791 filename = gfx::ElideFilename(download()->GetFileNameToReportUser(), 783 filename = gfx::ElideFilename(download()->GetFileNameToReportUser(),
792 font_list_, kTextWidth); 784 font_list_, kTextWidth);
793 } else { 785 } else {
794 // First, Calculate the download status opening string width. 786 // First, Calculate the download status opening string width.
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after
1353 animation->Reset((to == HOT) ? 1.0 : 0.0); 1345 animation->Reset((to == HOT) ? 1.0 : 0.0);
1354 } 1346 }
1355 } 1347 }
1356 1348
1357 void DownloadItemView::ProgressTimerFired() { 1349 void DownloadItemView::ProgressTimerFired() {
1358 // Only repaint for the indeterminate size case. Otherwise, we'll repaint only 1350 // Only repaint for the indeterminate size case. Otherwise, we'll repaint only
1359 // when there's an update notified via OnDownloadUpdated(). 1351 // when there's an update notified via OnDownloadUpdated().
1360 if (model_.PercentComplete() < 0) 1352 if (model_.PercentComplete() < 0)
1361 SchedulePaint(); 1353 SchedulePaint();
1362 } 1354 }
OLDNEW
« no previous file with comments | « ash/common/system/tray/tray_popup_label_button_border.cc ('k') | chrome/browser/ui/views/toolbar/app_menu.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698