Fix bug 782152 - Replace DOMMouseScroll with wheel event. r=philipp

--HG--
extra : rebase_source : 8e6045705aa906725dc5338b0fe46fd2041a39fb
This commit is contained in:
Chen Zeyu 2012-09-25 22:23:50 +08:00
Родитель 23275a6f25
Коммит ab8c02bbce
6 изменённых файлов: 184 добавлений и 74 удалений

Просмотреть файл

@ -38,6 +38,7 @@
<field name="mShadowOffset">null</field>
<field name="mDropShadows">null</field>
<field name="mMagnifyAmount">0</field>
<field name="mPixelScrollDelta">0</field>
<field name="mPrefObserver"><![CDATA[
({ calView: this,
observe: function calViewPrefChange(subj, topic, pref) {
@ -764,9 +765,27 @@
break;
}
]]></handler>
<handler event="DOMMouseScroll"><![CDATA[
if (event.shiftKey && getPrefSafe('calendar.view.mousescroll', true)) {
this.moveView(event.detail < 0 ? -1 : 1);
<handler event="wheel"><![CDATA[
const pixelThreshold = 150;
if (event.shiftKey && cal.getPrefSafe('calendar.view.mousescroll', true)){
if (event.deltaMode == event.DOM_DELTA_LINE) {
if (event.deltaY != 0) {
deltaView = event.deltaY < 0 ? -1 : 1;
}
} else if (event.deltaMode == event.DOM_DELTA_PIXEL) {
this.mPixelScrollDelta += event.deltaY;
if (this.mPixelScrollDelta > pixelThreshold){
deltaView = 1;
this.mPixelScrollDelta = 0;
} else if (this.mPixelScrollDelta < -pixelThreshold) {
deltaView = -1;
this.mPixelScrollDelta = 0;
}
}
if (deltaView != 0) {
this.moveView(deltaView);
}
}
// Prevent default scroll handling

Просмотреть файл

@ -327,7 +327,7 @@
this.calendarView.setSelectedItems(0, []);
}
]]></handler>
<handler event="DOMMouseScroll"><![CDATA[
<handler event="wheel"><![CDATA[
if (getParentNodeOrThisByAttribute(event.originalTarget, "anonid", "day-label") == null) {
if (this.dayitems.scrollHeight > this.dayitems.clientHeight) {
event.stopPropagation();
@ -1000,18 +1000,34 @@
</implementation>
<handlers>
<handler event="DOMMouseScroll"><![CDATA[
<handler event="wheel"><![CDATA[
const pixelThreshold = 150;
let scrollEnabled = getPrefSafe('calendar.view.mousescroll', true);
if (!event.ctrlKey &&
!event.shiftKey &&
!event.altKey &&
!event.metaKey &&
scrollEnabled) {
if (!event.ctrlKey && !event.shiftKey &&
!event.altKey && !event.metaKey && scrollEnabled) {
// In the month view, the only thing that can be scrolled
// is the month the user is in. calendar-base-view takes care
// of the shift key, so only move the view when no modifier
// is pressed.
this.moveView(event.detail < 0 ? -1 : 1);
let deltaView = 0;
if (event.deltaMode == event.DOM_DELTA_LINE) {
if (event.deltaY != 0) {
deltaView = event.deltaY < 0 ? -1 : 1;
}
} else if (event.deltaMode == event.DOM_DELTA_PIXEL) {
this.mPixelScrollDelta += event.deltaY;
if (this.mPixelScrollDelta > pixelThreshold){
deltaView = 1;
this.mPixelScrollDelta = 0;
} else if (this.mPixelScrollDelta < -pixelThreshold) {
deltaView = -1;
this.mPixelScrollDelta = 0;
}
}
if (deltaView != 0) {
this.moveView(deltaView);
}
}
]]></handler>
</handlers>

Просмотреть файл

@ -2134,7 +2134,7 @@
this.calendarView.selectedDateTime = newStart;
event.stopPropagation();
]]></handler>
<handler event="DOMMouseScroll"><![CDATA[
<handler event="wheel"><![CDATA[
if (this.getAttribute("orient") == "vertical") {
// In vertical view (normal), don't let the parent multiday view
// handle the scrolling in its bubbling phase. The default action
@ -3732,14 +3732,26 @@
<handler event="click" button="2"><![CDATA[
this.selectedDateTime = null;
]]></handler>
<handler event="DOMMouseScroll" phase="bubbling"><![CDATA[
if (!event.ctrlKey &&
!event.shiftKey &&
!event.altKey &&
!event.metaKey) {
<handler event="wheel" phase="bubbling"><![CDATA[
if (!event.ctrlKey && !event.shiftKey &&
!event.altKey && !event.metaKey) {
// Only shift hours if no modifier is pressed.
this.scrollToMinute(this.mFirstVisibleMinute +
(event.detail < 0 ? -60 : 60));
let minute = this.mFirstVisibleMinute;
if (event.deltaMode == event.DOM_DELTA_LINE) {
if (this.rotated && event.deltaX != 0) {
minute += event.deltaX < 0 ? -60 : 60;
} else if (!this.rotated && event.deltaY != 0) {
minute += event.deltaY < 0 ? -60 : 60;
}
} else if (event.deltaMode == event.DOM_DELTA_PIXEL) {
if (this.rotated && event.deltaX != 0) {
minute += Math.ceil(event.deltaX / this.mPixPerMin);
} else if (!this.rotated && event.deltaY != 0) {
minute += Math.ceil(event.deltaY / this.mPixPerMin);
}
}
this.scrollToMinute(minute);
}
// We are taking care of scrolling, so prevent the default

Просмотреть файл

@ -27,11 +27,15 @@ function onLoad() {
window.addEventListener("resize", onResize, true);
window.addEventListener("modify", onModify, true);
window.addEventListener("rowchange", onRowChange, true);
window.addEventListener("DOMMouseScroll", onMouseScroll, true);
window.addEventListener("DOMAttrModified", onAttrModified, true);
window.addEventListener("timebar", onTimebar, true);
window.addEventListener("timechange", onTimeChange, true);
// As long as DOMMouseScroll is still implemented, we need to keep it
// around to make sure scrolling is blocked.
window.addEventListener("wheel", onMouseScroll, true);
window.addEventListener("DOMMouseScroll", onMouseScroll, true);
var args = window.arguments[0];
var startTime = args.startTime;
var endTime = args.endTime;
@ -852,7 +856,7 @@ function onRowChange(event) {
/**
* Handler function to take care of mouse scrolling on the window
*
* @param event The DOMMouseScroll event caused by scrolling.
* @param event The wheel event caused by scrolling.
*/
function onMouseScroll(event) {
// ignore mouse scrolling for now...

Просмотреть файл

@ -135,26 +135,24 @@
<implementation>
<field name="kMinimonth">null</field>
<field name="mPopup">null</field>
<field name="mScrollYearsHandler">{}</field>
<field name="mScrollYearsHandler">null</field>
<field name="mPixelScrollDelta">0</field>
<constructor><![CDATA[
this.kMinimonth = getParentNodeOrThis(this, "minimonth");
document.getAnonymousElementByAttribute(this, "anonid", "back-button").kMinimonth = this.kMinimonth;
document.getAnonymousElementByAttribute(this, "anonid", "today-button").kMinimonth = this.kMinimonth;
document.getAnonymousElementByAttribute(this, "anonid", "forward-button").kMinimonth = this.kMinimonth;
this.mScrollYearsHandler = {
binding: this,
handleEvent: function scrollYears_handleEvent(event) {
this.binding.scrollYears(event);
}
};
this.mScrollYearsHandler = this.scrollYears.bind(this);
document.getAnonymousElementByAttribute(this, "anonid", "years-popup")
.addEventListener("DOMMouseScroll", this.mScrollYearsHandler, true);
.addEventListener("wheel", this.mScrollYearsHandler, true);
]]></constructor>
<destructor><![CDATA[
document.getAnonymousElementByAttribute(this, "anonid", "years-popup")
.removeEventListener("DOMMouseScroll", this.mScrollYearsHandler, true);
this.mScrollYearsHandler.binding = null;
.removeEventListener("wheel", this.mScrollYearsHandler, true);
this.mScrollYearsHandler = null;
]]></destructor>
<method name="showPopupList">
<parameter name="aEvent"/>
<parameter name="aPopupAnonId"/>
@ -214,18 +212,27 @@
<parameter name="event"/>
<body><![CDATA[
let yearPopup = getParentNodeOrThis(event.target, "menupopup");
const pixelThreshold = 75;
if (yearPopup) {
let monthList = yearPopup.getElementsByAttribute("class", "minimonth-list");
if (monthList && monthList.length > 0) {
if (event.detail == UIEvent.SCROLL_PAGE_UP) {
this.moveYears('up', monthList.length);
} else if (event.detail == UIEvent.SCROLL_PAGE_DOWN) {
this.moveYears('down', monthList.length);
} else if (event.detail < 0) {
this.moveYears('up', 1);
} else if (event.detail > 0) {
this.moveYears('down', 1);
if (event.deltaMode == event.DOM_DELTA_PAGE) {
let dir = (event.deltaY > 0 ? "up" : "down");
this.moveYears(dir, Math.abs(event.deltaY) * monthList.length);
} else if (event.deltaMode == event.DOM_DELTA_LINE) {
let dir = (event.deltaY > 0 ? "up" : "down");
this.moveYears(dir, 1);
} else if (event.deltaMode == event.DOM_DELTA_PIXEL) {
this.mPixelScrollDelta += event.deltaY;
if (this.mPixelScrollDelta > pixelThreshold) {
this.moveYears("down", 1);
this.mPixelScrollDelta = 0;
} else if (this.mPixelScrollDelta < -pixelThreshold) {
this.moveYears("up", 1);
this.mPixelScrollDelta = 0;
}
}
event.stopPropagation();
event.preventDefault();
}
@ -406,6 +413,7 @@
<field name="mDaymap">null</field>
<field name="mValue">null</field>
<field name="mEditorDate">null</field>
<field name="mPixelScrollDelta">0</field>
<field name="mIsReadOnly">false</field>
<field name="mObservesComposite">false</field>
<constructor><![CDATA[
@ -1108,23 +1116,36 @@
</method>
</implementation>
<handlers>
<handler event="DOMMouseScroll">
<handler event="wheel">
<![CDATA[
const pixelThreshold = 150;
let deltaView = 0;
if (this.mIsReadOnly) {
// No scrolling on readonly months
return;
}
var rows = event.detail;
if (rows == UIEvent.SCROLL_PAGE_UP) {
rows = -1;
} else if (rows == UIEvent.SCROLL_PAGE_DOWN) {
rows = 1;
} else {
// In this case event.detail contains the default number of lines
// to scroll. We always want to only scroll 1 month though
rows = (rows > 0) ? 1 : -1;
if (event.deltaMode == event.DOM_DELTA_LINE ||
event.deltaMode == event.DOM_DELTA_PAGE) {
if (event.deltaY != 0) {
deltaView = event.deltaY > 0 ? 1 : -1;
}
} else if (event.deltaMode == event.DOM_DELTA_PIXEL) {
this.mPixelScrollDelta += event.deltaY;
if (this.mPixelScrollDelta > pixelThreshold) {
deltaView = 1;
this.mPixelScrollDelta = 0;
} else if (this.mPixelScrollDelta < -pixelThreshold) {
deltaView = -1;
this.mPixelScrollDelta = 0;
}
}
this.advanceMonth(rows);
if (deltaView != 0){
this.advanceMonth(deltaView);
}
event.stopPropagation();
event.preventDefault();
]]>
</handler>
</handlers>

Просмотреть файл

@ -525,20 +525,39 @@
</xul:vbox>
<xul:spacer flex="1"/>
</content>
<implementation>
<field name="mPixelScrollDelta">0</field>
</implementation>
<handlers>
<handler event="DOMMouseScroll">
<handler event="wheel">
<![CDATA[
var rows = event.detail;
if (rows == UIEvent.SCROLL_PAGE_UP) {
rows = -1;
} else if (rows == UIEvent.SCROLL_PAGE_DOWN) {
rows = 1;
} else {
// In this case event.detail contains the default number of lines
// to scroll. We always want to only scroll 1 hour though
rows = (rows > 0) ? 1 : -1;
}
moveHours(rows);
const pixelThreshold = 50;
let deltaView = 0;
if (event.deltaMode == event.DOM_DELTA_PAGE ||
event.deltaMode == event.DOM_DELTA_LINE) {
// Line/Page scrolling is usually vertical
if (event.deltaY) {
deltaView = event.deltaY < 0 ? -1 : 1;
}
} else if (event.deltaMode == event.DOM_DELTA_PIXEL) {
// The natural direction for pixel scrolling is left/right
this.mPixelScrollDelta += event.deltaX
if (this.mPixelScrollDelta > pixelThreshold) {
deltaView = 1;
this.mPixelScrollDelta = 0;
} else if (this.mPixelScrollDelta < -pixelThreshold) {
deltaView = -1;
this.mPixelScrollDelta = 0;
}
}
if (deltaView != 0) {
moveHours(deltaView);
}
event.stopPropagation();
event.preventDefault();
]]>
</handler>
</handlers>
@ -555,20 +574,39 @@
</xul:vbox>
<xul:spacer flex="1"/>
</content>
<implementation>
<field name="mPixelScrollDelta">0</field>
</implementation>
<handlers>
<handler event="DOMMouseScroll">
<handler event="wheel">
<![CDATA[
var rows = event.detail;
if (rows == UIEvent.SCROLL_PAGE_UP) {
rows = -1;
} else if (rows == UIEvent.SCROLL_PAGE_DOWN) {
rows = 1;
} else {
// In this case event.detail contains the default number of lines
// to scroll. We always want to only scroll 1 minute though
rows = (rows > 0) ? 1 : -1;
}
moveMinutes(rows);
const pixelThreshold = 50;
let deltaView = 0;
if (event.deltaMode == event.DOM_DELTA_PAGE ||
event.deltaMode == event.DOM_DELTA_LINE) {
// Line/Page scrolling is usually vertical
if (event.deltaY) {
deltaView = event.deltaY < 0 ? -1 : 1;
}
} else if (event.deltaMode == event.DOM_DELTA_PIXEL) {
// The natural direction for pixel scrolling is left/right
this.mPixelScrollDelta += event.deltaX
if (this.mPixelScrollDelta > pixelThreshold) {
deltaView = 1;
this.mPixelScrollDelta = 0;
} else if (this.mPixelScrollDelta < -pixelThreshold) {
deltaView = -1;
this.mPixelScrollDelta = 0;
}
}
if (deltaView != 0) {
moveMinutes(deltaView);
}
event.stopPropagation();
event.preventDefault();
]]>
</handler>
</handlers>