Changeset 180465 in webkit
- Timestamp:
- Feb 20, 2015 4:09:48 PM (9 years ago)
- Location:
- trunk/Source
- Files:
-
- 24 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r180464 r180465 1 2015-02-20 Enrica Casucci <enrica@apple.com> 2 3 [WK2] Add support for font panel on OS X. 4 https://bugs.webkit.org/show_bug.cgi?id=141777 5 6 Reviewed by Tim Horton. 7 8 This patch adds the necessary hooks to the Editor class to support 9 the font panel. 10 11 * editing/Editor.h: 12 * editing/mac/EditorMac.mm: 13 (WebCore::Editor::applyFontStyles): 14 1 15 2015-02-20 Zalan Bujtas <zalan@apple.com> 2 16 -
trunk/Source/WebCore/editing/Editor.h
r179861 r180465 433 433 WEBCORE_EXPORT void replaceNodeFromPasteboard(Node*, const String& pasteboardName); 434 434 WEBCORE_EXPORT PassRefPtr<SharedBuffer> dataSelectionForPasteboard(const String& pasteboardName); 435 WEBCORE_EXPORT void applyFontStyles(const String& fontFamily, double fontSize, unsigned fontTraits); 435 436 #endif // !PLATFORM(IOS) 436 437 WEBCORE_EXPORT void replaceSelectionWithAttributedString(NSAttributedString *, MailBlockquoteHandling = MailBlockquoteHandling::RespectBlockquote); -
trunk/Source/WebCore/editing/mac/EditorMac.mm
r179143 r180465 28 28 29 29 #import "BlockExceptions.h" 30 #import "CSSPrimitiveValueMappings.h" 31 #import "CSSValuePool.h" 30 32 #import "CachedResourceLoader.h" 31 33 #import "ColorMac.h" … … 682 684 } 683 685 686 void Editor::applyFontStyles(const String& fontFamily, double fontSize, unsigned fontTraits) 687 { 688 Ref<MutableStyleProperties> style = MutableStyleProperties::create(); 689 style->setProperty(CSSPropertyFontFamily, cssValuePool().createFontFamilyValue(fontFamily)); 690 style->setProperty(CSSPropertyFontStyle, (fontTraits & NSFontItalicTrait) ? CSSValueItalic : CSSValueNormal); 691 style->setProperty(CSSPropertyFontWeight, cssValuePool().createValue(fontTraits & NSFontBoldTrait ? FontWeightBold : FontWeightNormal)); 692 style->setProperty(CSSPropertyFontSize, cssValuePool().createValue(fontSize, CSSPrimitiveValue::CSS_PX)); 693 applyStyleToSelection(style.ptr(), EditActionSetFont); 694 } 695 684 696 } // namespace WebCore -
trunk/Source/WebKit2/ChangeLog
r180456 r180465 1 2015-02-20 Enrica Casucci <enrica@apple.com> 2 3 [WK2] Add support for font panel on OS X. 4 https://bugs.webkit.org/show_bug.cgi?id=141777 5 6 Reviewed by Tim Horton. 7 8 This patch adds the necessary hooks to WKView to support 9 the font panel. It also includes refactoring of WebPage::editorState 10 and WebPageProxy::editorStateChanged to separate the different platform 11 specific tasks. 12 13 * Shared/EditorState.cpp: 14 (WebKit::EditorState::encode): 15 (WebKit::EditorState::decode): 16 * Shared/EditorState.h: 17 (WebKit::EditorState::EditorState): 18 * UIProcess/API/mac/WKView.mm: 19 (-[WKView _selectionChanged]): 20 (-[WKView changeFont:]): 21 * UIProcess/API/mac/WKViewInternal.h: 22 * UIProcess/PageClient.h: 23 * UIProcess/WebPageProxy.cpp: 24 (WebKit::WebPageProxy::editorStateChanged): Deleted. 25 * UIProcess/WebPageProxy.h: 26 * UIProcess/efl/WebPageProxyEfl.cpp: 27 (WebKit::WebPageProxy::editorStateChanged): 28 * UIProcess/gtk/WebPageProxyGtk.cpp: 29 (WebKit::WebPageProxy::editorStateChanged): 30 * UIProcess/ios/WebPageProxyIOS.mm: 31 (WebKit::WebPageProxy::editorStateChanged): 32 * UIProcess/mac/PageClientImpl.h: 33 * UIProcess/mac/PageClientImpl.mm: 34 (WebKit::PageClientImpl::selectionDidChange): 35 * UIProcess/mac/WebPageProxyMac.mm: 36 (WebKit::WebPageProxy::setFont): 37 (WebKit::WebPageProxy::editorStateChanged): 38 * WebProcess/WebPage/WebPage.cpp: 39 (WebKit::WebPage::editorState): 40 * WebProcess/WebPage/WebPage.h: 41 * WebProcess/WebPage/WebPage.messages.in: 42 * WebProcess/WebPage/efl/WebPageEfl.cpp: 43 (WebKit::WebPage::platformEditorState): 44 * WebProcess/WebPage/gtk/WebPageGtk.cpp: 45 (WebKit::WebPage::platformEditorState): 46 * WebProcess/WebPage/ios/WebPageIOS.mm: 47 (WebKit::WebPage::platformEditorState): 48 * WebProcess/WebPage/mac/WebPageMac.mm: 49 (WebKit::WebPage::platformEditorState): 50 (WebKit::WebPage::setFont): 51 1 52 2015-02-20 Chris Dumez <cdumez@apple.com> 2 53 -
trunk/Source/WebKit2/Shared/EditorState.cpp
r179578 r180465 42 42 encoder << isInPlugin; 43 43 encoder << hasComposition; 44 45 #if PLATFORM(MAC) 46 encoder << fontName; 47 encoder << fontSize; 48 encoder << selectionHasMultipleFonts; 49 #endif 44 50 45 51 #if PLATFORM(IOS) … … 91 97 return false; 92 98 99 #if PLATFORM(MAC) 100 if (!decoder.decode(result.fontName)) 101 return false; 102 103 if (!decoder.decode(result.fontSize)) 104 return false; 105 106 if (!decoder.decode(result.selectionHasMultipleFonts)) 107 return false; 108 #endif 109 93 110 #if PLATFORM(IOS) 94 111 if (!decoder.decode(result.isReplaceAllowed)) -
trunk/Source/WebKit2/Shared/EditorState.h
r171203 r180465 54 54 , isInPlugin(false) 55 55 , hasComposition(false) 56 #if PLATFORM(MAC) 57 , selectionHasMultipleFonts(false) 58 , fontSize(0) 59 #endif 56 60 #if PLATFORM(IOS) 57 61 , isReplaceAllowed(false) … … 75 79 bool isInPlugin; 76 80 bool hasComposition; 81 82 #if PLATFORM(MAC) 83 bool selectionHasMultipleFonts; 84 String fontName; 85 double fontSize; 86 #endif 77 87 78 88 #if PLATFORM(IOS) -
trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm
r180354 r180465 738 738 } 739 739 740 // Font panel support. 741 742 - (void)_selectionChanged 743 { 744 const EditorState& editorState = _data->_page->editorState(); 745 if (editorState.selectionIsNone || !editorState.isContentEditable) 746 return; 747 NSFont *font = [NSFont fontWithName:editorState.fontName size:editorState.fontSize]; 748 [[NSFontManager sharedFontManager] setSelectedFont:font isMultiple:editorState.selectionHasMultipleFonts]; 749 } 750 751 - (void)changeFont:(id)sender 752 { 753 NSFontManager *fontManager = [NSFontManager sharedFontManager]; 754 NSFont *font = [fontManager convertFont:[fontManager selectedFont]]; 755 if (!font) 756 return; 757 _data->_page->setFont([font familyName], [font pointSize], [[font fontDescriptor] symbolicTraits]); 758 } 759 740 760 /* 741 761 … … 746 766 Editing-related methods still unimplemented that are implemented in WebKit1: 747 767 748 - (void)changeFont:(id)sender;749 768 - (void)complete:(id)sender; 750 769 - (void)copyFont:(id)sender; -
trunk/Source/WebKit2/UIProcess/API/mac/WKViewInternal.h
r177692 r180465 88 88 - (void)_setTextIndicator:(PassRefPtr<WebCore::TextIndicator>)textIndicator fadeOut:(BOOL)fadeOut; 89 89 - (void)_setTextIndicatorAnimationProgress:(float)progress; 90 - (void)_selectionChanged; 90 91 91 92 - (void)_setAcceleratedCompositingModeRootLayer:(CALayer *)rootLayer; -
trunk/Source/WebKit2/UIProcess/PageClient.h
r178820 r180465 182 182 virtual PassRefPtr<ViewSnapshot> takeViewSnapshot() = 0; 183 183 virtual void wheelEventWasNotHandledByWebCore(const NativeWebWheelEvent&) = 0; 184 virtual void selectionDidChange() = 0; 184 185 #endif 185 186 … … 269 270 virtual void stopAssistingNode() = 0; 270 271 virtual bool isAssistingNode() = 0; 271 virtual void selectionDidChange() = 0;272 272 virtual bool interpretKeyEvent(const NativeWebKeyboardEvent&, bool isCharEvent) = 0; 273 273 virtual void positionInformationDidChange(const InteractionInformationAtPosition&) = 0; -
trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp
r180354 r180465 3759 3759 } 3760 3760 3761 void WebPageProxy::editorStateChanged(const EditorState& editorState)3762 {3763 #if PLATFORM(COCOA)3764 bool couldChangeSecureInputState = m_editorState.isInPasswordField != editorState.isInPasswordField || m_editorState.selectionIsNone;3765 #endif3766 #if PLATFORM(MAC) && !USE(ASYNC_NSTEXTINPUTCLIENT)3767 bool closedComposition = !editorState.shouldIgnoreCompositionSelectionChange && !editorState.hasComposition && (m_editorState.hasComposition || m_temporarilyClosedComposition);3768 m_temporarilyClosedComposition = editorState.shouldIgnoreCompositionSelectionChange && (m_temporarilyClosedComposition || m_editorState.hasComposition) && !editorState.hasComposition;3769 bool editabilityChanged = m_editorState.isContentEditable != editorState.isContentEditable;3770 #endif3771 3772 m_editorState = editorState;3773 3774 #if PLATFORM(COCOA)3775 // Selection being none is a temporary state when editing. Flipping secure input state too quickly was causing trouble (not fully understood).3776 if (couldChangeSecureInputState && !editorState.selectionIsNone)3777 m_pageClient.updateSecureInputState();3778 #endif3779 3780 if (editorState.shouldIgnoreCompositionSelectionChange)3781 return;3782 3783 #if PLATFORM(MAC) && !USE(ASYNC_NSTEXTINPUTCLIENT)3784 if (closedComposition)3785 m_pageClient.notifyInputContextAboutDiscardedComposition();3786 if (editabilityChanged) {3787 // This is only needed in sync code path, because AppKit automatically refreshes input context for async clients (<rdar://problem/18604360>).3788 m_pageClient.notifyApplicationAboutInputContextChange();3789 }3790 if (editorState.hasComposition) {3791 // Abandon the current inline input session if selection changed for any other reason but an input method changing the composition.3792 // FIXME: This logic should be in WebCore, no need to round-trip to UI process to cancel the composition.3793 cancelComposition();3794 m_pageClient.notifyInputContextAboutDiscardedComposition();3795 }3796 #elif PLATFORM(IOS)3797 // We always need to notify the client on iOS to make sure the selection is redrawn,3798 // even during composition to support phrase boundary gesture.3799 notifyRevealedSelection();3800 #elif PLATFORM(EFL) || PLATFORM(GTK)3801 m_pageClient.updateTextInputState();3802 #endif3803 }3804 3805 3761 void WebPageProxy::compositionWasCanceled(const EditorState& editorState) 3806 3762 { -
trunk/Source/WebKit2/UIProcess/WebPageProxy.h
r180115 r180465 539 539 void insertDictatedTextAsync(const String& text, const EditingRange& replacementRange, const Vector<WebCore::TextAlternativeWithRange>& dictationAlternatives, bool registerUndoGroup); 540 540 void attributedSubstringForCharacterRangeAsync(const EditingRange&, std::function<void (const AttributedString&, const EditingRange&, CallbackBase::Error)>); 541 void setFont(const String& fontFamily, double fontSize, uint64_t fontTraits); 541 542 542 543 #if !USE(ASYNC_NSTEXTINPUTCLIENT) -
trunk/Source/WebKit2/UIProcess/efl/WebPageProxyEfl.cpp
r175098 r180465 84 84 } 85 85 86 void WebPageProxy::editorStateChanged(const EditorState& editorState) 87 { 88 m_editorState = editorState; 89 90 if (editorState.shouldIgnoreCompositionSelectionChange) 91 return; 92 m_pageClient.updateTextInputState(); 93 } 94 86 95 void WebPageProxy::setThemePath(const String& themePath) 87 96 { -
trunk/Source/WebKit2/UIProcess/gtk/WebPageProxyGtk.cpp
r176954 r180465 77 77 } 78 78 79 void WebPageProxy::editorStateChanged(const EditorState& editorState) 80 { 81 m_editorState = editorState; 82 83 if (editorState.shouldIgnoreCompositionSelectionChange) 84 return; 85 m_pageClient.updateTextInputState(); 86 } 87 79 88 #if PLUGIN_ARCHITECTURE(X11) 80 89 typedef HashMap<uint64_t, GtkWidget* > PluginWindowMap; -
trunk/Source/WebKit2/UIProcess/ios/WebPageProxyIOS.mm
r178980 r180465 885 885 } 886 886 887 void WebPageProxy::editorStateChanged(const EditorState& editorState) 888 { 889 bool couldChangeSecureInputState = m_editorState.isInPasswordField != editorState.isInPasswordField || m_editorState.selectionIsNone; 890 891 m_editorState = editorState; 892 893 // Selection being none is a temporary state when editing. Flipping secure input state too quickly was causing trouble (not fully understood). 894 if (couldChangeSecureInputState && !editorState.selectionIsNone) 895 m_pageClient.updateSecureInputState(); 896 897 if (editorState.shouldIgnoreCompositionSelectionChange) 898 return; 899 900 // We always need to notify the client on iOS to make sure the selection is redrawn, 901 // even during composition to support phrase boundary gesture. 902 notifyRevealedSelection(); 903 } 904 887 905 #if USE(QUICK_LOOK) 888 906 -
trunk/Source/WebKit2/UIProcess/mac/PageClientImpl.h
r180441 r180465 99 99 virtual void resetSecureInputState() override; 100 100 virtual void notifyInputContextAboutDiscardedComposition() override; 101 virtual void selectionDidChange(); 101 102 #if PLATFORM(MAC) && !USE(ASYNC_NSTEXTINPUTCLIENT) 102 103 virtual void notifyApplicationAboutInputContextChange() override; -
trunk/Source/WebKit2/UIProcess/mac/PageClientImpl.mm
r179409 r180465 532 532 } 533 533 534 void PageClientImpl::selectionDidChange() 535 { 536 [m_wkView _selectionChanged]; 537 } 538 534 539 void PageClientImpl::wheelEventWasNotHandledByWebCore(const NativeWebWheelEvent& event) 535 540 { -
trunk/Source/WebKit2/UIProcess/mac/WebPageProxyMac.mm
r180076 r180465 666 666 return applicationIsAppleMail(); 667 667 } 668 669 void WebPageProxy::setFont(const String& fontFamily, double fontSize, uint64_t fontTraits) 670 { 671 if (!isValid()) 672 return; 673 674 process().send(Messages::WebPage::SetFont(fontFamily, fontSize, fontTraits), m_pageID); 675 } 676 677 void WebPageProxy::editorStateChanged(const EditorState& editorState) 678 { 679 bool couldChangeSecureInputState = m_editorState.isInPasswordField != editorState.isInPasswordField || m_editorState.selectionIsNone; 680 #if !USE(ASYNC_NSTEXTINPUTCLIENT) 681 bool closedComposition = !editorState.shouldIgnoreCompositionSelectionChange && !editorState.hasComposition && (m_editorState.hasComposition || m_temporarilyClosedComposition); 682 m_temporarilyClosedComposition = editorState.shouldIgnoreCompositionSelectionChange && (m_temporarilyClosedComposition || m_editorState.hasComposition) && !editorState.hasComposition; 683 bool editabilityChanged = m_editorState.isContentEditable != editorState.isContentEditable; 684 #endif 685 686 m_editorState = editorState; 687 688 // Selection being none is a temporary state when editing. Flipping secure input state too quickly was causing trouble (not fully understood). 689 if (couldChangeSecureInputState && !editorState.selectionIsNone) 690 m_pageClient.updateSecureInputState(); 691 692 if (editorState.shouldIgnoreCompositionSelectionChange) 693 return; 694 695 m_pageClient.selectionDidChange(); 696 697 #if !USE(ASYNC_NSTEXTINPUTCLIENT) 698 if (closedComposition) 699 m_pageClient.notifyInputContextAboutDiscardedComposition(); 700 if (editabilityChanged) { 701 // This is only needed in sync code path, because AppKit automatically refreshes input context for async clients (<rdar://problem/18604360>). 702 m_pageClient.notifyApplicationAboutInputContextChange(); 703 } 704 if (editorState.hasComposition) { 705 // Abandon the current inline input session if selection changed for any other reason but an input method changing the composition. 706 // FIXME: This logic should be in WebCore, no need to round-trip to UI process to cancel the composition. 707 cancelComposition(); 708 m_pageClient.notifyInputContextAboutDiscardedComposition(); 709 } 710 #endif 711 } 668 712 669 713 } // namespace WebKit -
trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp
r180416 r180465 765 765 result.hasComposition = frame.editor().hasComposition(); 766 766 result.shouldIgnoreCompositionSelectionChange = frame.editor().ignoreCompositionSelectionChange(); 767 768 #if PLATFORM(IOS) 769 if (frame.editor().hasComposition()) { 770 RefPtr<Range> compositionRange = frame.editor().compositionRange(); 771 Vector<WebCore::SelectionRect> compositionRects; 772 compositionRange->collectSelectionRects(compositionRects); 773 if (compositionRects.size()) 774 result.firstMarkedRect = compositionRects[0].rect(); 775 if (compositionRects.size() > 1) 776 result.lastMarkedRect = compositionRects.last().rect(); 777 else 778 result.lastMarkedRect = result.firstMarkedRect; 779 result.markedText = plainTextReplacingNoBreakSpace(compositionRange.get()); 780 } 781 FrameView* view = frame.view(); 782 if (selection.isCaret()) { 783 result.caretRectAtStart = view->contentsToRootView(frame.selection().absoluteCaretBounds()); 784 result.caretRectAtEnd = result.caretRectAtStart; 785 // FIXME: The following check should take into account writing direction. 786 result.isReplaceAllowed = result.isContentEditable && atBoundaryOfGranularity(selection.start(), WordGranularity, DirectionForward); 787 result.wordAtSelection = plainTextReplacingNoBreakSpace(wordRangeFromPosition(selection.start()).get()); 788 if (selection.isContentEditable()) { 789 charactersAroundPosition(selection.start(), result.characterAfterSelection, result.characterBeforeSelection, result.twoCharacterBeforeSelection); 790 Node* root = selection.rootEditableElement(); 791 result.hasContent = root && root->hasChildNodes() && !isEndOfEditableOrNonEditableContent(firstPositionInNode(root)); 792 } 793 } else if (selection.isRange()) { 794 result.caretRectAtStart = view->contentsToRootView(VisiblePosition(selection.start()).absoluteCaretBounds()); 795 result.caretRectAtEnd = view->contentsToRootView(VisiblePosition(selection.end()).absoluteCaretBounds()); 796 RefPtr<Range> selectedRange = selection.toNormalizedRange(); 797 selectedRange->collectSelectionRects(result.selectionRects); 798 convertSelectionRectsToRootView(view, result.selectionRects); 799 String selectedText = plainTextReplacingNoBreakSpace(selectedRange.get(), TextIteratorDefaultBehavior, true); 800 // FIXME: We should disallow replace when the string contains only CJ characters. 801 result.isReplaceAllowed = result.isContentEditable && !result.isInPasswordField && !selectedText.containsOnlyWhitespace(); 802 result.selectedTextLength = selectedText.length(); 803 const int maxSelectedTextLength = 200; 804 if (selectedText.length() <= maxSelectedTextLength) 805 result.wordAtSelection = selectedText; 806 } 807 if (!selection.isNone()) { 808 Node* nodeToRemove; 809 if (RenderStyle* style = Editor::styleForSelectionStart(&frame, nodeToRemove)) { 810 CTFontRef font = style->fontCascade().primaryFont().getCTFont(); 811 CTFontSymbolicTraits traits = font ? CTFontGetSymbolicTraits(font) : 0; 812 813 if (traits & kCTFontTraitBold) 814 result.typingAttributes |= AttributeBold; 815 if (traits & kCTFontTraitItalic) 816 result.typingAttributes |= AttributeItalics; 817 818 RefPtr<EditingStyle> typingStyle = frame.selection().typingStyle(); 819 if (typingStyle && typingStyle->style()) { 820 String value = typingStyle->style()->getPropertyValue(CSSPropertyWebkitTextDecorationsInEffect); 821 if (value.contains("underline")) 822 result.typingAttributes |= AttributeUnderline; 823 } else { 824 if (style->textDecorationsInEffect() & TextDecorationUnderline) 825 result.typingAttributes |= AttributeUnderline; 826 } 827 828 if (nodeToRemove) 829 nodeToRemove->remove(ASSERT_NO_EXCEPTION); 830 } 831 } 832 #endif 833 834 #if PLATFORM(GTK) 835 result.cursorRect = frame.selection().absoluteCaretBounds(); 836 #endif 767 768 platformEditorState(frame, result); 837 769 838 770 return result; -
trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h
r180031 r180465 873 873 void platformInitialize(); 874 874 void platformDetach(); 875 void platformEditorState(WebCore::Frame&, EditorState& result) const; 875 876 876 877 void didReceiveWebPageMessage(IPC::Connection&, IPC::MessageDecoder&); … … 1083 1084 void selectLastActionMenuRange(); 1084 1085 void focusAndSelectLastActionMenuHitTestResult(); 1086 void setFont(const String& fontFamily, double fontSize, uint64_t fontTraits); 1085 1087 1086 1088 void dataDetectorsDidPresentUI(WebCore::PageOverlay::PageOverlayID); -
trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in
r180031 r180465 167 167 #if PLATFORM(MAC) 168 168 PerformDictionaryLookupOfCurrentSelection() 169 SetFont(String fontFamily, double fontSize, uint64_t fontTraits) 169 170 #endif 170 171 -
trunk/Source/WebKit2/WebProcess/WebPage/efl/WebPageEfl.cpp
r174380 r180465 83 83 } 84 84 85 void WebPage::platformEditorState(Frame&, EditorState&) const 86 { 87 } 88 85 89 bool WebPage::performDefaultBehaviorForKeyEvent(const WebKeyboardEvent& keyboardEvent) 86 90 { -
trunk/Source/WebKit2/WebProcess/WebPage/gtk/WebPageGtk.cpp
r177162 r180465 29 29 #include "WebPage.h" 30 30 31 #include "EditorState.h" 31 32 #include "NotImplemented.h" 32 33 #include "WebEvent.h" … … 66 67 void WebPage::platformDetach() 67 68 { 69 } 70 71 void WebPage::platformEditorState(Frame& frame, EditorState& result) const 72 { 73 result.cursorRect = frame.selection().absoluteCaretBounds(); 68 74 } 69 75 -
trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm
r180225 r180465 87 87 #import <WebCore/RenderView.h> 88 88 #import <WebCore/SharedBuffer.h> 89 #import <WebCore/StyleProperties.h> 89 90 #import <WebCore/TextIterator.h> 90 91 #import <WebCore/VisibleUnits.h> … … 126 127 { 127 128 notImplemented(); 129 } 130 131 void WebPage::platformEditorState(Frame& frame, EditorState& result) const 132 { 133 const VisibleSelection& selection = frame.selection().selection(); 134 if (frame.editor().hasComposition()) { 135 RefPtr<Range> compositionRange = frame.editor().compositionRange(); 136 Vector<WebCore::SelectionRect> compositionRects; 137 compositionRange->collectSelectionRects(compositionRects); 138 if (compositionRects.size()) 139 result.firstMarkedRect = compositionRects[0].rect(); 140 if (compositionRects.size() > 1) 141 result.lastMarkedRect = compositionRects.last().rect(); 142 else 143 result.lastMarkedRect = result.firstMarkedRect; 144 result.markedText = plainTextReplacingNoBreakSpace(compositionRange.get()); 145 } 146 FrameView* view = frame.view(); 147 if (selection.isCaret()) { 148 result.caretRectAtStart = view->contentsToRootView(frame.selection().absoluteCaretBounds()); 149 result.caretRectAtEnd = result.caretRectAtStart; 150 // FIXME: The following check should take into account writing direction. 151 result.isReplaceAllowed = result.isContentEditable && atBoundaryOfGranularity(selection.start(), WordGranularity, DirectionForward); 152 result.wordAtSelection = plainTextReplacingNoBreakSpace(wordRangeFromPosition(selection.start()).get()); 153 if (selection.isContentEditable()) { 154 charactersAroundPosition(selection.start(), result.characterAfterSelection, result.characterBeforeSelection, result.twoCharacterBeforeSelection); 155 Node* root = selection.rootEditableElement(); 156 result.hasContent = root && root->hasChildNodes() && !isEndOfEditableOrNonEditableContent(firstPositionInNode(root)); 157 } 158 } else if (selection.isRange()) { 159 result.caretRectAtStart = view->contentsToRootView(VisiblePosition(selection.start()).absoluteCaretBounds()); 160 result.caretRectAtEnd = view->contentsToRootView(VisiblePosition(selection.end()).absoluteCaretBounds()); 161 RefPtr<Range> selectedRange = selection.toNormalizedRange(); 162 selectedRange->collectSelectionRects(result.selectionRects); 163 convertSelectionRectsToRootView(view, result.selectionRects); 164 String selectedText = plainTextReplacingNoBreakSpace(selectedRange.get(), TextIteratorDefaultBehavior, true); 165 // FIXME: We should disallow replace when the string contains only CJ characters. 166 result.isReplaceAllowed = result.isContentEditable && !result.isInPasswordField && !selectedText.containsOnlyWhitespace(); 167 result.selectedTextLength = selectedText.length(); 168 const int maxSelectedTextLength = 200; 169 if (selectedText.length() <= maxSelectedTextLength) 170 result.wordAtSelection = selectedText; 171 } 172 if (!selection.isNone()) { 173 Node* nodeToRemove; 174 if (RenderStyle* style = Editor::styleForSelectionStart(&frame, nodeToRemove)) { 175 CTFontRef font = style->fontCascade().primaryFont().getCTFont(); 176 CTFontSymbolicTraits traits = font ? CTFontGetSymbolicTraits(font) : 0; 177 178 if (traits & kCTFontTraitBold) 179 result.typingAttributes |= AttributeBold; 180 if (traits & kCTFontTraitItalic) 181 result.typingAttributes |= AttributeItalics; 182 183 RefPtr<EditingStyle> typingStyle = frame.selection().typingStyle(); 184 if (typingStyle && typingStyle->style()) { 185 String value = typingStyle->style()->getPropertyValue(CSSPropertyWebkitTextDecorationsInEffect); 186 if (value.contains("underline")) 187 result.typingAttributes |= AttributeUnderline; 188 } else { 189 if (style->textDecorationsInEffect() & TextDecorationUnderline) 190 result.typingAttributes |= AttributeUnderline; 191 } 192 193 if (nodeToRemove) 194 nodeToRemove->remove(ASSERT_NO_EXCEPTION); 195 } 196 } 128 197 } 129 198 -
trunk/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm
r179409 r180465 118 118 [m_mockAccessibilityElement setWebPage:nullptr]; 119 119 } 120 120 121 void WebPage::platformEditorState(Frame& frame, EditorState& result) const 122 { 123 if (frame.selection().selection().isNone()) 124 return; 125 126 const Font* font = frame.editor().fontForSelection(result.selectionHasMultipleFonts); 127 NSFont *nsFont = font ? font->getNSFont() : nil; 128 if (nsFont) { 129 result.fontName = nsFont.fontName; 130 result.fontSize = nsFont.pointSize; 131 } 132 } 133 121 134 NSObject *WebPage::accessibilityObjectForMainFramePlugin() 122 135 { … … 1160 1173 } 1161 1174 1175 void WebPage::setFont(const String& fontFamily, double fontSize, uint64_t fontTraits) 1176 { 1177 Frame& frame = m_page->focusController().focusedOrMainFrame(); 1178 frame.editor().applyFontStyles(fontFamily, fontSize, fontTraits); 1179 } 1180 1162 1181 } // namespace WebKit 1163 1182
Note: See TracChangeset
for help on using the changeset viewer.