WebHitTestResult.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * Copyright (C) 2011 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 library 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 library; 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. #include "config.h"
  20. #include "WebHitTestResult.h"
  21. #include "WebCoreArgumentCoders.h"
  22. #include <WebCore/Document.h>
  23. #include <WebCore/Frame.h>
  24. #include <WebCore/FrameView.h>
  25. #include <WebCore/HitTestResult.h>
  26. #include <WebCore/KURL.h>
  27. #include <WebCore/Node.h>
  28. #include <wtf/text/WTFString.h>
  29. using namespace WebCore;
  30. namespace WebKit {
  31. PassRefPtr<WebHitTestResult> WebHitTestResult::create(const WebHitTestResult::Data& hitTestResultData)
  32. {
  33. return adoptRef(new WebHitTestResult(hitTestResultData));
  34. }
  35. WebHitTestResult::Data::Data()
  36. {
  37. }
  38. WebHitTestResult::Data::Data(const HitTestResult& hitTestResult)
  39. : absoluteImageURL(hitTestResult.absoluteImageURL().string())
  40. , absolutePDFURL(hitTestResult.absolutePDFURL().string())
  41. , absoluteLinkURL(hitTestResult.absoluteLinkURL().string())
  42. , absoluteMediaURL(hitTestResult.absoluteMediaURL().string())
  43. , linkLabel(hitTestResult.textContent())
  44. , linkTitle(hitTestResult.titleDisplayString())
  45. , isContentEditable(hitTestResult.isContentEditable())
  46. , elementBoundingBox(elementBoundingBoxInWindowCoordinates(hitTestResult))
  47. , isScrollbar(hitTestResult.scrollbar())
  48. {
  49. }
  50. WebHitTestResult::Data::~Data()
  51. {
  52. }
  53. void WebHitTestResult::Data::encode(CoreIPC::ArgumentEncoder& encoder) const
  54. {
  55. encoder << absoluteImageURL;
  56. encoder << absolutePDFURL;
  57. encoder << absoluteLinkURL;
  58. encoder << absoluteMediaURL;
  59. encoder << linkLabel;
  60. encoder << linkTitle;
  61. encoder << isContentEditable;
  62. encoder << elementBoundingBox;
  63. encoder << isScrollbar;
  64. }
  65. bool WebHitTestResult::Data::decode(CoreIPC::ArgumentDecoder& decoder, WebHitTestResult::Data& hitTestResultData)
  66. {
  67. if (!decoder.decode(hitTestResultData.absoluteImageURL)
  68. || !decoder.decode(hitTestResultData.absolutePDFURL)
  69. || !decoder.decode(hitTestResultData.absoluteLinkURL)
  70. || !decoder.decode(hitTestResultData.absoluteMediaURL)
  71. || !decoder.decode(hitTestResultData.linkLabel)
  72. || !decoder.decode(hitTestResultData.linkTitle)
  73. || !decoder.decode(hitTestResultData.isContentEditable)
  74. || !decoder.decode(hitTestResultData.elementBoundingBox)
  75. || !decoder.decode(hitTestResultData.isScrollbar))
  76. return false;
  77. return true;
  78. }
  79. IntRect WebHitTestResult::Data::elementBoundingBoxInWindowCoordinates(const HitTestResult& hitTestResult)
  80. {
  81. Node* node = hitTestResult.innerNonSharedNode();
  82. if (!node)
  83. return IntRect();
  84. Frame* frame = node->document()->frame();
  85. if (!frame)
  86. return IntRect();
  87. FrameView* view = frame->view();
  88. if (!view)
  89. return IntRect();
  90. return view->contentsToWindow(node->pixelSnappedBoundingBox());
  91. }
  92. } // WebKit