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

Side by Side Diff: chrome/browser/ui/libgtkui/printing_gtk_util.cc

Issue 2453243002: Gtk3 UI: Rename files in libgtkui containing gtk2 in their name (Closed)
Patch Set: Fix git cl format mistake Created 4 years, 1 month 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 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/libgtkui/printing_gtk2_util.h" 5 #include "chrome/browser/ui/libgtkui/printing_gtk_util.h"
6 6
7 #include <gtk/gtk.h> 7 #include <gtk/gtk.h>
8 #include <gtk/gtkunixprint.h> 8 #include <gtk/gtkunixprint.h>
9 9
10 #include "base/strings/string16.h" 10 #include "base/strings/string16.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "printing/print_settings.h" 12 #include "printing/print_settings.h"
13 #include "printing/printing_context_linux.h" 13 #include "printing/printing_context_linux.h"
14 #include "printing/units.h" 14 #include "printing/units.h"
15 #include "ui/gfx/geometry/size.h" 15 #include "ui/gfx/geometry/size.h"
(...skipping 13 matching lines...) Expand all
29 GtkPageSetup* page_setup = gtk_page_setup_new(); 29 GtkPageSetup* page_setup = gtk_page_setup_new();
30 30
31 gfx::SizeF paper_size( 31 gfx::SizeF paper_size(
32 gtk_page_setup_get_paper_width(page_setup, GTK_UNIT_INCH), 32 gtk_page_setup_get_paper_width(page_setup, GTK_UNIT_INCH),
33 gtk_page_setup_get_paper_height(page_setup, GTK_UNIT_INCH)); 33 gtk_page_setup_get_paper_height(page_setup, GTK_UNIT_INCH));
34 34
35 g_object_unref(page_setup); 35 g_object_unref(page_setup);
36 36
37 const printing::PrintSettings& settings = context->settings(); 37 const printing::PrintSettings& settings = context->settings();
38 38
39 return gfx::Size( 39 return gfx::Size(paper_size.width() * settings.device_units_per_inch(),
40 paper_size.width() * settings.device_units_per_inch(), 40 paper_size.height() * settings.device_units_per_inch());
41 paper_size.height() * settings.device_units_per_inch());
42 } 41 }
43 42
44 void InitPrintSettingsGtk(GtkPrintSettings* settings, 43 void InitPrintSettingsGtk(GtkPrintSettings* settings,
45 GtkPageSetup* page_setup, 44 GtkPageSetup* page_setup,
46 printing::PrintSettings* print_settings) { 45 printing::PrintSettings* print_settings) {
47 DCHECK(settings); 46 DCHECK(settings);
48 DCHECK(page_setup); 47 DCHECK(page_setup);
49 DCHECK(print_settings); 48 DCHECK(print_settings);
50 49
51 base::string16 name(base::UTF8ToUTF16(static_cast<const char*>( 50 base::string16 name(base::UTF8ToUTF16(
52 gtk_print_settings_get_printer(settings)))); 51 static_cast<const char*>(gtk_print_settings_get_printer(settings))));
53 print_settings->set_device_name(name); 52 print_settings->set_device_name(name);
54 53
55 gfx::Size physical_size_device_units; 54 gfx::Size physical_size_device_units;
56 gfx::Rect printable_area_device_units; 55 gfx::Rect printable_area_device_units;
57 int dpi = gtk_print_settings_get_resolution(settings); 56 int dpi = gtk_print_settings_get_resolution(settings);
58 if (dpi) { 57 if (dpi) {
59 // Initialize page_setup_device_units_. 58 // Initialize page_setup_device_units_.
60 physical_size_device_units.SetSize( 59 physical_size_device_units.SetSize(
61 gtk_page_setup_get_paper_width(page_setup, GTK_UNIT_INCH) * dpi, 60 gtk_page_setup_get_paper_width(page_setup, GTK_UNIT_INCH) * dpi,
62 gtk_page_setup_get_paper_height(page_setup, GTK_UNIT_INCH) * dpi); 61 gtk_page_setup_get_paper_height(page_setup, GTK_UNIT_INCH) * dpi);
63 printable_area_device_units.SetRect( 62 printable_area_device_units.SetRect(
64 gtk_page_setup_get_left_margin(page_setup, GTK_UNIT_INCH) * dpi, 63 gtk_page_setup_get_left_margin(page_setup, GTK_UNIT_INCH) * dpi,
65 gtk_page_setup_get_top_margin(page_setup, GTK_UNIT_INCH) * dpi, 64 gtk_page_setup_get_top_margin(page_setup, GTK_UNIT_INCH) * dpi,
66 gtk_page_setup_get_page_width(page_setup, GTK_UNIT_INCH) * dpi, 65 gtk_page_setup_get_page_width(page_setup, GTK_UNIT_INCH) * dpi,
67 gtk_page_setup_get_page_height(page_setup, GTK_UNIT_INCH) * dpi); 66 gtk_page_setup_get_page_height(page_setup, GTK_UNIT_INCH) * dpi);
68 } else { 67 } else {
69 // Use default values if we cannot get valid values from the print dialog. 68 // Use default values if we cannot get valid values from the print dialog.
70 dpi = printing::kPixelsPerInch; 69 dpi = printing::kPixelsPerInch;
71 double page_width_in_pixel = printing::kLetterWidthInch * dpi; 70 double page_width_in_pixel = printing::kLetterWidthInch * dpi;
72 double page_height_in_pixel = printing::kLetterHeightInch * dpi; 71 double page_height_in_pixel = printing::kLetterHeightInch * dpi;
73 physical_size_device_units.SetSize( 72 physical_size_device_units.SetSize(static_cast<int>(page_width_in_pixel),
74 static_cast<int>(page_width_in_pixel), 73 static_cast<int>(page_height_in_pixel));
75 static_cast<int>(page_height_in_pixel));
76 printable_area_device_units.SetRect( 74 printable_area_device_units.SetRect(
77 static_cast<int>(kLeftMarginInInch * dpi), 75 static_cast<int>(kLeftMarginInInch * dpi),
78 static_cast<int>(kTopMarginInInch * dpi), 76 static_cast<int>(kTopMarginInInch * dpi),
79 page_width_in_pixel - (kLeftMarginInInch + kRightMarginInInch) * dpi, 77 page_width_in_pixel - (kLeftMarginInInch + kRightMarginInInch) * dpi,
80 page_height_in_pixel - (kTopMarginInInch + kBottomMarginInInch) * dpi); 78 page_height_in_pixel - (kTopMarginInInch + kBottomMarginInInch) * dpi);
81 } 79 }
82 80
83 print_settings->set_dpi(dpi); 81 print_settings->set_dpi(dpi);
84 82
85 // Note: With the normal GTK print dialog, when the user selects the landscape 83 // Note: With the normal GTK print dialog, when the user selects the landscape
86 // orientation, all that does is change the paper size. Which seems to be 84 // orientation, all that does is change the paper size. Which seems to be
87 // enough to render the right output and send it to the printer. 85 // enough to render the right output and send it to the printer.
88 // The orientation value stays as portrait and does not actually affect 86 // The orientation value stays as portrait and does not actually affect
89 // printing. 87 // printing.
90 // Thus this is only useful in print preview mode, where we manually set the 88 // Thus this is only useful in print preview mode, where we manually set the
91 // orientation and change the paper size ourselves. 89 // orientation and change the paper size ourselves.
92 GtkPageOrientation orientation = gtk_print_settings_get_orientation(settings); 90 GtkPageOrientation orientation = gtk_print_settings_get_orientation(settings);
93 // Set before SetPrinterPrintableArea to make it flip area if necessary. 91 // Set before SetPrinterPrintableArea to make it flip area if necessary.
94 print_settings->SetOrientation(orientation == GTK_PAGE_ORIENTATION_LANDSCAPE); 92 print_settings->SetOrientation(orientation == GTK_PAGE_ORIENTATION_LANDSCAPE);
95 DCHECK_EQ(print_settings->device_units_per_inch(), dpi); 93 DCHECK_EQ(print_settings->device_units_per_inch(), dpi);
96 print_settings->SetPrinterPrintableArea(physical_size_device_units, 94 print_settings->SetPrinterPrintableArea(physical_size_device_units,
97 printable_area_device_units, 95 printable_area_device_units, true);
98 true);
99 } 96 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/libgtkui/printing_gtk_util.h ('k') | chrome/browser/ui/libgtkui/select_file_dialog_impl_gtk.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698