Beispiel #1
0
        public void pushState(object state, string title, string url)
        {
            HistoryState hs = CreateState(state, title, url);

            // Add to back:
            back_.Add(current);
            current = hs;           // Don't dispatch.
        }
Beispiel #2
0
        internal void DocumentNavigated()
        {
            if (current != null)
            {
                Push(true, current);
            }

            // Create current:
            current = CreateState(null, null, null);
        }
Beispiel #3
0
        /// <summary>Loads the given state now.</summary>
        private void LoadNow(HistoryState state)
        {
            if (state == current)
            {
                // Reload:
                window.document.location.reload();
            }
            else
            {
                // Set as current:
                current = state;
                Dispatch();

                // Go there now (handles relative urls for us):
                window.document.location.assign(state.url, false);
            }
        }
Beispiel #4
0
        private void Push(bool back, HistoryState state)
        {
            List <HistoryState> stack = back?back_ : forward_;

            if (stack == null)
            {
                stack = new List <HistoryState>();

                if (back)
                {
                    back_ = stack;
                }
                else
                {
                    forward_ = stack;
                }
            }

            stack.Add(state);
        }
Beispiel #5
0
        private HistoryState CreateState(object state, string title, string url)
        {
            if (window.document != null)
            {
                if (url == null)
                {
                    url = window.document.baseURI;
                }

                if (title == null)
                {
                    title = window.document.title;
                }
            }

            HistoryState hs = new HistoryState();

            hs.state = state;
            hs.title = title;
            hs.url   = url;

            return(hs);
        }
Beispiel #6
0
        public void go(int delta)
        {
            if (delta == 0)
            {
                LoadNow(current);
                return;
            }

            HistoryState state = null;
            bool         back  = (delta < 0);

            List <HistoryState> set;

            if (back)
            {
                // Going back
                delta = -delta;
                set   = back_;
            }
            else
            {
                set = forward_;
            }

            // Range check - got enough scope for delta?
            if (set == null || set.Count < delta)
            {
                // Nope - silently do nothing.
                return;
            }

            // Pop and push (always in range):
            for (int i = 0; i < delta; i++)
            {
                // Pop:
                state = set[set.Count - 1];
                set.RemoveAt(set.Count - 1);

                // Push current:
                Push(!back, current);

                // Update current (don't dispatch just yet):
                // current=state;
            }

            if (set.Count == 0)
            {
                // Clear it:
                if (back)
                {
                    back_ = null;
                }
                else
                {
                    forward_ = null;
                }
            }

            // Dispatch:
            LoadNow(state);
        }
Beispiel #7
0
 public void replaceState(object state, string title, string url)
 {
     // Don't dispatch.
     current = CreateState(state, title, url);
 }