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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 using blink::FrameHost; | 64 using blink::FrameHost; |
65 using blink::GraphicsLayer; | 65 using blink::GraphicsLayer; |
66 using blink::GraphicsLayerFactory; | 66 using blink::GraphicsLayerFactory; |
67 | 67 |
68 namespace blink { | 68 namespace blink { |
69 | 69 |
70 VisualViewport::VisualViewport(FrameHost& owner) | 70 VisualViewport::VisualViewport(FrameHost& owner) |
71 : m_frameHost(&owner) | 71 : m_frameHost(&owner) |
72 , m_scale(1) | 72 , m_scale(1) |
73 , m_topControlsAdjustment(0) | 73 , m_topControlsAdjustment(0) |
| 74 , m_maxPageScale(-1) |
| 75 , m_trackPinchZoomStatsForPage(false) |
74 { | 76 { |
75 reset(); | 77 reset(); |
76 } | 78 } |
77 | 79 |
78 VisualViewport::~VisualViewport() | 80 VisualViewport::~VisualViewport() |
79 { | 81 { |
| 82 sendUMAMetrics(); |
80 } | 83 } |
81 | 84 |
82 DEFINE_TRACE(VisualViewport) | 85 DEFINE_TRACE(VisualViewport) |
83 { | 86 { |
84 visitor->trace(m_frameHost); | 87 visitor->trace(m_frameHost); |
85 ScrollableArea::trace(visitor); | 88 ScrollableArea::trace(visitor); |
86 } | 89 } |
87 | 90 |
88 void VisualViewport::setSize(const IntSize& size) | 91 void VisualViewport::setSize(const IntSize& size) |
89 { | 92 { |
(...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
647 // FIXME: How to snap to pixels? | 650 // FIXME: How to snap to pixels? |
648 return flooredIntPoint(FloatPoint(viewportToRootFrame(FloatPoint(pointInView
port)))); | 651 return flooredIntPoint(FloatPoint(viewportToRootFrame(FloatPoint(pointInView
port)))); |
649 } | 652 } |
650 | 653 |
651 IntPoint VisualViewport::rootFrameToViewport(const IntPoint& pointInRootFrame) c
onst | 654 IntPoint VisualViewport::rootFrameToViewport(const IntPoint& pointInRootFrame) c
onst |
652 { | 655 { |
653 // FIXME: How to snap to pixels? | 656 // FIXME: How to snap to pixels? |
654 return flooredIntPoint(FloatPoint(rootFrameToViewport(FloatPoint(pointInRoot
Frame)))); | 657 return flooredIntPoint(FloatPoint(rootFrameToViewport(FloatPoint(pointInRoot
Frame)))); |
655 } | 658 } |
656 | 659 |
| 660 void VisualViewport::startTrackingPinchStats() |
| 661 { |
| 662 if (!mainFrame()) |
| 663 return; |
| 664 |
| 665 Document* document = mainFrame()->document(); |
| 666 if (!document) |
| 667 return; |
| 668 |
| 669 if (!document->url().protocolIsInHTTPFamily()) |
| 670 return; |
| 671 |
| 672 m_trackPinchZoomStatsForPage = !shouldDisableDesktopWorkarounds(); |
| 673 } |
| 674 |
| 675 void VisualViewport::userDidChangeScale() |
| 676 { |
| 677 if (!m_trackPinchZoomStatsForPage) |
| 678 return; |
| 679 |
| 680 m_maxPageScale = std::max(m_maxPageScale, m_scale); |
| 681 } |
| 682 |
| 683 void VisualViewport::sendUMAMetrics() |
| 684 { |
| 685 if (m_trackPinchZoomStatsForPage) { |
| 686 bool didScale = m_maxPageScale > 0; |
| 687 |
| 688 Platform::current()->histogramEnumeration("Viewport.DidScalePage", didSc
ale ? 1 : 0, 2); |
| 689 |
| 690 if (didScale) { |
| 691 int zoomPercentage = floor(m_maxPageScale * 100); |
| 692 |
| 693 // See the PageScaleFactor enumeration in histograms.xml for the buc
ket ranges. |
| 694 int bucket = floor(zoomPercentage / 25.f); |
| 695 |
| 696 Platform::current()->histogramEnumeration("Viewport.MaxPageScale", b
ucket, 21); |
| 697 } |
| 698 } |
| 699 |
| 700 m_maxPageScale = -1; |
| 701 m_trackPinchZoomStatsForPage = false; |
| 702 } |
| 703 |
| 704 bool VisualViewport::shouldDisableDesktopWorkarounds() const |
| 705 { |
| 706 if (!mainFrame() || !mainFrame()->view()) |
| 707 return false; |
| 708 |
| 709 if (!mainFrame()->settings()->viewportEnabled()) |
| 710 return false; |
| 711 |
| 712 // A document is considered adapted to small screen UAs if one of these hold
s: |
| 713 // 1. The author specified viewport has a constrained width that is equal to |
| 714 // the initial viewport width. |
| 715 // 2. The author has disabled viewport zoom. |
| 716 const PageScaleConstraints& constraints = frameHost().pageScaleConstraintsSe
t().pageDefinedConstraints(); |
| 717 |
| 718 return mainFrame()->view()->layoutSize().width() == m_size.width() |
| 719 || (constraints.minimumScale == constraints.maximumScale && constraints.
minimumScale != -1); |
| 720 } |
| 721 |
657 String VisualViewport::debugName(const GraphicsLayer* graphicsLayer) | 722 String VisualViewport::debugName(const GraphicsLayer* graphicsLayer) |
658 { | 723 { |
659 String name; | 724 String name; |
660 if (graphicsLayer == m_innerViewportContainerLayer.get()) { | 725 if (graphicsLayer == m_innerViewportContainerLayer.get()) { |
661 name = "Inner Viewport Container Layer"; | 726 name = "Inner Viewport Container Layer"; |
662 } else if (graphicsLayer == m_overscrollElasticityLayer.get()) { | 727 } else if (graphicsLayer == m_overscrollElasticityLayer.get()) { |
663 name = "Overscroll Elasticity Layer"; | 728 name = "Overscroll Elasticity Layer"; |
664 } else if (graphicsLayer == m_pageScaleLayer.get()) { | 729 } else if (graphicsLayer == m_pageScaleLayer.get()) { |
665 name = "Page Scale Layer"; | 730 name = "Page Scale Layer"; |
666 } else if (graphicsLayer == m_innerViewportScrollLayer.get()) { | 731 } else if (graphicsLayer == m_innerViewportScrollLayer.get()) { |
667 name = "Inner Viewport Scroll Layer"; | 732 name = "Inner Viewport Scroll Layer"; |
668 } else if (graphicsLayer == m_overlayScrollbarHorizontal.get()) { | 733 } else if (graphicsLayer == m_overlayScrollbarHorizontal.get()) { |
669 name = "Overlay Scrollbar Horizontal Layer"; | 734 name = "Overlay Scrollbar Horizontal Layer"; |
670 } else if (graphicsLayer == m_overlayScrollbarVertical.get()) { | 735 } else if (graphicsLayer == m_overlayScrollbarVertical.get()) { |
671 name = "Overlay Scrollbar Vertical Layer"; | 736 name = "Overlay Scrollbar Vertical Layer"; |
672 } else if (graphicsLayer == m_rootTransformLayer) { | 737 } else if (graphicsLayer == m_rootTransformLayer) { |
673 name = "Root Transform Layer"; | 738 name = "Root Transform Layer"; |
674 } else { | 739 } else { |
675 ASSERT_NOT_REACHED(); | 740 ASSERT_NOT_REACHED(); |
676 } | 741 } |
677 | 742 |
678 return name; | 743 return name; |
679 } | 744 } |
680 | 745 |
681 } // namespace blink | 746 } // namespace blink |
OLD | NEW |