Commit 44cb6549 authored by Christopher Lam's avatar Christopher Lam Committed by Commit Bot

WebUI Polymer 2 migration: Remove cr-lazy-render type extension.

This CL upgrades cr-lazy-render for compatibility with Polymer 2. It
does this by using a slot for a <template> from the light DOM which
gets templatized since the cr-lazy-render element itself can no longer
be a <template>.

This means that all clients need to wrap their light DOM in <template>
tags.

Bug: 818279
Cq-Include-Trybots: master.tryserver.chromium.linux:closure_compilation
Change-Id: Ieaed7cb2f9422557aed0c3a388939b17b5825245
Reviewed-on: https://chromium-review.googlesource.com/977203
Commit-Queue: calamity <calamity@chromium.org>
Reviewed-by: default avatarDemetrios Papadopoulos <dpapad@chromium.org>
Cr-Commit-Position: refs/heads/master@{#546012}
parent 68272510
...@@ -28,7 +28,8 @@ ...@@ -28,7 +28,8 @@
display: none; display: none;
} }
</style> </style>
<template is="cr-lazy-render" id="dropdown"> <cr-lazy-render id="dropdown">
<template>
<cr-action-menu on-mousedown="onMenuMousedown_"> <cr-action-menu on-mousedown="onMenuMousedown_">
<template is="dom-repeat" items="[[menuCommands_]]" as="command"> <template is="dom-repeat" items="[[menuCommands_]]" as="command">
<button slot="item" class="dropdown-item" <button slot="item" class="dropdown-item"
...@@ -45,14 +46,17 @@ ...@@ -45,14 +46,17 @@
</button> </button>
<hr hidden$="[[!showDividerAfter_(command, menuIds_)]]" <hr hidden$="[[!showDividerAfter_(command, menuIds_)]]"
aria-hidden="true"> aria-hidden="true">
</hr>
</template> </template>
</cr-action-menu> </cr-action-menu>
</template> </template>
<template is="cr-lazy-render" id="editDialog"> </cr-lazy-render>
<cr-lazy-render id="editDialog">
<template>
<bookmarks-edit-dialog></bookmarks-edit-dialog> <bookmarks-edit-dialog></bookmarks-edit-dialog>
</template> </template>
<template is="cr-lazy-render" id="openDialog"> </cr-lazy-render>
<cr-lazy-render id="openDialog">
<template>
<dialog is="cr-dialog"> <dialog is="cr-dialog">
<div slot="title">$i18n{openDialogTitle}</div> <div slot="title">$i18n{openDialogTitle}</div>
<div slot="body"></div> <div slot="body"></div>
...@@ -66,6 +70,7 @@ ...@@ -66,6 +70,7 @@
</div> </div>
</dialog> </dialog>
</template> </template>
</cr-lazy-render>
</template> </template>
<script src="chrome://bookmarks/command_manager.js"></script> <script src="chrome://bookmarks/command_manager.js"></script>
</dom-module> </dom-module>
...@@ -87,23 +87,29 @@ ...@@ -87,23 +87,29 @@
apps="[[apps_]]" extensions="[[extensions_]]" apps="[[apps_]]" extensions="[[extensions_]]"
on-show-install-warnings="onShowInstallWarnings_"> on-show-install-warnings="onShowInstallWarnings_">
</extensions-item-list> </extensions-item-list>
<template id="details-view" is="cr-lazy-render"> <cr-lazy-render id="details-view">
<template>
<extensions-detail-view delegate="[[delegate]]" slot="view" <extensions-detail-view delegate="[[delegate]]" slot="view"
in-dev-mode="[[inDevMode]]" in-dev-mode="[[inDevMode]]"
incognito-available="[[incognitoAvailable_]]" incognito-available="[[incognitoAvailable_]]"
data="[[detailViewItem_]]"> data="[[detailViewItem_]]">
</extensions-detail-view> </extensions-detail-view>
</template> </template>
<template id="keyboard-shortcuts" is="cr-lazy-render"> </cr-lazy-render>
<cr-lazy-render id="keyboard-shortcuts">
<template>
<extensions-keyboard-shortcuts delegate="[[delegate]]" slot="view" <extensions-keyboard-shortcuts delegate="[[delegate]]" slot="view"
items="[[extensions_]]"> items="[[extensions_]]">
</extensions-keyboard-shortcuts> </extensions-keyboard-shortcuts>
</template> </template>
<template id="error-page" is="cr-lazy-render"> </cr-lazy-render>
<cr-lazy-render id="error-page">
<template>
<extensions-error-page data="[[errorPageItem_]]" slot="view" <extensions-error-page data="[[errorPageItem_]]" slot="view"
delegate="[[delegate]]" slot="view"> delegate="[[delegate]]" slot="view">
</extensions-error-page> </extensions-error-page>
</template> </template>
</cr-lazy-render>
</extensions-view-manager> </extensions-view-manager>
<template is="dom-if" if="[[showOptionsDialog_]]" restamp> <template is="dom-if" if="[[showOptionsDialog_]]" restamp>
<extensions-options-dialog id="options-dialog" <extensions-options-dialog id="options-dialog"
......
...@@ -80,8 +80,7 @@ cr.define('extensions', function() { ...@@ -80,8 +80,7 @@ cr.define('extensions', function() {
const animationFunction = extensions.viewAnimations.get(animation); const animationFunction = extensions.viewAnimations.get(animation);
assert(animationFunction); assert(animationFunction);
let effectiveView = let effectiveView = view.matches('cr-lazy-render') ? view.get() : view;
view.matches('[is=cr-lazy-render]') ? view.get() : view;
effectiveView.classList.add('active'); effectiveView.classList.add('active');
effectiveView.dispatchEvent(new CustomEvent('view-enter-start')); effectiveView.dispatchEvent(new CustomEvent('view-enter-start'));
......
...@@ -103,7 +103,8 @@ ...@@ -103,7 +103,8 @@
</iron-pages> </iron-pages>
</div> </div>
<template is="cr-lazy-render" id="drawer"> <cr-lazy-render id="drawer">
<template>
<cr-drawer heading="$i18n{title}" align="$i18n{textdirection}" <cr-drawer heading="$i18n{title}" align="$i18n{textdirection}"
swipe-open> swipe-open>
<history-side-bar id="drawer-side-bar" class="drawer-content" <history-side-bar id="drawer-side-bar" class="drawer-content"
...@@ -112,6 +113,7 @@ ...@@ -112,6 +113,7 @@
</history-side-bar> </history-side-bar>
</cr-drawer> </cr-drawer>
</template> </template>
</cr-lazy-render>
<iron-media-query query="(max-width: 1023px)" <iron-media-query query="(max-width: 1023px)"
query-matches="{{hasDrawer_}}"> query-matches="{{hasDrawer_}}">
......
...@@ -58,7 +58,8 @@ ...@@ -58,7 +58,8 @@
lower-threshold="500" on-lower-threshold="onScrollToBottom_"> lower-threshold="500" on-lower-threshold="onScrollToBottom_">
</iron-scroll-threshold> </iron-scroll-threshold>
<template is="cr-lazy-render" id="dialog"> <cr-lazy-render id="dialog">
<template>
<dialog is="cr-dialog"> <dialog is="cr-dialog">
<div slot="title">$i18n{removeSelected}</div> <div slot="title">$i18n{removeSelected}</div>
<div slot="body">$i18n{deleteWarning}</div> <div slot="body">$i18n{deleteWarning}</div>
...@@ -72,8 +73,10 @@ ...@@ -72,8 +73,10 @@
</div> </div>
</dialog> </dialog>
</template> </template>
</cr-lazy-render>
<template is="cr-lazy-render" id="sharedMenu"> <cr-lazy-render id="sharedMenu">
<template>
<cr-action-menu> <cr-action-menu>
<button id="menuMoreButton" slot="item" class="dropdown-item" <button id="menuMoreButton" slot="item" class="dropdown-item"
hidden="[[!canSearchMoreFromSite_( hidden="[[!canSearchMoreFromSite_(
...@@ -88,6 +91,7 @@ ...@@ -88,6 +91,7 @@
</button> </button>
</cr-action-menu> </cr-action-menu>
</template> </template>
</cr-lazy-render>
</template> </template>
<script src="chrome://history/history_list.js"></script> <script src="chrome://history/history_list.js"></script>
</dom-module> </dom-module>
...@@ -87,7 +87,8 @@ ...@@ -87,7 +87,8 @@
</paper-button> </paper-button>
</div> </div>
<template is="cr-lazy-render" id="menu"> <cr-lazy-render id="menu">
<template>
<cr-action-menu> <cr-action-menu>
<button id="menuOpenButton" slot="item" class="dropdown-item" <button id="menuOpenButton" slot="item" class="dropdown-item"
on-click="onOpenAllTap_"> on-click="onOpenAllTap_">
...@@ -99,6 +100,7 @@ ...@@ -99,6 +100,7 @@
</button> </button>
</cr-action-menu> </cr-action-menu>
</template> </template>
</cr-lazy-render>
</template> </template>
<script src="chrome://history/synced_device_manager.js"></script> <script src="chrome://history/synced_device_manager.js"></script>
</dom-module> </dom-module>
...@@ -24,11 +24,13 @@ ...@@ -24,11 +24,13 @@
</button> </button>
</div> </div>
</print-preview-settings-section> </print-preview-settings-section>
<template is="cr-lazy-render" id="advancedDialog"> <cr-lazy-render id="advancedDialog">
<template>
<print-preview-advanced-dialog <print-preview-advanced-dialog
settings="{{settings}}" destination="[[destination]]"> settings="{{settings}}" destination="[[destination]]">
</print-preview-advanced-dialog> </print-preview-advanced-dialog>
</template> </template>
</cr-lazy-render>
</template> </template>
<script src="advanced_options_settings.js"></script> <script src="advanced_options_settings.js"></script>
</dom-module> </dom-module>
...@@ -88,7 +88,8 @@ ...@@ -88,7 +88,8 @@
</button> </button>
</div> </div>
</print-preview-settings-section> </print-preview-settings-section>
<template is="cr-lazy-render" id="destinationDialog"> <cr-lazy-render id="destinationDialog">
<template>
<print-preview-destination-dialog <print-preview-destination-dialog
destination-store="[[destinationStore]]" destination-store="[[destinationStore]]"
recent-destinations="[[recentDestinations]]" recent-destinations="[[recentDestinations]]"
...@@ -96,6 +97,7 @@ ...@@ -96,6 +97,7 @@
show-cloud-print-promo="{{showCloudPrintPromo_}}"> show-cloud-print-promo="{{showCloudPrintPromo_}}">
</print-preview-destination-dialog> </print-preview-destination-dialog>
</template> </template>
</cr-lazy-render>
</template> </template>
<script src="destination_settings.js"></script> <script src="destination_settings.js"></script>
</dom-module> </dom-module>
...@@ -265,7 +265,8 @@ ...@@ -265,7 +265,8 @@
</div> </div>
</iron-collapse> </iron-collapse>
</if> </if>
<template is="cr-lazy-render" id="menu"> <cr-lazy-render id="menu">
<template>
<cr-action-menu <cr-action-menu
class$="[[getMenuClass_(prefs.translate.enabled.value)]]"> class$="[[getMenuClass_(prefs.translate.enabled.value)]]">
<if expr="chromeos or is_win"> <if expr="chromeos or is_win">
...@@ -298,7 +299,8 @@ ...@@ -298,7 +299,8 @@
</button> </button>
<button slot="item" class="dropdown-item" role="menuitem" <button slot="item" class="dropdown-item" role="menuitem"
on-click="onMoveUpTap_" on-click="onMoveUpTap_"
hidden="[[!showMoveUp_(detailLanguage_, languages.enabled.*)]]"> hidden="[[!showMoveUp_(detailLanguage_,
languages.enabled.*)]]">
$i18n{moveUp} $i18n{moveUp}
</button> </button>
<button slot="item" class="dropdown-item" role="menuitem" <button slot="item" class="dropdown-item" role="menuitem"
...@@ -314,6 +316,7 @@ ...@@ -314,6 +316,7 @@
</button> </button>
</cr-action-menu> </cr-action-menu>
</template> </template>
</cr-lazy-render>
</neon-animatable> </neon-animatable>
<if expr="chromeos"> <if expr="chromeos">
<template is="dom-if" route-path="/inputMethods"> <template is="dom-if" route-path="/inputMethods">
......
...@@ -30,7 +30,8 @@ ...@@ -30,7 +30,8 @@
focus-row-control focus-type="menu"> focus-row-control focus-type="menu">
</button> </button>
</paper-icon-button-light> </paper-icon-button-light>
<template is="cr-lazy-render" id="menu"> <cr-lazy-render id="menu">
<template>
<cr-action-menu> <cr-action-menu>
<button slot="item" class="dropdown-item" on-click="onEditTap_"> <button slot="item" class="dropdown-item" on-click="onEditTap_">
$i18n{edit} $i18n{edit}
...@@ -41,6 +42,7 @@ ...@@ -41,6 +42,7 @@
</button> </button>
</cr-action-menu> </cr-action-menu>
</template> </template>
</cr-lazy-render>
</template> </template>
</div> </div>
</template> </template>
......
...@@ -40,10 +40,13 @@ ...@@ -40,10 +40,13 @@
</div> </div>
<!-- Keep a single instance of reset-profile-dialog on purpose, to <!-- Keep a single instance of reset-profile-dialog on purpose, to
preserve state across show/hide operations. --> preserve state across show/hide operations. -->
<template is="cr-lazy-render" id="resetProfileDialog"> <cr-lazy-render id="resetProfileDialog">
<settings-reset-profile-dialog on-close="onResetProfileDialogClose_"> <template>
<settings-reset-profile-dialog
on-close="onResetProfileDialogClose_">
</settings-reset-profile-dialog> </settings-reset-profile-dialog>
</template> </template>
</cr-lazy-render>
<if expr="chromeos"> <if expr="chromeos">
<div class="settings-box two-line" id="powerwash" actionable <div class="settings-box two-line" id="powerwash" actionable
on-click="onShowPowerwashDialog_" hidden="[[!allowPowerwash_]]"> on-click="onShowPowerwashDialog_" hidden="[[!allowPowerwash_]]">
......
...@@ -13,15 +13,17 @@ suite('cr-lazy-render', function() { ...@@ -13,15 +13,17 @@ suite('cr-lazy-render', function() {
setup(function() { setup(function() {
PolymerTest.clearBody(); PolymerTest.clearBody();
const template = const template = `
'<template is="dom-bind" id="bind">' + <template is="dom-bind" id="bind">
' <template is="cr-lazy-render" id="lazy">' + <cr-lazy-render id="lazy">
' <h1>' + <template>
' <paper-checkbox checked="{{checked}}"></paper-checkbox>' + <h1>
' {{name}}' + <paper-checkbox checked="{{checked}}"></paper-checkbox>
' </h1>' + {{name}}
' </template>' + </h1>
'</template>'; </template>
</cr-lazy-render>
</template>`;
document.body.innerHTML = template; document.body.innerHTML = template;
lazy = document.getElementById('lazy'); lazy = document.getElementById('lazy');
bind = document.getElementById('bind'); bind = document.getElementById('bind');
......
...@@ -36,7 +36,8 @@ ...@@ -36,7 +36,8 @@
<button id="dots" title="[[i18n('moreActions')]]" on-tap="onDotsTap_"> <button id="dots" title="[[i18n('moreActions')]]" on-tap="onDotsTap_">
</button> </button>
</paper-icon-button-light> </paper-icon-button-light>
<template is="cr-lazy-render" id="menu"> <cr-lazy-render id="menu">
<template>
<cr-action-menu> <cr-action-menu>
<button slot="item" class="dropdown-item" id="view" <button slot="item" class="dropdown-item" id="view"
on-tap="onViewTap_"> on-tap="onViewTap_">
...@@ -59,6 +60,7 @@ ...@@ -59,6 +60,7 @@
</button> </button>
</cr-action-menu> </cr-action-menu>
</template> </template>
</cr-lazy-render>
<div> <div>
</template> </template>
<script src="certificate_subentry.js"></script> <script src="certificate_subentry.js"></script>
......
<link rel="import" href="chrome://resources/html/polymer.html"> <link rel="import" href="chrome://resources/html/polymer.html">
<script src="cr_lazy_render.js"></script> <dom-module id="cr-lazy-render">
<template>
<slot></slot>
</template>
<script src="cr_lazy_render.js"></script>
</dom-module>
...@@ -7,16 +7,20 @@ ...@@ -7,16 +7,20 @@
* cr-lazy-render is a simple variant of dom-if designed for lazy rendering * cr-lazy-render is a simple variant of dom-if designed for lazy rendering
* of elements that are accessed imperatively. * of elements that are accessed imperatively.
* Usage: * Usage:
* <template is="cr-lazy-render" id="menu"> * <cr-lazy-render id="menu">
* <template>
* <heavy-menu></heavy-menu> * <heavy-menu></heavy-menu>
* </template> * </template>
* </cr-lazy-render>
* *
* this.$.menu.get().show(); * this.$.menu.get().show();
*
* TODO(calamity): Use Polymer.Templatize instead of inheriting the
* Polymer.Templatizer behavior once Polymer 2.0 is available.
*/ */
Polymer({ Polymer({
is: 'cr-lazy-render', is: 'cr-lazy-render',
extends: 'template',
behaviors: [Polymer.Templatizer], behaviors: [Polymer.Templatizer],
...@@ -43,8 +47,9 @@ Polymer({ ...@@ -43,8 +47,9 @@ Polymer({
/** @private */ /** @private */
render_: function() { render_: function() {
if (!this.ctor) var template = this.getContentChildren()[0];
this.templatize(this); if (!template.ctor)
this.templatize(template);
var parentNode = this.parentNode; var parentNode = this.parentNode;
if (parentNode && !this.child_) { if (parentNode && !this.child_) {
var instance = this.stamp({}); var instance = this.stamp({});
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment