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.twist.left", "");
pref("browser.gesture.tap", "cmd_fullZoomReset"); 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 #ifdef XP_MACOSX
// On OS X, if the wheel has one axis only, shift+wheel comes through as a // 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 // horizontal scroll event. Thus, we can't assign anything other than normal
// scrolling to shift+wheel. // scrolling to shift+wheel.
pref("mousewheel.withshiftkey.action",0); pref("mousewheel.with_alt.action", 2);
pref("mousewheel.withaltkey.action",2); pref("mousewheel.with_shift.action", 1);
pref("mousewheel.withmetakey.action",0);
#else #else
pref("mousewheel.withshiftkey.action",2); pref("mousewheel.with_alt.action", 1);
pref("mousewheel.withaltkey.action",0); pref("mousewheel.with_shift.action", 2);
pref("mousewheel.withmetakey.action",0);
#endif #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 to control the alert notification
pref("alerts.slideIncrement", 1); 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 { class nsMouseWheelTransaction {
public: public:
static nsIFrame* GetTargetFrame() { return sTargetFrame; } static nsIFrame* GetTargetFrame() { return sTargetFrame; }
@ -2686,43 +2658,55 @@ nsEventStateManager::SendPixelScrollEvent(nsIFrame* aTargetFrame,
} }
PRInt32 PRInt32
nsEventStateManager::ComputeWheelActionFor(nsMouseScrollEvent* aMouseEvent) nsEventStateManager::ComputeWheelActionFor(nsMouseScrollEvent* aEvent)
{ {
PRInt32 action = GetWheelActionFor(aMouseEvent); PRInt32 result = -1;
if (!aMouseEvent->customizedByUserPrefs && bool isPage =
(aMouseEvent->scrollFlags & nsMouseScrollEvent::kIsFullPage)) { (aEvent->scrollFlags & nsMouseScrollEvent::kIsFullPage) != 0;
action = MOUSE_SCROLL_PAGE; 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 == WheelPrefs::ACTION_SCROLL) {
if (action == MOUSE_SCROLL_N_LINES || action == MOUSE_SCROLL_PAGE || if (isPixel) {
(aMouseEvent->scrollFlags & nsMouseScrollEvent::kIsMomentum)) { return MOUSE_SCROLL_PIXELS;
action = MOUSE_SCROLL_PIXELS;
} else {
// Do not scroll pixels when zooming
action = -1;
} }
} else if (((aMouseEvent->scrollFlags & nsMouseScrollEvent::kHasPixels) && // Don't need to scroll, will be scrolled by following pixel event.
(!aMouseEvent->customizedByUserPrefs || if (hasPixel) {
action == MOUSE_SCROLL_N_LINES || action == MOUSE_SCROLL_PAGE)) || return -1;
((aMouseEvent->scrollFlags & nsMouseScrollEvent::kIsMomentum) && }
(action == MOUSE_SCROLL_HISTORY || action == MOUSE_SCROLL_ZOOM))) { return isPage ? MOUSE_SCROLL_PAGE : MOUSE_SCROLL_N_LINES;
// 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;
} }
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 // Special actions shouldn't be run by pixel scroll event or momentum events.
nsEventStateManager::GetWheelActionFor(nsMouseScrollEvent* aMouseEvent) if (isMomentum || isPixel) {
{ return -1;
nsCAutoString prefName; }
GetBasePrefKeyForMouseWheel(aMouseEvent, prefName);
prefName.Append(".action"); if (action == WheelPrefs::ACTION_HISTORY) {
return Preferences::GetInt(prefName.get()); return MOUSE_SCROLL_HISTORY;
}
if (action == WheelPrefs::ACTION_ZOOM) {
return MOUSE_SCROLL_ZOOM;
}
NS_WARNING("Unsupported wheel action pref value!");
return -1;
} }
nsIScrollableFrame* nsIScrollableFrame*
@ -5232,6 +5216,10 @@ nsEventStateManager::WheelPrefs::Reset()
nsEventStateManager::WheelPrefs::Index nsEventStateManager::WheelPrefs::Index
nsEventStateManager::WheelPrefs::GetIndexFor(nsMouseEvent_base* aEvent) nsEventStateManager::WheelPrefs::GetIndexFor(nsMouseEvent_base* aEvent)
{ {
if (!aEvent) {
return INDEX_DEFAULT;
}
widget::Modifiers modifiers = widget::Modifiers modifiers =
(aEvent->modifiers & (widget::MODIFIER_ALT | (aEvent->modifiers & (widget::MODIFIER_ALT |
widget::MODIFIER_CONTROL | widget::MODIFIER_CONTROL |
@ -5265,23 +5253,23 @@ nsEventStateManager::WheelPrefs::GetBasePrefName(
aBasePrefName.AssignLiteral("mousewheel."); aBasePrefName.AssignLiteral("mousewheel.");
switch (aIndex) { switch (aIndex) {
case INDEX_ALT: case INDEX_ALT:
aBasePrefName.AppendLiteral("withaltkey."); aBasePrefName.AppendLiteral("with_alt.");
break; break;
case INDEX_CONTROL: case INDEX_CONTROL:
aBasePrefName.AppendLiteral("withcontrolkey."); aBasePrefName.AppendLiteral("with_control.");
break; break;
case INDEX_META: case INDEX_META:
aBasePrefName.AppendLiteral("withmetakey."); aBasePrefName.AppendLiteral("with_meta.");
break; break;
case INDEX_SHIFT: case INDEX_SHIFT:
aBasePrefName.AppendLiteral("withshiftkey."); aBasePrefName.AppendLiteral("with_shift.");
break; break;
case INDEX_OS: case INDEX_OS:
aBasePrefName.AppendLiteral("withwinkey."); aBasePrefName.AppendLiteral("with_win.");
break; break;
case INDEX_DEFAULT: case INDEX_DEFAULT:
default: default:
aBasePrefName.AppendLiteral("withnokey."); aBasePrefName.AppendLiteral("default.");
break; break;
} }
} }
@ -5313,6 +5301,16 @@ nsEventStateManager::WheelPrefs::Init(
if (mMultiplierY[aIndex] < 1.0 && mMultiplierY[aIndex] > -1.0) { if (mMultiplierY[aIndex] < 1.0 && mMultiplierY[aIndex] > -1.0) {
mMultiplierY[aIndex] = mMultiplierY[aIndex] < 0.0 ? -1.0 : 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 void
@ -5334,3 +5332,11 @@ nsEventStateManager::WheelPrefs::ApplyUserPrefsToDelta(
aEvent->customizedByUserPrefs = (mMultiplierY[index] != 1.0); 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); 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: private:
WheelPrefs(); WheelPrefs();
~WheelPrefs(); ~WheelPrefs();
@ -362,7 +375,8 @@ protected:
* It's decided by GetModifierForPref() which modifier should be used for * It's decided by GetModifierForPref() which modifier should be used for
* the aEvent. * 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); void GetBasePrefName(Index aIndex, nsACString& aBasePrefName);
@ -373,6 +387,7 @@ protected:
bool mInit[COUNT_OF_MULTIPLIERS]; bool mInit[COUNT_OF_MULTIPLIERS];
double mMultiplierX[COUNT_OF_MULTIPLIERS]; double mMultiplierX[COUNT_OF_MULTIPLIERS];
double mMultiplierY[COUNT_OF_MULTIPLIERS]; double mMultiplierY[COUNT_OF_MULTIPLIERS];
Action mActions[COUNT_OF_MULTIPLIERS];
static WheelPrefs* sInstance; static WheelPrefs* sInstance;
}; };
@ -448,12 +463,7 @@ protected:
* When the result is -1, nothing happens for the event. * When the result is -1, nothing happens for the event.
*/ */
PRInt32 ComputeWheelActionFor(nsMouseScrollEvent* aMouseEvent); 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 // end mousewheel functions
/* /*

View File

@ -110,7 +110,7 @@ function initPrefs()
prefSvc.setIntPref("mousewheel.acceleration.start", -1); prefSvc.setIntPref("mousewheel.acceleration.start", -1);
prefSvc.setBoolPref("mousewheel.system_scroll_override_on_root_content.enabled", false); prefSvc.setBoolPref("mousewheel.system_scroll_override_on_root_content.enabled", false);
// Enable zooming for ctrl-scrolling // Enable zooming for ctrl-scrolling
prefSvc.setIntPref("mousewheel.withcontrolkey.action", 3); prefSvc.setIntPref("mousewheel.with_control.action", 3);
} }
function clearPrefs() function clearPrefs()
@ -122,7 +122,7 @@ function clearPrefs()
prefSvc.clearUserPref("general.smoothScroll"); prefSvc.clearUserPref("general.smoothScroll");
prefSvc.clearUserPref("mousewheel.acceleration.start"); prefSvc.clearUserPref("mousewheel.acceleration.start");
prefSvc.clearUserPref("mousewheel.system_scroll_override_on_root_content.enabled"); prefSvc.clearUserPref("mousewheel.system_scroll_override_on_root_content.enabled");
prefSvc.clearUserPref("mousewheel.withcontrolkey.action"); prefSvc.clearUserPref("mousewheel.with_control.action");
} }
window.onload = function () { 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.vertical.factor", 200);
pref("mousewheel.system_scroll_override_on_root_content.horizontal.factor", 200); pref("mousewheel.system_scroll_override_on_root_content.horizontal.factor", 200);
// 0=lines, 1=pages, 2=history , 3=text size // mousewheel.*.action can specify the action when you use mosue wheel.
pref("mousewheel.withnokey.action",0); // When no modifier keys are pressed or two or more modifires are pressed,
pref("mousewheel.withcontrolkey.action",0); // .default is used.
// mousewheel.withshiftkey, see the Mac note below. // 0: Nothing happens
pref("mousewheel.withshiftkey.action",0); // 1: Scrolling contents
pref("mousewheel.withaltkey.action",2); // 2: Go back or go forward, in your history
pref("mousewheel.withmetakey.action",0); // 3: Zoom in or out.
pref("mousewheel.default.action", 1);
// activate horizontal scrolling by default pref("mousewheel.with_alt.action", 2);
pref("mousewheel.horizscroll.withnokey.action",0); pref("mousewheel.with_control.action", 3);
pref("mousewheel.horizscroll.withcontrolkey.action",0); pref("mousewheel.with_meta.action", 1); // command key on Mac
pref("mousewheel.horizscroll.withshiftkey.action",0); pref("mousewheel.with_shift.action", 1);
pref("mousewheel.horizscroll.withaltkey.action",2); pref("mousewheel.with_win.action", 1);
pref("mousewheel.horizscroll.withmetakey.action",0);
// mousewheel.*.delta_multiplier_* can specify the value muliplied by the delta // 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, // 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 // -100 means -1.0. If the values were negative, the direction would be
// reverted. The absolue value must be 100 or larger. // reverted. The absolue value must be 100 or larger.
pref("mousewheel.withnokey.delta_multiplier_x", 100); pref("mousewheel.default.delta_multiplier_x", 100);
pref("mousewheel.withnokey.delta_multiplier_y", 100); pref("mousewheel.default.delta_multiplier_y", 100);
pref("mousewheel.withaltkey.delta_multiplier_x", 100); pref("mousewheel.with_alt.delta_multiplier_x", 100);
pref("mousewheel.withaltkey.delta_multiplier_y", 100); pref("mousewheel.with_alt.delta_multiplier_y", 100);
pref("mousewheel.withcontrolkey.delta_multiplier_x", 100); pref("mousewheel.with_control.delta_multiplier_x", 100);
pref("mousewheel.withcontrolkey.delta_multiplier_y", 100); pref("mousewheel.with_control.delta_multiplier_y", 100);
pref("mousewheel.withmetakey.delta_multiplier_x", 100); // command key on Mac pref("mousewheel.with_meta.delta_multiplier_x", 100); // command key on Mac
pref("mousewheel.withmetakey.delta_multiplier_y", 100); // command key on Mac pref("mousewheel.with_meta.delta_multiplier_y", 100); // command key on Mac
pref("mousewheel.withshiftkey.delta_multiplier_x", 100); pref("mousewheel.with_shift.delta_multiplier_x", 100);
pref("mousewheel.withshiftkey.delta_multiplier_y", 100); pref("mousewheel.with_shift.delta_multiplier_y", 100);
pref("mousewheel.withwinkey.delta_multiplier_x", 100); pref("mousewheel.with_win.delta_multiplier_x", 100);
pref("mousewheel.withwinkey.delta_multiplier_y", 100); pref("mousewheel.with_win.delta_multiplier_y", 100);
// These define the smooth scroll behavior (min ms, max ms) for different triggers // These define the smooth scroll behavior (min ms, max ms) for different triggers
// Some 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 kSystemScrollSpeedOverridePref = "mousewheel.system_scroll_override_on_root_content.enabled";
const kAltKeyVActionPref = "mousewheel.withaltkey.action"; const kAltKeyActionPref = "mousewheel.with_alt.action";
const kAltKeyHActionPref = "mousewheel.horizscroll.withaltkey.action"; const kCtrlKeyActionPref = "mousewheel.with_control.action";
const kCtrlKeyVActionPref = "mousewheel.withcontrolkey.action"; const kShiftKeyActionPref = "mousewheel.with_shift.action";
const kCtrlKeyHActionPref = "mousewheel.horizscroll.withcontrolkey.action"; const kWinKeyActionPref = "mousewheel.with_win.action";
const kShiftKeyVActionPref = "mousewheel.withshiftkey.action";
const kShiftKeyHActionPref = "mousewheel.horizscroll.withshiftkey.action";
const kAltKeyDeltaMultiplierXPref = "mousewheel.withaltkey.delta_multiplier_x"; const kAltKeyDeltaMultiplierXPref = "mousewheel.with_alt.delta_multiplier_x";
const kAltKeyDeltaMultiplierYPref = "mousewheel.withaltkey.delta_multiplier_y"; const kAltKeyDeltaMultiplierYPref = "mousewheel.with_alt.delta_multiplier_y";
const kCtrlKeyDeltaMultiplierXPref = "mousewheel.withcontrolkey.delta_multiplier_x"; const kCtrlKeyDeltaMultiplierXPref = "mousewheel.with_control.delta_multiplier_x";
const kCtrlKeyDeltaMultiplierYPref = "mousewheel.withcontrolkey.delta_multiplier_y"; const kCtrlKeyDeltaMultiplierYPref = "mousewheel.with_control.delta_multiplier_y";
const kShiftKeyDeltaMultiplierXPref = "mousewheel.withshiftkey.delta_multiplier_x"; const kShiftKeyDeltaMultiplierXPref = "mousewheel.with_shift.delta_multiplier_x";
const kShiftKeyDeltaMultiplierYPref = "mousewheel.withshiftkey.delta_multiplier_y"; const kShiftKeyDeltaMultiplierYPref = "mousewheel.with_shift.delta_multiplier_y";
const kWinKeyDeltaMultiplierXPref = "mousewheel.withwinkey.delta_multiplier_x"; const kWinKeyDeltaMultiplierXPref = "mousewheel.with_win.delta_multiplier_x";
const kWinKeyDeltaMultiplierYPref = "mousewheel.withwinkey.delta_multiplier_y"; const kWinKeyDeltaMultiplierYPref = "mousewheel.with_win.delta_multiplier_y";
const kPixelEnabledPref = "mousewheel.enable_pixel_scrolling"; const kPixelEnabledPref = "mousewheel.enable_pixel_scrolling";
const kEmulateWheelByWMSCROLLPref = "mousewheel.emulate_at_wm_scroll"; const kEmulateWheelByWMSCROLLPref = "mousewheel.emulate_at_wm_scroll";
@ -109,12 +107,10 @@ function todo_is(aLeft, aRight, aMessage)
function onUnload() function onUnload()
{ {
SpecialPowers.clearUserPref(kAltKeyVActionPref); SpecialPowers.clearUserPref(kAltKeyActionPref);
SpecialPowers.clearUserPref(kAltKeyHActionPref); SpecialPowers.clearUserPref(kCtrlKeyActionPref);
SpecialPowers.clearUserPref(kCtrlKeyVActionPref); SpecialPowers.clearUserPref(kShiftKeyActionPref);
SpecialPowers.clearUserPref(kCtrlKeyHActionPref); SpecialPowers.clearUserPref(kWinKeyActionPref);
SpecialPowers.clearUserPref(kShiftKeyVActionPref);
SpecialPowers.clearUserPref(kShiftKeyHActionPref);
SpecialPowers.clearUserPref(kAltKeyDeltaMultiplierXPref); SpecialPowers.clearUserPref(kAltKeyDeltaMultiplierXPref);
SpecialPowers.clearUserPref(kAltKeyDeltaMultiplierYPref); SpecialPowers.clearUserPref(kAltKeyDeltaMultiplierYPref);
@ -1878,12 +1874,10 @@ function runNextTest(aTests, aIndex)
function prepareTests() function prepareTests()
{ {
// Disable special action with modifier key // Disable special action with modifier key
SpecialPowers.setIntPref(kAltKeyVActionPref, 0); SpecialPowers.setIntPref(kAltKeyActionPref, 1);
SpecialPowers.setIntPref(kCtrlKeyVActionPref, 0); SpecialPowers.setIntPref(kCtrlKeyActionPref, 1);
SpecialPowers.setIntPref(kShiftKeyVActionPref, 0); SpecialPowers.setIntPref(kShiftKeyActionPref, 1);
SpecialPowers.setIntPref(kAltKeyHActionPref, 0); SpecialPowers.setIntPref(kWinKeyActionPref, 1);
SpecialPowers.setIntPref(kCtrlKeyHActionPref, 0);
SpecialPowers.setIntPref(kShiftKeyHActionPref, 0);
SpecialPowers.setIntPref(kAltKeyDeltaMultiplierXPref, 100); SpecialPowers.setIntPref(kAltKeyDeltaMultiplierXPref, 100);
SpecialPowers.setIntPref(kAltKeyDeltaMultiplierYPref, 100); SpecialPowers.setIntPref(kAltKeyDeltaMultiplierYPref, 100);