1 // Copyright (c) 2013-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.internal;
7 import java.io.Serializable;
9 import org.chromium.content.browser.NavigationHistory;
12 * This class represents a navigation history for a XWalkViewInternal instance.
13 * It's not thread-safe and should be only called on UI thread.
15 public class XWalkNavigationHistoryInternal implements Cloneable, Serializable {
16 private NavigationHistory mHistory;
17 private XWalkViewInternal mXWalkView;
19 XWalkNavigationHistoryInternal(XWalkViewInternal view, NavigationHistory history) {
24 public XWalkNavigationHistoryInternal(XWalkNavigationHistoryInternal history) {
25 mXWalkView = history.mXWalkView;
26 mHistory = history.mHistory;
30 * Total size of navigation history for the XWalkViewInternal.
31 * @return the size of total navigation items.
35 return mHistory.getEntryCount();
39 * Test whether there is an item at a specific index.
40 * @param index the given index.
41 * @return true if there is an item at the specific index.
44 public boolean hasItemAt(int index) {
45 return index >=0 && index <= size() - 1;
49 * Get a specific item given by index.
50 * @param index the given index.
51 * @return the navigation item for the given index.
54 public XWalkNavigationItemInternal getItemAt(int index) {
55 if (index < 0 || index >= size()) return null;
56 return new XWalkNavigationItemInternal(mHistory.getEntryAtIndex(index));
60 * Get the current item which XWalkViewInternal displays.
61 * @return the current navigation item.
64 public XWalkNavigationItemInternal getCurrentItem() {
65 return getItemAt(getCurrentIndex());
69 * Test whether XWalkViewInternal can go back.
70 * @return true if it can go back.
73 public boolean canGoBack() {
74 return mXWalkView.canGoBack();
78 * Test whether XWalkViewInternal can go forward.
79 * @return true if it can go forward.
82 public boolean canGoForward() {
83 return mXWalkView.canGoForward();
87 * The direction for web page navigation.
90 public enum DirectionInternal {
91 /** The backward direction for web page navigation. */
93 /** The forward direction for web page navigation. */
98 * Navigates to the specified step from the current navigation item.
99 * Do nothing if the offset is out of bound.
100 * @param direction the direction of navigation.
101 * @param steps go back or foward with a given steps.
104 public void navigate(DirectionInternal direction, int steps) {
107 mXWalkView.navigateTo(steps);
110 mXWalkView.navigateTo(-steps);
118 * Get the index for current navigation item.
119 * @return current index in the navigation history.
122 public int getCurrentIndex() {
123 return mHistory.getCurrentEntryIndex();
127 * Clear all history owned by this XWalkViewInternal.
130 public void clear() {
131 mXWalkView.clearHistory();
134 protected synchronized XWalkNavigationHistoryInternal clone() {
135 return new XWalkNavigationHistoryInternal(this);