TapHighlightController.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. #include "config.h"
  21. #include "TapHighlightController.h"
  22. #if ENABLE(TOUCH_EVENTS)
  23. #include "ShareableBitmap.h"
  24. #include "WKPage.h"
  25. #include "WebCoreArgumentCoders.h"
  26. #include "WebPage.h"
  27. #include "WebPageProxyMessages.h"
  28. #include "WebProcess.h"
  29. #include <WebCore/FocusController.h>
  30. #include <WebCore/Frame.h>
  31. #include <WebCore/FrameView.h>
  32. #include <WebCore/GestureTapHighlighter.h>
  33. #include <WebCore/GraphicsContext.h>
  34. #include <WebCore/Page.h>
  35. #include <WebCore/RenderObject.h>
  36. using namespace std;
  37. using namespace WebCore;
  38. namespace WebKit {
  39. TapHighlightController::TapHighlightController(WebPage* webPage)
  40. : m_webPage(webPage)
  41. , m_overlay(0)
  42. {
  43. }
  44. TapHighlightController::~TapHighlightController()
  45. {
  46. }
  47. void TapHighlightController::highlight(Node* node)
  48. {
  49. ASSERT(node);
  50. m_path = GestureTapHighlighter::pathForNodeHighlight(node);
  51. m_color = node->renderer()->style()->tapHighlightColor();
  52. if (!m_overlay) {
  53. RefPtr<PageOverlay> overlay = PageOverlay::create(this);
  54. m_overlay = overlay.get();
  55. m_webPage->installPageOverlay(overlay.release());
  56. } else
  57. m_overlay->setNeedsDisplay();
  58. }
  59. void TapHighlightController::hideHighlight()
  60. {
  61. if (m_overlay)
  62. m_webPage->uninstallPageOverlay(m_overlay, /* fadeout */ true);
  63. }
  64. void TapHighlightController::pageOverlayDestroyed(PageOverlay*)
  65. {
  66. }
  67. void TapHighlightController::willMoveToWebPage(PageOverlay*, WebPage* webPage)
  68. {
  69. if (webPage)
  70. return;
  71. // The page overlay is moving away from the web page, reset it.
  72. ASSERT(m_overlay);
  73. m_overlay = 0;
  74. }
  75. void TapHighlightController::didMoveToWebPage(PageOverlay*, WebPage*)
  76. {
  77. }
  78. static Color highlightColor(Color baseColor, float fractionFadedIn)
  79. {
  80. return Color(baseColor.red(), baseColor.green(), baseColor.blue(), int(baseColor.alpha() * fractionFadedIn));
  81. }
  82. void TapHighlightController::drawRect(PageOverlay* pageOverlay, GraphicsContext& context, const IntRect& /*dirtyRect*/)
  83. {
  84. if (m_path.isEmpty())
  85. return;
  86. {
  87. GraphicsContextStateSaver stateSaver(context);
  88. if (m_webPage->drawingArea()->pageOverlayShouldApplyFadeWhenPainting())
  89. context.setFillColor(highlightColor(m_color, pageOverlay->fractionFadedIn() * 0.5f), ColorSpaceSRGB);
  90. else
  91. context.setFillColor(highlightColor(m_color, 0.5f), ColorSpaceSRGB);
  92. context.fillPath(m_path);
  93. }
  94. }
  95. bool TapHighlightController::mouseEvent(PageOverlay*, const WebMouseEvent&)
  96. {
  97. return false;
  98. }
  99. } // namespace WebKit
  100. #endif // ENABLE(TOUCH_EVENTS)