Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(754)

Side by Side Diff: third_party/WebKit/Source/core/layout/LayoutPart.cpp

Issue 2814643003: Remove FrameViewBase as base class of PluginView. (Closed)
Patch Set: fix unused var Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 2000 Simon Hausmann <hausmann@kde.org> 3 * (C) 2000 Simon Hausmann <hausmann@kde.org>
4 * (C) 2000 Stefan Schimanski (1Stein@gmx.de) 4 * (C) 2000 Stefan Schimanski (1Stein@gmx.de)
5 * Copyright (C) 2004, 2005, 2006, 2009 Apple Inc. All rights reserved. 5 * Copyright (C) 2004, 2005, 2006, 2009 Apple Inc. All rights reserved.
6 * Copyright (C) Research In Motion Limited 2011. All rights reserved. 6 * Copyright (C) Research In Motion Limited 2011. All rights reserved.
7 * 7 *
8 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public 9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version. 11 * version 2 of the License, or (at your option) any later version.
12 * 12 *
13 * This library is distributed in the hope that it will be useful, 13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details. 16 * Library General Public License for more details.
17 * 17 *
18 * You should have received a copy of the GNU Library General Public License 18 * You should have received a copy of the GNU Library General Public License
19 * along with this library; see the file COPYING.LIB. If not, write to 19 * along with this library; see the file COPYING.LIB. If not, write to
20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA. 21 * Boston, MA 02110-1301, USA.
22 * 22 *
23 */ 23 */
24 24
25 #include "core/layout/LayoutPart.h" 25 #include "core/layout/LayoutPart.h"
26 26
27 #include "core/dom/AXObjectCache.h" 27 #include "core/dom/AXObjectCache.h"
28 #include "core/frame/FrameOrPlugin.h"
28 #include "core/frame/FrameView.h" 29 #include "core/frame/FrameView.h"
29 #include "core/frame/LocalFrame.h" 30 #include "core/frame/LocalFrame.h"
30 #include "core/html/HTMLFrameElementBase.h" 31 #include "core/html/HTMLFrameElementBase.h"
31 #include "core/html/HTMLPlugInElement.h" 32 #include "core/html/HTMLPlugInElement.h"
32 #include "core/layout/HitTestResult.h" 33 #include "core/layout/HitTestResult.h"
33 #include "core/layout/LayoutAnalyzer.h" 34 #include "core/layout/LayoutAnalyzer.h"
34 #include "core/layout/LayoutView.h" 35 #include "core/layout/LayoutView.h"
35 #include "core/layout/api/LayoutAPIShim.h" 36 #include "core/layout/api/LayoutAPIShim.h"
36 #include "core/layout/api/LayoutViewItem.h" 37 #include "core/layout/api/LayoutViewItem.h"
37 #include "core/paint/PartPainter.h" 38 #include "core/paint/PartPainter.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 // we don't access it in the future. 84 // we don't access it in the future.
84 ClearNode(); 85 ClearNode();
85 Deref(); 86 Deref();
86 } 87 }
87 88
88 LayoutPart::~LayoutPart() { 89 LayoutPart::~LayoutPart() {
89 DCHECK_LE(ref_count_, 0); 90 DCHECK_LE(ref_count_, 0);
90 } 91 }
91 92
92 FrameViewBase* LayoutPart::GetFrameViewBase() const { 93 FrameViewBase* LayoutPart::GetFrameViewBase() const {
93 // Plugin FrameViewBases are stored in their DOM node. 94 // FrameViews are stored in HTMLFrameOwnerElement node.
94 Element* element = ToElement(GetNode()); 95 Element* element = ToElement(GetNode());
95 96
96 if (element && element->IsFrameOwnerElement()) 97 if (element && element->IsFrameOwnerElement())
97 return ToHTMLFrameOwnerElement(element)->OwnedWidget(); 98 return ToHTMLFrameOwnerElement(element)->OwnedWidget();
98 99
99 return nullptr; 100 return nullptr;
100 } 101 }
101 102
102 PluginView* LayoutPart::Plugin() const { 103 PluginView* LayoutPart::Plugin() const {
103 // Plugins are stored in their DOM node. 104 // Plugins are stored in their DOM node.
104 return GetNode() && IsHTMLPlugInElement(GetNode()) 105 return GetNode() && IsHTMLPlugInElement(GetNode())
105 ? ToHTMLPlugInElement(GetNode())->Plugin() 106 ? ToHTMLPlugInElement(GetNode())->Plugin()
106 : nullptr; 107 : nullptr;
107 } 108 }
108 109
109 FrameViewBase* LayoutPart::PluginOrFrame() const { 110 FrameOrPlugin* LayoutPart::GetFrameOrPlugin() const {
110 FrameViewBase* result = GetFrameViewBase(); 111 FrameOrPlugin* result = nullptr;
112 FrameViewBase* frame_view_base = GetFrameViewBase();
113 if (frame_view_base && frame_view_base->IsFrameView()) {
114 result = ToFrameView(frame_view_base);
115 }
111 if (!result) 116 if (!result)
112 result = Plugin(); 117 result = Plugin();
113 return result; 118 return result;
114 } 119 }
115 120
116 PaintLayerType LayoutPart::LayerTypeRequired() const { 121 PaintLayerType LayoutPart::LayerTypeRequired() const {
117 PaintLayerType type = LayoutReplaced::LayerTypeRequired(); 122 PaintLayerType type = LayoutReplaced::LayerTypeRequired();
118 if (type != kNoPaintLayer) 123 if (type != kNoPaintLayer)
119 return type; 124 return type;
120 return kForcedPaintLayer; 125 return kForcedPaintLayer;
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 254
250 CompositingReasons LayoutPart::AdditionalCompositingReasons() const { 255 CompositingReasons LayoutPart::AdditionalCompositingReasons() const {
251 if (RequiresAcceleratedCompositing()) 256 if (RequiresAcceleratedCompositing())
252 return kCompositingReasonIFrame; 257 return kCompositingReasonIFrame;
253 return kCompositingReasonNone; 258 return kCompositingReasonNone;
254 } 259 }
255 260
256 void LayoutPart::StyleDidChange(StyleDifference diff, 261 void LayoutPart::StyleDidChange(StyleDifference diff,
257 const ComputedStyle* old_style) { 262 const ComputedStyle* old_style) {
258 LayoutReplaced::StyleDidChange(diff, old_style); 263 LayoutReplaced::StyleDidChange(diff, old_style);
259 FrameViewBase* frame_view_base = this->PluginOrFrame(); 264 FrameOrPlugin* frame_or_plugin = GetFrameOrPlugin();
260 if (!frame_view_base) 265 if (!frame_or_plugin)
261 return; 266 return;
262 267
263 // If the iframe has custom scrollbars, recalculate their style. 268 // If the iframe has custom scrollbars, recalculate their style.
264 if (frame_view_base->IsFrameView()) 269 FrameViewBase* frame_view_base = GetFrameViewBase();
265 ToFrameView(frame_view_base)->RecalculateCustomScrollbarStyle(); 270 if (frame_view_base && frame_view_base->IsFrameView()) {
dcheng 2017/04/12 00:06:39 Maybe it would be more natural to write this as a
joelhockey 2017/04/12 04:33:00 My preferred solution is to make FrameView accessi
271 FrameView* frame_view = ToFrameView(frame_view_base);
272 frame_view->RecalculateCustomScrollbarStyle();
273 }
266 274
267 if (Style()->Visibility() != EVisibility::kVisible) { 275 if (Style()->Visibility() != EVisibility::kVisible) {
268 frame_view_base->Hide(); 276 frame_or_plugin->Hide();
269 } else { 277 } else {
270 frame_view_base->Show(); 278 frame_or_plugin->Show();
271 } 279 }
272 } 280 }
273 281
274 void LayoutPart::GetLayout() { 282 void LayoutPart::GetLayout() {
275 DCHECK(NeedsLayout()); 283 DCHECK(NeedsLayout());
276 LayoutAnalyzer::Scope analyzer(*this); 284 LayoutAnalyzer::Scope analyzer(*this);
277 ClearNeedsLayout(); 285 ClearNeedsLayout();
278 } 286 }
279 287
280 void LayoutPart::Paint(const PaintInfo& paint_info, 288 void LayoutPart::Paint(const PaintInfo& paint_info,
(...skipping 21 matching lines...) Expand all
302 // rect is snapped at the document boundary, and sub-pixel movement could 310 // rect is snapped at the document boundary, and sub-pixel movement could
303 // cause the sub-frame to layout due to the 1px snap difference. In order to 311 // cause the sub-frame to layout due to the 1px snap difference. In order to
304 // avoid that, the size of sub-frame is rounded in advance. 312 // avoid that, the size of sub-frame is rounded in advance.
305 LayoutRect size_rounded_rect = ContentBoxRect(); 313 LayoutRect size_rounded_rect = ContentBoxRect();
306 size_rounded_rect.SetSize( 314 size_rounded_rect.SetSize(
307 LayoutSize(RoundedIntSize(size_rounded_rect.size()))); 315 LayoutSize(RoundedIntSize(size_rounded_rect.size())));
308 return size_rounded_rect; 316 return size_rounded_rect;
309 } 317 }
310 318
311 void LayoutPart::UpdateOnWidgetChange() { 319 void LayoutPart::UpdateOnWidgetChange() {
312 FrameViewBase* frame_view_base = this->PluginOrFrame(); 320 FrameOrPlugin* frame_or_plugin = GetFrameOrPlugin();
313 if (!frame_view_base) 321 if (!frame_or_plugin)
314 return; 322 return;
315 323
316 if (!Style()) 324 if (!Style())
317 return; 325 return;
318 326
319 if (!NeedsLayout()) 327 if (!NeedsLayout())
320 UpdateGeometryInternal(*frame_view_base); 328 UpdateGeometryInternal(*frame_or_plugin);
321 329
322 if (Style()->Visibility() != EVisibility::kVisible) { 330 if (Style()->Visibility() != EVisibility::kVisible) {
323 frame_view_base->Hide(); 331 frame_or_plugin->Hide();
324 } else { 332 } else {
325 frame_view_base->Show(); 333 frame_or_plugin->Show();
326 // FIXME: Why do we issue a full paint invalidation in this case, but not 334 // FIXME: Why do we issue a full paint invalidation in this case, but not
327 // the other? 335 // the other?
328 SetShouldDoFullPaintInvalidation(); 336 SetShouldDoFullPaintInvalidation();
329 } 337 }
330 } 338 }
331 339
332 void LayoutPart::UpdateGeometry() { 340 void LayoutPart::UpdateGeometry() {
333 FrameViewBase* frame_view_base = this->PluginOrFrame(); 341 FrameOrPlugin* frame_or_plugin = GetFrameOrPlugin();
334 if (!frame_view_base || 342 if (!frame_or_plugin ||
335 !GetNode()) // Check the node in case destroy() has been called. 343 !GetNode()) // Check the node in case destroy() has been called.
336 return; 344 return;
337 345
338 LayoutRect new_frame = ReplacedContentRect(); 346 LayoutRect new_frame = ReplacedContentRect();
339 DCHECK(new_frame.size() == RoundedIntSize(new_frame.size())); 347 DCHECK(new_frame.size() == RoundedIntSize(new_frame.size()));
340 bool bounds_will_change = 348 bool bounds_will_change =
341 LayoutSize(frame_view_base->FrameRect().size()) != new_frame.size(); 349 LayoutSize(frame_or_plugin->FrameRect().size()) != new_frame.size();
342 350
343 FrameView* frame_view = 351 FrameViewBase* frame_view_base = GetFrameViewBase();
344 frame_view_base->IsFrameView() ? ToFrameView(frame_view_base) : nullptr; 352 FrameView* frame_view = nullptr;
353 if (frame_view_base && frame_view_base->IsFrameView()) {
dcheng 2017/04/12 00:06:39 Ditto -- it seems a bit unusual to have this null
joelhockey 2017/04/12 04:33:00 I'll clean this up as a prequel CL.
354 frame_view = ToFrameView(frame_view_base);
355 }
345 356
346 // If frame bounds are changing mark the view for layout. Also check the 357 // If frame bounds are changing mark the view for layout. Also check the
347 // frame's page to make sure that the frame isn't in the process of being 358 // frame's page to make sure that the frame isn't in the process of being
348 // destroyed. If iframe scrollbars needs reconstruction from native to custom 359 // destroyed. If iframe scrollbars needs reconstruction from native to custom
349 // scrollbar, then also we need to layout the frameview. 360 // scrollbar, then also we need to layout the frameview.
350 if (frame_view && frame_view->GetFrame().GetPage() && 361 if (frame_view && frame_view->GetFrame().GetPage() &&
351 (bounds_will_change || frame_view->NeedsScrollbarReconstruction())) 362 (bounds_will_change || frame_view->NeedsScrollbarReconstruction()))
352 frame_view->SetNeedsLayout(); 363 frame_view->SetNeedsLayout();
353 364
354 UpdateGeometryInternal(*frame_view_base); 365 UpdateGeometryInternal(*frame_or_plugin);
355 366
356 // If view needs layout, either because bounds have changed or possibly 367 // If view needs layout, either because bounds have changed or possibly
357 // indicating content size is wrong, we have to do a layout to set the right 368 // indicating content size is wrong, we have to do a layout to set the right
358 // FrameViewBase size. 369 // FrameView size.
359 if (frame_view && frame_view->NeedsLayout() && 370 if (frame_view && frame_view->NeedsLayout() &&
360 frame_view->GetFrame().GetPage()) 371 frame_view->GetFrame().GetPage())
361 frame_view->Layout(); 372 frame_view->Layout();
362 373
363 frame_view_base->GeometryMayHaveChanged(); 374 if (PluginView* plugin = Plugin())
375 plugin->GeometryMayHaveChanged();
364 } 376 }
365 377
366 void LayoutPart::UpdateGeometryInternal(FrameViewBase& frame_view_base) { 378 void LayoutPart::UpdateGeometryInternal(FrameOrPlugin& frame_or_plugin) {
367 // Ignore transform here, as we only care about the sub-pixel accumulation. 379 // Ignore transform here, as we only care about the sub-pixel accumulation.
368 // TODO(trchen): What about multicol? Need a LayoutBox function to query 380 // TODO(trchen): What about multicol? Need a LayoutBox function to query
369 // sub-pixel accumulation. 381 // sub-pixel accumulation.
370 LayoutPoint absolute_location(LocalToAbsolute(FloatPoint())); 382 LayoutPoint absolute_location(LocalToAbsolute(FloatPoint()));
371 LayoutRect absolute_replaced_rect = ReplacedContentRect(); 383 LayoutRect absolute_replaced_rect = ReplacedContentRect();
372 absolute_replaced_rect.MoveBy(absolute_location); 384 absolute_replaced_rect.MoveBy(absolute_location);
373 385
374 IntRect frame_rect(IntPoint(), 386 IntRect frame_rect(IntPoint(),
375 PixelSnappedIntRect(absolute_replaced_rect).size()); 387 PixelSnappedIntRect(absolute_replaced_rect).size());
376 // Normally the location of the frame rect is ignored by the painter, but 388 // Normally the location of the frame rect is ignored by the painter, but
377 // currently it is still used by a family of coordinate conversion function in 389 // currently it is still used by a family of coordinate conversion function in
378 // FrameViewBase/FrameView. This is incorrect because coordinate conversion 390 // FrameView. This is incorrect because coordinate conversion
379 // needs to take transform and into account. A few callers still use the 391 // needs to take transform and into account. A few callers still use the
380 // family of conversion function, including but not exhaustive: 392 // family of conversion function, including but not exhaustive:
381 // FrameView::updateViewportIntersectionIfNeeded() 393 // FrameView::updateViewportIntersectionIfNeeded()
382 // RemoteFrameView::frameRectsChanged(). 394 // RemoteFrameView::frameRectsChanged().
383 // WebPluginContainerImpl::reportGeometry() 395 // WebPluginContainerImpl::reportGeometry()
384 // TODO(trchen): Remove this hack once we fixed all callers. 396 // TODO(trchen): Remove this hack once we fixed all callers.
385 FloatRect absolute_bounding_box = 397 FloatRect absolute_bounding_box =
386 LocalToAbsoluteQuad(FloatRect(ReplacedContentRect())).BoundingBox(); 398 LocalToAbsoluteQuad(FloatRect(ReplacedContentRect())).BoundingBox();
387 frame_rect.SetLocation(RoundedIntPoint(absolute_bounding_box.Location())); 399 frame_rect.SetLocation(RoundedIntPoint(absolute_bounding_box.Location()));
388 400
389 // Why is the protector needed? 401 // Why is the protector needed?
390 RefPtr<LayoutPart> protector(this); 402 RefPtr<LayoutPart> protector(this);
391 frame_view_base.SetFrameRect(frame_rect); 403 frame_or_plugin.SetFrameRect(frame_rect);
392 } 404 }
393 405
394 void LayoutPart::InvalidatePaintOfSubtreesIfNeeded( 406 void LayoutPart::InvalidatePaintOfSubtreesIfNeeded(
395 const PaintInvalidationState& paint_invalidation_state) { 407 const PaintInvalidationState& paint_invalidation_state) {
396 if (GetFrameViewBase() && GetFrameViewBase()->IsFrameView() && 408 if (GetFrameViewBase() && GetFrameViewBase()->IsFrameView() &&
397 !IsThrottledFrameView()) { 409 !IsThrottledFrameView()) {
398 FrameView* child_frame_view = ToFrameView(GetFrameViewBase()); 410 FrameView* child_frame_view = ToFrameView(GetFrameViewBase());
399 // |childFrameView| is in another document, which could be 411 // |childFrameView| is in another document, which could be
400 // missing its LayoutView. TODO(jchaffraix): Ideally we should 412 // missing its LayoutView. TODO(jchaffraix): Ideally we should
401 // not need this code. 413 // not need this code.
(...skipping 11 matching lines...) Expand all
413 } 425 }
414 426
415 bool LayoutPart::IsThrottledFrameView() const { 427 bool LayoutPart::IsThrottledFrameView() const {
416 if (!GetFrameViewBase() || !GetFrameViewBase()->IsFrameView()) 428 if (!GetFrameViewBase() || !GetFrameViewBase()->IsFrameView())
417 return false; 429 return false;
418 const FrameView* frame_view = ToFrameView(GetFrameViewBase()); 430 const FrameView* frame_view = ToFrameView(GetFrameViewBase());
419 return frame_view->ShouldThrottleRendering(); 431 return frame_view->ShouldThrottleRendering();
420 } 432 }
421 433
422 } // namespace blink 434 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698