Skip to content

Commit

Permalink
gwt: Fix PopupPanel scroll bug and Ctrl+C problem.
Browse files Browse the repository at this point in the history
  • Loading branch information
calin-iorgulescu committed Mar 10, 2015
1 parent 1e0249a commit a222ad3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
font-size: 14px;
background-color: #FFF;
padding: 30px 10px 10px 10px;
overflow-x: scroll;
overflow-wrap: break-word;
word-wrap: break-word;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.PopupPanel;
import com.google.gwt.user.client.ui.ScrollPanel;
import com.google.gwt.user.client.ui.FocusPanel;
import com.google.gwt.event.dom.client.KeyCodes;
import com.google.gwt.user.client.Event;
import com.google.gwt.event.dom.client.BlurEvent;
import com.google.gwt.event.dom.client.BlurHandler;
import com.google.gwt.user.client.Event.NativePreviewEvent;
import com.google.gwt.core.client.Scheduler;
import com.google.gwt.dom.client.Style;
import com.google.gwt.dom.client.Style.Overflow;
import com.google.gwt.dom.client.Document;
Expand All @@ -35,7 +36,7 @@ public class VmcheckerPopup extends PopupPanel {
private static VmcheckerConstants constants = GWT
.create(VmcheckerConstants.class);
private FlowPanel detailsPopupContainer = new FlowPanel();
private ScrollPanel detailsPopupContent = new ScrollPanel();
private FocusPanel detailsPopupContent = new FocusPanel();
private Anchor popupCloseButton = new Anchor();

public VmcheckerPopup() {
Expand Down Expand Up @@ -64,6 +65,14 @@ public void onClick(ClickEvent event) {
}
});

detailsPopupContent.addBlurHandler(new BlurHandler() {
@Override
public void onBlur(BlurEvent event) {
if (isShowing()) {
detailsPopupContent.setFocus(true);
}
}
});
}

public void showContent(String htmlContent) {
Expand All @@ -72,6 +81,7 @@ public void showContent(String htmlContent) {
center();
show();
Document.get().getBody().getStyle().setOverflow(Style.Overflow.HIDDEN);
detailsPopupContent.setFocus(true);
}

@Override
Expand All @@ -86,57 +96,6 @@ protected void onPreviewNativeEvent(NativePreviewEvent event) {
if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ESCAPE) {
hide();
}
// XXX: It seems that on Chrome or Safari focusing the scrollpanel doesn't work.
// There's probably a better way to do this, but for now, it'll do.
if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_DOWN) {
int scrollIncrement = (detailsPopupContent.getMaximumVerticalScrollPosition() -
detailsPopupContent.getMinimumVerticalScrollPosition()) / 200;
if (detailsPopupContent.getVerticalScrollPosition() <
detailsPopupContent.getMaximumVerticalScrollPosition()) {
detailsPopupContent.setVerticalScrollPosition(
detailsPopupContent.getVerticalScrollPosition() + scrollIncrement);
}
}

if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_UP) {
int scrollIncrement = (detailsPopupContent.getMaximumVerticalScrollPosition() -
detailsPopupContent.getMinimumVerticalScrollPosition()) / 200;
if (detailsPopupContent.getVerticalScrollPosition() >
detailsPopupContent.getMinimumVerticalScrollPosition()) {
detailsPopupContent.setVerticalScrollPosition(
detailsPopupContent.getVerticalScrollPosition() - scrollIncrement);
}
}

if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_PAGEDOWN) {
int scrollIncrement = (detailsPopupContent.getMaximumVerticalScrollPosition() -
detailsPopupContent.getMinimumVerticalScrollPosition()) / 20;
if (detailsPopupContent.getVerticalScrollPosition() <
detailsPopupContent.getMaximumVerticalScrollPosition()) {
detailsPopupContent.setVerticalScrollPosition(
detailsPopupContent.getVerticalScrollPosition() + scrollIncrement);
}
}

if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_PAGEUP) {
int scrollIncrement = (detailsPopupContent.getMaximumVerticalScrollPosition() -
detailsPopupContent.getMinimumVerticalScrollPosition()) / 20;
if (detailsPopupContent.getVerticalScrollPosition() >
detailsPopupContent.getMinimumVerticalScrollPosition()) {
detailsPopupContent.setVerticalScrollPosition(
detailsPopupContent.getVerticalScrollPosition() - scrollIncrement);
}
}

if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_END) {
detailsPopupContent.scrollToBottom();
}

if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_HOME) {
detailsPopupContent.scrollToTop();
}

event.cancel();
break;
}
}
Expand Down
4 changes: 3 additions & 1 deletion gwt/vmchecker-gui/war/Vmchecker.css
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,11 @@ a.fillButton:hover {
margin-top: 10px;
padding-top: 10px;
border-top: 1px solid #CCCCCC;
overflow-x: scroll;
overflow-y: auto;
overflow-x: hidden;
overflow-wrap: break-word;
word-wrap: break-word;
outline: 0;
}

.check_error {
Expand Down

0 comments on commit a222ad3

Please sign in to comment.