Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / forms / calendar-picker / resources / calendar-picker-common.js
blob36374f784c790282c2c93aecb0cd3011b4c05c51
1 function currentMonth() {
2     return popupWindow.global.picker.currentMonth().toString();
5 function availableDayCells() {
6     skipAnimation();
7     return Array.prototype.map.call(popupWindow.document.querySelectorAll(".day-cell:not(.disabled):not(.hidden)"), function(element) {
8         return element.$view.day.toString();
9     }).sort().join();
12 function highlightedDayCells() {
13     skipAnimation();
14     return Array.prototype.map.call(popupWindow.document.querySelectorAll(".day-cell.highlighted:not(.hidden)"), function(element) {
15         return element.$view.day.toString();
16     }).sort().join();
19 function selectedDayCells() {
20     skipAnimation();
21     return Array.prototype.map.call(popupWindow.document.querySelectorAll(".day-cell.selected:not(.hidden)"), function(element) {
22         return element.$view.day.toString();
23     }).sort().join();
26 function availableWeekNumberCells() {
27     skipAnimation();
28     return Array.prototype.map.call(popupWindow.document.querySelectorAll(".week-number-cell.highlighted:not(.hidden)"), function(element) {
29         return element.$view.day.toString();
30     }).sort().join();
33 function highlightedWeekNumberCells() {
34     skipAnimation();
35     return Array.prototype.map.call(popupWindow.document.querySelectorAll(".week-number-cell.highlighted:not(.hidden)"), function(element) {
36         return element.$view.day.toString();
37     }).sort().join();
40 function selectedWeekNumberCells() {
41     skipAnimation();
42     return Array.prototype.map.call(popupWindow.document.querySelectorAll(".week-number-cell.selected:not(.hidden)"), function(element) {
43         return element.$view.day.toString();
44     }).sort().join();
47 function highlightedValue() {
48     var highlight = popupWindow.global.picker.highlight();
49     if (highlight)
50         return highlight.toString();
51     return null;
54 function selectedValue() {
55     var selection = popupWindow.global.picker.selection();
56     if (selection)
57         return selection.toString();
58     return null;
61 function skipAnimation() {
62     popupWindow.AnimationManager.shared._animationFrameCallback(Infinity);
65 function hoverOverDayCellAt(column, row) {
66     skipAnimation();
67     var offset = cumulativeOffset(popupWindow.global.picker.calendarTableView.element);
68     var x = offset[0];
69     var y = offset[1];
70     if (popupWindow.global.picker.calendarTableView.hasWeekNumberColumn)
71         x += popupWindow.WeekNumberCell.Width;
72     x += (column + 0.5) * popupWindow.DayCell.Width;
73     y += (row + 0.5) * popupWindow.DayCell.Height + popupWindow.CalendarTableHeaderView.Height;
74     eventSender.mouseMoveTo(x, y);
77 function clickDayCellAt(column, row) {
78     hoverOverDayCellAt(column, row);
79     eventSender.mouseDown();
80     eventSender.mouseUp();
83 function highlightedMonthButton() {
84     skipAnimation();
85     var year = popupWindow.global.picker.monthPopupView.yearListView.selectedRow + 1;
86     return Array.prototype.map.call(popupWindow.document.querySelectorAll(".month-button.highlighted"), function(element) {
87         return new popupWindow.Month(year, Number(element.dataset.month)).toString();
88     }).sort().join();
91 function skipAnimationAndGetPositionOfMonthPopupButton() {
92     skipAnimation();
93     var buttonElement = popupWindow.global.picker.calendarHeaderView.monthPopupButton.element;
94     var offset = cumulativeOffset(buttonElement);
95     return {x: offset[0] + buttonElement.offsetWidth / 2, y: offset[1] + buttonElement.offsetHeight / 2};
98 function hoverOverMonthPopupButton() {
99     var position = skipAnimationAndGetPositionOfMonthPopupButton();
100     eventSender.mouseMoveTo(position.x, position.y);
103 function clickMonthPopupButton() {
104     hoverOverMonthPopupButton();
105     eventSender.mouseDown();
106     eventSender.mouseUp();
109 function clickYearListCell(year) {
110     skipAnimation();
111     var row = year - 1;
112     var rowCell = popupWindow.global.picker.monthPopupView.yearListView.cellAtRow(row);
114     var rowScrollOffset = popupWindow.global.picker.monthPopupView.yearListView.scrollOffsetForRow(row);
115     var scrollOffset = popupWindow.global.picker.monthPopupView.yearListView.scrollView.contentOffset();
116     var rowOffsetFromViewportTop = rowScrollOffset - scrollOffset;
118     var scrollViewOffset = cumulativeOffset(popupWindow.global.picker.monthPopupView.yearListView.scrollView.element);
119     var rowCellCenterX = scrollViewOffset[0] + rowCell.element.offsetWidth / 2;
120     var rowCellCenterY = scrollViewOffset[1] + rowOffsetFromViewportTop + rowCell.element.offsetHeight / 2;
121     eventSender.mouseMoveTo(rowCellCenterX, rowCellCenterY);
122     eventSender.mouseDown();
123     eventSender.mouseUp();
126 function skipAnimationAndGetPositionOfMonthButton(year, month) {
127     skipAnimation();
128     var row = year - 1;
129     var rowCell = popupWindow.global.picker.monthPopupView.yearListView.cellAtRow(row);
131     var rowScrollOffset = popupWindow.global.picker.monthPopupView.yearListView.scrollOffsetForRow(row);
132     var scrollOffset = popupWindow.global.picker.monthPopupView.yearListView.scrollView.contentOffset();
133     var rowOffsetFromViewportTop = rowScrollOffset - scrollOffset;
135     var button = popupWindow.global.picker.monthPopupView.yearListView.buttonForMonth(new popupWindow.Month(year, month));
136     var buttonOffset = cumulativeOffset(button);
137     var rowCellOffset = cumulativeOffset(rowCell.element);
138     var buttonOffsetRelativeToRowCell = [buttonOffset[0] - rowCellOffset[0], buttonOffset[1] - rowCellOffset[1]];
140     var scrollViewOffset = cumulativeOffset(popupWindow.global.picker.monthPopupView.yearListView.scrollView.element);
141     var buttonCenterX = scrollViewOffset[0] + buttonOffsetRelativeToRowCell[0] + button.offsetWidth / 2;
142     var buttonCenterY = scrollViewOffset[1] + buttonOffsetRelativeToRowCell[1] + rowOffsetFromViewportTop + button.offsetHeight / 2;
143     return {x: buttonCenterX, y: buttonCenterY};
146 function hoverOverMonthButton(year, month) {
147     var position = skipAnimationAndGetPositionOfMonthButton(year, month);
148     eventSender.mouseMoveTo(position.x, position.y);
151 function clickMonthButton(year, month) {
152     hoverOverMonthButton(year, month);
153     eventSender.mouseDown();
154     eventSender.mouseUp();
157 var lastYearListViewScrollOffset = NaN;
158 function checkYearListViewScrollOffset() {
159     skipAnimation();
160     var scrollOffset = popupWindow.global.picker.monthPopupView.yearListView.scrollView.contentOffset();
161     var change = lastYearListViewScrollOffset - scrollOffset;
162     lastYearListViewScrollOffset = scrollOffset;
163     return change;
166 function isCalendarTableScrollingWithAnimation() {
167     var animator = popupWindow.global.picker.calendarTableView.scrollView.scrollAnimator();
168     if (!animator)
169         return false;
170     return animator.isRunning();
173 function removeCommitDelay() {
174     popupWindow.CalendarPicker.commitDelayMs = 0;
177 function setNoCloseOnCommit() {
178     popupWindow.CalendarPicker.commitDelayMs = -1;