1 // Copyright (c) 2014 Intel Corporation. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "xwalk/runtime/browser/ui/splash_screen_tizen.h"
7 #include "base/location.h"
8 #include "ui/compositor/layer.h"
9 #include "ui/compositor/scoped_layer_animation_settings.h"
10 #include "ui/gfx/canvas.h"
11 #include "ui/gfx/image/image_skia.h"
12 #include "ui/views/widget/widget.h"
13 #include "xwalk/runtime/browser/image_util.h"
18 const int kHideAnimationDuration = 1; // second
21 class SplashScreenTizen::SplashScreenLayerDelegate : public ui::LayerDelegate {
23 SplashScreenLayerDelegate() {}
25 virtual ~SplashScreenLayerDelegate() {}
27 void set_image(const gfx::Image& image) { image_ = image; }
28 const gfx::Image& image() const { return image_; }
30 virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE {
31 if (!image_.IsEmpty()) {
32 canvas->DrawImageInt(image_.AsImageSkia(), 0, 0);
34 LOG(WARNING) << "The splash screen image is not loaded.";
38 virtual void OnDelegatedFrameDamage(
39 const gfx::Rect& damage_rect_in_dip) OVERRIDE {}
41 virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE {}
43 virtual base::Closure PrepareForLayerBoundsChange() OVERRIDE {
44 return base::Closure();
50 DISALLOW_COPY_AND_ASSIGN(SplashScreenLayerDelegate);
53 SplashScreenTizen::SplashScreenTizen(views::Widget* host,
54 const base::FilePath& file,
55 content::WebContents* web_contents)
56 : content::WebContentsObserver(web_contents),
58 splash_screen_image_(file),
59 layer_(new ui::Layer(ui::LAYER_TEXTURED)),
60 layer_delegate_(new SplashScreenLayerDelegate()),
63 layer_->set_delegate(layer_delegate_.get());
66 SplashScreenTizen::~SplashScreenTizen() {}
68 void SplashScreenTizen::Start() {
74 gfx::Image image = xwalk_utils::LoadImageFromFilePath(splash_screen_image_);
75 if (!image.IsEmpty()) {
76 layer_delegate_->set_image(image);
77 ui::Layer* top_layer = widget_host_->GetLayer();
78 gfx::Rect rc = gfx::Rect(widget_host_->GetWindowBoundsInScreen());
79 // The bound of current layer locating at the host window.
80 gfx::Rect layer_bound((rc.width() - image.Width()) / 2,
81 (rc.height() - image.Height()) / 2, image.Width(), image.Height());
82 layer_->SetBounds(layer_bound);
83 top_layer->Add(layer_.get());
84 top_layer->StackAtTop(layer_.get());
88 void SplashScreenTizen::Stop() {
94 ui::ScopedLayerAnimationSettings settings(layer_->GetAnimator());
95 settings.SetTransitionDuration(base::TimeDelta::FromSeconds(
96 kHideAnimationDuration));
97 settings.SetPreemptionStrategy(ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS);
98 settings.AddObserver(this);
99 layer_->SetOpacity(0.0f);
102 void SplashScreenTizen::DidFinishLoad(
103 content::RenderFrameHost* render_frame_host,
104 const GURL& validated_url) {
108 void SplashScreenTizen::DidFailLoad(
109 content::RenderFrameHost* render_frame_host,
110 const GURL& validated_url,
112 const base::string16& error_description) {
116 void SplashScreenTizen::OnImplicitAnimationsCompleted() {
117 DCHECK(widget_host_);
118 widget_host_->GetLayer()->Remove(layer_.get());