From efa0f2876ccd7713cfb09e4dd2c76c837692f267 Mon Sep 17 00:00:00 2001 From: "bryner%uiuc.edu" Date: Mon, 15 May 2000 02:10:11 +0000 Subject: [PATCH] Hook up text enlarge/reduce with ctrl+mousewheel. bug 25427. r=erik@netscape.com. git-svn-id: svn://10.0.0.236/trunk@69719 18797224-902f-48f8-a5cc-f745e15eee43 --- .../events/src/nsEventStateManager.cpp | 80 +++++++++++-------- .../content/events/src/nsEventStateManager.h | 1 + .../layout/events/src/nsEventStateManager.cpp | 80 +++++++++++-------- .../layout/events/src/nsEventStateManager.h | 1 + mozilla/modules/libpref/src/init/all.js | 4 +- 5 files changed, 94 insertions(+), 72 deletions(-) diff --git a/mozilla/content/events/src/nsEventStateManager.cpp b/mozilla/content/events/src/nsEventStateManager.cpp index e7d18425934..7d05aa6fe14 100644 --- a/mozilla/content/events/src/nsEventStateManager.cpp +++ b/mozilla/content/events/src/nsEventStateManager.cpp @@ -66,6 +66,8 @@ #include "nsIDOMXULCommandDispatcher.h" #include "nsIObserverService.h" #include "prlog.h" +#include "nsIDocShell.h" +#include "nsIMarkupDocumentViewer.h" //we will use key binding by default now. this wil lbreak viewer for now #define NON_KEYBINDING 0 @@ -692,6 +694,29 @@ nsEventStateManager :: GenerateDragGesture ( nsIPresContext* aPresContext, nsGUI } } // GenerateDragGesture +nsresult +nsEventStateManager::ChangeTextSize(PRInt32 change) +{ + nsCOMPtr pcContainer; + mPresContext->GetContainer(getter_AddRefs(pcContainer)); + NS_ENSURE_TRUE(pcContainer, NS_ERROR_FAILURE); + + nsCOMPtr docshell(do_QueryInterface(pcContainer)); + NS_ENSURE_TRUE(docshell, NS_ERROR_FAILURE); + + nsCOMPtr cv; + docshell->GetContentViewer(getter_AddRefs(cv)); + NS_ENSURE_TRUE(cv, NS_ERROR_FAILURE); + + nsCOMPtr mv(do_QueryInterface(cv)); + NS_ENSURE_TRUE(mv, NS_ERROR_FAILURE); + + float textzoom; + mv->GetTextZoom(&textzoom); + mv->SetTextZoom(textzoom + 0.1*change); + + return NS_OK; +} NS_IMETHODIMP nsEventStateManager::PostHandleEvent(nsIPresContext* aPresContext, @@ -823,6 +848,7 @@ nsEventStateManager::PostHandleEvent(nsIPresContext* aPresContext, switch (action) { case MOUSE_SCROLL_N_LINES: + case MOUSE_SCROLL_PAGE: { nsIView* focusView = nsnull; nsIScrollableView* sv = nsnull; @@ -833,44 +859,29 @@ nsEventStateManager::PostHandleEvent(nsIPresContext* aPresContext, aTargetFrame, aView, sv, sf, focusView))) { - if (sv) - { + if (sv) { + if (action == MOUSE_SCROLL_N_LINES) sv->ScrollByLines(numLines); - ForceViewUpdate(focusView); - } - else if (sf) - sf->ScrollByLines(aPresContext, numLines); - } - // We may end up with a different PresContext than we started with. - // If so, we are done with it now, so release it. - - if (mwPresContext != aPresContext) - NS_RELEASE(mwPresContext); - - } - - break; - - case MOUSE_SCROLL_PAGE: - { - nsIView* focusView = nsnull; - nsIScrollableView* sv = nsnull; - nsISelfScrollingFrame* sf = nsnull; - - if (NS_SUCCEEDED(GetScrollableFrameOrView(aPresContext, aTargetFrame, - aView, sv, sf, focusView))) - { - if (sv) - { + else sv->ScrollByPages((numLines > 0) ? 1 : -1); - ForceViewUpdate(focusView); - } - else if (sf) - sf->ScrollByPages(aPresContext, (numLines > 0) ? 1 : -1); + ForceViewUpdate(focusView); + } else if (sf) { + if (action == MOUSE_SCROLL_N_LINES) + sf->ScrollByLines(aPresContext, numLines); + else + sf->ScrollByPages(aPresContext, (numLines > 0) ? 1 : -1); + } } + + // We may end up with a different PresContext than we started + // with. If so, we are done with it now, so release it. + + if (mwPresContext != aPresContext) + NS_RELEASE(mwPresContext); } + break; - + case MOUSE_SCROLL_HISTORY: { nsCOMPtr pcContainer; @@ -888,9 +899,8 @@ nsEventStateManager::PostHandleEvent(nsIPresContext* aPresContext, break; case MOUSE_SCROLL_TEXTSIZE: - { + ChangeTextSize((numLines > 0) ? 1 : -1); break; - } } *aStatus = nsEventStatus_eConsumeNoDefault; diff --git a/mozilla/content/events/src/nsEventStateManager.h b/mozilla/content/events/src/nsEventStateManager.h index da5907b26aa..fc8b768318b 100644 --- a/mozilla/content/events/src/nsEventStateManager.h +++ b/mozilla/content/events/src/nsEventStateManager.h @@ -132,6 +132,7 @@ protected: nsIView* &focusView); void ForceViewUpdate(nsIView* aView); nsresult getPrefService(); + nsresult ChangeTextSize(PRInt32 change); // end mousewheel functions // routines for the d&d gesture tracking state machine diff --git a/mozilla/layout/events/src/nsEventStateManager.cpp b/mozilla/layout/events/src/nsEventStateManager.cpp index e7d18425934..7d05aa6fe14 100644 --- a/mozilla/layout/events/src/nsEventStateManager.cpp +++ b/mozilla/layout/events/src/nsEventStateManager.cpp @@ -66,6 +66,8 @@ #include "nsIDOMXULCommandDispatcher.h" #include "nsIObserverService.h" #include "prlog.h" +#include "nsIDocShell.h" +#include "nsIMarkupDocumentViewer.h" //we will use key binding by default now. this wil lbreak viewer for now #define NON_KEYBINDING 0 @@ -692,6 +694,29 @@ nsEventStateManager :: GenerateDragGesture ( nsIPresContext* aPresContext, nsGUI } } // GenerateDragGesture +nsresult +nsEventStateManager::ChangeTextSize(PRInt32 change) +{ + nsCOMPtr pcContainer; + mPresContext->GetContainer(getter_AddRefs(pcContainer)); + NS_ENSURE_TRUE(pcContainer, NS_ERROR_FAILURE); + + nsCOMPtr docshell(do_QueryInterface(pcContainer)); + NS_ENSURE_TRUE(docshell, NS_ERROR_FAILURE); + + nsCOMPtr cv; + docshell->GetContentViewer(getter_AddRefs(cv)); + NS_ENSURE_TRUE(cv, NS_ERROR_FAILURE); + + nsCOMPtr mv(do_QueryInterface(cv)); + NS_ENSURE_TRUE(mv, NS_ERROR_FAILURE); + + float textzoom; + mv->GetTextZoom(&textzoom); + mv->SetTextZoom(textzoom + 0.1*change); + + return NS_OK; +} NS_IMETHODIMP nsEventStateManager::PostHandleEvent(nsIPresContext* aPresContext, @@ -823,6 +848,7 @@ nsEventStateManager::PostHandleEvent(nsIPresContext* aPresContext, switch (action) { case MOUSE_SCROLL_N_LINES: + case MOUSE_SCROLL_PAGE: { nsIView* focusView = nsnull; nsIScrollableView* sv = nsnull; @@ -833,44 +859,29 @@ nsEventStateManager::PostHandleEvent(nsIPresContext* aPresContext, aTargetFrame, aView, sv, sf, focusView))) { - if (sv) - { + if (sv) { + if (action == MOUSE_SCROLL_N_LINES) sv->ScrollByLines(numLines); - ForceViewUpdate(focusView); - } - else if (sf) - sf->ScrollByLines(aPresContext, numLines); - } - // We may end up with a different PresContext than we started with. - // If so, we are done with it now, so release it. - - if (mwPresContext != aPresContext) - NS_RELEASE(mwPresContext); - - } - - break; - - case MOUSE_SCROLL_PAGE: - { - nsIView* focusView = nsnull; - nsIScrollableView* sv = nsnull; - nsISelfScrollingFrame* sf = nsnull; - - if (NS_SUCCEEDED(GetScrollableFrameOrView(aPresContext, aTargetFrame, - aView, sv, sf, focusView))) - { - if (sv) - { + else sv->ScrollByPages((numLines > 0) ? 1 : -1); - ForceViewUpdate(focusView); - } - else if (sf) - sf->ScrollByPages(aPresContext, (numLines > 0) ? 1 : -1); + ForceViewUpdate(focusView); + } else if (sf) { + if (action == MOUSE_SCROLL_N_LINES) + sf->ScrollByLines(aPresContext, numLines); + else + sf->ScrollByPages(aPresContext, (numLines > 0) ? 1 : -1); + } } + + // We may end up with a different PresContext than we started + // with. If so, we are done with it now, so release it. + + if (mwPresContext != aPresContext) + NS_RELEASE(mwPresContext); } + break; - + case MOUSE_SCROLL_HISTORY: { nsCOMPtr pcContainer; @@ -888,9 +899,8 @@ nsEventStateManager::PostHandleEvent(nsIPresContext* aPresContext, break; case MOUSE_SCROLL_TEXTSIZE: - { + ChangeTextSize((numLines > 0) ? 1 : -1); break; - } } *aStatus = nsEventStatus_eConsumeNoDefault; diff --git a/mozilla/layout/events/src/nsEventStateManager.h b/mozilla/layout/events/src/nsEventStateManager.h index da5907b26aa..fc8b768318b 100644 --- a/mozilla/layout/events/src/nsEventStateManager.h +++ b/mozilla/layout/events/src/nsEventStateManager.h @@ -132,6 +132,7 @@ protected: nsIView* &focusView); void ForceViewUpdate(nsIView* aView); nsresult getPrefService(); + nsresult ChangeTextSize(PRInt32 change); // end mousewheel functions // routines for the d&d gesture tracking state machine diff --git a/mozilla/modules/libpref/src/init/all.js b/mozilla/modules/libpref/src/init/all.js index 0bcbdf0776b..47212571f8e 100644 --- a/mozilla/modules/libpref/src/init/all.js +++ b/mozilla/modules/libpref/src/init/all.js @@ -501,11 +501,11 @@ pref("security.policy.default.window.scriptglobals", "sameOrigin"); pref("middlemouse.paste", false); pref("middlemouse.openNewWindow", false); -/* 0=lines, 1=pages, 2=history */ +/* 0=lines, 1=pages, 2=history , 3=text size */ pref("mousewheel.withnokey.action",0); pref("mousewheel.withnokey.numlines",1); pref("mousewheel.withnokey.sysnumlines",true); -pref("mousewheel.withcontrolkey.action",1); +pref("mousewheel.withcontrolkey.action",3); pref("mousewheel.withcontrolkey.numlines",1); pref("mousewheel.withcontrolkey.sysnumlines",false); pref("mousewheel.withshiftkey.action",0);