Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(239)

Side by Side Diff: third_party/WebKit/Source/core/page/PrintContext.cpp

Issue 2838343003: Blink Rename follow-up: Rename PrintContext::begin/end to Begin/EndPrintMode. (Closed)
Patch Set: Fix compilation of PrintContextTest.cpp Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2007 Alp Toker <alp@atoker.com> 2 * Copyright (C) 2007 Alp Toker <alp@atoker.com>
3 * Copyright (C) 2007 Apple Inc. 3 * Copyright (C) 2007 Apple Inc.
4 * 4 *
5 * This library is free software; you can redistribute it and/or 5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public 6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either 7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version. 8 * version 2 of the License, or (at your option) any later version.
9 * 9 *
10 * This library is distributed in the hope that it will be useful, 10 * This library is distributed in the hope that it will be useful,
(...skipping 28 matching lines...) Expand all
39 // reduced smaller to make the widest line fit, we just clip instead (this 39 // reduced smaller to make the widest line fit, we just clip instead (this
40 // behavior matches MacIE and Mozilla, at least). 40 // behavior matches MacIE and Mozilla, at least).
41 // TODO(rhogan): Decide if this quirk is still required. 41 // TODO(rhogan): Decide if this quirk is still required.
42 const float kPrintingMaximumShrinkFactor = 2; 42 const float kPrintingMaximumShrinkFactor = 2;
43 43
44 PrintContext::PrintContext(LocalFrame* frame) 44 PrintContext::PrintContext(LocalFrame* frame)
45 : frame_(frame), is_printing_(false), linked_destinations_valid_(false) {} 45 : frame_(frame), is_printing_(false), linked_destinations_valid_(false) {}
46 46
47 PrintContext::~PrintContext() { 47 PrintContext::~PrintContext() {
48 if (is_printing_) 48 if (is_printing_)
49 end(); 49 EndPrintMode();
50 } 50 }
51 51
52 void PrintContext::ComputePageRects(const FloatRect& print_rect, 52 void PrintContext::ComputePageRects(const FloatRect& print_rect,
53 float header_height, 53 float header_height,
54 float footer_height, 54 float footer_height,
55 float user_scale_factor, 55 float user_scale_factor,
56 float& out_page_height) { 56 float& out_page_height) {
57 page_rects_.clear(); 57 page_rects_.clear();
58 out_page_height = 0; 58 out_page_height = 0;
59 59
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 ? inline_direction_start 156 ? inline_direction_start
157 : inline_direction_start - page_logical_width; 157 : inline_direction_start - page_logical_width;
158 IntRect page_rect(page_logical_left, page_logical_top, page_logical_width, 158 IntRect page_rect(page_logical_left, page_logical_top, page_logical_width,
159 page_logical_height); 159 page_logical_height);
160 if (!is_horizontal) 160 if (!is_horizontal)
161 page_rect = page_rect.TransposedRect(); 161 page_rect = page_rect.TransposedRect();
162 page_rects_.push_back(page_rect); 162 page_rects_.push_back(page_rect);
163 } 163 }
164 } 164 }
165 165
166 void PrintContext::begin(float width, float height) { 166 void PrintContext::BeginPrintMode(float width, float height) {
167 ASSERT(width > 0); 167 ASSERT(width > 0);
168 ASSERT(height > 0); 168 ASSERT(height > 0);
169 169
170 // This function can be called multiple times to adjust printing parameters 170 // This function can be called multiple times to adjust printing parameters
171 // without going back to screen mode. 171 // without going back to screen mode.
172 is_printing_ = true; 172 is_printing_ = true;
173 173
174 FloatSize original_page_size = FloatSize(width, height); 174 FloatSize original_page_size = FloatSize(width, height);
175 FloatSize min_layout_size = frame_->ResizePageRectsKeepingRatio( 175 FloatSize min_layout_size = frame_->ResizePageRectsKeepingRatio(
176 original_page_size, FloatSize(width * kPrintingMinimumShrinkFactor, 176 original_page_size, FloatSize(width * kPrintingMinimumShrinkFactor,
177 height * kPrintingMinimumShrinkFactor)); 177 height * kPrintingMinimumShrinkFactor));
178 178
179 // This changes layout, so callers need to make sure that they don't paint to 179 // This changes layout, so callers need to make sure that they don't paint to
180 // screen while in printing mode. 180 // screen while in printing mode.
181 frame_->SetPrinting( 181 frame_->SetPrinting(
182 true, min_layout_size, original_page_size, 182 true, min_layout_size, original_page_size,
183 kPrintingMaximumShrinkFactor / kPrintingMinimumShrinkFactor); 183 kPrintingMaximumShrinkFactor / kPrintingMinimumShrinkFactor);
184 } 184 }
185 185
186 void PrintContext::end() { 186 void PrintContext::EndPrintMode() {
187 ASSERT(is_printing_); 187 ASSERT(is_printing_);
188 is_printing_ = false; 188 is_printing_ = false;
189 frame_->SetPrinting(false, FloatSize(), FloatSize(), 0); 189 frame_->SetPrinting(false, FloatSize(), FloatSize(), 0);
190 linked_destinations_.clear(); 190 linked_destinations_.clear();
191 linked_destinations_valid_ = false; 191 linked_destinations_valid_ = false;
192 } 192 }
193 193
194 static LayoutBoxModelObject* EnclosingBoxModelObject(LayoutObject* object) { 194 static LayoutBoxModelObject* EnclosingBoxModelObject(LayoutObject* object) {
195 while (object && !object->IsBoxModelObject()) 195 while (object && !object->IsBoxModelObject())
196 object = object->Parent(); 196 object = object->Parent();
197 if (!object) 197 if (!object)
198 return nullptr; 198 return nullptr;
199 return ToLayoutBoxModelObject(object); 199 return ToLayoutBoxModelObject(object);
200 } 200 }
201 201
202 int PrintContext::PageNumberForElement(Element* element, 202 int PrintContext::PageNumberForElement(Element* element,
203 const FloatSize& page_size_in_pixels) { 203 const FloatSize& page_size_in_pixels) {
204 element->GetDocument().UpdateStyleAndLayout(); 204 element->GetDocument().UpdateStyleAndLayout();
205 205
206 LocalFrame* frame = element->GetDocument().GetFrame(); 206 LocalFrame* frame = element->GetDocument().GetFrame();
207 FloatRect page_rect(FloatPoint(0, 0), page_size_in_pixels); 207 FloatRect page_rect(FloatPoint(0, 0), page_size_in_pixels);
208 PrintContext print_context(frame); 208 PrintContext print_context(frame);
209 print_context.begin(page_rect.Width(), page_rect.Height()); 209 print_context.BeginPrintMode(page_rect.Width(), page_rect.Height());
210 210
211 LayoutBoxModelObject* box = 211 LayoutBoxModelObject* box =
212 EnclosingBoxModelObject(element->GetLayoutObject()); 212 EnclosingBoxModelObject(element->GetLayoutObject());
213 if (!box) 213 if (!box)
214 return -1; 214 return -1;
215 215
216 FloatSize scaled_page_size = page_size_in_pixels; 216 FloatSize scaled_page_size = page_size_in_pixels;
217 scaled_page_size.Scale(frame->View()->ContentsSize().Width() / 217 scaled_page_size.Scale(frame->View()->ContentsSize().Width() /
218 page_rect.Width()); 218 page_rect.Width());
219 print_context.ComputePageRectsWithPageSize(scaled_page_size); 219 print_context.ComputePageRectsWithPageSize(scaled_page_size);
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 } 278 }
279 279
280 String PrintContext::PageProperty(LocalFrame* frame, 280 String PrintContext::PageProperty(LocalFrame* frame,
281 const char* property_name, 281 const char* property_name,
282 int page_number) { 282 int page_number) {
283 Document* document = frame->GetDocument(); 283 Document* document = frame->GetDocument();
284 PrintContext print_context(frame); 284 PrintContext print_context(frame);
285 // Any non-zero size is OK here. We don't care about actual layout. We just 285 // Any non-zero size is OK here. We don't care about actual layout. We just
286 // want to collect @page rules and figure out what declarations apply on a 286 // want to collect @page rules and figure out what declarations apply on a
287 // given page (that may or may not exist). 287 // given page (that may or may not exist).
288 print_context.begin(800, 1000); 288 print_context.BeginPrintMode(800, 1000);
289 RefPtr<ComputedStyle> style = document->StyleForPage(page_number); 289 RefPtr<ComputedStyle> style = document->StyleForPage(page_number);
290 290
291 // Implement formatters for properties we care about. 291 // Implement formatters for properties we care about.
292 if (!strcmp(property_name, "margin-left")) { 292 if (!strcmp(property_name, "margin-left")) {
293 if (style->MarginLeft().IsAuto()) 293 if (style->MarginLeft().IsAuto())
294 return String("auto"); 294 return String("auto");
295 return String::Number(style->MarginLeft().Value()); 295 return String::Number(style->MarginLeft().Value());
296 } 296 }
297 if (!strcmp(property_name, "line-height")) 297 if (!strcmp(property_name, "line-height"))
298 return String::Number(style->LineHeight().Value()); 298 return String::Number(style->LineHeight().Value());
(...skipping 30 matching lines...) Expand all
329 String::Number(margin_top) + ' ' + String::Number(margin_right) + ' ' + 329 String::Number(margin_top) + ' ' + String::Number(margin_right) + ' ' +
330 String::Number(margin_bottom) + ' ' + String::Number(margin_left); 330 String::Number(margin_bottom) + ' ' + String::Number(margin_left);
331 } 331 }
332 332
333 int PrintContext::NumberOfPages(LocalFrame* frame, 333 int PrintContext::NumberOfPages(LocalFrame* frame,
334 const FloatSize& page_size_in_pixels) { 334 const FloatSize& page_size_in_pixels) {
335 frame->GetDocument()->UpdateStyleAndLayout(); 335 frame->GetDocument()->UpdateStyleAndLayout();
336 336
337 FloatRect page_rect(FloatPoint(0, 0), page_size_in_pixels); 337 FloatRect page_rect(FloatPoint(0, 0), page_size_in_pixels);
338 PrintContext print_context(frame); 338 PrintContext print_context(frame);
339 print_context.begin(page_rect.Width(), page_rect.Height()); 339 print_context.BeginPrintMode(page_rect.Width(), page_rect.Height());
340 // Account for shrink-to-fit. 340 // Account for shrink-to-fit.
341 FloatSize scaled_page_size = page_size_in_pixels; 341 FloatSize scaled_page_size = page_size_in_pixels;
342 scaled_page_size.Scale(frame->View()->ContentsSize().Width() / 342 scaled_page_size.Scale(frame->View()->ContentsSize().Width() /
343 page_rect.Width()); 343 page_rect.Width());
344 print_context.ComputePageRectsWithPageSize(scaled_page_size); 344 print_context.ComputePageRectsWithPageSize(scaled_page_size);
345 return print_context.PageCount(); 345 return print_context.PageCount();
346 } 346 }
347 347
348 DEFINE_TRACE(PrintContext) { 348 DEFINE_TRACE(PrintContext) {
349 visitor->Trace(frame_); 349 visitor->Trace(frame_);
350 visitor->Trace(linked_destinations_); 350 visitor->Trace(linked_destinations_);
351 } 351 }
352 352
353 } // namespace blink 353 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698