Commit 6194f01f authored by W. James MacLean's avatar W. James MacLean Committed by Chromium LUCI CQ

Rename VisualViewport::MainFrame() to LocalMainFrame() for readability.

The function VisualViewport::MainFrame() is often used in if-statements
to test for the existence of a *local* mainframe. But since we could
also have a remote mainframe, or no mainframe at all, the name is
ambiguous. This CL renames the function to make it clear what condition
is actually being tested.

This CL is a cleanup-refactor prior to landing a fix for the associated
issue.

Bug: 1150977
Change-Id: Id1542e46516288b15306be6ba75ff1805206ddc7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2585634Reviewed-by: default avatarDavid Bokan <bokan@chromium.org>
Commit-Queue: James MacLean <wjmaclean@chromium.org>
Cr-Commit-Position: refs/heads/master@{#836170}
parent 4cf813fb
......@@ -219,8 +219,8 @@ PaintPropertyChangeType VisualViewport::UpdatePaintPropertyNodesIfNeeded(
state.max_scroll_offset_affected_by_page_scale = true;
state.compositor_element_id = GetScrollElementId();
if (MainFrame() && MainFrame()->GetDocument()) {
Document* document = MainFrame()->GetDocument();
if (LocalMainFrame() && LocalMainFrame()->GetDocument()) {
Document* document = LocalMainFrame()->GetDocument();
bool uses_default_root_scroller =
&document->GetRootScrollerController().EffectiveRootScroller() ==
document;
......@@ -238,8 +238,8 @@ PaintPropertyChangeType VisualViewport::UpdatePaintPropertyNodesIfNeeded(
state.prevent_viewport_scrolling_from_inner = !uses_default_root_scroller;
}
if (MainFrame() &&
!MainFrame()->GetSettings()->GetThreadedScrollingEnabled()) {
if (LocalMainFrame() &&
!LocalMainFrame()->GetSettings()->GetThreadedScrollingEnabled()) {
state.main_thread_scrolling_reasons =
cc::MainThreadScrollingReason::kThreadedScrollingDisabled;
}
......@@ -325,8 +325,10 @@ PaintPropertyChangeType VisualViewport::UpdatePaintPropertyNodesIfNeeded(
parent_property_tree_state_ =
PropertyTreeStateOrAlias(*transform_parent, *clip_parent, *effect_parent);
if (change == PaintPropertyChangeType::kNodeAddedOrRemoved && MainFrame())
MainFrame()->View()->SetVisualViewportNeedsRepaint();
if (change == PaintPropertyChangeType::kNodeAddedOrRemoved &&
LocalMainFrame()) {
LocalMainFrame()->View()->SetVisualViewportNeedsRepaint();
}
return change;
}
......@@ -341,20 +343,20 @@ void VisualViewport::Trace(Visitor* visitor) const {
}
void VisualViewport::UpdateStyleAndLayout(DocumentUpdateReason reason) const {
if (!MainFrame())
if (!LocalMainFrame())
return;
if (Document* document = MainFrame()->GetDocument())
if (Document* document = LocalMainFrame()->GetDocument())
document->UpdateStyleAndLayout(reason);
}
void VisualViewport::EnqueueScrollEvent() {
if (Document* document = MainFrame()->GetDocument())
if (Document* document = LocalMainFrame()->GetDocument())
document->EnqueueVisualViewportScrollEvent();
}
void VisualViewport::EnqueueResizeEvent() {
if (Document* document = MainFrame()->GetDocument())
if (Document* document = LocalMainFrame()->GetDocument())
document->EnqueueVisualViewportResizeEvent();
}
......@@ -370,7 +372,7 @@ void VisualViewport::SetSize(const IntSize& size) {
TRACE_EVENT_INSTANT1("loading", "viewport", TRACE_EVENT_SCOPE_THREAD, "data",
ViewportToTracedValue());
if (!MainFrame())
if (!LocalMainFrame())
return;
// Need to re-compute sizes for the overlay scrollbars.
......@@ -378,7 +380,7 @@ void VisualViewport::SetSize(const IntSize& size) {
DCHECK(scrollbar_layer_vertical_);
UpdateScrollbarLayer(kHorizontalScrollbar);
UpdateScrollbarLayer(kVerticalScrollbar);
MainFrame()->View()->SetVisualViewportNeedsRepaint();
LocalMainFrame()->View()->SetVisualViewportNeedsRepaint();
}
EnqueueResizeEvent();
......@@ -433,21 +435,21 @@ void VisualViewport::SetScale(float scale) {
}
double VisualViewport::OffsetLeft() const {
if (!MainFrame())
if (!LocalMainFrame())
return 0;
UpdateStyleAndLayout(DocumentUpdateReason::kJavaScript);
return VisibleRect().X() / MainFrame()->PageZoomFactor();
return VisibleRect().X() / LocalMainFrame()->PageZoomFactor();
}
double VisualViewport::OffsetTop() const {
if (!MainFrame())
if (!LocalMainFrame())
return 0;
UpdateStyleAndLayout(DocumentUpdateReason::kJavaScript);
return VisibleRect().Y() / MainFrame()->PageZoomFactor();
return VisibleRect().Y() / LocalMainFrame()->PageZoomFactor();
}
double VisualViewport::Width() const {
......@@ -469,7 +471,7 @@ void VisualViewport::SetScaleAndLocation(float scale,
const FloatPoint& location) {
if (DidSetScaleOrLocation(scale, is_pinch_gesture_active, location)) {
NotifyRootFrameViewport();
Document* document = MainFrame()->GetDocument();
Document* document = LocalMainFrame()->GetDocument();
if (AXObjectCache* cache = document->ExistingAXObjectCache()) {
cache->HandleScaleAndLocationChanged(document);
}
......@@ -477,19 +479,19 @@ void VisualViewport::SetScaleAndLocation(float scale,
}
double VisualViewport::VisibleWidthCSSPx() const {
if (!MainFrame())
if (!LocalMainFrame())
return 0;
float zoom = MainFrame()->PageZoomFactor();
float zoom = LocalMainFrame()->PageZoomFactor();
float width_css_px = VisibleRect().Width() / zoom;
return width_css_px;
}
double VisualViewport::VisibleHeightCSSPx() const {
if (!MainFrame())
if (!LocalMainFrame())
return 0;
float zoom = MainFrame()->PageZoomFactor();
float zoom = LocalMainFrame()->PageZoomFactor();
float height_css_px = VisibleRect().Height() / zoom;
return height_css_px;
}
......@@ -497,7 +499,7 @@ double VisualViewport::VisibleHeightCSSPx() const {
bool VisualViewport::DidSetScaleOrLocation(float scale,
bool is_pinch_gesture_active,
const FloatPoint& location) {
if (!MainFrame())
if (!LocalMainFrame())
return false;
bool values_changed = false;
......@@ -539,20 +541,20 @@ bool VisualViewport::DidSetScaleOrLocation(float scale,
// ScrollingCoordinator.
if (auto* coordinator = GetPage().GetScrollingCoordinator()) {
if (scroll_layer_)
coordinator->UpdateCompositorScrollOffset(*MainFrame(), *this);
coordinator->UpdateCompositorScrollOffset(*LocalMainFrame(), *this);
}
EnqueueScrollEvent();
MainFrame()->View()->DidChangeScrollOffset();
LocalMainFrame()->View()->DidChangeScrollOffset();
values_changed = true;
}
if (!values_changed)
return false;
probe::DidChangeViewport(MainFrame());
MainFrame()->Loader().SaveScrollState();
probe::DidChangeViewport(LocalMainFrame());
LocalMainFrame()->Loader().SaveScrollState();
ClampToBoundaries();
......@@ -588,8 +590,8 @@ void VisualViewport::CreateLayers() {
InitializeScrollbars();
if (MainFrame())
coordinator->UpdateCompositorScrollOffset(*MainFrame(), *this);
if (LocalMainFrame())
coordinator->UpdateCompositorScrollOffset(*LocalMainFrame(), *this);
}
void VisualViewport::InitializeScrollbars() {
......@@ -610,7 +612,7 @@ void VisualViewport::InitializeScrollbars() {
// Ensure existing LocalFrameView scrollbars are removed if the visual
// viewport scrollbars are now supplied, or created if the visual viewport no
// longer supplies scrollbars.
LocalFrame* frame = MainFrame();
LocalFrame* frame = LocalMainFrame();
if (frame && frame->View())
frame->View()->VisualViewportScrollbarsChanged();
}
......@@ -654,7 +656,7 @@ bool VisualViewport::VisualViewportSuppliesScrollbars() const {
}
const Document* VisualViewport::GetDocument() const {
return MainFrame() ? MainFrame()->GetDocument() : nullptr;
return LocalMainFrame() ? LocalMainFrame()->GetDocument() : nullptr;
}
CompositorElementId VisualViewport::GetScrollElementId() const {
......@@ -670,9 +672,9 @@ ChromeClient* VisualViewport::GetChromeClient() const {
}
SmoothScrollSequencer* VisualViewport::GetSmoothScrollSequencer() const {
if (!MainFrame())
if (!LocalMainFrame())
return nullptr;
return &MainFrame()->GetSmoothScrollSequencer();
return &LocalMainFrame()->GetSmoothScrollSequencer();
}
void VisualViewport::SetScrollOffset(
......@@ -742,7 +744,7 @@ IntSize VisualViewport::MaximumScrollOffsetInt() const {
}
ScrollOffset VisualViewport::MaximumScrollOffset() const {
if (!MainFrame())
if (!LocalMainFrame())
return ScrollOffset();
// TODO(bokan): We probably shouldn't be storing the bounds in a float.
......@@ -768,10 +770,10 @@ ScrollOffset VisualViewport::MaximumScrollOffset() const {
IntPoint VisualViewport::ClampDocumentOffsetAtScale(const IntPoint& offset,
float scale) {
if (!MainFrame() || !MainFrame()->View())
if (!LocalMainFrame() || !LocalMainFrame()->View())
return IntPoint();
LocalFrameView* view = MainFrame()->View();
LocalFrameView* view = LocalMainFrame()->View();
FloatSize scaled_size(ExcludeScrollbars(size_));
scaled_size.Scale(1 / scale);
......@@ -805,7 +807,8 @@ float VisualViewport::BrowserControlsAdjustment() const {
bool VisualViewport::UserInputScrollable(ScrollbarOrientation) const {
// If there is a non-root fullscreen element, prevent the viewport from
// scrolling.
Document* main_document = MainFrame() ? MainFrame()->GetDocument() : nullptr;
Document* main_document =
LocalMainFrame() ? LocalMainFrame()->GetDocument() : nullptr;
if (main_document) {
Element* fullscreen_element =
Fullscreen::FullscreenElementFrom(*main_document);
......@@ -816,7 +819,7 @@ bool VisualViewport::UserInputScrollable(ScrollbarOrientation) const {
}
IntSize VisualViewport::ContentsSize() const {
LocalFrame* frame = MainFrame();
LocalFrame* frame = LocalMainFrame();
if (!frame || !frame->View())
return IntSize();
......@@ -830,11 +833,11 @@ IntRect VisualViewport::VisibleContentRect(
scoped_refptr<base::SingleThreadTaskRunner> VisualViewport::GetTimerTaskRunner()
const {
return MainFrame()->GetTaskRunner(TaskType::kInternalDefault);
return LocalMainFrame()->GetTaskRunner(TaskType::kInternalDefault);
}
mojom::blink::ColorScheme VisualViewport::UsedColorScheme() const {
if (LocalFrame* main_frame = MainFrame()) {
if (LocalFrame* main_frame = LocalMainFrame()) {
if (Document* main_document = main_frame->GetDocument())
return main_document->GetLayoutView()->StyleRef().UsedColorScheme();
}
......@@ -867,13 +870,13 @@ cc::Layer* VisualViewport::LayerForVerticalScrollbar() const {
}
RootFrameViewport* VisualViewport::GetRootFrameViewport() const {
if (!MainFrame() || !MainFrame()->View())
if (!LocalMainFrame() || !LocalMainFrame()->View())
return nullptr;
return MainFrame()->View()->GetRootFrameViewport();
return LocalMainFrame()->View()->GetRootFrameViewport();
}
LocalFrame* VisualViewport::MainFrame() const {
LocalFrame* VisualViewport::LocalMainFrame() const {
return GetPage().MainFrame() && GetPage().MainFrame()->IsLocalFrame()
? GetPage().DeprecatedLocalMainFrame()
: nullptr;
......@@ -889,7 +892,7 @@ IntSize VisualViewport::ExcludeScrollbars(const IntSize& size) const {
}
bool VisualViewport::ScheduleAnimation() {
GetPage().GetChromeClient().ScheduleAnimation(MainFrame()->View());
GetPage().GetChromeClient().ScheduleAnimation(LocalMainFrame()->View());
return true;
}
......@@ -956,10 +959,10 @@ IntPoint VisualViewport::RootFrameToViewport(
}
void VisualViewport::StartTrackingPinchStats() {
if (!MainFrame())
if (!LocalMainFrame())
return;
Document* document = MainFrame()->GetDocument();
Document* document = LocalMainFrame()->GetDocument();
if (!document)
return;
......@@ -998,10 +1001,10 @@ void VisualViewport::SendUMAMetrics() {
}
bool VisualViewport::ShouldDisableDesktopWorkarounds() const {
if (!MainFrame() || !MainFrame()->View())
if (!LocalMainFrame() || !LocalMainFrame()->View())
return false;
if (!MainFrame()->GetSettings()->GetViewportEnabled())
if (!LocalMainFrame()->GetSettings()->GetViewportEnabled())
return false;
// A document is considered adapted to small screen UAs if one of these holds:
......@@ -1011,7 +1014,7 @@ bool VisualViewport::ShouldDisableDesktopWorkarounds() const {
const PageScaleConstraints& constraints =
GetPage().GetPageScaleConstraintsSet().PageDefinedConstraints();
return MainFrame()->View()->GetLayoutSize().Width() == size_.Width() ||
return LocalMainFrame()->View()->GetLayoutSize().Width() == size_.Width() ||
(constraints.minimum_scale == constraints.maximum_scale &&
constraints.minimum_scale != -1);
}
......@@ -1041,8 +1044,8 @@ ScrollbarTheme& VisualViewport::GetPageScrollbarTheme() const {
}
PaintArtifactCompositor* VisualViewport::GetPaintArtifactCompositor() const {
if (MainFrame() && MainFrame()->View())
return MainFrame()->View()->GetPaintArtifactCompositor();
if (LocalMainFrame() && LocalMainFrame()->View())
return LocalMainFrame()->View()->GetPaintArtifactCompositor();
return nullptr;
}
......
......@@ -289,7 +289,7 @@ class CORE_EXPORT VisualViewport : public GarbageCollected<VisualViewport>,
RootFrameViewport* GetRootFrameViewport() const;
LocalFrame* MainFrame() const;
LocalFrame* LocalMainFrame() const;
Page& GetPage() const {
DCHECK(page_);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment