1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341
|
/*
* Copyright (C) 2009, 2010, 2011 Research In Motion Limited. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "config.h"
#include "BackingStoreClient.h"
#include "BackingStore.h"
#include "BackingStore_p.h"
#include "FloatPoint.h"
#include "FocusController.h"
#include "Frame.h"
#include "FrameView.h"
#include "HTMLFrameOwnerElement.h"
#include "Page.h"
#include "RenderBox.h"
#include "WebPage_p.h"
// FIXME: Leaving the below lines commented out as a reference for us to soon be sure if we need these
// methods and class variables be moved from WebPage to BackingStoreClient.
// Notification methods that deliver changes to the real geometry of the device as specified above.
// void notifyTransformChanged();
// void notifyTransformedContentsSizeChanged();
// void notifyTransformedScrollChanged();
// m_overflowExceedsContentsSize = true;
// haspendingscrollevent
using namespace WebCore;
namespace BlackBerry {
namespace WebKit {
static inline IntSize pointToSize(const IntPoint& point)
{
return IntSize(point.x(), point.y());
}
BackingStoreClient* BackingStoreClient::create(Frame* frame, Frame* parentFrame, WebPage* parentPage)
{
ASSERT(!parentFrame);
BackingStoreClient* it = new BackingStoreClient(frame, parentPage);
return it;
}
BackingStoreClient::BackingStoreClient(Frame* frame, WebPage* parentPage)
: m_frame(frame)
, m_webPage(parentPage)
, m_backingStore(0)
, m_isClientGeneratedScroll(false)
, m_isScrollNotificationSuppressed(false)
{
m_backingStore = new BackingStore(m_webPage, this);
}
BackingStoreClient::~BackingStoreClient()
{
delete m_backingStore;
m_backingStore = 0;
m_frame = 0;
}
IntRect BackingStoreClient::absoluteRect() const
{
IntRect rect = IntRect(IntPoint::zero(), viewportSize());
// FIXME: Speed it up!
Frame* frame = m_frame;
while (frame) {
if (Element* element = static_cast<Element*>(frame->ownerElement())) {
do {
rect.move(element->offsetLeft(), element->offsetTop());
} while ((element = element->offsetParent()));
}
if ((frame = frame->tree()->parent()))
rect.move((-frame->view()->scrollOffset()));
}
return rect;
}
IntRect BackingStoreClient::transformedAbsoluteRect() const
{
return m_webPage->d->mapToTransformed(absoluteRect());
}
IntPoint BackingStoreClient::absoluteLocation() const
{
return absoluteRect().location();
}
IntPoint BackingStoreClient::transformedAbsoluteLocation() const
{
return m_webPage->d->mapToTransformed(transformedAbsoluteRect()).location();
}
IntPoint BackingStoreClient::scrollPosition() const
{
ASSERT(m_frame);
if (!m_frame->view())
return IntPoint();
return m_frame->view()->scrollPosition() - pointToSize(m_frame->view()->minimumScrollPosition());
}
IntPoint BackingStoreClient::transformedScrollPosition() const
{
return m_webPage->d->mapToTransformed(scrollPosition());
}
void BackingStoreClient::setScrollPosition(const IntPoint& pos)
{
ASSERT(m_frame);
if (!m_frame->view())
return;
if (pos == scrollPosition())
return;
// We set a flag here to note that this scroll operation was originated
// within the BlackBerry-specific layer of WebKit and not by WebCore.
// This flag is checked in checkOriginOfCurrentScrollOperation() to decide
// whether to notify the client of the current scroll operation. This is
// why it is important that all scroll operations that originate within
// BlackBerry-specific code are encapsulated here and that callers of this
// method also directly or indirectly call notifyTransformedScrollChanged().
m_isScrollNotificationSuppressed = true;
m_frame->view()->setScrollPosition(pos + pointToSize(m_frame->view()->minimumScrollPosition()));
m_isScrollNotificationSuppressed = false;
}
IntPoint BackingStoreClient::maximumScrollPosition() const
{
ASSERT(m_frame);
if (!m_frame->view())
return IntPoint();
return m_frame->view()->maximumScrollPosition() - pointToSize(m_frame->view()->minimumScrollPosition());
}
IntPoint BackingStoreClient::transformedMaximumScrollPosition() const
{
return m_webPage->d->mapToTransformed(maximumScrollPosition());
}
IntSize BackingStoreClient::actualVisibleSize() const
{
return m_webPage->d->mapFromTransformed(transformedActualVisibleSize());
}
IntSize BackingStoreClient::transformedActualVisibleSize() const
{
ASSERT(isMainFrame());
return m_webPage->d->transformedActualVisibleSize();
}
IntSize BackingStoreClient::viewportSize() const
{
ASSERT(m_frame);
if (!m_frame->view())
return IntSize();
ASSERT(isMainFrame());
return m_webPage->d->viewportSize();
}
IntSize BackingStoreClient::transformedViewportSize() const
{
ASSERT(m_frame);
if (!m_frame->view())
return IntSize();
ASSERT(isMainFrame());
return m_webPage->d->transformedViewportSize();
}
IntRect BackingStoreClient::visibleContentsRect() const
{
ASSERT(m_frame);
if (!m_frame->view())
return IntRect();
IntRect visibleContentRect = m_frame->view()->visibleContentRect();
ASSERT(isMainFrame());
return visibleContentRect;
}
IntRect BackingStoreClient::transformedVisibleContentsRect() const
{
// Usually this would be mapToTransformed(visibleContentsRect()), but
// that results in rounding errors because we already set the WebCore
// viewport size from our original transformedViewportSize().
// Instead, we only transform the scroll position and take the
// viewport size as it is, which ensures that e.g. blitting operations
// always cover the whole widget/screen.
IntRect visibleContentsRect = IntRect(transformedScrollPosition(), transformedViewportSize());
ASSERT(isMainFrame());
return visibleContentsRect;
}
IntSize BackingStoreClient::contentsSize() const
{
ASSERT(m_frame);
if (!m_frame->view())
return IntSize();
return m_frame->view()->contentsSize();
}
IntSize BackingStoreClient::transformedContentsSize() const
{
// mapToTransformed() functions use this method to crop their results,
// so we can't make use of them here. While we want rounding inside page
// boundaries to extend rectangles and round points, we need to crop the
// contents size to the floored values so that we don't try to display
// or report points that are not fully covered by the actual float-point
// contents rectangle.
const IntSize untransformedContentsSize = contentsSize();
const FloatPoint transformedBottomRight = m_webPage->d->m_transformationMatrix->mapPoint(
FloatPoint(untransformedContentsSize.width(), untransformedContentsSize.height()));
return IntSize(floorf(transformedBottomRight.x()), floorf(transformedBottomRight.y()));
}
void BackingStoreClient::clipToTransformedContentsRect(IntRect& rect) const
{
// FIXME: Needs to proper translate coordinates here?
rect.intersect(IntRect(IntPoint::zero(), transformedContentsSize()));
}
IntPoint BackingStoreClient::mapFromContentsToViewport(const IntPoint& point) const
{
const IntPoint scrollPosition = this->scrollPosition();
return IntPoint(point.x() - scrollPosition.x(), point.y() - scrollPosition.y());
}
IntPoint BackingStoreClient::mapFromViewportToContents(const IntPoint& point) const
{
const IntPoint scrollPosition = this->scrollPosition();
return IntPoint(point.x() + scrollPosition.x(), point.y() + scrollPosition.y());
}
IntRect BackingStoreClient::mapFromContentsToViewport(const IntRect& rect) const
{
return IntRect(mapFromContentsToViewport(rect.location()), rect.size());
}
IntRect BackingStoreClient::mapFromViewportToContents(const IntRect& rect) const
{
return IntRect(mapFromViewportToContents(rect.location()), rect.size());
}
IntPoint BackingStoreClient::mapFromTransformedContentsToTransformedViewport(const IntPoint& point) const
{
const IntPoint scrollPosition = transformedScrollPosition();
return IntPoint(point.x() - scrollPosition.x(), point.y() - scrollPosition.y());
}
IntPoint BackingStoreClient::mapFromTransformedViewportToTransformedContents(const IntPoint& point) const
{
const IntPoint scrollPosition = transformedScrollPosition();
return IntPoint(point.x() + scrollPosition.x(), point.y() + scrollPosition.y());
}
IntRect BackingStoreClient::mapFromTransformedContentsToTransformedViewport(const IntRect& rect) const
{
return IntRect(mapFromTransformedContentsToTransformedViewport(rect.location()), rect.size());
}
IntRect BackingStoreClient::mapFromTransformedViewportToTransformedContents(const IntRect& rect) const
{
return IntRect(mapFromTransformedViewportToTransformedContents(rect.location()), rect.size());
}
WebPagePrivate::LoadState BackingStoreClient::loadState() const
{
// FIXME: Does it need to call WebPage's?
return m_webPage->d->loadState();
}
bool BackingStoreClient::isLoading() const
{
// FIXME: Does it need to call WebPage's?
return m_webPage->d->isLoading();
}
bool BackingStoreClient::isFocused() const
{
return m_frame && m_frame->page() && m_frame->page()->focusController()
&& m_frame->page()->focusController()->focusedFrame() == m_frame;
}
bool BackingStoreClient::isClientGeneratedScroll() const
{
return m_isClientGeneratedScroll;
}
void BackingStoreClient::setIsClientGeneratedScroll(bool flag)
{
m_isClientGeneratedScroll = flag;
}
bool BackingStoreClient::isScrollNotificationSuppressed() const
{
return m_isScrollNotificationSuppressed;
}
void BackingStoreClient::setIsScrollNotificationSuppressed(bool flag)
{
m_isScrollNotificationSuppressed = flag;
}
void BackingStoreClient::checkOriginOfCurrentScrollOperation()
{
// This is called via ChromeClientBlackBerry::scroll in order to check the origin
// of the current scroll operation to decide whether to notify the client.
// If the current scroll operation was initiated internally by WebCore itself
// either via JavaScript, back/forward or otherwise then we need to go ahead
// and notify the client of this change.
if (isScrollNotificationSuppressed())
return;
ASSERT(isMainFrame());
m_webPage->d->notifyTransformedScrollChanged();
}
}
}
|