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.
5 package org.xwalk.core;
7 import org.xwalk.core.internal.XWalkNavigationHistoryInternal;
8 import org.xwalk.core.internal.XWalkNavigationHistoryInternal.DirectionInternal;
9 import org.xwalk.core.internal.XWalkNavigationItemInternal;
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.
15 public final class XWalkNavigationHistory extends XWalkNavigationHistoryInternal {
17 XWalkNavigationHistory(XWalkNavigationHistoryInternal internal) {
22 * Total size of navigation history for the XWalkView.
23 * @return the size of total navigation items.
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.
36 public boolean hasItemAt(int index) {
37 return super.hasItemAt(index);
41 * Get a specific item given by index.
42 * @param index the given index.
43 * @return the navigation item for the given index.
46 public XWalkNavigationItem getItemAt(int index) {
47 XWalkNavigationItemInternal item = super.getItemAt(index);
48 if (item == null || item instanceof XWalkNavigationItem) {
49 return (XWalkNavigationItem) item;
52 return new XWalkNavigationItem(item);
56 * Get the current item which XWalkView displays.
57 * @return the current navigation item.
60 public XWalkNavigationItem getCurrentItem() {
61 XWalkNavigationItemInternal item = super.getCurrentItem();
62 if (item == null || item instanceof XWalkNavigationItem) {
63 return (XWalkNavigationItem) item;
66 return new XWalkNavigationItem(item);
70 * Test whether XWalkView can go back.
71 * @return true if it can go back.
74 public boolean canGoBack() {
75 return super.canGoBack();
79 * Test whether XWalkView can go forward.
80 * @return true if it can go forward.
83 public boolean canGoForward() {
84 return super.canGoForward();
88 * The direction for web page navigation.
91 public enum Direction {
92 /** The backward direction for web page navigation. */
94 /** The forward direction for web page navigation. */
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.
105 public void navigate(Direction direction, int steps) {
106 super.navigate(DirectionInternal.valueOf(direction.toString()), steps);
110 * Get the index for current navigation item.
111 * @return current index in the navigation history.
114 public int getCurrentIndex() {
115 return super.getCurrentIndex();
119 * Clear all history owned by this XWalkView.
122 public void clear() {