Chromium Code Reviews| Index: Source/core/html/shadow/PluginPlaceholderElement.js |
| diff --git a/Source/core/html/shadow/PluginPlaceholderElement.js b/Source/core/html/shadow/PluginPlaceholderElement.js |
| index 21cc3b782cc90ab99789d7c5ec5706f130f89255..21f02894ffff2571165007ba859395ae3a533eda 100644 |
| --- a/Source/core/html/shadow/PluginPlaceholderElement.js |
| +++ b/Source/core/html/shadow/PluginPlaceholderElement.js |
| @@ -33,15 +33,66 @@ installClass('PluginPlaceholderElement', function(PluginPlaceholderElementProtot |
| var messageElement = document.createElement('div'); |
| messageElement.id = 'plugin-placeholder-message'; |
| + // FIXME: UI polish, l10n, etc. for the close button. |
| + var closeButton = document.createElement('button'); |
| + closeButton.id = 'plugin-placeholder-close-button'; |
|
Mike West
2014/11/02 14:01:44
Are you sure that only one of these can exist per
jbroman
2014/11/03 16:20:36
Shadow roots scope IDs within them; since (except
|
| + closeButton.textContent = 'Close'; |
|
Mike West
2014/11/02 14:01:44
Do we have a localization scheme in place for UI g
jbroman
2014/11/03 16:20:36
Not yet, as far as I know. This button may get rep
Mike West
2014/11/03 16:35:46
You'll need some text on the button, otherwise it
|
| + closeButton.style.display = 'none'; |
| + closeButton.addEventListener('click', function() { |
| + // FIXME: Record UMA Plugin_Hide_Click. |
| + this.hide(); |
| + }.bind(this)); |
| + |
| contentElement.appendChild(messageElement); |
| + contentElement.appendChild(closeButton); |
| this.appendChild(styleElement); |
| this.appendChild(contentElement); |
| this.messageElement = messageElement; |
| + this.closeButton = closeButton; |
| + }; |
| + |
| + PluginPlaceholderElementPrototype.hide = function() { |
| + var host = (this.parentNode instanceof ShadowRoot) ? this.parentNode.host : this; |
| + host.style.display = 'none'; |
| + |
| + // If we have a width and height, search for a parent (often <div>) with the |
| + // same dimensions. If we find such a parent, hide that as well. |
| + // This makes much more uncovered page content usable (including clickable) |
| + // as opposed to merely visible. |
| + // TODO(cevans) -- it's a foul heuristic but we're going to tolerate it for |
| + // now for these reasons: |
| + // 1) Makes the user experience better. |
| + // 2) Foulness is encapsulated within this single function. |
| + // 3) Confidence in no false positives. |
| + // 4) Seems to have a good / low false negative rate at this time. |
|
Mike West
2014/11/02 14:01:44
Nit: Please add a note here pointing to the heuris
jbroman
2014/11/03 16:20:36
Done. Once this version ships, I expect the other
|
| + if (host.hasAttribute('width') && host.hasAttribute('height')) { |
| + var presentationAttributeInPixels = function(attr) { |
| + var match = host.getAttribute(attr).match(/^\s*(\d+)\s*(px)?\s*$/); |
| + if (match) |
| + return match[1] + 'px'; |
| + }; |
| + var width = presentationAttributeInPixels('width'); |
| + var height = presentationAttributeInPixels('height'); |
| + if (!width || !height) |
| + return; |
| + |
| + var element = host; |
| + while (element instanceof Element) { |
| + if (element.style.width == width && element.style.height == height) |
| + element.style.display = 'none'; |
| + element = element.parentNode; |
| + } |
| + } |
| }; |
| Object.defineProperty(PluginPlaceholderElementPrototype, 'message', { |
| get: function() { return this.messageElement.textContent; }, |
| set: function(message) { this.messageElement.textContent = message; }, |
| }); |
| + |
| + Object.defineProperty(PluginPlaceholderElementPrototype, 'closeable', { |
| + get: function() { return this.closeButton.style.display != 'none'; }, |
| + set: function(closeable) { this.closeButton.style.display = closeable ? '' : 'none'; }, |
| + }); |
| }); |