Bug 719320 part.5 Redesign mouse wheel action prefs r=smaug

This commit is contained in:
Masayuki Nakano 2012-08-12 10:42:35 +09:00
parent 08a826f3e2
commit 0920874b2c
6 changed files with 145 additions and 133 deletions

View File

@ -510,20 +510,23 @@ pref("browser.gesture.twist.right", "");
pref("browser.gesture.twist.left", "");
pref("browser.gesture.tap", "cmd_fullZoomReset");
// 0=lines, 1=pages, 2=history , 3=text size
// 0: Nothing happens
// 1: Scrolling contents
// 2: Go back or go forward, in your history
// 3: Zoom in or out.
#ifdef XP_MACOSX
// On OS X, if the wheel has one axis only, shift+wheel comes through as a
// horizontal scroll event. Thus, we can't assign anything other than normal
// scrolling to shift+wheel.
pref("mousewheel.withshiftkey.action",0);
pref("mousewheel.withaltkey.action",2);
pref("mousewheel.withmetakey.action",0);
pref("mousewheel.with_alt.action", 2);
pref("mousewheel.with_shift.action", 1);
#else
pref("mousewheel.withshiftkey.action",2);
pref("mousewheel.withaltkey.action",0);
pref("mousewheel.withmetakey.action",0);
pref("mousewheel.with_alt.action", 1);
pref("mousewheel.with_shift.action", 2);
#endif
pref("mousewheel.withcontrolkey.action",3);
pref("mousewheel.with_control.action",3);
pref("mousewheel.with_meta.action", 1); // command key on Mac
pref("mousewheel.with_win.action", 1);
// pref to control the alert notification
pref("alerts.slideIncrement", 1);

View File

@ -302,34 +302,6 @@ GetAccessModifierMaskFromPref(PRInt32 aItemType)
}
}
static void
GetBasePrefKeyForMouseWheel(nsMouseScrollEvent* aEvent, nsACString& aPref)
{
NS_NAMED_LITERAL_CSTRING(prefbase, "mousewheel");
NS_NAMED_LITERAL_CSTRING(horizscroll, ".horizscroll");
NS_NAMED_LITERAL_CSTRING(withshift, ".withshiftkey");
NS_NAMED_LITERAL_CSTRING(withalt, ".withaltkey");
NS_NAMED_LITERAL_CSTRING(withcontrol, ".withcontrolkey");
NS_NAMED_LITERAL_CSTRING(withmetakey, ".withmetakey");
NS_NAMED_LITERAL_CSTRING(withno, ".withnokey");
aPref = prefbase;
if (aEvent->scrollFlags & nsMouseScrollEvent::kIsHorizontal) {
aPref.Append(horizscroll);
}
if (aEvent->IsShift()) {
aPref.Append(withshift);
} else if (aEvent->IsControl()) {
aPref.Append(withcontrol);
} else if (aEvent->IsAlt()) {
aPref.Append(withalt);
} else if (aEvent->IsMeta()) {
aPref.Append(withmetakey);
} else {
aPref.Append(withno);
}
}
class nsMouseWheelTransaction {
public:
static nsIFrame* GetTargetFrame() { return sTargetFrame; }
@ -2686,43 +2658,55 @@ nsEventStateManager::SendPixelScrollEvent(nsIFrame* aTargetFrame,
}
PRInt32
nsEventStateManager::ComputeWheelActionFor(nsMouseScrollEvent* aMouseEvent)
nsEventStateManager::ComputeWheelActionFor(nsMouseScrollEvent* aEvent)
{
PRInt32 action = GetWheelActionFor(aMouseEvent);
if (!aMouseEvent->customizedByUserPrefs &&
(aMouseEvent->scrollFlags & nsMouseScrollEvent::kIsFullPage)) {
action = MOUSE_SCROLL_PAGE;
PRInt32 result = -1;
bool isPage =
(aEvent->scrollFlags & nsMouseScrollEvent::kIsFullPage) != 0;
bool isMomentum =
(aEvent->scrollFlags & nsMouseScrollEvent::kIsMomentum) != 0;
bool hasPixel =
(aEvent->scrollFlags & nsMouseScrollEvent::kHasPixels) != 0;
bool isPixel = (aEvent->message == NS_MOUSE_PIXEL_SCROLL);
WheelPrefs::Action action = WheelPrefs::GetInstance()->GetActionFor(aEvent);
if (action == WheelPrefs::ACTION_NONE) {
return -1;
}
if (aMouseEvent->message == NS_MOUSE_PIXEL_SCROLL) {
if (action == MOUSE_SCROLL_N_LINES || action == MOUSE_SCROLL_PAGE ||
(aMouseEvent->scrollFlags & nsMouseScrollEvent::kIsMomentum)) {
action = MOUSE_SCROLL_PIXELS;
} else {
// Do not scroll pixels when zooming
action = -1;
if (action == WheelPrefs::ACTION_SCROLL) {
if (isPixel) {
return MOUSE_SCROLL_PIXELS;
}
} else if (((aMouseEvent->scrollFlags & nsMouseScrollEvent::kHasPixels) &&
(!aMouseEvent->customizedByUserPrefs ||
action == MOUSE_SCROLL_N_LINES || action == MOUSE_SCROLL_PAGE)) ||
((aMouseEvent->scrollFlags & nsMouseScrollEvent::kIsMomentum) &&
(action == MOUSE_SCROLL_HISTORY || action == MOUSE_SCROLL_ZOOM))) {
// Don't scroll lines or page when a pixel scroll event will follow.
// Also, don't do history scrolling or zooming for momentum scrolls,
// no matter what's going on with pixel scrolling.
action = -1;
// Don't need to scroll, will be scrolled by following pixel event.
if (hasPixel) {
return -1;
}
return isPage ? MOUSE_SCROLL_PAGE : MOUSE_SCROLL_N_LINES;
}
return action;
}
// Momentum pixel events shouldn't run special actions.
if (isPixel && isMomentum) {
// Get the default action. Note that user might kill the wheel scrolling.
action = WheelPrefs::GetInstance()->GetActionFor(nullptr);
return (action == WheelPrefs::ACTION_SCROLL) ? MOUSE_SCROLL_PIXELS : -1;
}
PRInt32
nsEventStateManager::GetWheelActionFor(nsMouseScrollEvent* aMouseEvent)
{
nsCAutoString prefName;
GetBasePrefKeyForMouseWheel(aMouseEvent, prefName);
prefName.Append(".action");
return Preferences::GetInt(prefName.get());
// Special actions shouldn't be run by pixel scroll event or momentum events.
if (isMomentum || isPixel) {
return -1;
}
if (action == WheelPrefs::ACTION_HISTORY) {
return MOUSE_SCROLL_HISTORY;
}
if (action == WheelPrefs::ACTION_ZOOM) {
return MOUSE_SCROLL_ZOOM;
}
NS_WARNING("Unsupported wheel action pref value!");
return -1;
}
nsIScrollableFrame*
@ -5232,6 +5216,10 @@ nsEventStateManager::WheelPrefs::Reset()
nsEventStateManager::WheelPrefs::Index
nsEventStateManager::WheelPrefs::GetIndexFor(nsMouseEvent_base* aEvent)
{
if (!aEvent) {
return INDEX_DEFAULT;
}
widget::Modifiers modifiers =
(aEvent->modifiers & (widget::MODIFIER_ALT |
widget::MODIFIER_CONTROL |
@ -5265,23 +5253,23 @@ nsEventStateManager::WheelPrefs::GetBasePrefName(
aBasePrefName.AssignLiteral("mousewheel.");
switch (aIndex) {
case INDEX_ALT:
aBasePrefName.AppendLiteral("withaltkey.");
aBasePrefName.AppendLiteral("with_alt.");
break;
case INDEX_CONTROL:
aBasePrefName.AppendLiteral("withcontrolkey.");
aBasePrefName.AppendLiteral("with_control.");
break;
case INDEX_META:
aBasePrefName.AppendLiteral("withmetakey.");
aBasePrefName.AppendLiteral("with_meta.");
break;
case INDEX_SHIFT:
aBasePrefName.AppendLiteral("withshiftkey.");
aBasePrefName.AppendLiteral("with_shift.");
break;
case INDEX_OS:
aBasePrefName.AppendLiteral("withwinkey.");
aBasePrefName.AppendLiteral("with_win.");
break;
case INDEX_DEFAULT:
default:
aBasePrefName.AppendLiteral("withnokey.");
aBasePrefName.AppendLiteral("default.");
break;
}
}
@ -5313,6 +5301,16 @@ nsEventStateManager::WheelPrefs::Init(
if (mMultiplierY[aIndex] < 1.0 && mMultiplierY[aIndex] > -1.0) {
mMultiplierY[aIndex] = mMultiplierY[aIndex] < 0.0 ? -1.0 : 1.0;
}
nsCAutoString prefNameAction(basePrefName);
prefNameAction.AppendLiteral("action");
mActions[aIndex] =
static_cast<Action>(Preferences::GetInt(prefNameAction.get(),
ACTION_SCROLL));
if (mActions[aIndex] < ACTION_NONE || mActions[aIndex] > ACTION_LAST) {
NS_WARNING("Unsupported action pref value, replaced with 'Scroll'.");
mActions[aIndex] = ACTION_SCROLL;
}
}
void
@ -5334,3 +5332,11 @@ nsEventStateManager::WheelPrefs::ApplyUserPrefsToDelta(
aEvent->customizedByUserPrefs = (mMultiplierY[index] != 1.0);
}
}
nsEventStateManager::WheelPrefs::Action
nsEventStateManager::WheelPrefs::GetActionFor(nsMouseScrollEvent* aEvent)
{
Index index = GetIndexFor(aEvent);
Init(index);
return mActions[index];
}

View File

@ -330,6 +330,19 @@ protected:
*/
void ApplyUserPrefsToDelta(nsMouseScrollEvent* aEvent);
/**
* Gets the wheel action for the aMouseEvent from the pref.
*/
enum Action
{
ACTION_NONE = 0,
ACTION_SCROLL,
ACTION_HISTORY,
ACTION_ZOOM,
ACTION_LAST = ACTION_ZOOM
};
Action GetActionFor(nsMouseScrollEvent* aMouseEvent);
private:
WheelPrefs();
~WheelPrefs();
@ -362,7 +375,8 @@ protected:
* It's decided by GetModifierForPref() which modifier should be used for
* the aEvent.
*
* @param aBasePrefName The result, it must be "mousewheel.with*.".
* @param aBasePrefName The result, must be "mousewheel.with_*." or
* "mousewheel.default.".
*/
void GetBasePrefName(Index aIndex, nsACString& aBasePrefName);
@ -373,6 +387,7 @@ protected:
bool mInit[COUNT_OF_MULTIPLIERS];
double mMultiplierX[COUNT_OF_MULTIPLIERS];
double mMultiplierY[COUNT_OF_MULTIPLIERS];
Action mActions[COUNT_OF_MULTIPLIERS];
static WheelPrefs* sInstance;
};
@ -448,12 +463,7 @@ protected:
* When the result is -1, nothing happens for the event.
*/
PRInt32 ComputeWheelActionFor(nsMouseScrollEvent* aMouseEvent);
/**
* Gets the wheel action for the aMouseEvent ONLY with the pref.
* When you actually do something for the event, probably you should use
* ComputeWheelActionFor().
*/
PRInt32 GetWheelActionFor(nsMouseScrollEvent* aMouseEvent);
// end mousewheel functions
/*

View File

@ -110,7 +110,7 @@ function initPrefs()
prefSvc.setIntPref("mousewheel.acceleration.start", -1);
prefSvc.setBoolPref("mousewheel.system_scroll_override_on_root_content.enabled", false);
// Enable zooming for ctrl-scrolling
prefSvc.setIntPref("mousewheel.withcontrolkey.action", 3);
prefSvc.setIntPref("mousewheel.with_control.action", 3);
}
function clearPrefs()
@ -122,7 +122,7 @@ function clearPrefs()
prefSvc.clearUserPref("general.smoothScroll");
prefSvc.clearUserPref("mousewheel.acceleration.start");
prefSvc.clearUserPref("mousewheel.system_scroll_override_on_root_content.enabled");
prefSvc.clearUserPref("mousewheel.withcontrolkey.action");
prefSvc.clearUserPref("mousewheel.with_control.action");
}
window.onload = function () {

View File

@ -1380,37 +1380,36 @@ pref("mousewheel.acceleration.factor", 10);
pref("mousewheel.system_scroll_override_on_root_content.vertical.factor", 200);
pref("mousewheel.system_scroll_override_on_root_content.horizontal.factor", 200);
// 0=lines, 1=pages, 2=history , 3=text size
pref("mousewheel.withnokey.action",0);
pref("mousewheel.withcontrolkey.action",0);
// mousewheel.withshiftkey, see the Mac note below.
pref("mousewheel.withshiftkey.action",0);
pref("mousewheel.withaltkey.action",2);
pref("mousewheel.withmetakey.action",0);
// activate horizontal scrolling by default
pref("mousewheel.horizscroll.withnokey.action",0);
pref("mousewheel.horizscroll.withcontrolkey.action",0);
pref("mousewheel.horizscroll.withshiftkey.action",0);
pref("mousewheel.horizscroll.withaltkey.action",2);
pref("mousewheel.horizscroll.withmetakey.action",0);
// mousewheel.*.action can specify the action when you use mosue wheel.
// When no modifier keys are pressed or two or more modifires are pressed,
// .default is used.
// 0: Nothing happens
// 1: Scrolling contents
// 2: Go back or go forward, in your history
// 3: Zoom in or out.
pref("mousewheel.default.action", 1);
pref("mousewheel.with_alt.action", 2);
pref("mousewheel.with_control.action", 3);
pref("mousewheel.with_meta.action", 1); // command key on Mac
pref("mousewheel.with_shift.action", 1);
pref("mousewheel.with_win.action", 1);
// mousewheel.*.delta_multiplier_* can specify the value muliplied by the delta
// value. The values will be used after divided by 100. I.e., 100 means 1.0,
// -100 means -1.0. If the values were negative, the direction would be
// reverted. The absolue value must be 100 or larger.
pref("mousewheel.withnokey.delta_multiplier_x", 100);
pref("mousewheel.withnokey.delta_multiplier_y", 100);
pref("mousewheel.withaltkey.delta_multiplier_x", 100);
pref("mousewheel.withaltkey.delta_multiplier_y", 100);
pref("mousewheel.withcontrolkey.delta_multiplier_x", 100);
pref("mousewheel.withcontrolkey.delta_multiplier_y", 100);
pref("mousewheel.withmetakey.delta_multiplier_x", 100); // command key on Mac
pref("mousewheel.withmetakey.delta_multiplier_y", 100); // command key on Mac
pref("mousewheel.withshiftkey.delta_multiplier_x", 100);
pref("mousewheel.withshiftkey.delta_multiplier_y", 100);
pref("mousewheel.withwinkey.delta_multiplier_x", 100);
pref("mousewheel.withwinkey.delta_multiplier_y", 100);
pref("mousewheel.default.delta_multiplier_x", 100);
pref("mousewheel.default.delta_multiplier_y", 100);
pref("mousewheel.with_alt.delta_multiplier_x", 100);
pref("mousewheel.with_alt.delta_multiplier_y", 100);
pref("mousewheel.with_control.delta_multiplier_x", 100);
pref("mousewheel.with_control.delta_multiplier_y", 100);
pref("mousewheel.with_meta.delta_multiplier_x", 100); // command key on Mac
pref("mousewheel.with_meta.delta_multiplier_y", 100); // command key on Mac
pref("mousewheel.with_shift.delta_multiplier_x", 100);
pref("mousewheel.with_shift.delta_multiplier_y", 100);
pref("mousewheel.with_win.delta_multiplier_x", 100);
pref("mousewheel.with_win.delta_multiplier_y", 100);
// These define the smooth scroll behavior (min ms, max ms) for different triggers
// Some triggers:

View File

@ -49,21 +49,19 @@ const DOM_PAGE_SCROLL_DELTA = 32768;
const kSystemScrollSpeedOverridePref = "mousewheel.system_scroll_override_on_root_content.enabled";
const kAltKeyVActionPref = "mousewheel.withaltkey.action";
const kAltKeyHActionPref = "mousewheel.horizscroll.withaltkey.action";
const kCtrlKeyVActionPref = "mousewheel.withcontrolkey.action";
const kCtrlKeyHActionPref = "mousewheel.horizscroll.withcontrolkey.action";
const kShiftKeyVActionPref = "mousewheel.withshiftkey.action";
const kShiftKeyHActionPref = "mousewheel.horizscroll.withshiftkey.action";
const kAltKeyActionPref = "mousewheel.with_alt.action";
const kCtrlKeyActionPref = "mousewheel.with_control.action";
const kShiftKeyActionPref = "mousewheel.with_shift.action";
const kWinKeyActionPref = "mousewheel.with_win.action";
const kAltKeyDeltaMultiplierXPref = "mousewheel.withaltkey.delta_multiplier_x";
const kAltKeyDeltaMultiplierYPref = "mousewheel.withaltkey.delta_multiplier_y";
const kCtrlKeyDeltaMultiplierXPref = "mousewheel.withcontrolkey.delta_multiplier_x";
const kCtrlKeyDeltaMultiplierYPref = "mousewheel.withcontrolkey.delta_multiplier_y";
const kShiftKeyDeltaMultiplierXPref = "mousewheel.withshiftkey.delta_multiplier_x";
const kShiftKeyDeltaMultiplierYPref = "mousewheel.withshiftkey.delta_multiplier_y";
const kWinKeyDeltaMultiplierXPref = "mousewheel.withwinkey.delta_multiplier_x";
const kWinKeyDeltaMultiplierYPref = "mousewheel.withwinkey.delta_multiplier_y";
const kAltKeyDeltaMultiplierXPref = "mousewheel.with_alt.delta_multiplier_x";
const kAltKeyDeltaMultiplierYPref = "mousewheel.with_alt.delta_multiplier_y";
const kCtrlKeyDeltaMultiplierXPref = "mousewheel.with_control.delta_multiplier_x";
const kCtrlKeyDeltaMultiplierYPref = "mousewheel.with_control.delta_multiplier_y";
const kShiftKeyDeltaMultiplierXPref = "mousewheel.with_shift.delta_multiplier_x";
const kShiftKeyDeltaMultiplierYPref = "mousewheel.with_shift.delta_multiplier_y";
const kWinKeyDeltaMultiplierXPref = "mousewheel.with_win.delta_multiplier_x";
const kWinKeyDeltaMultiplierYPref = "mousewheel.with_win.delta_multiplier_y";
const kPixelEnabledPref = "mousewheel.enable_pixel_scrolling";
const kEmulateWheelByWMSCROLLPref = "mousewheel.emulate_at_wm_scroll";
@ -109,12 +107,10 @@ function todo_is(aLeft, aRight, aMessage)
function onUnload()
{
SpecialPowers.clearUserPref(kAltKeyVActionPref);
SpecialPowers.clearUserPref(kAltKeyHActionPref);
SpecialPowers.clearUserPref(kCtrlKeyVActionPref);
SpecialPowers.clearUserPref(kCtrlKeyHActionPref);
SpecialPowers.clearUserPref(kShiftKeyVActionPref);
SpecialPowers.clearUserPref(kShiftKeyHActionPref);
SpecialPowers.clearUserPref(kAltKeyActionPref);
SpecialPowers.clearUserPref(kCtrlKeyActionPref);
SpecialPowers.clearUserPref(kShiftKeyActionPref);
SpecialPowers.clearUserPref(kWinKeyActionPref);
SpecialPowers.clearUserPref(kAltKeyDeltaMultiplierXPref);
SpecialPowers.clearUserPref(kAltKeyDeltaMultiplierYPref);
@ -1878,12 +1874,10 @@ function runNextTest(aTests, aIndex)
function prepareTests()
{
// Disable special action with modifier key
SpecialPowers.setIntPref(kAltKeyVActionPref, 0);
SpecialPowers.setIntPref(kCtrlKeyVActionPref, 0);
SpecialPowers.setIntPref(kShiftKeyVActionPref, 0);
SpecialPowers.setIntPref(kAltKeyHActionPref, 0);
SpecialPowers.setIntPref(kCtrlKeyHActionPref, 0);
SpecialPowers.setIntPref(kShiftKeyHActionPref, 0);
SpecialPowers.setIntPref(kAltKeyActionPref, 1);
SpecialPowers.setIntPref(kCtrlKeyActionPref, 1);
SpecialPowers.setIntPref(kShiftKeyActionPref, 1);
SpecialPowers.setIntPref(kWinKeyActionPref, 1);
SpecialPowers.setIntPref(kAltKeyDeltaMultiplierXPref, 100);
SpecialPowers.setIntPref(kAltKeyDeltaMultiplierYPref, 100);