SelectionHandler.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. * Copyright (C) 2010, 2011, 2012, 2013 Research In Motion Limited. All rights reserved.
  3. *
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser 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. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with this library; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #ifndef SelectionHandler_h
  19. #define SelectionHandler_h
  20. #include "BlackBerryPlatformIntRectRegion.h"
  21. #include "BlackBerryPlatformPrimitives.h"
  22. #include "BlackBerryPlatformStopWatch.h"
  23. #include "Color.h"
  24. #include "TextGranularity.h"
  25. #include <wtf/Vector.h>
  26. namespace WTF {
  27. class String;
  28. }
  29. namespace WebCore {
  30. class FloatQuad;
  31. class IntPoint;
  32. class IntRect;
  33. class Node;
  34. class VisiblePosition;
  35. class VisibleSelection;
  36. }
  37. namespace BlackBerry {
  38. namespace Platform {
  39. class String;
  40. }
  41. namespace WebKit {
  42. class FatFingersResult;
  43. class WebPagePrivate;
  44. class SelectionHandler {
  45. public:
  46. SelectionHandler(WebPagePrivate*);
  47. ~SelectionHandler();
  48. bool isSelectionActive() { return m_selectionActive; }
  49. void setSelectionActive(bool active) { m_selectionActive = active; }
  50. void cancelSelection();
  51. BlackBerry::Platform::String selectedText() const;
  52. bool selectionContains(const WebCore::IntPoint&);
  53. void setSelection(WebCore::IntPoint start, WebCore::IntPoint end);
  54. void selectAtPoint(const WebCore::IntPoint&, SelectionExpansionType);
  55. void selectObject(const WebCore::IntPoint&, WebCore::TextGranularity);
  56. void selectObject(WebCore::TextGranularity);
  57. void selectObject(WebCore::Node*);
  58. void selectionPositionChanged(bool forceUpdateWithoutChange = false);
  59. void setCaretPosition(const WebCore::IntPoint&);
  60. bool lastUpdatedEndPointIsValid() const { return m_lastUpdatedEndPointIsValid; }
  61. void inputHandlerDidFinishProcessingChange();
  62. void expandSelection(bool isScrollStarted);
  63. void setOverlayExpansionHeight(int dy) { m_overlayExpansionHeight = dy; }
  64. void setParagraphExpansionScrollMargin(const WebCore::IntSize&);
  65. void setSelectionViewportSize(const WebCore::IntSize& selectionViewportSize) { m_selectionViewportSize = selectionViewportSize; }
  66. void setSelectionSubframeViewportRect(const WebCore::IntRect& selectionSubframeViewportRect) { m_selectionSubframeViewportRect = selectionSubframeViewportRect; }
  67. WebCore::IntRect selectionViewportRect() const;
  68. private:
  69. void notifyCaretPositionChangedIfNeeded(bool userTouchTriggeredOnTextField);
  70. void caretPositionChanged(bool userTouchTriggered);
  71. void regionForTextQuads(WTF::Vector<WebCore::FloatQuad>&, BlackBerry::Platform::IntRectRegion&, bool shouldClipToVisibleContent = true) const;
  72. WebCore::IntRect clippingRectForVisibleContent() const;
  73. bool updateOrHandleInputSelection(WebCore::VisibleSelection& newSelection, const WebCore::IntPoint& relativeStart, const WebCore::IntPoint& relativeEnd);
  74. WebCore::Node* DOMContainerNodeForVisiblePosition(const WebCore::VisiblePosition&) const;
  75. bool shouldUpdateSelectionOrCaretForPoint(const WebCore::IntPoint&, const WebCore::IntRect&, bool startCaret = true) const;
  76. unsigned extendSelectionToFieldBoundary(bool isStartHandle, const WebCore::IntPoint& selectionPoint, WebCore::VisibleSelection& newSelection);
  77. WebCore::IntPoint clipPointToVisibleContainer(const WebCore::IntPoint&) const;
  78. void selectNextParagraph();
  79. void drawAnimationOverlay(BlackBerry::Platform::IntRectRegion, bool isExpandingOverlayAtConstantRate, bool isStartOfSelection = false);
  80. Platform::IntRectRegion regionForSelectionQuads(WebCore::VisibleSelection);
  81. bool findNextAnimationOverlayRegion();
  82. bool ensureSelectedTextVisible(const WebCore::IntPoint&, bool scrollIfNeeded);
  83. bool expandSelectionToGranularity(WebCore::Frame*, WebCore::VisibleSelection, WebCore::TextGranularity, bool isInputMode);
  84. bool inputNodeOverridesTouch() const;
  85. BlackBerry::Platform::RequestedHandlePosition requestedSelectionHandlePosition(const WebCore::VisibleSelection&) const;
  86. bool selectNodeIfFatFingersResultIsLink(FatFingersResult);
  87. WebCore::IntRect startCaretViewportRect(const WebCore::IntPoint& frameOffset) const;
  88. WebPagePrivate* m_webPage;
  89. bool m_selectionActive;
  90. bool m_caretActive;
  91. bool m_lastUpdatedEndPointIsValid;
  92. bool m_didSuppressCaretPositionChangedNotification;
  93. BlackBerry::Platform::IntRectRegion m_lastSelectionRegion;
  94. WebCore::VisiblePosition m_animationOverlayStartPos;
  95. WebCore::VisiblePosition m_animationOverlayEndPos;
  96. BlackBerry::Platform::IntRectRegion m_currentAnimationOverlayRegion;
  97. BlackBerry::Platform::IntRectRegion m_nextAnimationOverlayRegion;
  98. int m_overlayExpansionHeight;
  99. WebCore::Color m_animationHighlightColor;
  100. BlackBerry::Platform::StopWatch m_timer;
  101. WebCore::IntSize m_scrollMargin;
  102. WebCore::IntSize m_selectionViewportSize;
  103. WebCore::IntRect m_selectionSubframeViewportRect;
  104. WebCore::VisibleSelection m_lastSelection;
  105. };
  106. }
  107. }
  108. #endif // SelectionHandler_h