This source file includes following definitions.
- popup_
- Reposition
- Close
- AnimateToState
- Show
#include "chrome/browser/download/download_started_animation.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_view.h"
#include "grit/theme_resources.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/animation/linear_animation.h"
#include "ui/gfx/rect.h"
#include "ui/views/controls/image_view.h"
#include "ui/views/widget/widget.h"
const int kMoveTimeMs = 600;
const int kFrameRateHz = 60;
namespace {
class DownloadStartedAnimationViews : public gfx::LinearAnimation,
public views::ImageView {
public:
explicit DownloadStartedAnimationViews(content::WebContents* web_contents);
private:
void Reposition();
void Close();
virtual void AnimateToState(double state) OVERRIDE;
views::Widget* popup_;
gfx::Rect web_contents_bounds_;
DISALLOW_COPY_AND_ASSIGN(DownloadStartedAnimationViews);
};
DownloadStartedAnimationViews::DownloadStartedAnimationViews(
content::WebContents* web_contents)
: gfx::LinearAnimation(kMoveTimeMs, kFrameRateHz, NULL),
popup_(NULL) {
static gfx::ImageSkia* kDownloadImage = NULL;
if (!kDownloadImage) {
kDownloadImage = ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
IDR_DOWNLOAD_ANIMATION_BEGIN);
}
web_contents->GetView()->GetContainerBounds(&web_contents_bounds_);
if (web_contents_bounds_.height() < kDownloadImage->height())
return;
SetImage(kDownloadImage);
popup_ = new views::Widget;
views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP);
params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
params.accept_events = false;
params.parent = web_contents->GetView()->GetNativeView();
popup_->Init(params);
popup_->SetOpacity(0x00);
popup_->SetContentsView(this);
Reposition();
popup_->Show();
Start();
}
void DownloadStartedAnimationViews::Reposition() {
gfx::Size size = GetPreferredSize();
int x = base::i18n::IsRTL() ?
web_contents_bounds_.right() - size.width() : web_contents_bounds_.x();
popup_->SetBounds(gfx::Rect(
x,
static_cast<int>(web_contents_bounds_.bottom() -
size.height() - size.height() * (1 - GetCurrentValue())),
size.width(),
size.height()));
}
void DownloadStartedAnimationViews::Close() {
popup_->Close();
}
void DownloadStartedAnimationViews::AnimateToState(double state) {
if (state >= 1.0) {
Close();
} else {
Reposition();
double opacity = std::min(1.0 - pow(GetCurrentValue() - 0.5, 2) * 4.0,
static_cast<double>(1.0));
popup_->SetOpacity(static_cast<unsigned char>(opacity * 255.0));
}
}
}
void DownloadStartedAnimation::Show(content::WebContents* web_contents) {
new DownloadStartedAnimationViews(web_contents);
}