From 080572cc312d3a19c4f714d357606eb6aced5d0d Mon Sep 17 00:00:00 2001 From: "tapted@chromium.org" Date: Wed, 16 Jul 2014 04:21:21 +0000 Subject: MacViews: Refactor DownloadShelf paint functions to remove views dependency We want to build Chrome with toolkit-views available, but port things gradually. This change converts a View* argument into a callback argument that calls the required member function on View. This lets us get rid of eleven #ifdef guards which would otherwise need to change (now, and again once the download shelf is ported to use views on Mac). BUG=390755 Review URL: https://codereview.chromium.org/377223002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@283330 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/download/download_shelf.cc | 64 ++++++++++++------------------- chrome/browser/download/download_shelf.h | 33 ++++++---------- 2 files changed, 37 insertions(+), 60 deletions(-) (limited to 'chrome/browser/download') diff --git a/chrome/browser/download/download_shelf.cc b/chrome/browser/download/download_shelf.cc index ddd4a85..81d11b8 100644 --- a/chrome/browser/download/download_shelf.cc +++ b/chrome/browser/download/download_shelf.cc @@ -32,10 +32,6 @@ #include "ui/gfx/canvas.h" #include "ui/gfx/image/image_skia.h" -#if defined(TOOLKIT_VIEWS) -#include "ui/views/view.h" -#endif - using content::DownloadItem; namespace { @@ -154,15 +150,14 @@ void DownloadShelf::PaintCustomDownloadProgress( } // static -void DownloadShelf::PaintDownloadProgress(gfx::Canvas* canvas, -#if defined(TOOLKIT_VIEWS) - views::View* containing_view, -#endif - int origin_x, - int origin_y, - int start_angle, - int percent_done, - PaintDownloadProgressSize size) { +void DownloadShelf::PaintDownloadProgress( + gfx::Canvas* canvas, + const BoundsAdjusterCallback& rtl_mirror, + int origin_x, + int origin_y, + int start_angle, + int percent_done, + PaintDownloadProgressSize size) { // Load up our common images. if (!g_background_16) { ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); @@ -189,11 +184,8 @@ void DownloadShelf::PaintDownloadProgress(gfx::Canvas* canvas, gfx::Rect bounds(origin_x, origin_y, background->width(), background->height()); -#if defined(TOOLKIT_VIEWS) // Mirror the positions if necessary. - int mirrored_x = containing_view->GetMirroredXForRect(bounds); - bounds.set_x(mirrored_x); -#endif + rtl_mirror.Run(&bounds); // Draw the background progress image. canvas->DrawImageInt(*background, @@ -210,14 +202,13 @@ void DownloadShelf::PaintDownloadProgress(gfx::Canvas* canvas, } // static -void DownloadShelf::PaintDownloadComplete(gfx::Canvas* canvas, -#if defined(TOOLKIT_VIEWS) - views::View* containing_view, -#endif - int origin_x, - int origin_y, - double animation_progress, - PaintDownloadProgressSize size) { +void DownloadShelf::PaintDownloadComplete( + gfx::Canvas* canvas, + const BoundsAdjusterCallback& rtl_mirror, + int origin_x, + int origin_y, + double animation_progress, + PaintDownloadProgressSize size) { // Load up our common images. if (!g_foreground_16) { ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); @@ -229,10 +220,8 @@ void DownloadShelf::PaintDownloadComplete(gfx::Canvas* canvas, gfx::Rect complete_bounds(origin_x, origin_y, complete->width(), complete->height()); -#if defined(TOOLKIT_VIEWS) // Mirror the positions if necessary. - complete_bounds.set_x(containing_view->GetMirroredXForRect(complete_bounds)); -#endif + rtl_mirror.Run(&complete_bounds); // Start at full opacity, then loop back and forth five times before ending // at zero opacity. @@ -241,14 +230,13 @@ void DownloadShelf::PaintDownloadComplete(gfx::Canvas* canvas, } // static -void DownloadShelf::PaintDownloadInterrupted(gfx::Canvas* canvas, -#if defined(TOOLKIT_VIEWS) - views::View* containing_view, -#endif - int origin_x, - int origin_y, - double animation_progress, - PaintDownloadProgressSize size) { +void DownloadShelf::PaintDownloadInterrupted( + gfx::Canvas* canvas, + const BoundsAdjusterCallback& rtl_mirror, + int origin_x, + int origin_y, + double animation_progress, + PaintDownloadProgressSize size) { // Load up our common images. if (!g_foreground_16) { ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); @@ -260,10 +248,8 @@ void DownloadShelf::PaintDownloadInterrupted(gfx::Canvas* canvas, gfx::Rect complete_bounds(origin_x, origin_y, complete->width(), complete->height()); -#if defined(TOOLKIT_VIEWS) // Mirror the positions if necessary. - complete_bounds.set_x(containing_view->GetMirroredXForRect(complete_bounds)); -#endif + rtl_mirror.Run(&complete_bounds); // Start at zero opacity, then loop back and forth five times before ending // at full opacity. diff --git a/chrome/browser/download/download_shelf.h b/chrome/browser/download/download_shelf.h index ac105ce..a42042f 100644 --- a/chrome/browser/download/download_shelf.h +++ b/chrome/browser/download/download_shelf.h @@ -5,6 +5,7 @@ #ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_SHELF_H_ #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_SHELF_H_ +#include "base/callback_forward.h" #include "base/memory/weak_ptr.h" #include "base/time/time.h" #include "build/build_config.h" @@ -22,12 +23,6 @@ class DownloadItem; class DownloadManager; } -#if defined(TOOLKIT_VIEWS) -namespace views { -class View; -} -#endif - // This is an abstract base class for platform specific download shelf // implementations. class DownloadShelf { @@ -78,6 +73,14 @@ class DownloadShelf { kSmallProgressIconOffset = (kSmallProgressIconSize - kSmallIconSize) / 2 }; + // Type of the callback used on toolkit-views platforms for the |rtl_mirror| + // argument of the PaintDownload functions. It captures the View subclass + // within which the progress animation is drawn and is used to update the + // correct 'left' value for the given rectangle in RTL locales. This is used + // to mirror the position of the progress animation. The callback is + // guaranteed to be invoked before the paint function returns. + typedef base::Callback BoundsAdjusterCallback; + DownloadShelf(); virtual ~DownloadShelf(); @@ -92,12 +95,6 @@ class DownloadShelf { // Paint the common download animation progress foreground and background, // clipping the foreground to 'percent' full. If percent is -1, then we don't // know the total size, so we just draw a rotating segment until we're done. - // - // |containing_view| is the View subclass within which the progress animation - // is drawn (generally either DownloadItemTabView or DownloadItemView). We - // require the containing View in addition to the canvas because if we are - // drawing in a right-to-left locale, we need to mirror the position of the - // progress animation within the containing View. static void PaintCustomDownloadProgress( gfx::Canvas* canvas, const gfx::ImageSkia& background_image, @@ -108,9 +105,7 @@ class DownloadShelf { int percent_done); static void PaintDownloadProgress(gfx::Canvas* canvas, -#if defined(TOOLKIT_VIEWS) - views::View* containing_view, -#endif + const BoundsAdjusterCallback& rtl_mirror, int origin_x, int origin_y, int start_angle, @@ -118,18 +113,14 @@ class DownloadShelf { PaintDownloadProgressSize size); static void PaintDownloadComplete(gfx::Canvas* canvas, -#if defined(TOOLKIT_VIEWS) - views::View* containing_view, -#endif + const BoundsAdjusterCallback& rtl_mirror, int origin_x, int origin_y, double animation_progress, PaintDownloadProgressSize size); static void PaintDownloadInterrupted(gfx::Canvas* canvas, -#if defined(TOOLKIT_VIEWS) - views::View* containing_view, -#endif + const BoundsAdjusterCallback& rtl_mirror, int origin_x, int origin_y, double animation_progress, -- cgit v1.1