WebCore:
authoroliver <oliver@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 7 Jul 2007 04:01:28 +0000 (04:01 +0000)
committeroliver <oliver@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 7 Jul 2007 04:01:28 +0000 (04:01 +0000)
        Reviewed by Maciej.

        Pulled a number of methods from WebKit and WebCoreFrameBridge into
        C++ objects.

        * WebCore.exp:
        * WebCore.xcodeproj/project.pbxproj:
        * editing/Editor.cpp:
        (WebCore::Editor::replaceMarkedText):
            From -[WebCoreFrameBridge replaceMarkedTextWithText:]
        * editing/Editor.h:
        * page/Frame.cpp:
        (WebCore::Frame::setMarkedTextRange):
            Pulled platform independent logic from Mac specific implementation
        (WebCore::Frame::selectRangeInMarkedText):
            Converted from -[WebHTMLView _selectRangeInMarkedText:]
        * page/Frame.h:
        * page/mac/FrameMac.mm:
        (WebCore::Frame::setMarkedTextRange):
            Now only does Mac specific logic when manipulating initial
            NSAttributedString
        * page/mac/WebCoreFrameBridge.h:
        * page/mac/WebCoreFrameBridge.mm:
            Removed -[WebCoreFrameBridge replaceMarkedTextWithText:]

WebKit:

        Reviewed by Maciej.

        <rdar://problem/5318756> Need to refactor IM/Marked text code to share logic with windows.

        Moved a number of methods from WebHTMLView into WebCore.
        Replaced bridge methods with calls directly into WebCore objects.

        * WebKit.xcodeproj/project.pbxproj:
        * WebView/WebHTMLView.mm:
        (-[WebHTMLView setMarkedText:selectedRange:]):
          Now calls WebCore object methods directly, rather than calling
          via the bridge.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@24085 268f45cc-cd09-0410-ab3c-d52691b4dbfc

13 files changed:
WebCore/ChangeLog
WebCore/WebCore.exp
WebCore/WebCore.xcodeproj/project.pbxproj
WebCore/editing/Editor.cpp
WebCore/editing/Editor.h
WebCore/page/Frame.cpp
WebCore/page/Frame.h
WebCore/page/mac/FrameMac.mm
WebCore/page/mac/WebCoreFrameBridge.h
WebCore/page/mac/WebCoreFrameBridge.mm
WebKit/ChangeLog
WebKit/WebKit.xcodeproj/project.pbxproj
WebKit/WebView/WebHTMLView.mm

index ebd68505ebef31e08e41acf0da5e348f48648f12..a52c80e1df2d66b54af5abb91054e73e476ec312 100644 (file)
@@ -1,3 +1,30 @@
+2007-07-06  Oliver Hunt  <oliver@apple.com>
+
+        Reviewed by Maciej.
+
+        Pulled a number of methods from WebKit and WebCoreFrameBridge into 
+        C++ objects.
+
+        * WebCore.exp:
+        * WebCore.xcodeproj/project.pbxproj:
+        * editing/Editor.cpp:
+        (WebCore::Editor::replaceMarkedText):
+            From -[WebCoreFrameBridge replaceMarkedTextWithText:]
+        * editing/Editor.h:
+        * page/Frame.cpp:
+        (WebCore::Frame::setMarkedTextRange):
+            Pulled platform independent logic from Mac specific implementation
+        (WebCore::Frame::selectRangeInMarkedText):
+            Converted from -[WebHTMLView _selectRangeInMarkedText:]
+        * page/Frame.h:
+        * page/mac/FrameMac.mm:
+        (WebCore::Frame::setMarkedTextRange):
+            Now only does Mac specific logic when manipulating initial
+            NSAttributedString
+        * page/mac/WebCoreFrameBridge.h:
+        * page/mac/WebCoreFrameBridge.mm:
+            Removed -[WebCoreFrameBridge replaceMarkedTextWithText:]
+
 2007-07-06  Mitz Pettel  <mitz@webkit.org>
 
         Reviewed by Darin.
index 72c0bd1b465108d461f18da1c0cd825da5818b21..b9e72c51e5231026c36f5ae6a7a109857739bed9 100644 (file)
@@ -360,6 +360,7 @@ __ZN7WebCore5Frame18windowScriptObjectEv
 __ZN7WebCore5Frame20setSelectionFromNoneEv
 __ZN7WebCore5Frame20windowScriptNPObjectEv
 __ZN7WebCore5Frame21setProhibitsScrollingEb
+__ZN7WebCore5Frame23selectRangeInMarkedTextEjj
 __ZN7WebCore5Frame26dashboardRegionsDictionaryEv
 __ZN7WebCore5Frame29cleanupScriptObjectsForPluginEPv
 __ZN7WebCore5Frame4initEv
@@ -389,6 +390,7 @@ __ZN7WebCore6Editor16pasteAsPlainTextEv
 __ZN7WebCore6Editor16selectMarkedTextEv
 __ZN7WebCore6Editor17discardMarkedTextEv
 __ZN7WebCore6Editor17insertOrderedListEv
+__ZN7WebCore6Editor17replaceMarkedTextERKNS_6StringE
 __ZN7WebCore6Editor19deleteWithDirectionENS_19SelectionController10EDirectionENS_15TextGranularityEbb
 __ZN7WebCore6Editor19insertUnorderedListEv
 __ZN7WebCore6Editor21applyStyleToSelectionEPNS_19CSSStyleDeclarationENS_10EditActionE
index 74585c85360df86d5b6ef03538d78f70bb116c42..8c82a7539eeaa643ebb19ba0e9fa31d822500bf8 100644 (file)
                0867D690FE84028FC02AAC07 /* Project object */ = {
                        isa = PBXProject;
                        buildConfigurationList = 149C284308902B11008A9EFC /* Build configuration list for PBXProject "WebCore" */;
-                       compatibilityVersion = "Xcode 2.4";
                        hasScannedForEncodings = 1;
                        knownRegions = (
                                English,
                        mainGroup = 0867D691FE84028FC02AAC07 /* WebKit */;
                        productRefGroup = 034768DFFF38A50411DB9C8B /* Products */;
                        projectDirPath = "";
-                       projectRoot = "";
                        targets = (
                                93F198A508245E59001E9ABC /* WebCore */,
                                DD041FBE09D9DDBE0010AF2A /* Derived Sources */,
index d5559bb68137065feb3dc6f720d7141ac11de94e..74a34c02abeaaeaff913a75fa0dfb75780c29ecf 100644 (file)
@@ -1702,6 +1702,23 @@ void Editor::unmarkText()
 }
 #endif
 
+void Editor::replaceMarkedText(const String& text)
+{
+    if (m_frame->selectionController()->isNone())
+        return;
+    
+    int exception = 0;
+    
+    Range *markedTextRange = m_frame->markedTextRange();
+    if (markedTextRange && !markedTextRange->collapsed(exception))
+        TypingCommand::deleteKeyPressed(m_frame->document(), false);
+    
+    if (!text.isEmpty())
+        TypingCommand::insertText(m_frame->document(), text, true);
+    
+    m_frame->revealSelection(RenderLayer::gAlignToEdgeIfNeeded);
+}
+
 void Editor::ignoreSpelling()
 {
     if (!client())
index 039ed718794eb2598a14b0e30e77de8ea75b821e..ef51cef0a1c7657affbf7a6dffb826d5bc38c679 100644 (file)
@@ -197,6 +197,7 @@ public:
     void selectMarkedText();
     void unmarkText();
     void discardMarkedText();
+    void replaceMarkedText(const String&);
 
     bool ignoreMarkedTextSelectionChange() const { return m_ignoreMarkedTextSelectionChange; }
     void setIgnoreMarkedTextSelectionChange(bool ignore) { m_ignoreMarkedTextSelectionChange = ignore; }
index 960e9756f4e70dd960f16bf74592d88fbf54b9be..35031e233572a4cc464f53be65403cc2bb00884a 100644 (file)
@@ -312,6 +312,53 @@ Range* Frame::markedTextRange() const
     return d->m_markedTextRange.get();
 }
 
+void Frame::setMarkedTextRange(Range* range, Vector<MarkedTextUnderline>& markedRangeDecorations)
+{
+    int exception = 0;
+    
+    ASSERT(!range || range->startContainer(exception) == range->endContainer(exception));
+    ASSERT(!range || range->collapsed(exception) || range->startContainer(exception)->isTextNode());
+    
+    d->m_markedTextUnderlines.clear();
+    if (markedRangeDecorations.size()) {
+        d->m_markedTextUsesUnderlines = true;
+        d->m_markedTextUnderlines = markedRangeDecorations;
+    } else 
+        d->m_markedTextUsesUnderlines = false;
+    
+    if (d->m_markedTextRange.get() && document() && d->m_markedTextRange->startContainer(exception)->renderer())
+        d->m_markedTextRange->startContainer(exception)->renderer()->repaint();
+    
+    if (range && range->collapsed(exception))
+        d->m_markedTextRange = 0;
+    else
+        d->m_markedTextRange = range;
+    
+    if (d->m_markedTextRange.get() && document() && d->m_markedTextRange->startContainer(exception)->renderer())
+        d->m_markedTextRange->startContainer(exception)->renderer()->repaint();    
+}
+
+void Frame::selectRangeInMarkedText(unsigned selOffset, unsigned selLength)
+{
+    ExceptionCode ec = 0;
+    
+    RefPtr<Range> selectedRange = document()->createRange();
+    Range* markedTextRange = this->markedTextRange();
+    
+    ASSERT(markedTextRange->startContainer(ec) == markedTextRange->endContainer(ec));
+    ASSERT(!ec);
+    unsigned selectionStart = markedTextRange->startOffset(ec) + selOffset;
+    unsigned selectionEnd = selectionStart + selLength;
+    ASSERT(!ec);
+    
+    selectedRange->setStart(markedTextRange->startContainer(ec), selectionStart, ec);
+    ASSERT(!ec);
+    selectedRange->setEnd(markedTextRange->startContainer(ec), selectionEnd, ec);
+    ASSERT(!ec);
+    
+    selectionController()->setSelectedRange(selectedRange.get(), DOWNSTREAM, false, ec);
+}
+
 SelectionController* Frame::selectionController() const
 {
     return &d->m_selectionController;
index a57e0732ac55b0246acd548b415348d9875b235c..a26ede7a239ba0dcd636f64b2afa218eebbf5443 100644 (file)
@@ -270,6 +270,7 @@ public:
     void removeEditingStyleFromElement(Element*) const;
 
     Range* markedTextRange() const;
+    
 #if PLATFORM(MAC)
     void issuePasteCommand();
 #endif
@@ -281,6 +282,8 @@ public:
 
     const Vector<MarkedTextUnderline>& markedTextUnderlines() const;  
     bool markedTextUsesUnderlines() const;
+    void setMarkedTextRange(Range* , Vector<MarkedTextUnderline>&);
+    void selectRangeInMarkedText(unsigned selOffset, unsigned selLength);
   
     unsigned markAllMatchesForText(const String&, bool caseFlag, unsigned limit);
     bool markedTextMatchesAreHighlighted() const;
@@ -373,7 +376,7 @@ public:
     NSDictionary* fontAttributesForSelectionStart() const;
     NSWritingDirection baseWritingDirectionForSelectionStart() const;
 
-    void setMarkedTextRange(const Range* , NSArray* attributes, NSArray* ranges);
+    void setMarkedTextRange(Range* , NSArray* attributes, NSArray* ranges);
 
 #endif
 
index da90ba6c31a943808136573667c712681b229f82..61cdd54e8ea217827461e444c786cde75cbad9f6 100644 (file)
@@ -560,31 +560,19 @@ static void convertAttributesToUnderlines(Vector<MarkedTextUnderline>& result, c
     }
 }
 
-void Frame::setMarkedTextRange(const Range* range, NSArray* attributes, NSArray* ranges)
+void Frame::setMarkedTextRange(Range* range, NSArray* attributes, NSArray* ranges)
 {
-    int exception = 0;
+    int exception;
+    exception = 0;
 
     ASSERT(!range || range->startContainer(exception) == range->endContainer(exception));
     ASSERT(!range || range->collapsed(exception) || range->startContainer(exception)->isTextNode());
 
-    d->m_markedTextUnderlines.clear();
-    if (attributes == nil)
-        d->m_markedTextUsesUnderlines = false;
-    else {
-        d->m_markedTextUsesUnderlines = true;
-        convertAttributesToUnderlines(d->m_markedTextUnderlines, range, attributes, ranges);
-    }
-
-    if (d->m_markedTextRange.get() && document() && d->m_markedTextRange->startContainer(exception)->renderer())
-        d->m_markedTextRange->startContainer(exception)->renderer()->repaint();
-
-    if (range && range->collapsed(exception))
-        d->m_markedTextRange = 0;
-    else
-        d->m_markedTextRange = const_cast<Range*>(range);
-
-    if (d->m_markedTextRange.get() && document() && d->m_markedTextRange->startContainer(exception)->renderer())
-        d->m_markedTextRange->startContainer(exception)->renderer()->repaint();
+    Vector<MarkedTextUnderline> decorations;
+    if (attributes)
+        convertAttributesToUnderlines(decorations, range, attributes, ranges);
+    
+    setMarkedTextRange(range, decorations);
 }
 
 NSMutableDictionary* Frame::dashboardRegionsDictionary()
index d8e031f38fd5a75c6039a0ed789e95b3f43aefa0..7d8b25c2decdad69763fbe1228b97e704dbaaf38 100644 (file)
@@ -174,7 +174,6 @@ typedef enum ObjectElementType {
 // international text input "marked text"
 - (void)setMarkedTextDOMRange:(DOMRange *)range customAttributes:(NSArray *)attributes ranges:(NSArray *)ranges;
 - (DOMRange *)markedTextDOMRange;
-- (void)replaceMarkedTextWithText:(NSString *)text;
 
 - (NSFont *)fontForSelection:(BOOL *)hasMultipleFonts;
 - (NSWritingDirection)baseWritingDirectionForSelectionStart;
index 6c520d2e9999fd60258a064da6309019865503fd..8597db740cc20bffb9be704dda0e5d8e6af5c938 100644 (file)
@@ -958,23 +958,6 @@ static HTMLFormElement *formElementFromDOMElement(DOMElement *element)
     return [self convertToNSRange:m_frame->markedTextRange()];
 }
 
-- (void)replaceMarkedTextWithText:(NSString *)text
-{
-    if (m_frame->selectionController()->isNone())
-        return;
-    
-    int exception = 0;
-
-    Range *markedTextRange = m_frame->markedTextRange();
-    if (markedTextRange && !markedTextRange->collapsed(exception))
-        TypingCommand::deleteKeyPressed(m_frame->document(), NO);
-    
-    if ([text length] > 0)
-        TypingCommand::insertText(m_frame->document(), text, YES);
-    
-    m_frame->revealSelection(RenderLayer::gAlignToEdgeIfNeeded);
-}
-
 // Given proposedRange, returns an extended range that includes adjacent whitespace that should
 // be deleted along with the proposed range in order to preserve proper spacing and punctuation of
 // the text surrounding the deletion.
index 31f59c26d4cbd73d0f8c20e2dc3d90999a269865..a938cb20f2bcb56df9fe0703fd368a7a57d5bd47 100644 (file)
@@ -1,3 +1,18 @@
+2007-07-06  Oliver Hunt  <oliver@apple.com>
+
+        Reviewed by Maciej.
+
+        <rdar://problem/5318756> Need to refactor IM/Marked text code to share logic with windows.
+
+        Moved a number of methods from WebHTMLView into WebCore.
+        Replaced bridge methods with calls directly into WebCore objects.
+
+        * WebKit.xcodeproj/project.pbxproj:
+        * WebView/WebHTMLView.mm:
+        (-[WebHTMLView setMarkedText:selectedRange:]):
+          Now calls WebCore object methods directly, rather than calling 
+          via the bridge.
+
 2007-07-06  John Sullivan  <sullivan@apple.com>
 
         Reviewed by Brady
index fa282e346e557520e9a3153ce34d58171083cda5..366881f2234597503b1a60ab4ffd132d2f423a81 100644 (file)
                0867D690FE84028FC02AAC07 /* Project object */ = {
                        isa = PBXProject;
                        buildConfigurationList = 149C283208902B0F008A9EFC /* Build configuration list for PBXProject "WebKit" */;
-                       compatibilityVersion = "Xcode 2.4";
                        hasScannedForEncodings = 1;
                        knownRegions = (
                                English,
                        mainGroup = 0867D691FE84028FC02AAC07 /* WebKit */;
                        productRefGroup = 034768DFFF38A50411DB9C8B /* Products */;
                        projectDirPath = "";
-                       projectRoot = "";
                        targets = (
                                9398100A0824BF01008DF038 /* WebKit */,
                        );
index b35ea46cd5c016e8004622a921e1e23782dfac5f..78b8dbabe52361fc87a948dcfc295ac254690ecf 100644 (file)
@@ -5290,29 +5290,6 @@ BOOL isTextInput(Frame *coreFrame)
         coreFrame->editor()->unmarkText();
 }
 
-- (void)_selectRangeInMarkedText:(NSRange)range
-{
-    ASSERT([self hasMarkedText]);
-
-    WebFrameBridge *bridge = [self _bridge];
-    DOMRange *selectedRange = [[[self _frame] DOMDocument] createRange];
-    DOMRange *markedTextRange = [bridge markedTextDOMRange];
-    
-    ASSERT([markedTextRange startContainer] == [markedTextRange endContainer]);
-
-    unsigned selectionStart = [markedTextRange startOffset] + range.location;
-    unsigned selectionEnd = selectionStart + range.length;
-
-    [selectedRange setStart:[markedTextRange startContainer] offset:selectionStart];
-    [selectedRange setEnd:[markedTextRange startContainer] offset:selectionEnd];
-
-    Frame* coreFrame = core([self _frame]);
-    if (coreFrame) {
-        ExceptionCode ec = 0;
-        coreFrame->selectionController()->setSelectedRange(core(selectedRange), DOWNSTREAM, false, ec);
-    }
-}
-
 - (void)_extractAttributes:(NSArray **)a ranges:(NSArray **)r fromAttributedString:(NSAttributedString *)string
 {
     int length = [[string string] length];
@@ -5376,10 +5353,10 @@ BOOL isTextInput(Frame *coreFrame)
         [self _extractAttributes:&attributes ranges:&ranges fromAttributedString:string];
     }
 
-    [bridge replaceMarkedTextWithText:text];
+    coreFrame->editor()->replaceMarkedText(text);
     [bridge setMarkedTextDOMRange:[self _selectedRange] customAttributes:attributes ranges:ranges];
     if ([self hasMarkedText])
-        [self _selectRangeInMarkedText:newSelRange];
+        coreFrame->selectRangeInMarkedText(newSelRange.location, newSelRange.length);
 
     coreFrame->editor()->setIgnoreMarkedTextSelectionChange(false);
 }