Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 'use strict'; | 5 'use strict'; |
| 6 | 6 |
| 7 installClass('PluginPlaceholderElement', function(PluginPlaceholderElementProtot ype) { | 7 installClass('PluginPlaceholderElement', function(PluginPlaceholderElementProtot ype) { |
| 8 // FIXME: Load this from a .css file. | 8 // FIXME: Load this from a .css file. |
| 9 var styleSource = | 9 var styleSource = |
| 10 '#plugin-placeholder {' + | 10 '#plugin-placeholder {' + |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 26 | 26 |
| 27 var styleElement = document.createElement('style'); | 27 var styleElement = document.createElement('style'); |
| 28 styleElement.textContent = styleSource; | 28 styleElement.textContent = styleSource; |
| 29 | 29 |
| 30 var contentElement = document.createElement('div'); | 30 var contentElement = document.createElement('div'); |
| 31 contentElement.id = 'plugin-placeholder-content'; | 31 contentElement.id = 'plugin-placeholder-content'; |
| 32 | 32 |
| 33 var messageElement = document.createElement('div'); | 33 var messageElement = document.createElement('div'); |
| 34 messageElement.id = 'plugin-placeholder-message'; | 34 messageElement.id = 'plugin-placeholder-message'; |
| 35 | 35 |
| 36 // FIXME: UI polish, l10n, etc. for the close button. | |
| 37 var closeButton = document.createElement('button'); | |
| 38 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
| |
| 39 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
| |
| 40 closeButton.style.display = 'none'; | |
| 41 closeButton.addEventListener('click', function() { | |
| 42 // FIXME: Record UMA Plugin_Hide_Click. | |
| 43 this.hide(); | |
| 44 }.bind(this)); | |
| 45 | |
| 36 contentElement.appendChild(messageElement); | 46 contentElement.appendChild(messageElement); |
| 47 contentElement.appendChild(closeButton); | |
| 37 this.appendChild(styleElement); | 48 this.appendChild(styleElement); |
| 38 this.appendChild(contentElement); | 49 this.appendChild(contentElement); |
| 39 | 50 |
| 40 this.messageElement = messageElement; | 51 this.messageElement = messageElement; |
| 52 this.closeButton = closeButton; | |
| 53 }; | |
| 54 | |
| 55 PluginPlaceholderElementPrototype.hide = function() { | |
| 56 var host = (this.parentNode instanceof ShadowRoot) ? this.parentNode.hos t : this; | |
| 57 host.style.display = 'none'; | |
| 58 | |
| 59 // If we have a width and height, search for a parent (often <div>) with the | |
| 60 // same dimensions. If we find such a parent, hide that as well. | |
| 61 // This makes much more uncovered page content usable (including clickab le) | |
| 62 // as opposed to merely visible. | |
| 63 // TODO(cevans) -- it's a foul heuristic but we're going to tolerate it for | |
| 64 // now for these reasons: | |
| 65 // 1) Makes the user experience better. | |
| 66 // 2) Foulness is encapsulated within this single function. | |
| 67 // 3) Confidence in no false positives. | |
| 68 // 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
| |
| 69 if (host.hasAttribute('width') && host.hasAttribute('height')) { | |
| 70 var presentationAttributeInPixels = function(attr) { | |
| 71 var match = host.getAttribute(attr).match(/^\s*(\d+)\s*(px)?\s*$ /); | |
| 72 if (match) | |
| 73 return match[1] + 'px'; | |
| 74 }; | |
| 75 var width = presentationAttributeInPixels('width'); | |
| 76 var height = presentationAttributeInPixels('height'); | |
| 77 if (!width || !height) | |
| 78 return; | |
| 79 | |
| 80 var element = host; | |
| 81 while (element instanceof Element) { | |
| 82 if (element.style.width == width && element.style.height == heig ht) | |
| 83 element.style.display = 'none'; | |
| 84 element = element.parentNode; | |
| 85 } | |
| 86 } | |
| 41 }; | 87 }; |
| 42 | 88 |
| 43 Object.defineProperty(PluginPlaceholderElementPrototype, 'message', { | 89 Object.defineProperty(PluginPlaceholderElementPrototype, 'message', { |
| 44 get: function() { return this.messageElement.textContent; }, | 90 get: function() { return this.messageElement.textContent; }, |
| 45 set: function(message) { this.messageElement.textContent = message; }, | 91 set: function(message) { this.messageElement.textContent = message; }, |
| 46 }); | 92 }); |
| 93 | |
| 94 Object.defineProperty(PluginPlaceholderElementPrototype, 'closeable', { | |
| 95 get: function() { return this.closeButton.style.display != 'none'; }, | |
| 96 set: function(closeable) { this.closeButton.style.display = closeable ? '' : 'none'; }, | |
| 97 }); | |
| 47 }); | 98 }); |
| OLD | NEW |