Page popup should be smarter about its layout
authorkeishi@webkit.org <keishi@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 9 Oct 2012 08:17:44 +0000 (08:17 +0000)
committerkeishi@webkit.org <keishi@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 9 Oct 2012 08:17:44 +0000 (08:17 +0000)
https://bugs.webkit.org/show_bug.cgi?id=98499

Reviewed by Kent Tamura.

Source/WebCore:

This change fixes these two issues:
1. Page popup should reposition itself so it won't get clipped by screen(Win/Linux) or rootview(Mac) bounds.
2. Page popup should resize itself when it doesn't fit.

Test: platform/chromium/fast/forms/page-popup/page-popup-adjust-rect.html

* Resources/pagepopups/calendarPicker.js:
(initialize): We need to set global.params at the beginning because we need it for resizeWindow().
* Resources/pagepopups/colorSuggestionPicker.js: Added global.params.
(handleMessage):
(initialize):
(handleArgumentsTimeout):
* Resources/pagepopups/pickerCommon.js:
(Rect): Represents an axis aligned rectangle.
(Rect.prototype.get maxX): Gets position of right edge.
(Rect.prototype.get maxY): Gets position of bottom edge.
(Rect.prototype.toString):
(Rect.intersection): Returns the intersection of two rectangles.
(resizeWindow): Resize window to a certain size. Don't allow shrinking.
(adjustWindowRect): Calculates the best position and size for the popup.
(_adjustWindowRectVertically):
(_adjustWindowRectHorizontally):
(setWindowRect): Sets the position and size of the popup to the given rect.
* Resources/pagepopups/suggestionPicker.css:
(.suggestion-list): Don't show horizontal scroll bar.
* Resources/pagepopups/suggestionPicker.js:
(SuggestionPicker.prototype._fixWindowSize):
* page/PagePopupClient.cpp:
(WebCore::PagePopupClient::addProperty): For adding an int to JSON.
(WebCore::PagePopupClient::addProperty): For adding an IntRect to JSON.
(WebCore):
* page/PagePopupClient.h:
(PagePopupClient):

Source/WebKit/chromium:

* src/ColorChooserUIController.cpp:
(WebKit::ColorChooserUIController::writeDocument): Send anchorRectInScreen, rootViewRectInScreen, and confineToRootView.
* src/DateTimeChooserImpl.cpp:
(WebKit::DateTimeChooserImpl::writeDocument): Send anchorRectInScreen, rootViewRectInScreen, and confineToRootView.
* src/WebPagePopupImpl.cpp:
(WebKit::WebPagePopupImpl::init): We keep the originBoundsInRootView argument for MockPagePopupDriver.
(WebKit::WebPagePopupImpl::resize): WebPagePopupImpl isn't in charge of setting the popup position any more.
* src/WebPagePopupImpl.h:
(WebPagePopupImpl):

LayoutTests:

* platform/chromium/fast/forms/page-popup/page-popup-adjust-rect-expected.txt: Added.
* platform/chromium/fast/forms/page-popup/page-popup-adjust-rect.html: Added.
* platform/chromium-android/TestExpectations: Added platform/chromium/fast/forms/page-popup.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@130734 268f45cc-cd09-0410-ab3c-d52691b4dbfc

17 files changed:
LayoutTests/ChangeLog
LayoutTests/platform/chromium-android/TestExpectations
LayoutTests/platform/chromium/fast/forms/page-popup/page-popup-adjust-rect-expected.txt [new file with mode: 0644]
LayoutTests/platform/chromium/fast/forms/page-popup/page-popup-adjust-rect.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/Resources/pagepopups/calendarPicker.js
Source/WebCore/Resources/pagepopups/colorSuggestionPicker.js
Source/WebCore/Resources/pagepopups/pickerCommon.js
Source/WebCore/Resources/pagepopups/suggestionPicker.css
Source/WebCore/Resources/pagepopups/suggestionPicker.js
Source/WebCore/page/PagePopupClient.cpp
Source/WebCore/page/PagePopupClient.h
Source/WebKit/chromium/ChangeLog
Source/WebKit/chromium/src/ColorChooserUIController.cpp
Source/WebKit/chromium/src/DateTimeChooserImpl.cpp
Source/WebKit/chromium/src/WebPagePopupImpl.cpp
Source/WebKit/chromium/src/WebPagePopupImpl.h

index 0fa8afd..f21a042 100644 (file)
@@ -1,3 +1,14 @@
+2012-10-09  Keishi Hattori  <keishi@webkit.org>
+
+        Page popup should be smarter about its layout
+        https://bugs.webkit.org/show_bug.cgi?id=98499
+
+        Reviewed by Kent Tamura.
+
+        * platform/chromium/fast/forms/page-popup/page-popup-adjust-rect-expected.txt: Added.
+        * platform/chromium/fast/forms/page-popup/page-popup-adjust-rect.html: Added.
+        * platform/chromium-android/TestExpectations: Added platform/chromium/fast/forms/page-popup.
+
 2012-10-09  Csaba Osztrogon√°c  <ossy@webkit.org>
 
         [Qt] Unskip now passing tests.
index 5c333ad..2057aaa 100644 (file)
@@ -82,3 +82,6 @@ fast/forms/date-multiple-fields [ WontFix ]
 fast/forms/month-multiple-fields [ WontFix ]
 fast/forms/time-multiple-fields [ WontFix ]
 fast/forms/week-multiple-fields [ WontFix ]
+
+# Page popup UI is for desktop platforms
+platform/chromium/fast/forms/page-popup [ WontFix ]
diff --git a/LayoutTests/platform/chromium/fast/forms/page-popup/page-popup-adjust-rect-expected.txt b/LayoutTests/platform/chromium/fast/forms/page-popup/page-popup-adjust-rect-expected.txt
new file mode 100644 (file)
index 0000000..e5fa024
--- /dev/null
@@ -0,0 +1,69 @@
+Test for child elements of a datalist element.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Move anchor element along the vertical axis.
+PASS popupWindow.adjustWindowRect(30, 10, 30, 10).toString() is "Rect(0,0,30,10)"
+PASS popupWindow.adjustWindowRect(30, 10, 30, 10).toString() is "Rect(0,0,30,10)"
+PASS popupWindow.adjustWindowRect(30, 10, 30, 10).toString() is "Rect(0,10,30,10)"
+PASS popupWindow.adjustWindowRect(30, 10, 30, 10).toString() is "Rect(0,20,30,10)"
+PASS popupWindow.adjustWindowRect(30, 10, 30, 10).toString() is "Rect(0,30,30,10)"
+PASS popupWindow.adjustWindowRect(30, 10, 30, 10).toString() is "Rect(0,40,30,10)"
+PASS popupWindow.adjustWindowRect(30, 10, 30, 10).toString() is "Rect(0,50,30,10)"
+PASS popupWindow.adjustWindowRect(30, 10, 30, 10).toString() is "Rect(0,40,30,10)"
+PASS popupWindow.adjustWindowRect(30, 10, 30, 10).toString() is "Rect(0,50,30,10)"
+PASS popupWindow.adjustWindowRect(30, 10, 30, 10).toString() is "Rect(0,50,30,10)"
+PASS popupWindow.adjustWindowRect(30, 10, 30, 10).toString() is "Rect(0,50,30,10)"
+Move anchor element along the horizontal axis.
+PASS popupWindow.adjustWindowRect(30, 10, 30, 10).toString() is "Rect(0,10,30,10)"
+PASS popupWindow.adjustWindowRect(30, 10, 30, 10).toString() is "Rect(0,10,30,10)"
+PASS popupWindow.adjustWindowRect(30, 10, 30, 10).toString() is "Rect(0,10,30,10)"
+PASS popupWindow.adjustWindowRect(30, 10, 30, 10).toString() is "Rect(0,10,30,10)"
+PASS popupWindow.adjustWindowRect(30, 10, 30, 10).toString() is "Rect(0,10,30,10)"
+PASS popupWindow.adjustWindowRect(30, 10, 30, 10).toString() is "Rect(10,10,30,10)"
+PASS popupWindow.adjustWindowRect(30, 10, 30, 10).toString() is "Rect(20,10,30,10)"
+PASS popupWindow.adjustWindowRect(30, 10, 30, 10).toString() is "Rect(30,10,30,10)"
+PASS popupWindow.adjustWindowRect(30, 10, 30, 10).toString() is "Rect(40,10,30,10)"
+PASS popupWindow.adjustWindowRect(30, 10, 30, 10).toString() is "Rect(50,10,30,10)"
+PASS popupWindow.adjustWindowRect(30, 10, 30, 10).toString() is "Rect(50,10,30,10)"
+PASS popupWindow.adjustWindowRect(30, 10, 30, 10).toString() is "Rect(50,10,30,10)"
+PASS popupWindow.adjustWindowRect(30, 10, 30, 10).toString() is "Rect(50,10,30,10)"
+PASS popupWindow.adjustWindowRect(30, 10, 30, 10).toString() is "Rect(50,10,30,10)"
+PASS popupWindow.adjustWindowRect(30, 10, 30, 10).toString() is "Rect(50,10,30,10)"
+Move anchor element along the vertical axis. Open popup that is too tall.
+PASS popupWindow.adjustWindowRect(30, 1000, 30, 10).toString() is "Rect(0,0,30,60)"
+PASS popupWindow.adjustWindowRect(30, 1000, 30, 10).toString() is "Rect(0,0,30,60)"
+PASS popupWindow.adjustWindowRect(30, 1000, 30, 10).toString() is "Rect(0,10,30,50)"
+PASS popupWindow.adjustWindowRect(30, 1000, 30, 10).toString() is "Rect(0,20,30,40)"
+PASS popupWindow.adjustWindowRect(30, 1000, 30, 10).toString() is "Rect(0,30,30,30)"
+PASS popupWindow.adjustWindowRect(30, 1000, 30, 10).toString() is "Rect(0,0,30,30)"
+PASS popupWindow.adjustWindowRect(30, 1000, 30, 10).toString() is "Rect(0,0,30,40)"
+PASS popupWindow.adjustWindowRect(30, 1000, 30, 10).toString() is "Rect(0,0,30,50)"
+PASS popupWindow.adjustWindowRect(30, 1000, 30, 10).toString() is "Rect(0,0,30,60)"
+PASS popupWindow.adjustWindowRect(30, 1000, 30, 10).toString() is "Rect(0,0,30,60)"
+PASS popupWindow.adjustWindowRect(30, 1000, 30, 10).toString() is "Rect(0,0,30,60)"
+Move anchor element along the vertical axis. Open popup that is too tall and won't shrink.
+PASS popupWindow.adjustWindowRect(30, 1000, 30, 1000).toString() is "Rect(0,0,30,1000)"
+PASS popupWindow.adjustWindowRect(30, 1000, 30, 1000).toString() is "Rect(0,0,30,1000)"
+PASS popupWindow.adjustWindowRect(30, 1000, 30, 1000).toString() is "Rect(0,0,30,1000)"
+PASS popupWindow.adjustWindowRect(30, 1000, 30, 1000).toString() is "Rect(0,0,30,1000)"
+PASS popupWindow.adjustWindowRect(30, 1000, 30, 1000).toString() is "Rect(0,0,30,1000)"
+PASS popupWindow.adjustWindowRect(30, 1000, 30, 1000).toString() is "Rect(0,0,30,1000)"
+PASS popupWindow.adjustWindowRect(30, 1000, 30, 1000).toString() is "Rect(0,0,30,1000)"
+PASS popupWindow.adjustWindowRect(30, 1000, 30, 1000).toString() is "Rect(0,0,30,1000)"
+PASS popupWindow.adjustWindowRect(30, 1000, 30, 1000).toString() is "Rect(0,0,30,1000)"
+PASS popupWindow.adjustWindowRect(30, 1000, 30, 1000).toString() is "Rect(0,0,30,1000)"
+PASS popupWindow.adjustWindowRect(30, 1000, 30, 1000).toString() is "Rect(0,0,30,1000)"
+Grow popup width.
+PASS popupWindow.adjustWindowRect(30, 10, 30, 10).toString() is "Rect(30,10,30,10)"
+PASS popupWindow.adjustWindowRect(40, 10, 40, 10).toString() is "Rect(30,10,40,10)"
+PASS popupWindow.adjustWindowRect(50, 10, 50, 10).toString() is "Rect(30,10,50,10)"
+PASS popupWindow.adjustWindowRect(60, 10, 60, 10).toString() is "Rect(20,10,60,10)"
+PASS popupWindow.adjustWindowRect(70, 10, 70, 10).toString() is "Rect(10,10,70,10)"
+PASS popupWindow.adjustWindowRect(80, 10, 80, 10).toString() is "Rect(0,10,80,10)"
+PASS popupWindow.adjustWindowRect(90, 10, 90, 10).toString() is "Rect(0,10,90,10)"
+PASS successfullyParsed is true
+
+TEST COMPLETE
diff --git a/LayoutTests/platform/chromium/fast/forms/page-popup/page-popup-adjust-rect.html b/LayoutTests/platform/chromium/fast/forms/page-popup/page-popup-adjust-rect.html
new file mode 100644 (file)
index 0000000..bdca888
--- /dev/null
@@ -0,0 +1,223 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../../../../fast/js/resources/js-test-pre.js"></script>
+<script src="../../../../../fast/forms/resources/common.js"></script>
+<script src="../../../../../fast/forms/date/calendar-picker-common.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<input type="date" id="date">
+
+<script>
+description('Test for child elements of a datalist element.');
+
+openPicker(document.getElementById('date'));
+
+popupWindow.addEventListener("resize", test, false);
+
+function makeRect(x, y, width, height) {
+    return {
+        x: x,
+        y: y,
+        width: width,
+        height: height
+    };
+}
+
+function test() {
+    popupWindow.global.params.confineToRootView = false;
+    popupWindow.screen = {
+        width: 80,
+        height: 60,
+        availLeft: 0,
+        availTop: 0,
+        availWidth: 80,
+        availHeight: 60,
+    };
+    popupWindow.global.params.rootViewRectInScreen = makeRect(0, 0, 80, 60);
+
+    debug("Move anchor element along the vertical axis.");
+
+    popupWindow.global.params.anchorRectInScreen = makeRect(0, -20, 20, 10);
+    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 10, 30, 10).toString()', 'Rect(0,0,30,10)');
+
+    popupWindow.global.params.anchorRectInScreen = makeRect(0, -10, 20, 10);
+    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 10, 30, 10).toString()', 'Rect(0,0,30,10)');
+
+    popupWindow.global.params.anchorRectInScreen = makeRect(0, 0, 20, 10);
+    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 10, 30, 10).toString()', 'Rect(0,10,30,10)');
+
+    popupWindow.global.params.anchorRectInScreen = makeRect(0, 10, 20, 10);
+    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 10, 30, 10).toString()', 'Rect(0,20,30,10)');
+
+    popupWindow.global.params.anchorRectInScreen = makeRect(0, 20, 20, 10);
+    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 10, 30, 10).toString()', 'Rect(0,30,30,10)');
+
+    popupWindow.global.params.anchorRectInScreen = makeRect(0, 30, 20, 10);
+    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 10, 30, 10).toString()', 'Rect(0,40,30,10)');
+
+    popupWindow.global.params.anchorRectInScreen = makeRect(0, 40, 20, 10);
+    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 10, 30, 10).toString()', 'Rect(0,50,30,10)');
+
+    popupWindow.global.params.anchorRectInScreen = makeRect(0, 50, 20, 10);
+    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 10, 30, 10).toString()', 'Rect(0,40,30,10)');
+
+    popupWindow.global.params.anchorRectInScreen = makeRect(0, 60, 20, 10);
+    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 10, 30, 10).toString()', 'Rect(0,50,30,10)');
+
+    popupWindow.global.params.anchorRectInScreen = makeRect(0, 70, 20, 10);
+    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 10, 30, 10).toString()', 'Rect(0,50,30,10)');
+
+    popupWindow.global.params.anchorRectInScreen = makeRect(0, 80, 20, 10);
+    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 10, 30, 10).toString()', 'Rect(0,50,30,10)');
+
+    debug("Move anchor element along the horizontal axis.");
+
+    popupWindow.global.params.anchorRectInScreen = makeRect(-40, 0, 20, 10);
+    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 10, 30, 10).toString()', 'Rect(0,10,30,10)');
+
+    popupWindow.global.params.anchorRectInScreen = makeRect(-30, 0, 20, 10);
+    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 10, 30, 10).toString()', 'Rect(0,10,30,10)');
+
+    popupWindow.global.params.anchorRectInScreen = makeRect(-20, 0, 20, 10);
+    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 10, 30, 10).toString()', 'Rect(0,10,30,10)');
+
+    popupWindow.global.params.anchorRectInScreen = makeRect(-10, 0, 20, 10);
+    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 10, 30, 10).toString()', 'Rect(0,10,30,10)');
+
+    popupWindow.global.params.anchorRectInScreen = makeRect(0, 0, 20, 10);
+    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 10, 30, 10).toString()', 'Rect(0,10,30,10)');
+
+    popupWindow.global.params.anchorRectInScreen = makeRect(10, 0, 20, 10);
+    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 10, 30, 10).toString()', 'Rect(10,10,30,10)');
+
+    popupWindow.global.params.anchorRectInScreen = makeRect(20, 0, 20, 10);
+    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 10, 30, 10).toString()', 'Rect(20,10,30,10)');
+
+    popupWindow.global.params.anchorRectInScreen = makeRect(30, 0, 20, 10);
+    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 10, 30, 10).toString()', 'Rect(30,10,30,10)');
+
+    popupWindow.global.params.anchorRectInScreen = makeRect(40, 0, 20, 10);
+    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 10, 30, 10).toString()', 'Rect(40,10,30,10)');
+
+    popupWindow.global.params.anchorRectInScreen = makeRect(50, 0, 20, 10);
+    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 10, 30, 10).toString()', 'Rect(50,10,30,10)');
+
+    popupWindow.global.params.anchorRectInScreen = makeRect(60, 0, 20, 10);
+    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 10, 30, 10).toString()', 'Rect(50,10,30,10)');
+
+    popupWindow.global.params.anchorRectInScreen = makeRect(70, 0, 20, 10);
+    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 10, 30, 10).toString()', 'Rect(50,10,30,10)');
+
+    popupWindow.global.params.anchorRectInScreen = makeRect(80, 0, 20, 10);
+    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 10, 30, 10).toString()', 'Rect(50,10,30,10)');
+
+    popupWindow.global.params.anchorRectInScreen = makeRect(90, 0, 20, 10);
+    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 10, 30, 10).toString()', 'Rect(50,10,30,10)');
+
+    popupWindow.global.params.anchorRectInScreen = makeRect(100, 0, 20, 10);
+    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 10, 30, 10).toString()', 'Rect(50,10,30,10)');
+
+    debug("Move anchor element along the vertical axis. Open popup that is too tall.");
+
+    popupWindow.global.params.anchorRectInScreen = makeRect(0, -20, 20, 10);
+    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 1000, 30, 10).toString()', 'Rect(0,0,30,60)');
+
+    popupWindow.global.params.anchorRectInScreen = makeRect(0, -10, 20, 10);
+    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 1000, 30, 10).toString()', 'Rect(0,0,30,60)');
+
+    popupWindow.global.params.anchorRectInScreen = makeRect(0, 0, 20, 10);
+    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 1000, 30, 10).toString()', 'Rect(0,10,30,50)');
+
+    popupWindow.global.params.anchorRectInScreen = makeRect(0, 10, 20, 10);
+    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 1000, 30, 10).toString()', 'Rect(0,20,30,40)');
+
+    popupWindow.global.params.anchorRectInScreen = makeRect(0, 20, 20, 10);
+    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 1000, 30, 10).toString()', 'Rect(0,30,30,30)');
+
+    popupWindow.global.params.anchorRectInScreen = makeRect(0, 30, 20, 10);
+    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 1000, 30, 10).toString()', 'Rect(0,0,30,30)');
+
+    popupWindow.global.params.anchorRectInScreen = makeRect(0, 40, 20, 10);
+    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 1000, 30, 10).toString()', 'Rect(0,0,30,40)');
+
+    popupWindow.global.params.anchorRectInScreen = makeRect(0, 50, 20, 10);
+    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 1000, 30, 10).toString()', 'Rect(0,0,30,50)');
+
+    popupWindow.global.params.anchorRectInScreen = makeRect(0, 60, 20, 10);
+    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 1000, 30, 10).toString()', 'Rect(0,0,30,60)');
+
+    popupWindow.global.params.anchorRectInScreen = makeRect(0, 70, 20, 10);
+    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 1000, 30, 10).toString()', 'Rect(0,0,30,60)');
+
+    popupWindow.global.params.anchorRectInScreen = makeRect(0, 80, 20, 10);
+    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 1000, 30, 10).toString()', 'Rect(0,0,30,60)');
+
+    debug("Move anchor element along the vertical axis. Open popup that is too tall and won't shrink.");
+
+    popupWindow.global.params.anchorRectInScreen = makeRect(0, -20, 20, 10);
+    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 1000, 30, 1000).toString()', 'Rect(0,0,30,1000)');
+
+    popupWindow.global.params.anchorRectInScreen = makeRect(0, -10, 20, 10);
+    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 1000, 30, 1000).toString()', 'Rect(0,0,30,1000)');
+
+    popupWindow.global.params.anchorRectInScreen = makeRect(0, 0, 20, 10);
+    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 1000, 30, 1000).toString()', 'Rect(0,0,30,1000)');
+
+    popupWindow.global.params.anchorRectInScreen = makeRect(0, 10, 20, 10);
+    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 1000, 30, 1000).toString()', 'Rect(0,0,30,1000)');
+
+    popupWindow.global.params.anchorRectInScreen = makeRect(0, 20, 20, 10);
+    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 1000, 30, 1000).toString()', 'Rect(0,0,30,1000)');
+
+    popupWindow.global.params.anchorRectInScreen = makeRect(0, 30, 20, 10);
+    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 1000, 30, 1000).toString()', 'Rect(0,0,30,1000)');
+
+    popupWindow.global.params.anchorRectInScreen = makeRect(0, 40, 20, 10);
+    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 1000, 30, 1000).toString()', 'Rect(0,0,30,1000)');
+
+    popupWindow.global.params.anchorRectInScreen = makeRect(0, 50, 20, 10);
+    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 1000, 30, 1000).toString()', 'Rect(0,0,30,1000)');
+
+    popupWindow.global.params.anchorRectInScreen = makeRect(0, 60, 20, 10);
+    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 1000, 30, 1000).toString()', 'Rect(0,0,30,1000)');
+
+    popupWindow.global.params.anchorRectInScreen = makeRect(0, 70, 20, 10);
+    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 1000, 30, 1000).toString()', 'Rect(0,0,30,1000)');
+
+    popupWindow.global.params.anchorRectInScreen = makeRect(0, 80, 20, 10);
+    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 1000, 30, 1000).toString()', 'Rect(0,0,30,1000)');
+
+    debug("Grow popup width.");
+
+    popupWindow.global.params.anchorRectInScreen = makeRect(30, 0, 30, 10);
+    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 10, 30, 10).toString()', 'Rect(30,10,30,10)');
+
+    popupWindow.global.params.anchorRectInScreen = makeRect(30, 0, 30, 10);
+    shouldBeEqualToString('popupWindow.adjustWindowRect(40, 10, 40, 10).toString()', 'Rect(30,10,40,10)');
+
+    popupWindow.global.params.anchorRectInScreen = makeRect(30, 0, 30, 10);
+    shouldBeEqualToString('popupWindow.adjustWindowRect(50, 10, 50, 10).toString()', 'Rect(30,10,50,10)');
+
+    popupWindow.global.params.anchorRectInScreen = makeRect(30, 0, 30, 10);
+    shouldBeEqualToString('popupWindow.adjustWindowRect(60, 10, 60, 10).toString()', 'Rect(20,10,60,10)');
+
+    popupWindow.global.params.anchorRectInScreen = makeRect(30, 0, 30, 10);
+    shouldBeEqualToString('popupWindow.adjustWindowRect(70, 10, 70, 10).toString()', 'Rect(10,10,70,10)');
+
+    popupWindow.global.params.anchorRectInScreen = makeRect(30, 0, 30, 10);
+    shouldBeEqualToString('popupWindow.adjustWindowRect(80, 10, 80, 10).toString()', 'Rect(0,10,80,10)');
+
+    popupWindow.global.params.anchorRectInScreen = makeRect(30, 0, 30, 10);
+    shouldBeEqualToString('popupWindow.adjustWindowRect(90, 10, 90, 10).toString()', 'Rect(0,10,90,10)');
+
+    finishJSTest();
+}
+
+</script>
+<script src="../../../../../fast/js/resources/js-test-post.js"></script>
+</body>
+</html>
index a2e4434..1c25b54 100644 (file)
@@ -1,3 +1,44 @@
+2012-10-09  Keishi Hattori  <keishi@webkit.org>
+
+        Page popup should be smarter about its layout
+        https://bugs.webkit.org/show_bug.cgi?id=98499
+
+        Reviewed by Kent Tamura.
+
+        This change fixes these two issues:
+        1. Page popup should reposition itself so it won't get clipped by screen(Win/Linux) or rootview(Mac) bounds.
+        2. Page popup should resize itself when it doesn't fit.
+
+        Test: platform/chromium/fast/forms/page-popup/page-popup-adjust-rect.html
+
+        * Resources/pagepopups/calendarPicker.js:
+        (initialize): We need to set global.params at the beginning because we need it for resizeWindow().
+        * Resources/pagepopups/colorSuggestionPicker.js: Added global.params.
+        (handleMessage):
+        (initialize):
+        (handleArgumentsTimeout):
+        * Resources/pagepopups/pickerCommon.js:
+        (Rect): Represents an axis aligned rectangle.
+        (Rect.prototype.get maxX): Gets position of right edge.
+        (Rect.prototype.get maxY): Gets position of bottom edge.
+        (Rect.prototype.toString):
+        (Rect.intersection): Returns the intersection of two rectangles.
+        (resizeWindow): Resize window to a certain size. Don't allow shrinking.
+        (adjustWindowRect): Calculates the best position and size for the popup.
+        (_adjustWindowRectVertically):
+        (_adjustWindowRectHorizontally):
+        (setWindowRect): Sets the position and size of the popup to the given rect.
+        * Resources/pagepopups/suggestionPicker.css:
+        (.suggestion-list): Don't show horizontal scroll bar.
+        * Resources/pagepopups/suggestionPicker.js:
+        (SuggestionPicker.prototype._fixWindowSize): 
+        * page/PagePopupClient.cpp:
+        (WebCore::PagePopupClient::addProperty): For adding an int to JSON.
+        (WebCore::PagePopupClient::addProperty): For adding an IntRect to JSON.
+        (WebCore):
+        * page/PagePopupClient.h:
+        (PagePopupClient):
+
 2012-10-09  Hajime Morrita  <morrita@google.com>
 
         [Refactoring] Scoped Style related code should have its own class.
index f7315b3..b9bd081 100644 (file)
@@ -267,7 +267,8 @@ CalendarPicker.validateConfig = function(config) {
 /**
  * @param {!Object} args
  */
-function initialize(args) {
+function initialize(args) { 
+    global.params = args;
     var errorString = CalendarPicker.validateConfig(args);
     if (args.suggestionValues)
         errorString = errorString || SuggestionPicker.validateConfig(args)
@@ -276,7 +277,6 @@ function initialize(args) {
         main.textContent = "Internal error: " + errorString;
         resizeWindow(main.offsetWidth, main.offsetHeight);
     } else {
-        global.params = args;
         if (global.params.suggestionValues && global.params.suggestionValues.length)
             openSuggestionPicker();
         else
index 46a0d49..559b9e6 100644 (file)
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-window.argumentsReceived = false;
+var global = {
+    argumentsReceived: false,
+    params: null
+};
 
 /**
  * @param {Event} event
  */
 function handleMessage(event) {
     initialize(JSON.parse(event.data));
-    window.argumentsReceived = true;
+    global.argumentsReceived = true;
 }
 
 /**
  * @param {!Object} args
  */
-function initialize(args) {
+function initialize(args) { 
+    global.params = args;
     var main = $("main");
     main.innerHTML = "";
     var errorString = validateArguments(args);
@@ -53,7 +57,7 @@ var DefaultColorPalette = ["#000000", "#404040", "#808080", "#c0c0c0",
     "#4a86e8", "#0000ff", "#9900ff", "#ff00ff"];
 
 function handleArgumentsTimeout() {
-    if (window.argumentsReceived)
+    if (global.argumentsReceived)
         return;
     var args = {
         values : DefaultColorPalette,
index 619f2ee..0e9ce7a 100644 (file)
@@ -45,16 +45,121 @@ function createElement(tagName, opt_class, opt_text) {
     return element;
 }
 
+function Rect(xOrRect, y, width, height) {
+    if (typeof xOrRect === "object") {
+        y = xOrRect.y;
+        width = xOrRect.width;
+        height = xOrRect.height;
+        xOrRect = xOrRect.x;
+    }
+    this.x = xOrRect;
+    this.y = y;
+    this.width = width;
+    this.height = height;
+}
+
+Rect.prototype = {
+    get maxX() { return this.x + this.width; },
+    get maxY() { return this.y + this.height; },
+    toString: function() { return "Rect(" + this.x + "," + this.y + "," + this.width + "," + this.height + ")"; }
+};
+
+/**
+ * @param {!number} Rect
+ * @param {!number} Rect
+ * @return {?Rect}
+ */
+Rect.intersection = function(rect1, rect2) {
+    var x = Math.max(rect1.x, rect2.x);
+    var maxX = Math.min(rect1.maxX, rect2.maxX);
+    var y = Math.max(rect1.y, rect2.y);
+    var maxY = Math.min(rect1.maxY, rect2.maxY);
+    var width = maxX - x;
+    var height = maxY - y;
+    if (width < 0 || height < 0)
+        return null;
+    return new Rect(x, y, width, height);
+};
+
 /**
  * @param {!number} width
  * @param {!number} height
  */
 function resizeWindow(width, height) {
+    setWindowRect(adjustWindowRect(width, height, width, height));
+}
+
+/**
+ * @param {!number} width
+ * @param {!number} height
+ * @param {?number} minWidth
+ * @param {?number} minHeight
+ * @return {!Rect}
+ */
+function adjustWindowRect(width, height, minWidth, minHeight) {
+    if (typeof minWidth !== "number")
+        minWidth = 0;
+    if (typeof minHeight !== "number")
+        minHeight = 0;
+
+    var windowRect = new Rect(0, 0, width, height);
+
+    if (!global.params.anchorRectInScreen)
+        return windowRect;
+
+    var anchorRect = new Rect(global.params.anchorRectInScreen);
+    var rootViewRect = new Rect(global.params.rootViewRectInScreen);
+    var availRect = new Rect(window.screen.availLeft, window.screen.availTop, window.screen.availWidth, window.screen.availHeight);
+    if (global.params.confineToRootView)
+        availRect = Rect.intersection(availRect, rootViewRect) || new Rect(0, 0, 0, 0);
+
+    _adjustWindowRectVertically(windowRect, availRect, anchorRect, minHeight);
+    _adjustWindowRectHorizontally(windowRect, availRect, anchorRect, minWidth);
+
+    return windowRect;
+}
+
+function _adjustWindowRectVertically(windowRect, availRect, anchorRect, minHeight) {
+    var availableSpaceAbove = anchorRect.y - availRect.y;
+    availableSpaceAbove = Math.max(0, Math.min(availRect.height, availableSpaceAbove));
+
+    var availableSpaceBelow = availRect.maxY - anchorRect.maxY;
+    availableSpaceBelow = Math.max(0, Math.min(availRect.height, availableSpaceBelow));
+
+    if (windowRect.height > availableSpaceBelow && availableSpaceBelow < availableSpaceAbove) {
+        windowRect.height = Math.min(windowRect.height, availableSpaceAbove);
+        windowRect.height = Math.max(windowRect.height, minHeight);
+        windowRect.y = anchorRect.y - windowRect.height;
+    } else {
+        windowRect.height = Math.min(windowRect.height, availableSpaceBelow);
+        windowRect.height = Math.max(windowRect.height, minHeight);
+        windowRect.y = anchorRect.maxY;
+    }
+    windowRect.y = Math.min(windowRect.y, availRect.maxY - windowRect.height);
+    windowRect.y = Math.max(windowRect.y, availRect.y);
+}
+
+function _adjustWindowRectHorizontally(windowRect, availRect, anchorRect, minWidth) {
+    windowRect.width = Math.min(windowRect.width, availRect.width);
+    windowRect.width = Math.max(windowRect.width, minWidth);
+    windowRect.x = anchorRect.x;
+    var availableSpaceToRight = availRect.maxX - anchorRect.x;
+    if (windowRect.width > availableSpaceToRight)
+        windowRect.x -= (windowRect.width - availableSpaceToRight);
+    windowRect.x = Math.min(windowRect.x, availRect.maxX - windowRect.width);
+    windowRect.x = Math.max(windowRect.x, availRect.x);
+}
+
+/**
+ * @param {!Rect} rect
+ */
+function setWindowRect(rect) {
     if (window.frameElement) {
-        window.frameElement.style.width = width + "px";
-        window.frameElement.style.height = height + "px";
+        window.frameElement.style.width = rect.width + "px";
+        window.frameElement.style.height = rect.height + "px";
     } else {
-        window.resizeTo(width, height);
+        window.moveTo(rect.x - window.screen.availLeft, rect.y - window.screen.availTop);
+        window.resizeTo(rect.width, rect.height);
     }
 }
 
index 91e0e34..dbde03e 100644 (file)
@@ -5,6 +5,7 @@
     font: -webkit-small-control;
     border: 1px solid #7f9db9;
     background-color: white;
+    overflow-x: hidden;
     overflow-y: auto;
 }
 
index 3c0e95c..0844063 100644 (file)
@@ -157,7 +157,9 @@ SuggestionPicker.prototype._fixWindowSize = function() {
         desiredWindowHeight = maxHeight;
     }
 
-    resizeWindow(desiredWindowWidth, desiredWindowHeight);
+    var windowRect = adjustWindowRect(desiredWindowWidth, desiredWindowHeight, desiredWindowWidth, 0);
+    this._containerElement.style.height = (windowRect.height - ListBorder) + "px";
+    setWindowRect(windowRect);
 };
 
 SuggestionPicker.prototype._layout = function() {
index 5b666ea..7dab828 100644 (file)
@@ -61,6 +61,14 @@ void PagePopupClient::addProperty(const char* name, const String& value, Documen
     addLiteral(",\n", writer);
 }
 
+void PagePopupClient::addProperty(const char* name, int value, DocumentWriter& writer)
+{
+    writer.addData(name, strlen(name));
+    addLiteral(": ", writer);
+    addString(String::number(value), writer);
+    addLiteral(",\n", writer);
+}
+
 void PagePopupClient::addProperty(const char* name, unsigned value, DocumentWriter& writer)
 {
     writer.addData(name, strlen(name));
@@ -92,6 +100,17 @@ void PagePopupClient::addProperty(const char* name, const Vector<String>& values
     addLiteral("],\n", writer);
 }
 
+void PagePopupClient::addProperty(const char* name, const IntRect& rect, DocumentWriter& writer)
+{
+    writer.addData(name, strlen(name));
+    addLiteral(": {", writer);
+    addProperty("x", rect.x(), writer);
+    addProperty("y", rect.y(), writer);
+    addProperty("width", rect.width(), writer);
+    addProperty("height", rect.height(), writer);
+    addLiteral("},\n", writer);
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(PAGE_POPUP)
index 7d97846..d0fb4bb 100644 (file)
@@ -34,7 +34,7 @@
 #if ENABLE(PAGE_POPUP)
 
 #include "DocumentWriter.h"
-#include "IntSize.h"
+#include "IntRect.h"
 #include <wtf/text/WTFString.h>
 
 namespace WebCore {
@@ -69,9 +69,11 @@ public:
     static void addString(const String&, DocumentWriter&);
     static void addJavaScriptString(const String&, DocumentWriter&);
     static void addProperty(const char* name, const String& value, DocumentWriter&);
+    static void addProperty(const char* name, int value, DocumentWriter&);
     static void addProperty(const char* name, unsigned value, DocumentWriter&);
     static void addProperty(const char* name, bool value, DocumentWriter&);
     static void addProperty(const char* name, const Vector<String>& values, DocumentWriter&);
+    static void addProperty(const char* name, const IntRect&, DocumentWriter&);
 };
 
 inline void PagePopupClient::addString(const String& str, DocumentWriter& writer)
index 3f78a58..7908409 100644 (file)
@@ -1,3 +1,20 @@
+2012-10-09  Keishi Hattori  <keishi@webkit.org>
+
+        Page popup should be smarter about its layout
+        https://bugs.webkit.org/show_bug.cgi?id=98499
+
+        Reviewed by Kent Tamura.
+
+        * src/ColorChooserUIController.cpp:
+        (WebKit::ColorChooserUIController::writeDocument): Send anchorRectInScreen, rootViewRectInScreen, and confineToRootView.
+        * src/DateTimeChooserImpl.cpp:
+        (WebKit::DateTimeChooserImpl::writeDocument): Send anchorRectInScreen, rootViewRectInScreen, and confineToRootView.
+        * src/WebPagePopupImpl.cpp:
+        (WebKit::WebPagePopupImpl::init): We keep the originBoundsInRootView argument for MockPagePopupDriver.
+        (WebKit::WebPagePopupImpl::resize): WebPagePopupImpl isn't in charge of setting the popup position any more.
+        * src/WebPagePopupImpl.h:
+        (WebPagePopupImpl):
+
 2012-10-08  Dirk Pranke  <dpranke@chromium.org>
 
         Chromium DEPS roll r160657:160764.
index 54d134f..330f59c 100644 (file)
 #include "Color.h"
 #include "ColorChooserClient.h"
 #include "ColorSuggestionPicker.h"
+#include "FrameView.h"
 #include "IntRect.h"
 #include "LocalizedStrings.h"
 #include "PickerCommon.h"
 #include "WebColorChooser.h"
+#include "WebViewImpl.h"
 #include <public/Platform.h>
 #include <public/WebColor.h>
 #include <public/WebLocalizedString.h>
 
+using namespace WebCore;
+
 namespace WebKit {
 
 // Keep in sync with Actions in colorSuggestionPicker.js.
@@ -49,11 +53,11 @@ enum ColorPickerPopupAction {
     ColorPickerPopupActionSetValue = 0
 };
 
-ColorChooserUIController::ColorChooserUIController(ChromeClientImpl* chromeClient, WebCore::ColorChooserClient* client)
+ColorChooserUIController::ColorChooserUIController(ChromeClientImpl* chromeClient, ColorChooserClient* client)
     : m_chromeClient(chromeClient)
     , m_client(client)
     , m_popup(0)
-    , m_localizer(WebCore::Localizer::createDefault())
+    , m_localizer(Localizer::createDefault())
 {
     if (m_client->shouldShowSuggestions())
         openPopup();
@@ -65,7 +69,7 @@ ColorChooserUIController::~ColorChooserUIController()
 {
 }
 
-void ColorChooserUIController::setSelectedColor(const WebCore::Color& color)
+void ColorChooserUIController::setSelectedColor(const Color& color)
 {
     ASSERT(m_chooser);
     m_chooser->setSelectedColor(static_cast<WebColor>(color.rgb()));
@@ -82,7 +86,7 @@ void ColorChooserUIController::endChooser()
 void ColorChooserUIController::didChooseColor(const WebColor& color)
 {
     ASSERT(m_client);
-    m_client->didChooseColor(WebCore::Color(static_cast<WebCore::RGBA32>(color)));
+    m_client->didChooseColor(Color(static_cast<RGBA32>(color)));
 }
 
 void ColorChooserUIController::didEndChooser()
@@ -92,32 +96,43 @@ void ColorChooserUIController::didEndChooser()
     m_client->didEndChooser();
 }
 
-WebCore::IntSize ColorChooserUIController::contentSize()
+IntSize ColorChooserUIController::contentSize()
 {
-    return WebCore::IntSize(0, 0);
+    return IntSize(0, 0);
 }
 
-void ColorChooserUIController::writeDocument(WebCore::DocumentWriter& writer)
+void ColorChooserUIController::writeDocument(DocumentWriter& writer)
 {
-    Vector<WebCore::Color> suggestions = m_client->suggestions();
+    Vector<Color> suggestions = m_client->suggestions();
     Vector<String> suggestionValues;
     for (unsigned i = 0; i < suggestions.size(); i++)
         suggestionValues.append(suggestions[i].serialized());
+    IntRect anchorRectInScreen = m_chromeClient->rootViewToScreen(m_client->elementRectRelativeToRootView());
+    FrameView* view = static_cast<WebViewImpl*>(m_chromeClient->webView())->page()->mainFrame()->view();
+    IntRect rootViewVisibleContentRect = view->visibleContentRect(true /* include scrollbars */);
+    IntRect rootViewRectInScreen = m_chromeClient->rootViewToScreen(rootViewVisibleContentRect);
     
-    WebCore::PagePopupClient::addString("<!DOCTYPE html><head><meta charset='UTF-8'><style>\n", writer);
-    writer.addData(WebCore::pickerCommonCss, sizeof(WebCore::pickerCommonCss));
-    writer.addData(WebCore::colorSuggestionPickerCss, sizeof(WebCore::colorSuggestionPickerCss));
-    WebCore::PagePopupClient::addString("</style></head><body><div id=main>Loading...</div><script>\n"
+    PagePopupClient::addString("<!DOCTYPE html><head><meta charset='UTF-8'><style>\n", writer);
+    writer.addData(pickerCommonCss, sizeof(pickerCommonCss));
+    writer.addData(colorSuggestionPickerCss, sizeof(colorSuggestionPickerCss));
+    PagePopupClient::addString("</style></head><body><div id=main>Loading...</div><script>\n"
                                       "window.dialogArguments = {\n", writer);
-    WebCore::PagePopupClient::addProperty("values", suggestionValues, writer);       
-    WebCore::PagePopupClient::addProperty("otherColorLabel", Platform::current()->queryLocalizedString(WebLocalizedString::OtherColorLabel), writer);
-    WebCore::PagePopupClient::addString("};\n", writer);
-    writer.addData(WebCore::pickerCommonJs, sizeof(WebCore::pickerCommonJs));
-    writer.addData(WebCore::colorSuggestionPickerJs, sizeof(WebCore::colorSuggestionPickerJs));
-    WebCore::PagePopupClient::addString("</script></body>\n", writer);
+    PagePopupClient::addProperty("values", suggestionValues, writer);       
+    PagePopupClient::addProperty("otherColorLabel", Platform::current()->queryLocalizedString(WebLocalizedString::OtherColorLabel), writer);
+    addProperty("anchorRectInScreen", anchorRectInScreen, writer);
+    addProperty("rootViewRectInScreen", rootViewRectInScreen, writer);
+#if OS(MAC_OS_X)
+    addProperty("confineToRootView", true, writer);
+#else
+    addProperty("confineToRootView", false, writer);
+#endif
+    PagePopupClient::addString("};\n", writer);
+    writer.addData(pickerCommonJs, sizeof(pickerCommonJs));
+    writer.addData(colorSuggestionPickerJs, sizeof(colorSuggestionPickerJs));
+    PagePopupClient::addString("</script></body>\n", writer);
 }
 
-WebCore::Localizer& ColorChooserUIController::localizer()
+Localizer& ColorChooserUIController::localizer()
 {
     return *m_localizer;
 }
@@ -127,7 +142,7 @@ void ColorChooserUIController::setValueAndClosePopup(int numValue, const String&
     ASSERT(m_popup);
     ASSERT(m_client);
     if (numValue == ColorPickerPopupActionSetValue)
-        m_client->didChooseColor(WebCore::Color(stringValue));
+        m_client->didChooseColor(Color(stringValue));
     if (numValue == ColorPickerPopupActionChooseOtherColor)
         openColorChooser();
     closePopup();
index cbd0fd6..1a5b7a2 100644 (file)
 #include "ChromeClientImpl.h"
 #include "DateComponents.h"
 #include "DateTimeChooserClient.h"
+#include "FrameView.h"
 #include "InputTypeNames.h"
 #include "Language.h"
 #include "Localizer.h"
 #include "NotImplemented.h"
 #include "PickerCommon.h"
 #include "RenderTheme.h"
+#include "WebViewImpl.h"
 #include <public/Platform.h>
 #include <public/WebLocalizedString.h>
 
@@ -89,6 +91,10 @@ void DateTimeChooserImpl::writeDocument(WebCore::DocumentWriter& writer)
     String stepString = String::number(m_parameters.step);
     String stepBaseString = String::number(m_parameters.stepBase, 11, WTF::TruncateTrailingZeros);
     OwnPtr<Localizer> localizer = Localizer::create(nullAtom);
+    IntRect anchorRectInScreen = m_chromeClient->rootViewToScreen(m_parameters.anchorRectInRootView);
+    FrameView* view = static_cast<WebViewImpl*>(m_chromeClient->webView())->page()->mainFrame()->view();
+    IntRect rootViewVisibleContentRect = view->visibleContentRect(true /* include scrollbars */);
+    IntRect rootViewRectInScreen = m_chromeClient->rootViewToScreen(rootViewVisibleContentRect);
 
     addString("<!DOCTYPE html><head><meta charset='UTF-8'><style>\n", writer);
     writer.addData(WebCore::pickerCommonCss, sizeof(WebCore::pickerCommonCss));
@@ -99,6 +105,13 @@ void DateTimeChooserImpl::writeDocument(WebCore::DocumentWriter& writer)
         writer.addData(extraStyle.data(), extraStyle.length());
     addString("</style></head><body><div id=main>Loading...</div><script>\n"
                "window.dialogArguments = {\n", writer);
+    addProperty("anchorRectInScreen", anchorRectInScreen, writer);
+    addProperty("rootViewRectInScreen", rootViewRectInScreen, writer);
+#if OS(MAC_OS_X)
+    addProperty("confineToRootView", true, writer);
+#else
+    addProperty("confineToRootView", false, writer);
+#endif
     addProperty("min", minString, writer);
     addProperty("max", maxString, writer);
     addProperty("step", stepString, writer);
index 1e0fceb..e4808fd 100644 (file)
@@ -151,15 +151,14 @@ WebPagePopupImpl::~WebPagePopupImpl()
     ASSERT(!m_page);
 }
 
-bool WebPagePopupImpl::init(WebViewImpl* webView, PagePopupClient* popupClient, const IntRect& originBoundsInRootView)
+bool WebPagePopupImpl::init(WebViewImpl* webView, PagePopupClient* popupClient, const IntRect&)
 {
     ASSERT(webView);
     ASSERT(popupClient);
     m_webView = webView;
     m_popupClient = popupClient;
-    m_originBoundsInRootView = originBoundsInRootView;
 
-    reposition(m_popupClient->contentSize());
+    resize(m_popupClient->contentSize());
 
     if (!initPage())
         return false;
@@ -233,22 +232,10 @@ void WebPagePopupImpl::paint(WebCanvas* canvas, const WebRect& rect, PaintOption
     PageWidgetDelegate::paint(m_page.get(), 0, canvas, rect, PageWidgetDelegate::Opaque);
 }
 
-void WebPagePopupImpl::reposition(const WebSize& popupSize)
-{
-    WebSize rootViewSize = m_webView->size();
-    IntRect popupBoundsInRootView(IntPoint(max(0, m_originBoundsInRootView.x()), max(0, m_originBoundsInRootView.maxY())), popupSize);
-    if (popupBoundsInRootView.maxY() > rootViewSize.height)
-        popupBoundsInRootView.setY(max(0, m_originBoundsInRootView.y() - popupSize.height));
-    if (popupBoundsInRootView.maxX() > rootViewSize.width)
-        popupBoundsInRootView.setX(max(0, rootViewSize.width - popupSize.width));
-    IntRect boundsInScreen = m_webView->page()->chrome()->rootViewToScreen(popupBoundsInRootView);
-    m_widgetClient->setWindowRect(boundsInScreen);
-    m_windowRectInScreen = boundsInScreen;
-}
-
 void WebPagePopupImpl::resize(const WebSize& newSize)
 {
-    reposition(newSize);
+    m_windowRectInScreen = WebRect(m_windowRectInScreen.x, m_windowRectInScreen.y, newSize.width, newSize.height);
+    m_widgetClient->setWindowRect(m_windowRectInScreen);
 
     if (m_page)
         m_page->mainFrame()->view()->resize(newSize);
index e6844bf..cf2bbba 100644 (file)
@@ -87,11 +87,9 @@ private:
 
     explicit WebPagePopupImpl(WebWidgetClient*);
     bool initPage();
-    void reposition(const WebSize&);
 
     WebWidgetClient* m_widgetClient;
     WebRect m_windowRectInScreen;
-    WebCore::IntRect m_originBoundsInRootView;
     WebViewImpl* m_webView;
     OwnPtr<WebCore::Page> m_page;
     OwnPtr<PagePopupChromeClient> m_chromeClient;