aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Persch <chpe@cvs.gnome.org>2004-12-19 03:40:08 +0800
committerChristian Persch <chpe@src.gnome.org>2004-12-19 03:40:08 +0800
commit0a389e07241775316dfb866341a1a3c9f6b8a441 (patch)
tree9d96af228f87def15b797f2f8ec5151bce6439c9
parent29604a8fa8cf16a2b0e55ff6f8b9d10e57dd9be5 (diff)
downloadgsoc2013-epiphany-0a389e07241775316dfb866341a1a3c9f6b8a441.tar
gsoc2013-epiphany-0a389e07241775316dfb866341a1a3c9f6b8a441.tar.gz
gsoc2013-epiphany-0a389e07241775316dfb866341a1a3c9f6b8a441.tar.bz2
gsoc2013-epiphany-0a389e07241775316dfb866341a1a3c9f6b8a441.tar.lz
gsoc2013-epiphany-0a389e07241775316dfb866341a1a3c9f6b8a441.tar.xz
gsoc2013-epiphany-0a389e07241775316dfb866341a1a3c9f6b8a441.tar.zst
gsoc2013-epiphany-0a389e07241775316dfb866341a1a3c9f6b8a441.zip
Disable Zoom items for images, and disable zoom, encoding and view source
2004-12-18 Christian Persch <chpe@cvs.gnome.org> * embed/ephy-embed.c: (ephy_embed_chrome_get_type), (ephy_embed_document_type_get_type), (ephy_embed_base_init): * embed/ephy-embed.h: * embed/mozilla/EphyBrowser.cpp: * embed/mozilla/EphyBrowser.h: * embed/mozilla/mozilla-embed.cpp: * src/ephy-tab.c: (ephy_tab_set_property), (ephy_tab_get_property), (ephy_tab_class_init), (ephy_tab_get_document_type), (ephy_tab_document_type_cb), (ephy_tab_init): * src/ephy-tab.h: * src/ephy-window.c: (sync_tab_document_type), (sync_tab_zoom), (ephy_window_set_active_tab): * src/toolbar.c: (toolbar_update_zoom): * src/toolbar.h: Disable Zoom items for images, and disable zoom, encoding and view source for images and xml (xul) documents. Fixes bug #132240.
-rw-r--r--ChangeLog20
-rw-r--r--embed/ephy-embed.c49
-rw-r--r--embed/ephy-embed.h13
-rw-r--r--embed/mozilla/EphyBrowser.cpp33
-rw-r--r--embed/mozilla/EphyBrowser.h2
-rw-r--r--embed/mozilla/mozilla-embed.cpp7
-rw-r--r--src/ephy-tab.c48
-rw-r--r--src/ephy-tab.h2
-rw-r--r--src/ephy-window.c54
-rwxr-xr-xsrc/toolbar.c8
-rw-r--r--src/toolbar.h1
11 files changed, 225 insertions, 12 deletions
diff --git a/ChangeLog b/ChangeLog
index 5d8f7be4c..25e2fd8ea 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,23 @@
+2004-12-18 Christian Persch <chpe@cvs.gnome.org>
+
+ * embed/ephy-embed.c: (ephy_embed_chrome_get_type),
+ (ephy_embed_document_type_get_type), (ephy_embed_base_init):
+ * embed/ephy-embed.h:
+ * embed/mozilla/EphyBrowser.cpp:
+ * embed/mozilla/EphyBrowser.h:
+ * embed/mozilla/mozilla-embed.cpp:
+ * src/ephy-tab.c: (ephy_tab_set_property), (ephy_tab_get_property),
+ (ephy_tab_class_init), (ephy_tab_get_document_type),
+ (ephy_tab_document_type_cb), (ephy_tab_init):
+ * src/ephy-tab.h:
+ * src/ephy-window.c: (sync_tab_document_type), (sync_tab_zoom),
+ (ephy_window_set_active_tab):
+ * src/toolbar.c: (toolbar_update_zoom):
+ * src/toolbar.h:
+
+ Disable Zoom items for images, and disable zoom, encoding and view source
+ for images and xml (xul) documents. Fixes bug #132240.
+
2004-12-17 Christian Persch <chpe@cvs.gnome.org>
* src/ephy-main.c: (handle_email):
diff --git a/embed/ephy-embed.c b/embed/ephy-embed.c
index a8476cd5c..5e43262f6 100644
--- a/embed/ephy-embed.c
+++ b/embed/ephy-embed.c
@@ -31,9 +31,9 @@ static void ephy_embed_base_init (gpointer g_class);
GType
ephy_embed_chrome_get_type (void)
{
- static GType etype = 0;
+ static GType type = 0;
- if (etype == 0)
+ if (G_UNLIKELY (type == 0))
{
static const GFlagsValue values[] =
{
@@ -44,10 +44,32 @@ ephy_embed_chrome_get_type (void)
{ 0, NULL, NULL }
};
- etype = g_flags_register_static ("EphyEmbedChrome", values);
+ type = g_flags_register_static ("EphyEmbedChrome", values);
+ }
+
+ return type;
+}
+
+GType
+ephy_embed_document_type_get_type (void)
+{
+ static GType type = 0;
+
+ if (G_UNLIKELY (type == 0))
+ {
+ static const GEnumValue values[] =
+ {
+ { EMBED_DOCUMENT_HTML, "EMBED_DOCUMENT_HTML", "html" },
+ { EMBED_DOCUMENT_XML, "EMBED_DOCUMENT_XML", "xml" },
+ { EMBED_DOCUMENT_IMAGE, "EMBED_DOCUMENT_IMAGE", "image" },
+ { EMBED_DOCUMENT_OTHER, "EMBED_DOCUMENT_OTHER", "other" },
+ { 0, NULL, NULL }
+ };
+
+ type = g_enum_register_static ("EphyEmbedDocumentType", values);
}
- return etype;
+ return type;
}
GType
@@ -129,7 +151,7 @@ ephy_embed_base_init (gpointer g_class)
g_signal_new ("ge_context_menu",
EPHY_TYPE_EMBED,
G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (EphyEmbedIface, context_menu),
+ G_STRUCT_OFFSET (EphyEmbedIface, dom_context_menu),
g_signal_accumulator_true_handled, NULL,
ephy_marshal_BOOLEAN__OBJECT,
G_TYPE_BOOLEAN,
@@ -318,6 +340,23 @@ ephy_embed_base_init (gpointer g_class)
G_TYPE_NONE,
0);
+/**
+ * EphyEmbed::ge-document-type:
+ * @embed:
+ * @type: the new document type
+ *
+ * The ::ge-document-type signal is emitted when @embed determines the type of its document.
+ **/
+ g_signal_new ("ge_document_type",
+ EPHY_TYPE_EMBED,
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (EphyEmbedIface, document_type),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__ENUM,
+ G_TYPE_NONE,
+ 1,
+ EPHY_TYPE_EMBED_DOCUMENT_TYPE);
+
initialized = TRUE;
}
}
diff --git a/embed/ephy-embed.h b/embed/ephy-embed.h
index c3d5a1a88..ab0a900d7 100644
--- a/embed/ephy-embed.h
+++ b/embed/ephy-embed.h
@@ -37,6 +37,7 @@ G_BEGIN_DECLS
#define EPHY_EMBED_GET_IFACE(inst) (G_TYPE_INSTANCE_GET_INTERFACE ((inst), EPHY_TYPE_EMBED, EphyEmbedIface))
#define EPHY_TYPE_EMBED_CHROME_MASK (ephy_embed_chrome_get_type ())
+#define EPHY_TYPE_EMBED_DOCUMENT_TYPE (ephy_embed_document_type_get_type ())
typedef struct _EphyEmbed EphyEmbed;
typedef struct _EphyEmbedIface EphyEmbedIface;
@@ -88,6 +89,14 @@ typedef enum
STATE_IS_SECURE_HIGH
} EmbedSecurityLevel;
+typedef enum
+{
+ EMBED_DOCUMENT_HTML,
+ EMBED_DOCUMENT_XML,
+ EMBED_DOCUMENT_IMAGE,
+ EMBED_DOCUMENT_OTHER
+} EmbedDocumentType;
+
struct _EphyEmbedIface
{
GTypeInterface base_iface;
@@ -133,6 +142,8 @@ struct _EphyEmbedIface
const char *uri);
gboolean (* modal_alert) (EphyEmbed *embed);
void (* modal_alert_closed) (EphyEmbed *embed);
+ void (* document_type) (EphyEmbed *embed,
+ EmbedDocumentType type);
/* Methods */
void (* load_url) (EphyEmbed *embed,
@@ -192,6 +203,8 @@ struct _EphyEmbedIface
GType ephy_embed_chrome_get_type (void);
+GType ephy_embed_document_type_get_type (void);
+
GType ephy_embed_get_type (void);
/* Base */
diff --git a/embed/mozilla/EphyBrowser.cpp b/embed/mozilla/EphyBrowser.cpp
index 8dffaa74d..2894b6e56 100644
--- a/embed/mozilla/EphyBrowser.cpp
+++ b/embed/mozilla/EphyBrowser.cpp
@@ -73,8 +73,11 @@
#include "nsIScriptSecurityManager.h"
#include "nsIServiceManager.h"
#include "nsIInterfaceRequestor.h"
+#include <nsIDOMHTMLDocument.h>
+#include <nsIDOMXMLDocument.h>
#ifdef ALLOW_PRIVATE_API
+#include <content/nsIImageDocument.h>
/* not frozen yet */
#include "nsIContentPolicy.h"
/* will never be frozen */
@@ -1129,3 +1132,33 @@ EphyBrowser::ShowCertificate ()
return NS_OK;
#endif
}
+
+EmbedDocumentType
+EphyBrowser::GetDocumentType ()
+{
+ EmbedDocumentType type = EMBED_DOCUMENT_OTHER;
+
+ nsresult rv;
+ nsCOMPtr<nsIDOMDocument> domDoc;
+ rv = GetDocument (getter_AddRefs (domDoc));
+ NS_ENSURE_SUCCESS (rv, type);
+
+ nsCOMPtr<nsIDOMHTMLDocument> htmlDoc (do_QueryInterface (domDoc));
+ nsCOMPtr<nsIDOMXMLDocument> xmlDoc (do_QueryInterface (domDoc));
+ nsCOMPtr<nsIImageDocument> imgDoc (do_QueryInterface (domDoc));
+
+ if (xmlDoc)
+ {
+ type = EMBED_DOCUMENT_XML;
+ }
+ else if (imgDoc)
+ {
+ type = EMBED_DOCUMENT_IMAGE;
+ }
+ else if (htmlDoc)
+ {
+ type = EMBED_DOCUMENT_HTML;
+ }
+
+ return type;
+}
diff --git a/embed/mozilla/EphyBrowser.h b/embed/mozilla/EphyBrowser.h
index 56962d183..05e93235e 100644
--- a/embed/mozilla/EphyBrowser.h
+++ b/embed/mozilla/EphyBrowser.h
@@ -147,6 +147,8 @@ public:
nsresult GetSecurityInfo (PRUint32 *aState, nsACString &aDescription);
nsresult ShowCertificate ();
+ EmbedDocumentType GetDocumentType ();
+
nsCOMPtr<nsIWebBrowser> mWebBrowser;
private:
GtkWidget *mEmbed;
diff --git a/embed/mozilla/mozilla-embed.cpp b/embed/mozilla/mozilla-embed.cpp
index fd71b5cb9..4a33a80ff 100644
--- a/embed/mozilla/mozilla-embed.cpp
+++ b/embed/mozilla/mozilla-embed.cpp
@@ -789,6 +789,13 @@ update_load_state (MozillaEmbed *membed, gint state)
{
MozillaEmbedPrivate *priv = membed->priv;
+ if (state & GTK_MOZ_EMBED_FLAG_IS_DOCUMENT &&
+ state & (GTK_MOZ_EMBED_FLAG_START | GTK_MOZ_EMBED_FLAG_STOP))
+ {
+ g_signal_emit_by_name (membed, "ge-document-type",
+ priv->browser->GetDocumentType ());
+ }
+
if (state & GTK_MOZ_EMBED_FLAG_IS_NETWORK)
{
if (state & GTK_MOZ_EMBED_FLAG_START)
diff --git a/src/ephy-tab.c b/src/ephy-tab.c
index f6e20e6d4..1cce14579 100644
--- a/src/ephy-tab.c
+++ b/src/ephy-tab.c
@@ -85,6 +85,7 @@ struct _EphyTabPrivate
GSList *hidden_popups;
GSList *shown_popups;
TabNavigationFlags nav_flags;
+ EmbedDocumentType document_type;
};
static void ephy_tab_class_init (EphyTabClass *klass);
@@ -95,6 +96,7 @@ enum
{
PROP_0,
PROP_ADDRESS,
+ PROP_DOCUMENT_TYPE,
PROP_ICON,
PROP_LOAD_PROGRESS,
PROP_LOAD_STATUS,
@@ -190,6 +192,7 @@ ephy_tab_set_property (GObject *object,
ephy_tab_set_popups_allowed
(tab, g_value_get_boolean (value));
break;
+ case PROP_DOCUMENT_TYPE:
case PROP_ICON:
case PROP_LOAD_PROGRESS:
case PROP_LOAD_STATUS:
@@ -218,6 +221,9 @@ ephy_tab_get_property (GObject *object,
case PROP_ADDRESS:
g_value_set_string (value, tab->priv->address);
break;
+ case PROP_DOCUMENT_TYPE:
+ g_value_set_enum (value, tab->priv->document_type);
+ break;
case PROP_ICON:
g_value_set_string (value, tab->priv->icon_address);
break;
@@ -352,6 +358,15 @@ ephy_tab_class_init (EphyTabClass *class)
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
+ PROP_DOCUMENT_TYPE,
+ g_param_spec_enum ("document-type",
+ "Document Type",
+ "The tab's documen type",
+ EPHY_TYPE_EMBED_DOCUMENT_TYPE,
+ EMBED_DOCUMENT_HTML,
+ G_PARAM_READABLE));
+
+ g_object_class_install_property (object_class,
PROP_ICON,
g_param_spec_string ("icon",
"Icon address",
@@ -783,6 +798,22 @@ ephy_tab_set_load_status (EphyTab *tab, gboolean status)
}
/**
+ * ephy_tab_get_document_type:
+ * @tab: an #EphyTab
+ *
+ * Returns the type of the document loaded in @tab.
+ *
+ * Return value: the #EmbedDocumentType
+ **/
+EmbedDocumentType
+ephy_tab_get_document_type (EphyTab *tab)
+{
+ g_return_val_if_fail (EPHY_IS_TAB (tab), EMBED_DOCUMENT_OTHER);
+
+ return tab->priv->document_type;
+}
+
+/**
* ephy_tab_get_load_status:
* @tab: an #EphyTab
*
@@ -1050,6 +1081,19 @@ ephy_tab_content_change_cb (EphyEmbed *embed, const char *address, EphyTab *tab)
}
static void
+ephy_tab_document_type_cb (EphyEmbed *embed,
+ EmbedDocumentType type,
+ EphyTab *tab)
+{
+ if (tab->priv->document_type != type)
+ {
+ tab->priv->document_type = type;
+g_print ("new doc type %d\n", type);
+ g_object_notify (G_OBJECT (tab), "document-type");
+ }
+}
+
+static void
ephy_tab_zoom_changed_cb (EphyEmbed *embed, float zoom, EphyTab *tab)
{
char *address;
@@ -1557,6 +1601,7 @@ ephy_tab_init (EphyTab *tab)
tab->priv->load_percent = 0;
tab->priv->load_status = FALSE;
tab->priv->security_level = STATE_IS_UNKNOWN;
+ tab->priv->document_type = EMBED_DOCUMENT_HTML;
tab->priv->zoom = 1.0;
tab->priv->address_expire = TAB_ADDRESS_EXPIRE_NOW;
@@ -1581,6 +1626,9 @@ ephy_tab_init (EphyTab *tab)
g_signal_connect_object (embed, "link_message",
G_CALLBACK (ephy_tab_link_message_cb),
tab, 0);
+ g_signal_connect_object (embed, "ge_document_type",
+ G_CALLBACK (ephy_tab_document_type_cb),
+ tab, 0);
g_signal_connect_object (embed, "ge_location",
G_CALLBACK (ephy_tab_address_cb),
tab, 0);
diff --git a/src/ephy-tab.h b/src/ephy-tab.h
index b94ec81eb..133fe4ccc 100644
--- a/src/ephy-tab.h
+++ b/src/ephy-tab.h
@@ -76,6 +76,8 @@ EphyEmbed *ephy_tab_get_embed (EphyTab *tab);
EphyTab *ephy_tab_for_embed (EphyEmbed *embed);
+EmbedDocumentType ephy_tab_get_document_type (EphyTab *tab);
+
const char *ephy_tab_get_icon_address (EphyTab *tab);
gboolean ephy_tab_get_load_status (EphyTab *tab);
diff --git a/src/ephy-window.c b/src/ephy-window.c
index 3c08bf238..75ab35961 100644
--- a/src/ephy-window.c
+++ b/src/ephy-window.c
@@ -82,6 +82,9 @@ static void ephy_window_view_bookmarksbar_cb (GtkAction *action,
EphyWindow *window);
static void ephy_window_view_popup_windows_cb (GtkAction *action,
EphyWindow *window);
+static void sync_tab_zoom (EphyTab *tab,
+ GParamSpec *pspec,
+ EphyWindow *window);
static GtkActionEntry ephy_menu_entries [] = {
@@ -1208,6 +1211,36 @@ sync_tab_address (EphyTab *tab, GParamSpec *pspec, EphyWindow *window)
}
static void
+sync_tab_document_type (EphyTab *tab,
+ GParamSpec *pspec,
+ EphyWindow *window)
+{
+ GtkActionGroup *action_group;
+ GtkAction *action;
+ EmbedDocumentType type;
+ gboolean can_find, enable;
+
+ /* update zoom actions */
+ sync_tab_zoom (tab, NULL, window);
+
+ type = ephy_tab_get_document_type (tab);
+ can_find = (type != EMBED_DOCUMENT_IMAGE);
+ enable = (type == EMBED_DOCUMENT_HTML);
+
+ action_group = window->priv->action_group;
+ action = gtk_action_group_get_action (action_group, "ViewEncoding");
+ g_object_set (action, "sensitive", enable, NULL);
+ action = gtk_action_group_get_action (action_group, "ViewPageSource");
+ g_object_set (action, "sensitive", enable, NULL);
+ action = gtk_action_group_get_action (action_group, "EditFind");
+ g_object_set (action, "sensitive", can_find, NULL);
+ action = gtk_action_group_get_action (action_group, "EditFindNext");
+ g_object_set (action, "sensitive", can_find, NULL);
+ action = gtk_action_group_get_action (action_group, "EditFindPrev");
+ g_object_set (action, "sensitive", can_find, NULL);
+}
+
+static void
sync_tab_icon (EphyTab *tab, GParamSpec *pspec, EphyWindow *window)
{
const char *address;
@@ -1507,12 +1540,15 @@ sync_tab_zoom (EphyTab *tab, GParamSpec *pspec, EphyWindow *window)
{
GtkActionGroup *action_group;
GtkAction *action;
- gboolean can_zoom_in = TRUE, can_zoom_out = TRUE, can_zoom_normal = FALSE;
+ EmbedDocumentType type;
+ gboolean can_zoom_in = TRUE, can_zoom_out = TRUE, can_zoom_normal = FALSE, can_zoom;
float zoom;
if (window->priv->closing) return;
zoom = ephy_tab_get_zoom (tab);
+ type = ephy_tab_get_document_type (tab);
+ can_zoom = (type != EMBED_DOCUMENT_IMAGE);
if (zoom >= ZOOM_MAXIMAL)
{
@@ -1527,15 +1563,15 @@ sync_tab_zoom (EphyTab *tab, GParamSpec *pspec, EphyWindow *window)
can_zoom_normal = TRUE;
}
- toolbar_update_zoom (window->priv->toolbar, zoom);
+ toolbar_update_zoom (window->priv->toolbar, can_zoom, zoom);
action_group = window->priv->action_group;
action = gtk_action_group_get_action (action_group, "ViewZoomIn");
- g_object_set (action, "sensitive", can_zoom_in, NULL);
+ g_object_set (action, "sensitive", can_zoom_in && can_zoom, NULL);
action = gtk_action_group_get_action (action_group, "ViewZoomOut");
- g_object_set (action, "sensitive", can_zoom_out, NULL);
+ g_object_set (action, "sensitive", can_zoom_out && can_zoom, NULL);
action = gtk_action_group_get_action (action_group, "ViewZoomNormal");
- g_object_set (action, "sensitive", can_zoom_normal, NULL);
+ g_object_set (action, "sensitive", can_zoom_normal && can_zoom, NULL);
}
static void
@@ -1833,6 +1869,9 @@ ephy_window_set_active_tab (EphyWindow *window, EphyTab *new_tab)
G_CALLBACK (sync_tab_address),
window);
g_signal_handlers_disconnect_by_func (G_OBJECT (old_tab),
+ G_CALLBACK (sync_tab_document_type),
+ window);
+ g_signal_handlers_disconnect_by_func (G_OBJECT (old_tab),
G_CALLBACK (sync_tab_icon),
window);
g_signal_handlers_disconnect_by_func (G_OBJECT (old_tab),
@@ -1877,6 +1916,7 @@ ephy_window_set_active_tab (EphyWindow *window, EphyTab *new_tab)
if (new_tab)
{
sync_tab_address (new_tab, NULL, window);
+ sync_tab_document_type (new_tab, NULL, window);
sync_tab_icon (new_tab, NULL, window);
sync_tab_load_progress (new_tab, NULL, window);
sync_tab_load_status (new_tab, NULL, window);
@@ -1893,6 +1933,10 @@ ephy_window_set_active_tab (EphyWindow *window, EphyTab *new_tab)
G_CALLBACK (sync_tab_address),
window, 0);
g_signal_connect_object (G_OBJECT (new_tab),
+ "notify::document-type",
+ G_CALLBACK (sync_tab_document_type),
+ window, 0);
+ g_signal_connect_object (G_OBJECT (new_tab),
"notify::icon",
G_CALLBACK (sync_tab_icon),
window, 0);
diff --git a/src/toolbar.c b/src/toolbar.c
index d93eee48f..2e2424a12 100755
--- a/src/toolbar.c
+++ b/src/toolbar.c
@@ -639,14 +639,18 @@ toolbar_update_navigation_actions (Toolbar *t, gboolean back, gboolean forward,
}
void
-toolbar_update_zoom (Toolbar *t, float zoom)
+toolbar_update_zoom (Toolbar *t,
+ gboolean can_zoom,
+ float zoom)
{
GtkActionGroup *action_group;
GtkAction *action;
action_group = t->priv->action_group;
action = gtk_action_group_get_action (action_group, "Zoom");
- g_object_set (action, "zoom", zoom, NULL);
+ g_object_set (action, "zoom", can_zoom ? zoom : 1.0,
+ "sensitive", can_zoom,
+ NULL);
}
Toolbar *
diff --git a/src/toolbar.h b/src/toolbar.h
index dc9cb5271..086943d40 100644
--- a/src/toolbar.h
+++ b/src/toolbar.h
@@ -81,6 +81,7 @@ void toolbar_update_navigation_actions (Toolbar *t,
gboolean up);
void toolbar_update_zoom (Toolbar *t,
+ gboolean can_zoom,
float zoom);
G_END_DECLS