summaryrefslogtreecommitdiffstats
path: root/chrome/browser/download
diff options
context:
space:
mode:
authortapted@chromium.org <tapted@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-07-16 04:21:21 +0000
committertapted@chromium.org <tapted@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-07-16 04:21:21 +0000
commit080572cc312d3a19c4f714d357606eb6aced5d0d (patch)
tree340f9a9e44490662d8c7a60c03d732257c3a9c4b /chrome/browser/download
parent94dce12150f1c103c6f39133efff69929309d566 (diff)
downloadchromium_src-080572cc312d3a19c4f714d357606eb6aced5d0d.zip
chromium_src-080572cc312d3a19c4f714d357606eb6aced5d0d.tar.gz
chromium_src-080572cc312d3a19c4f714d357606eb6aced5d0d.tar.bz2
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
Diffstat (limited to 'chrome/browser/download')
-rw-r--r--chrome/browser/download/download_shelf.cc64
-rw-r--r--chrome/browser/download/download_shelf.h33
2 files changed, 37 insertions, 60 deletions
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<void(gfx::Rect*)> 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,