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.
6 #include "core/page/PageAnimator.h"
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"
18 PageAnimator::PageAnimator(Page* page)
20 , m_animationFramePending(false)
21 , m_servicingAnimations(false)
22 , m_updatingLayoutAndStyleForPainting(false)
26 void PageAnimator::serviceScriptedAnimations(double monotonicAnimationStartTime)
28 m_animationFramePending = false;
29 TemporaryChange<bool> servicing(m_servicingAnimations, true);
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());
37 for (size_t i = 0; i < documents.size(); ++i) {
38 if (documents[i]->frame())
39 documents[i]->view()->serviceScrollAnimations(monotonicAnimationStartTime);
42 for (size_t i = 0; i < documents.size(); ++i) {
43 DocumentAnimations::updateAnimationTimingForAnimationFrame(*documents[i], monotonicAnimationStartTime);
44 SVGDocumentExtensions::serviceOnAnimationFrame(*documents[i], monotonicAnimationStartTime);
47 for (size_t i = 0; i < documents.size(); ++i)
48 documents[i]->serviceScriptedAnimations(monotonicAnimationStartTime);
51 void PageAnimator::scheduleVisualUpdate()
53 // FIXME: also include m_animationFramePending here. It is currently not there due to crbug.com/353756.
54 if (m_servicingAnimations || m_updatingLayoutAndStyleForPainting)
56 m_page->chrome().scheduleAnimation();
59 void PageAnimator::updateLayoutAndStyleForPainting(LocalFrame* rootFrame)
61 RefPtr<FrameView> view = rootFrame->view();
63 TemporaryChange<bool> servicing(m_updatingLayoutAndStyleForPainting, true);
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());
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();