From 36a201f22f66989bf7a78ce8afce1ee64aaa0a22 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Wed, 6 Mar 2013 14:55:15 +0200 Subject: Fixed focus and tab index handling for UI (#11129) Change-Id: I80377792ade11946337e2900a7ea84209ae1d060 --- .../client/ui/AbstractComponentConnector.java | 13 ++- client/src/com/vaadin/client/ui/FocusUtil.java | 94 ++++++++++++++++++++++ client/src/com/vaadin/client/ui/VUI.java | 25 +++++- .../src/com/vaadin/client/ui/ui/UIConnector.java | 8 +- 4 files changed, 130 insertions(+), 10 deletions(-) create mode 100644 client/src/com/vaadin/client/ui/FocusUtil.java (limited to 'client') diff --git a/client/src/com/vaadin/client/ui/AbstractComponentConnector.java b/client/src/com/vaadin/client/ui/AbstractComponentConnector.java index 694db6f02c..74cb85c297 100644 --- a/client/src/com/vaadin/client/ui/AbstractComponentConnector.java +++ b/client/src/com/vaadin/client/ui/AbstractComponentConnector.java @@ -137,10 +137,15 @@ public abstract class AbstractComponentConnector extends AbstractConnector * implementation). */ Profiler.enter("AbstractComponentConnector.onStateChanged update tab index"); - if (getState() instanceof TabIndexState - && getWidget() instanceof Focusable) { - ((Focusable) getWidget()) - .setTabIndex(((TabIndexState) getState()).tabIndex); + if (getState() instanceof TabIndexState) { + if (getWidget() instanceof Focusable) { + ((Focusable) getWidget()) + .setTabIndex(((TabIndexState) getState()).tabIndex); + } else { + VConsole.error("Tab index received for " + + Util.getSimpleName(getWidget()) + + " which does not implement Focusable"); + } } Profiler.leave("AbstractComponentConnector.onStateChanged update tab index"); diff --git a/client/src/com/vaadin/client/ui/FocusUtil.java b/client/src/com/vaadin/client/ui/FocusUtil.java new file mode 100644 index 0000000000..7c0fea5f6d --- /dev/null +++ b/client/src/com/vaadin/client/ui/FocusUtil.java @@ -0,0 +1,94 @@ +/* + * Copyright 2000-2013 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.client.ui; + +import com.google.gwt.user.client.ui.Focusable; +import com.google.gwt.user.client.ui.Widget; + +/** + * A helper class used to make it easier for {@link Widget}s to implement + * {@link Focusable}. + * + * @author Vaadin Ltd + * @version @VERSION@ + * @since 7.0.3 + * + */ +public class FocusUtil { + + /** + * Sets the access key property + * + * @param focusable + * The widget for which we want to set the access key. + * @param key + * The access key to set + */ + public static void setAccessKey(Widget focusable, char key) { + assert (focusable != null && focusable.getElement() != null) : "Can't setAccessKey for a widget without an element"; + focusable.getElement().setPropertyString("accessKey", "" + key); + } + + /** + * Explicitly focus/unfocus the given widget. Only one widget can have focus + * at a time, and the widget that does will receive all keyboard events. + * + * @param focusable + * the widget to focus/unfocus + * @param focused + * whether this widget should take focus or release it + */ + public static void setFocus(Widget focusable, boolean focus) { + assert (focusable != null && focusable.getElement() != null) : "Can't setFocus for a widget without an element"; + + if (focus) { + focusable.getElement().focus(); + } else { + focusable.getElement().blur(); + } + } + + /** + * Sets the widget's position in the tab index. If more than one widget has + * the same tab index, each such widget will receive focus in an arbitrary + * order. Setting the tab index to -1 will cause the widget to + * be removed from the tab order. + * + * @param focusable + * The widget + * @param tabIndex + * the widget's tab index + */ + public static void setTabIndex(Widget focusable, int tabIndex) { + assert (focusable != null && focusable.getElement() != null) : "Can't setTabIndex for a widget without an element"; + + focusable.getElement().setTabIndex(tabIndex); + } + + /** + * Gets the widget's position in the tab index. + * + * @param focusable + * The widget + * + * @return the widget's tab index + */ + public static int getTabIndex(Widget focusable) { + assert (focusable != null && focusable.getElement() != null) : "Can't getTabIndex for a widget without an element"; + + return focusable.getElement().getTabIndex(); + } +} diff --git a/client/src/com/vaadin/client/ui/VUI.java b/client/src/com/vaadin/client/ui/VUI.java index b627d4a2a9..b07593896f 100644 --- a/client/src/com/vaadin/client/ui/VUI.java +++ b/client/src/com/vaadin/client/ui/VUI.java @@ -53,7 +53,8 @@ import com.vaadin.shared.ui.ui.UIConstants; */ public class VUI extends SimplePanel implements ResizeHandler, Window.ClosingHandler, ShortcutActionHandlerOwner, Focusable, - HasResizeHandlers, HasScrollHandlers { + com.google.gwt.user.client.ui.Focusable, HasResizeHandlers, + HasScrollHandlers { private static int MONITOR_PARENT_TIMER_INTERVAL = 1000; @@ -437,7 +438,7 @@ public class VUI extends SimplePanel implements ResizeHandler, @Override public void focus() { - getElement().focus(); + setFocus(true); } /** @@ -462,4 +463,24 @@ public class VUI extends SimplePanel implements ResizeHandler, return addHandler(scrollHandler, ScrollEvent.getType()); } + @Override + public int getTabIndex() { + return FocusUtil.getTabIndex(this); + } + + @Override + public void setAccessKey(char key) { + FocusUtil.setAccessKey(this, key); + } + + @Override + public void setFocus(boolean focused) { + FocusUtil.setFocus(this, focused); + } + + @Override + public void setTabIndex(int index) { + FocusUtil.setTabIndex(this, index); + } + } diff --git a/client/src/com/vaadin/client/ui/ui/UIConnector.java b/client/src/com/vaadin/client/ui/ui/UIConnector.java index 0fb7439587..ac441fc625 100644 --- a/client/src/com/vaadin/client/ui/ui/UIConnector.java +++ b/client/src/com/vaadin/client/ui/ui/UIConnector.java @@ -329,10 +329,6 @@ public class UIConnector extends AbstractSingleComponentContainerConnector DOM.sinkEvents(getWidget().getElement(), Event.ONKEYDOWN | Event.ONSCROLL); - // iview is focused when created so element needs tabIndex - // 1 due 0 is at the end of natural tabbing order - DOM.setElementProperty(getWidget().getElement(), "tabIndex", "1"); - RootPanel root = RootPanel.get(rootPanelId); // Remove the v-app-loading or any splash screen added inside the div by @@ -347,6 +343,10 @@ public class UIConnector extends AbstractSingleComponentContainerConnector root.add(getWidget()); + // Set default tab index before focus call. State change handler + // will update this later if needed. + getWidget().setTabIndex(1); + if (applicationConnection.getConfiguration().isStandalone()) { // set focus to iview element by default to listen possible keyboard // shortcuts. For embedded applications this is unacceptable as we -- cgit v1.2.3 From 9748ed6932022abfc044913eb706d11c0a2dfec5 Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Tue, 12 Mar 2013 15:52:21 +0200 Subject: Fixed IE8 sub window focus issue after editing a RichTextArea #10776 Tests were merged to 7.0 in a previous commit. svn changeset:25458/svn branch:6.8 Change-Id: Ib4233f4d96311c76c104f1041f132377d357916d --- client/src/com/vaadin/client/ui/VWindow.java | 34 ++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'client') diff --git a/client/src/com/vaadin/client/ui/VWindow.java b/client/src/com/vaadin/client/ui/VWindow.java index bd9493c761..fd2a701334 100644 --- a/client/src/com/vaadin/client/ui/VWindow.java +++ b/client/src/com/vaadin/client/ui/VWindow.java @@ -22,6 +22,9 @@ import java.util.Comparator; import com.google.gwt.core.client.Scheduler; import com.google.gwt.core.client.Scheduler.ScheduledCommand; +import com.google.gwt.dom.client.Style; +import com.google.gwt.dom.client.Style.Position; +import com.google.gwt.dom.client.Style.Unit; import com.google.gwt.event.dom.client.BlurEvent; import com.google.gwt.event.dom.client.BlurHandler; import com.google.gwt.event.dom.client.FocusEvent; @@ -35,6 +38,7 @@ import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.Element; import com.google.gwt.user.client.Event; import com.google.gwt.user.client.Window; +import com.google.gwt.user.client.ui.RootPanel; import com.google.gwt.user.client.ui.Widget; import com.vaadin.client.ApplicationConnection; import com.vaadin.client.BrowserInfo; @@ -423,6 +427,36 @@ public class VWindow extends VOverlay implements ShortcutActionHandlerOwner, // Remove window from windowOrder to avoid references being left // hanging. windowOrder.remove(this); + + /* + * If the window has a RichTextArea and the RTA is focused at the time + * of hiding in IE8 only the window will have some problems returning + * the focus to the correct place. Curiously the focus will be returned + * correctly if clicking on the "close" button in the window header but + * closing the window from a button for example in the window will fail. + * Symptom described in #10776 + * + * The problematic part is that for the focus to be returned correctly + * an input element needs to be focused in the root panel. Focusing some + * other element apparently won't work. + */ + if (BrowserInfo.get().isIE8()) { + fixIE8FocusCaptureIssue(); + } + } + + private void fixIE8FocusCaptureIssue() { + Element e = DOM.createInputText(); + Style elemStyle = e.getStyle(); + elemStyle.setPosition(Position.ABSOLUTE); + elemStyle.setLeft(-10, Unit.PX); + elemStyle.setWidth(0, Unit.PX); + elemStyle.setHeight(0, Unit.PX); + + Element rootPanel = RootPanel.getBodyElement(); + rootPanel.appendChild(e); + e.focus(); + rootPanel.removeChild(e); } /** For internal use only. May be removed or replaced in the future. */ -- cgit v1.2.3 From 0d75be99df6075f86ceb48ef4e430411cf47a854 Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Tue, 12 Mar 2013 18:44:16 +0200 Subject: Ensure nonwrapping textarea has white-space: pre; style (#10536) Change-Id: Iaac6b58d204082374827cb7b6caef5f5f81e3dbc --- client/src/com/vaadin/client/ui/VTextArea.java | 3 +++ 1 file changed, 3 insertions(+) (limited to 'client') diff --git a/client/src/com/vaadin/client/ui/VTextArea.java b/client/src/com/vaadin/client/ui/VTextArea.java index 6e93a076d9..139cd87ca4 100644 --- a/client/src/com/vaadin/client/ui/VTextArea.java +++ b/client/src/com/vaadin/client/ui/VTextArea.java @@ -18,6 +18,7 @@ package com.vaadin.client.ui; import com.google.gwt.core.client.Scheduler; import com.google.gwt.dom.client.Style.Overflow; +import com.google.gwt.dom.client.Style.WhiteSpace; import com.google.gwt.dom.client.TextAreaElement; import com.google.gwt.event.dom.client.ChangeEvent; import com.google.gwt.event.dom.client.ChangeHandler; @@ -154,9 +155,11 @@ public class VTextArea extends VTextField { if (wordwrap) { getElement().removeAttribute("wrap"); getElement().getStyle().clearOverflow(); + getElement().getStyle().clearWhiteSpace(); } else { getElement().setAttribute("wrap", "off"); getElement().getStyle().setOverflow(Overflow.AUTO); + getElement().getStyle().setWhiteSpace(WhiteSpace.PRE); } if (BrowserInfo.get().isOpera()) { // Opera fails to dynamically update the wrap attribute so we detach -- cgit v1.2.3 From 371259c75868469b4c16a16bef29299f4664cc26 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Wed, 13 Mar 2013 09:11:19 +0200 Subject: Fixed header to make checkstyles happy (#11129) Change-Id: I4f1da57d318407da6a47a7095dbe4a08a6acc0f7 --- client/src/com/vaadin/client/ui/FocusUtil.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'client') diff --git a/client/src/com/vaadin/client/ui/FocusUtil.java b/client/src/com/vaadin/client/ui/FocusUtil.java index 7c0fea5f6d..8de3f767bd 100644 --- a/client/src/com/vaadin/client/ui/FocusUtil.java +++ b/client/src/com/vaadin/client/ui/FocusUtil.java @@ -1,12 +1,12 @@ /* * Copyright 2000-2013 Vaadin Ltd. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -- cgit v1.2.3 From 6b83d70033b95ea573b2f20b3fadfcd3c21f7621 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Wed, 13 Mar 2013 10:35:03 +0200 Subject: Fixed Tree keyboard navigation in Opera 12 (#11183) Change-Id: I6bbd486caef0056703d1b9ebc1ba5537aca75cfd --- client/src/com/vaadin/client/ui/VTree.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'client') diff --git a/client/src/com/vaadin/client/ui/VTree.java b/client/src/com/vaadin/client/ui/VTree.java index 809ed9c82d..624dce4f13 100644 --- a/client/src/com/vaadin/client/ui/VTree.java +++ b/client/src/com/vaadin/client/ui/VTree.java @@ -189,7 +189,7 @@ public class VTree extends FocusElementPanel implements VHasDropHandler, * handler, other browsers handle it correctly when using a key down * handler */ - if (BrowserInfo.get().isGecko() || BrowserInfo.get().isOpera()) { + if (BrowserInfo.get().isGecko()) { addKeyPressHandler(this); } else { addKeyDownHandler(this); -- cgit v1.2.3 From 749fd7085ec2db6af0b4f401378b2694be3626c7 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Wed, 13 Mar 2013 13:50:44 +0200 Subject: Added missing state update on the client side (#11028) Change-Id: I547f6e6426208d788b92ea8f429d4bb0aa9fdf24 --- client/src/com/vaadin/client/ui/checkbox/CheckBoxConnector.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'client') diff --git a/client/src/com/vaadin/client/ui/checkbox/CheckBoxConnector.java b/client/src/com/vaadin/client/ui/checkbox/CheckBoxConnector.java index 014ea849a2..772419e730 100644 --- a/client/src/com/vaadin/client/ui/checkbox/CheckBoxConnector.java +++ b/client/src/com/vaadin/client/ui/checkbox/CheckBoxConnector.java @@ -143,11 +143,13 @@ public class CheckBoxConnector extends AbstractFieldConnector implements return; } + getState().checked = getWidget().getValue(); + // Add mouse details MouseEventDetails details = MouseEventDetailsBuilder .buildMouseEventDetails(event.getNativeEvent(), getWidget() .getElement()); - getRpcProxy(CheckBoxServerRpc.class).setChecked(getWidget().getValue(), + getRpcProxy(CheckBoxServerRpc.class).setChecked(getState().checked, details); } -- cgit v1.2.3 From d2d4279e9946f9b193c0b706ecad9e01a5bf77c3 Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Wed, 13 Mar 2013 09:50:41 +0200 Subject: Fixed setting column width back to undefined by setting it to -1. #7922 svn changeset:25591/svn branch:6.8 Conflicts: server/src/com/vaadin/ui/Table.java Reverted change included by mistake in changeset [25591] for #7922 svn changeset:25606/svn branch:6.8 Change-Id: I6765a52ab213c131cca053227ee72b0007552f7f --- client/src/com/vaadin/client/ui/VScrollTable.java | 24 +++++-- server/src/com/vaadin/ui/Table.java | 71 ++++++++++++------ .../table/TableColumnWidthsAndExpandRatios.html | 83 ++++++++++++++++++++++ .../table/TableColumnWidthsAndExpandRatios.java | 57 +++++++++++++++ 4 files changed, 208 insertions(+), 27 deletions(-) create mode 100644 uitest/src/com/vaadin/tests/components/table/TableColumnWidthsAndExpandRatios.html create mode 100644 uitest/src/com/vaadin/tests/components/table/TableColumnWidthsAndExpandRatios.java (limited to 'client') diff --git a/client/src/com/vaadin/client/ui/VScrollTable.java b/client/src/com/vaadin/client/ui/VScrollTable.java index 6f9fd6da88..4d61fba429 100644 --- a/client/src/com/vaadin/client/ui/VScrollTable.java +++ b/client/src/com/vaadin/client/ui/VScrollTable.java @@ -3056,7 +3056,7 @@ public class VScrollTable extends FlowPanel implements HasWidgets, .hasNext(); columnIndex++) { if (it.next() == this) { break; - } + } } } final int cw = scrollBody.getColWidth(columnIndex); @@ -3266,10 +3266,9 @@ public class VScrollTable extends FlowPanel implements HasWidgets, } if (col.hasAttribute("width")) { - final String widthStr = col.getStringAttribute("width"); // Make sure to accomodate for the sort indicator if // necessary. - int width = Integer.parseInt(widthStr); + int width = col.getIntAttribute("width"); int widthWithoutAddedIndent = width; // get min width with indent, no padding @@ -3301,12 +3300,25 @@ public class VScrollTable extends FlowPanel implements HasWidgets, // save min width without indent c.setWidth(widthWithoutAddedIndent, true); } + } else if (col.hasAttribute("er")) { + c.setExpandRatio(col.getFloatAttribute("er")); + } else if (recalcWidths) { c.setUndefinedWidth(); + + } else { + boolean hadExpandRatio = c.getExpandRatio() > 0; + boolean hadDefinedWidth = c.isDefinedWidth(); + if (hadExpandRatio || hadDefinedWidth) { + // Someone has removed a expand width or the defined + // width on the server side (setting it to -1), make the + // column undefined again and measure columns again. + c.setUndefinedWidth(); + c.setExpandRatio(0); + refreshContentWidths = true; + } } - if (col.hasAttribute("er")) { - c.setExpandRatio(col.getFloatAttribute("er")); - } + if (col.hasAttribute("collapsed")) { // ensure header is properly removed from parent (case when // collapsing happens via servers side api) diff --git a/server/src/com/vaadin/ui/Table.java b/server/src/com/vaadin/ui/Table.java index 641c0ff1f6..3d7cb42050 100644 --- a/server/src/com/vaadin/ui/Table.java +++ b/server/src/com/vaadin/ui/Table.java @@ -396,10 +396,14 @@ public class Table extends AbstractSelect implements Action.Container, private HashMap columnAlignments = new HashMap(); /** - * Holds column widths in pixels (Integer) or expand ratios (Float) for - * visible columns (by propertyId). + * Holds column widths in pixels for visible columns (by propertyId). */ - private final HashMap columnWidths = new HashMap(); + private final HashMap columnWidths = new HashMap(); + + /** + * Holds column expand rations for visible columns (by propertyId). + */ + private final HashMap columnExpandRatios = new HashMap(); /** * Holds column generators @@ -886,10 +890,14 @@ public class Table extends AbstractSelect implements Action.Container, // id to store the width of the row header. propertyId = ROW_HEADER_FAKE_PROPERTY_ID; } + + // Setting column width should remove any expand ratios as well + columnExpandRatios.remove(propertyId); + if (width < 0) { columnWidths.remove(propertyId); } else { - columnWidths.put(propertyId, Integer.valueOf(width)); + columnWidths.put(propertyId, width); } markAsDirty(); } @@ -930,21 +938,39 @@ public class Table extends AbstractSelect implements Action.Container, * the expandRatio used to divide excess space for this column */ public void setColumnExpandRatio(Object propertyId, float expandRatio) { + if (propertyId == null) { + // Since propertyId is null, this is the row header. Use the magic + // id to store the width of the row header. + propertyId = ROW_HEADER_FAKE_PROPERTY_ID; + } + + // Setting the column expand ratio should remove and defined column + // width + columnWidths.remove(propertyId); + if (expandRatio < 0) { - columnWidths.remove(propertyId); + columnExpandRatios.remove(propertyId); } else { - columnWidths.put(propertyId, new Float(expandRatio)); + columnExpandRatios.put(propertyId, expandRatio); } + + requestRepaint(); } + /** + * Gets the column expand ratio for a columnd. See + * {@link #setColumnExpandRatio(Object, float)} + * + * @param propertyId + * columns property id + * @return the expandRatio used to divide excess space for this column + */ public float getColumnExpandRatio(Object propertyId) { - final Object width = columnWidths.get(propertyId); - if (width == null || !(width instanceof Float)) { + final Float width = columnExpandRatios.get(propertyId); + if (width == null) { return -1; } - final Float value = (Float) width; - return value.floatValue(); - + return width.floatValue(); } /** @@ -959,12 +985,11 @@ public class Table extends AbstractSelect implements Action.Container, // id to retrieve the width of the row header. propertyId = ROW_HEADER_FAKE_PROPERTY_ID; } - final Object width = columnWidths.get(propertyId); - if (width == null || !(width instanceof Integer)) { + final Integer width = columnWidths.get(propertyId); + if (width == null) { return -1; } - final Integer value = (Integer) width; - return value.intValue(); + return width.intValue(); } /** @@ -3434,6 +3459,7 @@ public class Table extends AbstractSelect implements Action.Container, target.startTag("column"); target.addAttribute("cid", ROW_HEADER_COLUMN_KEY); paintColumnWidth(target, ROW_HEADER_FAKE_PROPERTY_ID); + paintColumnExpandRatio(target, ROW_HEADER_FAKE_PROPERTY_ID); target.endTag("column"); } final Collection sortables = getSortableContainerPropertyIds(); @@ -3461,6 +3487,7 @@ public class Table extends AbstractSelect implements Action.Container, .toString()); } paintColumnWidth(target, colId); + paintColumnExpandRatio(target, colId); target.endTag("column"); } } @@ -3706,12 +3733,14 @@ public class Table extends AbstractSelect implements Action.Container, private void paintColumnWidth(PaintTarget target, final Object columnId) throws PaintException { if (columnWidths.containsKey(columnId)) { - if (getColumnWidth(columnId) > -1) { - target.addAttribute("width", - String.valueOf(getColumnWidth(columnId))); - } else { - target.addAttribute("er", getColumnExpandRatio(columnId)); - } + target.addAttribute("width", getColumnWidth(columnId)); + } + } + + private void paintColumnExpandRatio(PaintTarget target, + final Object columnId) throws PaintException { + if (columnExpandRatios.containsKey(columnId)) { + target.addAttribute("er", getColumnExpandRatio(columnId)); } } diff --git a/uitest/src/com/vaadin/tests/components/table/TableColumnWidthsAndExpandRatios.html b/uitest/src/com/vaadin/tests/components/table/TableColumnWidthsAndExpandRatios.html new file mode 100644 index 0000000000..75d98ce2e6 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/table/TableColumnWidthsAndExpandRatios.html @@ -0,0 +1,83 @@ + + + + + + +New Test + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
New Test
open/run/com.vaadin.tests.components.table.TableColumnWidthsAndExpandRatios?restartApplication
screenCaptureinitial-all-columns-undefined
dragAndDropvaadin=runcomvaadintestscomponentstableTableColumnWidthsAndExpandRatios::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VScrollTable[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]-300,0
dragAndDropvaadin=runcomvaadintestscomponentstableTableColumnWidthsAndExpandRatios::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VScrollTable[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[1]/domChild[0]-300,0
dragAndDropvaadin=runcomvaadintestscomponentstableTableColumnWidthsAndExpandRatios::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VScrollTable[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[2]/domChild[0]-300,0
screenCapturecolumns-defined-width
mouseClickvaadin=runcomvaadintestscomponentstableTableColumnWidthsAndExpandRatios::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VHorizontalLayout[0]/ChildComponentContainer[0]/VNativeButton[0]114,4
screenCapturecolumn1-undefined
mouseClickvaadin=runcomvaadintestscomponentstableTableColumnWidthsAndExpandRatios::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VHorizontalLayout[0]/ChildComponentContainer[1]/VNativeButton[0]98,13
screenCapturecolumn2-undefined
mouseClickvaadin=runcomvaadintestscomponentstableTableColumnWidthsAndExpandRatios::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VHorizontalLayout[0]/ChildComponentContainer[2]/VNativeButton[0]40,10
screenCapturecolumns-undefined-width
+ + diff --git a/uitest/src/com/vaadin/tests/components/table/TableColumnWidthsAndExpandRatios.java b/uitest/src/com/vaadin/tests/components/table/TableColumnWidthsAndExpandRatios.java new file mode 100644 index 0000000000..747c99468f --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/table/TableColumnWidthsAndExpandRatios.java @@ -0,0 +1,57 @@ +package com.vaadin.tests.components.table; + +import com.vaadin.tests.components.TestBase; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.HorizontalLayout; +import com.vaadin.ui.NativeButton; +import com.vaadin.ui.Table; + +public class TableColumnWidthsAndExpandRatios extends TestBase { + + @Override + protected void setup() { + getLayout().setSizeFull(); + + final Table table = new Table(); + table.setSizeFull(); + + table.addContainerProperty("column1", String.class, "Humpty"); + table.addContainerProperty("column2", String.class, "Dumpty"); + table.addContainerProperty("column3", String.class, "Doe"); + + for (int row = 0; row < 100; row++) { + table.addItem(); + } + + HorizontalLayout buttons = new HorizontalLayout(); + for (Object col : table.getContainerPropertyIds()) { + buttons.addComponent(createResetButton(col, table)); + } + + addComponent(table); + addComponent(buttons); + } + + private NativeButton createResetButton(final Object property, + final Table table) { + return new NativeButton("Reset " + property + " width", + new Button.ClickListener() { + + public void buttonClick(ClickEvent event) { + table.setColumnWidth(property, -1); + } + }); + } + + @Override + protected String getDescription() { + return "Changing column width to -1 should remove any previous size measurements"; + } + + @Override + protected Integer getTicketNumber() { + return 7922; + } + +} -- cgit v1.2.3 From 468438fc0ff41c299e2e015f569f96fbd5e09411 Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Thu, 14 Mar 2013 16:31:06 +0200 Subject: Reattach when wrapping in webkit for correct text flow (#10536) Change-Id: I431b6a3c61a9308ad4189e5d79a5e70de8f1f560 --- client/src/com/vaadin/client/ui/VTextArea.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'client') diff --git a/client/src/com/vaadin/client/ui/VTextArea.java b/client/src/com/vaadin/client/ui/VTextArea.java index 139cd87ca4..4a5de23828 100644 --- a/client/src/com/vaadin/client/ui/VTextArea.java +++ b/client/src/com/vaadin/client/ui/VTextArea.java @@ -161,9 +161,12 @@ public class VTextArea extends VTextField { getElement().getStyle().setOverflow(Overflow.AUTO); getElement().getStyle().setWhiteSpace(WhiteSpace.PRE); } - if (BrowserInfo.get().isOpera()) { + if (BrowserInfo.get().isOpera() + || (BrowserInfo.get().isWebkit() && wordwrap)) { // Opera fails to dynamically update the wrap attribute so we detach // and reattach the whole TextArea. + // Webkit fails to properly reflow the text when enabling wrapping, + // same workaround Util.detachAttach(getElement()); } this.wordwrap = wordwrap; -- cgit v1.2.3 From f7b9f9f9afe8b09571d05f1790c9fe0c68a363a9 Mon Sep 17 00:00:00 2001 From: Marc Englund Date: Thu, 14 Mar 2013 14:21:53 +0200 Subject: Audio/Video fixes, for #11160 but it was much more broken. Also quite a few browser differences. Ticket: 11160 Change-Id: I1ee228e593eab75d96c285bfa26af9939e058d47 --- .../com/vaadin/client/ui/MediaBaseConnector.java | 25 ++++-- client/src/com/vaadin/client/ui/VMediaBase.java | 26 ++++++- .../com/vaadin/client/ui/audio/AudioConnector.java | 48 ++++++++---- .../vaadin/tests/components/media/AudioTest.html | 66 ++++++++++++++++ .../vaadin/tests/components/media/AudioTest.java | 86 +++++++++++++++++++++ .../src/com/vaadin/tests/components/media/bip.mp3 | Bin 0 -> 13837 bytes .../src/com/vaadin/tests/components/media/bip.ogg | Bin 0 -> 15137 bytes .../tests/components/media/toyphone_dialling.mp3 | Bin 0 -> 80083 bytes .../tests/components/media/toyphone_dialling.ogg | Bin 0 -> 77861 bytes 9 files changed, 225 insertions(+), 26 deletions(-) create mode 100644 uitest/src/com/vaadin/tests/components/media/AudioTest.html create mode 100644 uitest/src/com/vaadin/tests/components/media/AudioTest.java create mode 100644 uitest/src/com/vaadin/tests/components/media/bip.mp3 create mode 100644 uitest/src/com/vaadin/tests/components/media/bip.ogg create mode 100644 uitest/src/com/vaadin/tests/components/media/toyphone_dialling.mp3 create mode 100644 uitest/src/com/vaadin/tests/components/media/toyphone_dialling.ogg (limited to 'client') diff --git a/client/src/com/vaadin/client/ui/MediaBaseConnector.java b/client/src/com/vaadin/client/ui/MediaBaseConnector.java index 6824caff78..8614977be1 100644 --- a/client/src/com/vaadin/client/ui/MediaBaseConnector.java +++ b/client/src/com/vaadin/client/ui/MediaBaseConnector.java @@ -46,15 +46,26 @@ public abstract class MediaBaseConnector extends AbstractComponentConnector { } @Override - public void onStateChanged(StateChangeEvent stateChangeEvent) { - super.onStateChanged(stateChangeEvent); + public void onStateChanged(StateChangeEvent event) { + super.onStateChanged(event); - for (int i = 0; i < getState().sources.size(); i++) { - URLReference source = getState().sources.get(i); - String sourceType = getState().sourceTypes.get(i); - getWidget().addSource(source.getURL(), sourceType); + final VMediaBase widget = getWidget(); + final AbstractMediaState state = getState(); + + setAltText(state.altText); // must do before loading sources + widget.setAutoplay(state.autoplay); + widget.setMuted(state.muted); + widget.setControls(state.showControls); + + if (event.hasPropertyChanged("sources")) { + widget.removeAllSources(); + for (int i = 0; i < state.sources.size(); i++) { + URLReference source = state.sources.get(i); + String sourceType = state.sourceTypes.get(i); + widget.addSource(source.getURL(), sourceType); + } + widget.load(); } - setAltText(getState().altText); } @Override diff --git a/client/src/com/vaadin/client/ui/VMediaBase.java b/client/src/com/vaadin/client/ui/VMediaBase.java index 8d40775c8d..b77e8bb161 100644 --- a/client/src/com/vaadin/client/ui/VMediaBase.java +++ b/client/src/com/vaadin/client/ui/VMediaBase.java @@ -18,12 +18,16 @@ package com.vaadin.client.ui; import com.google.gwt.dom.client.Document; import com.google.gwt.dom.client.MediaElement; +import com.google.gwt.dom.client.NodeList; +import com.google.gwt.dom.client.SourceElement; +import com.google.gwt.dom.client.Text; import com.google.gwt.user.client.Element; import com.google.gwt.user.client.ui.Widget; public abstract class VMediaBase extends Widget { private MediaElement media; + private Text altText; /** * Sets the MediaElement that is to receive all commands and properties. @@ -44,7 +48,12 @@ public abstract class VMediaBase extends Widget { } public void setAltText(String alt) { - media.appendChild(Document.get().createTextNode(alt)); + if (altText == null) { + altText = Document.get().createTextNode(alt); + media.appendChild(altText); + } else { + altText.setNodeValue(alt); + } } public void setControls(boolean shouldShowControls) { @@ -59,8 +68,21 @@ public abstract class VMediaBase extends Widget { media.setMuted(mediaMuted); } + public void removeAllSources() { + NodeList l = media + .getElementsByTagName(SourceElement.TAG); + for (int i = l.getLength() - 1; i >= 0; i--) { + media.removeChild(l.getItem(i)); + } + + } + + public void load() { + media.load(); + } + public void addSource(String sourceUrl, String sourceType) { - Element src = Document.get().createElement("source").cast(); + Element src = Document.get().createElement(SourceElement.TAG).cast(); src.setAttribute("src", sourceUrl); src.setAttribute("type", sourceType); media.appendChild(src); diff --git a/client/src/com/vaadin/client/ui/audio/AudioConnector.java b/client/src/com/vaadin/client/ui/audio/AudioConnector.java index c7d20ef585..5a90cab09d 100644 --- a/client/src/com/vaadin/client/ui/audio/AudioConnector.java +++ b/client/src/com/vaadin/client/ui/audio/AudioConnector.java @@ -29,23 +29,6 @@ import com.vaadin.ui.Audio; @Connect(Audio.class) public class AudioConnector extends MediaBaseConnector { - @Override - public void onStateChanged(StateChangeEvent stateChangeEvent) { - super.onStateChanged(stateChangeEvent); - - Style style = getWidget().getElement().getStyle(); - - // Make sure that the controls are not clipped if visible. - if (getState().showControls - && (style.getHeight() == null || "".equals(style.getHeight()))) { - if (BrowserInfo.get().isChrome()) { - style.setHeight(32, Unit.PX); - } else { - style.setHeight(25, Unit.PX); - } - } - } - @Override protected Widget createWidget() { return GWT.create(VAudio.class); @@ -55,4 +38,35 @@ public class AudioConnector extends MediaBaseConnector { protected String getDefaultAltHtml() { return "Your browser does not support the audio element."; } + + @Override + public void onStateChanged(StateChangeEvent stateChangeEvent) { + super.onStateChanged(stateChangeEvent); + + // Opera (12.14) has a bug where an audio element w/o controls is shown + // as 150x300px, which is not usually desired. However, in order to show + // the error/alt message, we only do this in the exact situation. + if (BrowserInfo.get().isOpera() + && stateChangeEvent.hasPropertyChanged("showControls")) { + Style style = getWidget().getElement().getStyle(); + if (!getState().showControls) { + if (isUndefinedHeight() && isUndefinedWidth() + && getWidget().getOffsetHeight() == 150 + && getWidget().getOffsetWidth() == 300) { + // only if no size set and 150x300 + style.setWidth(0, Unit.PX); + style.setHeight(0, Unit.PX); + } + } else { + // clear sizes if it's supposed to be undefined + if (isUndefinedHeight()) { + style.clearHeight(); + } + if (isUndefinedWidth()) { + style.clearWidth(); + } + } + } + } + } diff --git a/uitest/src/com/vaadin/tests/components/media/AudioTest.html b/uitest/src/com/vaadin/tests/components/media/AudioTest.html new file mode 100644 index 0000000000..8425cad38a --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/media/AudioTest.html @@ -0,0 +1,66 @@ + + + + + + +AudioTest + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
AudioTest
open/run/AudioTest?restartApplication
pause3000
screenCaptureshortAtEndUnmuted
mouseClickvaadin=runAudioTest::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[2]/VCheckBox[0]/domChild[0]11,7
mouseClickvaadin=runAudioTest::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[3]/VCheckBox[0]/domChild[0]6,7
clickvaadin=runAudioTest::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[5]/VButton[0]/domChild[0]/domChild[0]
pause5000
screenCapturelongerAtEndMuted
mouseClickvaadin=runAudioTest::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[1]/VCheckBox[0]/domChild[0]69,9
screenCapturecontrolsHidden
+ + diff --git a/uitest/src/com/vaadin/tests/components/media/AudioTest.java b/uitest/src/com/vaadin/tests/components/media/AudioTest.java new file mode 100644 index 0000000000..28d1a7716f --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/media/AudioTest.java @@ -0,0 +1,86 @@ +/* + * Copyright 2000-2013 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package com.vaadin.tests.components.media; + +import com.vaadin.data.util.MethodProperty; +import com.vaadin.server.ClassResource; +import com.vaadin.server.Resource; +import com.vaadin.tests.components.TestBase; +import com.vaadin.ui.Audio; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.CheckBox; + +public class AudioTest extends TestBase { + + @Override + protected void setup() { + + // Public domain sounds from pdsounds.org 27.2.2013 + + final Resource[] s1 = { new ClassResource(getClass(), "bip.mp3"), + new ClassResource(getClass(), "bip.ogg") }; + final Resource[] s2 = { + new ClassResource(getClass(), "toyphone_dialling.mp3"), + new ClassResource(getClass(), "toyphone_dialling.ogg") }; + + final Audio audio = new Audio(); + + audio.setSources(s1); + audio.setShowControls(true); + audio.setHtmlContentAllowed(true); + audio.setAltText("Can't play media"); + audio.setAutoplay(true); + + addComponent(audio); + + CheckBox checkBox = new CheckBox("Show controls", + new MethodProperty(audio, "showControls")); + addComponent(checkBox); + checkBox = new CheckBox("HtmlContentAllowed", + new MethodProperty(audio, "htmlContentAllowed")); + addComponent(checkBox); + checkBox = new CheckBox("muted", new MethodProperty(audio, + "muted")); + addComponent(checkBox); + checkBox = new CheckBox("autoplay", new MethodProperty(audio, + "autoplay")); + addComponent(checkBox); + + Button b = new Button("Change", new Button.ClickListener() { + + @Override + public void buttonClick(ClickEvent event) { + audio.setSources(s2); + } + }); + addComponent(b); + getLayout().setHeight("400px"); + getLayout().setExpandRatio(b, 1.0f); + } + + @Override + protected String getDescription() { + return "Should autoplay, manipulating checkboxes should do appropriate thing, button changes file."; + } + + @Override + protected Integer getTicketNumber() { + return 11160; + } + +} diff --git a/uitest/src/com/vaadin/tests/components/media/bip.mp3 b/uitest/src/com/vaadin/tests/components/media/bip.mp3 new file mode 100644 index 0000000000..2c7e790cf7 Binary files /dev/null and b/uitest/src/com/vaadin/tests/components/media/bip.mp3 differ diff --git a/uitest/src/com/vaadin/tests/components/media/bip.ogg b/uitest/src/com/vaadin/tests/components/media/bip.ogg new file mode 100644 index 0000000000..4e5014d92f Binary files /dev/null and b/uitest/src/com/vaadin/tests/components/media/bip.ogg differ diff --git a/uitest/src/com/vaadin/tests/components/media/toyphone_dialling.mp3 b/uitest/src/com/vaadin/tests/components/media/toyphone_dialling.mp3 new file mode 100644 index 0000000000..1788026856 Binary files /dev/null and b/uitest/src/com/vaadin/tests/components/media/toyphone_dialling.mp3 differ diff --git a/uitest/src/com/vaadin/tests/components/media/toyphone_dialling.ogg b/uitest/src/com/vaadin/tests/components/media/toyphone_dialling.ogg new file mode 100644 index 0000000000..a042da5795 Binary files /dev/null and b/uitest/src/com/vaadin/tests/components/media/toyphone_dialling.ogg differ -- cgit v1.2.3 From 17f64543bcc74f74017a3d1c13e5db83c7a4ec41 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Tue, 19 Mar 2013 20:27:22 +0200 Subject: Disabled TabIndex warning for now (#11325) Change-Id: I89311c7e4bdab3a70aa335c203ef57badab7bec8 --- .../src/com/vaadin/client/ui/AbstractComponentConnector.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'client') diff --git a/client/src/com/vaadin/client/ui/AbstractComponentConnector.java b/client/src/com/vaadin/client/ui/AbstractComponentConnector.java index 74cb85c297..ecd6abae08 100644 --- a/client/src/com/vaadin/client/ui/AbstractComponentConnector.java +++ b/client/src/com/vaadin/client/ui/AbstractComponentConnector.java @@ -142,9 +142,13 @@ public abstract class AbstractComponentConnector extends AbstractConnector ((Focusable) getWidget()) .setTabIndex(((TabIndexState) getState()).tabIndex); } else { - VConsole.error("Tab index received for " - + Util.getSimpleName(getWidget()) - + " which does not implement Focusable"); + /* + * TODO Enable this error when all widgets have been fixed to + * properly support tabIndex, i.e. implement Focusable + */ + // VConsole.error("Tab index received for " + // + Util.getSimpleName(getWidget()) + // + " which does not implement Focusable"); } } Profiler.leave("AbstractComponentConnector.onStateChanged update tab index"); -- cgit v1.2.3 From 5ea677d377c96c60fbc546eb2381bb88f2d4b478 Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Tue, 12 Mar 2013 18:34:18 +0200 Subject: Make TextArea.setCursorPosition work in all browsers (#8769) svn changeset:25579/svn branch:6.8 Conflicts: client/src/com/vaadin/client/ui/VTextField.java Change-Id: I3b53be8df4ce0564f34d8aa9bc1ce1c34648eadd --- client/src/com/vaadin/client/ui/VTextArea.java | 114 ++++++++++++++ client/src/com/vaadin/client/ui/VTextField.java | 4 + .../tests/components/textarea/ScrollCursor.html | 169 +++++++++++++++++++++ .../tests/components/textarea/ScrollCursor.java | 89 +++++++++++ 4 files changed, 376 insertions(+) create mode 100644 uitest/src/com/vaadin/tests/components/textarea/ScrollCursor.html create mode 100644 uitest/src/com/vaadin/tests/components/textarea/ScrollCursor.java (limited to 'client') diff --git a/client/src/com/vaadin/client/ui/VTextArea.java b/client/src/com/vaadin/client/ui/VTextArea.java index 4a5de23828..45e0532451 100644 --- a/client/src/com/vaadin/client/ui/VTextArea.java +++ b/client/src/com/vaadin/client/ui/VTextArea.java @@ -63,6 +63,120 @@ public class VTextArea extends VTextField { getTextAreaElement().setRows(rows); } + @Override + public void setSelectionRange(int pos, int length) { + super.setSelectionRange(pos, length); + final String value = getValue(); + /* + * Align position to index inside string value + */ + int index = pos; + if (index < 0) { + index = 0; + } + if (index > value.length()) { + index = value.length(); + } + // Get pixels count required to scroll textarea vertically + int scrollTop = getScrollTop(value, index); + int scrollLeft = -1; + /* + * Check if textarea has wrap attribute set to "off". In the latter case + * horizontal scroll is also required. + */ + if (!isWordwrap()) { + // Get pixels count required to scroll textarea horizontally + scrollLeft = getScrollLeft(value, index); + } + // Set back original text if previous methods calls changed it + if (!isWordwrap() || index < value.length()) { + setValue(value, false); + } + /* + * Call original method to set cursor position. In most browsers it + * doesn't lead to scrolling. + */ + super.setSelectionRange(pos, length); + /* + * Align vertical scroll to middle of textarea view (height) if + * scrolling is reqiured at all. + */ + if (scrollTop > 0) { + scrollTop += getElement().getClientHeight() / 2; + } + /* + * Align horizontal scroll to middle of textarea view (widht) if + * scrolling is reqiured at all. + */ + if (scrollLeft > 0) { + scrollLeft += getElement().getClientWidth() / 2; + } + /* + * Scroll if computed scrollTop is greater than scroll after cursor + * setting + */ + if (getElement().getScrollTop() < scrollTop) { + getElement().setScrollTop(scrollTop); + } + /* + * Scroll if computed scrollLeft is greater than scroll after cursor + * setting + */ + if (getElement().getScrollLeft() < scrollLeft) { + getElement().setScrollLeft(scrollLeft); + } + } + + /* + * Get horizontal scroll value required to get position visible. Method is + * called only when text wrapping is off. There is need to scroll + * horizontally in case words are wrapped. + */ + private int getScrollLeft(String value, int index) { + String beginning = value.substring(0, index); + // Compute beginning of the current line + int begin = beginning.lastIndexOf('\n'); + String line = value.substring(begin + 1); + index = index - begin - 1; + if (index < line.length()) { + index++; + } + line = line.substring(0, index); + /* + * Now line contains current line up to index position + */ + setValue(line.trim(), false); // Set this line to the textarea. + /* + * Scroll textarea up to the end of the line (maximum possible + * horizontal scrolling value). Now the end line becomes visible. + */ + getElement().setScrollLeft(getElement().getScrollWidth()); + // Return resulting horizontal scrolling value. + return getElement().getScrollLeft(); + } + + /* + * Get vertical scroll value required to get position visible + */ + private int getScrollTop(String value, int index) { + /* + * Trim text after position and set this trimmed text if index is not + * very end. + */ + if (index < value.length()) { + String beginning = value.substring(0, index); + setValue(beginning, false); + } + /* + * Now textarea contains trimmed text and could be scrolled up to the + * top. Scroll it to maximum possible value to get end of the text + * visible. + */ + getElement().setScrollTop(getElement().getScrollHeight()); + // Return resulting vertical scrolling value. + return getElement().getScrollTop(); + } + private class MaxLengthHandler implements KeyUpHandler, ChangeHandler { @Override diff --git a/client/src/com/vaadin/client/ui/VTextField.java b/client/src/com/vaadin/client/ui/VTextField.java index 0fbed0dd90..da9445c811 100644 --- a/client/src/com/vaadin/client/ui/VTextField.java +++ b/client/src/com/vaadin/client/ui/VTextField.java @@ -446,4 +446,8 @@ public class VTextField extends TextBoxBase implements Field, ChangeHandler, this.inputPrompt = inputPrompt; } + protected boolean isWordwrap() { + String wrap = getElement().getAttribute("wrap"); + return !"off".equals(wrap); + } } diff --git a/uitest/src/com/vaadin/tests/components/textarea/ScrollCursor.html b/uitest/src/com/vaadin/tests/components/textarea/ScrollCursor.html new file mode 100644 index 0000000000..9eaa1ceada --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/textarea/ScrollCursor.html @@ -0,0 +1,169 @@ + + + + + + +New Test + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
New Test
open/run/com.vaadin.tests.components.textarea.ScrollCursor?restartApplication
mouseClickvaadin=runcomvaadintestscomponentstextareaScrollCursor::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/domChild[0]/domChild[0]191,94
clickvaadin=runcomvaadintestscomponentstextareaScrollCursor::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[3]/VButton[0]/domChild[0]/domChild[0]
clickvaadin=runcomvaadintestscomponentstextareaScrollCursor::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VButton[0]/domChild[0]/domChild[0]
screenCapturewrap-start
clickvaadin=runcomvaadintestscomponentstextareaScrollCursor::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[4]/VButton[0]/domChild[0]/domChild[0]
clickvaadin=runcomvaadintestscomponentstextareaScrollCursor::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VButton[0]/domChild[0]/domChild[0]
screenCapturewrap-middle
clickvaadin=runcomvaadintestscomponentstextareaScrollCursor::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[5]/VButton[0]/domChild[0]/domChild[0]
clickvaadin=runcomvaadintestscomponentstextareaScrollCursor::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VButton[0]/domChild[0]/domChild[0]
screenCapturewrap-end
clickvaadin=runcomvaadintestscomponentstextareaScrollCursor::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[3]/VButton[0]/domChild[0]/domChild[0]
clickvaadin=runcomvaadintestscomponentstextareaScrollCursor::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VButton[0]/domChild[0]/domChild[0]
screenCapturewrap-end-start
clickvaadin=runcomvaadintestscomponentstextareaScrollCursor::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[2]/VButton[0]/domChild[0]/domChild[0]
clickvaadin=runcomvaadintestscomponentstextareaScrollCursor::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[3]/VButton[0]/domChild[0]/domChild[0]
clickvaadin=runcomvaadintestscomponentstextareaScrollCursor::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VButton[0]/domChild[0]/domChild[0]
screenCapturenowrap-start
clickvaadin=runcomvaadintestscomponentstextareaScrollCursor::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[4]/VButton[0]/domChild[0]/domChild[0]
clickvaadin=runcomvaadintestscomponentstextareaScrollCursor::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VButton[0]/domChild[0]/domChild[0]
screenCapturenowrap-middle
clickvaadin=runcomvaadintestscomponentstextareaScrollCursor::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[5]/VButton[0]/domChild[0]/domChild[0]
clickvaadin=runcomvaadintestscomponentstextareaScrollCursor::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VButton[0]/domChild[0]/domChild[0]
screenCapturenowrap-end
clickvaadin=runcomvaadintestscomponentstextareaScrollCursor::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[3]/VButton[0]/domChild[0]/domChild[0]
clickvaadin=runcomvaadintestscomponentstextareaScrollCursor::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VButton[0]/domChild[0]
screenCapturenowrap-end-start
+ + diff --git a/uitest/src/com/vaadin/tests/components/textarea/ScrollCursor.java b/uitest/src/com/vaadin/tests/components/textarea/ScrollCursor.java new file mode 100644 index 0000000000..c95731d94f --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/textarea/ScrollCursor.java @@ -0,0 +1,89 @@ +package com.vaadin.tests.components.textarea; + +import com.vaadin.tests.components.TestBase; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Button.ClickListener; +import com.vaadin.ui.TextArea; + +/** + * @author denis + * + */ +public class ScrollCursor extends TestBase { + + private TextArea textArea; + private int position; + + @Override + protected void setup() { + textArea = new TextArea(); + textArea.setValue("saddddddddddd fdgdfgfdgfd\n" + + "aasddddddddddd\n" + "dsaffffffdsf\n" + "sdf\n" + + "dsfsdfsdfsdfsd\n\n" + "ffffffffffffffffffff\n" + + "sdfdsfdsfsdfsdfsd xxxxxxxxxxxxxxxx\n" + "sdgfsd\n" + + "dsf\n" + "ds\n" + "fds\n" + "fds\nfs"); + addComponent(textArea); + Button button = new Button("Scroll"); + button.addListener(new ClickListener() { + + public void buttonClick(ClickEvent event) { + textArea.setCursorPosition(getPosition()); + } + }); + Button wrap = new Button("Set wrap"); + wrap.addListener(new ClickListener() { + + public void buttonClick(ClickEvent event) { + textArea.setWordwrap(false); + } + }); + + Button toBegin = new Button("To begin"); + toBegin.addListener(new ClickListener() { + + public void buttonClick(ClickEvent event) { + position = 3; + } + }); + + Button toMiddle = new Button("To middle"); + toMiddle.addListener(new ClickListener() { + + public void buttonClick(ClickEvent event) { + position = 130; + } + }); + + Button toEnd = new Button("To end"); + toEnd.addListener(new ClickListener() { + + public void buttonClick(ClickEvent event) { + position = textArea.getValue().toString().length(); + } + }); + + addComponent(button); + addComponent(wrap); + addComponent(toBegin); + addComponent(toMiddle); + addComponent(toEnd); + } + + @Override + protected String getDescription() { + return "Tests scrolling for TextArea with different word wrapping settings. " + + "Sets cursor position at the beginning, middle and the end " + + "of text and checks textarea is scrolled."; + } + + @Override + protected Integer getTicketNumber() { + return 8769; + } + + private int getPosition() { + return position; + } + +} -- cgit v1.2.3 From e4c9eda51082a443822b66864df2fe14be7dc6d7 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Mon, 18 Mar 2013 21:34:27 +0200 Subject: Enable a Vaadin applications to be re-initialized if if has been re-added to the same page (#8350) Change-Id: I30dbc14f00108fa699694ecd1d37679d8a0dff4b --- WebContent/VAADIN/vaadinBootstrap.js | 34 +++++++++++++++++++--- .../com/vaadin/client/ApplicationConnection.java | 1 + 2 files changed, 31 insertions(+), 4 deletions(-) (limited to 'client') diff --git a/WebContent/VAADIN/vaadinBootstrap.js b/WebContent/VAADIN/vaadinBootstrap.js index 9e012ae987..81adfcccc6 100644 --- a/WebContent/VAADIN/vaadinBootstrap.js +++ b/WebContent/VAADIN/vaadinBootstrap.js @@ -55,19 +55,45 @@ pendingApps: [] }; }; - + + var isInitializedInDom = function(appId) { + var appDiv = document.getElementById(appId); + if (!appDiv) { + return false; + } + for ( var i = 0; i < appDiv.childElementCount; i++) { + var className = appDiv.childNodes[i].className; + // If the app div contains a child with the class + // "v-app-loading" we have only received the HTML + // but not yet started the widget set + // (UIConnector removes the v-app-loading div). + if (className && className.contains("v-app-loading")) { + return false; + } + } + return true; + }; + window.vaadin = window.vaadin || { initApplication: function(appId, config) { + var testbenchId = appId.replace(/-\d+$/, ''); + if (apps[appId]) { - throw "Application " + appId + " already initialized"; + if (window.vaadin && window.vaadin.clients && window.vaadin.clients[testbenchId] && window.vaadin.clients[testbenchId].initializing) { + throw "Application " + appId + " is already being initialized"; + } + if (isInitializedInDom(appId)) { + throw "Application " + appId + " already initialized"; + } } + log("init application", appId, config); - var testbenchId = appId.replace(/-\d+$/, ''); window.vaadin.clients[testbenchId] = { isActive: function() { return true; - } + }, + initializing: true }; var getConfig = function(name) { diff --git a/client/src/com/vaadin/client/ApplicationConnection.java b/client/src/com/vaadin/client/ApplicationConnection.java index 62827feffb..4ddbd7c39b 100644 --- a/client/src/com/vaadin/client/ApplicationConnection.java +++ b/client/src/com/vaadin/client/ApplicationConnection.java @@ -510,6 +510,7 @@ public class ApplicationConnection { client.getPathForElement = $entry(function(element) { return componentLocator.@com.vaadin.client.ComponentLocator::getPathForElement(Lcom/google/gwt/user/client/Element;)(element); }); + client.initializing = false; $wnd.vaadin.clients[TTAppId] = client; }-*/; -- cgit v1.2.3