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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 #include "public/platform/WebCompositorSupport.h" | 56 #include "public/platform/WebCompositorSupport.h" |
57 #include "public/platform/WebScrollbar.h" | 57 #include "public/platform/WebScrollbar.h" |
58 #include "public/platform/WebScrollbarLayer.h" | 58 #include "public/platform/WebScrollbarLayer.h" |
59 #include <memory> | 59 #include <memory> |
60 | 60 |
61 namespace blink { | 61 namespace blink { |
62 | 62 |
63 VisualViewport::VisualViewport(FrameHost& owner) | 63 VisualViewport::VisualViewport(FrameHost& owner) |
64 : m_frameHost(&owner), | 64 : m_frameHost(&owner), |
65 m_scale(1), | 65 m_scale(1), |
66 m_topControlsAdjustment(0), | 66 m_browserControlsAdjustment(0), |
67 m_maxPageScale(-1), | 67 m_maxPageScale(-1), |
68 m_trackPinchZoomStatsForPage(false) { | 68 m_trackPinchZoomStatsForPage(false) { |
69 reset(); | 69 reset(); |
70 } | 70 } |
71 | 71 |
72 VisualViewport::~VisualViewport() { | 72 VisualViewport::~VisualViewport() { |
73 sendUMAMetrics(); | 73 sendUMAMetrics(); |
74 } | 74 } |
75 | 75 |
76 DEFINE_TRACE(VisualViewport) { | 76 DEFINE_TRACE(VisualViewport) { |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 | 144 |
145 // In unit tests we may not have initialized the layer tree. | 145 // In unit tests we may not have initialized the layer tree. |
146 if (m_innerViewportScrollLayer) | 146 if (m_innerViewportScrollLayer) |
147 m_innerViewportScrollLayer->setSize(FloatSize(contentsSize())); | 147 m_innerViewportScrollLayer->setSize(FloatSize(contentsSize())); |
148 | 148 |
149 clampToBoundaries(); | 149 clampToBoundaries(); |
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_browserControlsAdjustment); |
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(FloatPoint(scrollOffset()), 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()) |
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
545 } | 545 } |
546 | 546 |
547 ScrollOffset VisualViewport::maximumScrollOffset() const { | 547 ScrollOffset VisualViewport::maximumScrollOffset() const { |
548 if (!mainFrame()) | 548 if (!mainFrame()) |
549 return ScrollOffset(); | 549 return ScrollOffset(); |
550 | 550 |
551 // TODO(bokan): We probably shouldn't be storing the bounds in a float. | 551 // TODO(bokan): We probably shouldn't be storing the bounds in a float. |
552 // crbug.com/470718. | 552 // crbug.com/470718. |
553 FloatSize frameViewSize(contentsSize()); | 553 FloatSize frameViewSize(contentsSize()); |
554 | 554 |
555 if (m_topControlsAdjustment) { | 555 if (m_browserControlsAdjustment) { |
556 float minScale = | 556 float minScale = |
557 frameHost().pageScaleConstraintsSet().finalConstraints().minimumScale; | 557 frameHost().pageScaleConstraintsSet().finalConstraints().minimumScale; |
558 frameViewSize.expand(0, m_topControlsAdjustment / minScale); | 558 frameViewSize.expand(0, m_browserControlsAdjustment / minScale); |
559 } | 559 } |
560 | 560 |
561 frameViewSize.scale(m_scale); | 561 frameViewSize.scale(m_scale); |
562 frameViewSize = FloatSize(flooredIntSize(frameViewSize)); | 562 frameViewSize = FloatSize(flooredIntSize(frameViewSize)); |
563 | 563 |
564 FloatSize viewportSize(m_size); | 564 FloatSize viewportSize(m_size); |
565 viewportSize.expand(0, ceilf(m_topControlsAdjustment)); | 565 viewportSize.expand(0, ceilf(m_browserControlsAdjustment)); |
566 | 566 |
567 FloatSize maxPosition = frameViewSize - viewportSize; | 567 FloatSize maxPosition = frameViewSize - viewportSize; |
568 maxPosition.scale(1 / m_scale); | 568 maxPosition.scale(1 / m_scale); |
569 return ScrollOffset(maxPosition); | 569 return ScrollOffset(maxPosition); |
570 } | 570 } |
571 | 571 |
572 IntPoint VisualViewport::clampDocumentOffsetAtScale(const IntPoint& offset, | 572 IntPoint VisualViewport::clampDocumentOffsetAtScale(const IntPoint& offset, |
573 float scale) { | 573 float scale) { |
574 if (!mainFrame() || !mainFrame()->view()) | 574 if (!mainFrame() || !mainFrame()->view()) |
575 return IntPoint(); | 575 return IntPoint(); |
576 | 576 |
577 FrameView* view = mainFrame()->view(); | 577 FrameView* view = mainFrame()->view(); |
578 | 578 |
579 FloatSize scaledSize(m_size); | 579 FloatSize scaledSize(m_size); |
580 scaledSize.scale(1 / scale); | 580 scaledSize.scale(1 / scale); |
581 | 581 |
582 IntSize visualViewportMax = | 582 IntSize visualViewportMax = |
583 flooredIntSize(FloatSize(contentsSize()) - scaledSize); | 583 flooredIntSize(FloatSize(contentsSize()) - scaledSize); |
584 IntSize max = view->maximumScrollOffsetInt() + visualViewportMax; | 584 IntSize max = view->maximumScrollOffsetInt() + visualViewportMax; |
585 IntSize min = | 585 IntSize min = |
586 view->minimumScrollOffsetInt(); // VisualViewportMin should be (0, 0) | 586 view->minimumScrollOffsetInt(); // VisualViewportMin should be (0, 0) |
587 | 587 |
588 IntSize clamped = toIntSize(offset); | 588 IntSize clamped = toIntSize(offset); |
589 clamped = clamped.shrunkTo(max); | 589 clamped = clamped.shrunkTo(max); |
590 clamped = clamped.expandedTo(min); | 590 clamped = clamped.expandedTo(min); |
591 return IntPoint(clamped); | 591 return IntPoint(clamped); |
592 } | 592 } |
593 | 593 |
594 void VisualViewport::setTopControlsAdjustment(float adjustment) { | 594 void VisualViewport::setBrowserControlsAdjustment(float adjustment) { |
595 m_topControlsAdjustment = adjustment; | 595 m_browserControlsAdjustment = adjustment; |
596 } | 596 } |
597 | 597 |
598 IntRect VisualViewport::scrollableAreaBoundingBox() const { | 598 IntRect VisualViewport::scrollableAreaBoundingBox() const { |
599 // This method should return the bounding box in the parent view's coordinate | 599 // This method should return the bounding box in the parent view's coordinate |
600 // space; however, VisualViewport technically isn't a child of any Frames. | 600 // space; however, VisualViewport technically isn't a child of any Frames. |
601 // Nonetheless, the VisualViewport always occupies the entire main frame so | 601 // Nonetheless, the VisualViewport always occupies the entire main frame so |
602 // just return that. | 602 // just return that. |
603 LocalFrame* frame = mainFrame(); | 603 LocalFrame* frame = mainFrame(); |
604 | 604 |
605 if (!frame || !frame->view()) | 605 if (!frame || !frame->view()) |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
824 } else if (graphicsLayer == m_rootTransformLayer.get()) { | 824 } else if (graphicsLayer == m_rootTransformLayer.get()) { |
825 name = "Root Transform Layer"; | 825 name = "Root Transform Layer"; |
826 } else { | 826 } else { |
827 ASSERT_NOT_REACHED(); | 827 ASSERT_NOT_REACHED(); |
828 } | 828 } |
829 | 829 |
830 return name; | 830 return name; |
831 } | 831 } |
832 | 832 |
833 } // namespace blink | 833 } // namespace blink |
OLD | NEW |