Skip to content
Browse files

If editor doesn't scroll to bottom when user types at end, try later.

R=jparent,carlanton,nicksantos
DELTA=116  (99 added, 1 deleted, 16 changed)


Revision created by MOE tool push_codebase.
MOE_MIGRATION=5790


git-svn-id: http://closure-library.googlecode.com/svn/trunk@2287 0b95b8e8-c90f-11de-9d4f-f947ee5921c8
  • Loading branch information...
1 parent 88756c2 commit 67d86530a67f082301874794600d17fef90097e5 treitel@google.com committed Nov 8, 2012
Showing with 91 additions and 1 deletion.
  1. +6 −1 closure/goog/editor/field.js
  2. +12 −0 closure/goog/editor/seamlessfield.js
  3. +73 −0 closure/goog/editor/seamlessfield_test.js
View
7 closure/goog/editor/field.js
@@ -253,11 +253,16 @@ goog.editor.Field.EventType = {
*/
BLUR: 'blur',
/**
- * Dispach before tab is handled by the field. This is a legacy way
+ * Dispatched before tab is handled by the field. This is a legacy way
* of controlling tab behavior. Use trog.plugins.AbstractTabHandler now.
*/
BEFORETAB: 'beforetab',
/**
+ * Dispatched after the iframe containing the field is resized, so that UI
+ * components which contain it can respond.
+ */
+ IFRAME_RESIZED: 'ifrsz',
+ /**
* Dispatched when the selection changes.
* Use handleSelectionChange from plugin API instead of listening
* directly to this event.
View
12 closure/goog/editor/seamlessfield.js
@@ -174,6 +174,7 @@ goog.editor.SeamlessField.prototype.handleOuterDocChange_ = function() {
*/
goog.editor.SeamlessField.prototype.sizeIframeToBodyHeightGecko_ = function() {
if (this.acquireSizeIframeLockGecko_()) {
+ var resized = false;
var ifr = this.getEditableIframe();
if (ifr) {
var fieldHeight = this.getIframeBodyHeightGecko_();
@@ -183,9 +184,13 @@ goog.editor.SeamlessField.prototype.sizeIframeToBodyHeightGecko_ = function() {
}
if (parseInt(goog.style.getStyle(ifr, 'height'), 10) != fieldHeight) {
ifr.style.height = fieldHeight + 'px';
+ resized = true;
}
}
this.releaseSizeIframeLockGecko_();
+ if (resized) {
+ this.dispatchEvent(goog.editor.Field.EventType.IFRAME_RESIZED);
+ }
}
};
@@ -260,6 +265,7 @@ goog.editor.SeamlessField.prototype.sizeIframeToWrapperGecko_ = function() {
if (this.acquireSizeIframeLockGecko_()) {
var ifr = this.getEditableIframe();
var field = this.getElement();
+ var resized = false;
if (ifr && field) {
var fieldPaddingBox;
var widthDiv = ifr.parentNode;
@@ -270,6 +276,7 @@ goog.editor.SeamlessField.prototype.sizeIframeToWrapperGecko_ = function() {
ifr.style.width = width + 'px';
field.style.width =
width - fieldPaddingBox.left - fieldPaddingBox.right + 'px';
+ resized = true;
}
var height = widthDiv.offsetHeight;
@@ -281,9 +288,14 @@ goog.editor.SeamlessField.prototype.sizeIframeToWrapperGecko_ = function() {
ifr.style.height = height + 'px';
field.style.height =
height - fieldPaddingBox.top - fieldPaddingBox.bottom + 'px';
+ resized = true;
}
+
}
this.releaseSizeIframeLockGecko_();
+ if (resized) {
+ this.dispatchEvent(goog.editor.Field.EventType.IFRAME_RESIZED);
+ }
}
};
View
73 closure/goog/editor/seamlessfield_test.js
@@ -148,6 +148,79 @@ function testIframeHeightGrowsOnWrap() {
}
}
+function testDispatchIframeResizedForWrapperHeight() {
+ if (!goog.editor.BrowserFeature.HAS_CONTENT_EDITABLE) {
+ var clock = new goog.testing.MockClock(true);
+ var blendedField = initSeamlessField('Hi!', {'border': '2px 5px'});
+ var iframe = createSeamlessIframe();
+ blendedField.attachIframe(iframe);
+
+ var resizeCalled = false;
+ goog.events.listenOnce(
+ blendedField,
+ goog.editor.Field.EventType.IFRAME_RESIZED,
+ function() {
+ resizeCalled = true;
+ });
+
+ try {
+ blendedField.makeEditable();
+ blendedField.setHtml(false, 'Content that should wrap after resize.');
+
+ // Ensure that the field was fully loaded and sized before measuring.
+ clock.tick(1);
+
+ assertFalse('Iframe resize must not be dispatched yet', resizeCalled);
+
+ // Resize the field such that the text should wrap.
+ fieldElem.style.width = '200px';
+ blendedField.sizeIframeToWrapperGecko_();
+ assertTrue('Iframe resize must be dispatched for Wrapper', resizeCalled);
+ } finally {
+ blendedField.dispose();
+ clock.dispose();
+ }
+ }
+}
+
+function testDispatchIframeResizedForBodyHeight() {
+ if (!goog.editor.BrowserFeature.HAS_CONTENT_EDITABLE) {
+ var clock = new goog.testing.MockClock(true);
+ var blendedField = initSeamlessField('Hi!', {'border': '2px 5px'});
+ var iframe = createSeamlessIframe();
+ blendedField.attachIframe(iframe);
+
+ var resizeCalled = false;
+ goog.events.listenOnce(
+ blendedField,
+ goog.editor.Field.EventType.IFRAME_RESIZED,
+ function() {
+ resizeCalled = true;
+ });
+
+ try {
+ blendedField.makeEditable();
+ blendedField.setHtml(false, 'Content that should wrap after resize.');
+
+ // Ensure that the field was fully loaded and sized before measuring.
+ clock.tick(1);
+
+ assertFalse('Iframe resize must not be dispatched yet', resizeCalled);
+
+ // Resize the field to a different body height.
+ var bodyHeight = blendedField.getIframeBodyHeightGecko_();
+ blendedField.getIframeBodyHeightGecko_ = function() {
+ return bodyHeight + 1;
+ };
+ blendedField.sizeIframeToBodyHeightGecko_();
+ assertTrue('Iframe resize must be dispatched for Body', resizeCalled);
+ } finally {
+ blendedField.dispose();
+ clock.dispose();
+ }
+ }
+}
+
function testDispatchBlur() {
if (!goog.editor.BrowserFeature.HAS_CONTENT_EDITABLE &&
!goog.editor.BrowserFeature.CLEARS_SELECTION_WHEN_FOCUS_LEAVES) {

0 comments on commit 67d8653

Please sign in to comment.
Something went wrong with that request. Please try again.