Index: chrome/browser/download/download_util.cc |
=================================================================== |
--- chrome/browser/download/download_util.cc (revision 134143) |
+++ chrome/browser/download/download_util.cc (working copy) |
@@ -6,9 +6,8 @@ |
#include "chrome/browser/download/download_util.h" |
-#if defined(OS_WIN) |
-#include <shobjidl.h> |
-#endif |
+#define _USE_MATH_DEFINES // For VC++ to get M_PI |
+#include <cmath> |
#include <string> |
#include "base/file_util.h" |
@@ -24,7 +23,6 @@ |
#include "base/utf_string_conversions.h" |
#include "base/value_conversions.h" |
#include "base/values.h" |
-#include "base/win/windows_version.h" |
Lei Zhang
2012/04/26 22:05:49
I don't know how this even compiled. :)
|
#include "chrome/browser/download/download_extensions.h" |
#include "chrome/browser/download/download_item_model.h" |
#include "chrome/browser/profiles/profile.h" |
@@ -52,6 +50,12 @@ |
#include "ui/gfx/image/image.h" |
#include "ui/gfx/rect.h" |
+#if defined(OS_WIN) |
+#include <shobjidl.h> |
+ |
+#include "base/win/windows_version.h" |
+#endif |
+ |
#if defined(TOOLKIT_VIEWS) |
#include "ui/base/dragdrop/drag_utils.h" |
#include "ui/base/dragdrop/os_exchange_data.h" |
@@ -73,12 +77,6 @@ |
#include "ui/base/dragdrop/os_exchange_data_provider_win.h" |
#endif |
-// TODO(phajdan.jr): Find some standard location for this, maintaining |
-// the same value on all platforms. |
-static const double PI = 3.141592653589793; |
Lei Zhang
2012/04/26 22:05:49
phajdan.jr: M_PI and friends are in cmath / math.h
|
- |
-using content::DownloadItem; |
- |
namespace { |
// Returns a string constant to be used as the |danger_type| value in |
@@ -103,13 +101,22 @@ |
} |
} |
+// Get the opacity based on |animation_progress|. |
asanka
2012/04/27 15:53:45
Nit: mention |animation_progress| is in [0.0,1.0]
Lei Zhang
2012/04/27 18:59:48
Done.
|
+// Range of return value is [0, 255]. |
+int GetOpacity(double animation_progress) { |
+ // How many times to cycle the complete animation. This should be an odd |
+ // number so that the animation ends faded out. |
+ static const int kCompleteAnimationCycles = 5; |
+ double temp = animation_progress * kCompleteAnimationCycles * M_PI + M_PI_2; |
+ temp = sin(temp) / 2 + 0.5; |
+ return static_cast<int>(255.0 * temp); |
+} |
+ |
} // namespace |
namespace download_util { |
-// How many times to cycle the complete animation. This should be an odd number |
-// so that the animation ends faded out. |
-static const int kCompleteAnimationCycles = 5; |
+using content::DownloadItem; |
// Download temporary file creation -------------------------------------------- |
@@ -122,6 +129,8 @@ |
NOTREACHED(); |
} |
if (DownloadPathIsDangerous(path_)) { |
+ // This is only useful on platforms that support |
+ // DIR_DEFAULT_DOWNLOADS_SAFE. |
if (!PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS_SAFE, &path_)) { |
NOTREACHED(); |
} |
@@ -138,7 +147,16 @@ |
return g_default_download_directory.Get().path(); |
} |
+// Consider downloads 'dangerous' if they go to the home directory on Linux and |
+// to the desktop on any platform. |
bool DownloadPathIsDangerous(const FilePath& download_path) { |
+#if defined(OS_LINUX) |
+ FilePath home_dir = file_util::GetHomeDir(); |
+ if (download_path == home_dir) { |
+ return true; |
+ } |
+#endif |
+ |
FilePath desktop_dir; |
if (!PathService::Get(chrome::DIR_USER_DESKTOP, &desktop_dir)) { |
NOTREACHED(); |
@@ -295,10 +313,7 @@ |
// Start at full opacity, then loop back and forth five times before ending |
// at zero opacity. |
- double opacity = sin(animation_progress * PI * kCompleteAnimationCycles + |
- PI/2) / 2 + 0.5; |
- |
- canvas->SaveLayerAlpha(static_cast<int>(255.0 * opacity), complete_bounds); |
+ canvas->SaveLayerAlpha(GetOpacity(animation_progress), complete_bounds); |
canvas->sk_canvas()->drawARGB(0, 255, 255, 255, SkXfermode::kClear_Mode); |
canvas->DrawBitmapInt(*complete, complete_bounds.x(), complete_bounds.y()); |
canvas->Restore(); |
@@ -330,11 +345,7 @@ |
// Start at zero opacity, then loop back and forth five times before ending |
// at full opacity. |
- double opacity = sin( |
- (1.0 - animation_progress) * PI * kCompleteAnimationCycles + PI/2) / 2 + |
- 0.5; |
- |
- canvas->SaveLayerAlpha(static_cast<int>(255.0 * opacity), complete_bounds); |
+ canvas->SaveLayerAlpha(GetOpacity(1.0 - animation_progress), complete_bounds); |
canvas->sk_canvas()->drawARGB(0, 255, 255, 255, SkXfermode::kClear_Mode); |
canvas->DrawBitmapInt(*complete, complete_bounds.x(), complete_bounds.y()); |
canvas->Restore(); |
@@ -397,7 +408,7 @@ |
// we pass NULL to RunShellDrag for the source view. |
widget->RunShellDrag(NULL, data, location, |
ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_LINK); |
-#else // We are on WIN without AURA |
+#else // We are on WIN without AURA |
// We cannot use Widget::RunShellDrag on WIN since the |view| is backed by a |
// TabContentsViewWin, not a NativeWidgetWin. |
scoped_refptr<ui::DragSource> drag_source(new ui::DragSource); |