[Laszlo-checkins] r14067 - in openlaszlo/trunk: WEB-INF/lps/lfc/kernel/dhtml WEB-INF/lps/lfc/views test/lfc
hqm@openlaszlo.org
hqm at openlaszlo.org
Fri Jun 5 08:34:53 PDT 2009
Author: hqm
Date: 2009-06-05 08:34:49 -0700 (Fri, 05 Jun 2009)
New Revision: 14067
Added:
openlaszlo/trunk/test/lfc/lpp-8200.lzx
Modified:
openlaszlo/trunk/WEB-INF/lps/lfc/kernel/dhtml/LzInputTextSprite.js
openlaszlo/trunk/WEB-INF/lps/lfc/kernel/dhtml/LzKeyboardKernel.js
openlaszlo/trunk/WEB-INF/lps/lfc/kernel/dhtml/LzMouseKernel.js
openlaszlo/trunk/WEB-INF/lps/lfc/kernel/dhtml/LzSprite.js
openlaszlo/trunk/WEB-INF/lps/lfc/kernel/dhtml/LzTextSprite.js
openlaszlo/trunk/WEB-INF/lps/lfc/views/LzText.lzs
Log:
Change 20090605-hqm-Q by hqm at badtzmaru.home on 2009-06-05 11:30:43 EDT
in /Users/hqm/openlaszlo/trunk5
for http://svn.openlaszlo.org/openlaszlo/trunk
Summary: fix for text selection in DHTML
New Features:
Bugs Fixed: LPP-8200
Technical Reviewer: max
QA Reviewer: andre
Doc Reviewer: (pending)
Documentation:
Release Notes:
Details:
+ LzSprite.js: only toggle the focus in focus_on_mouseover quirk when there is some text selected.
+ LzKeyboardKernel.js: Instead of cancelling a mouse event completely,
just cancel bubbling. This lets the div handle the event, and allows
text selection to work, but should disable it from propagating to
global handlers.
+ LzTextSprite.js: use correct CSS properties for toggling selectability, in Safari
+ LzInputTextSprite.js: do not bind the global document.onselectstart handler, that prevents
text selection from working in some browsers
+ LzText.lzs: add the 'onselectable' event, not required for this
patch, but I noticed it was missing when writing a test case
Tests:
+ added lpp-8200.lzx test, try selecting a region in each the text
fields, except for the last (non-selectable) one.
+ text selection should work in DHTML on selectable text or input text, all
browsers
+ tested tabbing behavior of examples/components/component_sampler.lzx?lzt=html&lzr=dhtml
in IE7, FF3(OSX), Safari(OSX). You can tab to all input text elements. This is based on the
original comment from [r2943 | max | 2006-12-06 23:49:36 -0500 (Wed, 06 Dec 2006) ]
Tests: Tabbing to select inputtexts and typing now works for for the
testcase for LPP-3197 and
http://localhost:8080/legals/examples/components/style_example.lzx?lzr=dhtml.
LzKeyboardKernel.js prevents bubbling for tab key events.
LzMouseKernel.js has more safety checking. LzInputTextSprite.js now
implements focusing and blurringi, selection and deselection properly.
LzTextSprite.js and LzInputTextSprite.js now track global UID
properly.
Modified: openlaszlo/trunk/WEB-INF/lps/lfc/kernel/dhtml/LzInputTextSprite.js
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/lfc/kernel/dhtml/LzInputTextSprite.js 2009-06-05 10:30:05 UTC (rev 14066)
+++ openlaszlo/trunk/WEB-INF/lps/lfc/kernel/dhtml/LzInputTextSprite.js 2009-06-05 15:34:49 UTC (rev 14067)
@@ -244,7 +244,11 @@
//Debug.warn('__show', this.owner);
// turn on text selection in IE
// can't use lz.embed.attachEventHandler because we need to cancel events selectively
- document.onselectstart = null;
+ if (lz.embed.browser.isIE) {
+ //this.__LZdiv.onselectstart = null;
+ this.__LZdiv.onselectstart = null;
+ }
+
}
LzInputTextSprite.prototype.__hideIfNotFocused = function(eventname, target) {
@@ -343,7 +347,9 @@
// turn off text selection in IE
// can't use lz.embed.attachEventHandler because we need to cancel events selectively
if (LzInputTextSprite.prototype.__lastshown == null) {
- document.onselectstart = LzTextSprite.prototype.__cancelhandler;
+ if (lz.embed.browser.isIE) {
+ this.__LZdiv.onselectstart = LzTextSprite.prototype.__cancelhandler
+ }
}
}
@@ -1061,7 +1067,3 @@
}
}
-// prevent text selection in IE
-// can't use lz.embed.attachEventHandler because we need to cancel events
-document.onselectstart = LzTextSprite.prototype.__cancelhandler;
-document.ondrag = LzTextSprite.prototype.__cancelhandler;
Modified: openlaszlo/trunk/WEB-INF/lps/lfc/kernel/dhtml/LzKeyboardKernel.js
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/lfc/kernel/dhtml/LzKeyboardKernel.js 2009-06-05 10:30:05 UTC (rev 14066)
+++ openlaszlo/trunk/WEB-INF/lps/lfc/kernel/dhtml/LzKeyboardKernel.js 2009-06-05 15:34:49 UTC (rev 14067)
@@ -58,13 +58,11 @@
if (k == 9) {
//Debug.write('canceling tab');
e.cancelBubble = true;
- e.returnValue = false;
return false;
} else if (LzKeyboardKernel.__cancelKeys && (k == 13 || k == 0 || k == 37 || k == 38 || k == 39 || k == 40) ) {
//Debug.write('canceling key', k, t);
// cancel event bubbling for enter, space(scroll) and arrow keys
e.cancelBubble = true;
- e.returnValue = false;
return false;
}
}
Modified: openlaszlo/trunk/WEB-INF/lps/lfc/kernel/dhtml/LzMouseKernel.js
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/lfc/kernel/dhtml/LzMouseKernel.js 2009-06-05 10:30:05 UTC (rev 14066)
+++ openlaszlo/trunk/WEB-INF/lps/lfc/kernel/dhtml/LzMouseKernel.js 2009-06-05 15:34:49 UTC (rev 14067)
@@ -30,14 +30,10 @@
// send option/shift/ctrl key events
if (window['LzKeyboardKernel'] && LzKeyboardKernel['__updateControlKeys']) {
LzKeyboardKernel.__updateControlKeys(e);
-
- // FIXME: [20090602 anba] this prevents text selection, see LPP-8200
- if (LzKeyboardKernel.__cancelKeys && e.keyCode == 0) {
- e.cancelBubble = true;
- e.returnValue = false;
- }
}
+ // check source.owner of event, see if textfield and selectable, then don't cancel event
+
var lzinputproto = window['LzInputTextSprite'] && LzInputTextSprite.prototype;
if (lzinputproto && lzinputproto.__lastshown != null) {
if (LzSprite.prototype.quirks.fix_ie_clickable) {
Modified: openlaszlo/trunk/WEB-INF/lps/lfc/kernel/dhtml/LzSprite.js
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/lfc/kernel/dhtml/LzSprite.js 2009-06-05 10:30:05 UTC (rev 14066)
+++ openlaszlo/trunk/WEB-INF/lps/lfc/kernel/dhtml/LzSprite.js 2009-06-05 15:34:49 UTC (rev 14067)
@@ -100,7 +100,9 @@
div.mouseisover = false;
div.onmouseover = function(e) {
if (LzSprite.prototype.quirks.focus_on_mouseover) {
- div.focus();
+ if (LzSprite.prototype.getSelectedText() == null) {
+ div.focus();
+ }
}
if (LzInputTextSprite.prototype.__focusedSprite == null) LzKeyboardKernel.setKeyboardControl(true);
LzMouseKernel.setMouseControl(true);
@@ -142,7 +144,11 @@
LzInputTextSprite.prototype.__setglobalclickable(true);
}
if (quirks.focus_on_mouseover) {
- if (LzInputTextSprite.prototype.__lastshown == null) div.focus();
+ if (LzInputTextSprite.prototype.__lastshown == null) {
+ if (LzSprite.prototype.getSelectedText() == null) {
+ div.focus();
+ }
+ }
}
LzKeyboardKernel.setKeyboardControl(true);
LzMouseKernel.setMouseControl(true);
@@ -150,7 +156,11 @@
this.mouseisover = true;
} else {
if (quirks.focus_on_mouseover) {
- if (LzInputTextSprite.prototype.__lastshown == null) div.blur();
+ if (LzInputTextSprite.prototype.__lastshown == null) {
+ if (LzSprite.prototype.getSelectedText() == null) {
+ div.blur();
+ }
+ }
}
LzKeyboardKernel.setKeyboardControl(false);
LzMouseKernel.setMouseControl(false);
@@ -2354,3 +2364,17 @@
}
lz.embed.attachEventHandler(window, 'beforeunload', window, '__cleanUpForIE');
}
+
+// Get any selected text
+LzSprite.prototype.getSelectedText = function () {
+ var txt = '';
+ if (window.getSelection) { // FF/Safari/Opera/Chrome
+ return window.getSelection();
+ } else if (document.selection) { // IE7
+ return document.selection.createRange().text;
+ } else if (document.getSelection) { // others
+ return document.getSelection();
+ } else {
+ return null;
+ }
+}
Modified: openlaszlo/trunk/WEB-INF/lps/lfc/kernel/dhtml/LzTextSprite.js
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/lfc/kernel/dhtml/LzTextSprite.js 2009-06-05 10:30:05 UTC (rev 14066)
+++ openlaszlo/trunk/WEB-INF/lps/lfc/kernel/dhtml/LzTextSprite.js 2009-06-05 15:34:49 UTC (rev 14067)
@@ -540,16 +540,28 @@
LzTextSprite.prototype.setSelectable = function (s) {
this.selectable = s;
//Debug.write('setSelectable', s, this.__LZdiv.style);
+ var browser = lz.embed.browser;
+
if (s) {
- this.__LZdiv.onselectstart = null;
- this.__LZdiv.style['MozUserSelect'] = 'normal';
- this.__LZdiv.style['KHTMLUserSelect'] = 'normal';
- this.__LZdiv.style['UserSelect'] = 'normal';
+ if (browser.isIE) {
+ this.__LZdiv.onselectstart = null;
+ } else if (browser.isFirefox) {
+ this.__LZdiv.style['MozUserSelect'] = 'text';
+ } else if (browser.isSafari) {
+ this.__LZdiv.style['WebkitUserSelect'] = 'text';
+ } else {
+ this.__LZdiv.style['UserSelect'] = 'text';
+ }
} else {
- this.__LZdiv.onselectstart = LzTextSprite.prototype.__cancelhandler;
- this.__LZdiv.style['MozUserSelect'] = 'none';
- this.__LZdiv.style['KHTMLUserSelect'] = 'none';
- this.__LZdiv.style['UserSelect'] = 'none';
+ if (browser.isIE) {
+ this.__LZdiv.onselectstart = LzTextSprite.prototype.__cancelhandler;
+ } else if (browser.isFirefox) {
+ this.__LZdiv.style['MozUserSelect'] = 'none';
+ } else if (browser.isSafari) {
+ this.__LZdiv.style['WebkitUserSelect'] = 'none';
+ } else {
+ this.__LZdiv.style['UserSelect'] = 'none';
+ }
}
}
Modified: openlaszlo/trunk/WEB-INF/lps/lfc/views/LzText.lzs
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/lfc/views/LzText.lzs 2009-06-05 10:30:05 UTC (rev 14066)
+++ openlaszlo/trunk/WEB-INF/lps/lfc/views/LzText.lzs 2009-06-05 15:34:49 UTC (rev 14067)
@@ -142,10 +142,15 @@
* @type Boolean
*/
var selectable = false;
+
+ /** @lzxtype event */
+ var onselectable:LzDeclaredEventClass = LzDeclaredEvent;
+
/** @access private */
function $lzc$set_selectable(isSel) {
this.selectable = isSel;
this.tsprite.setSelectable(isSel);
+ if (this.onselectable.ready) this.onselectable.sendEvent(isSel);
}
/*
Added: openlaszlo/trunk/test/lfc/lpp-8200.lzx
Property changes on: openlaszlo/trunk/test/lfc/lpp-8200.lzx
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
More information about the Laszlo-checkins
mailing list