Commit ac7f5658 authored by oliver's avatar oliver
Browse files

WebCore:

        Reviewed by Justin.

        Remove incorrect assertions.
        
        These assertions were made on the assumption that 
        TSM would always call with a range that was contained 
        by an editable region.
        
        TSM may call -[WebHTMLView characterIndexForPoint:] on a mouse
        event that is otherwise unrelated to editing, which may
        be outside the current editing region, triggering these 
        assertions.

        * page/mac/WebCoreFrameBridge.mm:
        (-[WebCoreFrameBridge convertToNSRange:]):

WebKit:

        Reviewed by Justin.
        
        Add checks to make sure we don't try to create, use
        or return invalid ranges to TSM when it calls us despite
        not currently being in an editable region.

        * WebView/WebHTMLView.mm:
        (isTextInput):
        (-[WebHTMLView textStorage]):
        (-[WebHTMLView firstRectForCharacterRange:]):
        (-[WebHTMLView selectedRange]):
        (-[WebHTMLView attributedSubstringFromRange:]):



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@22058 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 47d836d7
2007-06-07 Oliver Hunt <oliver@apple.com>
Reviewed by Justin.
Remove incorrect assertions.
These assertions were made on the assumption that
TSM would always call with a range that was contained
by an editable region.
TSM may call -[WebHTMLView characterIndexForPoint:] on a mouse
event that is otherwise unrelated to editing, which may
be outside the current editing region, triggering these
assertions.
* page/mac/WebCoreFrameBridge.mm:
(-[WebCoreFrameBridge convertToNSRange:]):
2007-06-07 Justin Garcia <justin.garcia@apple.com>
 
Reviewed by John.
......@@ -857,10 +857,13 @@ static HTMLFormElement *formElementFromDOMElement(DOMElement *element)
Element* selectionRoot = m_frame->selectionController()->rootEditableElement();
Element* scope = selectionRoot ? selectionRoot : m_frame->document()->documentElement();
// our critical assumption is that we are only called by input methods that
// concentrate on a given area containing the selection. See comments in convertToDOMRange.
ASSERT(range->startContainer(exception) == scope || range->startContainer(exception)->isDescendantOf(scope));
ASSERT(range->endContainer(exception) == scope || range->endContainer(exception)->isDescendantOf(scope));
// Mouse events may cause TSM to attempt to create an NSRange for a portion of the view
// that is not inside the current editable region. These checks ensure we don't produce
// potentially invalid data when responding to such requests.
if (range->startContainer(exception) != scope && !range->startContainer(exception)->isDescendantOf(scope))
return NSMakeRange(NSNotFound, 0);
if(range->endContainer(exception) != scope && !range->endContainer(exception)->isDescendantOf(scope))
return NSMakeRange(NSNotFound, 0);
RefPtr<Range> testRange = new Range(scope->document(), scope, 0, range->startContainer(exception), range->startOffset(exception));
ASSERT(testRange->startContainer(exception) == scope);
......
2007-06-07 Oliver Hunt <oliver@apple.com>
Reviewed by Justin.
Add checks to make sure we don't try to create, use
or return invalid ranges to TSM when it calls us despite
not currently being in an editable region.
* WebView/WebHTMLView.mm:
(isTextInput):
(-[WebHTMLView textStorage]):
(-[WebHTMLView firstRectForCharacterRange:]):
(-[WebHTMLView selectedRange]):
(-[WebHTMLView attributedSubstringFromRange:]):
2007-06-06 David Hyatt <hyatt@apple.com>
 
Make sure to hand back a script object for webkit plugins (the container
......
......@@ -5237,6 +5237,23 @@ static CGPoint coreGraphicsScreenPointForAppKitScreenPoint(NSPoint point)
return validAttributes;
}
// Utility function to make sure we don't return anything through the NSTextInput
// API when an editable region is not currently focused.
BOOL isTextInput(Frame *coreFrame)
{
return coreFrame && !coreFrame->selectionController()->isNone() && coreFrame->selectionController()->isContentEditable();
}
- (NSAttributedString *)textStorage
{
if (!isTextInput(core([self _frame])))
return nil;
NSAttributedString *result = [self attributedSubstringFromRange:NSMakeRange(0, UINT_MAX)];
// We have to return an empty string rather than null to prevent TSM from calling -string
return result ? result : [[[NSAttributedString alloc] initWithString:@""] autorelease];
}
- (WebNSUInteger)characterIndexForPoint:(NSPoint)thePoint
{
NSWindow *window = [self window];
......@@ -5255,6 +5272,9 @@ static CGPoint coreGraphicsScreenPointForAppKitScreenPoint(NSPoint point)
- (NSRect)firstRectForCharacterRange:(NSRange)theRange
{
if (!isTextInput(core([self _frame])))
return NSMakeRect(0,0,0,0);
WebFrameBridge *bridge = [self _bridge];
// Just to match NSTextView's behavior. Regression tests cannot detect this;
......@@ -5282,6 +5302,8 @@ static CGPoint coreGraphicsScreenPointForAppKitScreenPoint(NSPoint point)
- (NSRange)selectedRange
{
if (!isTextInput(core([self _frame])))
return NSMakeRange(NSNotFound,0);
return [[self _bridge] selectedNSRange];
}
......@@ -5294,6 +5316,8 @@ static CGPoint coreGraphicsScreenPointForAppKitScreenPoint(NSPoint point)
- (NSAttributedString *)attributedSubstringFromRange:(NSRange)nsRange
{
if (!isTextInput(core([self _frame])))
return nil;
WebFrameBridge *bridge = [self _bridge];
DOMRange *domRange = [bridge convertNSRangeToDOMRange:nsRange];
if (!domRange)
......@@ -5905,17 +5929,6 @@ static CGPoint coreGraphicsScreenPointForAppKitScreenPoint(NSPoint point)
return [[self _bridge] stringForRange:[self _documentRange]];
}
- (NSAttributedString *)textStorage
{
Frame* coreFrame = core([self _frame]);
if (!coreFrame || coreFrame->selectionController()->isNone()
|| !coreFrame->selectionController()->isContentEditable())
return nil;
NSAttributedString *result = [self attributedSubstringFromRange:NSMakeRange(0, UINT_MAX)];
// We have to return an empty string rather than null to prevent TSM from calling -string
return result ? result : [[[NSAttributedString alloc] initWithString:@""] autorelease];
}
- (NSAttributedString *)_attributeStringFromDOMRange:(DOMRange *)range
{
NSAttributedString *attributedString;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment