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/dom/IntersectionObserverEntry.h" |
8 #include "core/frame/FrameView.h" | 8 #include "core/frame/FrameView.h" |
9 #include "core/frame/LocalFrame.h" | 9 #include "core/frame/LocalFrame.h" |
10 #include "core/frame/RemoteFrame.h" | 10 #include "core/frame/RemoteFrame.h" |
11 #include "core/frame/RemoteFrameClient.h" | 11 #include "core/frame/RemoteFrameClient.h" |
12 #include "core/html/HTMLFrameOwnerElement.h" | 12 #include "core/html/HTMLFrameOwnerElement.h" |
13 #include "core/layout/LayoutView.h" | 13 #include "core/layout/LayoutView.h" |
14 #include "core/layout/api/LayoutPartItem.h" | 14 #include "core/layout/api/LayoutPartItem.h" |
15 | 15 |
16 namespace blink { | 16 namespace blink { |
17 | 17 |
18 RemoteFrameView::RemoteFrameView(RemoteFrame* remote_frame) | 18 RemoteFrameView::RemoteFrameView(RemoteFrame* remote_frame) |
19 : remote_frame_(remote_frame) { | 19 : remote_frame_(remote_frame) { |
20 ASSERT(remote_frame); | 20 ASSERT(remote_frame); |
21 } | 21 } |
22 | 22 |
23 RemoteFrameView::~RemoteFrameView() {} | 23 RemoteFrameView::~RemoteFrameView() {} |
24 | 24 |
25 void RemoteFrameView::SetParent(FrameViewBase* parent) { | 25 void RemoteFrameView::SetParent(FrameViewBase* parent_frame_view_base) { |
26 FrameViewBase::SetParent(parent); | 26 FrameView* parent = ToFrameView(parent_frame_view_base); |
| 27 if (parent == parent_) |
| 28 return; |
| 29 |
| 30 DCHECK(!parent || !parent_); |
| 31 if (!parent || !parent->IsVisible()) |
| 32 SetParentVisible(false); |
| 33 parent_ = parent; |
| 34 if (parent && parent->IsVisible()) |
| 35 SetParentVisible(true); |
27 FrameRectsChanged(); | 36 FrameRectsChanged(); |
28 } | 37 } |
29 | 38 |
30 RemoteFrameView* RemoteFrameView::Create(RemoteFrame* remote_frame) { | 39 RemoteFrameView* RemoteFrameView::Create(RemoteFrame* remote_frame) { |
31 RemoteFrameView* view = new RemoteFrameView(remote_frame); | 40 RemoteFrameView* view = new RemoteFrameView(remote_frame); |
32 view->Show(); | 41 view->Show(); |
33 return view; | 42 return view; |
34 } | 43 } |
35 | 44 |
36 void RemoteFrameView::UpdateRemoteViewportIntersection() { | 45 void RemoteFrameView::UpdateRemoteViewportIntersection() { |
37 if (!remote_frame_->OwnerLayoutObject()) | 46 if (!remote_frame_->OwnerLayoutObject()) |
38 return; | 47 return; |
39 | 48 |
40 FrameView* local_root_view = | 49 FrameView* local_root_view = |
41 ToLocalFrame(remote_frame_->Tree().Parent())->LocalFrameRoot()->View(); | 50 ToLocalFrame(remote_frame_->Tree().Parent())->LocalFrameRoot()->View(); |
42 if (!local_root_view) | 51 if (!local_root_view) |
43 return; | 52 return; |
44 | 53 |
45 // Start with rect in remote frame's coordinate space. Then | 54 // Start with rect in remote frame's coordinate space. Then |
46 // mapToVisualRectInAncestorSpace will move it to the local root's coordinate | 55 // mapToVisualRectInAncestorSpace will move it to the local root's coordinate |
47 // space and account for any clip from containing elements such as a | 56 // space and account for any clip from containing elements such as a |
48 // scrollable div. Passing nullptr as an argument to | 57 // scrollable div. Passing nullptr as an argument to |
49 // mapToVisualRectInAncestorSpace causes it to be clipped to the viewport, | 58 // mapToVisualRectInAncestorSpace causes it to be clipped to the viewport, |
50 // even if there are RemoteFrame ancestors in the frame tree. | 59 // even if there are RemoteFrame ancestors in the frame tree. |
51 LayoutRect rect(0, 0, FrameRect().Width(), FrameRect().Height()); | 60 LayoutRect rect(0, 0, frame_rect_.Width(), frame_rect_.Height()); |
52 rect.Move(remote_frame_->OwnerLayoutObject()->ContentBoxOffset()); | 61 rect.Move(remote_frame_->OwnerLayoutObject()->ContentBoxOffset()); |
53 if (!remote_frame_->OwnerLayoutObject()->MapToVisualRectInAncestorSpace( | 62 if (!remote_frame_->OwnerLayoutObject()->MapToVisualRectInAncestorSpace( |
54 nullptr, rect)) | 63 nullptr, rect)) |
55 return; | 64 return; |
56 IntRect root_visible_rect = local_root_view->VisibleContentRect(); | 65 IntRect root_visible_rect = local_root_view->VisibleContentRect(); |
57 IntRect viewport_intersection(rect); | 66 IntRect viewport_intersection(rect); |
58 viewport_intersection.Intersect(root_visible_rect); | 67 viewport_intersection.Intersect(root_visible_rect); |
59 viewport_intersection.Move(-local_root_view->ScrollOffsetInt()); | 68 viewport_intersection.Move(-local_root_view->ScrollOffsetInt()); |
60 | 69 |
61 // Translate the intersection rect from the root frame's coordinate space | 70 // Translate the intersection rect from the root frame's coordinate space |
62 // to the remote frame's coordinate space. | 71 // to the remote frame's coordinate space. |
63 viewport_intersection = ConvertFromRootFrame(viewport_intersection); | 72 viewport_intersection = ConvertFromRootFrame(viewport_intersection); |
64 if (viewport_intersection != last_viewport_intersection_) { | 73 if (viewport_intersection != last_viewport_intersection_) { |
65 remote_frame_->Client()->UpdateRemoteViewportIntersection( | 74 remote_frame_->Client()->UpdateRemoteViewportIntersection( |
66 viewport_intersection); | 75 viewport_intersection); |
67 } | 76 } |
68 last_viewport_intersection_ = viewport_intersection; | 77 last_viewport_intersection_ = viewport_intersection; |
69 } | 78 } |
70 | 79 |
71 void RemoteFrameView::Dispose() { | 80 void RemoteFrameView::Dispose() { |
72 HTMLFrameOwnerElement* owner_element = remote_frame_->DeprecatedLocalOwner(); | 81 HTMLFrameOwnerElement* owner_element = remote_frame_->DeprecatedLocalOwner(); |
73 // ownerElement can be null during frame swaps, because the | 82 // ownerElement can be null during frame swaps, because the |
74 // RemoteFrameView is disconnected before detachment. | 83 // RemoteFrameView is disconnected before detachment. |
75 if (owner_element && owner_element->OwnedWidget() == this) | 84 if (owner_element && owner_element->OwnedWidget() == this) |
76 owner_element->SetWidget(nullptr); | 85 owner_element->SetWidget(nullptr); |
77 FrameViewBase::Dispose(); | |
78 } | 86 } |
79 | 87 |
80 void RemoteFrameView::InvalidateRect(const IntRect& rect) { | 88 void RemoteFrameView::InvalidateRect(const IntRect& rect) { |
81 LayoutPartItem layout_item = remote_frame_->OwnerLayoutItem(); | 89 LayoutPartItem layout_item = remote_frame_->OwnerLayoutItem(); |
82 if (layout_item.IsNull()) | 90 if (layout_item.IsNull()) |
83 return; | 91 return; |
84 | 92 |
85 LayoutRect repaint_rect(rect); | 93 LayoutRect repaint_rect(rect); |
86 repaint_rect.Move(layout_item.BorderLeft() + layout_item.PaddingLeft(), | 94 repaint_rect.Move(layout_item.BorderLeft() + layout_item.PaddingLeft(), |
87 layout_item.BorderTop() + layout_item.PaddingTop()); | 95 layout_item.BorderTop() + layout_item.PaddingTop()); |
88 layout_item.InvalidatePaintRectangle(repaint_rect); | 96 layout_item.InvalidatePaintRectangle(repaint_rect); |
89 } | 97 } |
90 | 98 |
91 void RemoteFrameView::SetFrameRect(const IntRect& new_rect) { | 99 void RemoteFrameView::SetFrameRect(const IntRect& frame_rect) { |
92 IntRect old_rect = FrameRect(); | 100 if (frame_rect == frame_rect_) |
93 | |
94 if (new_rect == old_rect) | |
95 return; | 101 return; |
96 | 102 |
97 FrameViewBase::SetFrameRect(new_rect); | 103 frame_rect_ = frame_rect; |
98 | |
99 FrameRectsChanged(); | 104 FrameRectsChanged(); |
100 } | 105 } |
101 | 106 |
102 void RemoteFrameView::FrameRectsChanged() { | 107 void RemoteFrameView::FrameRectsChanged() { |
103 // Update the rect to reflect the position of the frame relative to the | 108 // Update the rect to reflect the position of the frame relative to the |
104 // containing local frame root. The position of the local root within | 109 // containing local frame root. The position of the local root within |
105 // any remote frames, if any, is accounted for by the embedder. | 110 // any remote frames, if any, is accounted for by the embedder. |
106 IntRect new_rect = FrameRect(); | 111 IntRect new_rect = frame_rect_; |
107 if (const FrameView* parent = ToFrameView(Parent())) | 112 if (parent_) |
108 new_rect = parent->ConvertToRootFrame(parent->ContentsToFrame(new_rect)); | 113 new_rect = parent_->ConvertToRootFrame(parent_->ContentsToFrame(new_rect)); |
109 | |
110 remote_frame_->Client()->FrameRectsChanged(new_rect); | 114 remote_frame_->Client()->FrameRectsChanged(new_rect); |
111 | 115 |
112 UpdateRemoteViewportIntersection(); | 116 UpdateRemoteViewportIntersection(); |
113 } | 117 } |
114 | 118 |
115 void RemoteFrameView::Hide() { | 119 void RemoteFrameView::Hide() { |
116 SetSelfVisible(false); | 120 self_visible_ = false; |
117 | |
118 remote_frame_->Client()->VisibilityChanged(false); | 121 remote_frame_->Client()->VisibilityChanged(false); |
119 } | 122 } |
120 | 123 |
121 void RemoteFrameView::Show() { | 124 void RemoteFrameView::Show() { |
122 SetSelfVisible(true); | 125 self_visible_ = true; |
123 | |
124 remote_frame_->Client()->VisibilityChanged(true); | 126 remote_frame_->Client()->VisibilityChanged(true); |
125 } | 127 } |
126 | 128 |
127 void RemoteFrameView::SetParentVisible(bool visible) { | 129 void RemoteFrameView::SetParentVisible(bool visible) { |
128 if (IsParentVisible() == visible) | 130 if (parent_visible_ == visible) |
129 return; | 131 return; |
130 | 132 |
131 FrameViewBase::SetParentVisible(visible); | 133 parent_visible_ = visible; |
132 if (!IsSelfVisible()) | 134 if (!self_visible_) |
133 return; | 135 return; |
134 | 136 |
135 remote_frame_->Client()->VisibilityChanged(IsVisible()); | 137 remote_frame_->Client()->VisibilityChanged(self_visible_ && parent_visible_); |
136 } | 138 } |
137 | 139 |
138 IntRect RemoteFrameView::ConvertFromContainingFrameViewBase( | 140 IntRect RemoteFrameView::ConvertFromContainingFrameViewBase( |
139 const IntRect& parent_rect) const { | 141 const IntRect& parent_rect) const { |
140 if (const FrameView* parent = ToFrameView(Parent())) { | 142 if (const FrameView* parent = ToFrameView(Parent())) { |
141 IntRect local_rect = parent_rect; | 143 IntRect local_rect = parent_rect; |
142 local_rect.SetLocation( | 144 local_rect.SetLocation( |
143 parent->ConvertSelfToChild(this, local_rect.Location())); | 145 parent->ConvertSelfToChild(this, local_rect.Location())); |
144 return local_rect; | 146 return local_rect; |
145 } | 147 } |
146 | 148 |
147 return parent_rect; | 149 return parent_rect; |
148 } | 150 } |
149 | 151 |
150 DEFINE_TRACE(RemoteFrameView) { | 152 DEFINE_TRACE(RemoteFrameView) { |
151 visitor->Trace(remote_frame_); | 153 visitor->Trace(remote_frame_); |
152 FrameViewBase::Trace(visitor); | 154 visitor->Trace(parent_); |
153 } | 155 } |
154 | 156 |
155 } // namespace blink | 157 } // namespace blink |
OLD | NEW |