Upstream version 9.37.193.0
[platform/framework/web/crosswalk.git] / src / xwalk / runtime / android / core / src / org / xwalk / core / XWalkNavigationHistory.java
1 // Copyright (c) 2014 Intel Corporation. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package org.xwalk.core;
6
7 import org.xwalk.core.internal.XWalkNavigationHistoryInternal;
8 import org.xwalk.core.internal.XWalkNavigationHistoryInternal.DirectionInternal;
9 import org.xwalk.core.internal.XWalkNavigationItemInternal;
10
11 /**
12  * This class represents a navigation history for a XWalkView instance.
13  * It's not thread-safe and should be only called on UI thread.
14  */
15 public final class XWalkNavigationHistory extends XWalkNavigationHistoryInternal {
16
17     XWalkNavigationHistory(XWalkNavigationHistoryInternal internal) {
18         super(internal);
19     }
20
21     /**
22      * Total size of navigation history for the XWalkView.
23      * @return the size of total navigation items.
24      * @since 1.0
25      */
26     public int size() {
27         return super.size();
28     }
29
30     /**
31      * Test whether there is an item at a specific index.
32      * @param index the given index.
33      * @return true if there is an item at the specific index.
34      * @since 1.0
35      */
36     public boolean hasItemAt(int index) {
37         return super.hasItemAt(index);
38     }
39
40     /**
41      * Get a specific item given by index.
42      * @param index the given index.
43      * @return the navigation item for the given index.
44      * @since 1.0
45      */
46     public XWalkNavigationItem getItemAt(int index) {
47         XWalkNavigationItemInternal item = super.getItemAt(index);
48         if (item == null || item instanceof XWalkNavigationItem) {
49             return (XWalkNavigationItem) item;
50         }
51
52         return new XWalkNavigationItem(item);
53     }
54
55     /**
56      * Get the current item which XWalkView displays.
57      * @return the current navigation item.
58      * @since 1.0
59      */
60     public XWalkNavigationItem getCurrentItem() {
61         XWalkNavigationItemInternal item = super.getCurrentItem();
62         if (item == null || item instanceof XWalkNavigationItem) {
63             return (XWalkNavigationItem) item;
64         }
65
66         return new XWalkNavigationItem(item);
67     }
68
69     /**
70      * Test whether XWalkView can go back.
71      * @return true if it can go back.
72      * @since 1.0
73      */
74     public boolean canGoBack() {
75         return super.canGoBack();
76     }
77
78     /**
79      * Test whether XWalkView can go forward.
80      * @return true if it can go forward.
81      * @since 1.0
82      */
83     public boolean canGoForward() {
84         return super.canGoForward();
85     }
86
87     /**
88      * The direction for web page navigation.
89      * @since 1.0
90      */
91     public enum Direction {
92         /** The backward direction for web page navigation. */
93         BACKWARD,
94         /** The forward direction for web page navigation. */
95         FORWARD
96     }
97
98     /**
99      * Navigates to the specified step from the current navigation item.
100      * Do nothing if the offset is out of bound.
101      * @param direction the direction of navigation.
102      * @param steps go back or foward with a given steps.
103      * @since 1.0
104      */
105     public void navigate(Direction direction, int steps) {
106         super.navigate(DirectionInternal.valueOf(direction.toString()), steps);
107     }
108
109     /**
110      * Get the index for current navigation item.
111      * @return current index in the navigation history.
112      * @since 1.0
113      */
114     public int getCurrentIndex() {
115         return super.getCurrentIndex();
116     }
117
118     /**
119      * Clear all history owned by this XWalkView.
120      * @since 1.0
121      */
122     public void clear() {
123         super.clear();
124     }
125 }