summaryrefslogtreecommitdiffstats
path: root/chrome/browser/resources/print_preview
diff options
context:
space:
mode:
authorkmadhusu@chromium.org <kmadhusu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-20 03:10:20 +0000
committerkmadhusu@chromium.org <kmadhusu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-20 03:10:20 +0000
commit0e77a1d0e67c41eaa07411b0d6958042c652476a (patch)
tree4386944cd86605ef5f7a55d6957f2dfc67f20e5b /chrome/browser/resources/print_preview
parent25cf2a0e92f4de4dd8a36c4dff25cba032fdbab4 (diff)
downloadchromium_src-0e77a1d0e67c41eaa07411b0d6958042c652476a.zip
chromium_src-0e77a1d0e67c41eaa07411b0d6958042c652476a.tar.gz
chromium_src-0e77a1d0e67c41eaa07411b0d6958042c652476a.tar.bz2
PrintPreview: Hide/Show the header footer option based on print frame margins.
BUG=104080 TEST= Please refer to bug report. Review URL: http://codereview.chromium.org/9699040 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@127631 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/resources/print_preview')
-rw-r--r--chrome/browser/resources/print_preview/header_footer_settings.js45
-rw-r--r--chrome/browser/resources/print_preview/margin_settings.js9
-rw-r--r--chrome/browser/resources/print_preview/print_preview.js13
3 files changed, 43 insertions, 24 deletions
diff --git a/chrome/browser/resources/print_preview/header_footer_settings.js b/chrome/browser/resources/print_preview/header_footer_settings.js
index 02776c5..882829b 100644
--- a/chrome/browser/resources/print_preview/header_footer_settings.js
+++ b/chrome/browser/resources/print_preview/header_footer_settings.js
@@ -13,7 +13,6 @@ cr.define('print_preview', function() {
function HeaderFooterSettings() {
this.headerFooterOption_ = $('header-footer-option');
this.headerFooterCheckbox_ = $('header-footer');
- this.headerFooterApplies_ = false;
this.addEventListeners_();
}
@@ -33,7 +32,7 @@ cr.define('print_preview', function() {
* @return {boolean} true if Headers and Footers are checked.
*/
hasHeaderFooter: function() {
- return this.headerFooterApplies_ && this.headerFooterCheckbox_.checked;
+ return previewModifiable && this.headerFooterCheckbox_.checked;
},
/**
@@ -46,6 +45,40 @@ cr.define('print_preview', function() {
},
/**
+ * Checks the printable area and updates the visibility of header footer
+ * option based on the selected margins.
+ * @param {{contentWidth: number, contentHeight: number, marginLeft: number,
+ * marginRight: number, marginTop: number, marginBottom: number,
+ * printableAreaX: number, printableAreaY: number,
+ * printableAreaWidth: number, printableAreaHeight: number}}
+ * pageLayout Specifies default page layout details in points.
+ * @param {number} marginsType Specifies the selected margins type value.
+ */
+ checkAndHideHeaderFooterOption: function(pageLayout, marginsType) {
+ var headerFooterApplies = true;
+ if (marginsType ==
+ print_preview.MarginSettings.MARGINS_VALUE_NO_MARGINS ||
+ !previewModifiable) {
+ headerFooterApplies = false;
+ } else if (marginsType !=
+ print_preview.MarginSettings.MARGINS_VALUE_MINIMUM) {
+ if (cr.isLinux || cr.isChromeOS) {
+ headerFooterApplies = pageLayout.marginTop > 0 ||
+ pageLayout.marginBottom > 0;
+ } else {
+ var pageHeight = pageLayout.marginTop + pageLayout.marginBottom +
+ pageLayout.contentHeight;
+ headerFooterApplies =
+ (pageLayout.marginTop > pageLayout.printableAreaY) ||
+ (pageLayout.marginBottom >
+ (pageHeight - pageLayout.printableAreaY -
+ pageLayout.printableAreaHeight));
+ }
+ }
+ this.setVisible_(headerFooterApplies);
+ },
+
+ /**
* Adding listeners to header footer related controls.
* @private
*/
@@ -54,14 +87,6 @@ cr.define('print_preview', function() {
this.onHeaderFooterChanged_.bind(this);
document.addEventListener(customEvents.PDF_LOADED,
this.onPDFLoaded_.bind(this));
- document.addEventListener(customEvents.MARGINS_SELECTION_CHANGED,
- this.onMarginsSelectionChanged_.bind(this));
- },
-
- onMarginsSelectionChanged_: function(event) {
- this.headerFooterApplies_ = event.selectedMargins !=
- print_preview.MarginSettings.MARGINS_VALUE_NO_MARGINS;
- this.setVisible_(this.headerFooterApplies_);
},
/**
diff --git a/chrome/browser/resources/print_preview/margin_settings.js b/chrome/browser/resources/print_preview/margin_settings.js
index 9faa640..0ffca9f 100644
--- a/chrome/browser/resources/print_preview/margin_settings.js
+++ b/chrome/browser/resources/print_preview/margin_settings.js
@@ -240,13 +240,6 @@ cr.define('print_preview', function() {
this.customMargins_ = new Margins(-1, -1, -1 , -1);
this.customMargins = lastUsedMarginsSettings;
}
- this.dispatchMarginsChangedEvent_();
- },
-
- dispatchMarginsChangedEvent_: function() {
- var customEvent = cr.Event(customEvents.MARGINS_SELECTION_CHANGED);
- customEvent.selectedMargins = this.selectedMarginsValue;
- document.dispatchEvent(customEvent);
},
/**
@@ -567,8 +560,6 @@ cr.define('print_preview', function() {
* @private
*/
onMarginsChanged_: function() {
- this.dispatchMarginsChangedEvent_();
-
if (this.isDefaultMarginsSelected() || this.isMinimumMarginsSelected() ||
this.isNoMarginsSelected())
this.onDefaultMinimumNoMarginsSelected_();
diff --git a/chrome/browser/resources/print_preview/print_preview.js b/chrome/browser/resources/print_preview/print_preview.js
index d39d666..d5d239d 100644
--- a/chrome/browser/resources/print_preview/print_preview.js
+++ b/chrome/browser/resources/print_preview/print_preview.js
@@ -126,8 +126,6 @@ var customEvents = {
MARGIN_TEXTBOX_FOCUSED: 'marginTextboxFocused',
// Fired when a new preview might be needed because of margin changes.
MARGINS_MAY_HAVE_CHANGED: 'marginsMayHaveChanged',
- // Fired when the margins selection in the dropdown changes.
- MARGINS_SELECTION_CHANGED: 'marginsSelectionChanged',
// Fired when a pdf generation related error occurs.
PDF_GENERATION_ERROR: 'PDFGenerationError',
// Fired once the first page of the pdf document is loaded in the plugin.
@@ -868,10 +866,13 @@ function onDidGetPreviewPageCount(pageCount, previewResponseId) {
}
/**
- * @param {printing::PageSizeMargins} pageLayout The default layout of the page
- * in points.
+ * @param {{contentWidth: number, contentHeight: number, marginLeft: number,
+ * marginRight: number, marginTop: number, marginBottom: number,
+ * printableAreaX: number, printableAreaY: number,
+ * printableAreaWidth: number, printableAreaHeight: number}} pageLayout
+ * Specifies default page layout details in points.
* @param {boolean} hasCustomPageSizeStyle Indicates whether the previewed
- * document has a custom page size style.
+ * document has a custom page size style.
*/
function onDidGetDefaultPageLayout(pageLayout, hasCustomPageSizeStyle) {
hasPageSizeStyle = hasCustomPageSizeStyle;
@@ -882,6 +883,8 @@ function onDidGetDefaultPageLayout(pageLayout, hasCustomPageSizeStyle) {
pageLayout.marginTop,
pageLayout.marginRight,
pageLayout.marginBottom);
+ headerFooterSettings.checkAndHideHeaderFooterOption(
+ pageLayout, marginSettings.selectedMarginsValue);
}
/**