Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / page / PageAnimator.cpp
1 // Copyright 2014 The Chromium Authors. 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.
4
5 #include "config.h"
6 #include "core/page/PageAnimator.h"
7
8 #include "core/animation/DocumentAnimations.h"
9 #include "core/frame/FrameView.h"
10 #include "core/frame/LocalFrame.h"
11 #include "core/page/Chrome.h"
12 #include "core/page/ChromeClient.h"
13 #include "core/page/Page.h"
14 #include "core/svg/SVGDocumentExtensions.h"
15
16 namespace blink {
17
18 PageAnimator::PageAnimator(Page* page)
19     : m_page(page)
20     , m_animationFramePending(false)
21     , m_servicingAnimations(false)
22     , m_updatingLayoutAndStyleForPainting(false)
23 {
24 }
25
26 void PageAnimator::serviceScriptedAnimations(double monotonicAnimationStartTime)
27 {
28     m_animationFramePending = false;
29     TemporaryChange<bool> servicing(m_servicingAnimations, true);
30
31     WillBeHeapVector<RefPtrWillBeMember<Document> > documents;
32     for (Frame* frame = m_page->mainFrame(); frame; frame = frame->tree().traverseNext()) {
33         if (frame->isLocalFrame())
34             documents.append(toLocalFrame(frame)->document());
35     }
36
37     for (size_t i = 0; i < documents.size(); ++i) {
38         if (documents[i]->frame())
39             documents[i]->view()->serviceScrollAnimations(monotonicAnimationStartTime);
40     }
41
42     for (size_t i = 0; i < documents.size(); ++i) {
43         DocumentAnimations::updateAnimationTimingForAnimationFrame(*documents[i], monotonicAnimationStartTime);
44         SVGDocumentExtensions::serviceOnAnimationFrame(*documents[i], monotonicAnimationStartTime);
45     }
46
47     for (size_t i = 0; i < documents.size(); ++i)
48         documents[i]->serviceScriptedAnimations(monotonicAnimationStartTime);
49 }
50
51 void PageAnimator::scheduleVisualUpdate()
52 {
53     // FIXME: also include m_animationFramePending here. It is currently not there due to crbug.com/353756.
54     if (m_servicingAnimations || m_updatingLayoutAndStyleForPainting)
55         return;
56     m_page->chrome().scheduleAnimation();
57 }
58
59 void PageAnimator::updateLayoutAndStyleForPainting(LocalFrame* rootFrame)
60 {
61     RefPtr<FrameView> view = rootFrame->view();
62
63     TemporaryChange<bool> servicing(m_updatingLayoutAndStyleForPainting, true);
64
65     // In order for our child HWNDs (NativeWindowWidgets) to update properly,
66     // they need to be told that we are updating the screen. The problem is that
67     // the native widgets need to recalculate their clip region and not overlap
68     // any of our non-native widgets. To force the resizing, call
69     // setFrameRect(). This will be a quick operation for most frames, but the
70     // NativeWindowWidgets will update a proper clipping region.
71     view->setFrameRect(view->frameRect());
72
73     // setFrameRect may have the side-effect of causing existing page layout to
74     // be invalidated, so layout needs to be called last.
75     view->updateLayoutAndStyleForPainting();
76 }
77
78 }