Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion js/tinymce/classes/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -1128,7 +1128,10 @@ define("tinymce/Editor", [
body.focus();
}
} else {
body.focus();
// Under native Shadow DOM body ==== self.targetElm and causes infinite loop
if (body !== self.targetElm || !Object.getPrototypeOf(document).registerElement) {
body.focus();
}
}

if (contentEditable) {
Expand Down
17 changes: 12 additions & 5 deletions js/tinymce/classes/FocusManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ define("tinymce/FocusManager", [
function FocusManager(editorManager) {
function getActiveElement() {
try {
return document.activeElement;
// TODO: Hack for WebComponents.js polyfill, that doesn't wrap `document` and thus `document.activeElement` is not wrapped too
return document.querySelector('html').parentNode.activeElement;
} catch (ex) {
// IE sometimes fails to get the activeElement when resizing table
// TODO: Investigate this
Expand Down Expand Up @@ -113,6 +114,11 @@ define("tinymce/FocusManager", [
node = editor.getBody();
}

// If node has Shadow Root - real active element is somewhere inside
while (node.shadowRoot && node.shadowRoot.activeElement) {
node = node.shadowRoot.activeElement;
}

if (editor.dom.isChildOf(node, editor.getBody())) {
editor.lastRng = editor.selection.getRng();
}
Expand Down Expand Up @@ -196,10 +202,10 @@ define("tinymce/FocusManager", [
var activeEditor = editorManager.activeEditor, target;

target = e.target;

if (activeEditor && target.ownerDocument == document) {
// TODO: Hack for WebComponents.js polyfill, that wraps `element.ownerDocument` and thus do not equal to `document` anymore
if (activeEditor && target.ownerDocument == document.querySelector('html').parentNode) {
// Check to make sure we have a valid selection don't update the bookmark if it's
// a focusin to the body of the editor see #7025
// a focusing to the body of the editor see #7025
if (activeEditor.selection && target != activeEditor.getBody()) {
activeEditor.selection.lastFocusBookmark = createBookmark(activeEditor.dom, activeEditor.lastRng);
}
Expand Down Expand Up @@ -260,8 +266,9 @@ define("tinymce/FocusManager", [
* @return {Boolean} True/false state if the element is part of the UI or not.
*/
FocusManager.isEditorUIElement = function(elm) {
// Focused Shadow Root doesn't have `elm.className` property
// Needs to be converted to string since svg can have focus: #6776
return elm.className.toString().indexOf('mce-') !== -1;
return elm.className && elm.className.toString().indexOf('mce-') !== -1;
};

return FocusManager;
Expand Down
2 changes: 2 additions & 0 deletions js/tinymce/classes/WindowManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ define("tinymce/WindowManager", [
self.open = function(args, params) {
var win;

args.target = editor.targetElm;

editor.editorManager.setActive(editor);

args.title = args.title || ' ';
Expand Down
10 changes: 5 additions & 5 deletions js/tinymce/classes/dom/DOMUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -396,19 +396,19 @@ define("tinymce/dom/DOMUtils", [
* Returns the specified element by ID or the input element if it isn't a string.
*
* @method get
* @param {String/Element} n Element id to look for or element to just pass though.
* @param {String/Element} elm Element id to look for or element to just pass though.
* @return {Element} Element matching the specified id or null if it wasn't found.
*/
get: function(elm) {
var name;
var name, root = this.settings.root_element || this.doc;

if (elm && this.doc && typeof elm == 'string') {
if (elm && root && typeof elm == 'string') {
name = elm;
elm = this.doc.getElementById(elm);
elm = root.querySelector('#' + elm);

// IE and Opera returns meta elements when they match the specified input ID, but getElementsByName seems to do the trick
if (elm && elm.id !== name) {
return this.doc.getElementsByName(name)[1];
return root.querySelector('[name=' + name + ']')[1];
}
}

Expand Down
3 changes: 2 additions & 1 deletion js/tinymce/classes/dom/DomQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,8 @@ define("tinymce/dom/DomQuery", [
node = node.nextSibling;
}
} else {
node = getElementDocument(context).getElementById(match[2]);
// Element might be in global scope or inside current context (within Shadow DOM)
node = getElementDocument(context).getElementById(match[2]) || context.querySelector('#' + match[2]);

if (!node) {
return self;
Expand Down
19 changes: 17 additions & 2 deletions js/tinymce/classes/dom/RangeUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -584,9 +584,24 @@ define("tinymce/dom/RangeUtils", [
* @returns {Range} caret range
*/
RangeUtils.getCaretRangeFromPoint = function(clientX, clientY, doc) {
var rng, point;
var element, point, rect, rng;

if (doc.caretPositionFromPoint) {
// Check whether target point is under Shadow DOM
element = doc.elementFromPoint(clientX, clientY);
if (element && element.shadowRoot) {
// Under Shadow DOM the best thing we can do it to determine end or start of target place, not exact position
rng = doc.createRange();
while (element.shadowRoot) {
element = element.shadowRoot.elementFromPoint(clientX, clientY);
}
rect = element.getBoundingClientRect();
// 10px is limit where insertion point will be considered to be at start, otherwise at the end
if (clientX > doc.scrollingElement.scrollLeft + rect.left + 10) {
rng.setStart(element, 1);
} else {
rng.setStart(element, 0);
}
} else if (doc.caretPositionFromPoint) {
point = doc.caretPositionFromPoint(clientX, clientY);
rng = doc.createRange();
rng.setStart(point.offsetNode, point.offset);
Expand Down
17 changes: 17 additions & 0 deletions js/tinymce/classes/dom/Selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,23 @@ define("tinymce/dom/Selection", [
*/
getSel: function() {
var win = this.win;
try {
// We need to return Shadow Root if target element is under Shadow DOM and not using iframe
if (!this.editor.iframeElement && this.editor.targetElm.matches && this.editor.targetElm.matches(':host *')) {
(function(target) {
while (target.parentNode) {
target = target.parentNode;
}
// If there is no parent node, but there is `host` property - we've just found Shadow Root,
// where we'll get selection
if (target.host) {
win = target;
}
})(this.editor.targetElm);
}
} catch (err) {
// Nothing, even if `.matches` method is present - it doesn't mean that browsers understands ':host *' selector
}

return win.getSelection ? win.getSelection() : win.document.selection;
},
Expand Down
5 changes: 5 additions & 0 deletions js/tinymce/classes/jquery.tinymce.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@
node.id = id = tinymce.DOM.uniqueId();
}

// Set target if not specified, otherwise we'll not be able to find in by id under Shadow DOM
if (!settings.target) {
settings = self.extend(settings, {target: node});
}

// Only init the editor once
if (tinymce.get(id)) {
return;
Expand Down
4 changes: 2 additions & 2 deletions js/tinymce/classes/ui/ComboBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ define("tinymce/ui/ComboBox", [
menu.type = menu.type || 'menu';
}

self.menu = Factory.create(menu).parent(self).renderTo(self.getContainerElm());
self.menu = Factory.create(menu, {target: self.settings.target}).parent(self).renderTo(self.getContainerElm());
self.fire('createmenu');
self.menu.reflow();
self.menu.on('cancel', function(e) {
Expand Down Expand Up @@ -303,4 +303,4 @@ define("tinymce/ui/ComboBox", [
this._super();
}
});
});
});
6 changes: 3 additions & 3 deletions js/tinymce/classes/ui/Container.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ define("tinymce/ui/Container", [
self.classes.add(settings.containerCls);
}

self._layout = Factory.create((settings.layout || '') + 'layout');
self._layout = Factory.create((settings.layout || '') + 'layout', {target: settings.target});

if (self.settings.items) {
self.add(self.settings.items);
Expand Down Expand Up @@ -234,7 +234,7 @@ define("tinymce/ui/Container", [
settings = Tools.extend({}, self.settings.defaults, item);
item.type = settings.type = settings.type || item.type || self.settings.defaultType ||
(settings.defaults ? settings.defaults.type : null);
item = Factory.create(settings);
item = Factory.create(settings, {target: self.settings.target});
}

ctrlItems.push(item);
Expand Down Expand Up @@ -503,4 +503,4 @@ define("tinymce/ui/Container", [
return this;
}
});
});
});
38 changes: 35 additions & 3 deletions js/tinymce/classes/ui/Control.js
Original file line number Diff line number Diff line change
Expand Up @@ -631,10 +631,36 @@ define("tinymce/ui/Control", [
* @return {Element} HTML DOM element for the current control or it's children.
*/
getEl: function(suffix) {
var id = suffix ? this._id + '-' + suffix : this._id;
var context, id = suffix ? this._id + '-' + suffix : this._id, target, editor = editor;

if (!this._elmCache[id]) {
this._elmCache[id] = $('#' + id)[0];
target = this.settings.target;
if (target === undefined && editor) {
target = editor.targetElm;
}
if (target === undefined) {
throw 'settings.target not specified, might not work under Shadow DOM, add corresponding parameter, please';
}

try {
// If element is under Shadow DOM - set context to it's Shadow Root
if (target && target.matches && target.matches(':host *')) {
(function(target) {
while (target.parentNode) {
target = target.parentNode;
}
// If there is no parent node, but there is `host` property - we've just found Shadow Root,
// this is our new context
if (target.host) {
context = target;
}
})(target);
}
} catch (err) {
// Nothing, even if `.matches` method is present - it doesn't mean that browsers understands ':host *' selector
}

this._elmCache[id] = $('#' + id, context)[0];
}

return this._elmCache[id];
Expand Down Expand Up @@ -697,7 +723,13 @@ define("tinymce/ui/Control", [
* @return {tinymce.ui.Control} Current control instance.
*/
aria: function(name, value) {
var self = this, elm = self.getEl(self.ariaTarget);
var self = this, editor = editor, elm, target;

target = self.settings.target;
if (target === undefined) {
target = editor.targetElm;
}
elm = self.getEl(self.ariaTarget, target);

if (typeof value === "undefined") {
return self._aria[name];
Expand Down
8 changes: 5 additions & 3 deletions js/tinymce/classes/ui/Factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,14 @@ define("tinymce/ui/Factory", [], function() {
namespaceInit = true;
}

settings = settings || {};
// If string is specified then use it as the type
if (typeof type == 'string') {
settings = settings || {};
settings.type = type;
} else {
settings = type;
for (var i in type) {
settings[i] = type[i];
}
type = settings.type;
}

Expand All @@ -102,4 +104,4 @@ define("tinymce/ui/Factory", [], function() {
return ControlType;
}
};
});
});
4 changes: 2 additions & 2 deletions js/tinymce/classes/ui/FloatPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,10 +361,10 @@ define("tinymce/ui/FloatPanel", [
},

postRender: function() {
var self = this;
var self = this, editor = editor;

if (self.settings.bodyRole) {
this.getEl('body').setAttribute('role', self.settings.bodyRole);
this.getEl('body', editor && editor.targetElm).setAttribute('role', self.settings.bodyRole);
}

return self._super();
Expand Down
5 changes: 3 additions & 2 deletions js/tinymce/classes/ui/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ define("tinymce/ui/Form", [
flex: 0,
forId: ctrl._id,
disabled: ctrl.disabled()
}
},
target: self.settings.target
}, self.settings.formItemDefaults));

formItem.type = 'formitem';
Expand Down Expand Up @@ -154,4 +155,4 @@ define("tinymce/ui/Form", [
recalcLabels();
}
});
});
});
2 changes: 1 addition & 1 deletion js/tinymce/classes/ui/MenuButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ define("tinymce/ui/MenuButton", [
}

if (!menu.renderTo) {
self.menu = Factory.create(menu).parent(self).renderTo();
self.menu = Factory.create(menu, {target: self.settings.target}).parent(self).renderTo();
} else {
self.menu = menu.parent(self).show().renderTo();
}
Expand Down
2 changes: 1 addition & 1 deletion js/tinymce/classes/ui/MenuItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ define("tinymce/ui/MenuItem", [
menu.itemDefaults = parent.settings.itemDefaults;
}

menu = self.menu = Factory.create(menu).parent(self).renderTo();
menu = self.menu = Factory.create(menu, {target: self.settings.target}).parent(self).renderTo();
menu.reflow();
menu.on('cancel', function(e) {
e.stopPropagation();
Expand Down
3 changes: 2 additions & 1 deletion js/tinymce/classes/ui/MessageBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ define("tinymce/ui/MessageBox", [
onClose: settings.onClose,
onCancel: function() {
callback(false);
}
},
target: null
}).renderTo(document.body).reflow();
},

Expand Down
3 changes: 2 additions & 1 deletion js/tinymce/classes/ui/PanelButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ define("tinymce/ui/PanelButton", [
panelSettings.popover = true;
panelSettings.autohide = true;
panelSettings.ariaRoot = true;
panelSettings.target = settings.target;

self.panel = new FloatPanel(panelSettings).on('hide', function() {
self.active(false);
Expand Down Expand Up @@ -111,4 +112,4 @@ define("tinymce/ui/PanelButton", [
return this._super();
}
});
});
});
5 changes: 4 additions & 1 deletion js/tinymce/classes/ui/Widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ define("tinymce/ui/Widget", [
*/
tooltip: function() {
if (!tooltip) {
tooltip = new Tooltip({type: 'tooltip'});
tooltip = new Tooltip({
type: 'tooltip',
target: null
});
tooltip.renderTo();
}

Expand Down
5 changes: 3 additions & 2 deletions js/tinymce/classes/ui/Window.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ define("tinymce/ui/Window", [
defaults: {
type: 'button'
},
items: settings.buttons
items: settings.buttons,
target: settings.target
});

self.statusbar.classes.add('foot');
Expand Down Expand Up @@ -472,4 +473,4 @@ define("tinymce/ui/Window", [
handleWindowResize();

return Window;
});
});
Loading