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