OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/webui/print_preview/print_preview_ui.h" | 5 #include "chrome/browser/ui/webui/print_preview/print_preview_ui.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 | 8 |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
12 #include "base/synchronization/lock.h" | 12 #include "base/synchronization/lock.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
14 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
15 #include "chrome/browser/printing/background_printing_manager.h" | 15 #include "chrome/browser/printing/background_printing_manager.h" |
16 #include "chrome/browser/printing/print_preview_data_service.h" | 16 #include "chrome/browser/printing/print_preview_data_service.h" |
17 #include "chrome/browser/printing/print_preview_tab_controller.h" | 17 #include "chrome/browser/printing/print_preview_tab_controller.h" |
18 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
19 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 19 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
20 #include "chrome/browser/ui/webui/html_dialog_ui.h" | 20 #include "chrome/browser/ui/webui/html_dialog_ui.h" |
21 #include "chrome/browser/ui/webui/print_preview/print_preview_data_source.h" | 21 #include "chrome/browser/ui/webui/print_preview/print_preview_data_source.h" |
22 #include "chrome/browser/ui/webui/print_preview/print_preview_handler.h" | 22 #include "chrome/browser/ui/webui/print_preview/print_preview_handler.h" |
23 #include "chrome/common/print_messages.h" | 23 #include "chrome/common/print_messages.h" |
24 #include "content/public/browser/web_contents.h" | 24 #include "content/public/browser/web_contents.h" |
25 #include "printing/page_size_margins.h" | 25 #include "printing/page_size_margins.h" |
26 #include "printing/print_job_constants.h" | 26 #include "printing/print_job_constants.h" |
27 #include "ui/gfx/rect.h" | |
27 | 28 |
28 using content::WebContents; | 29 using content::WebContents; |
29 using printing::PageSizeMargins; | 30 using printing::PageSizeMargins; |
30 | 31 |
31 namespace { | 32 namespace { |
32 | 33 |
33 // Thread-safe wrapper around a std::map to keep track of mappings from | 34 // Thread-safe wrapper around a std::map to keep track of mappings from |
34 // PrintPreviewUI addresses to most recent print preview request ids. | 35 // PrintPreviewUI addresses to most recent print preview request ids. |
35 class PrintPreviewRequestIdMapWithLock { | 36 class PrintPreviewRequestIdMapWithLock { |
36 public: | 37 public: |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
199 const PrintHostMsg_DidGetPreviewPageCount_Params& params) { | 200 const PrintHostMsg_DidGetPreviewPageCount_Params& params) { |
200 DCHECK_GT(params.page_count, 0); | 201 DCHECK_GT(params.page_count, 0); |
201 base::FundamentalValue count(params.page_count); | 202 base::FundamentalValue count(params.page_count); |
202 base::FundamentalValue request_id(params.preview_request_id); | 203 base::FundamentalValue request_id(params.preview_request_id); |
203 web_ui()->CallJavascriptFunction("onDidGetPreviewPageCount", | 204 web_ui()->CallJavascriptFunction("onDidGetPreviewPageCount", |
204 count, | 205 count, |
205 request_id); | 206 request_id); |
206 } | 207 } |
207 | 208 |
208 void PrintPreviewUI::OnDidGetDefaultPageLayout( | 209 void PrintPreviewUI::OnDidGetDefaultPageLayout( |
209 const PageSizeMargins& page_layout, bool has_custom_page_size_style) { | 210 const PageSizeMargins& page_layout, const gfx::Rect& printable_area, |
211 bool has_custom_page_size_style) { | |
210 if (page_layout.margin_top < 0 || page_layout.margin_left < 0 || | 212 if (page_layout.margin_top < 0 || page_layout.margin_left < 0 || |
211 page_layout.margin_bottom < 0 || page_layout.margin_right < 0 || | 213 page_layout.margin_bottom < 0 || page_layout.margin_right < 0 || |
212 page_layout.content_width < 0 || page_layout.content_height < 0) { | 214 page_layout.content_width < 0 || page_layout.content_height < 0 || |
215 printable_area.width() <= 0 || printable_area.height() <= 0) { | |
213 NOTREACHED(); | 216 NOTREACHED(); |
214 return; | 217 return; |
215 } | 218 } |
216 | 219 |
217 base::DictionaryValue layout; | 220 base::DictionaryValue layout; |
218 layout.SetDouble(printing::kSettingMarginTop, page_layout.margin_top); | 221 layout.SetDouble(printing::kSettingMarginTop, page_layout.margin_top); |
219 layout.SetDouble(printing::kSettingMarginLeft, page_layout.margin_left); | 222 layout.SetDouble(printing::kSettingMarginLeft, page_layout.margin_left); |
220 layout.SetDouble(printing::kSettingMarginBottom, page_layout.margin_bottom); | 223 layout.SetDouble(printing::kSettingMarginBottom, page_layout.margin_bottom); |
221 layout.SetDouble(printing::kSettingMarginRight, page_layout.margin_right); | 224 layout.SetDouble(printing::kSettingMarginRight, page_layout.margin_right); |
222 layout.SetDouble(printing::kSettingContentWidth, page_layout.content_width); | 225 layout.SetDouble(printing::kSettingContentWidth, page_layout.content_width); |
223 layout.SetDouble(printing::kSettingContentHeight, page_layout.content_height); | 226 layout.SetDouble(printing::kSettingContentHeight, page_layout.content_height); |
224 | 227 |
228 base::DictionaryValue printable_area_info; | |
vandebo (ex-Chrome)
2012/03/19 17:11:30
Seems like you could put this in the layout dictio
kmadhusu
2012/03/19 18:45:31
Added printable area details in page layout dictio
| |
229 printable_area_info.SetInteger(printing::kSettingPrintableAreaX, | |
230 printable_area.x()); | |
231 printable_area_info.SetInteger(printing::kSettingPrintableAreaY, | |
232 printable_area.y()); | |
233 printable_area_info.SetInteger(printing::kSettingPrintableAreaWidth, | |
234 printable_area.width()); | |
235 printable_area_info.SetInteger(printing::kSettingPrintableAreaHeight, | |
236 printable_area.height()); | |
237 | |
225 base::FundamentalValue has_page_size_style(has_custom_page_size_style); | 238 base::FundamentalValue has_page_size_style(has_custom_page_size_style); |
226 web_ui()->CallJavascriptFunction("onDidGetDefaultPageLayout", layout, | 239 web_ui()->CallJavascriptFunction("onDidGetDefaultPageLayout", layout, |
240 printable_area_info, | |
227 has_page_size_style); | 241 has_page_size_style); |
228 } | 242 } |
229 | 243 |
230 void PrintPreviewUI::OnDidPreviewPage(int page_number, | 244 void PrintPreviewUI::OnDidPreviewPage(int page_number, |
231 int preview_request_id) { | 245 int preview_request_id) { |
232 DCHECK_GE(page_number, 0); | 246 DCHECK_GE(page_number, 0); |
233 base::FundamentalValue number(page_number); | 247 base::FundamentalValue number(page_number); |
234 StringValue ui_identifier(preview_ui_addr_str_); | 248 StringValue ui_identifier(preview_ui_addr_str_); |
235 base::FundamentalValue request_id(preview_request_id); | 249 base::FundamentalValue request_id(preview_request_id); |
236 web_ui()->CallJavascriptFunction( | 250 web_ui()->CallJavascriptFunction( |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
311 ConstrainedHtmlUIDelegate* delegate = GetConstrainedDelegate(); | 325 ConstrainedHtmlUIDelegate* delegate = GetConstrainedDelegate(); |
312 if (!delegate) | 326 if (!delegate) |
313 return; | 327 return; |
314 delegate->GetHtmlDialogUIDelegate()->OnDialogClosed(""); | 328 delegate->GetHtmlDialogUIDelegate()->OnDialogClosed(""); |
315 delegate->OnDialogCloseFromWebUI(); | 329 delegate->OnDialogCloseFromWebUI(); |
316 } | 330 } |
317 | 331 |
318 void PrintPreviewUI::OnReloadPrintersList() { | 332 void PrintPreviewUI::OnReloadPrintersList() { |
319 web_ui()->CallJavascriptFunction("reloadPrintersList"); | 333 web_ui()->CallJavascriptFunction("reloadPrintersList"); |
320 } | 334 } |
OLD | NEW |