|
Lines 22-27
Link Here
|
| 22 |
* Contributor(s): |
22 |
* Contributor(s): |
| 23 |
* Makoto Kato <m_kato@ga2.so-net.ne.jp> |
23 |
* Makoto Kato <m_kato@ga2.so-net.ne.jp> |
| 24 |
* Dean Tessman <dean_tessman@hotmail.com> |
24 |
* Dean Tessman <dean_tessman@hotmail.com> |
|
|
25 |
* Andrew Wellington <proton@wiretapped.net> |
| 26 |
* Graham Dennis <u3952328@anu.edu.au> |
| 27 |
* Thomas Kleffel <thomas.kleffel@maintech.de> |
| 25 |
* |
28 |
* |
| 26 |
* Alternatively, the contents of this file may be used under the terms of |
29 |
* Alternatively, the contents of this file may be used under the terms of |
| 27 |
* either the GNU General Public License Version 2 or later (the "GPL"), or |
30 |
* either the GNU General Public License Version 2 or later (the "GPL"), or |
|
Lines 1536-1549
Link Here
|
| 1536 |
return NS_OK; |
1539 |
return NS_OK; |
| 1537 |
} |
1540 |
} |
| 1538 |
|
1541 |
|
|
|
1542 |
nsresult |
| 1543 |
nsEventStateManager::DoScrollHistory(PRInt32 direction) |
| 1544 |
{ |
| 1545 |
nsCOMPtr<nsISupports> pcContainer; |
| 1546 |
mPresContext->GetContainer(getter_AddRefs(pcContainer)); |
| 1547 |
if (pcContainer) { |
| 1548 |
nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(pcContainer)); |
| 1549 |
if (webNav) { |
| 1550 |
// negative direction to go back one step, nonneg to go forward |
| 1551 |
if (direction < 0) |
| 1552 |
webNav->GoBack(); |
| 1553 |
else |
| 1554 |
webNav->GoForward(); |
| 1555 |
} |
| 1556 |
} |
| 1557 |
return NS_OK; |
| 1558 |
} |
| 1559 |
|
| 1560 |
nsresult |
| 1561 |
nsEventStateManager::DoScrollTextsize(nsIFrame *aTargetFrame, |
| 1562 |
PRInt32 adjustment) |
| 1563 |
{ |
| 1564 |
// Exclude form controls and XUL content. |
| 1565 |
nsIContent *content = aTargetFrame->GetContent(); |
| 1566 |
if (content && |
| 1567 |
!content->IsContentOfType(nsIContent::eHTML_FORM_CONTROL) && |
| 1568 |
!content->IsContentOfType(nsIContent::eXUL)) |
| 1569 |
{ |
| 1570 |
// positive adjustment to increase text size, non-positive to decrease |
| 1571 |
ChangeTextSize((adjustment > 0) ? 1 : -1); |
| 1572 |
} |
| 1573 |
return NS_OK; |
| 1574 |
} |
| 1539 |
|
1575 |
|
| 1540 |
// |
1576 |
// |
| 1541 |
nsresult |
1577 |
nsresult |
| 1542 |
nsEventStateManager::DoWheelScroll(nsIPresContext* aPresContext, |
1578 |
nsEventStateManager::DoScrollText(nsIPresContext* aPresContext, |
| 1543 |
nsIFrame* aTargetFrame, |
1579 |
nsIFrame* aTargetFrame, |
| 1544 |
nsMouseScrollEvent* aMSEvent, |
1580 |
nsInputEvent* aEvent, |
| 1545 |
PRInt32 aNumLines, PRBool aScrollHorizontal, PRBool aScrollPage, |
1581 |
PRInt32 aNumLines, |
| 1546 |
PRBool aUseTargetFrame) |
1582 |
PRBool aScrollHorizontal, |
|
|
1583 |
PRBool aScrollPage, |
| 1584 |
PRBool aUseTargetFrame) |
| 1547 |
{ |
1585 |
{ |
| 1548 |
nsCOMPtr<nsIContent> targetContent = aTargetFrame->GetContent(); |
1586 |
nsCOMPtr<nsIContent> targetContent = aTargetFrame->GetContent(); |
| 1549 |
if (!targetContent) |
1587 |
if (!targetContent) |
|
Lines 1570-1580
Link Here
|
| 1570 |
} |
1608 |
} |
| 1571 |
} |
1609 |
} |
| 1572 |
|
1610 |
|
| 1573 |
mouseEvent->InitMouseEvent(NS_LITERAL_STRING("DOMMouseScroll"), PR_TRUE, PR_TRUE, |
1611 |
mouseEvent->InitMouseEvent(NS_LITERAL_STRING("DOMMouseScroll"), |
|
|
1612 |
PR_TRUE, PR_TRUE, |
| 1574 |
view, aNumLines, |
1613 |
view, aNumLines, |
| 1575 |
aMSEvent->refPoint.x, aMSEvent->refPoint.y, |
1614 |
aEvent->refPoint.x, aEvent->refPoint.y, |
| 1576 |
aMSEvent->point.x, aMSEvent->point.y, |
1615 |
aEvent->point.x, aEvent->point.y, |
| 1577 |
aMSEvent->isControl, aMSEvent->isAlt, aMSEvent->isShift, aMSEvent->isMeta, |
1616 |
aEvent->isControl, aEvent->isAlt, |
|
|
1617 |
aEvent->isShift, aEvent->isMeta, |
| 1578 |
0, nsnull); |
1618 |
0, nsnull); |
| 1579 |
PRBool allowDefault; |
1619 |
PRBool allowDefault; |
| 1580 |
nsCOMPtr<nsIDOMEventTarget> target(do_QueryInterface(targetContent)); |
1620 |
nsCOMPtr<nsIDOMEventTarget> target(do_QueryInterface(targetContent)); |
|
Lines 1595-1601
Link Here
|
| 1595 |
nsMouseEvent mouseOutEvent; |
1635 |
nsMouseEvent mouseOutEvent; |
| 1596 |
mouseOutEvent.eventStructType = NS_MOUSE_EVENT; |
1636 |
mouseOutEvent.eventStructType = NS_MOUSE_EVENT; |
| 1597 |
mouseOutEvent.message = NS_MOUSE_EXIT; |
1637 |
mouseOutEvent.message = NS_MOUSE_EXIT; |
| 1598 |
mouseOutEvent.widget = aMSEvent->widget; |
1638 |
mouseOutEvent.widget = aEvent->widget; |
| 1599 |
mouseOutEvent.clickCount = 0; |
1639 |
mouseOutEvent.clickCount = 0; |
| 1600 |
mouseOutEvent.point = nsPoint(0,0); |
1640 |
mouseOutEvent.point = nsPoint(0,0); |
| 1601 |
mouseOutEvent.refPoint = nsPoint(0,0); |
1641 |
mouseOutEvent.refPoint = nsPoint(0,0); |
|
Lines 1676-1683
Link Here
|
| 1676 |
return NS_ERROR_FAILURE; |
1716 |
return NS_ERROR_FAILURE; |
| 1677 |
nsRect portRect = portView->GetBounds(); |
1717 |
nsRect portRect = portView->GetBounds(); |
| 1678 |
|
1718 |
|
| 1679 |
passToParent = aScrollHorizontal ? (xPos + portRect.width >= scrolledSize.width) |
1719 |
passToParent = (aScrollHorizontal ? |
| 1680 |
: (yPos + portRect.height >= scrolledSize.height); |
1720 |
(xPos + portRect.width >= scrolledSize.width) : |
|
|
1721 |
(yPos + portRect.height >= scrolledSize.height)); |
| 1681 |
} |
1722 |
} |
| 1682 |
} |
1723 |
} |
| 1683 |
|
1724 |
|
|
Lines 1710-1720
Link Here
|
| 1710 |
nsIFrame* newFrame = nsnull; |
1751 |
nsIFrame* newFrame = nsnull; |
| 1711 |
nsCOMPtr<nsIPresContext> newPresContext; |
1752 |
nsCOMPtr<nsIPresContext> newPresContext; |
| 1712 |
|
1753 |
|
| 1713 |
rv = GetParentScrollingView(aMSEvent, aPresContext, newFrame, |
1754 |
rv = GetParentScrollingView(aEvent, aPresContext, newFrame, |
| 1714 |
*getter_AddRefs(newPresContext)); |
1755 |
*getter_AddRefs(newPresContext)); |
| 1715 |
if (NS_SUCCEEDED(rv) && newFrame) |
1756 |
if (NS_SUCCEEDED(rv) && newFrame) |
| 1716 |
return DoWheelScroll(newPresContext, newFrame, aMSEvent, aNumLines, |
1757 |
return DoScrollText(newPresContext, newFrame, aEvent, aNumLines, |
| 1717 |
aScrollHorizontal, aScrollPage, PR_TRUE); |
1758 |
aScrollHorizontal, aScrollPage, PR_TRUE); |
| 1718 |
else |
1759 |
else |
| 1719 |
return NS_ERROR_FAILURE; |
1760 |
return NS_ERROR_FAILURE; |
| 1720 |
} |
1761 |
} |
|
Lines 1723-1729
Link Here
|
| 1723 |
} |
1764 |
} |
| 1724 |
|
1765 |
|
| 1725 |
nsresult |
1766 |
nsresult |
| 1726 |
nsEventStateManager::GetParentScrollingView(nsMouseScrollEvent *aEvent, |
1767 |
nsEventStateManager::GetParentScrollingView(nsInputEvent *aEvent, |
| 1727 |
nsIPresContext* aPresContext, |
1768 |
nsIPresContext* aPresContext, |
| 1728 |
nsIFrame* &targetOuterFrame, |
1769 |
nsIFrame* &targetOuterFrame, |
| 1729 |
nsIPresContext* &presCtxOuter) |
1770 |
nsIPresContext* &presCtxOuter) |
|
Lines 1911-1916
Link Here
|
| 1911 |
} |
1952 |
} |
| 1912 |
} |
1953 |
} |
| 1913 |
break; |
1954 |
break; |
|
|
1955 |
case NS_MOUSE_EXTENDED_BUTTON: |
| 1956 |
{ |
| 1957 |
nsMouseEvent *mEvent = (nsMouseEvent* )aEvent; |
| 1958 |
nsresult rv; |
| 1959 |
nsCAutoString actionKey, numLinesKey; |
| 1960 |
PRInt32 action; |
| 1961 |
PRInt32 numLines; |
| 1962 |
|
| 1963 |
NS_NAMED_LITERAL_CSTRING(prefbase, "mousebuttonsextended.buttons."); |
| 1964 |
NS_NAMED_LITERAL_CSTRING(prefaction, ".action"); |
| 1965 |
NS_NAMED_LITERAL_CSTRING(prefnumlines, ".numlines"); |
| 1966 |
|
| 1967 |
nsCAutoString prefstatus(((mEvent->status == nsMouseEventStatus_up) |
| 1968 |
? ".up" : ".down")); |
| 1969 |
|
| 1970 |
rv = getPrefBranch(); |
| 1971 |
if (NS_FAILED(rv)) return rv; |
| 1972 |
|
| 1973 |
actionKey = prefbase; |
| 1974 |
actionKey.AppendInt(mEvent->button); |
| 1975 |
actionKey.Append(prefaction); |
| 1976 |
actionKey.Append(prefstatus); |
| 1977 |
rv = mPrefBranch->GetIntPref(PromiseFlatCString(actionKey).get(), |
| 1978 |
&action); |
| 1979 |
if (NS_FAILED(rv)) break; |
| 1980 |
|
| 1981 |
numLinesKey = prefbase; |
| 1982 |
numLinesKey.AppendInt(mEvent->button); |
| 1983 |
numLinesKey.Append(prefnumlines); |
| 1984 |
numLinesKey.Append(prefstatus); |
| 1985 |
rv = mPrefBranch->GetIntPref(PromiseFlatCString(numLinesKey).get(), |
| 1986 |
&numLines); |
| 1987 |
if (NS_FAILED(rv)) break; |
| 1988 |
|
| 1989 |
switch (action) { |
| 1990 |
|
| 1991 |
case MOUSE_SCROLL_N_LINES: |
| 1992 |
case MOUSE_SCROLL_PAGE: |
| 1993 |
{ |
| 1994 |
DoScrollText(aPresContext, aTargetFrame, mEvent, numLines, |
| 1995 |
0, (action == MOUSE_SCROLL_PAGE), PR_FALSE); |
| 1996 |
} |
| 1997 |
break; |
| 1998 |
|
| 1999 |
case MOUSE_SCROLL_HISTORY: |
| 2000 |
{ |
| 2001 |
DoScrollHistory(numLines); |
| 2002 |
} |
| 2003 |
break; |
| 2004 |
|
| 2005 |
case MOUSE_SCROLL_TEXTSIZE: |
| 2006 |
{ |
| 2007 |
DoScrollTextsize(aTargetFrame, numLines); |
| 2008 |
} |
| 2009 |
break; |
| 2010 |
|
| 2011 |
default: // Including -1 (do nothing) |
| 2012 |
break; |
| 2013 |
} |
| 2014 |
} |
| 2015 |
break; |
| 1914 |
case NS_MOUSE_SCROLL: |
2016 |
case NS_MOUSE_SCROLL: |
| 1915 |
if (nsEventStatus_eConsumeNoDefault != *aStatus) { |
2017 |
if (nsEventStatus_eConsumeNoDefault != *aStatus) { |
| 1916 |
nsresult rv; |
2018 |
nsresult rv; |
|
Lines 1920-2014
Link Here
|
| 1920 |
nsMouseScrollEvent *msEvent = (nsMouseScrollEvent*) aEvent; |
2022 |
nsMouseScrollEvent *msEvent = (nsMouseScrollEvent*) aEvent; |
| 1921 |
PRInt32 action = 0; |
2023 |
PRInt32 action = 0; |
| 1922 |
PRInt32 numLines = 0; |
2024 |
PRInt32 numLines = 0; |
| 1923 |
PRBool aBool; |
2025 |
PRBool useSysNumLines; |
| 1924 |
if (msEvent->isShift) { |
|
|
| 1925 |
mPrefBranch->GetIntPref("mousewheel.withshiftkey.action", &action); |
| 1926 |
mPrefBranch->GetBoolPref("mousewheel.withshiftkey.sysnumlines", |
| 1927 |
&aBool); |
| 1928 |
if (aBool) { |
| 1929 |
numLines = msEvent->delta; |
| 1930 |
if (msEvent->scrollFlags & nsMouseScrollEvent::kIsFullPage) |
| 1931 |
action = MOUSE_SCROLL_PAGE; |
| 1932 |
} |
| 1933 |
else |
| 1934 |
mPrefBranch->GetIntPref("mousewheel.withshiftkey.numlines", |
| 1935 |
&numLines); |
| 1936 |
} else if (msEvent->isControl) { |
| 1937 |
mPrefBranch->GetIntPref("mousewheel.withcontrolkey.action", &action); |
| 1938 |
mPrefBranch->GetBoolPref("mousewheel.withcontrolkey.sysnumlines", |
| 1939 |
&aBool); |
| 1940 |
if (aBool) { |
| 1941 |
numLines = msEvent->delta; |
| 1942 |
if (msEvent->scrollFlags & nsMouseScrollEvent::kIsFullPage) |
| 1943 |
action = MOUSE_SCROLL_PAGE; |
| 1944 |
} |
| 1945 |
else |
| 1946 |
mPrefBranch->GetIntPref("mousewheel.withcontrolkey.numlines", |
| 1947 |
&numLines); |
| 1948 |
} else if (msEvent->isAlt) { |
| 1949 |
mPrefBranch->GetIntPref("mousewheel.withaltkey.action", &action); |
| 1950 |
mPrefBranch->GetBoolPref("mousewheel.withaltkey.sysnumlines", &aBool); |
| 1951 |
if (aBool) { |
| 1952 |
numLines = msEvent->delta; |
| 1953 |
if (msEvent->scrollFlags & nsMouseScrollEvent::kIsFullPage) |
| 1954 |
action = MOUSE_SCROLL_PAGE; |
| 1955 |
} |
| 1956 |
else |
| 1957 |
mPrefBranch->GetIntPref("mousewheel.withaltkey.numlines", |
| 1958 |
&numLines); |
| 1959 |
} else { |
| 1960 |
mPrefBranch->GetIntPref("mousewheel.withnokey.action", &action); |
| 1961 |
mPrefBranch->GetBoolPref("mousewheel.withnokey.sysnumlines", &aBool); |
| 1962 |
if (aBool) { |
| 1963 |
numLines = msEvent->delta; |
| 1964 |
if (msEvent->scrollFlags & nsMouseScrollEvent::kIsFullPage) |
| 1965 |
action = MOUSE_SCROLL_PAGE; |
| 1966 |
} |
| 1967 |
else |
| 1968 |
mPrefBranch->GetIntPref("mousewheel.withnokey.numlines", &numLines); |
| 1969 |
} |
| 1970 |
|
2026 |
|
| 1971 |
if ((msEvent->delta < 0) && (numLines > 0)) |
2027 |
NS_NAMED_LITERAL_CSTRING(prefmousewheel, "mousewheel"); |
|
|
2028 |
NS_NAMED_LITERAL_CSTRING(prefhoriz, ".horizscroll"); |
| 2029 |
NS_NAMED_LITERAL_CSTRING(prefvert, ""); |
| 2030 |
NS_NAMED_LITERAL_CSTRING(prefnodir, ""); |
| 2031 |
NS_NAMED_LITERAL_CSTRING(prefnokey, ".withnokey"); |
| 2032 |
NS_NAMED_LITERAL_CSTRING(prefshiftkey, ".withshiftkey"); |
| 2033 |
NS_NAMED_LITERAL_CSTRING(prefctrlkey, ".withcontrolkey"); |
| 2034 |
NS_NAMED_LITERAL_CSTRING(prefaltkey, ".withaltkey"); |
| 2035 |
NS_NAMED_LITERAL_CSTRING(prefaction, ".action"); |
| 2036 |
NS_NAMED_LITERAL_CSTRING(prefsysnumlines, ".sysnumlines"); |
| 2037 |
NS_NAMED_LITERAL_CSTRING(prefnumlines, ".numlines"); |
| 2038 |
|
| 2039 |
nsCString prefDirection; |
| 2040 |
nsCString prefModifier; |
| 2041 |
|
| 2042 |
//if delta==0 we have nothing to do! |
| 2043 |
if(msEvent->delta == 0) break; |
| 2044 |
|
| 2045 |
prefDirection = prefnodir; |
| 2046 |
switch(msEvent->scrollFlags) { |
| 2047 |
case nsMouseScrollEvent::kIsHorizontal: |
| 2048 |
prefDirection = prefhoriz; break; |
| 2049 |
case nsMouseScrollEvent::kIsVertical: |
| 2050 |
prefDirection = prefvert; break; |
| 2051 |
} |
| 2052 |
|
| 2053 |
prefModifier = prefnokey; |
| 2054 |
if(msEvent->isAlt) prefModifier = prefaltkey; |
| 2055 |
if(msEvent->isControl) prefModifier = prefctrlkey; |
| 2056 |
if(msEvent->isShift) prefModifier = prefshiftkey; |
| 2057 |
|
| 2058 |
rv = mPrefBranch->GetIntPref(PromiseFlatCString(prefmousewheel + |
| 2059 |
prefDirection + prefModifier + prefaction).get(), |
| 2060 |
&action); |
| 2061 |
if(NS_FAILED(rv)) break; |
| 2062 |
|
| 2063 |
rv = mPrefBranch->GetIntPref(PromiseFlatCString(prefmousewheel + |
| 2064 |
prefDirection + prefModifier + prefnumlines).get(), |
| 2065 |
&numLines); |
| 2066 |
|
| 2067 |
rv = mPrefBranch->GetBoolPref(PromiseFlatCString(prefmousewheel + |
| 2068 |
prefDirection + prefModifier + prefsysnumlines).get(), |
| 2069 |
&useSysNumLines); |
| 2070 |
if(NS_FAILED(rv)) break; |
| 2071 |
|
| 2072 |
// if numlines == 0 take the system value |
| 2073 |
if(numLines == 0 || useSysNumLines) |
| 2074 |
numLines = msEvent->delta; |
| 2075 |
// invert the given value if the system delta is negative |
| 2076 |
else if(msEvent->delta < 0) |
| 1972 |
numLines = -numLines; |
2077 |
numLines = -numLines; |
| 1973 |
|
2078 |
|
| 1974 |
switch (action) { |
2079 |
switch (action) { |
| 1975 |
case MOUSE_SCROLL_N_LINES: |
2080 |
case MOUSE_SCROLL_N_LINES: |
| 1976 |
case MOUSE_SCROLL_PAGE: |
2081 |
case MOUSE_SCROLL_PAGE: |
| 1977 |
{ |
2082 |
{ |
| 1978 |
DoWheelScroll(aPresContext, aTargetFrame, msEvent, numLines, |
2083 |
DoScrollText(aPresContext, aTargetFrame, msEvent, numLines, |
| 1979 |
(msEvent->scrollFlags & nsMouseScrollEvent::kIsHorizontal), |
2084 |
(msEvent->scrollFlags & nsMouseScrollEvent::kIsHorizontal), |
| 1980 |
(action == MOUSE_SCROLL_PAGE), PR_FALSE); |
2085 |
(action == MOUSE_SCROLL_PAGE), PR_FALSE); |
| 1981 |
|
|
|
| 1982 |
} |
2086 |
} |
| 1983 |
|
|
|
| 1984 |
break; |
2087 |
break; |
| 1985 |
|
2088 |
|
| 1986 |
case MOUSE_SCROLL_HISTORY: |
2089 |
case MOUSE_SCROLL_HISTORY: |
| 1987 |
{ |
2090 |
{ |
| 1988 |
nsCOMPtr<nsISupports> pcContainer; |
2091 |
DoScrollHistory(numLines); |
| 1989 |
mPresContext->GetContainer(getter_AddRefs(pcContainer)); |
|
|
| 1990 |
if (pcContainer) { |
| 1991 |
nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(pcContainer)); |
| 1992 |
if (webNav) { |
| 1993 |
if (msEvent->delta > 0) |
| 1994 |
webNav->GoBack(); |
| 1995 |
else |
| 1996 |
webNav->GoForward(); |
| 1997 |
} |
| 1998 |
} |
| 1999 |
} |
2092 |
} |
| 2000 |
break; |
2093 |
break; |
| 2001 |
|
2094 |
|
| 2002 |
case MOUSE_SCROLL_TEXTSIZE: |
2095 |
case MOUSE_SCROLL_TEXTSIZE: |
| 2003 |
{ |
2096 |
{ |
| 2004 |
// Exclude form controls and XUL content. |
2097 |
DoScrollTextsize(aTargetFrame, numLines); |
| 2005 |
nsIContent* content = aTargetFrame->GetContent(); |
|
|
| 2006 |
if (content && |
| 2007 |
!content->IsContentOfType(nsIContent::eHTML_FORM_CONTROL) && |
| 2008 |
!content->IsContentOfType(nsIContent::eXUL)) |
| 2009 |
{ |
| 2010 |
ChangeTextSize((msEvent->delta > 0) ? 1 : -1); |
| 2011 |
} |
| 2012 |
} |
2098 |
} |
| 2013 |
break; |
2099 |
break; |
| 2014 |
} |
2100 |
} |