KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > google > gwt > user > client > ui > impl > PopupImplMozilla


1 /*
2  * Copyright 2007 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations under
14  * the License.
15  */

16 package com.google.gwt.user.client.ui.impl;
17
18 import com.google.gwt.user.client.Command;
19 import com.google.gwt.user.client.DeferredCommand;
20 import com.google.gwt.user.client.DOM;
21 import com.google.gwt.user.client.Element;
22
23 /**
24  * Implementation class used by {@link com.google.gwt.user.client.ui.PopupPanel}.
25  * This implementation is identical to the implementation provided by
26  * {@link com.google.gwt.user.client.ui.impl.PopupImpl} in the case where
27  * Mozilla is NOT running on the Mac.
28  * <p>
29  * A different implemention is provided for the Mac in order to prevent
30  * scrollbars underneath the PopupPanel from being rendered on top of the
31  * PopupPanel (issue #410). Unfortunately, the solution that fixes this problem
32  * for the Mac causes a problem with dragging a
33  * {@link com.google.gwt.user.client.ui.DialogBox} on Linux. While dragging the
34  * DialogBox (especially diagonally), it jitters significantly.
35  * </p>
36  * <p>
37  * We did not introduce a deferred binding rule for Mozilla on the Mac because
38  * this is the first instance in which we have a Mozilla-related bug fix which
39  * does not work on all platforms.
40  * </p>
41  * <p>
42  * This implementation can be simplified in the event that the jittering problem
43  * on Linux is fixed, or the scrollbar rendering problem on the Mac is fixed.
44  * </p>
45  */

46 public class PopupImplMozilla extends PopupImpl {
47
48   /**
49    * Cache the value to avoid repeated calls.
50    */

51   private static boolean isMac = isMac();
52   
53   private static native boolean isMac() /*-{
54     if (navigator.userAgent.indexOf("Macintosh") != -1) {
55       return true;
56     }
57     return false;
58   }-*/
;
59
60   public Element createElement() {
61     final Element outerElem = DOM.createDiv();
62
63     if (isMac) {
64       // To solve the scrollbar rendering problem on the Mac, we have to make
65
// the PopupPanel a 'heavyweight' element by setting a style of
66
// 'overflow:auto' on the outermost div. This ensures that all of the
67
// elements that are children of this div will be rendered on top of
68
// any underlying scrollbars.
69

70       // Unfortunately, if we add a border to the outer div (which has
71
// a style of 'overflow:auto'), the border will not be rendered on top
72
// of underlying scrollbars. To get around this problem, we introduce an
73
// inner div which acts as the new containing element for the PopupPanel,
74
// and this element is the one to which all styling is applied to.
75
DOM.setInnerHTML(outerElem, "<div></div>");
76
77       // Mozilla determines the default stacking order for heavyweight elements
78
// by their order on the page. If the PopupPanel is declared before
79
// another
80
// heavyweight element on the page, then the scrollbars of the heavyweight
81
// element will still shine through the PopupPanel. By setting
82
// 'overflow:auto' after all of the elements on the page have been
83
// rendered,
84
// the PopupPanel becomes the highest element in the stacking order.
85
DeferredCommand.addCommand(new Command() {
86         public void execute() {
87           DOM.setStyleAttribute(outerElem, "overflow", "auto");
88         }
89       });
90     }
91
92     return outerElem;
93   }
94
95   public Element getContainerElement(Element outerElem) {
96     return isMac ? DOM.getFirstChild(outerElem) : outerElem;
97   }
98 }
99
Popular Tags