Skip to content
This repository was archived by the owner on Jun 24, 2022. It is now read-only.

Commit 5091529

Browse files
Refactor HighlightData
https://bugs.webkit.org/show_bug.cgi?id=217711 Reviewed by Darin Adler. HighlightData was renamed when it was used for more that selections, but more than half the file was only supposed to be used to deal with the current selection, so I've split it back out into a more reasonable set of files. Also made offsets no longer optional, as there doesn't seem to be a need. Extended the HighlightData setRenderRange into InlineTextBox, as it's a better way to calculate that does not use deprecated functions. No behavior change. * Headers.cmake: * Sources.txt: * WebCore.xcodeproj/project.pbxproj: * editing/FrameSelection.cpp: (WebCore::FrameSelection::setNeedsSelectionUpdate): (WebCore::DragCaretController::nodeWillBeRemoved): (WebCore::FrameSelection::respondToNodeModification): (WebCore::FrameSelection::willBeRemovedFromFrame): (WebCore::FrameSelection::focusedOrActiveStateChanged): (WebCore::FrameSelection::updateAppearance): * page/FrameView.cpp: (WebCore::FrameView::paintContentsForSnapshot): * platform/DragImage.cpp: (WebCore::ScopedFrameSelectionState::~ScopedFrameSelectionState): (WebCore::createDragImageForRange): * rendering/HighlightData.cpp: (WebCore::RenderRangeIterator::RenderRangeIterator): (WebCore::RenderRangeIterator::current const): (WebCore::RenderRangeIterator::next): (WebCore::RenderRangeIterator::checkForSpanner): (WebCore::rendererAfterOffset): (WebCore::HighlightData::highlightStateForRenderer): (): Deleted. (WebCore::isValidRendererForSelection): Deleted. (WebCore::containingBlockBelowView): Deleted. (WebCore::collectSelectionData): Deleted. (WebCore::HighlightData::HighlightData): Deleted. (WebCore::HighlightData::setSelection): Deleted. (WebCore::HighlightData::clearSelection): Deleted. (WebCore::HighlightData::repaintSelection const): Deleted. (WebCore::HighlightData::collectBounds const): Deleted. (WebCore::HighlightData::applySelection): Deleted. * rendering/HighlightData.h: (WebCore::RenderRange::RenderRange): (WebCore::RenderRange::start const): (WebCore::RenderRange::end const): (WebCore::RenderRange::startOffset const): (WebCore::RenderRange::endOffset const): (WebCore::RenderRange::operator== const): (WebCore::HighlightData::startOffset const): (WebCore::HighlightData::endOffset const): (WebCore::HighlightData::RenderRange::RenderRange): Deleted. (WebCore::HighlightData::RenderRange::start const): Deleted. (WebCore::HighlightData::RenderRange::end const): Deleted. (WebCore::HighlightData::RenderRange::startOffset const): Deleted. (WebCore::HighlightData::RenderRange::endOffset const): Deleted. (WebCore::HighlightData::RenderRange::operator== const): Deleted. (WebCore::HighlightData::bounds const): Deleted. (WebCore::HighlightData::boundsClippedToVisibleContent const): Deleted. * rendering/InlineTextBox.cpp: (WebCore::InlineTextBox::collectMarkedTextsForHighlights const): * rendering/RenderReplaced.cpp: (WebCore::RenderReplaced::calculateHighlightColor const): * rendering/RenderView.h: * rendering/SelectionRangeData.cpp: Copied from Source/WebCore/rendering/HighlightData.cpp. (WebCore::rendererAfterOffset): (WebCore::isValidRendererForSelection): (WebCore::containingBlockBelowView): (WebCore::collectSelectionData): (WebCore::SelectionRangeData::SelectionData): (WebCore::SelectionRangeData::set): (WebCore::SelectionRangeData::clear): (WebCore::SelectionRangeData::repaint const): (WebCore::SelectionRangeData::collectBounds const): (WebCore::SelectionRangeData::apply): * rendering/SelectionRangeData.h: Added. (WebCore::SelectionRangeData::bounds const): (WebCore::SelectionRangeData::boundsClippedToVisibleContent const): git-svn-id: http://svn.webkit.org/repository/webkit/trunk@268484 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent df4a307 commit 5091529

File tree

14 files changed

+572
-383
lines changed

14 files changed

+572
-383
lines changed

Source/WebCore/ChangeLog

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,88 @@
1+
2020-10-14 Megan Gardner <[email protected]>
2+
3+
Refactor HighlightData
4+
https://bugs.webkit.org/show_bug.cgi?id=217711
5+
6+
Reviewed by Darin Adler.
7+
8+
HighlightData was renamed when it was used for more that selections, but
9+
more than half the file was only supposed to be used to deal with the current
10+
selection, so I've split it back out into a more reasonable set of files.
11+
Also made offsets no longer optional, as there doesn't seem to be a need.
12+
Extended the HighlightData setRenderRange into InlineTextBox, as it's a better
13+
way to calculate that does not use deprecated functions.
14+
15+
No behavior change.
16+
17+
* Headers.cmake:
18+
* Sources.txt:
19+
* WebCore.xcodeproj/project.pbxproj:
20+
* editing/FrameSelection.cpp:
21+
(WebCore::FrameSelection::setNeedsSelectionUpdate):
22+
(WebCore::DragCaretController::nodeWillBeRemoved):
23+
(WebCore::FrameSelection::respondToNodeModification):
24+
(WebCore::FrameSelection::willBeRemovedFromFrame):
25+
(WebCore::FrameSelection::focusedOrActiveStateChanged):
26+
(WebCore::FrameSelection::updateAppearance):
27+
* page/FrameView.cpp:
28+
(WebCore::FrameView::paintContentsForSnapshot):
29+
* platform/DragImage.cpp:
30+
(WebCore::ScopedFrameSelectionState::~ScopedFrameSelectionState):
31+
(WebCore::createDragImageForRange):
32+
* rendering/HighlightData.cpp:
33+
(WebCore::RenderRangeIterator::RenderRangeIterator):
34+
(WebCore::RenderRangeIterator::current const):
35+
(WebCore::RenderRangeIterator::next):
36+
(WebCore::RenderRangeIterator::checkForSpanner):
37+
(WebCore::rendererAfterOffset):
38+
(WebCore::HighlightData::highlightStateForRenderer):
39+
(): Deleted.
40+
(WebCore::isValidRendererForSelection): Deleted.
41+
(WebCore::containingBlockBelowView): Deleted.
42+
(WebCore::collectSelectionData): Deleted.
43+
(WebCore::HighlightData::HighlightData): Deleted.
44+
(WebCore::HighlightData::setSelection): Deleted.
45+
(WebCore::HighlightData::clearSelection): Deleted.
46+
(WebCore::HighlightData::repaintSelection const): Deleted.
47+
(WebCore::HighlightData::collectBounds const): Deleted.
48+
(WebCore::HighlightData::applySelection): Deleted.
49+
* rendering/HighlightData.h:
50+
(WebCore::RenderRange::RenderRange):
51+
(WebCore::RenderRange::start const):
52+
(WebCore::RenderRange::end const):
53+
(WebCore::RenderRange::startOffset const):
54+
(WebCore::RenderRange::endOffset const):
55+
(WebCore::RenderRange::operator== const):
56+
(WebCore::HighlightData::startOffset const):
57+
(WebCore::HighlightData::endOffset const):
58+
(WebCore::HighlightData::RenderRange::RenderRange): Deleted.
59+
(WebCore::HighlightData::RenderRange::start const): Deleted.
60+
(WebCore::HighlightData::RenderRange::end const): Deleted.
61+
(WebCore::HighlightData::RenderRange::startOffset const): Deleted.
62+
(WebCore::HighlightData::RenderRange::endOffset const): Deleted.
63+
(WebCore::HighlightData::RenderRange::operator== const): Deleted.
64+
(WebCore::HighlightData::bounds const): Deleted.
65+
(WebCore::HighlightData::boundsClippedToVisibleContent const): Deleted.
66+
* rendering/InlineTextBox.cpp:
67+
(WebCore::InlineTextBox::collectMarkedTextsForHighlights const):
68+
* rendering/RenderReplaced.cpp:
69+
(WebCore::RenderReplaced::calculateHighlightColor const):
70+
* rendering/RenderView.h:
71+
* rendering/SelectionRangeData.cpp: Copied from Source/WebCore/rendering/HighlightData.cpp.
72+
(WebCore::rendererAfterOffset):
73+
(WebCore::isValidRendererForSelection):
74+
(WebCore::containingBlockBelowView):
75+
(WebCore::collectSelectionData):
76+
(WebCore::SelectionRangeData::SelectionData):
77+
(WebCore::SelectionRangeData::set):
78+
(WebCore::SelectionRangeData::clear):
79+
(WebCore::SelectionRangeData::repaint const):
80+
(WebCore::SelectionRangeData::collectBounds const):
81+
(WebCore::SelectionRangeData::apply):
82+
* rendering/SelectionRangeData.h: Added.
83+
(WebCore::SelectionRangeData::bounds const):
84+
(WebCore::SelectionRangeData::boundsClippedToVisibleContent const):
85+
186
2020-10-14 Antoine Quint <[email protected]>
287

388
Simplify management of LayerPropertyAnimation instances in GraphicsLayerCA

Source/WebCore/Headers.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1439,6 +1439,7 @@ set(WebCore_PRIVATE_FRAMEWORK_HEADERS
14391439
rendering/RenderWidget.h
14401440
rendering/RootInlineBox.h
14411441
rendering/ScrollAlignment.h
1442+
rendering/SelectionRangeData.h
14421443

14431444
rendering/line/LineWidth.h
14441445
rendering/line/TrailingObjects.h

Source/WebCore/Sources.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2221,6 +2221,7 @@ rendering/RenderView.cpp
22212221
rendering/RenderWidget.cpp
22222222
rendering/RootInlineBox.cpp
22232223
rendering/ScrollAlignment.cpp
2224+
rendering/SelectionRangeData.cpp
22242225
rendering/TableLayout.cpp
22252226
rendering/TextDecorationPainter.cpp
22262227
rendering/TextPaintStyle.cpp

Source/WebCore/WebCore.xcodeproj/project.pbxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1197,6 +1197,7 @@
11971197
4415292E0E1AE8A000C4A2D0 /* HTMLPlugInImageElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 4415292C0E1AE8A000C4A2D0 /* HTMLPlugInImageElement.h */; settings = {ATTRIBUTES = (Private, ); }; };
11981198
445775E520472F73008DCE5D /* LocalDefaultSystemAppearance.h in Headers */ = {isa = PBXBuildFile; fileRef = 445775E420472F73008DCE5D /* LocalDefaultSystemAppearance.h */; settings = {ATTRIBUTES = (Private, ); }; };
11991199
4463CF682212FA68001A8577 /* DataDetectorsCoreSoftLink.mm in Sources */ = {isa = PBXBuildFile; fileRef = 7C7941E21C56C29300A4C58E /* DataDetectorsCoreSoftLink.mm */; };
1200+
4465D7BD2536D05E0016666D /* SelectionRangeData.h in Headers */ = {isa = PBXBuildFile; fileRef = 44B38BF42536901A00A4458D /* SelectionRangeData.h */; settings = {ATTRIBUTES = (Private, ); }; };
12001201
446DC64824A29DAB0061F390 /* PlaybackTargetClientContextIdentifier.h in Headers */ = {isa = PBXBuildFile; fileRef = 446DC64624A29D9B0061F390 /* PlaybackTargetClientContextIdentifier.h */; settings = {ATTRIBUTES = (Private, ); }; };
12011202
4471710E205AF945000A116E /* MediaQueryParserContext.h in Headers */ = {isa = PBXBuildFile; fileRef = 4471710C205AF945000A116E /* MediaQueryParserContext.h */; settings = {ATTRIBUTES = (Private, ); }; };
12021203
447958041643B49A001E0A7F /* ParsedContentType.h in Headers */ = {isa = PBXBuildFile; fileRef = 447958031643B47B001E0A7F /* ParsedContentType.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -7923,6 +7924,8 @@
79237924
44A20DB80F84166C00B3E1FE /* WebCoreURLResponseIOS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebCoreURLResponseIOS.h; sourceTree = "<group>"; };
79247925
44A28AAB12DFB8AC00AE923B /* MathMLElementFactory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MathMLElementFactory.h; path = DerivedSources/WebCore/MathMLElementFactory.h; sourceTree = BUILT_PRODUCTS_DIR; };
79257926
44A28AAE12DFB8BF00AE923B /* MathMLNames.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MathMLNames.h; path = DerivedSources/WebCore/MathMLNames.h; sourceTree = BUILT_PRODUCTS_DIR; };
7927+
44B38BF42536901A00A4458D /* SelectionRangeData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SelectionRangeData.h; sourceTree = "<group>"; };
7928+
44B38BF925369A8800A4458D /* SelectionRangeData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SelectionRangeData.cpp; sourceTree = "<group>"; };
79267929
44C991810F3D1E0D00586670 /* ScrollbarThemeIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ScrollbarThemeIOS.mm; sourceTree = "<group>"; };
79277930
44C991850F3D1EBE00586670 /* ScrollbarThemeIOS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScrollbarThemeIOS.h; sourceTree = "<group>"; };
79287931
44C9919D0F3D210E00586670 /* ThemeIOS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ThemeIOS.h; sourceTree = "<group>"; };
@@ -29255,6 +29258,8 @@
2925529258
A8CFF5DA0A155A05000A4234 /* RootInlineBox.h */,
2925629259
5D925B650F64D4DD00B847F0 /* ScrollAlignment.cpp */,
2925729260
5D925B660F64D4DD00B847F0 /* ScrollAlignment.h */,
29261+
44B38BF925369A8800A4458D /* SelectionRangeData.cpp */,
29262+
44B38BF42536901A00A4458D /* SelectionRangeData.h */,
2925829263
E31CD750229F749500FBDA19 /* TableLayout.cpp */,
2925929264
A8CFF04C0A154F09000A4234 /* TableLayout.h */,
2926029265
0F54DCE31881051D003EEDBB /* TextAutoSizing.cpp */,
@@ -33877,6 +33882,7 @@
3387733882
974D2DA5146A535D00D51F8B /* SecurityPolicy.h in Headers */,
3387833883
2D5BC42716F882EE007048D0 /* SecurityPolicyViolationEvent.h in Headers */,
3387933884
B2C3DA2F0D006C1D00EF6F26 /* SegmentedString.h in Headers */,
33885+
4465D7BD2536D05E0016666D /* SelectionRangeData.h in Headers */,
3388033886
BEA807C90F714A0300524199 /* SelectionRect.h in Headers */,
3388133887
51405C89190B014400754F94 /* SelectionRectGatherer.h in Headers */,
3388233888
E44B4BB4141650D7002B1D8B /* SelectorChecker.h in Headers */,

Source/WebCore/editing/FrameSelection.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ void FrameSelection::setNeedsSelectionUpdate(RevealSelectionAfterUpdate revealMo
451451
m_selectionRevealMode = SelectionRevealMode::Reveal;
452452
m_pendingSelectionUpdate = true;
453453
if (RenderView* view = m_document->renderView())
454-
view->selection().clearSelection();
454+
view->selection().clear();
455455
}
456456

457457
void FrameSelection::updateAndRevealSelection(const AXTextStateChangeIntent& intent)
@@ -507,7 +507,7 @@ void DragCaretController::nodeWillBeRemoved(Node& node)
507507
return;
508508

509509
if (RenderView* view = node.document().renderView())
510-
view->selection().clearSelection();
510+
view->selection().clear();
511511

512512
clear();
513513
}
@@ -566,7 +566,7 @@ void FrameSelection::respondToNodeModification(Node& node, bool baseRemoved, boo
566566

567567
if (clearRenderTreeSelection) {
568568
if (auto* renderView = node.document().renderView()) {
569-
renderView->selection().clearSelection();
569+
renderView->selection().clear();
570570

571571
// Trigger a selection update so the selection will be set again.
572572
m_selectionRevealIntent = AXTextStateChangeIntent();
@@ -1570,7 +1570,7 @@ void FrameSelection::willBeRemovedFromFrame()
15701570
#endif
15711571

15721572
if (auto* view = m_document->renderView())
1573-
view->selection().clearSelection();
1573+
view->selection().clear();
15741574

15751575
setSelectionWithoutUpdatingAppearance(VisibleSelection(), defaultSetSelectionOptions(), AlignCursorOnScrollIfNeeded, TextGranularity::CharacterGranularity);
15761576
m_previousCaretNode = nullptr;
@@ -2058,7 +2058,7 @@ void FrameSelection::focusedOrActiveStateChanged()
20582058
// RenderObject::selectionForegroundColor() check if the frame is active,
20592059
// we have to update places those colors were painted.
20602060
if (RenderView* view = m_document->renderView())
2061-
view->selection().repaintSelection();
2061+
view->selection().repaint();
20622062

20632063
// Caret appears in the active frame.
20642064
if (activeAndFocused)
@@ -2153,7 +2153,7 @@ void FrameSelection::updateAppearance()
21532153
#endif
21542154

21552155
if (!selection.isRange()) {
2156-
view->selection().clearSelection();
2156+
view->selection().clear();
21572157
return;
21582158
}
21592159

@@ -2178,7 +2178,7 @@ void FrameSelection::updateAppearance()
21782178
RenderObject* endRenderer = endPos.deprecatedNode()->renderer();
21792179
int endOffset = endPos.deprecatedEditingOffset();
21802180
ASSERT(startOffset >= 0 && endOffset >= 0);
2181-
view->selection().setSelection({ startRenderer, endRenderer, static_cast<unsigned>(startOffset), static_cast<unsigned>(endOffset) });
2181+
view->selection().set({ startRenderer, endRenderer, static_cast<unsigned>(startOffset), static_cast<unsigned>(endOffset) });
21822182
}
21832183
}
21842184

Source/WebCore/page/FrameView.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4351,7 +4351,7 @@ void FrameView::paintContentsForSnapshot(GraphicsContext& context, const IntRect
43514351
if (shouldPaintSelection == ExcludeSelection) {
43524352
for (auto* frame = m_frame.ptr(); frame; frame = frame->tree().traverseNext(m_frame.ptr())) {
43534353
if (auto* renderView = frame->contentRenderer())
4354-
renderView->selection().clearSelection();
4354+
renderView->selection().clear();
43554355
}
43564356
}
43574357

Source/WebCore/platform/DragImage.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "Position.h"
3535
#include "RenderElement.h"
3636
#include "RenderView.h"
37+
#include "SelectionRangeData.h"
3738
#include "SimpleRange.h"
3839
#include "TextIndicator.h"
3940

@@ -143,12 +144,12 @@ struct ScopedFrameSelectionState {
143144
{
144145
if (auto* renderView = frame.contentRenderer()) {
145146
ASSERT(selection);
146-
renderView->selection().setSelection(selection.value(), HighlightData::RepaintMode::Nothing);
147+
renderView->selection().set(selection.value(), SelectionRangeData::RepaintMode::Nothing);
147148
}
148149
}
149150

150151
const Frame& frame;
151-
Optional<HighlightData::RenderRange> selection;
152+
Optional<RenderRange> selection;
152153
};
153154

154155
#if !PLATFORM(IOS_FAMILY)
@@ -185,7 +186,7 @@ DragImageRef createDragImageForRange(Frame& frame, const SimpleRange& range, boo
185186
int startOffset = start.deprecatedEditingOffset();
186187
int endOffset = end.deprecatedEditingOffset();
187188
ASSERT(startOffset >= 0 && endOffset >= 0);
188-
view->selection().setSelection({ startRenderer, endRenderer, static_cast<unsigned>(startOffset), static_cast<unsigned>(endOffset) }, HighlightData::RepaintMode::Nothing);
189+
view->selection().set({ startRenderer, endRenderer, static_cast<unsigned>(startOffset), static_cast<unsigned>(endOffset) }, SelectionRangeData::RepaintMode::Nothing);
189190
// We capture using snapshotFrameRect() because we fake up the selection using
190191
// FrameView but snapshotSelection() uses the selection from the Frame itself.
191192
return createDragImageFromSnapshot(snapshotFrameRect(frame, view->selection().boundsClippedToVisibleContent(), options), nullptr);

0 commit comments

Comments
 (0)