2 * Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies)
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public License
15 * along with this program; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
22 #include "TapHighlightController.h"
24 #if ENABLE(TOUCH_EVENTS)
26 #include "ShareableBitmap.h"
28 #include "WebCoreArgumentCoders.h"
30 #include "WebPageProxyMessages.h"
31 #include "WebProcess.h"
32 #include <WebCore/FocusController.h>
33 #include <WebCore/Frame.h>
34 #include <WebCore/FrameView.h>
35 #include <WebCore/GestureTapHighlighter.h>
36 #include <WebCore/GraphicsContext.h>
37 #include <WebCore/Page.h>
39 #include <WebCore/RenderObject.h>
42 using namespace WebCore;
46 TapHighlightController::TapHighlightController(WebPage* webPage)
52 TapHighlightController::~TapHighlightController()
56 void TapHighlightController::highlight(Node* node)
60 m_path = GestureTapHighlighter::pathForNodeHighlight(node);
61 m_color = node->renderer()->style()->tapHighlightColor();
64 RefPtr<PageOverlay> overlay = PageOverlay::create(this);
65 m_overlay = overlay.get();
66 m_webPage->installPageOverlay(overlay.release());
68 m_overlay->setNeedsDisplay();
71 void TapHighlightController::hideHighlight()
74 m_webPage->uninstallPageOverlay(m_overlay, /* fadeout */ true);
77 void TapHighlightController::pageOverlayDestroyed(PageOverlay*)
81 void TapHighlightController::willMoveToWebPage(PageOverlay*, WebPage* webPage)
86 // The page overlay is moving away from the web page, reset it.
91 void TapHighlightController::didMoveToWebPage(PageOverlay*, WebPage*)
95 static Color highlightColor(Color baseColor, float fractionFadedIn)
97 return Color(baseColor.red(), baseColor.green(), baseColor.blue(), int(baseColor.alpha() * fractionFadedIn));
100 void TapHighlightController::drawRect(PageOverlay* pageOverlay, GraphicsContext& context, const IntRect& dirtyRect)
102 if (m_path.isEmpty())
106 GraphicsContextStateSaver stateSaver(context);
107 if (m_webPage->drawingArea()->pageOverlayShouldApplyFadeWhenPainting())
108 context.setFillColor(highlightColor(m_color, pageOverlay->fractionFadedIn()), ColorSpaceSRGB);
110 context.setFillColor(m_color, ColorSpaceSRGB);
111 context.fillPath(m_path);
115 bool TapHighlightController::mouseEvent(PageOverlay*, const WebMouseEvent&)
120 } // namespace WebKit
122 #endif // ENABLE(TOUCH_EVENTS)