diff options
Diffstat (limited to 'WebKit/mac/WebView/WebHTMLView.mm')
| -rw-r--r-- | WebKit/mac/WebView/WebHTMLView.mm | 550 |
1 files changed, 336 insertions, 214 deletions
diff --git a/WebKit/mac/WebView/WebHTMLView.mm b/WebKit/mac/WebView/WebHTMLView.mm index 54a177e..a619f18 100644 --- a/WebKit/mac/WebView/WebHTMLView.mm +++ b/WebKit/mac/WebView/WebHTMLView.mm @@ -118,6 +118,7 @@ #import <dlfcn.h> #import <limits> #import <runtime/InitializeThreading.h> +#import <wtf/Threading.h> #if USE(ACCELERATED_COMPOSITING) #import <QuartzCore/QuartzCore.h> @@ -148,26 +149,54 @@ using namespace std; - (BOOL)receivedUnhandledCommand; @end -static IMP oldSetCursorIMP = NULL; +// if YES, do the standard NSView hit test (which can't give the right result when HTML overlaps a view) +static BOOL forceNSViewHitTest; -#ifdef BUILDING_ON_TIGER +// if YES, do the "top WebHTMLView" hit test (which we'd like to do all the time but can't because of Java requirements [see bug 4349721]) +static BOOL forceWebHTMLViewHitTest; + +static WebHTMLView *lastHitView; + +static bool needsCursorRectsSupportAtPoint(NSWindow* window, NSPoint point) +{ + forceNSViewHitTest = YES; + NSView* view = [[window _web_borderView] hitTest:point]; + forceNSViewHitTest = NO; + + // WebHTMLView doesn't use cursor rects. + if ([view isKindOfClass:[WebHTMLView class]]) + return false; + +#if ENABLE(NETSCAPE_PLUGIN_API) + // Neither do NPAPI plug-ins. + if ([view isKindOfClass:[WebBaseNetscapePluginView class]]) + return false; +#endif + + // Non-Web content, WebPDFView, and WebKit plug-ins use normal cursor handling. + return true; +} -static IMP oldResetCursorRectsIMP = NULL; +#ifndef BUILDING_ON_TIGER + +static IMP oldSetCursorForMouseLocationIMP; + +// Overriding an internal method is a hack; <rdar://problem/7662987> tracks finding a better solution. +static void setCursor(NSWindow *self, SEL cmd, NSPoint point) +{ + if (needsCursorRectsSupportAtPoint(self, point)) + oldSetCursorForMouseLocationIMP(self, cmd, point); +} + +#else + +static IMP oldResetCursorRectsIMP; +static IMP oldSetCursorIMP; static BOOL canSetCursor = YES; static void resetCursorRects(NSWindow* self, SEL cmd) { - NSPoint point = [self mouseLocationOutsideOfEventStream]; - NSView* view = [[self _web_borderView] hitTest:point]; - if ([view isKindOfClass:[WebHTMLView class]]) { - WebHTMLView *htmlView = (WebHTMLView*)view; - NSPoint localPoint = [htmlView convertPoint:point fromView:nil]; - NSDictionary *dict = [htmlView elementAtPoint:localPoint allowShadowContent:NO]; - DOMElement *element = [dict objectForKey:WebElementDOMNodeKey]; - if (![element isKindOfClass:[DOMHTMLAppletElement class]] && ![element isKindOfClass:[DOMHTMLObjectElement class]] && - ![element isKindOfClass:[DOMHTMLEmbedElement class]]) - canSetCursor = NO; - } + canSetCursor = needsCursorRectsSupportAtPoint(self, [self mouseLocationOutsideOfEventStream]); oldResetCursorRectsIMP(self, cmd); canSetCursor = YES; } @@ -178,23 +207,6 @@ static void setCursor(NSCursor* self, SEL cmd) oldSetCursorIMP(self, cmd); } -#else - -static void setCursor(NSWindow* self, SEL cmd, NSPoint point) -{ - NSView* view = [[self _web_borderView] hitTest:point]; - if ([view isKindOfClass:[WebHTMLView class]]) { - WebHTMLView *htmlView = (WebHTMLView*)view; - NSPoint localPoint = [htmlView convertPoint:point fromView:nil]; - NSDictionary *dict = [htmlView elementAtPoint:localPoint allowShadowContent:NO]; - DOMElement *element = [dict objectForKey:WebElementDOMNodeKey]; - if (![element isKindOfClass:[DOMHTMLAppletElement class]] && ![element isKindOfClass:[DOMHTMLObjectElement class]] && - ![element isKindOfClass:[DOMHTMLEmbedElement class]]) - return; - } - oldSetCursorIMP(self, cmd, point); -} - #endif extern "C" { @@ -212,6 +224,7 @@ extern NSString *NSTextInputReplacementRangeAttributeName; - (void)_recursive:(BOOL)recurse displayRectIgnoringOpacity:(NSRect)displayRect inContext:(NSGraphicsContext *)context topView:(BOOL)topView; - (NSRect)_dirtyRect; - (void)_setDrawsOwnDescendants:(BOOL)drawsOwnDescendants; +- (BOOL)_drawnByAncestor; - (void)_propagateDirtyRectsToOpaqueAncestors; - (void)_windowChangedKeyState; #if USE(ACCELERATED_COMPOSITING) && defined(BUILDING_ON_LEOPARD) @@ -219,6 +232,42 @@ extern NSString *NSTextInputReplacementRangeAttributeName; #endif @end +#if USE(ACCELERATED_COMPOSITING) +static IMP oldSetNeedsDisplayInRectIMP; + +static void setNeedsDisplayInRect(NSView *self, SEL cmd, NSRect invalidRect) +{ + if (![self _drawnByAncestor]) { + oldSetNeedsDisplayInRectIMP(self, cmd, invalidRect); + return; + } + + static Class webFrameViewClass = [WebFrameView class]; + WebFrameView *enclosingWebFrameView = (WebFrameView *)self; + while (enclosingWebFrameView && ![enclosingWebFrameView isKindOfClass:webFrameViewClass]) + enclosingWebFrameView = (WebFrameView *)[enclosingWebFrameView superview]; + + if (!enclosingWebFrameView) { + oldSetNeedsDisplayInRectIMP(self, cmd, invalidRect); + return; + } + + Frame* coreFrame = core([enclosingWebFrameView webFrame]); + FrameView* frameView = coreFrame ? coreFrame->view() : 0; + if (!frameView || !frameView->isEnclosedInCompositingLayer()) { + oldSetNeedsDisplayInRectIMP(self, cmd, invalidRect); + return; + } + + NSRect invalidRectInWebFrameViewCoordinates = [enclosingWebFrameView convertRect:invalidRect fromView:self]; + IntRect invalidRectInFrameViewCoordinates(invalidRectInWebFrameViewCoordinates); + if (![enclosingWebFrameView isFlipped]) + invalidRectInFrameViewCoordinates.setY(frameView->frameRect().size().height() - invalidRectInFrameViewCoordinates.bottom()); + + frameView->invalidateRect(invalidRectInFrameViewCoordinates); +} +#endif // USE(ACCELERATED_COMPOSITING) + @interface NSApplication (WebNSApplicationDetails) - (void)speakString:(NSString *)string; @end @@ -241,13 +290,13 @@ extern NSString *NSTextInputReplacementRangeAttributeName; // print in IE and Camino. This lets them use fewer sheets than they // would otherwise, which is presumably why other browsers do this. // Wide pages will be scaled down more than this. -#define PrintingMinimumShrinkFactor 1.25f +const float _WebHTMLViewPrintingMinimumShrinkFactor = 1.25; // This number determines how small we are willing to reduce the page content // in order to accommodate the widest line. If the page would have to be // reduced smaller to make the widest line fit, we just clip instead (this // behavior matches MacIE and Mozilla, at least) -#define PrintingMaximumShrinkFactor 2.0f +const float _WebHTMLViewPrintingMaximumShrinkFactor = 2; // This number determines how short the last printed page of a multi-page print session // can be before we try to shrink the scale in order to reduce the number of pages, and @@ -294,14 +343,6 @@ extern NSString *NSTextInputReplacementRangeAttributeName; @implementation WebCoreScrollView @end -// if YES, do the standard NSView hit test (which can't give the right result when HTML overlaps a view) -static BOOL forceNSViewHitTest; - -// if YES, do the "top WebHTMLView" hit test (which we'd like to do all the time but can't because of Java requirements [see bug 4349721]) -static BOOL forceWebHTMLViewHitTest; - -static WebHTMLView *lastHitView; - // We need this to be able to safely reference the CachedImage for the promised drag data static CachedResourceClient* promisedDataClient() { @@ -314,14 +355,12 @@ static CachedResourceClient* promisedDataClient() - (DOMDocumentFragment *)_documentFragmentFromPasteboard:(NSPasteboard *)pasteboard inContext:(DOMRange *)context allowPlainText:(BOOL)allowPlainText; - (NSString *)_plainTextFromPasteboard:(NSPasteboard *)pasteboard; - (void)_pasteWithPasteboard:(NSPasteboard *)pasteboard allowPlainText:(BOOL)allowPlainText; -- (void)_pasteAsPlainTextWithPasteboard:(NSPasteboard *)pasteboard; - (void)_removeMouseMovedObserverUnconditionally; - (void)_removeSuperviewObservers; - (void)_removeWindowObservers; - (BOOL)_shouldInsertFragment:(DOMDocumentFragment *)fragment replacingDOMRange:(DOMRange *)range givenAction:(WebViewInsertAction)action; - (BOOL)_shouldInsertText:(NSString *)text replacingDOMRange:(DOMRange *)range givenAction:(WebViewInsertAction)action; - (BOOL)_shouldReplaceSelectionWithText:(NSString *)text givenAction:(WebViewInsertAction)action; -- (float)_calculatePrintHeight; - (DOMRange *)_selectedRange; - (BOOL)_shouldDeleteRange:(DOMRange *)range; - (NSView *)_hitViewForEvent:(NSEvent *)event; @@ -362,7 +401,7 @@ static CachedResourceClient* promisedDataClient() #endif @interface WebHTMLView (WebForwardDeclaration) // FIXME: Put this in a normal category and stop doing the forward declaration trick. -- (void)_setPrinting:(BOOL)printing minimumPageWidth:(float)minPageWidth maximumPageWidth:(float)maxPageWidth adjustViewSize:(BOOL)adjustViewSize; +- (void)_setPrinting:(BOOL)printing minimumPageWidth:(float)minPageWidth height:(float)minPageHeight maximumPageWidth:(float)maxPageWidth adjustViewSize:(BOOL)adjustViewSize paginateScreenContent:(BOOL)paginateScreenContent; @end @class NSTextInputContext; @@ -408,6 +447,7 @@ struct WebHTMLViewInterpretKeyEventsParameters { BOOL ignoringMouseDraggedEvents; BOOL printing; BOOL avoidingPrintOrphan; + BOOL paginateScreenContent; BOOL observingMouseMovedNotifications; BOOL observingSuperviewNotifications; BOOL observingWindowNotifications; @@ -428,6 +468,9 @@ struct WebHTMLViewInterpretKeyEventsParameters { BOOL exposeInputContext; NSPoint lastScrollPosition; +#ifndef BUILDING_ON_TIGER + BOOL inScrollPositionChanged; +#endif WebPluginController *pluginController; @@ -487,23 +530,35 @@ static NSCellStateValue kit(TriState state) + (void)initialize { JSC::initializeThreading(); + WTF::initializeMainThreadToProcessMainThread(); #ifndef BUILDING_ON_TIGER WebCoreObjCFinalizeOnMainThread(self); #endif + +#ifndef BUILDING_ON_TIGER + if (!oldSetCursorForMouseLocationIMP) { + Method setCursorMethod = class_getInstanceMethod([NSWindow class], @selector(_setCursorForMouseLocation:)); + ASSERT(setCursorMethod); + oldSetCursorForMouseLocationIMP = method_setImplementation(setCursorMethod, (IMP)setCursor); + ASSERT(oldSetCursorForMouseLocationIMP); + } + +#if USE(ACCELERATED_COMPOSITING) + if (!oldSetNeedsDisplayInRectIMP) { + Method setNeedsDisplayInRectMethod = class_getInstanceMethod([NSView class], @selector(setNeedsDisplayInRect:)); + ASSERT(setNeedsDisplayInRectMethod); + oldSetNeedsDisplayInRectIMP = method_setImplementation(setNeedsDisplayInRectMethod, (IMP)setNeedsDisplayInRect); + ASSERT(oldSetNeedsDisplayInRectIMP); + } +#endif // USE(ACCELERATED_COMPOSITING) +#else // defined(BUILDING_ON_TIGER) if (!oldSetCursorIMP) { -#ifdef BUILDING_ON_TIGER Method setCursorMethod = class_getInstanceMethod([NSCursor class], @selector(set)); -#else - Method setCursorMethod = class_getInstanceMethod([NSWindow class], @selector(_setCursorForMouseLocation:)); -#endif ASSERT(setCursorMethod); - oldSetCursorIMP = method_setImplementation(setCursorMethod, (IMP)setCursor); ASSERT(oldSetCursorIMP); } - -#ifdef BUILDING_ON_TIGER if (!oldResetCursorRectsIMP) { Method resetCursorRectsMethod = class_getInstanceMethod([NSWindow class], @selector(resetCursorRects)); ASSERT(resetCursorRectsMethod); @@ -797,11 +852,12 @@ static NSURL* uniqueURLWithRelativePart(NSString *relativePart) [webView _setInsertionPasteboard:pasteboard]; DOMRange *range = [self _selectedRange]; + Frame* coreFrame = core([self _frame]); #if !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD) DOMDocumentFragment *fragment = [self _documentFragmentFromPasteboard:pasteboard inContext:range allowPlainText:allowPlainText]; if (fragment && [self _shouldInsertFragment:fragment replacingDOMRange:range givenAction:WebViewInsertActionPasted]) - [[self _frame] _replaceSelectionWithFragment:fragment selectReplacement:NO smartReplace:[self _canSmartReplaceWithPasteboard:pasteboard] matchStyle:NO]; + coreFrame->editor()->pasteAsFragment(core(fragment), [self _canSmartReplaceWithPasteboard:pasteboard], false); #else // Mail is ignoring the frament passed to the delegate and creates a new one. // We want to avoid creating the fragment twice. @@ -809,31 +865,18 @@ static NSURL* uniqueURLWithRelativePart(NSString *relativePart) if ([self _shouldInsertFragment:nil replacingDOMRange:range givenAction:WebViewInsertActionPasted]) { DOMDocumentFragment *fragment = [self _documentFragmentFromPasteboard:pasteboard inContext:range allowPlainText:allowPlainText]; if (fragment) - [[self _frame] _replaceSelectionWithFragment:fragment selectReplacement:NO smartReplace:[self _canSmartReplaceWithPasteboard:pasteboard] matchStyle:NO]; + coreFrame->editor()->pasteAsFragment(core(fragment), [self _canSmartReplaceWithPasteboard:pasteboard], false); } } else { DOMDocumentFragment *fragment = [self _documentFragmentFromPasteboard:pasteboard inContext:range allowPlainText:allowPlainText]; if (fragment && [self _shouldInsertFragment:fragment replacingDOMRange:range givenAction:WebViewInsertActionPasted]) - [[self _frame] _replaceSelectionWithFragment:fragment selectReplacement:NO smartReplace:[self _canSmartReplaceWithPasteboard:pasteboard] matchStyle:NO]; + coreFrame->editor()->pasteAsFragment(core(fragment), [self _canSmartReplaceWithPasteboard:pasteboard], false); } #endif [webView _setInsertionPasteboard:nil]; [webView release]; } -- (void)_pasteAsPlainTextWithPasteboard:(NSPasteboard *)pasteboard -{ - WebView *webView = [[self _webView] retain]; - [webView _setInsertionPasteboard:pasteboard]; - - NSString *text = [self _plainTextFromPasteboard:pasteboard]; - if ([self _shouldReplaceSelectionWithText:text givenAction:WebViewInsertActionPasted]) - [[self _frame] _replaceSelectionWithText:text selectReplacement:NO smartReplace:[self _canSmartReplaceWithPasteboard:pasteboard]]; - - [webView _setInsertionPasteboard:nil]; - [webView release]; -} - - (void)_removeMouseMovedObserverUnconditionally { if (!_private || !_private->observingMouseMovedNotifications) @@ -896,17 +939,6 @@ static NSURL* uniqueURLWithRelativePart(NSString *relativePart) return [self _shouldInsertText:text replacingDOMRange:[self _selectedRange] givenAction:action]; } -// Calculate the vertical size of the view that fits on a single page -- (float)_calculatePrintHeight -{ - // Obtain the print info object for the current operation - NSPrintInfo *pi = [[NSPrintOperation currentOperation] printInfo]; - - // Calculate the page height in points - NSSize paperSize = [pi paperSize]; - return paperSize.height - [pi topMargin] - [pi bottomMargin]; -} - - (DOMRange *)_selectedRange { Frame* coreFrame = core([self _frame]); @@ -1012,7 +1044,7 @@ static NSURL* uniqueURLWithRelativePart(NSString *relativePart) - (void)_web_setPrintingModeRecursive { - [self _setPrinting:YES minimumPageWidth:0.0f maximumPageWidth:0.0f adjustViewSize:NO]; + [self _setPrinting:YES minimumPageWidth:0 height:0 maximumPageWidth:0 adjustViewSize:NO paginateScreenContent:[self _isInScreenPaginationMode]]; #ifndef NDEBUG _private->enumeratingSubviews = YES; @@ -1024,7 +1056,7 @@ static NSURL* uniqueURLWithRelativePart(NSString *relativePart) unsigned count = [descendantWebHTMLViews count]; for (unsigned i = 0; i < count; ++i) - [[descendantWebHTMLViews objectAtIndex:i] _setPrinting:YES minimumPageWidth:0.0f maximumPageWidth:0.0f adjustViewSize:NO]; + [[descendantWebHTMLViews objectAtIndex:i] _setPrinting:YES minimumPageWidth:0 height:0 maximumPageWidth:0 adjustViewSize:NO paginateScreenContent:[self _isInScreenPaginationMode]]; [descendantWebHTMLViews release]; @@ -1035,7 +1067,7 @@ static NSURL* uniqueURLWithRelativePart(NSString *relativePart) - (void)_web_clearPrintingModeRecursive { - [self _setPrinting:NO minimumPageWidth:0.0f maximumPageWidth:0.0f adjustViewSize:NO]; + [self _setPrinting:NO minimumPageWidth:0 height:0 maximumPageWidth:0 adjustViewSize:NO paginateScreenContent:[self _isInScreenPaginationMode]]; #ifndef NDEBUG _private->enumeratingSubviews = YES; @@ -1047,7 +1079,7 @@ static NSURL* uniqueURLWithRelativePart(NSString *relativePart) unsigned count = [descendantWebHTMLViews count]; for (unsigned i = 0; i < count; ++i) - [[descendantWebHTMLViews objectAtIndex:i] _setPrinting:NO minimumPageWidth:0.0f maximumPageWidth:0.0f adjustViewSize:NO]; + [[descendantWebHTMLViews objectAtIndex:i] _setPrinting:NO minimumPageWidth:0 height:0 maximumPageWidth:0 adjustViewSize:NO paginateScreenContent:[self _isInScreenPaginationMode]]; [descendantWebHTMLViews release]; @@ -1058,7 +1090,7 @@ static NSURL* uniqueURLWithRelativePart(NSString *relativePart) - (void)_web_setPrintingModeRecursiveAndAdjustViewSize { - [self _setPrinting:YES minimumPageWidth:0.0f maximumPageWidth:0.0f adjustViewSize:YES]; + [self _setPrinting:YES minimumPageWidth:0 height:0 maximumPageWidth:0 adjustViewSize:YES paginateScreenContent:[self _isInScreenPaginationMode]]; #ifndef NDEBUG _private->enumeratingSubviews = YES; @@ -1070,7 +1102,7 @@ static NSURL* uniqueURLWithRelativePart(NSString *relativePart) unsigned count = [descendantWebHTMLViews count]; for (unsigned i = 0; i < count; ++i) - [[descendantWebHTMLViews objectAtIndex:i] _setPrinting:YES minimumPageWidth:0.0f maximumPageWidth:0.0f adjustViewSize:YES]; + [[descendantWebHTMLViews objectAtIndex:i] _setPrinting:YES minimumPageWidth:0 height:0 maximumPageWidth:0 adjustViewSize:YES paginateScreenContent:[self _isInScreenPaginationMode]]; [descendantWebHTMLViews release]; @@ -1169,8 +1201,15 @@ static void _updateMouseoverTimerCallback(CFRunLoopTimerRef timer, void *info) NSPoint origin = [[self superview] bounds].origin; if (!NSEqualPoints(_private->lastScrollPosition, origin)) { if (Frame* coreFrame = core([self _frame])) { - if (FrameView* coreView = coreFrame->view()) - coreView->scrollPositionChanged(); + if (FrameView* coreView = coreFrame->view()) { +#ifndef BUILDING_ON_TIGER + _private->inScrollPositionChanged = YES; +#endif + coreView->scrollPositionChangedViaPlatformWidget(); +#ifndef BUILDING_ON_TIGER + _private->inScrollPositionChanged = NO; +#endif + } } [_private->completionController endRevertingChange:NO moveLeft:NO]; @@ -1239,15 +1278,6 @@ static void _updateMouseoverTimerCallback(CFRunLoopTimerRef timer, void *info) if (_private->enumeratingSubviews) LOG(View, "A view of class %s was added during subview enumeration for layout or printing mode change. This view might paint without first receiving layout.", object_getClassName([subview class])); } - -- (void)willRemoveSubview:(NSView *)subview -{ - // Have to null-check _private, since this can be called via -dealloc when - // cleaning up the the layerHostingView. - if (_private && _private->enumeratingSubviews) - LOG(View, "A view of class %s was removed during subview enumeration for layout or printing mode change. We will still do layout or the printing mode change even though this view is no longer in the view hierarchy.", object_getClassName([subview class])); -} - #endif #ifdef BUILDING_ON_TIGER @@ -1299,11 +1329,15 @@ static void _updateMouseoverTimerCallback(CFRunLoopTimerRef timer, void *info) // There are known cases where -viewWillDraw is not called on all views being drawn. // See <rdar://problem/6964278> for example. Performing layout at this point prevents us from // trying to paint without layout (which WebCore now refuses to do, instead bailing out without - // drawing at all), but we may still fail to update and regions dirtied by the layout which are + // drawing at all), but we may still fail to update any regions dirtied by the layout which are // not already dirty. if ([self _needsLayout]) { - LOG_ERROR("View needs layout. Either -viewWillDraw wasn't called or layout was invalidated during the display operation. Performing layout now."); - [self _web_layoutIfNeededRecursive]; + NSInteger rectCount; + [self getRectsBeingDrawn:0 count:&rectCount]; + if (rectCount) { + LOG_ERROR("View needs layout. Either -viewWillDraw wasn't called or layout was invalidated during the display operation. Performing layout now."); + [self _web_layoutIfNeededRecursive]; + } } #else // Because Tiger does not have viewWillDraw we need to do layout here. @@ -1430,6 +1464,7 @@ static void _updateMouseoverTimerCallback(CFRunLoopTimerRef timer, void *info) else if (forceWebHTMLViewHitTest) captureHitsOnSubviews = YES; else { + // FIXME: Why doesn't this include mouse entered/exited events, or other mouse button events? NSEvent *event = [[self window] currentEvent]; captureHitsOnSubviews = !([event type] == NSMouseMoved || [event type] == NSRightMouseDown @@ -2194,6 +2229,93 @@ static void _updateMouseoverTimerCallback(CFRunLoopTimerRef timer, void *info) #endif } +- (BOOL)_isInPrintMode +{ + return _private->printing; +} + +- (BOOL)_beginPrintModeWithPageWidth:(float)pageWidth height:(float)pageHeight shrinkToFit:(BOOL)shrinkToFit +{ + Frame* frame = core([self _frame]); + if (!frame) + return NO; + + float minLayoutWidth = 0; + float minLayoutHeight = 0; + float maxLayoutWidth = 0; + + // If we are a frameset just print with the layout we have onscreen, otherwise relayout + // according to the page width. + if (!frame->document() || !frame->document()->isFrameSet()) { + minLayoutWidth = shrinkToFit ? pageWidth * _WebHTMLViewPrintingMinimumShrinkFactor : pageWidth; + minLayoutHeight = shrinkToFit ? pageHeight * _WebHTMLViewPrintingMinimumShrinkFactor : pageHeight; + maxLayoutWidth = shrinkToFit ? pageWidth * _WebHTMLViewPrintingMaximumShrinkFactor : pageWidth; + } + [self _setPrinting:YES minimumPageWidth:minLayoutWidth height:minLayoutHeight maximumPageWidth:maxLayoutWidth adjustViewSize:YES paginateScreenContent:[self _isInScreenPaginationMode]]; + + return YES; +} + +- (void)_endPrintMode +{ + [self _setPrinting:NO minimumPageWidth:0 height:0 maximumPageWidth:0 adjustViewSize:YES paginateScreenContent:[self _isInScreenPaginationMode]]; +} + +- (BOOL)_isInScreenPaginationMode +{ + return _private->paginateScreenContent; +} + +- (BOOL)_beginScreenPaginationModeWithPageSize:(CGSize)pageSize shrinkToFit:(BOOL)shrinkToFit +{ + Frame* frame = core([self _frame]); + if (!frame) + return NO; + + CGFloat minLayoutWidth = 0; + CGFloat minLayoutHeight = 0; + CGFloat maxLayoutWidth = 0; + + // If we are a frameset just print with the layout we have on the screen. Otherwise do a relayout + // according to the page width. + if (!frame->document() || !frame->document()->isFrameSet()) { + minLayoutWidth = shrinkToFit ? pageSize.width * _WebHTMLViewPrintingMinimumShrinkFactor : pageSize.width; + minLayoutHeight = shrinkToFit ? pageSize.height * _WebHTMLViewPrintingMinimumShrinkFactor : pageSize.height; + maxLayoutWidth = shrinkToFit ? pageSize.width * _WebHTMLViewPrintingMaximumShrinkFactor : pageSize.width; + } + [self _setPrinting:[self _isInPrintMode] minimumPageWidth:minLayoutWidth height:minLayoutHeight maximumPageWidth:maxLayoutWidth adjustViewSize:YES paginateScreenContent:YES]; + + return YES; +} + +- (void)_endScreenPaginationMode +{ + [self _setPrinting:[self _isInPrintMode] minimumPageWidth:0 height:0 maximumPageWidth:0 adjustViewSize:YES paginateScreenContent:NO]; +} + +- (CGFloat)_adjustedBottomOfPageWithTop:(CGFloat)top bottom:(CGFloat)bottom limit:(CGFloat)bottomLimit +{ + Frame* frame = core([self _frame]); + if (!frame) + return bottom; + + FrameView* view = frame->view(); + if (!view) + return bottom; + + float newBottom; + view->adjustPageHeight(&newBottom, top, bottom, bottomLimit); + +#ifdef __LP64__ + // If the new bottom is equal to the old bottom (when both are treated as floats), we just return the original + // bottom. This prevents rounding errors that can occur when converting newBottom to a double. + if (fabs(static_cast<float>(bottom) - newBottom) <= numeric_limits<float>::epsilon()) + return bottom; + else +#endif + return newBottom; +} + @end @implementation NSView (WebHTMLViewFileInternal) @@ -2268,6 +2390,7 @@ static bool matchesExtensionOrEquivalent(NSString *filename, NSString *extension [NSApp registerServicesMenuSendTypes:[[self class] _selectionPasteboardTypes] returnTypes:[[self class] _insertablePasteboardTypes]]; JSC::initializeThreading(); + WTF::initializeMainThreadToProcessMainThread(); #ifndef BUILDING_ON_TIGER WebCoreObjCFinalizeOnMainThread(self); #endif @@ -2477,6 +2600,7 @@ WEBCORE_COMMAND(pageDown) WEBCORE_COMMAND(pageDownAndModifySelection) WEBCORE_COMMAND(pageUp) WEBCORE_COMMAND(pageUpAndModifySelection) +WEBCORE_COMMAND(pasteAsPlainText) WEBCORE_COMMAND(selectAll) WEBCORE_COMMAND(selectLine) WEBCORE_COMMAND(selectParagraph) @@ -2516,22 +2640,16 @@ WEBCORE_COMMAND(yankAndSelect) return YES; } -- (BOOL)readSelectionFromPasteboard:(NSPasteboard *)pasteboard -{ - Frame* coreFrame = core([self _frame]); - if (!coreFrame) - return NO; - if (coreFrame->selection()->isContentRichlyEditable()) - [self _pasteWithPasteboard:pasteboard allowPlainText:YES]; - else - [self _pasteAsPlainTextWithPasteboard:pasteboard]; - return YES; -} - - (id)validRequestorForSendType:(NSString *)sendType returnType:(NSString *)returnType { BOOL isSendTypeOK = !sendType || ([[self pasteboardTypesForSelection] containsObject:sendType] && [self _hasSelection]); - BOOL isReturnTypeOK = !returnType || ([[[self class] _insertablePasteboardTypes] containsObject:returnType] && [self _isEditable]); + BOOL isReturnTypeOK = NO; + if (!returnType) + isReturnTypeOK = YES; + else if ([[[self class] _insertablePasteboardTypes] containsObject:returnType] && [self _isEditable]) { + // We can insert strings in any editable context. We can insert other types, like images, only in rich edit contexts. + isReturnTypeOK = [returnType isEqualToString:NSStringPboardType] || [self _canEditRichly]; + } if (isSendTypeOK && isReturnTypeOK) return self; return [[self nextResponder] validRequestorForSendType:sendType returnType:returnType]; @@ -2924,7 +3042,9 @@ WEBCORE_COMMAND(yankAndSelect) [self _removeWindowObservers]; [self _removeSuperviewObservers]; [self _cancelUpdateMouseoverTimer]; - + + // FIXME: This accomplishes the same thing as the call to setCanStartMedia(false) in + // WebView. It would be nice to have a single mechanism instead of two. [[self _pluginController] stopAllPlugins]; } @@ -2944,9 +3064,20 @@ WEBCORE_COMMAND(yankAndSelect) [self addSuperviewObservers]; [self addMouseMovedObserver]; + // FIXME: This accomplishes the same thing as the call to setCanStartMedia(true) in + // WebView. It would be nice to have a single mechanism instead of two. [[self _pluginController] startAllPlugins]; _private->lastScrollPosition = NSZeroPoint; + +#if USE(ACCELERATED_COMPOSITING) && !defined(BUILDING_ON_LEOPARD) + // We may have created the layer hosting view while outside the window. Update the scale factor + // now that we have a window to get it from. + if (_private->layerHostingView) { + CGFloat scaleFactor = [[self window] userSpaceScaleFactor]; + [[_private->layerHostingView layer] setTransform:CATransform3DMakeScale(scaleFactor, scaleFactor, 1)]; + } +#endif } } @@ -2971,6 +3102,13 @@ WEBCORE_COMMAND(yankAndSelect) - (void)willRemoveSubview:(NSView *)subview { +#ifndef NDEBUG + // Have to null-check _private, since this can be called via -dealloc when + // cleaning up the the layerHostingView. + if (_private && _private->enumeratingSubviews) + LOG(View, "A view of class %s was removed during subview enumeration for layout or printing mode change. We will still do layout or the printing mode change even though this view is no longer in the view hierarchy.", object_getClassName([subview class])); +#endif + if ([WebPluginController isPlugInView:subview]) [[self _pluginController] destroyPlugin:subview]; @@ -2989,8 +3127,10 @@ WEBCORE_COMMAND(yankAndSelect) if (Frame* coreFrame = core([self _frame])) { if (FrameView* coreView = coreFrame->view()) coreView->setMediaType(_private->printing ? "print" : "screen"); - if (Document* document = coreFrame->document()) + if (Document* document = coreFrame->document()) { + document->setPaginatedForScreen(_private->paginateScreenContent); document->setPrinting(_private->printing); + } coreFrame->reapplyStyles(); } @@ -3004,7 +3144,7 @@ WEBCORE_COMMAND(yankAndSelect) // Do a layout, but set up a new fixed width for the purposes of doing printing layout. // minPageWidth==0 implies a non-printing layout -- (void)layoutToMinimumPageWidth:(float)minPageWidth maximumPageWidth:(float)maxPageWidth adjustingViewSize:(BOOL)adjustViewSize +- (void)layoutToMinimumPageWidth:(float)minPageWidth height:(float)minPageHeight maximumPageWidth:(float)maxPageWidth adjustingViewSize:(BOOL)adjustViewSize { [self reapplyStyles]; @@ -3023,7 +3163,7 @@ WEBCORE_COMMAND(yankAndSelect) if (FrameView* coreView = coreFrame->view()) { if (minPageWidth > 0.0) - coreView->forceLayoutWithPageWidthRange(minPageWidth, maxPageWidth, adjustViewSize); + coreView->forceLayoutForPagination(FloatSize(minPageWidth, minPageHeight), maxPageWidth / minPageWidth, adjustViewSize ? Frame::AdjustViewSize : Frame::DoNotAdjustViewSize); else { coreView->forceLayout(!adjustViewSize); if (adjustViewSize) @@ -3039,7 +3179,7 @@ WEBCORE_COMMAND(yankAndSelect) - (void)layout { - [self layoutToMinimumPageWidth:0.0f maximumPageWidth:0.0f adjustingViewSize:NO]; + [self layoutToMinimumPageWidth:0 height:0 maximumPageWidth:0 adjustingViewSize:NO]; } // Deliver mouseup events to the DOM for button 2. @@ -3128,11 +3268,29 @@ WEBCORE_COMMAND(yankAndSelect) return [[self _webView] drawsBackground]; } +#if !LOG_DISABLED - (void)setNeedsDisplay:(BOOL)flag { LOG(View, "%@ setNeedsDisplay:%@", self, flag ? @"YES" : @"NO"); [super setNeedsDisplay:flag]; } +#endif + +#ifndef BUILDING_ON_TIGER +- (void)setNeedsDisplayInRect:(NSRect)invalidRect +{ + if (_private->inScrollPositionChanged) { + // When scrolling, the dirty regions are adjusted for the scroll only + // after NSViewBoundsDidChangeNotification is sent. Translate the invalid + // rect to pre-scrolled coordinates in order to get the right dirty region + // after adjustment. See <rdar://problem/7678927>. + NSPoint origin = [[self superview] bounds].origin; + invalidRect.origin.x -= _private->lastScrollPosition.x - origin.x; + invalidRect.origin.y -= _private->lastScrollPosition.y - origin.y; + } + [super setNeedsDisplayInRect:invalidRect]; +} +#endif - (void)setNeedsLayout: (BOOL)flag { @@ -3224,16 +3382,14 @@ WEBCORE_COMMAND(yankAndSelect) if (subviewsWereSetAside) [self _setAsideSubviews]; - + #if USE(ACCELERATED_COMPOSITING) - if ([webView _needsOneShotDrawingSynchronization]) { - // Disable screen updates so that any layer changes committed here - // don't show up on the screen before the window flush at the end - // of the current window display, but only if a window flush is actually - // going to happen. - NSWindow *window = [self window]; - if ([window viewsNeedDisplay]) - [window disableScreenUpdatesUntilFlush]; + // Only do the synchronization dance if we're drawing into the window, otherwise + // we risk disabling screen updates when no flush is pending. + if ([NSGraphicsContext currentContext] == [[self window] graphicsContext] && [webView _needsOneShotDrawingSynchronization]) { + // Disable screen updates to minimize the chances of the race between the CA + // display link and AppKit drawing causing flashes. + [[self window] disableScreenUpdatesUntilFlush]; // Make sure any layer changes that happened as a result of layout // via -viewWillDraw are committed. @@ -3248,7 +3404,7 @@ WEBCORE_COMMAND(yankAndSelect) { if (!([[self superview] isKindOfClass:[WebClipView class]])) return [super visibleRect]; - + WebClipView *clipView = (WebClipView *)[self superview]; BOOL hasAdditionalClip = [clipView hasAdditionalClip]; @@ -3704,8 +3860,11 @@ static BOOL isInPasswordField(Frame* coreFrame) // Does setNeedsDisplay:NO as a side effect when printing is ending. // pageWidth != 0 implies we will relayout to a new width -- (void)_setPrinting:(BOOL)printing minimumPageWidth:(float)minPageWidth maximumPageWidth:(float)maxPageWidth adjustViewSize:(BOOL)adjustViewSize +- (void)_setPrinting:(BOOL)printing minimumPageWidth:(float)minPageWidth height:(float)minPageHeight maximumPageWidth:(float)maxPageWidth adjustViewSize:(BOOL)adjustViewSize paginateScreenContent:(BOOL)paginateScreenContent { + if (printing == _private->printing && paginateScreenContent == _private->paginateScreenContent) + return; + WebFrame *frame = [self _frame]; NSArray *subframes = [frame childFrames]; unsigned n = [subframes count]; @@ -3714,23 +3873,22 @@ static BOOL isInPasswordField(Frame* coreFrame) WebFrame *subframe = [subframes objectAtIndex:i]; WebFrameView *frameView = [subframe frameView]; if ([[subframe _dataSource] _isDocumentHTML]) { - [(WebHTMLView *)[frameView documentView] _setPrinting:printing minimumPageWidth:0.0f maximumPageWidth:0.0f adjustViewSize:adjustViewSize]; + [(WebHTMLView *)[frameView documentView] _setPrinting:printing minimumPageWidth:0 height:0 maximumPageWidth:0 adjustViewSize:adjustViewSize paginateScreenContent:paginateScreenContent]; } } - if (printing != _private->printing) { - [_private->pageRects release]; - _private->pageRects = nil; - _private->printing = printing; - if (!printing) - _private->avoidingPrintOrphan = NO; - [self setNeedsToApplyStyles:YES]; - [self setNeedsLayout:YES]; - [self layoutToMinimumPageWidth:minPageWidth maximumPageWidth:maxPageWidth adjustingViewSize:adjustViewSize]; - if (!printing) { - // Can't do this when starting printing or nested printing won't work, see 3491427. - [self setNeedsDisplay:NO]; - } + [_private->pageRects release]; + _private->pageRects = nil; + _private->printing = printing; + _private->paginateScreenContent = paginateScreenContent; + if (!printing && !paginateScreenContent) + _private->avoidingPrintOrphan = NO; + [self setNeedsToApplyStyles:YES]; + [self setNeedsLayout:YES]; + [self layoutToMinimumPageWidth:minPageWidth height:minPageHeight maximumPageWidth:maxPageWidth adjustingViewSize:adjustViewSize]; + if (!printing) { + // Can't do this when starting printing or nested printing won't work, see 3491427. + [self setNeedsDisplay:NO]; } } @@ -3747,23 +3905,10 @@ static BOOL isInPasswordField(Frame* coreFrame) // If the WebHTMLView itself is what we're printing, then we will never have to do this. BOOL wasInPrintingMode = _private->printing; if (!wasInPrintingMode) - [self _setPrinting:YES minimumPageWidth:0.0f maximumPageWidth:0.0f adjustViewSize:NO]; + [self _setPrinting:YES minimumPageWidth:0 height:0 maximumPageWidth:0 adjustViewSize:NO paginateScreenContent:[self _isInScreenPaginationMode]]; - float newBottomFloat = *newBottom; - if (Frame* frame = core([self _frame])) { - if (FrameView* view = frame->view()) - view->adjustPageHeight(&newBottomFloat, oldTop, oldBottom, bottomLimit); - } + *newBottom = [self _adjustedBottomOfPageWithTop:oldTop bottom:oldBottom limit:bottomLimit]; -#ifdef __LP64__ - // If the new bottom is equal to the old bottom (when both are treated as floats), we just copy - // oldBottom over to newBottom. This prevents rounding errors that can occur when converting newBottomFloat to a double. - if (fabs((float)oldBottom - newBottomFloat) <= numeric_limits<float>::epsilon()) - *newBottom = oldBottom; - else -#endif - *newBottom = newBottomFloat; - if (!wasInPrintingMode) { NSPrintOperation *currenPrintOperation = [NSPrintOperation currentOperation]; if (currenPrintOperation) @@ -3771,16 +3916,10 @@ static BOOL isInPasswordField(Frame* coreFrame) [self performSelector:@selector(_delayedEndPrintMode:) withObject:currenPrintOperation afterDelay:0]; else // not sure if this is actually ever invoked, it probably shouldn't be - [self _setPrinting:NO minimumPageWidth:0.0f maximumPageWidth:0.0f adjustViewSize:NO]; + [self _setPrinting:NO minimumPageWidth:0 height:0 maximumPageWidth:0 adjustViewSize:NO paginateScreenContent:[self _isInScreenPaginationMode]]; } } -- (float)_availablePaperWidthForPrintOperation:(NSPrintOperation *)printOperation -{ - NSPrintInfo *printInfo = [printOperation printInfo]; - return [printInfo paperSize].width - [printInfo leftMargin] - [printInfo rightMargin]; -} - - (float)_scaleFactorForPrintOperation:(NSPrintOperation *)printOperation { float viewWidth = NSWidth([self bounds]); @@ -3790,8 +3929,8 @@ static BOOL isInPasswordField(Frame* coreFrame) } float userScaleFactor = [printOperation _web_pageSetupScaleFactor]; - float maxShrinkToFitScaleFactor = 1.0f / PrintingMaximumShrinkFactor; - float shrinkToFitScaleFactor = [self _availablePaperWidthForPrintOperation:printOperation]/viewWidth; + float maxShrinkToFitScaleFactor = 1.0f / _WebHTMLViewPrintingMaximumShrinkFactor; + float shrinkToFitScaleFactor = [printOperation _web_availablePaperWidth] / viewWidth; float shrinkToAvoidOrphan = _private->avoidingPrintOrphan ? (1.0f / PrintingOrphanShrinkAdjustment) : 1.0f; return userScaleFactor * max(maxShrinkToFitScaleFactor, shrinkToFitScaleFactor) * shrinkToAvoidOrphan; } @@ -3807,13 +3946,13 @@ static BOOL isInPasswordField(Frame* coreFrame) // This is used for Carbon printing. At some point we might want to make this public API. - (void)setPageWidthForPrinting:(float)pageWidth { - [self _setPrinting:NO minimumPageWidth:0.0f maximumPageWidth:0.0f adjustViewSize:NO]; - [self _setPrinting:YES minimumPageWidth:pageWidth maximumPageWidth:pageWidth adjustViewSize:YES]; + [self _setPrinting:NO minimumPageWidth:0 height:0 maximumPageWidth:0 adjustViewSize:NO paginateScreenContent:[self _isInScreenPaginationMode]]; + [self _setPrinting:YES minimumPageWidth:pageWidth height:0 maximumPageWidth:pageWidth adjustViewSize:YES paginateScreenContent:[self _isInScreenPaginationMode]]; } -- (void)_endPrintMode +- (void)_endPrintModeAndRestoreWindowAutodisplay { - [self _setPrinting:NO minimumPageWidth:0.0f maximumPageWidth:0.0f adjustViewSize:YES]; + [self _endPrintMode]; [[self window] setAutodisplay:YES]; } @@ -3839,7 +3978,7 @@ static BOOL isInPasswordField(Frame* coreFrame) // cancelled, beginDocument and endDocument must not have been called, and we need to clean up // the print mode here. ASSERT(currentOperation == nil); - [self _endPrintMode]; + [self _endPrintModeAndRestoreWindowAutodisplay]; } } @@ -3849,22 +3988,13 @@ static BOOL isInPasswordField(Frame* coreFrame) // Must do this explicit display here, because otherwise the view might redisplay while the print // sheet was up, using printer fonts (and looking different). [self displayIfNeeded]; - [[self window] setAutodisplay:NO]; - - // If we are a frameset just print with the layout we have onscreen, otherwise relayout - // according to the paper size - float minLayoutWidth = 0.0f; - float maxLayoutWidth = 0.0f; - Frame* frame = core([self _frame]); - if (!frame) - return NO; - if (!frame->document() || !frame->document()->isFrameSet()) { - float paperWidth = [self _availablePaperWidthForPrintOperation:[NSPrintOperation currentOperation]]; - minLayoutWidth = paperWidth * PrintingMinimumShrinkFactor; - maxLayoutWidth = paperWidth * PrintingMaximumShrinkFactor; - } - [self _setPrinting:YES minimumPageWidth:minLayoutWidth maximumPageWidth:maxLayoutWidth adjustViewSize:YES]; // will relayout + [[self window] setAutodisplay:NO]; + + [[self _webView] _adjustPrintingMarginsForHeaderAndFooter]; NSPrintOperation *printOperation = [NSPrintOperation currentOperation]; + if (![self _beginPrintModeWithPageWidth:[printOperation _web_availablePaperWidth] height:[printOperation _web_availablePaperHeight] shrinkToFit:YES]) + return NO; + // Certain types of errors, including invalid page ranges, can cause beginDocument and // endDocument to be skipped after we've put ourselves in print mode (see 4145905). In those cases // we need to get out of print mode without relying on any more callbacks from the printing mechanism. @@ -3872,7 +4002,6 @@ static BOOL isInPasswordField(Frame* coreFrame) // If not cancelled, this delayed call will be invoked in the next pass through the main event loop, // which is after beginDocument and endDocument would be called. [self performSelector:@selector(_delayedEndPrintMode:) withObject:printOperation afterDelay:0]; - [[self _webView] _adjustPrintingMarginsForHeaderAndFooter]; // There is a theoretical chance that someone could do some drawing between here and endDocument, // if something caused setNeedsDisplay after this point. If so, it's not a big tragedy, because @@ -3882,9 +4011,9 @@ static BOOL isInPasswordField(Frame* coreFrame) float totalScaleFactor = [self _scaleFactorForPrintOperation:printOperation]; float userScaleFactor = [printOperation _web_pageSetupScaleFactor]; [_private->pageRects release]; - float fullPageHeight = floorf([self _calculatePrintHeight]/totalScaleFactor); - NSArray *newPageRects = [[self _frame] _computePageRectsWithPrintWidthScaleFactor:userScaleFactor - printHeight:fullPageHeight]; + float fullPageHeight = floorf([printOperation _web_availablePaperHeight] / totalScaleFactor); + WebFrame *frame = [self _frame]; + NSArray *newPageRects = [frame _computePageRectsWithPrintWidthScaleFactor:userScaleFactor printHeight:fullPageHeight]; // AppKit gets all messed up if you give it a zero-length page count (see 3576334), so if we // hit that case we'll pass along a degenerate 1 pixel square to print. This will print @@ -3897,8 +4026,7 @@ static BOOL isInPasswordField(Frame* coreFrame) // content onto one fewer page. If it does, use the adjusted scale. If not, use the original scale. float lastPageHeight = NSHeight([[newPageRects lastObject] rectValue]); if (lastPageHeight/fullPageHeight < LastPrintedPageOrphanRatio) { - NSArray *adjustedPageRects = [[self _frame] _computePageRectsWithPrintWidthScaleFactor:userScaleFactor - printHeight:fullPageHeight*PrintingOrphanShrinkAdjustment]; + NSArray *adjustedPageRects = [frame _computePageRectsWithPrintWidthScaleFactor:userScaleFactor printHeight:fullPageHeight * PrintingOrphanShrinkAdjustment]; // Use the adjusted rects only if the page count went down if ([adjustedPageRects count] < [newPageRects count]) { newPageRects = adjustedPageRects; @@ -3938,7 +4066,7 @@ static BOOL isInPasswordField(Frame* coreFrame) } @catch (NSException *localException) { // Exception during [super beginDocument] means that endDocument will not get called, // so we need to clean up our "print mode" here. - [self _endPrintMode]; + [self _endPrintModeAndRestoreWindowAutodisplay]; } } @@ -3946,7 +4074,7 @@ static BOOL isInPasswordField(Frame* coreFrame) { [super endDocument]; // Note sadly at this point [NSGraphicsContext currentContextDrawingToScreen] is still NO - [self _endPrintMode]; + [self _endPrintModeAndRestoreWindowAutodisplay]; } - (void)keyDown:(NSEvent *)event @@ -4242,9 +4370,6 @@ static BOOL isInPasswordField(Frame* coreFrame) // the current event prevents that from causing a problem inside WebKit or AppKit code. [[event retain] autorelease]; - if ([self _handleStyleKeyEquivalent:event]) - return YES; - BOOL eventWasSentToWebCore = (_private->keyDownEvent == event); BOOL ret = NO; @@ -4262,7 +4387,7 @@ static BOOL isInPasswordField(Frame* coreFrame) ret = frame->eventHandler()->keyEvent(event); if (!ret) - ret = [super performKeyEquivalent:event]; + ret = [self _handleStyleKeyEquivalent:event] || [super performKeyEquivalent:event]; [self release]; @@ -4984,22 +5109,21 @@ static BOOL writingDirectionKeyBindingsEnabled() { // FIXME: NSTextView bails out if becoming or resigning first responder, for which it has ivar flags. Not // sure if we need to do something similar. - + if (![self _canEdit]) return; - + NSWindow *window = [self window]; // FIXME: is this first-responder check correct? What happens if a subframe is editable and is first responder? - if ([NSApp keyWindow] != window || [window firstResponder] != self) + if (![window isKeyWindow] || [window firstResponder] != self) return; - + bool multipleFonts = false; NSFont *font = nil; if (Frame* coreFrame = core([self _frame])) { if (const SimpleFontData* fd = coreFrame->editor()->fontForSelection(multipleFonts)) font = fd->getNSFont(); } - // FIXME: for now, return a bogus font that distinguishes the empty selection from the non-empty // selection. We should be able to remove this once the rest of this code works properly. @@ -5052,16 +5176,7 @@ static BOOL writingDirectionKeyBindingsEnabled() if (coreFrame->selection()->isContentRichlyEditable()) [self _pasteWithPasteboard:[NSPasteboard generalPasteboard] allowPlainText:YES]; else - coreFrame->editor()->pasteAsPlainText(); -} - -- (void)pasteAsPlainText:(id)sender -{ - COMMAND_PROLOGUE - - if (![self _canEdit]) - return; - [self _pasteAsPlainTextWithPasteboard:[NSPasteboard generalPasteboard]]; + coreFrame->editor()->pasteAsPlainTextBypassingDHTML(); } - (void)closeIfNotCurrentView @@ -5463,6 +5578,13 @@ static CGPoint coreGraphicsScreenPointForAppKitScreenPoint(NSPoint point) [viewLayer setStyle:[NSDictionary dictionaryWithObject:actions forKey:@"actions"]]; #endif +#if !defined(BUILDING_ON_LEOPARD) + // If we aren't in the window yet, we'll use the screen's scale factor now, and reset the scale + // via -viewDidMoveToWindow. + CGFloat scaleFactor = [self window] ? [[self window] userSpaceScaleFactor] : [[NSScreen mainScreen] userSpaceScaleFactor]; + [viewLayer setTransform:CATransform3DMakeScale(scaleFactor, scaleFactor, 1)]; +#endif + [_private->layerHostingView setLayer:viewLayer]; [_private->layerHostingView setWantsLayer:YES]; @@ -6108,7 +6230,7 @@ static void extractUnderlines(NSAttributedString *string, Vector<CompositionUnde Document* document = coreFrame->document(); if (!document) return; - document->removeMarkers(DocumentMarker::TextMatch); + document->markers()->removeMarkers(DocumentMarker::TextMatch); } - (NSArray *)rectsForTextMatches @@ -6120,7 +6242,7 @@ static void extractUnderlines(NSAttributedString *string, Vector<CompositionUnde if (!document) return [NSArray array]; - Vector<IntRect> rects = document->renderedRectsForMarkers(DocumentMarker::TextMatch); + Vector<IntRect> rects = document->markers()->renderedRectsForMarkers(DocumentMarker::TextMatch); unsigned count = rects.size(); NSMutableArray *result = [NSMutableArray arrayWithCapacity:count]; for (unsigned index = 0; index < count; ++index) |
