KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > google > gwt > user > client > impl > HistoryImplFrame


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.impl;
17
18 import com.google.gwt.user.client.Element;
19
20 /**
21  * An IFRAME implementation of
22  * {@link com.google.gwt.user.client.impl.HistoryImpl}.
23  */

24 abstract class HistoryImplFrame extends HistoryImpl {
25
26   private static native Element findHistoryFrame() /*-{
27     var historyFrame = $doc.getElementById('__gwt_historyFrame');
28     return historyFrame || null;
29   }-*/
;
30
31   private static native Element getTokenElement(Element historyFrame) /*-{
32     // Initialize the history iframe. If '__gwt_historyToken' already exists, then
33     // we're probably backing into the app, so _don't_ set the iframe's location.
34     var tokenElement = null;
35     if (historyFrame.contentWindow) {
36       var doc = historyFrame.contentWindow.document;
37       tokenElement = doc.getElementById('__gwt_historyToken') || null;
38     }
39     return tokenElement;
40   }-*/
;
41
42   private Element historyFrame;
43
44   public boolean init() {
45     historyFrame = findHistoryFrame();
46     if (historyFrame == null) {
47       return false;
48     }
49
50     initHistoryToken();
51
52     // Initialize the history iframe. If a token element already exists, then
53
// we're probably backing into the app, so _don't_ create a new item.
54
Element tokenElement = getTokenElement(historyFrame);
55     if (tokenElement != null) {
56       setToken(getTokenElementContent(tokenElement));
57     } else {
58       newItemImpl(historyFrame, getToken(), true);
59     }
60
61     injectGlobalHandler();
62     return true;
63   }
64
65   public void newItem(String JavaDoc historyToken) {
66     newItemImpl(historyFrame, historyToken, false);
67   }
68
69   protected abstract String JavaDoc getTokenElementContent(Element tokenElement);
70
71   protected abstract void initHistoryToken();
72
73   protected abstract void injectGlobalHandler();
74
75   protected abstract void newItemImpl(Element historyFrame,
76       String JavaDoc historyToken, boolean forceAdd);
77 }
78
Popular Tags