Changeset 180465 in webkit


Ignore:
Timestamp:
Feb 20, 2015 4:09:48 PM (9 years ago)
Author:
enrica@apple.com
Message:

[WK2] Add support for font panel on OS X.
https://bugs.webkit.org/show_bug.cgi?id=141777

Reviewed by Tim Horton.

Source/WebCore:

This patch adds the necessary hooks to the Editor class to support
the font panel.

  • editing/Editor.h:
  • editing/mac/EditorMac.mm:

(WebCore::Editor::applyFontStyles):

Source/WebKit2:

This patch adds the necessary hooks to WKView to support
the font panel. It also includes refactoring of WebPage::editorState
and WebPageProxy::editorStateChanged to separate the different platform
specific tasks.

  • Shared/EditorState.cpp:

(WebKit::EditorState::encode):
(WebKit::EditorState::decode):

  • Shared/EditorState.h:

(WebKit::EditorState::EditorState):

  • UIProcess/API/mac/WKView.mm:

(-[WKView _selectionChanged]):
(-[WKView changeFont:]):

  • UIProcess/API/mac/WKViewInternal.h:
  • UIProcess/PageClient.h:
  • UIProcess/WebPageProxy.cpp:

(WebKit::WebPageProxy::editorStateChanged): Deleted.

  • UIProcess/WebPageProxy.h:
  • UIProcess/efl/WebPageProxyEfl.cpp:

(WebKit::WebPageProxy::editorStateChanged):

  • UIProcess/gtk/WebPageProxyGtk.cpp:

(WebKit::WebPageProxy::editorStateChanged):

  • UIProcess/ios/WebPageProxyIOS.mm:

(WebKit::WebPageProxy::editorStateChanged):

  • UIProcess/mac/PageClientImpl.h:
  • UIProcess/mac/PageClientImpl.mm:

(WebKit::PageClientImpl::selectionDidChange):

  • UIProcess/mac/WebPageProxyMac.mm:

(WebKit::WebPageProxy::setFont):
(WebKit::WebPageProxy::editorStateChanged):

  • WebProcess/WebPage/WebPage.cpp:

(WebKit::WebPage::editorState):

  • WebProcess/WebPage/WebPage.h:
  • WebProcess/WebPage/WebPage.messages.in:
  • WebProcess/WebPage/efl/WebPageEfl.cpp:

(WebKit::WebPage::platformEditorState):

  • WebProcess/WebPage/gtk/WebPageGtk.cpp:

(WebKit::WebPage::platformEditorState):

  • WebProcess/WebPage/ios/WebPageIOS.mm:

(WebKit::WebPage::platformEditorState):

  • WebProcess/WebPage/mac/WebPageMac.mm:

(WebKit::WebPage::platformEditorState):
(WebKit::WebPage::setFont):

Location:
trunk/Source
Files:
24 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r180464 r180465  
     12015-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
    1152015-02-20  Zalan Bujtas  <zalan@apple.com>
    216
  • trunk/Source/WebCore/editing/Editor.h

    r179861 r180465  
    433433    WEBCORE_EXPORT void replaceNodeFromPasteboard(Node*, const String& pasteboardName);
    434434    WEBCORE_EXPORT PassRefPtr<SharedBuffer> dataSelectionForPasteboard(const String& pasteboardName);
     435    WEBCORE_EXPORT void applyFontStyles(const String& fontFamily, double fontSize, unsigned fontTraits);
    435436#endif // !PLATFORM(IOS)
    436437    WEBCORE_EXPORT void replaceSelectionWithAttributedString(NSAttributedString *, MailBlockquoteHandling = MailBlockquoteHandling::RespectBlockquote);
  • trunk/Source/WebCore/editing/mac/EditorMac.mm

    r179143 r180465  
    2828
    2929#import "BlockExceptions.h"
     30#import "CSSPrimitiveValueMappings.h"
     31#import "CSSValuePool.h"
    3032#import "CachedResourceLoader.h"
    3133#import "ColorMac.h"
     
    682684}
    683685
     686void 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
    684696} // namespace WebCore
  • trunk/Source/WebKit2/ChangeLog

    r180456 r180465  
     12015-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
    1522015-02-20  Chris Dumez  <cdumez@apple.com>
    253
  • trunk/Source/WebKit2/Shared/EditorState.cpp

    r179578 r180465  
    4242    encoder << isInPlugin;
    4343    encoder << hasComposition;
     44
     45#if PLATFORM(MAC)
     46    encoder << fontName;
     47    encoder << fontSize;
     48    encoder << selectionHasMultipleFonts;
     49#endif
    4450
    4551#if PLATFORM(IOS)
     
    9197        return false;
    9298
     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
    93110#if PLATFORM(IOS)
    94111    if (!decoder.decode(result.isReplaceAllowed))
  • trunk/Source/WebKit2/Shared/EditorState.h

    r171203 r180465  
    5454        , isInPlugin(false)
    5555        , hasComposition(false)
     56#if PLATFORM(MAC)
     57        , selectionHasMultipleFonts(false)
     58        , fontSize(0)
     59#endif
    5660#if PLATFORM(IOS)
    5761        , isReplaceAllowed(false)
     
    7579    bool isInPlugin;
    7680    bool hasComposition;
     81
     82#if PLATFORM(MAC)
     83    bool selectionHasMultipleFonts;
     84    String fontName;
     85    double fontSize;
     86#endif
    7787
    7888#if PLATFORM(IOS)
  • trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm

    r180354 r180465  
    738738}
    739739
     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
    740760/*
    741761
     
    746766Editing-related methods still unimplemented that are implemented in WebKit1:
    747767
    748 - (void)changeFont:(id)sender;
    749768- (void)complete:(id)sender;
    750769- (void)copyFont:(id)sender;
  • trunk/Source/WebKit2/UIProcess/API/mac/WKViewInternal.h

    r177692 r180465  
    8888- (void)_setTextIndicator:(PassRefPtr<WebCore::TextIndicator>)textIndicator fadeOut:(BOOL)fadeOut;
    8989- (void)_setTextIndicatorAnimationProgress:(float)progress;
     90- (void)_selectionChanged;
    9091
    9192- (void)_setAcceleratedCompositingModeRootLayer:(CALayer *)rootLayer;
  • trunk/Source/WebKit2/UIProcess/PageClient.h

    r178820 r180465  
    182182    virtual PassRefPtr<ViewSnapshot> takeViewSnapshot() = 0;
    183183    virtual void wheelEventWasNotHandledByWebCore(const NativeWebWheelEvent&) = 0;
     184    virtual void selectionDidChange() = 0;
    184185#endif
    185186
     
    269270    virtual void stopAssistingNode() = 0;
    270271    virtual bool isAssistingNode() = 0;
    271     virtual void selectionDidChange() = 0;
    272272    virtual bool interpretKeyEvent(const NativeWebKeyboardEvent&, bool isCharEvent) = 0;
    273273    virtual void positionInformationDidChange(const InteractionInformationAtPosition&) = 0;
  • trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp

    r180354 r180465  
    37593759}
    37603760
    3761 void WebPageProxy::editorStateChanged(const EditorState& editorState)
    3762 {
    3763 #if PLATFORM(COCOA)
    3764     bool couldChangeSecureInputState = m_editorState.isInPasswordField != editorState.isInPasswordField || m_editorState.selectionIsNone;
    3765 #endif
    3766 #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 #endif
    3771 
    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 #endif
    3779 
    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 #endif
    3803 }
    3804 
    38053761void WebPageProxy::compositionWasCanceled(const EditorState& editorState)
    38063762{
  • trunk/Source/WebKit2/UIProcess/WebPageProxy.h

    r180115 r180465  
    539539    void insertDictatedTextAsync(const String& text, const EditingRange& replacementRange, const Vector<WebCore::TextAlternativeWithRange>& dictationAlternatives, bool registerUndoGroup);
    540540    void attributedSubstringForCharacterRangeAsync(const EditingRange&, std::function<void (const AttributedString&, const EditingRange&, CallbackBase::Error)>);
     541    void setFont(const String& fontFamily, double fontSize, uint64_t fontTraits);
    541542
    542543#if !USE(ASYNC_NSTEXTINPUTCLIENT)
  • trunk/Source/WebKit2/UIProcess/efl/WebPageProxyEfl.cpp

    r175098 r180465  
    8484}
    8585
     86void WebPageProxy::editorStateChanged(const EditorState& editorState)
     87{
     88    m_editorState = editorState;
     89   
     90    if (editorState.shouldIgnoreCompositionSelectionChange)
     91        return;
     92    m_pageClient.updateTextInputState();
     93}
     94
    8695void WebPageProxy::setThemePath(const String& themePath)
    8796{
  • trunk/Source/WebKit2/UIProcess/gtk/WebPageProxyGtk.cpp

    r176954 r180465  
    7777}
    7878
     79void WebPageProxy::editorStateChanged(const EditorState& editorState)
     80{
     81    m_editorState = editorState;
     82   
     83    if (editorState.shouldIgnoreCompositionSelectionChange)
     84        return;
     85    m_pageClient.updateTextInputState();
     86}
     87
    7988#if PLUGIN_ARCHITECTURE(X11)
    8089typedef HashMap<uint64_t, GtkWidget* > PluginWindowMap;
  • trunk/Source/WebKit2/UIProcess/ios/WebPageProxyIOS.mm

    r178980 r180465  
    885885}
    886886
     887void 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
    887905#if USE(QUICK_LOOK)
    888906   
  • trunk/Source/WebKit2/UIProcess/mac/PageClientImpl.h

    r180441 r180465  
    9999    virtual void resetSecureInputState() override;
    100100    virtual void notifyInputContextAboutDiscardedComposition() override;
     101    virtual void selectionDidChange();
    101102#if PLATFORM(MAC) && !USE(ASYNC_NSTEXTINPUTCLIENT)
    102103    virtual void notifyApplicationAboutInputContextChange() override;
  • trunk/Source/WebKit2/UIProcess/mac/PageClientImpl.mm

    r179409 r180465  
    532532}
    533533
     534void PageClientImpl::selectionDidChange()
     535{
     536    [m_wkView _selectionChanged];
     537}
     538
    534539void PageClientImpl::wheelEventWasNotHandledByWebCore(const NativeWebWheelEvent& event)
    535540{
  • trunk/Source/WebKit2/UIProcess/mac/WebPageProxyMac.mm

    r180076 r180465  
    666666    return applicationIsAppleMail();
    667667}
     668
     669void 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
     677void 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}
    668712   
    669713} // namespace WebKit
  • trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp

    r180416 r180465  
    765765    result.hasComposition = frame.editor().hasComposition();
    766766    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);
    837769
    838770    return result;
  • trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h

    r180031 r180465  
    873873    void platformInitialize();
    874874    void platformDetach();
     875    void platformEditorState(WebCore::Frame&, EditorState& result) const;
    875876
    876877    void didReceiveWebPageMessage(IPC::Connection&, IPC::MessageDecoder&);
     
    10831084    void selectLastActionMenuRange();
    10841085    void focusAndSelectLastActionMenuHitTestResult();
     1086    void setFont(const String& fontFamily, double fontSize, uint64_t fontTraits);
    10851087
    10861088    void dataDetectorsDidPresentUI(WebCore::PageOverlay::PageOverlayID);
  • trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in

    r180031 r180465  
    167167#if PLATFORM(MAC)
    168168    PerformDictionaryLookupOfCurrentSelection()
     169    SetFont(String fontFamily, double fontSize, uint64_t fontTraits)
    169170#endif
    170171
  • trunk/Source/WebKit2/WebProcess/WebPage/efl/WebPageEfl.cpp

    r174380 r180465  
    8383}
    8484
     85void WebPage::platformEditorState(Frame&, EditorState&) const
     86{
     87}
     88
    8589bool WebPage::performDefaultBehaviorForKeyEvent(const WebKeyboardEvent& keyboardEvent)
    8690{
  • trunk/Source/WebKit2/WebProcess/WebPage/gtk/WebPageGtk.cpp

    r177162 r180465  
    2929#include "WebPage.h"
    3030
     31#include "EditorState.h"
    3132#include "NotImplemented.h"
    3233#include "WebEvent.h"
     
    6667void WebPage::platformDetach()
    6768{
     69}
     70
     71void WebPage::platformEditorState(Frame& frame, EditorState& result) const
     72{
     73    result.cursorRect = frame.selection().absoluteCaretBounds();
    6874}
    6975
  • trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm

    r180225 r180465  
    8787#import <WebCore/RenderView.h>
    8888#import <WebCore/SharedBuffer.h>
     89#import <WebCore/StyleProperties.h>
    8990#import <WebCore/TextIterator.h>
    9091#import <WebCore/VisibleUnits.h>
     
    126127{
    127128    notImplemented();
     129}
     130
     131void 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    }
    128197}
    129198
  • trunk/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm

    r179409 r180465  
    118118    [m_mockAccessibilityElement setWebPage:nullptr];
    119119}
    120    
     120
     121void 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
    121134NSObject *WebPage::accessibilityObjectForMainFramePlugin()
    122135{
     
    11601173}
    11611174
     1175void 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
    11621181} // namespace WebKit
    11631182
Note: See TracChangeset for help on using the changeset viewer.