-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adopt more smart pointers in RenderElement #19451
Adopt more smart pointers in RenderElement #19451
Conversation
EWS run on previous version of this PR (hash 065db4c) |
Source/WebCore/page/EventHandler.cpp
Outdated
@@ -1706,7 +1700,7 @@ std::optional<Cursor> EventHandler::selectCursor(const HitTestResult& result, bo | |||
#if ENABLE(CURSOR_VISIBILITY) | |||
void EventHandler::startAutoHideCursorTimer() | |||
{ | |||
Page* page = m_frame.page(); | |||
Page* page = m_frame->page(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use checkedPage here as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes to EventHandler are not meant to be exhaustive. This patch's focus is RenderElement. I just made some changes to EventHandler store it in a CheckedPtr/CheckedRef and changing m_frame ended up making the change large.
Looking at this particular function though, you can see the page is only used to query a setting. I figure this was safe so I didn't opportunistically use CheckedPtr for the page here.
Source/WebCore/page/EventHandler.cpp
Outdated
@@ -1728,11 +1722,11 @@ void EventHandler::cancelAutoHideCursorTimer() | |||
|
|||
void EventHandler::autoHideCursorTimerFired() | |||
{ | |||
auto* view = m_frame.view(); | |||
auto* view = m_frame->view(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use RefPtr?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It only called view->isActive()
so it seemed excessive?
Source/WebCore/page/EventHandler.cpp
Outdated
MonotonicTime savedLastHandledUserGestureTimestamp; | ||
bool savedUserDidInteractWithPage = topDocument ? topDocument->userDidInteractWithPage() : false; | ||
|
||
if (m_frame.document()) | ||
savedLastHandledUserGestureTimestamp = m_frame.document()->lastHandledUserGestureTimestamp(); | ||
if (auto* document = frame->document()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use RefPtr?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We only call a trivial getter on the document so this seemed excessive.
Also note that there are still plenty of potentially unsafe pointer usage in this file. The focus on this patch is RenderElement, not EventHandler.
Source/WebCore/page/EventHandler.cpp
Outdated
@@ -4308,10 +4302,10 @@ bool EventHandler::handleDrag(const MouseEventWithHitTestResults& event, CheckDr | |||
// FIXME: Consider doing this earlier in this function as the earliest point we're sure it would be safe to drop an old drag. | |||
invalidateDataTransfer(); | |||
|
|||
if (!m_frame.document()) | |||
if (!frame->document()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can do:
RefPtr document = frame->document();
if (document)
return false;
dragState().dataTransfer = DataTransfer::createForDrag(*document);
Source/WebCore/page/EventHandler.h
Outdated
@@ -136,6 +137,10 @@ class EventHandler { | |||
explicit EventHandler(LocalFrame&); | |||
~EventHandler(); | |||
|
|||
// For CheckedPtr / CheckedRef use. | |||
void incrementPtrCount() const; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should just make EventHandler inherit from CanMakeCheckedPtr
unless this is absolutely necessary for correctness, in which case the reason should be stated in the commit message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this goes against @darinadler 's recommendation on my earlier PR?
The EventHandler is completely owned by the Frame via a UniqueRef so we don't need to increase the size of EventHandler unnecessarily. I also made EventHandler::m_frame be a CheckedRef so that the lifetime safety is bi-directional.
I don't mind either way. I merely went this way to be consistent with my earlier PR where I think Darin suggested this (the review comments were not 100% clear to me so I may have misunderstood as well).
@@ -734,7 +734,7 @@ static bool frameHasPlatformWidget(const LocalFrame& frame) | |||
PlatformMouseEvent EventHandler::currentPlatformMouseEvent() const | |||
{ | |||
NSView *windowView = nil; | |||
if (Page* page = m_frame.page()) | |||
if (Page* page = m_frame->page()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use CheckedPtr?
@@ -338,7 +338,7 @@ static bool findViewInSubviews(NSView *superview, NSView *target) | |||
if (!mouseDownView) { | |||
return nil; | |||
} | |||
auto* topFrameView = m_frame.view(); | |||
auto* topFrameView = m_frame->view(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use RefPtr?
@@ -518,7 +518,7 @@ static void selfRetainingNSScrollViewScrollWheel(NSScrollView *self, SEL selecto | |||
|
|||
void EventHandler::mouseDown(NSEvent *event, NSEvent *correspondingPressureEvent) | |||
{ | |||
auto* v = m_frame.view(); | |||
auto* v = m_frame->view(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use RefPtr?
@@ -535,7 +535,7 @@ static void selfRetainingNSScrollViewScrollWheel(NSScrollView *self, SEL selecto | |||
|
|||
void EventHandler::mouseDragged(NSEvent *event, NSEvent *correspondingPressureEvent) | |||
{ | |||
auto* v = m_frame.view(); | |||
auto* v = m_frame->view(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use RefPtr?
@@ -549,7 +549,7 @@ static void selfRetainingNSScrollViewScrollWheel(NSScrollView *self, SEL selecto | |||
|
|||
void EventHandler::mouseUp(NSEvent *event, NSEvent *correspondingPressureEvent) | |||
{ | |||
auto* v = m_frame.view(); | |||
auto* v = m_frame->view(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use RefPtr?
@@ -586,7 +586,7 @@ static void selfRetainingNSScrollViewScrollWheel(NSScrollView *self, SEL selecto | |||
*/ | |||
void EventHandler::sendFakeEventsAfterWidgetTracking(NSEvent *initiatingEvent) | |||
{ | |||
auto* view = m_frame.view(); | |||
auto* view = m_frame->view(); | |||
if (!view) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use RefPtr?
if (!page) | ||
return; | ||
|
||
auto* view = m_frame.view(); | ||
auto* view = m_frame->view(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use RefPtr?
065db4c
to
cbc9a86
Compare
EWS run on previous version of this PR (hash cbc9a86) |
cbc9a86
to
80e0df0
Compare
EWS run on previous version of this PR (hash 80e0df0) |
80e0df0
to
73eae54
Compare
EWS run on current version of this PR (hash 73eae54) |
https://bugs.webkit.org/show_bug.cgi?id=263542 Reviewed by Ryosuke Niwa. Adopt more smart pointers in RenderElement. I also made some changes to EventHandler so that we can store it in a CheckedPtr / CheckedRef. I made it forward its checked pointer count to its associated frame since it is owned by the frame. As extra safety, I made EventHandler::m_frame be a CheckedRef<Frame> which required me to update all uses of m_frame in this file. That said, the changes in EventHandler are NOT meant to be exhaustive. * Source/WebCore/dom/Document.cpp: (WebCore::Document::protectedView const): * Source/WebCore/page/EventHandler.cpp: (WebCore::EventHandler::incrementPtrCount const): (WebCore::EventHandler::decrementPtrCount const): * Source/WebCore/page/EventHandler.h: * Source/WebCore/page/LocalFrame.cpp: (WebCore::LocalFrame::checkedEventHandler): (WebCore::LocalFrame::checkedEventHandler const): (WebCore::Document::protectedView const): Deleted. * Source/WebCore/page/LocalFrame.h: * Source/WebCore/rendering/RenderElement.cpp: (WebCore::RenderElement::createFor): (WebCore::RenderElement::updateFillImages): (WebCore::RenderElement::updateShapeImage): (WebCore::RenderElement::repaintBeforeStyleChange): (WebCore::RenderElement::initializeStyle): (WebCore::RenderElement::setStyle): (WebCore::RenderElement::didAttachChild): (WebCore::RenderElement::attachRendererInternal): (WebCore::RenderElement::detachRendererInternal): (WebCore::findNextLayer): (WebCore::layerNextSiblingRespectingTopLayer): (WebCore::addLayers): (WebCore::RenderElement::removeLayers): (WebCore::RenderElement::moveLayers): (WebCore::RenderElement::layerParent const): (WebCore::RenderElement::propagateStyleToAnonymousChildren): (WebCore::RenderElement::styleWillChange): (WebCore::RenderElement::styleDidChange): (WebCore::RenderElement::insertedIntoTree): (WebCore::RenderElement::willBeRemovedFromTree): (WebCore::RenderElement::clearSubtreeLayoutRootIfNeeded const): (WebCore::RenderElement::willBeDestroyed): * Source/WebCore/rendering/RenderElement.h: * Source/WebCore/rendering/RenderObject.h: (WebCore::RenderObject::protectedFrame const): * Source/WebCore/rendering/RenderObjectInlines.h: (WebCore::RenderObject::protectedDocument const): * Source/WebCore/rendering/style/NinePieceImage.h: (WebCore::NinePieceImage::protectedImage const): * Source/WebCore/rendering/style/RenderStyle.h: * Source/WebCore/rendering/style/RenderStyleInlines.h: (WebCore::RenderStyle::protectedBackgroundLayers const): (WebCore::RenderStyle::protectedMaskLayers const): (WebCore::RenderStyle::protectedShapeOutside const): * Source/WebCore/rendering/style/ShapeValue.h: (WebCore::ShapeValue::protectedImage const): Canonical link: https://commits.webkit.org/269712@main
73eae54
to
ea4f8e5
Compare
Committed 269712@main (ea4f8e5): https://commits.webkit.org/269712@main Reviewed commits have been landed. Closing PR #19451 and removing active labels. |
ea4f8e5
73eae54