Skip to content

Commit cf72dc9

Browse files
author
Anders Carlsson
committed
2011-04-15 Anders Carlsson <andersca@apple.com>
Reviewed by Sam Weinig. Add the ability for PageOverlays to fade in and out https://bugs.webkit.org/show_bug.cgi?id=58694 * WebProcess/InjectedBundle/API/c/WKBundlePage.cpp: (WKBundlePageUninstallPageOverlay): WebPage::uninstallPageOverlay now takes a boolean. Default to false for now. * WebProcess/WebPage/FindController.cpp: (WebKit::FindController::findString): Pass false to uninstallPageOverlay. (WebKit::FindController::hideFindUI): Pass true to uninstallPageOverlay. * WebProcess/WebPage/PageOverlay.cpp: (WebKit::PageOverlay::PageOverlay): Initialize new member variables. (WebKit::PageOverlay::bounds): Get rid of an unnecessary webPage() getter. (WebKit::PageOverlay::setPage): Stop the animation timer. (WebKit::PageOverlay::startFadeInAnimation): Update m_fractionFadedIn and call startFadeAnimation. (WebKit::PageOverlay::startFadeOutAnimation): Ditto. (WebKit::PageOverlay::startFadeAnimation): Initialize m_fadeAnimationStartTime and start the fade animation timer. (WebKit::PageOverlay::fadeAnimationTimerFired): Update m_fractionFadedIn and call setNeedsDisplay(). * WebProcess/WebPage/PageOverlay.h: * WebProcess/WebPage/WebPage.cpp: (WebKit::WebPage::uninstallPageOverlay): If fadeOut is true, tell the page overlay to start the fade out animation. When the fade animation is complete, the page overlay will uninstall itself. Canonical link: https://commits.webkit.org/73776@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@84034 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent cc2215c commit cf72dc9

7 files changed

Lines changed: 143 additions & 12 deletions

File tree

Source/WebKit2/ChangeLog

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,49 @@
1+
2011-04-15 Anders Carlsson <andersca@apple.com>
2+
3+
Reviewed by Sam Weinig.
4+
5+
Add the ability for PageOverlays to fade in and out
6+
https://bugs.webkit.org/show_bug.cgi?id=58694
7+
8+
* WebProcess/InjectedBundle/API/c/WKBundlePage.cpp:
9+
(WKBundlePageUninstallPageOverlay):
10+
WebPage::uninstallPageOverlay now takes a boolean. Default to false for now.
11+
12+
* WebProcess/WebPage/FindController.cpp:
13+
(WebKit::FindController::findString):
14+
Pass false to uninstallPageOverlay.
15+
16+
(WebKit::FindController::hideFindUI):
17+
Pass true to uninstallPageOverlay.
18+
19+
* WebProcess/WebPage/PageOverlay.cpp:
20+
(WebKit::PageOverlay::PageOverlay):
21+
Initialize new member variables.
22+
23+
(WebKit::PageOverlay::bounds):
24+
Get rid of an unnecessary webPage() getter.
25+
26+
(WebKit::PageOverlay::setPage):
27+
Stop the animation timer.
28+
29+
(WebKit::PageOverlay::startFadeInAnimation):
30+
Update m_fractionFadedIn and call startFadeAnimation.
31+
32+
(WebKit::PageOverlay::startFadeOutAnimation):
33+
Ditto.
34+
35+
(WebKit::PageOverlay::startFadeAnimation):
36+
Initialize m_fadeAnimationStartTime and start the fade animation timer.
37+
38+
(WebKit::PageOverlay::fadeAnimationTimerFired):
39+
Update m_fractionFadedIn and call setNeedsDisplay().
40+
41+
* WebProcess/WebPage/PageOverlay.h:
42+
* WebProcess/WebPage/WebPage.cpp:
43+
(WebKit::WebPage::uninstallPageOverlay):
44+
If fadeOut is true, tell the page overlay to start the fade out animation.
45+
When the fade animation is complete, the page overlay will uninstall itself.
46+
147
2011-04-15 Brian Weinstein <bweinstein@apple.com>
248

349
Reviewed by Adam Roben.

Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundlePage.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ void WKBundlePageInstallPageOverlay(WKBundlePageRef pageRef, WKBundlePageOverlay
175175

176176
void WKBundlePageUninstallPageOverlay(WKBundlePageRef pageRef, WKBundlePageOverlayRef pageOverlayRef)
177177
{
178-
toImpl(pageRef)->uninstallPageOverlay(toImpl(pageOverlayRef));
178+
toImpl(pageRef)->uninstallPageOverlay(toImpl(pageOverlayRef), false);
179179
}
180180

181181
bool WKBundlePageHasLocalDataForURL(WKBundlePageRef pageRef, WKURLRef urlRef)

Source/WebKit2/WebProcess/WebPage/FindController.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ void FindController::findString(const String& string, FindOptions options, unsig
133133
if (!shouldShowOverlay) {
134134
if (m_findPageOverlay) {
135135
// Get rid of the overlay.
136-
m_webPage->uninstallPageOverlay(m_findPageOverlay);
136+
m_webPage->uninstallPageOverlay(m_findPageOverlay, false);
137137
}
138138

139139
ASSERT(!m_findPageOverlay);
@@ -153,7 +153,7 @@ void FindController::findString(const String& string, FindOptions options, unsig
153153
void FindController::hideFindUI()
154154
{
155155
if (m_findPageOverlay)
156-
m_webPage->uninstallPageOverlay(m_findPageOverlay);
156+
m_webPage->uninstallPageOverlay(m_findPageOverlay, true);
157157

158158
hideFindIndicator();
159159
}

Source/WebKit2/WebProcess/WebPage/PageOverlay.cpp

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "PageOverlay.h"
2828

2929
#include "WebPage.h"
30+
#include "WebProcess.h"
3031
#include <WebCore/Frame.h>
3132
#include <WebCore/FrameView.h>
3233
#include <WebCore/GraphicsContext.h>
@@ -37,6 +38,9 @@ using namespace WebCore;
3738

3839
namespace WebKit {
3940

41+
static const double fadeAnimationDuration = 0.2;
42+
static const double fadeAnimationFrameRate = 30;
43+
4044
PassRefPtr<PageOverlay> PageOverlay::create(Client* client)
4145
{
4246
return adoptRef(new PageOverlay(client));
@@ -45,6 +49,11 @@ PassRefPtr<PageOverlay> PageOverlay::create(Client* client)
4549
PageOverlay::PageOverlay(Client* client)
4650
: m_client(client)
4751
, m_webPage(0)
52+
, m_fadeAnimationTimer(WebProcess::shared().runLoop(), this, &PageOverlay::fadeAnimationTimerFired)
53+
, m_fadeAnimationStartTime(0.0)
54+
, m_fadeAnimationDuration(fadeAnimationDuration)
55+
, m_fadeAnimationType(NoAnimation)
56+
, m_fractionFadedIn(1.0)
4857
{
4958
}
5059

@@ -54,7 +63,7 @@ PageOverlay::~PageOverlay()
5463

5564
IntRect PageOverlay::bounds() const
5665
{
57-
FrameView* frameView = webPage()->corePage()->mainFrame()->view();
66+
FrameView* frameView = m_webPage->corePage()->mainFrame()->view();
5867

5968
int width = frameView->width();
6069
int height = frameView->height();
@@ -73,6 +82,11 @@ void PageOverlay::setPage(WebPage* webPage)
7382
m_client->willMoveToWebPage(this, webPage);
7483
m_webPage = webPage;
7584
m_client->didMoveToWebPage(this, webPage);
85+
86+
if (m_webPage)
87+
setNeedsDisplay();
88+
89+
m_fadeAnimationTimer.stop();
7690
}
7791

7892
void PageOverlay::setNeedsDisplay(const IntRect& dirtyRect)
@@ -112,4 +126,54 @@ bool PageOverlay::mouseEvent(const WebMouseEvent& mouseEvent)
112126
return m_client->mouseEvent(this, mouseEvent);
113127
}
114128

129+
void PageOverlay::startFadeInAnimation()
130+
{
131+
m_fractionFadedIn = 0.0;
132+
m_fadeAnimationType = FadeInAnimation;
133+
134+
startFadeAnimation();
135+
}
136+
137+
void PageOverlay::startFadeOutAnimation()
138+
{
139+
m_fractionFadedIn = 1.0;
140+
m_fadeAnimationType = FadeOutAnimation;
141+
142+
startFadeAnimation();
143+
}
144+
145+
void PageOverlay::startFadeAnimation()
146+
{
147+
m_fadeAnimationStartTime = currentTime();
148+
149+
// Start the timer
150+
m_fadeAnimationTimer.startRepeating(1 / fadeAnimationFrameRate);
151+
}
152+
153+
void PageOverlay::fadeAnimationTimerFired()
154+
{
155+
float animationProgress = (currentTime() - m_fadeAnimationStartTime) / m_fadeAnimationDuration;
156+
157+
if (animationProgress >= 1.0)
158+
animationProgress = 1.0;
159+
160+
double sine = sin(M_PI_2 * animationProgress);
161+
float fadeAnimationValue = sine * sine;
162+
163+
m_fractionFadedIn = (m_fadeAnimationType == FadeInAnimation) ? fadeAnimationValue : 1 - fadeAnimationValue;
164+
setNeedsDisplay();
165+
166+
if (animationProgress == 1.0) {
167+
m_fadeAnimationTimer.stop();
168+
169+
bool wasFadingOut = m_fadeAnimationType == FadeOutAnimation;
170+
m_fadeAnimationType = NoAnimation;
171+
172+
if (wasFadingOut) {
173+
// If this was a fade out, go ahead and uninstall the page overlay.
174+
m_webPage->uninstallPageOverlay(this, false);
175+
}
176+
}
177+
}
178+
115179
} // namespace WebKit

Source/WebKit2/WebProcess/WebPage/PageOverlay.h

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#define PageOverlay_h
2828

2929
#include "APIObject.h"
30+
#include "RunLoop.h"
3031
#include <wtf/PassRefPtr.h>
3132

3233
namespace WebCore {
@@ -65,20 +66,38 @@ class PageOverlay : public APIObject {
6566
void drawRect(WebCore::GraphicsContext&, const WebCore::IntRect& dirtyRect);
6667
bool mouseEvent(const WebMouseEvent&);
6768

69+
void startFadeInAnimation();
70+
void startFadeOutAnimation();
71+
72+
float fractionFadedIn() const { return m_fractionFadedIn; }
73+
6874
protected:
6975
explicit PageOverlay(Client*);
7076

71-
WebPage* webPage() const { return m_webPage; }
72-
7377
private:
7478
// APIObject
7579
virtual Type type() const { return APIType; }
7680

7781
WebCore::IntRect bounds() const;
7882

79-
Client* m_client;
83+
void startFadeAnimation();
84+
void fadeAnimationTimerFired();
8085

86+
Client* m_client;
8187
WebPage* m_webPage;
88+
89+
RunLoop::Timer<PageOverlay> m_fadeAnimationTimer;
90+
double m_fadeAnimationStartTime;
91+
double m_fadeAnimationDuration;
92+
93+
enum FadeAnimationType {
94+
NoAnimation,
95+
FadeInAnimation,
96+
FadeOutAnimation,
97+
};
98+
99+
FadeAnimationType m_fadeAnimationType;
100+
float m_fractionFadedIn;
82101
};
83102

84103
} // namespace WebKit

Source/WebKit2/WebProcess/WebPage/WebPage.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -729,17 +729,19 @@ void WebPage::installPageOverlay(PassRefPtr<PageOverlay> pageOverlay)
729729

730730
m_pageOverlay = pageOverlay;
731731
m_pageOverlay->setPage(this);
732-
733732
m_drawingArea->didInstallPageOverlay();
734-
735-
m_pageOverlay->setNeedsDisplay();
736733
}
737734

738-
void WebPage::uninstallPageOverlay(PageOverlay* pageOverlay)
735+
void WebPage::uninstallPageOverlay(PageOverlay* pageOverlay, bool fadeOut)
739736
{
740737
if (pageOverlay != m_pageOverlay)
741738
return;
742739

740+
if (fadeOut) {
741+
m_pageOverlay->startFadeOutAnimation();
742+
return;
743+
}
744+
743745
m_pageOverlay->setPage(0);
744746
m_pageOverlay = nullptr;
745747

Source/WebKit2/WebProcess/WebPage/WebPage.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ class WebPage : public APIObject, public CoreIPC::MessageSender<WebPage> {
252252

253253
bool windowIsFocused() const;
254254
void installPageOverlay(PassRefPtr<PageOverlay>);
255-
void uninstallPageOverlay(PageOverlay*);
255+
void uninstallPageOverlay(PageOverlay*, bool fadeOut);
256256
bool hasPageOverlay() const { return m_pageOverlay; }
257257
WebCore::IntRect windowToScreen(const WebCore::IntRect&);
258258

0 commit comments

Comments
 (0)