BackingStoreClient.cpp 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /*
  2. * Copyright (C) 2009, 2010, 2011 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. #include "config.h"
  19. #include "BackingStoreClient.h"
  20. #include "BackingStore.h"
  21. #include "BackingStore_p.h"
  22. #include "FloatPoint.h"
  23. #include "FocusController.h"
  24. #include "Frame.h"
  25. #include "FrameView.h"
  26. #include "HTMLFrameOwnerElement.h"
  27. #include "Page.h"
  28. #include "RenderBox.h"
  29. #include "WebPage_p.h"
  30. #include <BlackBerryPlatformViewportAccessor.h>
  31. // FIXME: Leaving the below lines commented out as a reference for us to soon be sure if we need these
  32. // methods and class variables be moved from WebPage to BackingStoreClient.
  33. // Notification methods that deliver changes to the real geometry of the device as specified above.
  34. // void notifyTransformChanged();
  35. // void notifyTransformedContentsSizeChanged();
  36. // void notifyTransformedScrollChanged();
  37. // m_overflowExceedsContentsSize = true;
  38. // haspendingscrollevent
  39. using namespace WebCore;
  40. namespace BlackBerry {
  41. namespace WebKit {
  42. static inline IntSize pointToSize(const IntPoint& point)
  43. {
  44. return IntSize(point.x(), point.y());
  45. }
  46. BackingStoreClient* BackingStoreClient::create(Frame* frame, Frame* parentFrame, WebPage* parentPage)
  47. {
  48. ASSERT_UNUSED(parentFrame, !parentFrame);
  49. BackingStoreClient* it = new BackingStoreClient(frame, parentPage);
  50. return it;
  51. }
  52. BackingStoreClient::BackingStoreClient(Frame* frame, WebPage* parentPage)
  53. : m_frame(frame)
  54. , m_webPage(parentPage)
  55. , m_backingStore(0)
  56. , m_isClientGeneratedScroll(false)
  57. , m_isScrollNotificationSuppressed(false)
  58. {
  59. m_backingStore = new BackingStore(m_webPage, this);
  60. }
  61. BackingStoreClient::~BackingStoreClient()
  62. {
  63. delete m_backingStore;
  64. m_backingStore = 0;
  65. m_frame = 0;
  66. }
  67. IntPoint BackingStoreClient::scrollPosition() const
  68. {
  69. ASSERT(m_frame);
  70. if (!m_frame->view())
  71. return IntPoint();
  72. return m_frame->view()->scrollPosition() - pointToSize(m_frame->view()->minimumScrollPosition());
  73. }
  74. IntPoint BackingStoreClient::transformedScrollPosition() const
  75. {
  76. return m_webPage->webkitThreadViewportAccessor()->pixelScrollPosition();
  77. }
  78. void BackingStoreClient::setScrollPosition(const IntPoint& pos)
  79. {
  80. ASSERT(m_frame);
  81. if (!m_frame->view())
  82. return;
  83. if (pos == scrollPosition())
  84. return;
  85. // We set a flag here to note that this scroll operation was originated
  86. // within the BlackBerry-specific layer of WebKit and not by WebCore.
  87. // This flag is checked in checkOriginOfCurrentScrollOperation() to decide
  88. // whether to notify the client of the current scroll operation. This is
  89. // why it is important that all scroll operations that originate within
  90. // BlackBerry-specific code are encapsulated here and that callers of this
  91. // method also directly or indirectly call notifyTransformedScrollChanged().
  92. m_isScrollNotificationSuppressed = true;
  93. m_frame->view()->setScrollPosition(pos + pointToSize(m_frame->view()->minimumScrollPosition()));
  94. m_isScrollNotificationSuppressed = false;
  95. }
  96. IntPoint BackingStoreClient::maximumScrollPosition() const
  97. {
  98. ASSERT(m_frame);
  99. if (!m_frame->view())
  100. return IntPoint();
  101. return m_frame->view()->maximumScrollPosition() - pointToSize(m_frame->view()->minimumScrollPosition());
  102. }
  103. IntPoint BackingStoreClient::transformedMaximumScrollPosition() const
  104. {
  105. return m_webPage->webkitThreadViewportAccessor()->roundToPixelFromDocumentContents(WebCore::FloatPoint(maximumScrollPosition()));
  106. }
  107. IntSize BackingStoreClient::actualVisibleSize() const
  108. {
  109. return m_webPage->webkitThreadViewportAccessor()->documentViewportSize();
  110. }
  111. IntSize BackingStoreClient::transformedActualVisibleSize() const
  112. {
  113. ASSERT(isMainFrame());
  114. return m_webPage->webkitThreadViewportAccessor()->pixelViewportSize();
  115. }
  116. IntSize BackingStoreClient::viewportSize() const
  117. {
  118. ASSERT(m_frame);
  119. if (!m_frame->view())
  120. return IntSize();
  121. ASSERT(isMainFrame());
  122. return m_webPage->d->viewportSize();
  123. }
  124. IntSize BackingStoreClient::transformedViewportSize() const
  125. {
  126. ASSERT(m_frame);
  127. if (!m_frame->view())
  128. return IntSize();
  129. ASSERT(isMainFrame());
  130. return m_webPage->d->transformedViewportSize();
  131. }
  132. IntRect BackingStoreClient::visibleContentsRect() const
  133. {
  134. ASSERT(m_frame);
  135. if (!m_frame->view())
  136. return IntRect();
  137. IntRect visibleContentRect = m_frame->view()->visibleContentRect();
  138. ASSERT(isMainFrame());
  139. return visibleContentRect;
  140. }
  141. IntSize BackingStoreClient::contentsSize() const
  142. {
  143. ASSERT(m_frame);
  144. if (!m_frame->view())
  145. return IntSize();
  146. return m_frame->view()->contentsSize();
  147. }
  148. WebPagePrivate::LoadState BackingStoreClient::loadState() const
  149. {
  150. // FIXME: Does it need to call WebPage's?
  151. return m_webPage->d->loadState();
  152. }
  153. bool BackingStoreClient::isLoading() const
  154. {
  155. // FIXME: Does it need to call WebPage's?
  156. return m_webPage->d->isLoading();
  157. }
  158. bool BackingStoreClient::isFocused() const
  159. {
  160. return m_frame && m_frame->page() && m_frame->page()->focusController()
  161. && m_frame->page()->focusController()->focusedFrame() == m_frame;
  162. }
  163. bool BackingStoreClient::isClientGeneratedScroll() const
  164. {
  165. return m_isClientGeneratedScroll;
  166. }
  167. void BackingStoreClient::setIsClientGeneratedScroll(bool flag)
  168. {
  169. m_isClientGeneratedScroll = flag;
  170. }
  171. bool BackingStoreClient::isScrollNotificationSuppressed() const
  172. {
  173. return m_isScrollNotificationSuppressed;
  174. }
  175. void BackingStoreClient::setIsScrollNotificationSuppressed(bool flag)
  176. {
  177. m_isScrollNotificationSuppressed = flag;
  178. }
  179. void BackingStoreClient::checkOriginOfCurrentScrollOperation()
  180. {
  181. // This is called via ChromeClientBlackBerry::scroll in order to check the origin
  182. // of the current scroll operation to decide whether to notify the client.
  183. // If the current scroll operation was initiated internally by WebCore itself
  184. // either via JavaScript, back/forward or otherwise then we need to go ahead
  185. // and notify the client of this change.
  186. if (isScrollNotificationSuppressed())
  187. return;
  188. ASSERT(isMainFrame());
  189. m_webPage->d->notifyTransformedScrollChanged();
  190. }
  191. }
  192. }