Commit c5bd666a authored by Xan Lopez's avatar Xan Lopez

Implement back and forward history, patch by Jan Alonzo

with several cleanups. (#506566)

svn path=/trunk/; revision=7918
parent ca956826
......@@ -8,7 +8,9 @@ libephywebkitembed_la_SOURCES = \
webkit-embed-persist.c \
webkit-embed-persist.h \
webkit-embed-single.c \
webkit-embed-single.h
webkit-embed-single.h \
webkit-history-item.c \
webkit-history-item.h
libephywebkitembed_la_CPPFLAGS = \
-I$(top_srcdir)/lib \
......
/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; -*- */
/*
* Copyright © 2007 Xan Lopez
* Copyright © 2008 Jan Alonzo
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -31,8 +32,10 @@
#include <string.h>
#include "webkit-embed.h"
#include "webkit-history-item.h"
#include "ephy-embed.h"
#include "ephy-base-embed.h"
#include "ephy-history-item.h"
static void webkit_embed_class_init (WebKitEmbedClass *klass);
static void webkit_embed_init (WebKitEmbed *gs);
......@@ -42,13 +45,22 @@ static void ephy_embed_iface_init (EphyEmbedIface *iface);
#define WEBKIT_EMBED_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), WEBKIT_TYPE_EMBED, WebKitEmbedPrivate))
#define WEBKIT_BACK_FORWARD_LIMIT 100
typedef enum
{
{
WEBKIT_EMBED_LOAD_STARTED,
WEBKIT_EMBED_LOAD_REDIRECTING,
WEBKIT_EMBED_LOAD_LOADING,
WEBKIT_EMBED_LOAD_STOPPED
} WebKitEmbedLoadState;
} WebKitEmbedLoadState;
typedef enum
{
WEBKIT_HISTORY_BACKWARD,
WEBKIT_HISTORY_FORWARD
} WebKitHistoryType;
struct WebKitEmbedPrivate
{
......@@ -57,6 +69,50 @@ struct WebKitEmbedPrivate
char *loading_uri;
};
static GList*
webkit_construct_history_list (WebKitEmbed *embed, WebKitHistoryType hist_type)
{
WebKitWebBackForwardList *web_back_forward_list;
GList *webkit_items, *iter, *ephy_items = NULL;
g_return_val_if_fail (WEBKIT_IS_EMBED (embed), NULL);
web_back_forward_list = webkit_web_view_get_back_forward_list (embed->priv->web_view);
if (hist_type == WEBKIT_HISTORY_FORWARD)
webkit_items = webkit_web_back_forward_list_get_forward_list_with_limit (web_back_forward_list,
WEBKIT_BACK_FORWARD_LIMIT);
else
webkit_items = webkit_web_back_forward_list_get_back_list_with_limit (web_back_forward_list,
WEBKIT_BACK_FORWARD_LIMIT);
for (iter = webkit_items; iter != NULL; iter = iter->next) {
EphyHistoryItem *item = webkit_history_item_new (WEBKIT_WEB_HISTORY_ITEM (iter->data));
ephy_items = g_list_prepend (ephy_items, item);
}
g_list_free (webkit_items);
return ephy_items;
}
static EphyHistoryItem*
webkit_construct_history_item (WebKitEmbed *embed, WebKitHistoryType hist_type)
{
WebKitWebBackForwardList *web_back_forward_list;
WebKitWebHistoryItem *history_item;
g_return_val_if_fail (WEBKIT_IS_EMBED (embed), NULL);
web_back_forward_list = webkit_web_view_get_back_forward_list (embed->priv->web_view);
if (hist_type == WEBKIT_HISTORY_FORWARD)
history_item = webkit_web_back_forward_list_get_forward_item (web_back_forward_list);
else
history_item = webkit_web_back_forward_list_get_back_item (web_back_forward_list);
return webkit_history_item_new (history_item);
}
static void
impl_manager_do_command (EphyCommandManager *manager,
const char *command)
......@@ -476,30 +532,38 @@ impl_has_modified_forms (EphyEmbed *embed)
static GList*
impl_get_backward_history (EphyEmbed *embed)
{
return NULL;
return webkit_construct_history_list (WEBKIT_EMBED (embed),
WEBKIT_HISTORY_BACKWARD);
}
static GList*
impl_get_forward_history (EphyEmbed *embed)
impl_get_forward_history (EphyEmbed *embed)
{
return NULL;
return webkit_construct_history_list (WEBKIT_EMBED (embed),
WEBKIT_HISTORY_FORWARD);
}
static EphyHistoryItem*
impl_get_next_history_item (EphyEmbed *embed)
impl_get_next_history_item (EphyEmbed *embed)
{
return NULL;
return webkit_construct_history_item (WEBKIT_EMBED (embed), WEBKIT_HISTORY_FORWARD);
}
static EphyHistoryItem*
impl_get_previous_history_item (EphyEmbed *embed)
{
return NULL;
return webkit_construct_history_item (WEBKIT_EMBED (embed), WEBKIT_HISTORY_BACKWARD);
}
static void
impl_go_to_history_item (EphyEmbed *embed, EphyHistoryItem *history_item)
impl_go_to_history_item (EphyEmbed *embed, EphyHistoryItem *history_item)
{
WebKitEmbed *wembed = WEBKIT_EMBED (embed);
WebKitWebHistoryItem *item = WEBKIT_HISTORY_ITEM (history_item)->data;
webkit_web_view_go_to_back_forward_item (wembed->priv->web_view, item);
}
static void
......
/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; -*- */
/*
* Copyright Jan Alonzo
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include "config.h"
#include "webkit-history-item.h"
static void webkit_history_item_finalize (GObject *object);
EphyHistoryItem*
webkit_history_item_new (WebKitWebHistoryItem *history_item)
{
WebKitHistoryItem *item;
if (!history_item) return NULL;
item = g_object_new (WEBKIT_TYPE_HISTORY_ITEM, NULL);
item->data = history_item;
return EPHY_HISTORY_ITEM (item);
}
static char*
impl_get_url (EphyHistoryItem *item)
{
const gchar *uri;
if (!item) return NULL;
uri = webkit_web_history_item_get_uri (WEBKIT_HISTORY_ITEM (item)->data);
return g_strdup (uri);
}
static char*
impl_get_title (EphyHistoryItem *item)
{
const gchar *title;
if (!item) return NULL;
title = webkit_web_history_item_get_title (WEBKIT_HISTORY_ITEM (item)->data);
return g_strdup (title);
}
static void
webkit_history_item_iface_init (EphyHistoryItemIface *iface)
{
iface->get_url = impl_get_url;
iface->get_title = impl_get_title;
}
G_DEFINE_TYPE_WITH_CODE (WebKitHistoryItem, webkit_history_item, G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE (EPHY_TYPE_HISTORY_ITEM,
webkit_history_item_iface_init))
static void
webkit_history_item_finalize (GObject *object)
{
WebKitHistoryItem *item = WEBKIT_HISTORY_ITEM (object);
g_object_unref (item->data);
G_OBJECT_CLASS (webkit_history_item_parent_class)->finalize (object);
}
static void
webkit_history_item_class_init (WebKitHistoryItemClass *klass)
{
GObjectClass *gobject_class = (GObjectClass*)klass;
gobject_class->finalize = webkit_history_item_finalize;
}
static void
webkit_history_item_init (WebKitHistoryItem *self)
{
}
/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; -*- */
/*
* Copyright 2008 Jan Alonzo
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#ifndef __WEBKIT_HISTORY_ITEM_H__
#define __WEBKIT_HISTORY_ITEM_H__
#include <glib.h>
#include <glib-object.h>
#include <webkit/webkit.h>
#include "ephy-history-item.h"
G_BEGIN_DECLS
#define WEBKIT_TYPE_HISTORY_ITEM (webkit_history_item_get_type ())
#define WEBKIT_HISTORY_ITEM(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), WEBKIT_TYPE_HISTORY_ITEM, WebKitHistoryItem))
#define WEBKIT_HISTORY_ITEM_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), WEBKIT_TYPE_HISTORY_ITEM, WebKitHistoryItemClass))
#define WEBKIT_IS_HISTORY_ITEM(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), WEBKIT_TYPE_HISTORY_ITEM))
#define WEBKIT_IS_HISTORY_ITEM_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), WEBKIT_TYPE_HISTORY_ITEM))
#define WEBKIT_HISTORY_ITEM_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_INTERFACE ((inst), WEBKIT_TYPE_HISTORY_ITEM, WebKitHistoryItemClass))
typedef struct _WebKitHistoryItem WebKitHistoryItem;
typedef struct _WebKitHistoryItemClass WebKitHistoryItemClass;
struct _WebKitHistoryItemClass
{
GObjectClass parent_class;
};
struct _WebKitHistoryItem
{
GObject parent_instance;
WebKitWebHistoryItem *data;
};
GType webkit_history_item_get_type (void) G_GNUC_CONST;
EphyHistoryItem *webkit_history_item_new (WebKitWebHistoryItem *item) G_GNUC_MALLOC;
G_END_DECLS
#endif /* __WEBKIT_HISTORY_ITEM_H__ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment