Changeset 260826 in webkit
- Timestamp:
- Apr 28, 2020 7:54:52 AM (4 years ago)
- Location:
- trunk/Source/WebKit
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit/ChangeLog
r260820 r260826 1 2020-04-28 Daniel Bates <dabates@apple.com> 2 3 [iOS] Marked text editor state only needs to be set when layout is up-to-date 4 https://bugs.webkit.org/show_bug.cgi?id=211087 5 6 Reviewed by Darin Adler. 7 8 Organize the code to reflect reality: editor state only has marked text rects if layout is 9 up-to-date. So, move these fields to from EditorState to EditorState::PostLayoutData. 10 11 While I am in this area of the code I also moved the editor state originIdentifierForPasteboard 12 to the top of the struct as it is aesthetically more pleasing to me to have the post layout 13 data last. It likely also produces better bit packing though this wasn't my primary motivation. 14 15 * Shared/EditorState.cpp: 16 (WebKit::EditorState::encode const): 17 (WebKit::EditorState::decode): 18 (WebKit::EditorState::PostLayoutData::encode const): 19 (WebKit::EditorState::PostLayoutData::decode): 20 Move encoding and decoding of marked test fields from EditorState to EditorState::PostLayoutData. 21 22 (WebKit::operator<<): Fix up code now that marked text fields are in PostLayoutData. 23 * Shared/EditorState.h: 24 * UIProcess/ios/WKContentViewInteraction.mm: 25 (-[WKContentView textFirstRect]): Update code now that this data is in the post layout data struct. 26 (-[WKContentView textLastRect]): Ditto. 27 (-[WKContentView _updateChangedSelection:]): Ditto. 28 * WebProcess/WebPage/ios/WebPageIOS.mm: 29 (WebKit::convertContentToRootViewSelectionRects): Added. 30 (WebKit::WebPage::getPlatformEditorState const): Update now that marked text fields are in the 31 post layout data struct. Simplify the early return as well: only continue if we're not missing post 32 layout data. If we're missing post layout data then we either do not have a frame view or layout is 33 not up-to-data. Either way we don't want to do anything. I also stored the FrameView in a Ref<> to 34 future proof the code should future code cause view detachment and destruction. Note that layout 35 could cause this, but the code currently covers this case. So, taking a Ref<> is about future proofing. 36 (WebKit::WebPage::getRectsForGranularityWithSelectionOffset): Update to use convertContentToRootViewSelectionRects(). 37 (WebKit::WebPage::getRectsAtSelectionOffsetWithText): Ditto. 38 (WebKit::WebPage::requestAutocorrectionData): Use Vector::map() to convert the selection rects to 39 from content to root view FloatRects. 40 (WebKit::WebPage::convertSelectionRectsToRootView): Deleted. 41 1 42 2020-04-28 Per Arne Vollan <pvollan@apple.com> 2 43 -
trunk/Source/WebKit/Shared/EditorState.cpp
r258131 r260826 1 1 /* 2 * Copyright (C) 2010 , 2011Apple Inc. All rights reserved.2 * Copyright (C) 2010-2020 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 35 35 void EditorState::encode(IPC::Encoder& encoder) const 36 36 { 37 encoder << originIdentifierForPasteboard; 37 38 encoder << shouldIgnoreSelectionChanges; 38 39 encoder << selectionIsNone; … … 44 45 encoder << hasComposition; 45 46 encoder << isMissingPostLayoutData; 46 47 47 if (!isMissingPostLayoutData) 48 48 m_postLayoutData.encode(encoder); 49 50 #if PLATFORM(IOS_FAMILY)51 encoder << firstMarkedRect;52 encoder << lastMarkedRect;53 encoder << markedText;54 #endif55 56 encoder << originIdentifierForPasteboard;57 49 } 58 50 59 51 bool EditorState::decode(IPC::Decoder& decoder, EditorState& result) 60 52 { 53 if (!decoder.decode(result.originIdentifierForPasteboard)) 54 return false; 55 61 56 if (!decoder.decode(result.shouldIgnoreSelectionChanges)) 62 57 return false; … … 90 85 return false; 91 86 } 92 93 #if PLATFORM(IOS_FAMILY)94 if (!decoder.decode(result.firstMarkedRect))95 return false;96 if (!decoder.decode(result.lastMarkedRect))97 return false;98 if (!decoder.decode(result.markedText))99 return false;100 #endif101 102 if (!decoder.decode(result.originIdentifierForPasteboard))103 return false;104 87 105 88 return true; … … 137 120 encoder << selectionStartIsAtParagraphBoundary; 138 121 encoder << selectionEndIsAtParagraphBoundary; 122 encoder << firstMarkedRect; 123 encoder << lastMarkedRect; 124 encoder << markedText; 139 125 #endif 140 126 #if PLATFORM(MAC) … … 209 195 if (!decoder.decode(result.selectionEndIsAtParagraphBoundary)) 210 196 return false; 197 if (!decoder.decode(result.firstMarkedRect)) 198 return false; 199 if (!decoder.decode(result.lastMarkedRect)) 200 return false; 201 if (!decoder.decode(result.markedText)) 202 return false; 211 203 #endif 212 204 #if PLATFORM(MAC) … … 248 240 TextStream& operator<<(TextStream& ts, const EditorState& editorState) 249 241 { 250 #if PLATFORM(IOS_FAMILY)251 if (editorState.firstMarkedRect != IntRect())252 ts.dumpProperty("firstMarkedRect", editorState.firstMarkedRect);253 if (editorState.lastMarkedRect != IntRect())254 ts.dumpProperty("lastMarkedRect", editorState.lastMarkedRect);255 if (editorState.markedText.length())256 ts.dumpProperty("markedText", editorState.markedText);257 #endif258 259 242 if (editorState.shouldIgnoreSelectionChanges) 260 243 ts.dumpProperty("shouldIgnoreSelectionChanges", editorState.shouldIgnoreSelectionChanges); … … 302 285 #endif // PLATFORM(COCOA) 303 286 #if PLATFORM(IOS_FAMILY) 287 if (editorState.postLayoutData().firstMarkedRect != IntRect()) 288 ts.dumpProperty("firstMarkedRect", editorState.postLayoutData().firstMarkedRect); 289 if (editorState.postLayoutData().lastMarkedRect != IntRect()) 290 ts.dumpProperty("lastMarkedRect", editorState.postLayoutData().lastMarkedRect); 291 if (editorState.postLayoutData().markedText.length()) 292 ts.dumpProperty("markedText", editorState.postLayoutData().markedText); 304 293 if (editorState.postLayoutData().caretRectAtEnd != IntRect()) 305 294 ts.dumpProperty("caretRectAtEnd", editorState.postLayoutData().caretRectAtEnd); -
trunk/Source/WebKit/Shared/EditorState.h
r260025 r260826 1 1 /* 2 * Copyright (C) 2010 , 2011Apple Inc. All rights reserved.2 * Copyright (C) 2010-2020 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 66 66 67 67 struct EditorState { 68 String originIdentifierForPasteboard; 68 69 bool shouldIgnoreSelectionChanges { false }; 69 70 70 bool selectionIsNone { true }; // This will be false when there is a caret selection. 71 71 bool selectionIsRange { false }; … … 76 76 bool hasComposition { false }; 77 77 bool isMissingPostLayoutData { true }; 78 79 #if PLATFORM(IOS_FAMILY)80 WebCore::IntRect firstMarkedRect;81 WebCore::IntRect lastMarkedRect;82 String markedText;83 #endif84 85 String originIdentifierForPasteboard;86 78 87 79 struct PostLayoutData { … … 115 107 bool selectionStartIsAtParagraphBoundary { false }; 116 108 bool selectionEndIsAtParagraphBoundary { false }; 109 WebCore::IntRect firstMarkedRect; 110 WebCore::IntRect lastMarkedRect; 111 String markedText; 117 112 #endif 118 113 #if PLATFORM(MAC) -
trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm
r260764 r260826 4119 4119 - (CGRect)textFirstRect 4120 4120 { 4121 return (_page->editorState().hasComposition) ? _page->editorState().firstMarkedRect : _autocorrectionData.textFirstRect;4121 return _page->editorState().hasComposition ? _page->editorState().postLayoutData().firstMarkedRect : _autocorrectionData.textFirstRect; 4122 4122 } 4123 4123 4124 4124 - (CGRect)textLastRect 4125 4125 { 4126 return (_page->editorState().hasComposition) ? _page->editorState().lastMarkedRect : _autocorrectionData.textLastRect;4126 return _page->editorState().hasComposition ? _page->editorState().postLayoutData().lastMarkedRect : _autocorrectionData.textLastRect; 4127 4127 } 4128 4128 … … 6523 6523 - (void)_updateChangedSelection:(BOOL)force 6524 6524 { 6525 auto& state = _page->editorState();6526 if ( state.isMissingPostLayoutData)6527 return; 6528 6529 auto& postLayoutData = state.postLayoutData();6530 WebKit::WKSelectionDrawingInfo selectionDrawingInfo (state);6525 auto& editorState = _page->editorState(); 6526 if (editorState.isMissingPostLayoutData) 6527 return; 6528 6529 auto& postLayoutData = editorState.postLayoutData(); 6530 WebKit::WKSelectionDrawingInfo selectionDrawingInfo { editorState }; 6531 6531 if (force || selectionDrawingInfo != _lastSelectionDrawingInfo) { 6532 6532 LOG_WITH_STREAM(Selection, stream << "_updateChangedSelection " << selectionDrawingInfo); … … 6536 6536 // FIXME: We need to figure out what to do if the selection is changed by Javascript. 6537 6537 if (_textInteractionAssistant) { 6538 _markedText = (_page->editorState().hasComposition) ? _page->editorState().markedText : String();6538 _markedText = editorState.hasComposition ? postLayoutData.markedText : String { }; 6539 6539 [_textInteractionAssistant selectionChanged]; 6540 6540 } -
trunk/Source/WebKit/WebProcess/WebPage/WebPage.h
r260820 r260826 1354 1354 void updateViewportSizeForCSSViewportUnits(); 1355 1355 1356 static void convertSelectionRectsToRootView(WebCore::FrameView*, Vector<WebCore::SelectionRect>&);1357 1358 1356 void getFocusedElementInformation(FocusedElementInformation&); 1359 1357 void platformInitializeAccessibility(); -
trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm
r260764 r260826 246 246 } 247 247 248 static void convertContentToRootViewSelectionRects(const FrameView& view, Vector<SelectionRect>& rects) 249 { 250 for (auto& rect : rects) 251 rect.setRect(view.contentsToRootView(rect.rect())); 252 } 253 248 254 void WebPage::getPlatformEditorState(Frame& frame, EditorState& result) const 249 255 { 250 256 getPlatformEditorStateCommon(frame, result); 251 257 252 FrameView* view = frame.view();253 if (!view) {254 result.isMissingPostLayoutData = true;255 return;256 }258 if (result.isMissingPostLayoutData) 259 return; 260 ASSERT(frame.view()); 261 auto& postLayoutData = result.postLayoutData(); 262 auto view = makeRef(*frame.view()); 257 263 258 264 if (frame.editor().hasComposition()) { 259 RefPtr<Range>compositionRange = frame.editor().compositionRange();265 auto compositionRange = frame.editor().compositionRange(); 260 266 Vector<WebCore::SelectionRect> compositionRects; 261 267 if (compositionRange) { 262 268 compositionRange->collectSelectionRects(compositionRects); 263 269 if (compositionRects.size()) 264 result.firstMarkedRect = view->contentsToRootView(compositionRects[0].rect());270 postLayoutData.firstMarkedRect = view->contentsToRootView(compositionRects[0].rect()); 265 271 if (compositionRects.size() > 1) 266 result.lastMarkedRect = view->contentsToRootView(compositionRects.last().rect());272 postLayoutData.lastMarkedRect = view->contentsToRootView(compositionRects.last().rect()); 267 273 else 268 result.lastMarkedRect = result.firstMarkedRect; 269 result.markedText = plainTextForContext(compositionRange.get()); 270 } 271 } 272 273 // We only set the remaining EditorState entries if layout is done as a performance optimization 274 // to avoid the need to force a synchronous layout here to compute these entries. 275 if (view->needsLayout() || result.isMissingPostLayoutData) 276 return; 277 278 auto& postLayoutData = result.postLayoutData(); 274 postLayoutData.lastMarkedRect = postLayoutData.firstMarkedRect; 275 postLayoutData.markedText = plainTextForContext(compositionRange.get()); 276 } 277 } 278 279 279 const auto& selection = frame.selection().selection(); 280 280 postLayoutData.isStableStateUpdate = m_isInStableState; … … 297 297 if (selectedRange) { 298 298 createLiveRange(*selectedRange)->collectSelectionRects(postLayoutData.selectionRects); 299 convert SelectionRectsToRootView(view, postLayoutData.selectionRects);299 convertContentToRootViewSelectionRects(view, postLayoutData.selectionRects); 300 300 selectedText = plainTextForDisplay(*selectedRange); 301 301 postLayoutData.selectedTextLength = selectedText.length(); … … 2005 2005 Vector<WebCore::SelectionRect> selectionRects; 2006 2006 range->collectSelectionRectsWithoutUnionInteriorLines(selectionRects); 2007 convert SelectionRectsToRootView(frame.view(), selectionRects);2007 convertContentToRootViewSelectionRects(*frame.view(), selectionRects); 2008 2008 send(Messages::WebPageProxy::SelectionRectsCallback(selectionRects, callbackID)); 2009 2009 } … … 2063 2063 Vector<WebCore::SelectionRect> selectionRects; 2064 2064 range->collectSelectionRectsWithoutUnionInteriorLines(selectionRects); 2065 convert SelectionRectsToRootView(frame.view(), selectionRects);2065 convertContentToRootViewSelectionRects(*frame.view(), selectionRects); 2066 2066 send(Messages::WebPageProxy::SelectionRectsCallback(selectionRects, callbackID)); 2067 2067 } … … 2258 2258 } 2259 2259 2260 void WebPage::convertSelectionRectsToRootView(FrameView* view, Vector<SelectionRect>& selectionRects)2261 {2262 for (size_t i = 0; i < selectionRects.size(); ++i) {2263 SelectionRect& currentRect = selectionRects[i];2264 currentRect.setRect(view->contentsToRootView(currentRect.rect()));2265 }2266 }2267 2268 2260 void WebPage::requestDictationContext(CallbackID callbackID) 2269 2261 { … … 2378 2370 range->collectSelectionRects(selectionRects); 2379 2371 2380 Vector<FloatRect> rectsForText; 2381 rectsForText.grow(selectionRects.size()); 2382 2383 convertSelectionRectsToRootView(frame.view(), selectionRects); 2384 for (size_t i = 0; i < selectionRects.size(); i++) 2385 rectsForText[i] = selectionRects[i].rect(); 2372 auto rootViewSelectionRects = selectionRects.map([&](const auto& selectionRect) -> FloatRect { return frame.view()->contentsToRootView(selectionRect.rect()); }); 2386 2373 2387 2374 bool multipleFonts = false; … … 2390 2377 font = coreFont->getCTFont(); 2391 2378 2392 reply({ WTFMove(r ectsForText), (__bridge UIFont *)font });2379 reply({ WTFMove(rootViewSelectionRects) , (__bridge UIFont *)font }); 2393 2380 } 2394 2381
Note: See TracChangeset
for help on using the changeset viewer.