| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/frame/RemoteFrameView.h" | 5 #include "core/frame/RemoteFrameView.h" |
| 6 | 6 |
| 7 #include "core/dom/IntersectionObserverEntry.h" |
| 7 #include "core/frame/FrameView.h" | 8 #include "core/frame/FrameView.h" |
| 9 #include "core/frame/LocalFrame.h" |
| 8 #include "core/frame/RemoteFrame.h" | 10 #include "core/frame/RemoteFrame.h" |
| 11 #include "core/frame/RemoteFrameClient.h" |
| 9 #include "core/html/HTMLFrameOwnerElement.h" | 12 #include "core/html/HTMLFrameOwnerElement.h" |
| 13 #include "core/layout/LayoutView.h" |
| 10 #include "core/layout/api/LayoutPartItem.h" | 14 #include "core/layout/api/LayoutPartItem.h" |
| 11 | 15 |
| 12 namespace blink { | 16 namespace blink { |
| 13 | 17 |
| 14 RemoteFrameView::RemoteFrameView(RemoteFrame* remoteFrame) | 18 RemoteFrameView::RemoteFrameView(RemoteFrame* remoteFrame) |
| 15 : m_remoteFrame(remoteFrame) { | 19 : m_remoteFrame(remoteFrame) { |
| 16 ASSERT(remoteFrame); | 20 ASSERT(remoteFrame); |
| 17 } | 21 } |
| 18 | 22 |
| 19 RemoteFrameView::~RemoteFrameView() {} | 23 RemoteFrameView::~RemoteFrameView() {} |
| 20 | 24 |
| 21 void RemoteFrameView::setParent(Widget* parent) { | 25 void RemoteFrameView::setParent(Widget* parent) { |
| 22 Widget::setParent(parent); | 26 Widget::setParent(parent); |
| 23 frameRectsChanged(); | 27 frameRectsChanged(); |
| 24 } | 28 } |
| 25 | 29 |
| 26 RemoteFrameView* RemoteFrameView::create(RemoteFrame* remoteFrame) { | 30 RemoteFrameView* RemoteFrameView::create(RemoteFrame* remoteFrame) { |
| 27 RemoteFrameView* view = new RemoteFrameView(remoteFrame); | 31 RemoteFrameView* view = new RemoteFrameView(remoteFrame); |
| 28 view->show(); | 32 view->show(); |
| 29 return view; | 33 return view; |
| 30 } | 34 } |
| 31 | 35 |
| 36 void RemoteFrameView::updateRemoteViewportIntersection() { |
| 37 if (!m_remoteFrame->ownerLayoutObject()) |
| 38 return; |
| 39 |
| 40 FrameView* localRootView = |
| 41 toLocalFrame(m_remoteFrame->tree().parent())->localFrameRoot()->view(); |
| 42 if (!localRootView) |
| 43 return; |
| 44 |
| 45 // Start with rect in remote frame's coordinate space. Then |
| 46 // mapToVisualRectInAncestorSpace will move it to the local root's coordinate |
| 47 // space and account for any clip from containing elements such as a |
| 48 // scrollable div. Passing nullptr as an argument to |
| 49 // mapToVisualRectInAncestorSpace causes it to be clipped to the viewport, |
| 50 // even if there are RemoteFrame ancestors in the frame tree. |
| 51 LayoutRect rect(0, 0, frameRect().width(), frameRect().height()); |
| 52 rect.move(m_remoteFrame->ownerLayoutObject()->contentBoxOffset()); |
| 53 if (!m_remoteFrame->ownerLayoutObject()->mapToVisualRectInAncestorSpace( |
| 54 nullptr, rect)) |
| 55 return; |
| 56 IntRect rootVisibleRect = localRootView->visibleContentRect(); |
| 57 IntRect viewportIntersection(rect); |
| 58 viewportIntersection.intersect(rootVisibleRect); |
| 59 viewportIntersection.move(-localRootView->scrollOffsetInt()); |
| 60 |
| 61 // Translate the intersection rect from the root frame's coordinate space |
| 62 // to the remote frame's coordinate space. |
| 63 viewportIntersection = convertFromRootFrame(viewportIntersection); |
| 64 if (viewportIntersection != m_lastViewportIntersection) { |
| 65 m_remoteFrame->client()->updateRemoteViewportIntersection( |
| 66 viewportIntersection); |
| 67 } |
| 68 m_lastViewportIntersection = viewportIntersection; |
| 69 } |
| 70 |
| 32 void RemoteFrameView::dispose() { | 71 void RemoteFrameView::dispose() { |
| 33 HTMLFrameOwnerElement* ownerElement = m_remoteFrame->deprecatedLocalOwner(); | 72 HTMLFrameOwnerElement* ownerElement = m_remoteFrame->deprecatedLocalOwner(); |
| 34 // ownerElement can be null during frame swaps, because the | 73 // ownerElement can be null during frame swaps, because the |
| 35 // RemoteFrameView is disconnected before detachment. | 74 // RemoteFrameView is disconnected before detachment. |
| 36 if (ownerElement && ownerElement->ownedWidget() == this) | 75 if (ownerElement && ownerElement->ownedWidget() == this) |
| 37 ownerElement->setWidget(nullptr); | 76 ownerElement->setWidget(nullptr); |
| 38 Widget::dispose(); | 77 Widget::dispose(); |
| 39 } | 78 } |
| 40 | 79 |
| 41 void RemoteFrameView::invalidateRect(const IntRect& rect) { | 80 void RemoteFrameView::invalidateRect(const IntRect& rect) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 61 } | 100 } |
| 62 | 101 |
| 63 void RemoteFrameView::frameRectsChanged() { | 102 void RemoteFrameView::frameRectsChanged() { |
| 64 // Update the rect to reflect the position of the frame relative to the | 103 // Update the rect to reflect the position of the frame relative to the |
| 65 // containing local frame root. The position of the local root within | 104 // containing local frame root. The position of the local root within |
| 66 // any remote frames, if any, is accounted for by the embedder. | 105 // any remote frames, if any, is accounted for by the embedder. |
| 67 IntRect newRect = frameRect(); | 106 IntRect newRect = frameRect(); |
| 68 if (parent() && parent()->isFrameView()) | 107 if (parent() && parent()->isFrameView()) |
| 69 newRect = parent()->convertToRootFrame( | 108 newRect = parent()->convertToRootFrame( |
| 70 toFrameView(parent())->contentsToFrame(newRect)); | 109 toFrameView(parent())->contentsToFrame(newRect)); |
| 71 m_remoteFrame->frameRectsChanged(newRect); | 110 m_remoteFrame->client()->frameRectsChanged(newRect); |
| 111 |
| 112 updateRemoteViewportIntersection(); |
| 72 } | 113 } |
| 73 | 114 |
| 74 void RemoteFrameView::hide() { | 115 void RemoteFrameView::hide() { |
| 75 setSelfVisible(false); | 116 setSelfVisible(false); |
| 76 | 117 |
| 77 Widget::hide(); | 118 Widget::hide(); |
| 78 | 119 |
| 79 m_remoteFrame->visibilityChanged(false); | 120 m_remoteFrame->client()->visibilityChanged(false); |
| 80 } | 121 } |
| 81 | 122 |
| 82 void RemoteFrameView::show() { | 123 void RemoteFrameView::show() { |
| 83 setSelfVisible(true); | 124 setSelfVisible(true); |
| 84 | 125 |
| 85 Widget::show(); | 126 Widget::show(); |
| 86 | 127 |
| 87 m_remoteFrame->visibilityChanged(true); | 128 m_remoteFrame->client()->visibilityChanged(true); |
| 88 } | 129 } |
| 89 | 130 |
| 90 void RemoteFrameView::setParentVisible(bool visible) { | 131 void RemoteFrameView::setParentVisible(bool visible) { |
| 91 if (isParentVisible() == visible) | 132 if (isParentVisible() == visible) |
| 92 return; | 133 return; |
| 93 | 134 |
| 94 Widget::setParentVisible(visible); | 135 Widget::setParentVisible(visible); |
| 95 if (!isSelfVisible()) | 136 if (!isSelfVisible()) |
| 96 return; | 137 return; |
| 97 | 138 |
| 98 m_remoteFrame->visibilityChanged(isVisible()); | 139 m_remoteFrame->client()->visibilityChanged(isVisible()); |
| 99 } | 140 } |
| 100 | 141 |
| 101 DEFINE_TRACE(RemoteFrameView) { | 142 DEFINE_TRACE(RemoteFrameView) { |
| 102 visitor->trace(m_remoteFrame); | 143 visitor->trace(m_remoteFrame); |
| 103 Widget::trace(visitor); | 144 Widget::trace(visitor); |
| 104 } | 145 } |
| 105 | 146 |
| 106 } // namespace blink | 147 } // namespace blink |
| OLD | NEW |