| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 #include "platform/PopupMenu.h" |
| 32 | 33 |
| 33 #include "core/dom/Element.h" | 34 #include "core/dom/Element.h" |
| 34 #include "core/frame/FrameView.h" | 35 #include "core/frame/FrameView.h" |
| 35 #include "core/frame/Settings.h" | 36 #include "core/frame/Settings.h" |
| 36 #include "core/html/HTMLSelectElement.h" | 37 #include "core/html/HTMLSelectElement.h" |
| 37 #include "core/page/EventHandler.h" | 38 #include "core/page/EventHandler.h" |
| 38 #include "core/rendering/RenderMenuList.h" | 39 #include "core/rendering/RenderMenuList.h" |
| 39 #include "core/testing/URLTestHelpers.h" | 40 #include "core/testing/URLTestHelpers.h" |
| 40 #include "platform/KeyboardCodes.h" | 41 #include "platform/KeyboardCodes.h" |
| 41 #include "platform/PlatformMouseEvent.h" | 42 #include "platform/PlatformMouseEvent.h" |
| 42 #include "platform/PopupMenu.h" | |
| 43 #include "platform/PopupMenuClient.h" | 43 #include "platform/PopupMenuClient.h" |
| 44 #include "platform/RuntimeEnabledFeatures.h" | 44 #include "platform/RuntimeEnabledFeatures.h" |
| 45 #include "platform/graphics/Color.h" | 45 #include "platform/graphics/Color.h" |
| 46 #include "platform/scroll/ScrollbarTheme.h" | 46 #include "platform/scroll/ScrollbarTheme.h" |
| 47 #include "public/platform/Platform.h" | 47 #include "public/platform/Platform.h" |
| 48 #include "public/platform/WebScreenInfo.h" | 48 #include "public/platform/WebScreenInfo.h" |
| 49 #include "public/platform/WebString.h" | 49 #include "public/platform/WebString.h" |
| 50 #include "public/platform/WebURL.h" | 50 #include "public/platform/WebURL.h" |
| 51 #include "public/platform/WebURLRequest.h" | 51 #include "public/platform/WebURLRequest.h" |
| 52 #include "public/platform/WebURLResponse.h" | 52 #include "public/platform/WebURLResponse.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 72 using namespace blink; | 72 using namespace blink; |
| 73 using namespace blink; | 73 using namespace blink; |
| 74 using blink::URLTestHelpers::toKURL; | 74 using blink::URLTestHelpers::toKURL; |
| 75 | 75 |
| 76 namespace { | 76 namespace { |
| 77 | 77 |
| 78 class TestPopupMenuClient : public PopupMenuClient { | 78 class TestPopupMenuClient : public PopupMenuClient { |
| 79 public: | 79 public: |
| 80 // Item at index 0 is selected by default. | 80 // Item at index 0 is selected by default. |
| 81 TestPopupMenuClient() : m_selectIndex(0), m_node(0), m_listSize(10) { } | 81 TestPopupMenuClient() : m_selectIndex(0), m_node(0), m_listSize(10) { } |
| 82 virtual ~TestPopupMenuClient() {} | 82 virtual ~TestPopupMenuClient() { } |
| 83 virtual void valueChanged(unsigned listIndex, bool fireEvents = true) | 83 virtual void valueChanged(unsigned listIndex, bool fireEvents = true) |
| 84 { | 84 { |
| 85 m_selectIndex = listIndex; | 85 m_selectIndex = listIndex; |
| 86 if (m_node) { | 86 if (m_node) { |
| 87 HTMLSelectElement* select = toHTMLSelectElement(m_node); | 87 HTMLSelectElement* select = toHTMLSelectElement(m_node); |
| 88 select->optionSelectedByUser(select->listToOptionIndex(listIndex), f
ireEvents); | 88 select->optionSelectedByUser(select->listToOptionIndex(listIndex), f
ireEvents); |
| 89 } | 89 } |
| 90 } | 90 } |
| 91 virtual void selectionChanged(unsigned, bool) {} | 91 virtual void selectionChanged(unsigned, bool) { } |
| 92 virtual void selectionCleared() {} | 92 virtual void selectionCleared() { } |
| 93 | 93 |
| 94 virtual String itemText(unsigned listIndex) const | 94 virtual String itemText(unsigned listIndex) const |
| 95 { | 95 { |
| 96 String str("Item "); | 96 String str("Item "); |
| 97 str.append(String::number(listIndex)); | 97 str.append(String::number(listIndex)); |
| 98 return str; | 98 return str; |
| 99 } | 99 } |
| 100 virtual String itemLabel(unsigned) const { return String(); } | 100 virtual String itemLabel(unsigned) const { return String(); } |
| 101 virtual String itemIcon(unsigned) const { return String(); } | 101 virtual String itemIcon(unsigned) const { return String(); } |
| 102 virtual String itemToolTip(unsigned listIndex) const { return itemText(listI
ndex); } | 102 virtual String itemToolTip(unsigned listIndex) const { return itemText(listI
ndex); } |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 WebKeyboardEvent keyEvent; | 234 WebKeyboardEvent keyEvent; |
| 235 keyEvent.windowsKeyCode = keyCode; | 235 keyEvent.windowsKeyCode = keyCode; |
| 236 keyEvent.type = eventType; | 236 keyEvent.type = eventType; |
| 237 webView()->handleInputEvent(keyEvent); | 237 webView()->handleInputEvent(keyEvent); |
| 238 } | 238 } |
| 239 | 239 |
| 240 // Simulates a mouse event on the select popup. | 240 // Simulates a mouse event on the select popup. |
| 241 void simulateLeftMouseDownEvent(const IntPoint& point) | 241 void simulateLeftMouseDownEvent(const IntPoint& point) |
| 242 { | 242 { |
| 243 PlatformMouseEvent mouseEvent(point, point, LeftButton, PlatformEvent::M
ousePressed, | 243 PlatformMouseEvent mouseEvent(point, point, LeftButton, PlatformEvent::M
ousePressed, |
| 244 1, false, false, false, false, 0); | 244 1, false, false, false, false, 0); |
| 245 webView()->selectPopup()->handleMouseDownEvent(mouseEvent); | 245 webView()->selectPopup()->handleMouseDownEvent(mouseEvent); |
| 246 } | 246 } |
| 247 void simulateLeftMouseUpEvent(const IntPoint& point) | 247 void simulateLeftMouseUpEvent(const IntPoint& point) |
| 248 { | 248 { |
| 249 PlatformMouseEvent mouseEvent(point, point, LeftButton, PlatformEvent::M
ouseReleased, | 249 PlatformMouseEvent mouseEvent(point, point, LeftButton, PlatformEvent::M
ouseReleased, |
| 250 1, false, false, false, false, 0); | 250 1, false, false, false, false, 0); |
| 251 webView()->selectPopup()->handleMouseReleaseEvent(mouseEvent); | 251 webView()->selectPopup()->handleMouseReleaseEvent(mouseEvent); |
| 252 } | 252 } |
| 253 | 253 |
| 254 void registerMockedURLLoad(const std::string& fileName) | 254 void registerMockedURLLoad(const std::string& fileName) |
| 255 { | 255 { |
| 256 URLTestHelpers::registerMockedURLLoad(toKURL(baseURL + fileName), WebStr
ing::fromUTF8(fileName.c_str()), WebString::fromUTF8("popup/"), WebString::fromU
TF8("text/html")); | 256 URLTestHelpers::registerMockedURLLoad(toKURL(baseURL + fileName), WebStr
ing::fromUTF8(fileName.c_str()), WebString::fromUTF8("popup/"), WebString::fromU
TF8("text/html")); |
| 257 } | 257 } |
| 258 | 258 |
| 259 void loadFrame(WebFrame* frame, const std::string& fileName) | 259 void loadFrame(WebFrame* frame, const std::string& fileName) |
| 260 { | 260 { |
| 261 FrameTestHelpers::loadFrame(frame, baseURL + fileName); | 261 FrameTestHelpers::loadFrame(frame, baseURL + fileName); |
| 262 } | 262 } |
| 263 | 263 |
| 264 WebViewImpl* webView() const { return m_helper.webViewImpl(); } | 264 WebViewImpl* webView() const { return m_helper.webViewImpl(); } |
| 265 WebLocalFrameImpl* mainFrame() const { return m_helper.webViewImpl()->mainFr
ameImpl(); } | 265 WebLocalFrameImpl* mainFrame() const { return m_helper.webViewImpl()->mainFr
ameImpl(); } |
| 266 | 266 |
| 267 protected: | 267 protected: |
| 268 PopupTestWebViewClient m_webviewClient; | 268 PopupTestWebViewClient m_webviewClient; |
| 269 TestPopupMenuClient m_popupMenuClient; | 269 TestPopupMenuClient m_popupMenuClient; |
| 270 RefPtr<PopupMenu> m_popupMenu; | 270 RefPtr<PopupMenu> m_popupMenu; |
| 271 std::string baseURL; | 271 std::string baseURL; |
| 272 | 272 |
| 273 private: | 273 private: |
| 274 FrameTestHelpers::WebViewHelper m_helper; | 274 FrameTestHelpers::WebViewHelper m_helper; |
| 275 }; | 275 }; |
| 276 | 276 |
| 277 // Tests that show/hide and repeats. Select popups are reused in web pages when | 277 // Tests that show/hide and repeats. Select popups are reused in web pages when |
| 278 // they are reopened, that what this is testing. | 278 // they are reopened, that what this is testing. |
| 279 TEST_F(SelectPopupMenuTest, ShowThenHide) | 279 TEST_F(SelectPopupMenuTest, ShowThenHide) |
| 280 { | 280 { |
| 281 for (int i = 0; i < 3; i++) { | 281 for (int i = 0; i < 3; i++) { |
| 282 showPopup(); | 282 showPopup(); |
| 283 hidePopup(); | 283 hidePopup(); |
| 284 } | 284 } |
| 285 } | 285 } |
| 286 | 286 |
| 287 // Tests that showing a select popup and deleting it does not cause problem. | 287 // Tests that showing a select popup and deleting it does not cause problem. |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 // leaves the seleted item unchanged. | 362 // leaves the seleted item unchanged. |
| 363 TEST_F(SelectPopupMenuTest, MouseOverItemClickOutside) | 363 TEST_F(SelectPopupMenuTest, MouseOverItemClickOutside) |
| 364 { | 364 { |
| 365 showPopup(); | 365 showPopup(); |
| 366 | 366 |
| 367 int menuItemHeight = webView()->selectPopup()->menuItemHeight(); | 367 int menuItemHeight = webView()->selectPopup()->menuItemHeight(); |
| 368 // menuItemHeight * 1.5 means the Y position on the item at index 1. | 368 // menuItemHeight * 1.5 means the Y position on the item at index 1. |
| 369 IntPoint row1Point(2, menuItemHeight * 1.5); | 369 IntPoint row1Point(2, menuItemHeight * 1.5); |
| 370 // Simulate the mouse moving over the first item. | 370 // Simulate the mouse moving over the first item. |
| 371 PlatformMouseEvent mouseEvent(row1Point, row1Point, NoButton, PlatformEvent:
:MouseMoved, | 371 PlatformMouseEvent mouseEvent(row1Point, row1Point, NoButton, PlatformEvent:
:MouseMoved, |
| 372 1, false, false, false, false, 0); | 372 1, false, false, false, false, 0); |
| 373 webView()->selectPopup()->handleMouseMoveEvent(mouseEvent); | 373 webView()->selectPopup()->handleMouseMoveEvent(mouseEvent); |
| 374 | 374 |
| 375 // Click outside the popup. | 375 // Click outside the popup. |
| 376 simulateLeftMouseDownEvent(IntPoint(1000, 1000)); | 376 simulateLeftMouseDownEvent(IntPoint(1000, 1000)); |
| 377 | 377 |
| 378 // Popup should have closed and item 0 should still be selected. | 378 // Popup should have closed and item 0 should still be selected. |
| 379 EXPECT_FALSE(popupOpen()); | 379 EXPECT_FALSE(popupOpen()); |
| 380 EXPECT_EQ(0, selectedIndex()); | 380 EXPECT_EQ(0, selectedIndex()); |
| 381 } | 381 } |
| 382 | 382 |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 605 ASSERT(menuList); | 605 ASSERT(menuList); |
| 606 menuList->showPopup(); | 606 menuList->showPopup(); |
| 607 ASSERT(popupOpen()); | 607 ASSERT(popupOpen()); |
| 608 PopupListBox* listBox = webView()->selectPopup()->listBox(); | 608 PopupListBox* listBox = webView()->selectPopup()->listBox(); |
| 609 int ltrWidth = listBox->getRowBaseWidth(0); | 609 int ltrWidth = listBox->getRowBaseWidth(0); |
| 610 int rtlWidth = listBox->getRowBaseWidth(1); | 610 int rtlWidth = listBox->getRowBaseWidth(1); |
| 611 EXPECT_LT(rtlWidth, ltrWidth); | 611 EXPECT_LT(rtlWidth, ltrWidth); |
| 612 } | 612 } |
| 613 | 613 |
| 614 } // namespace | 614 } // namespace |
| OLD | NEW |