Commit 080572cc authored by tapted@chromium.org's avatar tapted@chromium.org

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
parent 94dce121
...@@ -32,10 +32,6 @@ ...@@ -32,10 +32,6 @@
#include "ui/gfx/canvas.h" #include "ui/gfx/canvas.h"
#include "ui/gfx/image/image_skia.h" #include "ui/gfx/image/image_skia.h"
#if defined(TOOLKIT_VIEWS)
#include "ui/views/view.h"
#endif
using content::DownloadItem; using content::DownloadItem;
namespace { namespace {
...@@ -154,15 +150,14 @@ void DownloadShelf::PaintCustomDownloadProgress( ...@@ -154,15 +150,14 @@ void DownloadShelf::PaintCustomDownloadProgress(
} }
// static // static
void DownloadShelf::PaintDownloadProgress(gfx::Canvas* canvas, void DownloadShelf::PaintDownloadProgress(
#if defined(TOOLKIT_VIEWS) gfx::Canvas* canvas,
views::View* containing_view, const BoundsAdjusterCallback& rtl_mirror,
#endif int origin_x,
int origin_x, int origin_y,
int origin_y, int start_angle,
int start_angle, int percent_done,
int percent_done, PaintDownloadProgressSize size) {
PaintDownloadProgressSize size) {
// Load up our common images. // Load up our common images.
if (!g_background_16) { if (!g_background_16) {
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
...@@ -189,11 +184,8 @@ void DownloadShelf::PaintDownloadProgress(gfx::Canvas* canvas, ...@@ -189,11 +184,8 @@ void DownloadShelf::PaintDownloadProgress(gfx::Canvas* canvas,
gfx::Rect bounds(origin_x, origin_y, gfx::Rect bounds(origin_x, origin_y,
background->width(), background->height()); background->width(), background->height());
#if defined(TOOLKIT_VIEWS)
// Mirror the positions if necessary. // Mirror the positions if necessary.
int mirrored_x = containing_view->GetMirroredXForRect(bounds); rtl_mirror.Run(&bounds);
bounds.set_x(mirrored_x);
#endif
// Draw the background progress image. // Draw the background progress image.
canvas->DrawImageInt(*background, canvas->DrawImageInt(*background,
...@@ -210,14 +202,13 @@ void DownloadShelf::PaintDownloadProgress(gfx::Canvas* canvas, ...@@ -210,14 +202,13 @@ void DownloadShelf::PaintDownloadProgress(gfx::Canvas* canvas,
} }
// static // static
void DownloadShelf::PaintDownloadComplete(gfx::Canvas* canvas, void DownloadShelf::PaintDownloadComplete(
#if defined(TOOLKIT_VIEWS) gfx::Canvas* canvas,
views::View* containing_view, const BoundsAdjusterCallback& rtl_mirror,
#endif int origin_x,
int origin_x, int origin_y,
int origin_y, double animation_progress,
double animation_progress, PaintDownloadProgressSize size) {
PaintDownloadProgressSize size) {
// Load up our common images. // Load up our common images.
if (!g_foreground_16) { if (!g_foreground_16) {
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
...@@ -229,10 +220,8 @@ void DownloadShelf::PaintDownloadComplete(gfx::Canvas* canvas, ...@@ -229,10 +220,8 @@ void DownloadShelf::PaintDownloadComplete(gfx::Canvas* canvas,
gfx::Rect complete_bounds(origin_x, origin_y, gfx::Rect complete_bounds(origin_x, origin_y,
complete->width(), complete->height()); complete->width(), complete->height());
#if defined(TOOLKIT_VIEWS)
// Mirror the positions if necessary. // Mirror the positions if necessary.
complete_bounds.set_x(containing_view->GetMirroredXForRect(complete_bounds)); rtl_mirror.Run(&complete_bounds);
#endif
// Start at full opacity, then loop back and forth five times before ending // Start at full opacity, then loop back and forth five times before ending
// at zero opacity. // at zero opacity.
...@@ -241,14 +230,13 @@ void DownloadShelf::PaintDownloadComplete(gfx::Canvas* canvas, ...@@ -241,14 +230,13 @@ void DownloadShelf::PaintDownloadComplete(gfx::Canvas* canvas,
} }
// static // static
void DownloadShelf::PaintDownloadInterrupted(gfx::Canvas* canvas, void DownloadShelf::PaintDownloadInterrupted(
#if defined(TOOLKIT_VIEWS) gfx::Canvas* canvas,
views::View* containing_view, const BoundsAdjusterCallback& rtl_mirror,
#endif int origin_x,
int origin_x, int origin_y,
int origin_y, double animation_progress,
double animation_progress, PaintDownloadProgressSize size) {
PaintDownloadProgressSize size) {
// Load up our common images. // Load up our common images.
if (!g_foreground_16) { if (!g_foreground_16) {
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
...@@ -260,10 +248,8 @@ void DownloadShelf::PaintDownloadInterrupted(gfx::Canvas* canvas, ...@@ -260,10 +248,8 @@ void DownloadShelf::PaintDownloadInterrupted(gfx::Canvas* canvas,
gfx::Rect complete_bounds(origin_x, origin_y, gfx::Rect complete_bounds(origin_x, origin_y,
complete->width(), complete->height()); complete->width(), complete->height());
#if defined(TOOLKIT_VIEWS)
// Mirror the positions if necessary. // Mirror the positions if necessary.
complete_bounds.set_x(containing_view->GetMirroredXForRect(complete_bounds)); rtl_mirror.Run(&complete_bounds);
#endif
// Start at zero opacity, then loop back and forth five times before ending // Start at zero opacity, then loop back and forth five times before ending
// at full opacity. // at full opacity.
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_SHELF_H_ #ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_SHELF_H_
#define 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/memory/weak_ptr.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "build/build_config.h" #include "build/build_config.h"
...@@ -22,12 +23,6 @@ class DownloadItem; ...@@ -22,12 +23,6 @@ class DownloadItem;
class DownloadManager; class DownloadManager;
} }
#if defined(TOOLKIT_VIEWS)
namespace views {
class View;
}
#endif
// This is an abstract base class for platform specific download shelf // This is an abstract base class for platform specific download shelf
// implementations. // implementations.
class DownloadShelf { class DownloadShelf {
...@@ -78,6 +73,14 @@ class DownloadShelf { ...@@ -78,6 +73,14 @@ class DownloadShelf {
kSmallProgressIconOffset = (kSmallProgressIconSize - kSmallIconSize) / 2 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(); DownloadShelf();
virtual ~DownloadShelf(); virtual ~DownloadShelf();
...@@ -92,12 +95,6 @@ class DownloadShelf { ...@@ -92,12 +95,6 @@ class DownloadShelf {
// Paint the common download animation progress foreground and background, // Paint the common download animation progress foreground and background,
// clipping the foreground to 'percent' full. If percent is -1, then we don't // 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. // 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( static void PaintCustomDownloadProgress(
gfx::Canvas* canvas, gfx::Canvas* canvas,
const gfx::ImageSkia& background_image, const gfx::ImageSkia& background_image,
...@@ -108,9 +105,7 @@ class DownloadShelf { ...@@ -108,9 +105,7 @@ class DownloadShelf {
int percent_done); int percent_done);
static void PaintDownloadProgress(gfx::Canvas* canvas, static void PaintDownloadProgress(gfx::Canvas* canvas,
#if defined(TOOLKIT_VIEWS) const BoundsAdjusterCallback& rtl_mirror,
views::View* containing_view,
#endif
int origin_x, int origin_x,
int origin_y, int origin_y,
int start_angle, int start_angle,
...@@ -118,18 +113,14 @@ class DownloadShelf { ...@@ -118,18 +113,14 @@ class DownloadShelf {
PaintDownloadProgressSize size); PaintDownloadProgressSize size);
static void PaintDownloadComplete(gfx::Canvas* canvas, static void PaintDownloadComplete(gfx::Canvas* canvas,
#if defined(TOOLKIT_VIEWS) const BoundsAdjusterCallback& rtl_mirror,
views::View* containing_view,
#endif
int origin_x, int origin_x,
int origin_y, int origin_y,
double animation_progress, double animation_progress,
PaintDownloadProgressSize size); PaintDownloadProgressSize size);
static void PaintDownloadInterrupted(gfx::Canvas* canvas, static void PaintDownloadInterrupted(gfx::Canvas* canvas,
#if defined(TOOLKIT_VIEWS) const BoundsAdjusterCallback& rtl_mirror,
views::View* containing_view,
#endif
int origin_x, int origin_x,
int origin_y, int origin_y,
double animation_progress, double animation_progress,
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#import "chrome/browser/ui/cocoa/download/download_item_cell.h" #import "chrome/browser/ui/cocoa/download/download_item_cell.h"
#include "base/bind.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#include "chrome/browser/download/download_item_model.h" #include "chrome/browser/download/download_item_model.h"
#include "chrome/browser/download/download_shelf.h" #include "chrome/browser/download/download_shelf.h"
...@@ -76,6 +77,16 @@ const CGFloat kInterruptedAnimationDuration = 2.5; ...@@ -76,6 +77,16 @@ const CGFloat kInterruptedAnimationDuration = 2.5;
using content::DownloadItem; using content::DownloadItem;
namespace {
// Passed as a callback to DownloadShelf paint functions. On toolkit-views
// platforms it will mirror the position of the download progress, but that's
// not done on Mac.
void DummyRTLMirror(gfx::Rect* bounds) {
}
} // namespace
// This is a helper class to animate the fading out of the status text. // This is a helper class to animate the fading out of the status text.
@interface DownloadItemCellAnimation : NSAnimation { @interface DownloadItemCellAnimation : NSAnimation {
@private @private
...@@ -557,6 +568,7 @@ using content::DownloadItem; ...@@ -557,6 +568,7 @@ using content::DownloadItem;
if (percentDone_ == -1) { if (percentDone_ == -1) {
DownloadShelf::PaintDownloadComplete( DownloadShelf::PaintDownloadComplete(
&canvas, &canvas,
base::Bind(&DummyRTLMirror),
x, x,
y, y,
[completionAnimation_ currentValue], [completionAnimation_ currentValue],
...@@ -564,6 +576,7 @@ using content::DownloadItem; ...@@ -564,6 +576,7 @@ using content::DownloadItem;
} else { } else {
DownloadShelf::PaintDownloadInterrupted( DownloadShelf::PaintDownloadInterrupted(
&canvas, &canvas,
base::Bind(&DummyRTLMirror),
x, x,
y, y,
[completionAnimation_ currentValue], [completionAnimation_ currentValue],
...@@ -572,6 +585,7 @@ using content::DownloadItem; ...@@ -572,6 +585,7 @@ using content::DownloadItem;
} }
} else if (percentDone_ >= 0 || indeterminateProgressTimer_) { } else if (percentDone_ >= 0 || indeterminateProgressTimer_) {
DownloadShelf::PaintDownloadProgress(&canvas, DownloadShelf::PaintDownloadProgress(&canvas,
base::Bind(&DummyRTLMirror),
x, x,
y, y,
indeterminateProgressAngle_, indeterminateProgressAngle_,
......
...@@ -53,6 +53,8 @@ ...@@ -53,6 +53,8 @@
#include "ui/views/widget/root_view.h" #include "ui/views/widget/root_view.h"
#include "ui/views/widget/widget.h" #include "ui/views/widget/widget.h"
using content::DownloadItem;
// TODO(paulg): These may need to be adjusted when download progress // TODO(paulg): These may need to be adjusted when download progress
// animation is added, and also possibly to take into account // animation is added, and also possibly to take into account
// different screen resolutions. // different screen resolutions.
...@@ -90,7 +92,15 @@ static const int kDisabledOnOpenDuration = 3000; ...@@ -90,7 +92,15 @@ static const int kDisabledOnOpenDuration = 3000;
// light-on-dark themes. // light-on-dark themes.
static const double kDownloadItemLuminanceMod = 0.8; static const double kDownloadItemLuminanceMod = 0.8;
using content::DownloadItem; namespace {
// Callback for DownloadShelf paint functions to mirror the progress animation
// in RTL locales.
void RTLMirrorXForView(views::View* containing_view, gfx::Rect* bounds) {
bounds->set_x(containing_view->GetMirroredXForRect(*bounds));
}
} // namespace
DownloadItemView::DownloadItemView(DownloadItem* download_item, DownloadItemView::DownloadItemView(DownloadItem* download_item,
DownloadShelfView* parent) DownloadShelfView* parent)
...@@ -834,9 +844,11 @@ void DownloadItemView::OnPaintBackground(gfx::Canvas* canvas) { ...@@ -834,9 +844,11 @@ void DownloadItemView::OnPaintBackground(gfx::Canvas* canvas) {
if (icon) { if (icon) {
if (!IsShowingWarningDialog()) { if (!IsShowingWarningDialog()) {
DownloadItem::DownloadState state = download()->GetState(); DownloadItem::DownloadState state = download()->GetState();
DownloadShelf::BoundsAdjusterCallback rtl_mirror =
base::Bind(&RTLMirrorXForView, base::Unretained(this));
if (state == DownloadItem::IN_PROGRESS) { if (state == DownloadItem::IN_PROGRESS) {
DownloadShelf::PaintDownloadProgress(canvas, DownloadShelf::PaintDownloadProgress(canvas,
this, rtl_mirror,
0, 0,
0, 0,
progress_angle_, progress_angle_,
...@@ -847,7 +859,7 @@ void DownloadItemView::OnPaintBackground(gfx::Canvas* canvas) { ...@@ -847,7 +859,7 @@ void DownloadItemView::OnPaintBackground(gfx::Canvas* canvas) {
if (state == DownloadItem::INTERRUPTED) { if (state == DownloadItem::INTERRUPTED) {
DownloadShelf::PaintDownloadInterrupted( DownloadShelf::PaintDownloadInterrupted(
canvas, canvas,
this, rtl_mirror,
0, 0,
0, 0,
complete_animation_->GetCurrentValue(), complete_animation_->GetCurrentValue(),
...@@ -856,7 +868,7 @@ void DownloadItemView::OnPaintBackground(gfx::Canvas* canvas) { ...@@ -856,7 +868,7 @@ void DownloadItemView::OnPaintBackground(gfx::Canvas* canvas) {
DCHECK_EQ(DownloadItem::COMPLETE, state); DCHECK_EQ(DownloadItem::COMPLETE, state);
DownloadShelf::PaintDownloadComplete( DownloadShelf::PaintDownloadComplete(
canvas, canvas,
this, rtl_mirror,
0, 0,
0, 0,
complete_animation_->GetCurrentValue(), complete_animation_->GetCurrentValue(),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment