[SCM] WebKit Debian packaging branch, debian/unstable, updated. debian/1.1.15-1-40151-g37bb677

kocienda kocienda at 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Sat Sep 26 08:42:39 UTC 2009


The following commit has been merged in the debian/unstable branch:
commit c4791bd2b0a11b0319077a3bbbd198cd2f24921f
Author: kocienda <kocienda at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Fri May 28 14:19:48 2004 +0000

    Tests:
    
            Reviewed by Maciej.
    
            - moved to new symlink technique for embedding frameworks
    
            * Blot/Blot.xcode/project.pbxproj: Call the new create-framework-symlinks script
            instead of copy-frameworks-to-dstroot.sh.
            * Blot/embed-frameworks.sh: Removed.
    
            * PDFViewer/PDFViewer.pbproj/project.pbxproj: Call the new create-framework-symlinks
            script instead using a copy files phase.
    
    WebCore:
    
            Reviewed by John
    
            * khtml/xml/dom_selection.cpp:
            (DOM::Selection::toRange): Add call to update document layout before returning a Range.
            This is done to ensure recently-done editing changes are reflected in the calculation
            of the Range. This change solves a specific problem with updating the font panel, where
            the wrong Range was used, resulting in an incorrect font. Also, defer converting
            positions to be range-compliant positions. The nodeIsBeforeNode function is not
            range-compliant-position-savvy.
    
    WebKit:
    
            Reviewed by John
    
            The font panel now updates correctly, reflecting the current selection. There may
            still be some bugs and corner cases to handle, but this will work for a general
            implementation of the feature.
    
            * WebView.subproj/WebView.m:
            (+[ElementOrTextFilter filter]): Added. This filter will accept DOM elements and
            text nodes and skip everything else. This filter is used when walking a selection
            to determine the fonts in use.
            (-[ElementOrTextFilter acceptNode:]): DOM node filter implementation method.
            (-[WebView _fontFromStyle]): Removed, in lieu of new fontForCurrentPosition call on the bridge.
            (-[WebView _updateFontPanel]): Reworked to use a TreeWalker instead of a NodeIterator. This
            was done since the iterator must be rooted at the document root, but start iterating
            at the start of the selection. TreeWalker's setCurrentNode allows this to be done.
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@6719 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/ChangeLog-2005-08-23 b/WebCore/ChangeLog-2005-08-23
index e3066a6..90c349e 100644
--- a/WebCore/ChangeLog-2005-08-23
+++ b/WebCore/ChangeLog-2005-08-23
@@ -1,3 +1,15 @@
+2004-05-27  Ken Kocienda  <kocienda at apple.com>
+
+        Reviewed by John
+
+        * khtml/xml/dom_selection.cpp:
+        (DOM::Selection::toRange): Add call to update document layout before returning a Range.
+        This is done to ensure recently-done editing changes are reflected in the calculation
+        of the Range. This change solves a specific problem with updating the font panel, where
+        the wrong Range was used, resulting in an incorrect font. Also, defer converting 
+        positions to be range-compliant positions. The nodeIsBeforeNode function is not 
+        range-compliant-position-savvy.
+
 2004-05-27  Kevin Decker  <kdecker at apple.com>
 
         Reviewed by NOBODY (OOPS!).
diff --git a/WebCore/khtml/editing/SelectionController.cpp b/WebCore/khtml/editing/SelectionController.cpp
index b28bbe5..6b02454 100644
--- a/WebCore/khtml/editing/SelectionController.cpp
+++ b/WebCore/khtml/editing/SelectionController.cpp
@@ -397,6 +397,12 @@ Range Selection::toRange() const
     if (isEmpty())
         return Range();
 
+    // Make sure we have an updated layout since this function is called
+    // in the course of running edit commands which modify the DOM.
+    // Failing to call this can result in equivalentXXXPosition calls returning
+    // incorrect results.
+    start().node()->getDocument()->updateLayout();
+
     Position s, e;
     if (state() == CARET) {
         // If the selection is a caret, move the range start upstream. This helps us match
@@ -418,8 +424,8 @@ Range Selection::toRange() const
         //                       ^ selected
         //
         ASSERT(state() == RANGE);
-        s = start().equivalentDownstreamPosition().equivalentRangeCompliantPosition();
-        e = end().equivalentUpstreamPosition().equivalentRangeCompliantPosition();
+        s = start().equivalentDownstreamPosition();
+        e = end().equivalentUpstreamPosition();
         if ((s.node() == e.node() && s.offset() > e.offset()) || !nodeIsBeforeNode(s.node(), e.node())) {
             // Make sure the start is before the end.
             // The end can wind up before the start if collapsed whitespace is the only thing selected.
@@ -427,8 +433,9 @@ Range Selection::toRange() const
             s = e;
             e = tmp;
         }
+        s = s.equivalentRangeCompliantPosition();
+        e = e.equivalentRangeCompliantPosition();
     }
-    ASSERT((s.node() == e.node() && s.offset() <= e.offset()) || nodeIsBeforeNode(s.node(), e.node()));
 
     return Range(Node(s.node()), s.offset(), Node(e.node()), e.offset());
 }
diff --git a/WebCore/khtml/editing/selection.cpp b/WebCore/khtml/editing/selection.cpp
index b28bbe5..6b02454 100644
--- a/WebCore/khtml/editing/selection.cpp
+++ b/WebCore/khtml/editing/selection.cpp
@@ -397,6 +397,12 @@ Range Selection::toRange() const
     if (isEmpty())
         return Range();
 
+    // Make sure we have an updated layout since this function is called
+    // in the course of running edit commands which modify the DOM.
+    // Failing to call this can result in equivalentXXXPosition calls returning
+    // incorrect results.
+    start().node()->getDocument()->updateLayout();
+
     Position s, e;
     if (state() == CARET) {
         // If the selection is a caret, move the range start upstream. This helps us match
@@ -418,8 +424,8 @@ Range Selection::toRange() const
         //                       ^ selected
         //
         ASSERT(state() == RANGE);
-        s = start().equivalentDownstreamPosition().equivalentRangeCompliantPosition();
-        e = end().equivalentUpstreamPosition().equivalentRangeCompliantPosition();
+        s = start().equivalentDownstreamPosition();
+        e = end().equivalentUpstreamPosition();
         if ((s.node() == e.node() && s.offset() > e.offset()) || !nodeIsBeforeNode(s.node(), e.node())) {
             // Make sure the start is before the end.
             // The end can wind up before the start if collapsed whitespace is the only thing selected.
@@ -427,8 +433,9 @@ Range Selection::toRange() const
             s = e;
             e = tmp;
         }
+        s = s.equivalentRangeCompliantPosition();
+        e = e.equivalentRangeCompliantPosition();
     }
-    ASSERT((s.node() == e.node() && s.offset() <= e.offset()) || nodeIsBeforeNode(s.node(), e.node()));
 
     return Range(Node(s.node()), s.offset(), Node(e.node()), e.offset());
 }
diff --git a/WebCore/khtml/xml/dom_selection.cpp b/WebCore/khtml/xml/dom_selection.cpp
index b28bbe5..6b02454 100644
--- a/WebCore/khtml/xml/dom_selection.cpp
+++ b/WebCore/khtml/xml/dom_selection.cpp
@@ -397,6 +397,12 @@ Range Selection::toRange() const
     if (isEmpty())
         return Range();
 
+    // Make sure we have an updated layout since this function is called
+    // in the course of running edit commands which modify the DOM.
+    // Failing to call this can result in equivalentXXXPosition calls returning
+    // incorrect results.
+    start().node()->getDocument()->updateLayout();
+
     Position s, e;
     if (state() == CARET) {
         // If the selection is a caret, move the range start upstream. This helps us match
@@ -418,8 +424,8 @@ Range Selection::toRange() const
         //                       ^ selected
         //
         ASSERT(state() == RANGE);
-        s = start().equivalentDownstreamPosition().equivalentRangeCompliantPosition();
-        e = end().equivalentUpstreamPosition().equivalentRangeCompliantPosition();
+        s = start().equivalentDownstreamPosition();
+        e = end().equivalentUpstreamPosition();
         if ((s.node() == e.node() && s.offset() > e.offset()) || !nodeIsBeforeNode(s.node(), e.node())) {
             // Make sure the start is before the end.
             // The end can wind up before the start if collapsed whitespace is the only thing selected.
@@ -427,8 +433,9 @@ Range Selection::toRange() const
             s = e;
             e = tmp;
         }
+        s = s.equivalentRangeCompliantPosition();
+        e = e.equivalentRangeCompliantPosition();
     }
-    ASSERT((s.node() == e.node() && s.offset() <= e.offset()) || nodeIsBeforeNode(s.node(), e.node()));
 
     return Range(Node(s.node()), s.offset(), Node(e.node()), e.offset());
 }
diff --git a/WebKit/ChangeLog b/WebKit/ChangeLog
index 863f658..d3ba34a 100644
--- a/WebKit/ChangeLog
+++ b/WebKit/ChangeLog
@@ -1,3 +1,21 @@
+2004-05-27  Ken Kocienda  <kocienda at apple.com>
+
+        Reviewed by John
+
+        The font panel now updates correctly, reflecting the current selection. There may
+        still be some bugs and corner cases to handle, but this will work for a general
+        implementation of the feature.
+
+        * WebView.subproj/WebView.m:
+        (+[ElementOrTextFilter filter]): Added. This filter will accept DOM elements and
+        text nodes and skip everything else. This filter is used when walking a selection
+        to determine the fonts in use.
+        (-[ElementOrTextFilter acceptNode:]): DOM node filter implementation method.
+        (-[WebView _fontFromStyle]): Removed, in lieu of new fontForCurrentPosition call on the bridge.
+        (-[WebView _updateFontPanel]): Reworked to use a TreeWalker instead of a NodeIterator. This
+        was done since the iterator must be rooted at the document root, but start iterating 
+        at the start of the selection. TreeWalker's setCurrentNode allows this to be done.
+
 2004-05-27  Kevin Decker  <kdecker at apple.com>
 
         Reviewed by NOBODY (OOPS!).
diff --git a/WebKit/WebView.subproj/WebView.m b/WebKit/WebView.subproj/WebView.m
index 56c5f79..3f82304 100644
--- a/WebKit/WebView.subproj/WebView.m
+++ b/WebKit/WebView.subproj/WebView.m
@@ -2240,6 +2240,28 @@ static WebFrame *incrementFrame(WebFrame *curr, BOOL forward, BOOL wrapFlag)
 //==========================================================================================
 // Editing
 
+ at interface ElementOrTextFilter : NSObject <DOMNodeFilter>
++ (ElementOrTextFilter *)filter;
+ at end
+
+static ElementOrTextFilter *elementOrTextFilterInstance = nil;
+
+ at implementation ElementOrTextFilter
+
++ (ElementOrTextFilter *)filter 
+{
+    if (!elementOrTextFilterInstance)
+        elementOrTextFilterInstance = [[ElementOrTextFilter alloc] init];
+    return elementOrTextFilterInstance;
+}
+
+- (short)acceptNode:(DOMNode *)n
+{
+    return ([n isKindOfClass:[DOMElement class]] || [n isKindOfClass:[DOMText class]]) ? DOM_FILTER_ACCEPT : DOM_FILTER_SKIP;
+}
+
+ at end
+
 @implementation WebView (WebViewCSS)
 
 - (DOMCSSStyleDeclaration *)computedStyleForElement:(DOMElement *)element pseudoElement:(NSString *)pseudoElement
@@ -2281,19 +2303,6 @@ static WebFrame *incrementFrame(WebFrame *curr, BOOL forward, BOOL wrapFlag)
 }
 
 // FIXME: Move to WebHTMLView.
-static NSFont *_fontFromStyle(DOMCSSStyleDeclaration *style)
-{
-    // FIXME: can't get at CSS_PROP_FONT_FAMILY and such from cssproperties.h in WebCore
-    // because that header file isn't available to WebKit. Is that a problem?
-    // FIXME: calling [DOMCSSStyleDeclaration fontFamily] doesn't work yet, returns nil.
-    // FIXME: calling [DOMCSSStyleDeclaration fontSize] doesn't work yet, returns nil.
-    // FIXME: is there SPI/API for converting a fontSize string into a numeric value?
-    // FIXME: calling [DOMCSSStyleDeclaration font] doesn't work yet, fails WebCore assertion
-    //ERROR("unimplemented");
-    return nil;
-}
-
-// FIXME: Move to WebHTMLView.
 - (void)_updateFontPanel
 {
     // FIXME: NSTextView bails out if becoming or resigning first responder, for which it has ivar flags. Not
@@ -2310,55 +2319,38 @@ static NSFont *_fontFromStyle(DOMCSSStyleDeclaration *style)
     }
     
     BOOL onlyOneFontInSelection = YES;
-    DOMCSSStyleDeclaration *style = nil;
     NSFont *font = nil;
+    WebBridge *bridge = [self _bridgeForCurrentSelection];
     
-    if (![[self _bridgeForCurrentSelection] haveSelection]) {
-        style = [self typingStyle];
-        font = _fontFromStyle(style);
-        // FIXME: We're currently thinking that typingStyle will always specify a font, but we need to
-        // make sure that it's implemented that way when it is implemented.
-    } else {
-        // FIXME: This code is being reached after backspacing with only an insertion
-        // point showing; this must be a bug in haveSelection or underlying code.
+    if (![bridge haveSelection]) {
+        font = [bridge fontForCurrentPosition];
+    } 
+    else {
         DOMRange *selection = [self selectedDOMRange];
+        DOMNode *startContainer = [selection startContainer];
+        DOMNode *endContainer = [selection endContainer];
         
-        DOMNode *firstSelectedElement = [selection startContainer];
-        while (firstSelectedElement != nil && ![firstSelectedElement isKindOfClass:[DOMElement class]]) {
-            firstSelectedElement = [firstSelectedElement parentNode];
-        }
-        ASSERT([firstSelectedElement isKindOfClass:[DOMElement class]]);
+        ASSERT(startContainer);
+        ASSERT(endContainer);
+        ASSERT([[ElementOrTextFilter filter] acceptNode:startContainer] == DOM_FILTER_ACCEPT);
+        ASSERT([[ElementOrTextFilter filter] acceptNode:endContainer] == DOM_FILTER_ACCEPT);
         
-        font = [[self _bridgeForCurrentSelection] renderedFontForNode:firstSelectedElement];
-        style = [self computedStyleForElement:(DOMElement *)firstSelectedElement pseudoElement:nil];
+        font = [bridge renderedFontForNode:startContainer];
         
-        // Iterate through all selected elements to see if fonts or attributes change.
-        if ([selection startContainer] != [selection endContainer]) {
-            DOMNode *lastSelectedElement = [selection endContainer];
-            while (lastSelectedElement != nil && ![lastSelectedElement isKindOfClass:[DOMElement class]]) {
-                lastSelectedElement = [lastSelectedElement parentNode];
-            }
-            ASSERT([lastSelectedElement isKindOfClass:[DOMElement class]]);
-            
-            // FIXME: The "&& NO" prevents createNodeIterator from being called, which is nice because
-            // it's not actually defined yet.
-            if (lastSelectedElement != firstSelectedElement && NO) {
-                DOMNodeIterator *iterator = [[[selection startContainer] ownerDocument]
-                    createNodeIterator:firstSelectedElement :DOM_SHOW_ELEMENT :nil :NO];
-                DOMNode *element = [iterator nextNode];
-                ASSERT(element == firstSelectedElement);
-                
-                for (; element != lastSelectedElement; element = [iterator nextNode]) {
-                    ASSERT([element isKindOfClass:[DOMElement class]]);
-                    
-                    NSFont *otherFont = [[self _bridgeForCurrentSelection] renderedFontForNode:element];
-                    if (![font isEqual:otherFont]) {
-                        onlyOneFontInSelection = NO;
-                        break;
-                    }
+        if (startContainer != endContainer) {
+            DOMDocument *document = [bridge DOMDocument];
+            DOMTreeWalker *treeWalker = [document createTreeWalker:document :DOM_SHOW_ALL :[ElementOrTextFilter filter] :NO];
+            DOMNode *node = startContainer;
+            [treeWalker setCurrentNode:node];
+            while (node) {
+                NSFont *otherFont = [bridge renderedFontForNode:node];
+                if (![font isEqual:otherFont]) {
+                    onlyOneFontInSelection = NO;
+                    break;
                 }
-                
-                // Since our iterator is autoreleased, we needn't call [iterator detach]
+                if (node == endContainer)
+                    break;
+                node = [treeWalker nextNode];
             }
         }
     }

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list