1/* 2 * Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies) 3 * 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. 8 * 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. 13 * 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. 18 * 19 */ 20 21#include "config.h" 22#include "TapHighlightController.h" 23 24#if ENABLE(TOUCH_EVENTS) 25 26#include "ShareableBitmap.h" 27#include "WKPage.h" 28#include "WebCoreArgumentCoders.h" 29#include "WebPage.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> 38#include <WebCore/RenderElement.h> 39 40using namespace std; 41using namespace WebCore; 42 43namespace WebKit { 44 45TapHighlightController::TapHighlightController(WebPage* webPage) 46 : m_webPage(webPage) 47 , m_overlay(0) 48{ 49} 50 51TapHighlightController::~TapHighlightController() 52{ 53} 54 55void TapHighlightController::highlight(Node* node) 56{ 57 ASSERT(node); 58 59 m_path = GestureTapHighlighter::pathForNodeHighlight(node); 60 m_color = node->renderer()->style().tapHighlightColor(); 61 62 if (!m_overlay) { 63 RefPtr<PageOverlay> overlay = PageOverlay::create(this); 64 m_overlay = overlay.get(); 65 m_webPage->installPageOverlay(overlay.release()); 66 } else 67 m_overlay->setNeedsDisplay(); 68} 69 70void TapHighlightController::hideHighlight() 71{ 72 if (m_overlay) 73 m_webPage->uninstallPageOverlay(m_overlay, PageOverlay::FadeMode::Fade); 74} 75 76void TapHighlightController::pageOverlayDestroyed(PageOverlay*) 77{ 78} 79 80void TapHighlightController::willMoveToWebPage(PageOverlay*, WebPage* webPage) 81{ 82 if (webPage) 83 return; 84 85 // The page overlay is moving away from the web page, reset it. 86 ASSERT(m_overlay); 87 m_overlay = 0; 88} 89 90void TapHighlightController::didMoveToWebPage(PageOverlay*, WebPage*) 91{ 92} 93 94static Color highlightColor(Color baseColor, float fractionFadedIn) 95{ 96 return Color(baseColor.red(), baseColor.green(), baseColor.blue(), int(baseColor.alpha() * fractionFadedIn)); 97} 98 99void TapHighlightController::drawRect(PageOverlay* /*pageOverlay*/, GraphicsContext& context, const IntRect& /*dirtyRect*/) 100{ 101 if (m_path.isEmpty()) 102 return; 103 104 { 105 GraphicsContextStateSaver stateSaver(context); 106 context.setFillColor(highlightColor(m_color, 0.5f), ColorSpaceSRGB); 107 context.fillPath(m_path); 108 } 109} 110 111bool TapHighlightController::mouseEvent(PageOverlay*, const WebMouseEvent&) 112{ 113 return false; 114} 115 116} // namespace WebKit 117 118#endif // ENABLE(TOUCH_EVENTS) 119