aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog13
-rw-r--r--data/default-prefs-common.js7
-rw-r--r--embed/mozilla/EphyBrowser.cpp55
-rw-r--r--embed/mozilla/EphyBrowser.h10
-rw-r--r--lib/ephy-zoom.c8
-rw-r--r--lib/ephy-zoom.h5
6 files changed, 90 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index 8ba005378..726b03991 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,18 @@
2005-05-31 Christian Persch <chpe@cvs.gnome.org>
+ * data/default-prefs-common.js:
+ * embed/mozilla/EphyBrowser.cpp:
+ * embed/mozilla/EphyBrowser.h:
+
+ Add scroll event listener, and change zoom on scroll+wheel events.
+
+ * lib/ephy-zoom.c: (ephy_zoom_get_changed_zoom_level):
+ * lib/ephy-zoom.h:
+
+ Fix signed/unsigned integer problems (underflow).
+
+2005-05-31 Christian Persch <chpe@cvs.gnome.org>
+
* src/ephy-notebook.c: (ephy_notebook_move_tab),
(move_tab_to_another_notebook), (button_release_cb):
* src/ephy-window.c: (update_tabs_menu_sensitivity):
diff --git a/data/default-prefs-common.js b/data/default-prefs-common.js
index 4475ff41e..e1995086f 100644
--- a/data/default-prefs-common.js
+++ b/data/default-prefs-common.js
@@ -1,7 +1,10 @@
-// mouse wheel
-pref("mousewheel.withcontrolkey.action", 1);
+// mouse wheel: disable mozilla's ctrl+wheel zooming
+// bug: setting this to -1 does not disable the built-in action, but instead
+// prevents event delivery at all!
+pref("mousewheel.withcontrolkey.action", 0);
pref("mousewheel.withcontrolkey.numlines", 1);
pref("mousewheel.withcontrolkey.sysnumlines", false);
+
// fix horizontal scroll with 2nd wheel, see bug #148557
pref("mousewheel.horizscroll.withnokey.action", 0);
pref("mousewheel.horizscroll.withnokey.sysnumlines", true);
diff --git a/embed/mozilla/EphyBrowser.cpp b/embed/mozilla/EphyBrowser.cpp
index 24258db6b..5266a5ece 100644
--- a/embed/mozilla/EphyBrowser.cpp
+++ b/embed/mozilla/EphyBrowser.cpp
@@ -28,6 +28,7 @@
#include "EventContext.h"
#include "ephy-embed.h"
#include "ephy-string.h"
+#include "ephy-zoom.h"
#include "ephy-debug.h"
#include "print-dialog.h"
#include "mozilla-embed.h"
@@ -102,6 +103,7 @@
const static PRUnichar kDOMLinkAdded[] = { 'D', 'O', 'M', 'L', 'i', 'n', 'k', 'A', 'd', 'd', 'e', 'd', '\0' };
const static PRUnichar kDOMContentLoaded[] = { 'D', 'O', 'M', 'C', 'o', 'n', 't', 'e', 'n', 't', 'L', 'o', 'a', 'd', 'e', 'd', '\0' };
const static PRUnichar kContextMenu[] = { 'c', 'o', 'n', 't', 'e', 'x', 't', 'm', 'e', 'n', 'u', '\0' };
+const static PRUnichar kDOMMouseScroll[] = { 'D', 'O', 'M', 'M', 'o', 'u', 's', 'e', 'S', 'c', 'r', 'o', 'l', 'l', '\0' };
const static PRUnichar kDOMPopupBlocked[] = { 'D', 'O', 'M', 'P', 'o', 'p', 'u', 'p', 'B', 'l', 'o', 'c', 'k', 'e', 'd', '\0' };
const static PRUnichar kDOMWillOpenModalDialog[] = { 'D', 'O', 'M', 'W', 'i', 'l', 'l', 'O', 'p', 'e', 'n', 'M', 'o', 'd', 'a', 'l', 'D', 'i', 'a', 'l', 'o', 'g', '\0' };
const static PRUnichar kDOMModalDialogClosed[] = { 'D', 'O', 'M', 'M', 'o', 'd', 'a', 'l', 'D', 'i', 'a', 'l', 'o', 'g', 'C', 'l', 'o', 's', 'e', 'd', '\0' };
@@ -387,6 +389,49 @@ EphyModalAlertEventListener::HandleEvent (nsIDOMEvent * aDOMEvent)
return NS_OK;
}
+NS_IMETHODIMP
+EphyDOMScrollEventListener::HandleEvent (nsIDOMEvent * aEvent)
+{
+ /* make sure the event is trusted */
+ nsresult rv;
+ nsCOMPtr<nsIDOMNSEvent> nsEvent (do_QueryInterface (aEvent, &rv));
+ NS_ENSURE_SUCCESS (rv, rv);
+ PRBool isTrusted = PR_FALSE;
+ nsEvent->GetIsTrusted (&isTrusted);
+ if (!isTrusted) return NS_OK;
+
+ nsCOMPtr<nsIDOMMouseEvent> mouseEvent (do_QueryInterface (aEvent, &rv));
+ NS_ENSURE_SUCCESS (rv, rv);
+
+ PRBool isAlt = PR_FALSE, isControl = PR_FALSE, isShift = PR_FALSE;
+ mouseEvent->GetAltKey (&isAlt);
+ mouseEvent->GetCtrlKey (&isControl);
+ mouseEvent->GetShiftKey (&isShift);
+ /* GetMetaKey is always false on gtk2 mozilla */
+
+ if (isControl && !isAlt && !isShift)
+ {
+ PRInt32 detail = 0;
+ mouseEvent->GetDetail(&detail);
+
+ float zoom, new_zoom;
+ rv = mOwner->GetZoom (&zoom);
+ NS_ENSURE_SUCCESS (rv, rv);
+
+ zoom = ephy_zoom_get_changed_zoom_level (zoom, detail > 0 ? 1 : detail < 0 ? -1 : 0);
+ rv = mOwner->SetZoom (zoom);
+ if (NS_SUCCEEDED (rv))
+ {
+ g_signal_emit_by_name (mOwner->mEmbed, "ge_zoom_change", zoom);
+ }
+
+ /* we consumed the event */
+ aEvent->PreventDefault();
+ }
+
+ return NS_OK;
+}
+
NS_IMPL_ISUPPORTS1(EphyContextMenuListener, nsIDOMContextMenuListener)
NS_IMETHODIMP
@@ -465,6 +510,7 @@ EphyContextMenuListener::HandleEvent (nsIDOMEvent* aDOMEvent)
EphyBrowser::EphyBrowser ()
: mDOMLinkEventListener(nsnull)
, mDOMContentLoadedEventListener(nsnull)
+, mDOMScrollEventListener(nsnull)
, mPopupBlockEventListener(nsnull)
, mModalAlertListener(nsnull)
, mContextMenuListener(nsnull)
@@ -503,6 +549,9 @@ nsresult EphyBrowser::Init (GtkMozEmbed *mozembed)
mDOMContentLoadedEventListener = new EphyDOMContentLoadedEventListener(this);
if (!mDOMContentLoadedEventListener) return NS_ERROR_OUT_OF_MEMORY;
+ mDOMScrollEventListener = new EphyDOMScrollEventListener(this);
+ if (!mDOMScrollEventListener) return NS_ERROR_OUT_OF_MEMORY;
+
mPopupBlockEventListener = new EphyPopupBlockEventListener(this);
if (!mPopupBlockEventListener) return NS_ERROR_OUT_OF_MEMORY;
@@ -601,10 +650,14 @@ EphyBrowser::AttachListeners(void)
mDOMLinkEventListener, PR_FALSE);
rv |= mEventTarget->AddEventListener(nsEmbedString(kDOMContentLoaded),
mDOMContentLoadedEventListener, PR_FALSE);
+ rv |= mEventTarget->AddEventListener(nsEmbedString(kDOMMouseScroll),
+ mDOMScrollEventListener, PR_TRUE); /* capture */
rv |= mEventTarget->AddEventListener(nsEmbedString(kDOMPopupBlocked),
mPopupBlockEventListener, PR_FALSE);
rv |= mEventTarget->AddEventListener(nsEmbedString(kDOMWillOpenModalDialog),
mModalAlertListener, PR_TRUE);
+ rv |= mEventTarget->AddEventListener(nsEmbedString(kDOMMouseScroll),
+ mDOMScrollEventListener, PR_TRUE);
rv |= mEventTarget->AddEventListener(nsEmbedString(kDOMModalDialogClosed),
mModalAlertListener, PR_TRUE);
rv |= mEventTarget->AddEventListener(nsEmbedString(kContextMenu),
@@ -624,6 +677,8 @@ EphyBrowser::DetachListeners(void)
mDOMLinkEventListener, PR_FALSE);
rv |= mEventTarget->RemoveEventListener(nsEmbedString(kDOMContentLoaded),
mDOMContentLoadedEventListener, PR_FALSE);
+ rv |= mEventTarget->RemoveEventListener(nsEmbedString(kDOMMouseScroll),
+ mDOMScrollEventListener, PR_TRUE); /* capture */
rv |= mEventTarget->RemoveEventListener(nsEmbedString(kDOMPopupBlocked),
mPopupBlockEventListener, PR_FALSE);
rv |= mEventTarget->RemoveEventListener(nsEmbedString(kDOMWillOpenModalDialog),
diff --git a/embed/mozilla/EphyBrowser.h b/embed/mozilla/EphyBrowser.h
index 159f449b3..77f2923a6 100644
--- a/embed/mozilla/EphyBrowser.h
+++ b/embed/mozilla/EphyBrowser.h
@@ -100,6 +100,14 @@ public:
EphyDOMContentLoadedEventListener(EphyBrowser *aOwner) : EphyEventListener(aOwner) { };
};
+class EphyDOMScrollEventListener : public EphyEventListener
+{
+public:
+ NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent);
+
+ EphyDOMScrollEventListener(EphyBrowser *aOwner) : EphyEventListener(aOwner) { };
+};
+
class EphyContextMenuListener : public nsIDOMContextMenuListener
{
public:
@@ -121,6 +129,7 @@ class EphyBrowser
friend class EphyEventListener;
friend class EphyDOMLinkEventListener;
friend class EphyDOMContentLoadedEventListener;
+friend class EphyDOMScrollEventListener;
friend class EphyPopupBlockEventListener;
friend class EphyModalAlertEventListener;
friend class EphyContextMenuListener;
@@ -186,6 +195,7 @@ private:
nsCOMPtr<nsIDOMWindow> mDOMWindow;
EphyDOMLinkEventListener *mDOMLinkEventListener;
EphyDOMContentLoadedEventListener *mDOMContentLoadedEventListener;
+ EphyDOMScrollEventListener *mDOMScrollEventListener;
EphyPopupBlockEventListener *mPopupBlockEventListener;
EphyModalAlertEventListener *mModalAlertListener;
EphyContextMenuListener *mContextMenuListener;
diff --git a/lib/ephy-zoom.c b/lib/ephy-zoom.c
index b6cf8c68b..00fd34aae 100644
--- a/lib/ephy-zoom.c
+++ b/lib/ephy-zoom.c
@@ -24,7 +24,7 @@
#include <math.h>
-guint
+int
ephy_zoom_get_zoom_level_index (float level)
{
guint i;
@@ -47,12 +47,12 @@ ephy_zoom_get_zoom_level_index (float level)
float
-ephy_zoom_get_changed_zoom_level (float level, gint steps)
+ephy_zoom_get_changed_zoom_level (float level, int steps)
{
- guint index;
+ int index;
index = ephy_zoom_get_zoom_level_index (level);
- return zoom_levels[CLAMP(index + steps, 0, n_zoom_levels - 1)].level;
+ return zoom_levels[CLAMP(index + steps, 0, (int) n_zoom_levels - 1)].level;
}
float ephy_zoom_get_nearest_zoom_level (float level)
diff --git a/lib/ephy-zoom.h b/lib/ephy-zoom.h
index a6853eeae..b8491329c 100644
--- a/lib/ephy-zoom.h
+++ b/lib/ephy-zoom.h
@@ -55,9 +55,10 @@ static const guint n_zoom_levels = G_N_ELEMENTS (zoom_levels);
#define ZOOM_IN (-1.0)
#define ZOOM_OUT (-2.0)
-guint ephy_zoom_get_zoom_level_index (float level);
+int ephy_zoom_get_zoom_level_index (float level);
-float ephy_zoom_get_changed_zoom_level (float level, gint steps);
+float ephy_zoom_get_changed_zoom_level (float level,
+ int steps);
float ephy_zoom_get_nearest_zoom_level (float level);