2011-01-24 Anders Carlsson <andersca@apple.com>
[WebKit.git] / Source / WebKit / mac / WebView / WebHTMLView.mm
index bf91af9f286a6f103fc07881e75d341acb247bf0..bfa0944f99077aa25bea762ce6461363e29a2132 100644 (file)
@@ -68,7 +68,6 @@
 #import "WebPreferences.h"
 #import "WebPreferencesPrivate.h"
 #import "WebResourcePrivate.h"
-#import "WebStringTruncator.h"
 #import "WebTextCompletionController.h"
 #import "WebTypesInternal.h"
 #import "WebUIDelegatePrivate.h"
@@ -348,30 +347,8 @@ const float _WebHTMLViewPrintingMinimumShrinkFactor = 1.25;
 // behavior matches MacIE and Mozilla, at least)
 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
-// thus eliminate the orphan.
-#define LastPrintedPageOrphanRatio      0.1f
-
-// This number determines the amount the scale factor is adjusted to try to eliminate orphans.
-// It has no direct mathematical relationship to LastPrintedPageOrphanRatio, due to variable
-// numbers of pages, logic to avoid breaking elements, and CSS-supplied hard page breaks.
-#define PrintingOrphanShrinkAdjustment  1.1f
-
 #define AUTOSCROLL_INTERVAL             0.1f
 
-#define DRAG_LABEL_BORDER_X             4.0f
-//Keep border_y in synch with DragController::LinkDragBorderInset
-#define DRAG_LABEL_BORDER_Y             2.0f
-#define DRAG_LABEL_RADIUS               5.0f
-#define DRAG_LABEL_BORDER_Y_OFFSET              2.0f
-
-#define MIN_DRAG_LABEL_WIDTH_BEFORE_CLIP        120.0f
-#define MAX_DRAG_LABEL_WIDTH                    320.0f
-
-#define DRAG_LINK_LABEL_FONT_SIZE   11.0f
-#define DRAG_LINK_URL_FONT_SIZE   10.0f
-
 // Any non-zero value will do, but using something recognizable might help us debug some day.
 #define TRACKING_RECT_TAG 0xBADFACE
 
@@ -495,7 +472,6 @@ struct WebHTMLViewInterpretKeyEventsParameters {
     BOOL closed;
     BOOL ignoringMouseDraggedEvents;
     BOOL printing;
-    BOOL avoidingPrintOrphan;
     BOOL paginateScreenContent;
     BOOL observingMouseMovedNotifications;
     BOOL observingSuperviewNotifications;
@@ -1739,87 +1715,6 @@ static void _updateMouseoverTimerCallback(CFRunLoopTimerRef timer, void *info)
     return [NSArray arrayWithObjects:WebArchivePboardType, NSRTFDPboardType, NSRTFPboardType, NSStringPboardType, nil];
 }
 
-- (NSImage *)_dragImageForURL:(NSString*)urlString withLabel:(NSString*)label
-{
-    BOOL drawURLString = YES;
-    BOOL clipURLString = NO, clipLabelString = NO;
-    
-    if (!label) {
-        drawURLString = NO;
-        label = urlString;
-    }
-    
-    NSFont *labelFont = [[NSFontManager sharedFontManager] convertFont:[NSFont systemFontOfSize:DRAG_LINK_LABEL_FONT_SIZE]
-                                                           toHaveTrait:NSBoldFontMask];
-    NSFont *urlFont = [NSFont systemFontOfSize: DRAG_LINK_URL_FONT_SIZE];
-    NSSize labelSize;
-    labelSize.width = [label _web_widthWithFont: labelFont];
-    labelSize.height = [labelFont ascender] - [labelFont descender];
-    if (labelSize.width > MAX_DRAG_LABEL_WIDTH){
-        labelSize.width = MAX_DRAG_LABEL_WIDTH;
-        clipLabelString = YES;
-    }
-    
-    NSSize imageSize, urlStringSize;
-    imageSize.width = labelSize.width + DRAG_LABEL_BORDER_X * 2.0f;
-    imageSize.height = labelSize.height + DRAG_LABEL_BORDER_Y * 2.0f;
-    if (drawURLString) {
-        urlStringSize.width = [urlString _web_widthWithFont: urlFont];
-        urlStringSize.height = [urlFont ascender] - [urlFont descender];
-        imageSize.height += urlStringSize.height;
-        if (urlStringSize.width > MAX_DRAG_LABEL_WIDTH) {
-            imageSize.width = max(MAX_DRAG_LABEL_WIDTH + DRAG_LABEL_BORDER_X * 2, MIN_DRAG_LABEL_WIDTH_BEFORE_CLIP);
-            clipURLString = YES;
-        } else {
-            imageSize.width = max(labelSize.width + DRAG_LABEL_BORDER_X * 2, urlStringSize.width + DRAG_LABEL_BORDER_X * 2);
-        }
-    }
-    NSImage *dragImage = [[[NSImage alloc] initWithSize: imageSize] autorelease];
-    [dragImage lockFocus];
-    
-    [[NSColor colorWithDeviceRed: 0.7f green: 0.7f blue: 0.7f alpha: 0.8f] set];
-    
-    // Drag a rectangle with rounded corners/
-    NSBezierPath *path = [NSBezierPath bezierPath];
-    [path appendBezierPathWithOvalInRect: NSMakeRect(0.0f, 0.0f, DRAG_LABEL_RADIUS * 2.0f, DRAG_LABEL_RADIUS * 2.0f)];
-    [path appendBezierPathWithOvalInRect: NSMakeRect(0, imageSize.height - DRAG_LABEL_RADIUS * 2.0f, DRAG_LABEL_RADIUS * 2.0f, DRAG_LABEL_RADIUS * 2.0f)];
-    [path appendBezierPathWithOvalInRect: NSMakeRect(imageSize.width - DRAG_LABEL_RADIUS * 2.0f, imageSize.height - DRAG_LABEL_RADIUS * 2.0f, DRAG_LABEL_RADIUS * 2.0f, DRAG_LABEL_RADIUS * 2.0f)];
-    [path appendBezierPathWithOvalInRect: NSMakeRect(imageSize.width - DRAG_LABEL_RADIUS * 2.0f, 0.0f, DRAG_LABEL_RADIUS * 2.0f, DRAG_LABEL_RADIUS * 2.0f)];
-    
-    [path appendBezierPathWithRect: NSMakeRect(DRAG_LABEL_RADIUS, 0.0f, imageSize.width - DRAG_LABEL_RADIUS * 2.0f, imageSize.height)];
-    [path appendBezierPathWithRect: NSMakeRect(0.0f, DRAG_LABEL_RADIUS, DRAG_LABEL_RADIUS + 10.0f, imageSize.height - 2.0f * DRAG_LABEL_RADIUS)];
-    [path appendBezierPathWithRect: NSMakeRect(imageSize.width - DRAG_LABEL_RADIUS - 20.0f, DRAG_LABEL_RADIUS, DRAG_LABEL_RADIUS + 20.0f, imageSize.height - 2.0f * DRAG_LABEL_RADIUS)];
-    [path fill];
-    
-    NSColor *topColor = [NSColor colorWithDeviceWhite:0.0f alpha:0.75f];
-    NSColor *bottomColor = [NSColor colorWithDeviceWhite:1.0f alpha:0.5f];
-    if (drawURLString) {
-        if (clipURLString)
-            urlString = [WebStringTruncator centerTruncateString: urlString toWidth:imageSize.width - (DRAG_LABEL_BORDER_X * 2.0f) withFont:urlFont];
-        
-        [urlString _web_drawDoubledAtPoint:NSMakePoint(DRAG_LABEL_BORDER_X, DRAG_LABEL_BORDER_Y - [urlFont descender]) 
-                              withTopColor:topColor bottomColor:bottomColor font:urlFont];
-    }
-    
-    if (clipLabelString)
-        label = [WebStringTruncator rightTruncateString: label toWidth:imageSize.width - (DRAG_LABEL_BORDER_X * 2.0f) withFont:labelFont];
-    [label _web_drawDoubledAtPoint:NSMakePoint (DRAG_LABEL_BORDER_X, imageSize.height - DRAG_LABEL_BORDER_Y_OFFSET - [labelFont pointSize])
-                      withTopColor:topColor bottomColor:bottomColor font:labelFont];
-    
-    [dragImage unlockFocus];
-    
-    return dragImage;
-}
-
-- (NSImage *)_dragImageForLinkElement:(NSDictionary *)element
-{
-    NSURL *linkURL = [element objectForKey: WebElementLinkURLKey];
-    
-    NSString *label = [element objectForKey: WebElementLinkLabelKey];
-    NSString *urlString = [linkURL _web_userVisibleString];
-    return [self _dragImageForURL:urlString withLabel:label];
-}
-
 - (void)pasteboardChangedOwner:(NSPasteboard *)pasteboard
 {
     [self setPromisedDragTIFFDataSource:0];
@@ -1838,6 +1733,14 @@ static void _updateMouseoverTimerCallback(CFRunLoopTimerRef timer, void *info)
     }
 }
 
+- (BOOL)mouseDownCanMoveWindow
+{
+    BOOL result = [super mouseDownCanMoveWindow];
+
+    NSLog(@"%@, %@ %d", self, NSStringFromSelector(_cmd), result);
+    return result;
+}
+
 - (void)_handleAutoscrollForMouseDragged:(NSEvent *)event 
 { 
     [self autoscroll:event]; 
@@ -4003,8 +3906,6 @@ static BOOL isInPasswordField(Frame* coreFrame)
     _private->pageRects = nil;
     _private->printing = printing;
     _private->paginateScreenContent = paginateScreenContent;
-    if (!printing && !paginateScreenContent)
-        _private->avoidingPrintOrphan = NO;
     
     Frame* coreFrame = core([self _frame]);
     if (coreFrame) {
@@ -4064,8 +3965,7 @@ static BOOL isInPasswordField(Frame* coreFrame)
     float userScaleFactor = [printOperation _web_pageSetupScaleFactor];
     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;
+    return userScaleFactor * max(maxShrinkToFitScaleFactor, shrinkToFitScaleFactor);
 }
 
 // FIXME 3491344: This is a secret AppKit-internal method that we need to override in order
@@ -4154,19 +4054,6 @@ static BOOL isInPasswordField(Frame* coreFrame)
     // the behavior of IE and Camino at least.
     if ([newPageRects count] == 0)
         newPageRects = [NSArray arrayWithObject:[NSValue valueWithRect:NSMakeRect(0, 0, 1, 1)]];
-    else if ([newPageRects count] > 1) {
-        // If the last page is a short orphan, try adjusting the print height slightly to see if this will squeeze the
-        // 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 = [frame _computePageRectsWithPrintWidthScaleFactor:userScaleFactor printHeight:fullPageHeight * PrintingOrphanShrinkAdjustment];
-            // Use the adjusted rects only if the page count went down
-            if ([adjustedPageRects count] < [newPageRects count]) {
-                newPageRects = adjustedPageRects;
-                _private->avoidingPrintOrphan = YES;
-            }
-        }
-    }
     
     _private->pageRects = [newPageRects retain];