| 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 using blink::WebScrollbar; | 57 using blink::WebScrollbar; |
| 58 using blink::WebScrollbarLayer; | 58 using blink::WebScrollbarLayer; |
| 59 using WebCore::FrameHost; | 59 using WebCore::FrameHost; |
| 60 using WebCore::GraphicsLayer; | 60 using WebCore::GraphicsLayer; |
| 61 using WebCore::GraphicsLayerFactory; | 61 using WebCore::GraphicsLayerFactory; |
| 62 | 62 |
| 63 namespace WebCore { | 63 namespace WebCore { |
| 64 | 64 |
| 65 PinchViewport::PinchViewport(FrameHost& owner) | 65 PinchViewport::PinchViewport(FrameHost& owner) |
| 66 : m_frameHost(owner) | 66 : m_frameHost(owner) |
| 67 , m_scale(1) | |
| 68 { | 67 { |
| 68 reset(); |
| 69 } | 69 } |
| 70 | 70 |
| 71 PinchViewport::~PinchViewport() { } | 71 PinchViewport::~PinchViewport() { } |
| 72 | 72 |
| 73 void PinchViewport::setSize(const IntSize& size) | 73 void PinchViewport::setSize(const IntSize& size) |
| 74 { | 74 { |
| 75 ASSERT(mainFrame() && mainFrame()->view()); | 75 ASSERT(mainFrame() && mainFrame()->view()); |
| 76 | 76 |
| 77 if (!m_innerViewportContainerLayer || !m_innerViewportScrollLayer) | 77 if (!m_innerViewportContainerLayer || !m_innerViewportScrollLayer) |
| 78 return; | 78 return; |
| 79 | 79 |
| 80 if (m_size == size) | 80 if (m_size == size) |
| 81 return; | 81 return; |
| 82 | 82 |
| 83 m_size = size; | 83 m_size = size; |
| 84 m_innerViewportContainerLayer->setSize(m_size); | 84 m_innerViewportContainerLayer->setSize(m_size); |
| 85 | 85 |
| 86 // Make sure we clamp the offset to within the new bounds. | 86 // Make sure we clamp the offset to within the new bounds. |
| 87 setLocation(m_offset); | 87 setLocation(m_offset); |
| 88 | 88 |
| 89 // Need to re-compute sizes for the overlay scrollbars. | 89 // Need to re-compute sizes for the overlay scrollbars. |
| 90 setupScrollbar(WebScrollbar::Horizontal); | 90 setupScrollbar(WebScrollbar::Horizontal); |
| 91 setupScrollbar(WebScrollbar::Vertical); | 91 setupScrollbar(WebScrollbar::Vertical); |
| 92 } | 92 } |
| 93 | 93 |
| 94 void PinchViewport::reset() |
| 95 { |
| 96 setLocation(FloatPoint()); |
| 97 setScale(1); |
| 98 } |
| 99 |
| 94 void PinchViewport::mainFrameDidChangeSize() | 100 void PinchViewport::mainFrameDidChangeSize() |
| 95 { | 101 { |
| 96 // In unit tests we may not have initialized the layer tree. | 102 // In unit tests we may not have initialized the layer tree. |
| 97 if (m_innerViewportScrollLayer) | 103 if (m_innerViewportScrollLayer) |
| 98 m_innerViewportScrollLayer->setSize(contentsSize()); | 104 m_innerViewportScrollLayer->setSize(contentsSize()); |
| 99 | 105 |
| 100 // Make sure the viewport's offset is clamped within the newly sized main fr
ame. | 106 // Make sure the viewport's offset is clamped within the newly sized main fr
ame. |
| 101 setLocation(m_offset); | 107 setLocation(m_offset); |
| 102 } | 108 } |
| 103 | 109 |
| 104 FloatRect PinchViewport::visibleRect() const | 110 FloatRect PinchViewport::visibleRect() const |
| 105 { | 111 { |
| 106 FloatSize scaledSize(m_size); | 112 FloatSize scaledSize(m_size); |
| 107 scaledSize.scale(1 / m_scale); | 113 scaledSize.scale(1 / m_scale); |
| 108 return FloatRect(m_offset, scaledSize); | 114 return FloatRect(m_offset, scaledSize); |
| 109 } | 115 } |
| 110 | 116 |
| 111 void PinchViewport::setLocation(const FloatPoint& newLocation) | 117 void PinchViewport::setLocation(const FloatPoint& newLocation) |
| 112 { | 118 { |
| 113 FloatPoint clampedOffset(clampOffsetToBoundaries(newLocation)); | 119 FloatPoint clampedOffset(clampOffsetToBoundaries(newLocation)); |
| 114 | 120 |
| 115 if (clampedOffset == m_offset) | 121 if (clampedOffset == m_offset) |
| 116 return; | 122 return; |
| 117 | 123 |
| 118 m_offset = clampedOffset; | 124 m_offset = clampedOffset; |
| 119 | 125 |
| 120 ScrollingCoordinator* coordinator = m_frameHost.page().scrollingCoordinator(
); | 126 ScrollingCoordinator* coordinator = m_frameHost.page().scrollingCoordinator(
); |
| 121 ASSERT(coordinator); | 127 ASSERT(coordinator); |
| 122 coordinator->scrollableAreaScrollLayerDidChange(this); | 128 coordinator->scrollableAreaScrollLayerDidChange(this); |
| 129 |
| 130 mainFrame()->loader().saveScrollState(); |
| 123 } | 131 } |
| 124 | 132 |
| 125 void PinchViewport::setScale(float scale) | 133 void PinchViewport::setScale(float scale) |
| 126 { | 134 { |
| 135 if (scale == m_scale) |
| 136 return; |
| 137 |
| 127 m_scale = scale; | 138 m_scale = scale; |
| 128 | 139 |
| 140 if (mainFrame()) |
| 141 mainFrame()->loader().saveScrollState(); |
| 142 |
| 129 // Old-style pinch sets scale here but we shouldn't call into the | 143 // Old-style pinch sets scale here but we shouldn't call into the |
| 130 // clamping code below. | 144 // clamping code below. |
| 131 if (!m_innerViewportScrollLayer) | 145 if (!m_innerViewportScrollLayer) |
| 132 return; | 146 return; |
| 133 | 147 |
| 134 // Ensure we clamp so we remain within the bounds. | 148 // Ensure we clamp so we remain within the bounds. |
| 135 setLocation(visibleRect().location()); | 149 setLocation(visibleRect().location()); |
| 150 |
| 151 // TODO: We should probably be calling scaleDidChange type functions here. |
| 152 // see Page::setPageScaleFactor. |
| 136 } | 153 } |
| 137 | 154 |
| 138 // Modifies the top of the graphics layer tree to add layers needed to support | 155 // Modifies the top of the graphics layer tree to add layers needed to support |
| 139 // the inner/outer viewport fixed-position model for pinch zoom. When finished, | 156 // the inner/outer viewport fixed-position model for pinch zoom. When finished, |
| 140 // the tree will look like this (with * denoting added layers): | 157 // the tree will look like this (with * denoting added layers): |
| 141 // | 158 // |
| 142 // *innerViewportContainerLayer (fixed pos container) | 159 // *innerViewportContainerLayer (fixed pos container) |
| 143 // +- *pageScaleLayer | 160 // +- *pageScaleLayer |
| 144 // | +- *innerViewportScrollLayer | 161 // | +- *innerViewportScrollLayer |
| 145 // | +-- overflowControlsHostLayer (root layer) | 162 // | +-- overflowControlsHostLayer (root layer) |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 } else if (graphicsLayer == m_overlayScrollbarVertical.get()) { | 398 } else if (graphicsLayer == m_overlayScrollbarVertical.get()) { |
| 382 name = "Overlay Scrollbar Vertical Layer"; | 399 name = "Overlay Scrollbar Vertical Layer"; |
| 383 } else { | 400 } else { |
| 384 ASSERT_NOT_REACHED(); | 401 ASSERT_NOT_REACHED(); |
| 385 } | 402 } |
| 386 | 403 |
| 387 return name; | 404 return name; |
| 388 } | 405 } |
| 389 | 406 |
| 390 } // namespace WebCore | 407 } // namespace WebCore |
| OLD | NEW |