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