| 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) | 
| 67 { | 68 { | 
| 68 } | 69 } | 
| 69 | 70 | 
| 70 PinchViewport::~PinchViewport() { } | 71 PinchViewport::~PinchViewport() { } | 
| 71 | 72 | 
| 72 void PinchViewport::setSize(const IntSize& newSize) | 73 void PinchViewport::mainFrameDidChangeSize() | 
| 73 { | 74 { | 
| 74     // TODO: This is currently called from WebViewImpl with the main frame size 
     which | 75     ASSERT(mainFrame() && mainFrame()->view()); | 
| 75     // is (or will be) incorrect, address in future patches. |  | 
| 76 | 76 | 
| 77     if (!m_innerViewportContainerLayer || !m_innerViewportScrollLayer) | 77     if (!m_innerViewportContainerLayer || !m_innerViewportScrollLayer) | 
| 78         return; | 78         return; | 
| 79 | 79 | 
|  | 80     IntSize newSize = mainFrame()->view()->frameRect().size(); | 
|  | 81 | 
| 80     m_innerViewportContainerLayer->setSize(newSize); | 82     m_innerViewportContainerLayer->setSize(newSize); | 
| 81     // The innerviewport scroll layer always has the same size as its clip layer
     , but | 83     // The innerviewport scroll layer always has the same size as its clip layer
     , but | 
| 82     // the page scale layer lives between them, allowing for non-zero max scroll | 84     // the page scale layer lives between them, allowing for non-zero max scroll | 
| 83     // offset when page scale > 1. | 85     // offset when page scale > 1. | 
| 84     m_innerViewportScrollLayer->setSize(newSize); | 86     m_innerViewportScrollLayer->setSize(newSize); | 
| 85 | 87 | 
|  | 88     m_offset = clampOffsetToBoundaries(m_offset); | 
|  | 89 | 
| 86     // Need to re-compute sizes for the overlay scrollbars. | 90     // Need to re-compute sizes for the overlay scrollbars. | 
| 87     setupScrollbar(WebScrollbar::Horizontal); | 91     setupScrollbar(WebScrollbar::Horizontal); | 
| 88     setupScrollbar(WebScrollbar::Vertical); | 92     setupScrollbar(WebScrollbar::Vertical); | 
| 89 } | 93 } | 
| 90 | 94 | 
| 91 void PinchViewport::setLocation(const IntPoint& newLocation) | 95 FloatRect PinchViewport::visibleRect() const | 
| 92 { | 96 { | 
| 93     // TODO: The update from the LayerTree will occur here before the scale delt
     a is applied. | 97     FloatSize viewportSize(mainFrame()->view()->frameRect().size()); | 
| 94     // this means that the clamping below may be incorrect. Once scaling is done
      in PinchViewport | 98     viewportSize.scale(1 / m_scale); | 
| 95     // change it so they happen at the same time. | 99     return FloatRect(m_offset, viewportSize); | 
|  | 100 } | 
| 96 | 101 | 
| 97     // Clamp the location within our extents. | 102 void PinchViewport::setLocation(const FloatPoint& newLocation) | 
| 98     IntPoint location(newLocation); | 103 { | 
| 99     location.shrunkTo(maximumScrollPosition()); | 104     FloatPoint clampedOffset(clampOffsetToBoundaries(newLocation)); | 
| 100     location.expandedTo(minimumScrollPosition()); |  | 
| 101 | 105 | 
| 102     m_visibleRect.setLocation(newLocation); | 106     if (clampedOffset == m_offset) | 
|  | 107         return; | 
|  | 108 | 
|  | 109     m_offset = clampedOffset; | 
| 103 | 110 | 
| 104     ScrollingCoordinator* coordinator = m_frameHost.page().scrollingCoordinator(
     ); | 111     ScrollingCoordinator* coordinator = m_frameHost.page().scrollingCoordinator(
     ); | 
| 105     ASSERT(coordinator); | 112     ASSERT(coordinator); | 
| 106 | 113 | 
| 107     coordinator->scrollableAreaScrollLayerDidChange(this); | 114     coordinator->scrollableAreaScrollLayerDidChange(this); | 
| 108 } | 115 } | 
| 109 | 116 | 
|  | 117 void PinchViewport::setScale(float scale) | 
|  | 118 { | 
|  | 119     m_scale = scale; | 
|  | 120 | 
|  | 121     // Old-style pinch sets scale here but we shouldn't call into the | 
|  | 122     // clamping code below. | 
|  | 123     if (!m_innerViewportScrollLayer) | 
|  | 124         return; | 
|  | 125 | 
|  | 126     // Ensure we clamp so we remain within the bounds. | 
|  | 127     setLocation(visibleRect().location()); | 
|  | 128 } | 
|  | 129 | 
| 110 // Modifies the top of the graphics layer tree to add layers needed to support | 130 // Modifies the top of the graphics layer tree to add layers needed to support | 
| 111 // the inner/outer viewport fixed-position model for pinch zoom. When finished, | 131 // the inner/outer viewport fixed-position model for pinch zoom. When finished, | 
| 112 // the tree will look like this (with * denoting added layers): | 132 // the tree will look like this (with * denoting added layers): | 
| 113 // | 133 // | 
| 114 // *innerViewportContainerLayer (fixed pos container) | 134 // *innerViewportContainerLayer (fixed pos container) | 
| 115 //  +- *pageScaleLayer | 135 //  +- *pageScaleLayer | 
| 116 //  |   +- *innerViewportScrollLayer | 136 //  |   +- *innerViewportScrollLayer | 
| 117 //  |       +-- overflowControlsHostLayer (root layer) | 137 //  |       +-- overflowControlsHostLayer (root layer) | 
| 118 //  |           +-- rootTransformLayer (optional) | 138 //  |           +-- rootTransformLayer (optional) | 
| 119 //  |               +-- outerViewportContainerLayer (fixed pos container) [frame
      container layer in RenderLayerCompositor] | 139 //  |               +-- outerViewportContainerLayer (fixed pos container) [frame
      container layer in RenderLayerCompositor] | 
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 164         m_pageScaleLayer->addChild(m_innerViewportScrollLayer.get()); | 184         m_pageScaleLayer->addChild(m_innerViewportScrollLayer.get()); | 
| 165         m_innerViewportContainerLayer->addChild(m_overlayScrollbarHorizontal.get
     ()); | 185         m_innerViewportContainerLayer->addChild(m_overlayScrollbarHorizontal.get
     ()); | 
| 166         m_innerViewportContainerLayer->addChild(m_overlayScrollbarVertical.get()
     ); | 186         m_innerViewportContainerLayer->addChild(m_overlayScrollbarVertical.get()
     ); | 
| 167 | 187 | 
| 168         // Ensure this class is set as the scroll layer's ScrollableArea | 188         // Ensure this class is set as the scroll layer's ScrollableArea | 
| 169         coordinator->scrollableAreaScrollLayerDidChange(this); | 189         coordinator->scrollableAreaScrollLayerDidChange(this); | 
| 170 | 190 | 
| 171         // Setup the inner viewport overlay scrollbars. | 191         // Setup the inner viewport overlay scrollbars. | 
| 172         setupScrollbar(WebScrollbar::Horizontal); | 192         setupScrollbar(WebScrollbar::Horizontal); | 
| 173         setupScrollbar(WebScrollbar::Vertical); | 193         setupScrollbar(WebScrollbar::Vertical); | 
|  | 194 | 
|  | 195         mainFrameDidChangeSize(); | 
| 174     } | 196     } | 
| 175 | 197 | 
| 176     m_innerViewportScrollLayer->removeAllChildren(); | 198     m_innerViewportScrollLayer->removeAllChildren(); | 
| 177     m_innerViewportScrollLayer->addChild(currentLayerTreeRoot); | 199     m_innerViewportScrollLayer->addChild(currentLayerTreeRoot); | 
| 178 | 200 | 
| 179     // We only need to disable the existing (outer viewport) scrollbars | 201     // We only need to disable the existing (outer viewport) scrollbars | 
| 180     // if the existing ones are already overlay. | 202     // if the existing ones are already overlay. | 
| 181     // FIXME: If we knew in advance before the overflowControlsHostLayer goes | 203     // FIXME: If we knew in advance before the overflowControlsHostLayer goes | 
| 182     // away, we would re-enable the drawing of these scrollbars. | 204     // away, we would re-enable the drawing of these scrollbars. | 
| 183     // FIXME: This doesn't seem to work (at least on Android). Commenting out fo
     r now until | 205     // FIXME: This doesn't seem to work (at least on Android). Commenting out fo
     r now until | 
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 253     return (orientation == HorizontalScrollbar) ? scrollDimensions.width() : scr
     ollDimensions.height(); | 275     return (orientation == HorizontalScrollbar) ? scrollDimensions.width() : scr
     ollDimensions.height(); | 
| 254 } | 276 } | 
| 255 | 277 | 
| 256 IntPoint PinchViewport::minimumScrollPosition() const | 278 IntPoint PinchViewport::minimumScrollPosition() const | 
| 257 { | 279 { | 
| 258     return IntPoint(); | 280     return IntPoint(); | 
| 259 } | 281 } | 
| 260 | 282 | 
| 261 IntPoint PinchViewport::maximumScrollPosition() const | 283 IntPoint PinchViewport::maximumScrollPosition() const | 
| 262 { | 284 { | 
| 263     // TODO: Doesn't take scale into account yet. | 285     return flooredIntPoint(FloatSize(contentsSize()) - visibleRect().size()); | 
| 264     IntPoint maxScrollPosition(contentsSize() - visibleRect().size()); |  | 
| 265     maxScrollPosition.clampNegativeToZero(); |  | 
| 266     return maxScrollPosition; |  | 
| 267 } | 286 } | 
| 268 | 287 | 
| 269 IntRect PinchViewport::scrollableAreaBoundingBox() const | 288 IntRect PinchViewport::scrollableAreaBoundingBox() const | 
| 270 { | 289 { | 
| 271     // This method should return the bounding box in the parent view's coordinat
     e | 290     // This method should return the bounding box in the parent view's coordinat
     e | 
| 272     // space; however, PinchViewport technically isn't a child of any Frames. | 291     // space; however, PinchViewport technically isn't a child of any Frames. | 
| 273     // Nonetheless, the PinchViewport always occupies the entire main frame so j
     ust | 292     // Nonetheless, the PinchViewport always occupies the entire main frame so j
     ust | 
| 274     // return that. | 293     // return that. | 
| 275     LocalFrame* frame = m_frameHost.page().mainFrame(); | 294     LocalFrame* frame = mainFrame(); | 
| 276 | 295 | 
| 277     if (!frame || !frame->view()) | 296     if (!frame || !frame->view()) | 
| 278         return IntRect(); | 297         return IntRect(); | 
| 279 | 298 | 
| 280     return frame->view()->frameRect(); | 299     return frame->view()->frameRect(); | 
| 281 } | 300 } | 
| 282 | 301 | 
| 283 IntSize PinchViewport::contentsSize() const | 302 IntSize PinchViewport::contentsSize() const | 
| 284 { | 303 { | 
| 285     LocalFrame* frame = m_frameHost.page().mainFrame(); | 304     LocalFrame* frame = mainFrame(); | 
| 286 | 305 | 
| 287     if (!frame || !frame->view()) | 306     if (!frame || !frame->view()) | 
| 288         return IntSize(); | 307         return IntSize(); | 
| 289 | 308 | 
| 290     // TODO: This will be visibleContentSize once page scale is removed from Fra
     meView | 309     ASSERT(frame->view()->visibleContentScaleFactor() == 1); | 
| 291     return frame->view()->unscaledVisibleContentSize(IncludeScrollbars); | 310     return frame->view()->visibleContentRect(IncludeScrollbars).size(); | 
| 292 } | 311 } | 
| 293 | 312 | 
| 294 void PinchViewport::invalidateScrollbarRect(Scrollbar*, const IntRect&) | 313 void PinchViewport::invalidateScrollbarRect(Scrollbar*, const IntRect&) | 
| 295 { | 314 { | 
| 296     // Do nothing. Pinch scrollbars live on the compositor thread and will | 315     // Do nothing. Pinch scrollbars live on the compositor thread and will | 
| 297     // be updated when the viewport is synced to the CC. | 316     // be updated when the viewport is synced to the CC. | 
| 298 } | 317 } | 
| 299 | 318 | 
| 300 void PinchViewport::setScrollOffset(const IntPoint& offset) | 319 void PinchViewport::setScrollOffset(const IntPoint& offset) | 
| 301 { | 320 { | 
| (...skipping 21 matching lines...) Expand all  Loading... | 
| 323 } | 342 } | 
| 324 | 343 | 
| 325 void PinchViewport::notifyAnimationStarted(const GraphicsLayer*, double monotoni
     cTime) | 344 void PinchViewport::notifyAnimationStarted(const GraphicsLayer*, double monotoni
     cTime) | 
| 326 { | 345 { | 
| 327 } | 346 } | 
| 328 | 347 | 
| 329 void PinchViewport::paintContents(const GraphicsLayer*, GraphicsContext&, Graphi
     csLayerPaintingPhase, const IntRect& inClip) | 348 void PinchViewport::paintContents(const GraphicsLayer*, GraphicsContext&, Graphi
     csLayerPaintingPhase, const IntRect& inClip) | 
| 330 { | 349 { | 
| 331 } | 350 } | 
| 332 | 351 | 
|  | 352 LocalFrame* PinchViewport::mainFrame() const | 
|  | 353 { | 
|  | 354     return m_frameHost.page().mainFrame(); | 
|  | 355 } | 
|  | 356 | 
|  | 357 FloatPoint PinchViewport::clampOffsetToBoundaries(const FloatPoint& offset) | 
|  | 358 { | 
|  | 359     FloatPoint clampedOffset(offset); | 
|  | 360     clampedOffset = clampedOffset.shrunkTo(FloatPoint(maximumScrollPosition())); | 
|  | 361     clampedOffset = clampedOffset.expandedTo(FloatPoint(minimumScrollPosition())
     ); | 
|  | 362     return clampedOffset; | 
|  | 363 } | 
|  | 364 | 
| 333 String PinchViewport::debugName(const GraphicsLayer* graphicsLayer) | 365 String PinchViewport::debugName(const GraphicsLayer* graphicsLayer) | 
| 334 { | 366 { | 
| 335     String name; | 367     String name; | 
| 336     if (graphicsLayer == m_innerViewportContainerLayer.get()) { | 368     if (graphicsLayer == m_innerViewportContainerLayer.get()) { | 
| 337         name = "Inner Viewport Container Layer"; | 369         name = "Inner Viewport Container Layer"; | 
| 338     } else if (graphicsLayer == m_pageScaleLayer.get()) { | 370     } else if (graphicsLayer == m_pageScaleLayer.get()) { | 
| 339         name =  "Page Scale Layer"; | 371         name =  "Page Scale Layer"; | 
| 340     } else if (graphicsLayer == m_innerViewportScrollLayer.get()) { | 372     } else if (graphicsLayer == m_innerViewportScrollLayer.get()) { | 
| 341         name =  "Inner Viewport Scroll Layer"; | 373         name =  "Inner Viewport Scroll Layer"; | 
| 342     } else if (graphicsLayer == m_overlayScrollbarHorizontal.get()) { | 374     } else if (graphicsLayer == m_overlayScrollbarHorizontal.get()) { | 
| 343         name =  "Overlay Scrollbar Horizontal Layer"; | 375         name =  "Overlay Scrollbar Horizontal Layer"; | 
| 344     } else if (graphicsLayer == m_overlayScrollbarVertical.get()) { | 376     } else if (graphicsLayer == m_overlayScrollbarVertical.get()) { | 
| 345         name =  "Overlay Scrollbar Vertical Layer"; | 377         name =  "Overlay Scrollbar Vertical Layer"; | 
| 346     } else { | 378     } else { | 
| 347         ASSERT_NOT_REACHED(); | 379         ASSERT_NOT_REACHED(); | 
| 348     } | 380     } | 
| 349 | 381 | 
| 350     return name; | 382     return name; | 
| 351 } | 383 } | 
| 352 | 384 | 
| 353 } // namespace WebCore | 385 } // namespace WebCore | 
| OLD | NEW | 
|---|