| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 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 * 1. Redistributions of source code must retain the above copyright | 8 * 1. 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 * | 10 * |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 */ | 27 */ |
| 28 | 28 |
| 29 #include "config.h" | 29 #include "config.h" |
| 30 #include "web/PageOverlay.h" | 30 #include "web/PageOverlay.h" |
| 31 | 31 |
| 32 #include "core/frame/Settings.h" | 32 #include "core/frame/Settings.h" |
| 33 #include "core/page/Page.h" | 33 #include "core/page/Page.h" |
| 34 #include "platform/graphics/GraphicsContext.h" | 34 #include "platform/graphics/GraphicsContext.h" |
| 35 #include "platform/graphics/GraphicsContextStateSaver.h" |
| 35 #include "platform/graphics/GraphicsLayer.h" | 36 #include "platform/graphics/GraphicsLayer.h" |
| 36 #include "platform/graphics/GraphicsLayerClient.h" | 37 #include "platform/graphics/paint/DisplayItem.h" |
| 38 #include "platform/graphics/paint/DrawingRecorder.h" |
| 37 #include "public/platform/WebLayer.h" | 39 #include "public/platform/WebLayer.h" |
| 38 #include "public/web/WebPageOverlay.h" | 40 #include "public/web/WebPageOverlay.h" |
| 39 #include "public/web/WebViewClient.h" | 41 #include "public/web/WebViewClient.h" |
| 40 #include "web/WebViewImpl.h" | 42 #include "web/WebViewImpl.h" |
| 41 | 43 |
| 42 namespace blink { | 44 namespace blink { |
| 43 | 45 |
| 44 namespace { | |
| 45 | |
| 46 WebCanvas* ToWebCanvas(GraphicsContext* gc) | |
| 47 { | |
| 48 return gc->canvas(); | |
| 49 } | |
| 50 | |
| 51 } // namespace | |
| 52 | |
| 53 PassOwnPtr<PageOverlay> PageOverlay::create(WebViewImpl* viewImpl, WebPageOverla
y* overlay) | 46 PassOwnPtr<PageOverlay> PageOverlay::create(WebViewImpl* viewImpl, WebPageOverla
y* overlay) |
| 54 { | 47 { |
| 55 return adoptPtr(new PageOverlay(viewImpl, overlay)); | 48 return adoptPtr(new PageOverlay(viewImpl, overlay)); |
| 56 } | 49 } |
| 57 | 50 |
| 51 PassOwnPtr<PageOverlay> PageOverlay::create(WebViewImpl* viewImpl, PageOverlay::
Painter* overlayPainter) |
| 52 { |
| 53 return adoptPtr(new PageOverlay(viewImpl, overlayPainter)); |
| 54 } |
| 55 |
| 58 PageOverlay::PageOverlay(WebViewImpl* viewImpl, WebPageOverlay* overlay) | 56 PageOverlay::PageOverlay(WebViewImpl* viewImpl, WebPageOverlay* overlay) |
| 59 : m_viewImpl(viewImpl) | 57 : m_viewImpl(viewImpl) |
| 60 , m_overlay(overlay) | 58 , m_overlay(overlay) |
| 59 , m_overlayPainter(nullptr) |
| 61 , m_zOrder(0) | 60 , m_zOrder(0) |
| 62 { | 61 { |
| 63 } | 62 } |
| 64 | 63 |
| 65 class OverlayGraphicsLayerClientImpl : public GraphicsLayerClient { | 64 PageOverlay::PageOverlay(WebViewImpl* viewImpl, PageOverlay::Painter* overlayPai
nter) |
| 66 public: | 65 : m_viewImpl(viewImpl) |
| 67 static PassOwnPtr<OverlayGraphicsLayerClientImpl> create(WebPageOverlay* ove
rlay) | 66 , m_overlay(nullptr) |
| 68 { | 67 , m_overlayPainter(overlayPainter) |
| 69 return adoptPtr(new OverlayGraphicsLayerClientImpl(overlay)); | 68 , m_zOrder(0) |
| 70 } | 69 { |
| 71 | 70 } |
| 72 virtual ~OverlayGraphicsLayerClientImpl() { } | |
| 73 | |
| 74 virtual void paintContents(const GraphicsLayer*, GraphicsContext& gc, Graphi
csLayerPaintingPhase, const IntRect& inClip) | |
| 75 { | |
| 76 gc.save(); | |
| 77 m_overlay->paintPageOverlay(ToWebCanvas(&gc)); | |
| 78 gc.restore(); | |
| 79 } | |
| 80 | |
| 81 virtual String debugName(const GraphicsLayer* graphicsLayer) override | |
| 82 { | |
| 83 return String("WebViewImpl Page Overlay Content Layer"); | |
| 84 } | |
| 85 | |
| 86 private: | |
| 87 explicit OverlayGraphicsLayerClientImpl(WebPageOverlay* overlay) | |
| 88 : m_overlay(overlay) | |
| 89 { | |
| 90 } | |
| 91 | |
| 92 WebPageOverlay* m_overlay; | |
| 93 }; | |
| 94 | 71 |
| 95 void PageOverlay::clear() | 72 void PageOverlay::clear() |
| 96 { | 73 { |
| 97 invalidateWebFrame(); | 74 invalidateWebFrame(); |
| 98 | 75 |
| 99 if (m_layer) { | 76 if (m_layer) { |
| 100 m_layer->removeFromParent(); | 77 m_layer->removeFromParent(); |
| 101 if (Page* page = m_viewImpl->page()) | 78 if (Page* page = m_viewImpl->page()) |
| 102 page->inspectorController().didRemovePageOverlay(m_layer.get()); | 79 page->inspectorController().didRemovePageOverlay(m_layer.get()); |
| 103 m_layer = nullptr; | 80 m_layer = nullptr; |
| 104 m_layerClient = nullptr; | |
| 105 } | 81 } |
| 106 } | 82 } |
| 107 | 83 |
| 108 void PageOverlay::update() | 84 void PageOverlay::update() |
| 109 { | 85 { |
| 110 invalidateWebFrame(); | 86 invalidateWebFrame(); |
| 111 | 87 |
| 112 if (!m_layer) { | 88 if (!m_layer) { |
| 113 m_layerClient = OverlayGraphicsLayerClientImpl::create(m_overlay); | 89 m_layer = GraphicsLayer::create(m_viewImpl->graphicsLayerFactory(), this
/* client */); |
| 114 m_layer = GraphicsLayer::create(m_viewImpl->graphicsLayerFactory(), m_la
yerClient.get()); | |
| 115 m_layer->setDrawsContent(true); | 90 m_layer->setDrawsContent(true); |
| 116 | 91 |
| 117 if (Page* page = m_viewImpl->page()) | 92 if (Page* page = m_viewImpl->page()) |
| 118 page->inspectorController().willAddPageOverlay(m_layer.get()); | 93 page->inspectorController().willAddPageOverlay(m_layer.get()); |
| 119 | 94 |
| 120 // This is required for contents of overlay to stay in sync with the pag
e while scrolling. | 95 // This is required for contents of overlay to stay in sync with the pag
e while scrolling. |
| 121 WebLayer* platformLayer = m_layer->platformLayer(); | 96 WebLayer* platformLayer = m_layer->platformLayer(); |
| 122 platformLayer->setShouldScrollOnMainThread(true); | 97 platformLayer->setShouldScrollOnMainThread(true); |
| 123 } | 98 } |
| 124 | 99 |
| 125 FloatSize size(m_viewImpl->size()); | 100 FloatSize size(m_viewImpl->size()); |
| 126 if (size != m_layer->size()) { | 101 if (size != m_layer->size()) { |
| 127 // Triggers re-adding to root layer to ensure that we are on top of | 102 // Triggers re-adding to root layer to ensure that we are on top of |
| 128 // scrollbars. | 103 // scrollbars. |
| 129 m_layer->removeFromParent(); | 104 m_layer->removeFromParent(); |
| 130 m_layer->setSize(size); | 105 m_layer->setSize(size); |
| 131 } | 106 } |
| 132 | 107 |
| 133 m_viewImpl->setOverlayLayer(m_layer.get()); | 108 m_viewImpl->setOverlayLayer(m_layer.get()); |
| 134 m_layer->setNeedsDisplay(); | 109 m_layer->setNeedsDisplay(); |
| 135 } | 110 } |
| 136 | 111 |
| 137 void PageOverlay::paintWebFrame(GraphicsContext& gc) | 112 void PageOverlay::paintWebFrame(GraphicsContext& gc) |
| 138 { | 113 { |
| 139 if (!m_viewImpl->isAcceleratedCompositingActive()) { | 114 if (m_overlay) { |
| 140 gc.save(); | 115 // We clip the painted contents to the WebViewImpl, because |
| 141 m_overlay->paintPageOverlay(ToWebCanvas(&gc)); | 116 // DrawingRecorder expects to know bounds. |
| 142 gc.restore(); | 117 DisplayItemClient displayItemClient = static_cast<DisplayItemClient>(sta
tic_cast<void*>(this)); |
| 118 IntSize size = m_viewImpl->size(); |
| 119 FloatRect clipRect(FloatPoint(0, 0), size); |
| 120 DrawingRecorder recorder(&gc, displayItemClient, DisplayItem::PageOverla
y, clipRect); |
| 121 GraphicsContextStateSaver saver(gc); |
| 122 gc.clipRect(clipRect); |
| 123 m_overlay->paintPageOverlay(gc.canvas()); |
| 124 } else if (m_overlayPainter) { |
| 125 // FIXME: Maybe we need to make the callee responsible for saving. |
| 126 // We can't save a GraphicsContext unless we have a canvas. |
| 127 m_overlayPainter->paintPageOverlay(gc); |
| 143 } | 128 } |
| 144 } | 129 } |
| 145 | 130 |
| 131 void PageOverlay::paintContents(const GraphicsLayer*, GraphicsContext& gc, Graph
icsLayerPaintingPhase, const IntRect& inClip) |
| 132 { |
| 133 paintWebFrame(gc); |
| 134 } |
| 135 |
| 136 String PageOverlay::debugName(const GraphicsLayer*) |
| 137 { |
| 138 return "WebViewImpl Page Overlay Content Layer"; |
| 139 } |
| 140 |
| 146 void PageOverlay::invalidateWebFrame() | 141 void PageOverlay::invalidateWebFrame() |
| 147 { | 142 { |
| 148 // WebPageOverlay does the actual painting of the overlay. | 143 // WebPageOverlay does the actual painting of the overlay. |
| 149 // Here we just make sure to invalidate. | 144 // Here we just make sure to invalidate. |
| 150 if (!m_viewImpl->isAcceleratedCompositingActive()) { | 145 if (!m_viewImpl->isAcceleratedCompositingActive()) { |
| 151 // FIXME: able to invalidate a smaller rect. | 146 // FIXME: able to invalidate a smaller rect. |
| 152 // FIXME: Is it important to just invalidate a smaller rect given that | 147 // FIXME: Is it important to just invalidate a smaller rect given that |
| 153 // this is not on a critical codepath? In order to do so, we'd | 148 // this is not on a critical codepath? In order to do so, we'd |
| 154 // have to take scrolling into account. | 149 // have to take scrolling into account. |
| 155 const WebSize& size = m_viewImpl->size(); | 150 const WebSize& size = m_viewImpl->size(); |
| 156 WebRect damagedRect(0, 0, size.width, size.height); | 151 WebRect damagedRect(0, 0, size.width, size.height); |
| 157 if (m_viewImpl->client()) | 152 if (m_viewImpl->client()) |
| 158 m_viewImpl->client()->didInvalidateRect(damagedRect); | 153 m_viewImpl->client()->didInvalidateRect(damagedRect); |
| 159 } | 154 } |
| 160 } | 155 } |
| 161 | 156 |
| 162 } // namespace blink | 157 } // namespace blink |
| OLD | NEW |