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/frame/FrameView.h" | 7 #include "core/frame/FrameView.h" |
| 8 #include "core/frame/LocalFrame.h" |
8 #include "core/frame/RemoteFrame.h" | 9 #include "core/frame/RemoteFrame.h" |
| 10 #include "core/frame/RemoteFrameClient.h" |
9 #include "core/html/HTMLFrameOwnerElement.h" | 11 #include "core/html/HTMLFrameOwnerElement.h" |
| 12 #include "core/layout/LayoutView.h" |
10 #include "core/layout/api/LayoutPartItem.h" | 13 #include "core/layout/api/LayoutPartItem.h" |
| 14 #include "platform/geometry/IntPoint.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->tree().parent() || |
| 38 !m_remoteFrame->tree().parent()->isLocalFrame() || |
| 39 !m_remoteFrame->client() || !m_remoteFrame->ownerLayoutObject()) |
| 40 return; |
| 41 |
| 42 FrameView* parentView = toLocalFrame(m_remoteFrame->tree().parent())->view(); |
| 43 if (!parentView) |
| 44 return; |
| 45 |
| 46 // Start with rect in remote frame's coordinate space. Then |
| 47 // mapToVisualRectInAncestorSpace will move it to its parent's coordinate |
| 48 // space and account for any clip from containing elements such as a |
| 49 // scrollable div. |
| 50 LayoutRect rect(0, 0, frameRect().width(), frameRect().height()); |
| 51 if (!m_remoteFrame->ownerLayoutObject()->mapToVisualRectInAncestorSpace( |
| 52 parentView->layoutView(), rect)) |
| 53 return; |
| 54 IntRect viewportIntersection(rect); |
| 55 viewportIntersection.move(-parentView->scrollOffsetInt()); |
| 56 |
| 57 IntRect parentViewportIntersection = parentView->viewportIntersection(); |
| 58 |
| 59 viewportIntersection.intersect(parentViewportIntersection); |
| 60 // Translate the intersection rect from the parent frame's coordinate space |
| 61 // to the remote frame's coordinate space. |
| 62 viewportIntersection = convertFromContainingWidget(viewportIntersection); |
| 63 if (viewportIntersection != m_lastViewportIntersection) { |
| 64 m_remoteFrame->client()->updateRemoteViewportIntersection( |
| 65 viewportIntersection); |
| 66 } |
| 67 m_lastViewportIntersection = viewportIntersection; |
| 68 } |
| 69 |
32 void RemoteFrameView::dispose() { | 70 void RemoteFrameView::dispose() { |
33 HTMLFrameOwnerElement* ownerElement = m_remoteFrame->deprecatedLocalOwner(); | 71 HTMLFrameOwnerElement* ownerElement = m_remoteFrame->deprecatedLocalOwner(); |
34 // ownerElement can be null during frame swaps, because the | 72 // ownerElement can be null during frame swaps, because the |
35 // RemoteFrameView is disconnected before detachment. | 73 // RemoteFrameView is disconnected before detachment. |
36 if (ownerElement && ownerElement->ownedWidget() == this) | 74 if (ownerElement && ownerElement->ownedWidget() == this) |
37 ownerElement->setWidget(nullptr); | 75 ownerElement->setWidget(nullptr); |
38 Widget::dispose(); | 76 Widget::dispose(); |
39 } | 77 } |
40 | 78 |
41 void RemoteFrameView::invalidateRect(const IntRect& rect) { | 79 void RemoteFrameView::invalidateRect(const IntRect& rect) { |
(...skipping 19 matching lines...) Expand all Loading... |
61 } | 99 } |
62 | 100 |
63 void RemoteFrameView::frameRectsChanged() { | 101 void RemoteFrameView::frameRectsChanged() { |
64 // Update the rect to reflect the position of the frame relative to the | 102 // 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 | 103 // containing local frame root. The position of the local root within |
66 // any remote frames, if any, is accounted for by the embedder. | 104 // any remote frames, if any, is accounted for by the embedder. |
67 IntRect newRect = frameRect(); | 105 IntRect newRect = frameRect(); |
68 if (parent() && parent()->isFrameView()) | 106 if (parent() && parent()->isFrameView()) |
69 newRect = parent()->convertToRootFrame( | 107 newRect = parent()->convertToRootFrame( |
70 toFrameView(parent())->contentsToFrame(newRect)); | 108 toFrameView(parent())->contentsToFrame(newRect)); |
71 m_remoteFrame->frameRectsChanged(newRect); | 109 m_remoteFrame->client()->frameRectsChanged(newRect); |
| 110 |
| 111 updateRemoteViewportIntersection(); |
72 } | 112 } |
73 | 113 |
74 void RemoteFrameView::hide() { | 114 void RemoteFrameView::hide() { |
75 setSelfVisible(false); | 115 setSelfVisible(false); |
76 | 116 |
77 Widget::hide(); | 117 Widget::hide(); |
78 | 118 |
79 m_remoteFrame->visibilityChanged(false); | 119 if (m_remoteFrame->client()) |
| 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 if (m_remoteFrame->client()) |
| 129 m_remoteFrame->client()->visibilityChanged(true); |
88 } | 130 } |
89 | 131 |
90 void RemoteFrameView::setParentVisible(bool visible) { | 132 void RemoteFrameView::setParentVisible(bool visible) { |
91 if (isParentVisible() == visible) | 133 if (isParentVisible() == visible) |
92 return; | 134 return; |
93 | 135 |
94 Widget::setParentVisible(visible); | 136 Widget::setParentVisible(visible); |
95 if (!isSelfVisible()) | 137 if (!isSelfVisible()) |
96 return; | 138 return; |
97 | 139 |
98 m_remoteFrame->visibilityChanged(isVisible()); | 140 if (m_remoteFrame->client()) |
| 141 m_remoteFrame->client()->visibilityChanged(isVisible()); |
99 } | 142 } |
100 | 143 |
101 DEFINE_TRACE(RemoteFrameView) { | 144 DEFINE_TRACE(RemoteFrameView) { |
102 visitor->trace(m_remoteFrame); | 145 visitor->trace(m_remoteFrame); |
103 Widget::trace(visitor); | 146 Widget::trace(visitor); |
104 } | 147 } |
105 | 148 |
106 } // namespace blink | 149 } // namespace blink |
OLD | NEW |