Skip to content

Commit c1c3453

Browse files
author
zhourenjian
committed
Add border absorbing on resizing a Shell window.
Fixing bug that Safari/Chrome acts a little strange on absorbing on right side
1 parent 8961598 commit c1c3453

1 file changed

Lines changed: 117 additions & 37 deletions

File tree

  • sources/net.sf.j2s.java.org.eclipse.swt/src/org/eclipse/swt/internal/dnd

sources/net.sf.j2s.java.org.eclipse.swt/src/org/eclipse/swt/internal/dnd/ShellFrameDND.java

Lines changed: 117 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,24 @@ public boolean dragBegan(DragEvent e) {
110110
return true;
111111
};
112112
public boolean dragging(DragEvent e) {
113+
114+
int gHeight = OS.getFixedBodyClientHeight(); //document.body.clientHeight;
115+
int gWidth = document.body.clientWidth;
116+
boolean noScroll = (document.body.style.overflow == "hidden");
117+
/**
118+
* @j2sNative
119+
* noScroll = noScroll || document.body.style.overflowX == "hidden";
120+
*/ {}
121+
if (noScroll) {
122+
gWidth = document.body.parentNode.clientWidth;
123+
}
124+
125+
CSSStyle style = e.sourceElement.style;
126+
int dWidth = style.width.length() > 0 ? Integer.parseInt(style.width) : 0;
127+
int dHeight = style.height.length() > 0 ? Integer.parseInt(style.height) : 0;
128+
int dX = style.left.length() > 0 ? Integer.parseInt(style.left) : 0;
129+
int dY = style.top.length() > 0 ? Integer.parseInt(style.top) : 0;
130+
113131
if (this.resize != null) {
114132
int xx = this.sourceX;
115133
int yy = this.sourceY;
@@ -164,6 +182,13 @@ public boolean dragging(DragEvent e) {
164182
hh += e.deltaY ();
165183
document.body.style.cursor = "se-resize";
166184
}
185+
186+
xx = adjustX(e, xx, gWidth, dWidth);
187+
yy = adjustY(e, yy, gHeight, dHeight);
188+
189+
ww = adjustW(e, ww, gWidth, dX);
190+
hh = adjustH(e, hh, gHeight, dY);
191+
167192
this.frame.style.left = xx + "px";
168193
this.frame.style.top = yy + "px";
169194
// this.frame.style.width = ((ww > 104) ? ww : 110) + "px";
@@ -174,28 +199,63 @@ public boolean dragging(DragEvent e) {
174199
}
175200
int xx = this.sourceX + e.deltaX ();
176201
int yy = this.sourceY + e.deltaY ();
202+
203+
xx = adjustX(e, xx, gWidth, dWidth);
204+
yy = adjustY(e, yy, gHeight, dHeight);
177205

178-
int gHeight = OS.getFixedBodyClientHeight(); //document.body.clientHeight;
179-
int gWidth = document.body.clientWidth;
180-
if (document.body.style.overflow == "hidden") {
181-
gWidth = document.body.parentNode.clientWidth;
206+
this.frame.style.left = xx + "px";
207+
this.frame.style.top = yy + "px";
208+
/*
209+
* In early SWT implementation, document.body is always with
210+
* "overflow:hidden;" CSS. Now, there are no such constraints.
211+
*
212+
* -Feb 27, 2007
213+
*
214+
if (document.body.scrollLeft != 0) {
215+
document.body.scrollLeft = 0;
216+
}
217+
if (document.body.scrollTop != 0) {
218+
document.body.scrollTop = 0;
182219
}
220+
*/
221+
return true;
222+
}
223+
private int adjustY(DragEvent e, int yy, int gHeight, int dHeight) {
183224
/*
184225
* On mozilla, the mousemove event can contain mousemove
185226
* outside the browser window, so make bound for the dragging.
186227
*/
187-
CSSStyle style = e.sourceElement.style;
188-
int dWidth = style.width.length() > 0 ? Integer.parseInt(style.width) : 0;
189-
if (xx < -dWidth) {
190-
xx = -dWidth;
191-
// It's OK to move outside the width, as there will be scrollbar
192-
// } else if (xx > gWidth - 2) {
193-
// xx = gWidth - 2;
194-
}
195228
if (yy < 0) {
196229
yy = 0;
197-
// } else if (yy > gHeight + 18) {
198-
// yy = gHeight + 18;
230+
// It's OK to move outside the width, as there will be scrollbar
231+
// } else if (yy > gHeight + 18) {
232+
// yy = gHeight + 18;
233+
}
234+
if (!((HTMLEvent) e.event.event).ctrlKey) {
235+
int dTop = Math.abs (yy);
236+
int dBottom = Math.abs (yy - gHeight + dHeight + 2);
237+
if (dBottom < 10) {
238+
if (dBottom < dTop) {
239+
yy = gHeight - dHeight - 2;
240+
} else { // dTop <= dBottom < 10
241+
yy = 0;
242+
}
243+
} else if (dTop < 10) {
244+
yy = 0;
245+
}
246+
}
247+
return yy;
248+
}
249+
private int adjustX(DragEvent e, int xx, int gWidth, int dWidth) {
250+
/*
251+
* On mozilla, the mousemove event can contain mousemove
252+
* outside the browser window, so make bound for the dragging.
253+
*/
254+
if (xx < -dWidth) {
255+
xx = -dWidth;
256+
// It's OK to move outside the width, as there will be scrollbar
257+
// } else if (xx > gWidth - 2) {
258+
// xx = gWidth - 2;
199259
}
200260

201261
/*
@@ -204,36 +264,56 @@ public boolean dragging(DragEvent e) {
204264
* of the browser client area.
205265
*/
206266
if (!((HTMLEvent) e.event.event).ctrlKey) {
207-
if (Math.abs (xx - gWidth + dWidth) < 10) {
208-
xx = gWidth - dWidth;
209-
} else if (Math.abs (xx) < 10) {
267+
int dLeft = Math.abs (xx);
268+
int dRight = Math.abs (xx - gWidth + dWidth + 2);
269+
if (dRight < 10) {
270+
if (dRight < dLeft) {
271+
xx = gWidth - dWidth - 2;
272+
} else { // dLeft <= dRight < 10
273+
xx = 0;
274+
}
275+
} else if (dLeft < 10) {
210276
xx = 0;
211277
}
212-
213-
int dHeight = style.height.length() > 0 ? Integer.parseInt(style.height) : 0;
214-
if (Math.abs (yy - gHeight + dHeight + 2) < 10) {
215-
yy = gHeight - dHeight - 2;
216-
} else if (Math.abs (yy - (-1)) < 10) {
217-
yy = -1;
218-
}
219278
}
220-
this.frame.style.left = xx + "px";
221-
this.frame.style.top = yy + "px";
279+
return xx;
280+
};
281+
private int adjustH(DragEvent e, int hh, int gHeight, int dY) {
282+
if (hh < 0) {
283+
hh = 16;
284+
}
222285
/*
223-
* In early SWT implementation, document.body is always with
224-
* "overflow:hidden;" CSS. Now, there are no such constraints.
225-
*
226-
* -Feb 27, 2007
227-
*
228-
if (document.body.scrollLeft != 0) {
229-
document.body.scrollLeft = 0;
286+
* When no Ctrl key is pressed while dragging, the
287+
* bound will try to attach the edge to the bounds
288+
* of the browser client area.
289+
*/
290+
if (!((HTMLEvent) e.event.event).ctrlKey) {
291+
int dBottom = Math.abs (dY + hh - gHeight + 2);
292+
if (dBottom < 10) {
293+
hh = gHeight - dY - 2;
294+
}
230295
}
231-
if (document.body.scrollTop != 0) {
232-
document.body.scrollTop = 0;
296+
return hh;
297+
}
298+
private int adjustW(DragEvent e, int ww, int gWidth, int dX) {
299+
if (ww < 16) {
300+
ww = 16;
233301
}
234-
*/
235-
return true;
302+
/*
303+
* When no Ctrl key is pressed while dragging, the
304+
* bound will try to attach the edge to the bounds
305+
* of the browser client area.
306+
*/
307+
if (!((HTMLEvent) e.event.event).ctrlKey) {
308+
int dRight = Math.abs (dX + ww - gWidth + 2);
309+
//System.out.println(dRight);
310+
if (dRight < 10) {
311+
ww = gWidth - dX - 2;
312+
}
313+
}
314+
return ww;
236315
};
316+
237317
public boolean dragEnded(DragEvent e) {
238318
CSSStyle style = this.frame.style;
239319
int x = Integer.parseInt (style.left);

0 commit comments

Comments
 (0)