Changeset 57246 in webkit
- Timestamp:
- Apr 7, 2010 9:11:48 PM (14 years ago)
- Location:
- trunk/WebKit/mac
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebKit/mac/ChangeLog
r57210 r57246 1 2010-04-07 Dan Bernstein <mitz@apple.com> 2 3 Reviewed by Adele Peterson. 4 5 Refactor WebHTMLView printing code and add private methods to enter and exit printing mode. 6 https://bugs.webkit.org/show_bug.cgi?id=37246 7 8 * Misc/WebNSPrintOperationExtras.h: Declared -_web_availablePaperWidth and -_web_availablePaperHeight. 9 * Misc/WebNSPrintOperationExtras.m: 10 (-[NSPrintOperation _web_availablePaperWidth]): Turned -[WebHTMLView _availablePaperWidthForPrintOperation:] 11 into this method. 12 (-[NSPrintOperation _web_availablePaperHeight]): Turned -[WebHTMLView _calculatePrintHeight] into this 13 method. 14 * WebView/WebHTMLView.mm: 15 (-[WebHTMLView _isInPrintMode]): Added this accessor. 16 (-[WebHTMLView _beginPrintModeWithPageWidth:shrinkToFit:]): Added. Moved the code from -knowsPageRange: that 17 computes the layout widths and enters printing mode into this private method. 18 (-[WebHTMLView _endPrintMode]): New private method (the old -_endPrintMode has been renamed). 19 (-[WebHTMLView _scaleFactorForPrintOperation:]): Use -[NSPrintOperation _web_availablePaperWidth]. 20 (-[WebHTMLView _endPrintModeAndRestoreWindowAutodisplay]): Renamed -_endPrintMode to this, changed it to call 21 _endPrintMode. 22 (-[WebHTMLView _delayedEndPrintMode:]): Updated for rename. 23 (-[WebHTMLView knowsPageRange:]): Use -_beginPrintModeWithPageWidth:shrintToFit:, 24 -[NSPrintOperation _web_availablePaperWidth], and -[NSPrintOperation _web_availablePaperHeight]. Updated for 25 rename. 26 (-[WebHTMLView beginDocument]): Updated for rename. 27 (-[WebHTMLView endDocument]): Ditto. 28 * WebView/WebHTMLViewPrivate.h: Declared new private methods -_isInPrintMode, 29 -_beginPrintModeWithPageWidth:shrinkToFit: and -_endPrintMode. 30 1 31 2010-04-07 Andrey Kosyakov <caseq@chromium.org> 2 32 -
trunk/WebKit/mac/Misc/WebNSPrintOperationExtras.h
r11962 r57246 32 32 33 33 - (float)_web_pageSetupScaleFactor; 34 - (float)_web_availablePaperWidth; 35 - (float)_web_availablePaperHeight; 34 36 35 37 @end -
trunk/WebKit/mac/Misc/WebNSPrintOperationExtras.m
r11962 r57246 36 36 } 37 37 38 - (float)_web_availablePaperWidth 39 { 40 NSPrintInfo *printInfo = [self printInfo]; 41 return [printInfo paperSize].width - [printInfo leftMargin] - [printInfo rightMargin]; 42 } 43 44 - (float)_web_availablePaperHeight 45 { 46 NSPrintInfo *printInfo = [self printInfo]; 47 return [printInfo paperSize].height - [printInfo topMargin] - [printInfo bottomMargin]; 48 } 49 38 50 @end -
trunk/WebKit/mac/WebView/WebHTMLView.mm
r57184 r57246 323 323 - (BOOL)_shouldInsertText:(NSString *)text replacingDOMRange:(DOMRange *)range givenAction:(WebViewInsertAction)action; 324 324 - (BOOL)_shouldReplaceSelectionWithText:(NSString *)text givenAction:(WebViewInsertAction)action; 325 - (float)_calculatePrintHeight;326 325 - (DOMRange *)_selectedRange; 327 326 - (BOOL)_shouldDeleteRange:(DOMRange *)range; … … 900 899 { 901 900 return [self _shouldInsertText:text replacingDOMRange:[self _selectedRange] givenAction:action]; 902 }903 904 // Calculate the vertical size of the view that fits on a single page905 - (float)_calculatePrintHeight906 {907 // Obtain the print info object for the current operation908 NSPrintInfo *pi = [[NSPrintOperation currentOperation] printInfo];909 910 // Calculate the page height in points911 NSSize paperSize = [pi paperSize];912 return paperSize.height - [pi topMargin] - [pi bottomMargin];913 901 } 914 902 … … 2201 2189 return 0; 2202 2190 #endif 2191 } 2192 2193 - (BOOL)_isInPrintMode 2194 { 2195 return _private->printing; 2196 } 2197 2198 - (BOOL)_beginPrintModeWithPageWidth:(float)pageWidth shrinkToFit:(BOOL)shrinkToFit 2199 { 2200 Frame* frame = core([self _frame]); 2201 if (!frame) 2202 return NO; 2203 2204 float minLayoutWidth = 0; 2205 float maxLayoutWidth = 0; 2206 2207 // If we are a frameset just print with the layout we have onscreen, otherwise relayout 2208 // according to the page width. 2209 if (!frame->document() || !frame->document()->isFrameSet()) { 2210 minLayoutWidth = shrinkToFit ? pageWidth * PrintingMinimumShrinkFactor : pageWidth; 2211 maxLayoutWidth = shrinkToFit ? pageWidth * PrintingMaximumShrinkFactor : pageWidth; 2212 } 2213 [self _setPrinting:YES minimumPageWidth:minLayoutWidth maximumPageWidth:maxLayoutWidth adjustViewSize:YES]; 2214 2215 return YES; 2216 } 2217 2218 - (void)_endPrintMode 2219 { 2220 [self _setPrinting:NO minimumPageWidth:0 maximumPageWidth:0 adjustViewSize:YES]; 2203 2221 } 2204 2222 … … 3829 3847 } 3830 3848 3831 - (float)_availablePaperWidthForPrintOperation:(NSPrintOperation *)printOperation3832 {3833 NSPrintInfo *printInfo = [printOperation printInfo];3834 return [printInfo paperSize].width - [printInfo leftMargin] - [printInfo rightMargin];3835 }3836 3837 3849 - (float)_scaleFactorForPrintOperation:(NSPrintOperation *)printOperation 3838 3850 { … … 3845 3857 float userScaleFactor = [printOperation _web_pageSetupScaleFactor]; 3846 3858 float maxShrinkToFitScaleFactor = 1.0f / PrintingMaximumShrinkFactor; 3847 float shrinkToFitScaleFactor = [ self _availablePaperWidthForPrintOperation:printOperation]/viewWidth;3859 float shrinkToFitScaleFactor = [printOperation _web_availablePaperWidth] / viewWidth; 3848 3860 float shrinkToAvoidOrphan = _private->avoidingPrintOrphan ? (1.0f / PrintingOrphanShrinkAdjustment) : 1.0f; 3849 3861 return userScaleFactor * max(maxShrinkToFitScaleFactor, shrinkToFitScaleFactor) * shrinkToAvoidOrphan; … … 3865 3877 } 3866 3878 3867 - (void)_endPrintMode 3868 { 3869 [self _ setPrinting:NO minimumPageWidth:0.0f maximumPageWidth:0.0f adjustViewSize:YES];3879 - (void)_endPrintModeAndRestoreWindowAutodisplay 3880 { 3881 [self _endPrintMode]; 3870 3882 [[self window] setAutodisplay:YES]; 3871 3883 } … … 3893 3905 // the print mode here. 3894 3906 ASSERT(currentOperation == nil); 3895 [self _endPrintMode ];3907 [self _endPrintModeAndRestoreWindowAutodisplay]; 3896 3908 } 3897 3909 } … … 3903 3915 // sheet was up, using printer fonts (and looking different). 3904 3916 [self displayIfNeeded]; 3905 [[self window] setAutodisplay:NO]; 3906 3907 // If we are a frameset just print with the layout we have onscreen, otherwise relayout 3908 // according to the paper size 3909 float minLayoutWidth = 0.0f; 3910 float maxLayoutWidth = 0.0f; 3911 Frame* frame = core([self _frame]); 3912 if (!frame) 3917 [[self window] setAutodisplay:NO]; 3918 3919 NSPrintOperation *printOperation = [NSPrintOperation currentOperation]; 3920 if (![self _beginPrintModeWithPageWidth:[printOperation _web_availablePaperWidth] shrinkToFit:YES]) 3913 3921 return NO; 3914 if (!frame->document() || !frame->document()->isFrameSet()) { 3915 float paperWidth = [self _availablePaperWidthForPrintOperation:[NSPrintOperation currentOperation]]; 3916 minLayoutWidth = paperWidth * PrintingMinimumShrinkFactor; 3917 maxLayoutWidth = paperWidth * PrintingMaximumShrinkFactor; 3918 } 3919 [self _setPrinting:YES minimumPageWidth:minLayoutWidth maximumPageWidth:maxLayoutWidth adjustViewSize:YES]; // will relayout 3920 NSPrintOperation *printOperation = [NSPrintOperation currentOperation]; 3922 3921 3923 // Certain types of errors, including invalid page ranges, can cause beginDocument and 3922 3924 // endDocument to be skipped after we've put ourselves in print mode (see 4145905). In those cases … … 3936 3938 float userScaleFactor = [printOperation _web_pageSetupScaleFactor]; 3937 3939 [_private->pageRects release]; 3938 float fullPageHeight = floorf([ self _calculatePrintHeight]/totalScaleFactor);3939 NSArray *newPageRects = [[self _frame] _computePageRectsWithPrintWidthScaleFactor:userScaleFactor3940 3940 float fullPageHeight = floorf([printOperation _web_availablePaperHeight] / totalScaleFactor); 3941 WebFrame *frame = [self _frame]; 3942 NSArray *newPageRects = [frame _computePageRectsWithPrintWidthScaleFactor:userScaleFactor printHeight:fullPageHeight]; 3941 3943 3942 3944 // AppKit gets all messed up if you give it a zero-length page count (see 3576334), so if we … … 3951 3953 float lastPageHeight = NSHeight([[newPageRects lastObject] rectValue]); 3952 3954 if (lastPageHeight/fullPageHeight < LastPrintedPageOrphanRatio) { 3953 NSArray *adjustedPageRects = [[self _frame] _computePageRectsWithPrintWidthScaleFactor:userScaleFactor 3954 printHeight:fullPageHeight*PrintingOrphanShrinkAdjustment]; 3955 NSArray *adjustedPageRects = [frame _computePageRectsWithPrintWidthScaleFactor:userScaleFactor printHeight:fullPageHeight * PrintingOrphanShrinkAdjustment]; 3955 3956 // Use the adjusted rects only if the page count went down 3956 3957 if ([adjustedPageRects count] < [newPageRects count]) { … … 3992 3993 // Exception during [super beginDocument] means that endDocument will not get called, 3993 3994 // so we need to clean up our "print mode" here. 3994 [self _endPrintMode ];3995 [self _endPrintModeAndRestoreWindowAutodisplay]; 3995 3996 } 3996 3997 } … … 4000 4001 [super endDocument]; 4001 4002 // Note sadly at this point [NSGraphicsContext currentContextDrawingToScreen] is still NO 4002 [self _endPrintMode ];4003 [self _endPrintModeAndRestoreWindowAutodisplay]; 4003 4004 } 4004 4005 -
trunk/WebKit/mac/WebView/WebHTMLViewPrivate.h
r57190 r57246 132 132 - (void)_layoutForPrinting; 133 133 - (WebCGFloat)_adjustedBottomOfPageWithTop:(WebCGFloat)top bottom:(WebCGFloat)bottom limit:(WebCGFloat)bottomLimit; 134 - (BOOL)_isInPrintMode; 135 - (BOOL)_beginPrintModeWithPageWidth:(float)pageWidth shrinkToFit:(BOOL)shrinkToFit; 136 - (void)_endPrintMode; 134 137 135 138 - (BOOL)_canSmartReplaceWithPasteboard:(NSPasteboard *)pasteboard;
Note: See TracChangeset
for help on using the changeset viewer.