| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 } | 149 } |
| 150 | 150 |
| 151 FloatSize VisualViewport::visibleSize() const { | 151 FloatSize VisualViewport::visibleSize() const { |
| 152 FloatSize scaledSize(m_size); | 152 FloatSize scaledSize(m_size); |
| 153 scaledSize.expand(0, m_topControlsAdjustment); | 153 scaledSize.expand(0, m_topControlsAdjustment); |
| 154 scaledSize.scale(1 / m_scale); | 154 scaledSize.scale(1 / m_scale); |
| 155 return scaledSize; | 155 return scaledSize; |
| 156 } | 156 } |
| 157 | 157 |
| 158 FloatRect VisualViewport::visibleRect() const { | 158 FloatRect VisualViewport::visibleRect() const { |
| 159 return FloatRect(location(), visibleSize()); | 159 return FloatRect(FloatPoint(scrollOffset()), visibleSize()); |
| 160 } | 160 } |
| 161 | 161 |
| 162 FloatRect VisualViewport::visibleRectInDocument() const { | 162 FloatRect VisualViewport::visibleRectInDocument() const { |
| 163 if (!mainFrame() || !mainFrame()->view()) | 163 if (!mainFrame() || !mainFrame()->view()) |
| 164 return FloatRect(); | 164 return FloatRect(); |
| 165 | 165 |
| 166 FloatPoint viewLocation = FloatPoint( | 166 FloatPoint viewLocation = |
| 167 mainFrame()->view()->getScrollableArea()->scrollPositionDouble()); | 167 FloatPoint(mainFrame()->view()->getScrollableArea()->scrollOffset()); |
| 168 return FloatRect(viewLocation, visibleSize()); | 168 return FloatRect(viewLocation, visibleSize()); |
| 169 } | 169 } |
| 170 | 170 |
| 171 FloatRect VisualViewport::mainViewToViewportCSSPixels( | 171 FloatRect VisualViewport::mainViewToViewportCSSPixels( |
| 172 const FloatRect& rect) const { | 172 const FloatRect& rect) const { |
| 173 // Note, this is in CSS Pixels so we don't apply scale. | 173 // Note, this is in CSS Pixels so we don't apply scale. |
| 174 FloatRect rectInViewport = rect; | 174 FloatRect rectInViewport = rect; |
| 175 rectInViewport.moveBy(-location()); | 175 rectInViewport.move(-scrollOffset()); |
| 176 return rectInViewport; | 176 return rectInViewport; |
| 177 } | 177 } |
| 178 | 178 |
| 179 FloatPoint VisualViewport::viewportCSSPixelsToRootFrame( | 179 FloatPoint VisualViewport::viewportCSSPixelsToRootFrame( |
| 180 const FloatPoint& point) const { | 180 const FloatPoint& point) const { |
| 181 // Note, this is in CSS Pixels so we don't apply scale. | 181 // Note, this is in CSS Pixels so we don't apply scale. |
| 182 FloatPoint pointInRootFrame = point; | 182 FloatPoint pointInRootFrame = point; |
| 183 pointInRootFrame.moveBy(location()); | 183 pointInRootFrame.move(scrollOffset()); |
| 184 return pointInRootFrame; | 184 return pointInRootFrame; |
| 185 } | 185 } |
| 186 | 186 |
| 187 void VisualViewport::setLocation(const FloatPoint& newLocation) { | 187 void VisualViewport::setLocation(const FloatPoint& newLocation) { |
| 188 setScaleAndLocation(m_scale, newLocation); | 188 setScaleAndLocation(m_scale, newLocation); |
| 189 } | 189 } |
| 190 | 190 |
| 191 void VisualViewport::move(const FloatPoint& delta) { | 191 void VisualViewport::move(const ScrollOffset& delta) { |
| 192 setLocation(m_offset + delta); | 192 setLocation(FloatPoint(m_offset + delta)); |
| 193 } | |
| 194 | |
| 195 void VisualViewport::move(const FloatSize& delta) { | |
| 196 setLocation(m_offset + delta); | |
| 197 } | 193 } |
| 198 | 194 |
| 199 void VisualViewport::setScale(float scale) { | 195 void VisualViewport::setScale(float scale) { |
| 200 setScaleAndLocation(scale, m_offset); | 196 setScaleAndLocation(scale, FloatPoint(m_offset)); |
| 201 } | 197 } |
| 202 | 198 |
| 203 double VisualViewport::scrollLeft() { | 199 double VisualViewport::scrollLeft() { |
| 204 if (!mainFrame()) | 200 if (!mainFrame()) |
| 205 return 0; | 201 return 0; |
| 206 | 202 |
| 207 updateStyleAndLayoutIgnorePendingStylesheets(); | 203 updateStyleAndLayoutIgnorePendingStylesheets(); |
| 208 | 204 |
| 209 return adjustScrollForAbsoluteZoom(visibleRect().x(), | 205 return adjustScrollForAbsoluteZoom(visibleRect().x(), |
| 210 mainFrame()->pageZoomFactor()); | 206 mainFrame()->pageZoomFactor()); |
| 211 } | 207 } |
| 212 | 208 |
| 213 double VisualViewport::scrollTop() { | 209 double VisualViewport::scrollTop() { |
| 214 if (!mainFrame()) | 210 if (!mainFrame()) |
| 215 return 0; | 211 return 0; |
| 216 | 212 |
| 217 updateStyleAndLayoutIgnorePendingStylesheets(); | 213 updateStyleAndLayoutIgnorePendingStylesheets(); |
| 218 | 214 |
| 219 return adjustScrollForAbsoluteZoom(visibleRect().y(), | 215 return adjustScrollForAbsoluteZoom(visibleRect().y(), |
| 220 mainFrame()->pageZoomFactor()); | 216 mainFrame()->pageZoomFactor()); |
| 221 } | 217 } |
| 222 | 218 |
| 223 double VisualViewport::clientWidth() { | 219 double VisualViewport::clientWidth() { |
| 224 if (!mainFrame()) | 220 if (!mainFrame()) |
| 225 return 0; | 221 return 0; |
| 226 | 222 |
| 227 updateStyleAndLayoutIgnorePendingStylesheets(); | 223 updateStyleAndLayoutIgnorePendingStylesheets(); |
| 228 | 224 |
| 229 double width = adjustScrollForAbsoluteZoom(visibleSize().width(), | 225 float width = adjustScrollForAbsoluteZoom(visibleSize().width(), |
| 230 mainFrame()->pageZoomFactor()); | 226 mainFrame()->pageZoomFactor()); |
| 231 return width - mainFrame()->view()->verticalScrollbarWidth() / m_scale; | 227 return width - mainFrame()->view()->verticalScrollbarWidth() / m_scale; |
| 232 } | 228 } |
| 233 | 229 |
| 234 double VisualViewport::clientHeight() { | 230 double VisualViewport::clientHeight() { |
| 235 if (!mainFrame()) | 231 if (!mainFrame()) |
| 236 return 0; | 232 return 0; |
| 237 | 233 |
| 238 updateStyleAndLayoutIgnorePendingStylesheets(); | 234 updateStyleAndLayoutIgnorePendingStylesheets(); |
| 239 | 235 |
| 240 double height = adjustScrollForAbsoluteZoom(visibleSize().height(), | 236 float height = adjustScrollForAbsoluteZoom(visibleSize().height(), |
| 241 mainFrame()->pageZoomFactor()); | 237 mainFrame()->pageZoomFactor()); |
| 242 return height - mainFrame()->view()->horizontalScrollbarHeight() / m_scale; | 238 return height - mainFrame()->view()->horizontalScrollbarHeight() / m_scale; |
| 243 } | 239 } |
| 244 | 240 |
| 245 double VisualViewport::pageScale() { | 241 double VisualViewport::pageScale() { |
| 246 updateStyleAndLayoutIgnorePendingStylesheets(); | 242 updateStyleAndLayoutIgnorePendingStylesheets(); |
| 247 | 243 |
| 248 return m_scale; | 244 return m_scale; |
| 249 } | 245 } |
| 250 | 246 |
| 251 void VisualViewport::setScaleAndLocation(float scale, | 247 void VisualViewport::setScaleAndLocation(float scale, |
| 252 const FloatPoint& location) { | 248 const FloatPoint& location) { |
| 253 if (didSetScaleOrLocation(scale, location)) | 249 if (didSetScaleOrLocation(scale, location)) |
| 254 notifyRootFrameViewport(); | 250 notifyRootFrameViewport(); |
| 255 } | 251 } |
| 256 | 252 |
| 257 bool VisualViewport::didSetScaleOrLocation(float scale, | 253 bool VisualViewport::didSetScaleOrLocation(float scale, |
| 258 const FloatPoint& location) { | 254 const FloatPoint& location) { |
| 259 if (!mainFrame()) | 255 if (!mainFrame()) |
| 260 return false; | 256 return false; |
| 261 | 257 |
| 262 bool valuesChanged = false; | 258 bool valuesChanged = false; |
| 263 | 259 |
| 264 if (scale != m_scale) { | 260 if (scale != m_scale) { |
| 265 m_scale = scale; | 261 m_scale = scale; |
| 266 valuesChanged = true; | 262 valuesChanged = true; |
| 267 frameHost().chromeClient().pageScaleFactorChanged(); | 263 frameHost().chromeClient().pageScaleFactorChanged(); |
| 268 enqueueResizeEvent(); | 264 enqueueResizeEvent(); |
| 269 } | 265 } |
| 270 | 266 |
| 271 FloatPoint clampedOffset(clampOffsetToBoundaries(location)); | 267 ScrollOffset clampedOffset = clampScrollOffset(toScrollOffset(location)); |
| 272 | 268 |
| 273 if (clampedOffset != m_offset) { | 269 if (clampedOffset != m_offset) { |
| 274 m_offset = clampedOffset; | 270 m_offset = clampedOffset; |
| 275 scrollAnimator().setCurrentPosition(m_offset); | 271 scrollAnimator().setCurrentOffset(m_offset); |
| 276 | 272 |
| 277 // SVG runs with accelerated compositing disabled so no ScrollingCoordinator
. | 273 // SVG runs with accelerated compositing disabled so no ScrollingCoordinator
. |
| 278 if (ScrollingCoordinator* coordinator = | 274 if (ScrollingCoordinator* coordinator = |
| 279 frameHost().page().scrollingCoordinator()) | 275 frameHost().page().scrollingCoordinator()) |
| 280 coordinator->scrollableAreaScrollLayerDidChange(this); | 276 coordinator->scrollableAreaScrollLayerDidChange(this); |
| 281 | 277 |
| 282 if (!frameHost().settings().inertVisualViewport()) { | 278 if (!frameHost().settings().inertVisualViewport()) { |
| 283 if (Document* document = mainFrame()->document()) | 279 if (Document* document = mainFrame()->document()) |
| 284 document->enqueueScrollEventForNode(document); | 280 document->enqueueScrollEventForNode(document); |
| 285 } | 281 } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 315 // Keep the center-of-pinch anchor in a stable position over the course | 311 // Keep the center-of-pinch anchor in a stable position over the course |
| 316 // of the magnify. | 312 // of the magnify. |
| 317 FloatPoint anchorAtOldScale = anchor.scaledBy(1.f / oldPageScale); | 313 FloatPoint anchorAtOldScale = anchor.scaledBy(1.f / oldPageScale); |
| 318 FloatPoint anchorAtNewScale = anchor.scaledBy(1.f / newPageScale); | 314 FloatPoint anchorAtNewScale = anchor.scaledBy(1.f / newPageScale); |
| 319 FloatSize anchorDelta = anchorAtOldScale - anchorAtNewScale; | 315 FloatSize anchorDelta = anchorAtOldScale - anchorAtNewScale; |
| 320 | 316 |
| 321 // First try to use the anchor's delta to scroll the FrameView. | 317 // First try to use the anchor's delta to scroll the FrameView. |
| 322 FloatSize anchorDeltaUnusedByScroll = anchorDelta; | 318 FloatSize anchorDeltaUnusedByScroll = anchorDelta; |
| 323 | 319 |
| 324 // Manually bubble any remaining anchor delta up to the visual viewport. | 320 // Manually bubble any remaining anchor delta up to the visual viewport. |
| 325 FloatPoint newLocation(location() + anchorDeltaUnusedByScroll); | 321 FloatPoint newLocation(FloatPoint(scrollOffset()) + |
| 322 anchorDeltaUnusedByScroll); |
| 326 setScaleAndLocation(newPageScale, newLocation); | 323 setScaleAndLocation(newPageScale, newLocation); |
| 327 return true; | 324 return true; |
| 328 } | 325 } |
| 329 | 326 |
| 330 // Modifies the top of the graphics layer tree to add layers needed to support | 327 // Modifies the top of the graphics layer tree to add layers needed to support |
| 331 // the inner/outer viewport fixed-position model for pinch zoom. When finished, | 328 // the inner/outer viewport fixed-position model for pinch zoom. When finished, |
| 332 // the tree will look like this (with * denoting added layers): | 329 // the tree will look like this (with * denoting added layers): |
| 333 // | 330 // |
| 334 // *rootTransformLayer | 331 // *rootTransformLayer |
| 335 // +- *innerViewportContainerLayer (fixed pos container) | 332 // +- *innerViewportContainerLayer (fixed pos container) |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 } | 492 } |
| 496 | 493 |
| 497 bool VisualViewport::scrollAnimatorEnabled() const { | 494 bool VisualViewport::scrollAnimatorEnabled() const { |
| 498 return frameHost().settings().scrollAnimatorEnabled(); | 495 return frameHost().settings().scrollAnimatorEnabled(); |
| 499 } | 496 } |
| 500 | 497 |
| 501 HostWindow* VisualViewport::getHostWindow() const { | 498 HostWindow* VisualViewport::getHostWindow() const { |
| 502 return &frameHost().chromeClient(); | 499 return &frameHost().chromeClient(); |
| 503 } | 500 } |
| 504 | 501 |
| 505 DoubleRect VisualViewport::visibleContentRectDouble( | |
| 506 IncludeScrollbarsInRect) const { | |
| 507 return visibleRect(); | |
| 508 } | |
| 509 | |
| 510 IntRect VisualViewport::visibleContentRect( | |
| 511 IncludeScrollbarsInRect scrollbarInclusion) const { | |
| 512 return enclosingIntRect(visibleContentRectDouble(scrollbarInclusion)); | |
| 513 } | |
| 514 | |
| 515 bool VisualViewport::shouldUseIntegerScrollOffset() const { | 502 bool VisualViewport::shouldUseIntegerScrollOffset() const { |
| 516 LocalFrame* frame = mainFrame(); | 503 LocalFrame* frame = mainFrame(); |
| 517 if (frame && frame->settings() && | 504 if (frame && frame->settings() && |
| 518 !frame->settings()->preferCompositingToLCDTextEnabled()) | 505 !frame->settings()->preferCompositingToLCDTextEnabled()) |
| 519 return true; | 506 return true; |
| 520 | 507 |
| 521 return ScrollableArea::shouldUseIntegerScrollOffset(); | 508 return ScrollableArea::shouldUseIntegerScrollOffset(); |
| 522 } | 509 } |
| 523 | 510 |
| 524 void VisualViewport::setScrollPosition(const DoublePoint& scrollPoint, | 511 void VisualViewport::setScrollOffset(const ScrollOffset& offset, |
| 525 ScrollType scrollType, | 512 ScrollType scrollType, |
| 526 ScrollBehavior scrollBehavior) { | 513 ScrollBehavior scrollBehavior) { |
| 527 // We clamp the position here, because the ScrollAnimator may otherwise be | 514 // We clamp the offset here, because the ScrollAnimator may otherwise be |
| 528 // set to a non-clamped position by ScrollableArea::setScrollPosition, | 515 // set to a non-clamped offset by ScrollableArea::setScrollOffset, |
| 529 // which may lead to incorrect scrolling behavior in RootFrameViewport down | 516 // which may lead to incorrect scrolling behavior in RootFrameViewport down |
| 530 // the line. | 517 // the line. |
| 531 // TODO(eseckler): Solve this instead by ensuring that ScrollableArea and | 518 // TODO(eseckler): Solve this instead by ensuring that ScrollableArea and |
| 532 // ScrollAnimator are kept in sync. This requires that ScrollableArea always | 519 // ScrollAnimator are kept in sync. This requires that ScrollableArea always |
| 533 // stores fractional offsets and that truncation happens elsewhere, see | 520 // stores fractional offsets and that truncation happens elsewhere, see |
| 534 // crbug.com/626315. | 521 // crbug.com/626315. |
| 535 DoublePoint newScrollPosition = clampScrollPosition(scrollPoint); | 522 ScrollOffset newScrollOffset = clampScrollOffset(offset); |
| 536 ScrollableArea::setScrollPosition(newScrollPosition, scrollType, | 523 ScrollableArea::setScrollOffset(newScrollOffset, scrollType, scrollBehavior); |
| 537 scrollBehavior); | |
| 538 } | 524 } |
| 539 | 525 |
| 540 int VisualViewport::scrollSize(ScrollbarOrientation orientation) const { | 526 int VisualViewport::scrollSize(ScrollbarOrientation orientation) const { |
| 541 IntSize scrollDimensions = maximumScrollPosition() - minimumScrollPosition(); | 527 IntSize scrollDimensions = |
| 528 maximumScrollOffsetInt() - minimumScrollOffsetInt(); |
| 542 return (orientation == HorizontalScrollbar) ? scrollDimensions.width() | 529 return (orientation == HorizontalScrollbar) ? scrollDimensions.width() |
| 543 : scrollDimensions.height(); | 530 : scrollDimensions.height(); |
| 544 } | 531 } |
| 545 | 532 |
| 546 IntPoint VisualViewport::minimumScrollPosition() const { | 533 IntSize VisualViewport::minimumScrollOffsetInt() const { |
| 547 return IntPoint(); | 534 return IntSize(); |
| 548 } | 535 } |
| 549 | 536 |
| 550 IntPoint VisualViewport::maximumScrollPosition() const { | 537 IntSize VisualViewport::maximumScrollOffsetInt() const { |
| 551 return flooredIntPoint(maximumScrollPositionDouble()); | 538 return flooredIntSize(maximumScrollOffset()); |
| 552 } | 539 } |
| 553 | 540 |
| 554 DoublePoint VisualViewport::maximumScrollPositionDouble() const { | 541 ScrollOffset VisualViewport::maximumScrollOffset() const { |
| 555 if (!mainFrame()) | 542 if (!mainFrame()) |
| 556 return IntPoint(); | 543 return ScrollOffset(); |
| 557 | 544 |
| 558 // TODO(bokan): We probably shouldn't be storing the bounds in a float. crbug.
com/470718. | 545 // TODO(bokan): We probably shouldn't be storing the bounds in a float. crbug.
com/470718. |
| 559 FloatSize frameViewSize(contentsSize()); | 546 FloatSize frameViewSize(contentsSize()); |
| 560 | 547 |
| 561 if (m_topControlsAdjustment) { | 548 if (m_topControlsAdjustment) { |
| 562 float minScale = | 549 float minScale = |
| 563 frameHost().pageScaleConstraintsSet().finalConstraints().minimumScale; | 550 frameHost().pageScaleConstraintsSet().finalConstraints().minimumScale; |
| 564 frameViewSize.expand(0, m_topControlsAdjustment / minScale); | 551 frameViewSize.expand(0, m_topControlsAdjustment / minScale); |
| 565 } | 552 } |
| 566 | 553 |
| 567 frameViewSize.scale(m_scale); | 554 frameViewSize.scale(m_scale); |
| 568 frameViewSize = FloatSize(flooredIntSize(frameViewSize)); | 555 frameViewSize = FloatSize(flooredIntSize(frameViewSize)); |
| 569 | 556 |
| 570 FloatSize viewportSize(m_size); | 557 FloatSize viewportSize(m_size); |
| 571 viewportSize.expand(0, ceilf(m_topControlsAdjustment)); | 558 viewportSize.expand(0, ceilf(m_topControlsAdjustment)); |
| 572 | 559 |
| 573 FloatSize maxPosition = frameViewSize - viewportSize; | 560 FloatSize maxPosition = frameViewSize - viewportSize; |
| 574 maxPosition.scale(1 / m_scale); | 561 maxPosition.scale(1 / m_scale); |
| 575 return DoublePoint(maxPosition); | 562 return ScrollOffset(maxPosition); |
| 576 } | 563 } |
| 577 | 564 |
| 578 IntPoint VisualViewport::clampDocumentOffsetAtScale(const IntPoint& offset, | 565 IntPoint VisualViewport::clampDocumentOffsetAtScale(const IntPoint& offset, |
| 579 float scale) { | 566 float scale) { |
| 580 if (!mainFrame() || !mainFrame()->view()) | 567 if (!mainFrame() || !mainFrame()->view()) |
| 581 return IntPoint(); | 568 return IntPoint(); |
| 582 | 569 |
| 583 FrameView* view = mainFrame()->view(); | 570 FrameView* view = mainFrame()->view(); |
| 584 | 571 |
| 585 FloatSize scaledSize(m_size); | 572 FloatSize scaledSize(m_size); |
| 586 scaledSize.scale(1 / scale); | 573 scaledSize.scale(1 / scale); |
| 587 | 574 |
| 588 IntPoint visualViewportMax = | 575 IntSize visualViewportMax = |
| 589 flooredIntPoint(FloatSize(contentsSize()) - scaledSize); | 576 flooredIntSize(FloatSize(contentsSize()) - scaledSize); |
| 590 IntPoint max = view->maximumScrollPosition() + visualViewportMax; | 577 IntSize max = view->maximumScrollOffsetInt() + visualViewportMax; |
| 591 IntPoint min = | 578 IntSize min = |
| 592 view->minimumScrollPosition(); // VisualViewportMin should be (0, 0) | 579 view->minimumScrollOffsetInt(); // VisualViewportMin should be (0, 0) |
| 593 | 580 |
| 594 IntPoint clamped = offset; | 581 IntSize clamped = toIntSize(offset); |
| 595 clamped = clamped.shrunkTo(max); | 582 clamped = clamped.shrunkTo(max); |
| 596 clamped = clamped.expandedTo(min); | 583 clamped = clamped.expandedTo(min); |
| 597 return clamped; | 584 return IntPoint(clamped); |
| 598 } | 585 } |
| 599 | 586 |
| 600 void VisualViewport::setTopControlsAdjustment(float adjustment) { | 587 void VisualViewport::setTopControlsAdjustment(float adjustment) { |
| 601 m_topControlsAdjustment = adjustment; | 588 m_topControlsAdjustment = adjustment; |
| 602 } | 589 } |
| 603 | 590 |
| 604 IntRect VisualViewport::scrollableAreaBoundingBox() const { | 591 IntRect VisualViewport::scrollableAreaBoundingBox() const { |
| 605 // This method should return the bounding box in the parent view's coordinate | 592 // This method should return the bounding box in the parent view's coordinate |
| 606 // space; however, VisualViewport technically isn't a child of any Frames. | 593 // space; however, VisualViewport technically isn't a child of any Frames. |
| 607 // Nonetheless, the VisualViewport always occupies the entire main frame so ju
st | 594 // Nonetheless, the VisualViewport always occupies the entire main frame so ju
st |
| 608 // return that. | 595 // return that. |
| 609 LocalFrame* frame = mainFrame(); | 596 LocalFrame* frame = mainFrame(); |
| 610 | 597 |
| 611 if (!frame || !frame->view()) | 598 if (!frame || !frame->view()) |
| 612 return IntRect(); | 599 return IntRect(); |
| 613 | 600 |
| 614 return frame->view()->frameRect(); | 601 return frame->view()->frameRect(); |
| 615 } | 602 } |
| 616 | 603 |
| 617 IntSize VisualViewport::contentsSize() const { | 604 IntSize VisualViewport::contentsSize() const { |
| 618 LocalFrame* frame = mainFrame(); | 605 LocalFrame* frame = mainFrame(); |
| 619 | 606 |
| 620 if (!frame || !frame->view()) | 607 if (!frame || !frame->view()) |
| 621 return IntSize(); | 608 return IntSize(); |
| 622 | 609 |
| 623 return frame->view()->visibleContentRect(IncludeScrollbars).size(); | 610 return frame->view()->visibleContentRect(IncludeScrollbars).size(); |
| 624 } | 611 } |
| 625 | 612 |
| 626 void VisualViewport::setScrollOffset(const DoublePoint& offset, | 613 void VisualViewport::updateScrollOffset(const ScrollOffset& position, |
| 627 ScrollType scrollType) { | 614 ScrollType scrollType) { |
| 628 if (didSetScaleOrLocation(m_scale, toFloatPoint(offset)) && | 615 if (didSetScaleOrLocation(m_scale, FloatPoint(position)) && |
| 629 scrollType != AnchoringScroll) | 616 scrollType != AnchoringScroll) |
| 630 notifyRootFrameViewport(); | 617 notifyRootFrameViewport(); |
| 631 } | 618 } |
| 632 | 619 |
| 633 GraphicsLayer* VisualViewport::layerForContainer() const { | 620 GraphicsLayer* VisualViewport::layerForContainer() const { |
| 634 return m_innerViewportContainerLayer.get(); | 621 return m_innerViewportContainerLayer.get(); |
| 635 } | 622 } |
| 636 | 623 |
| 637 GraphicsLayer* VisualViewport::layerForScrolling() const { | 624 GraphicsLayer* VisualViewport::layerForScrolling() const { |
| 638 return m_innerViewportScrollLayer.get(); | 625 return m_innerViewportScrollLayer.get(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 660 return frameHost().page().mainFrame() && | 647 return frameHost().page().mainFrame() && |
| 661 frameHost().page().mainFrame()->isLocalFrame() | 648 frameHost().page().mainFrame()->isLocalFrame() |
| 662 ? frameHost().page().deprecatedLocalMainFrame() | 649 ? frameHost().page().deprecatedLocalMainFrame() |
| 663 : 0; | 650 : 0; |
| 664 } | 651 } |
| 665 | 652 |
| 666 Widget* VisualViewport::getWidget() { | 653 Widget* VisualViewport::getWidget() { |
| 667 return mainFrame()->view(); | 654 return mainFrame()->view(); |
| 668 } | 655 } |
| 669 | 656 |
| 670 FloatPoint VisualViewport::clampOffsetToBoundaries(const FloatPoint& offset) { | |
| 671 FloatPoint clampedOffset(offset); | |
| 672 clampedOffset = | |
| 673 clampedOffset.shrunkTo(FloatPoint(maximumScrollPositionDouble())); | |
| 674 clampedOffset = | |
| 675 clampedOffset.expandedTo(FloatPoint(minimumScrollPositionDouble())); | |
| 676 return clampedOffset; | |
| 677 } | |
| 678 | |
| 679 void VisualViewport::clampToBoundaries() { | 657 void VisualViewport::clampToBoundaries() { |
| 680 setLocation(m_offset); | 658 setLocation(FloatPoint(m_offset)); |
| 681 } | 659 } |
| 682 | 660 |
| 683 FloatRect VisualViewport::viewportToRootFrame( | 661 FloatRect VisualViewport::viewportToRootFrame( |
| 684 const FloatRect& rectInViewport) const { | 662 const FloatRect& rectInViewport) const { |
| 685 FloatRect rectInRootFrame = rectInViewport; | 663 FloatRect rectInRootFrame = rectInViewport; |
| 686 rectInRootFrame.scale(1 / scale()); | 664 rectInRootFrame.scale(1 / scale()); |
| 687 rectInRootFrame.moveBy(location()); | 665 rectInRootFrame.move(scrollOffset()); |
| 688 return rectInRootFrame; | 666 return rectInRootFrame; |
| 689 } | 667 } |
| 690 | 668 |
| 691 IntRect VisualViewport::viewportToRootFrame( | 669 IntRect VisualViewport::viewportToRootFrame( |
| 692 const IntRect& rectInViewport) const { | 670 const IntRect& rectInViewport) const { |
| 693 // FIXME: How to snap to pixels? | 671 // FIXME: How to snap to pixels? |
| 694 return enclosingIntRect(viewportToRootFrame(FloatRect(rectInViewport))); | 672 return enclosingIntRect(viewportToRootFrame(FloatRect(rectInViewport))); |
| 695 } | 673 } |
| 696 | 674 |
| 697 FloatRect VisualViewport::rootFrameToViewport( | 675 FloatRect VisualViewport::rootFrameToViewport( |
| 698 const FloatRect& rectInRootFrame) const { | 676 const FloatRect& rectInRootFrame) const { |
| 699 FloatRect rectInViewport = rectInRootFrame; | 677 FloatRect rectInViewport = rectInRootFrame; |
| 700 rectInViewport.moveBy(-location()); | 678 rectInViewport.move(-scrollOffset()); |
| 701 rectInViewport.scale(scale()); | 679 rectInViewport.scale(scale()); |
| 702 return rectInViewport; | 680 return rectInViewport; |
| 703 } | 681 } |
| 704 | 682 |
| 705 IntRect VisualViewport::rootFrameToViewport( | 683 IntRect VisualViewport::rootFrameToViewport( |
| 706 const IntRect& rectInRootFrame) const { | 684 const IntRect& rectInRootFrame) const { |
| 707 // FIXME: How to snap to pixels? | 685 // FIXME: How to snap to pixels? |
| 708 return enclosingIntRect(rootFrameToViewport(FloatRect(rectInRootFrame))); | 686 return enclosingIntRect(rootFrameToViewport(FloatRect(rectInRootFrame))); |
| 709 } | 687 } |
| 710 | 688 |
| 711 FloatPoint VisualViewport::viewportToRootFrame( | 689 FloatPoint VisualViewport::viewportToRootFrame( |
| 712 const FloatPoint& pointInViewport) const { | 690 const FloatPoint& pointInViewport) const { |
| 713 FloatPoint pointInRootFrame = pointInViewport; | 691 FloatPoint pointInRootFrame = pointInViewport; |
| 714 pointInRootFrame.scale(1 / scale(), 1 / scale()); | 692 pointInRootFrame.scale(1 / scale(), 1 / scale()); |
| 715 pointInRootFrame.moveBy(location()); | 693 pointInRootFrame.move(scrollOffset()); |
| 716 return pointInRootFrame; | 694 return pointInRootFrame; |
| 717 } | 695 } |
| 718 | 696 |
| 719 FloatPoint VisualViewport::rootFrameToViewport( | 697 FloatPoint VisualViewport::rootFrameToViewport( |
| 720 const FloatPoint& pointInRootFrame) const { | 698 const FloatPoint& pointInRootFrame) const { |
| 721 FloatPoint pointInViewport = pointInRootFrame; | 699 FloatPoint pointInViewport = pointInRootFrame; |
| 722 pointInViewport.moveBy(-location()); | 700 pointInViewport.move(-scrollOffset()); |
| 723 pointInViewport.scale(scale(), scale()); | 701 pointInViewport.scale(scale(), scale()); |
| 724 return pointInViewport; | 702 return pointInViewport; |
| 725 } | 703 } |
| 726 | 704 |
| 727 IntPoint VisualViewport::viewportToRootFrame( | 705 IntPoint VisualViewport::viewportToRootFrame( |
| 728 const IntPoint& pointInViewport) const { | 706 const IntPoint& pointInViewport) const { |
| 729 // FIXME: How to snap to pixels? | 707 // FIXME: How to snap to pixels? |
| 730 return flooredIntPoint( | 708 return flooredIntPoint( |
| 731 FloatPoint(viewportToRootFrame(FloatPoint(pointInViewport)))); | 709 FloatPoint(viewportToRootFrame(FloatPoint(pointInViewport)))); |
| 732 } | 710 } |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 838 } else if (graphicsLayer == m_rootTransformLayer.get()) { | 816 } else if (graphicsLayer == m_rootTransformLayer.get()) { |
| 839 name = "Root Transform Layer"; | 817 name = "Root Transform Layer"; |
| 840 } else { | 818 } else { |
| 841 ASSERT_NOT_REACHED(); | 819 ASSERT_NOT_REACHED(); |
| 842 } | 820 } |
| 843 | 821 |
| 844 return name; | 822 return name; |
| 845 } | 823 } |
| 846 | 824 |
| 847 } // namespace blink | 825 } // namespace blink |
| OLD | NEW |