Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: Source/web/WebViewImpl.cpp

Issue 736883002: Implement <select> Popup Menu using PagePopup (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2011, 2012 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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 #include "public/web/WebTextInputInfo.h" 139 #include "public/web/WebTextInputInfo.h"
140 #include "public/web/WebViewClient.h" 140 #include "public/web/WebViewClient.h"
141 #include "public/web/WebWindowFeatures.h" 141 #include "public/web/WebWindowFeatures.h"
142 #include "web/CompositionUnderlineVectorBuilder.h" 142 #include "web/CompositionUnderlineVectorBuilder.h"
143 #include "web/ContextFeaturesClientImpl.h" 143 #include "web/ContextFeaturesClientImpl.h"
144 #include "web/DatabaseClientImpl.h" 144 #include "web/DatabaseClientImpl.h"
145 #include "web/FullscreenController.h" 145 #include "web/FullscreenController.h"
146 #include "web/GraphicsLayerFactoryChromium.h" 146 #include "web/GraphicsLayerFactoryChromium.h"
147 #include "web/LinkHighlight.h" 147 #include "web/LinkHighlight.h"
148 #include "web/NavigatorContentUtilsClientImpl.h" 148 #include "web/NavigatorContentUtilsClientImpl.h"
149 #include "web/PopupContainer.h"
150 #include "web/PrerendererClientImpl.h" 149 #include "web/PrerendererClientImpl.h"
151 #include "web/StorageQuotaClientImpl.h" 150 #include "web/StorageQuotaClientImpl.h"
152 #include "web/ValidationMessageClientImpl.h" 151 #include "web/ValidationMessageClientImpl.h"
153 #include "web/ViewportAnchor.h" 152 #include "web/ViewportAnchor.h"
154 #include "web/WebDevToolsAgentImpl.h" 153 #include "web/WebDevToolsAgentImpl.h"
155 #include "web/WebDevToolsAgentPrivate.h" 154 #include "web/WebDevToolsAgentPrivate.h"
156 #include "web/WebInputEventConversion.h" 155 #include "web/WebInputEventConversion.h"
157 #include "web/WebLocalFrameImpl.h" 156 #include "web/WebLocalFrameImpl.h"
158 #include "web/WebPagePopupImpl.h" 157 #include "web/WebPagePopupImpl.h"
159 #include "web/WebPluginContainerImpl.h" 158 #include "web/WebPluginContainerImpl.h"
160 #include "web/WebPopupMenuImpl.h"
161 #include "web/WebRemoteFrameImpl.h" 159 #include "web/WebRemoteFrameImpl.h"
162 #include "web/WebSettingsImpl.h" 160 #include "web/WebSettingsImpl.h"
163 #include "web/WorkerGlobalScopeProxyProviderImpl.h" 161 #include "web/WorkerGlobalScopeProxyProviderImpl.h"
164 #include "web/painting/ContinuousPainter.h" 162 #include "web/painting/ContinuousPainter.h"
165 #include "wtf/CurrentTime.h" 163 #include "wtf/CurrentTime.h"
166 #include "wtf/RefPtr.h" 164 #include "wtf/RefPtr.h"
167 #include "wtf/TemporaryChange.h" 165 #include "wtf/TemporaryChange.h"
168 166
169 #if USE(DEFAULT_RENDER_THEME) 167 #if USE(DEFAULT_RENDER_THEME)
170 #include "core/rendering/RenderThemeChromiumDefault.h" 168 #include "core/rendering/RenderThemeChromiumDefault.h"
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 { 478 {
481 m_client->setMouseOverURL(WebURL()); 479 m_client->setMouseOverURL(WebURL());
482 PageWidgetEventHandler::handleMouseLeave(mainFrame, event); 480 PageWidgetEventHandler::handleMouseLeave(mainFrame, event);
483 } 481 }
484 482
485 void WebViewImpl::handleMouseDown(LocalFrame& mainFrame, const WebMouseEvent& ev ent) 483 void WebViewImpl::handleMouseDown(LocalFrame& mainFrame, const WebMouseEvent& ev ent)
486 { 484 {
487 // If there is a popup open, close it as the user is clicking on the page (o utside of the 485 // If there is a popup open, close it as the user is clicking on the page (o utside of the
488 // popup). We also save it so we can prevent a click on an element from imme diately 486 // popup). We also save it so we can prevent a click on an element from imme diately
489 // reopening the same popup. 487 // reopening the same popup.
490 RefPtrWillBeRawPtr<PopupContainer> selectPopup = nullptr;
491 RefPtr<WebPagePopupImpl> pagePopup; 488 RefPtr<WebPagePopupImpl> pagePopup;
492 if (event.button == WebMouseEvent::ButtonLeft) { 489 if (event.button == WebMouseEvent::ButtonLeft) {
493 selectPopup = m_selectPopup;
494 pagePopup = m_pagePopup; 490 pagePopup = m_pagePopup;
495 hidePopups(); 491 hidePopups();
496 ASSERT(!m_selectPopup);
497 ASSERT(!m_pagePopup); 492 ASSERT(!m_pagePopup);
498 } 493 }
499 494
500 m_lastMouseDownPoint = WebPoint(event.x, event.y); 495 m_lastMouseDownPoint = WebPoint(event.x, event.y);
501 496
502 // Take capture on a mouse down on a plugin so we can send it mouse events. 497 // Take capture on a mouse down on a plugin so we can send it mouse events.
503 // If the hit node is a plugin but a scrollbar is over it don't start mouse 498 // If the hit node is a plugin but a scrollbar is over it don't start mouse
504 // capture because it will interfere with the scrollbar receiving events. 499 // capture because it will interfere with the scrollbar receiving events.
505 IntPoint point(event.x, event.y); 500 IntPoint point(event.x, event.y);
506 if (event.button == WebMouseEvent::ButtonLeft && m_page->mainFrame()->isLoca lFrame()) { 501 if (event.button == WebMouseEvent::ButtonLeft && m_page->mainFrame()->isLoca lFrame()) {
507 point = m_page->deprecatedLocalMainFrame()->view()->windowToContents(poi nt); 502 point = m_page->deprecatedLocalMainFrame()->view()->windowToContents(poi nt);
508 HitTestResult result(m_page->deprecatedLocalMainFrame()->eventHandler(). hitTestResultAtPoint(point)); 503 HitTestResult result(m_page->deprecatedLocalMainFrame()->eventHandler(). hitTestResultAtPoint(point));
509 result.setToShadowHostIfInUserAgentShadowRoot(); 504 result.setToShadowHostIfInUserAgentShadowRoot();
510 Node* hitNode = result.innerNonSharedNode(); 505 Node* hitNode = result.innerNonSharedNode();
511 506
512 if (!result.scrollbar() && hitNode && hitNode->renderer() && hitNode->re nderer()->isEmbeddedObject()) { 507 if (!result.scrollbar() && hitNode && hitNode->renderer() && hitNode->re nderer()->isEmbeddedObject()) {
513 m_mouseCaptureNode = hitNode; 508 m_mouseCaptureNode = hitNode;
514 TRACE_EVENT_ASYNC_BEGIN0("input", "capturing mouse", this); 509 TRACE_EVENT_ASYNC_BEGIN0("input", "capturing mouse", this);
515 } 510 }
516 } 511 }
517 512
518 PageWidgetEventHandler::handleMouseDown(mainFrame, event); 513 PageWidgetEventHandler::handleMouseDown(mainFrame, event);
519 514
520 if (event.button == WebMouseEvent::ButtonLeft && m_mouseCaptureNode) 515 if (event.button == WebMouseEvent::ButtonLeft && m_mouseCaptureNode)
521 m_mouseCaptureGestureToken = mainFrame.eventHandler().takeLastMouseDownG estureToken(); 516 m_mouseCaptureGestureToken = mainFrame.eventHandler().takeLastMouseDownG estureToken();
522 517
523 if (m_selectPopup && m_selectPopup == selectPopup) {
524 // That click triggered a select popup which is the same as the one that
525 // was showing before the click. It means the user clicked the select
526 // while the popup was showing, and as a result we first closed then
527 // immediately reopened the select popup. It needs to be closed.
528 hideSelectPopup();
529 }
530
531 if (m_pagePopup && pagePopup && m_pagePopup->hasSamePopupClient(pagePopup.ge t())) { 518 if (m_pagePopup && pagePopup && m_pagePopup->hasSamePopupClient(pagePopup.ge t())) {
532 // That click triggered a page popup that is the same as the one we just closed. 519 // That click triggered a page popup that is the same as the one we just closed.
533 // It needs to be closed. 520 // It needs to be closed.
534 closePagePopup(m_pagePopup.get()); 521 closePagePopup(m_pagePopup.get());
535 } 522 }
536 523
537 // Dispatch the contextmenu event regardless of if the click was swallowed. 524 // Dispatch the contextmenu event regardless of if the click was swallowed.
538 if (!page()->settings().showContextMenuOnMouseUp()) { 525 if (!page()->settings().showContextMenuOnMouseUp()) {
539 #if OS(MACOSX) 526 #if OS(MACOSX)
540 if (event.button == WebMouseEvent::ButtonRight 527 if (event.button == WebMouseEvent::ButtonRight
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
728 } 715 }
729 716
730 switch (event.type) { 717 switch (event.type) {
731 case WebInputEvent::GestureTap: { 718 case WebInputEvent::GestureTap: {
732 m_client->cancelScheduledContentIntents(); 719 m_client->cancelScheduledContentIntents();
733 if (detectContentOnTouch(targetedEvent)) { 720 if (detectContentOnTouch(targetedEvent)) {
734 eventSwallowed = true; 721 eventSwallowed = true;
735 break; 722 break;
736 } 723 }
737 724
738 RefPtrWillBeRawPtr<PopupContainer> selectPopup = nullptr;
739 selectPopup = m_selectPopup;
740 hideSelectPopup();
741 ASSERT(!m_selectPopup);
742
743 // Don't trigger a disambiguation popup on sites designed for mobile dev ices. 725 // Don't trigger a disambiguation popup on sites designed for mobile dev ices.
744 // Instead, assume that the page has been designed with big enough butto ns and links. 726 // Instead, assume that the page has been designed with big enough butto ns and links.
745 // Don't trigger a disambiguation popup when screencasting, since it's i mplemented outside of 727 // Don't trigger a disambiguation popup when screencasting, since it's i mplemented outside of
746 // compositor pipeline and is not being screencasted itself. This leads to bad user experience. 728 // compositor pipeline and is not being screencasted itself. This leads to bad user experience.
747 if (event.data.tap.width > 0 && !shouldDisableDesktopWorkarounds() && !p age()->inspectorController().screencastEnabled()) { 729 if (event.data.tap.width > 0 && !shouldDisableDesktopWorkarounds() && !p age()->inspectorController().screencastEnabled()) {
748 WebGestureEvent scaledEvent = event; 730 WebGestureEvent scaledEvent = event;
749 scaledEvent.x = event.x / pageScaleFactor(); 731 scaledEvent.x = event.x / pageScaleFactor();
750 scaledEvent.y = event.y / pageScaleFactor(); 732 scaledEvent.y = event.y / pageScaleFactor();
751 scaledEvent.data.tap.width = event.data.tap.width / pageScaleFactor( ); 733 scaledEvent.data.tap.width = event.data.tap.width / pageScaleFactor( );
752 scaledEvent.data.tap.height = event.data.tap.height / pageScaleFacto r(); 734 scaledEvent.data.tap.height = event.data.tap.height / pageScaleFacto r();
(...skipping 21 matching lines...) Expand all
774 for (size_t i = 0; i < m_linkHighlights.size(); ++i) 756 for (size_t i = 0; i < m_linkHighlights.size(); ++i)
775 m_linkHighlights[i]->startHighlightAnimationIfNeeded(); 757 m_linkHighlights[i]->startHighlightAnimationIfNeeded();
776 eventSwallowed = true; 758 eventSwallowed = true;
777 eventCancelled = true; 759 eventCancelled = true;
778 break; 760 break;
779 } 761 }
780 } 762 }
781 763
782 eventSwallowed = mainFrameImpl()->frame()->eventHandler().handleGestureE vent(targetedEvent); 764 eventSwallowed = mainFrameImpl()->frame()->eventHandler().handleGestureE vent(targetedEvent);
783 765
784 if (m_selectPopup && m_selectPopup == selectPopup) {
785 // That tap triggered a select popup which is the same as the one th at
786 // was showing before the tap. It means the user tapped the select
787 // while the popup was showing, and as a result we first closed then
788 // immediately reopened the select popup. It needs to be closed.
789 hideSelectPopup();
790 }
791
792 break; 766 break;
793 } 767 }
794 case WebInputEvent::GestureTwoFingerTap: 768 case WebInputEvent::GestureTwoFingerTap:
795 case WebInputEvent::GestureLongPress: 769 case WebInputEvent::GestureLongPress:
796 case WebInputEvent::GestureLongTap: { 770 case WebInputEvent::GestureLongTap: {
797 if (!mainFrameImpl() || !mainFrameImpl()->frameView()) 771 if (!mainFrameImpl() || !mainFrameImpl()->frameView())
798 break; 772 break;
799 773
800 m_client->cancelScheduledContentIntents(); 774 m_client->cancelScheduledContentIntents();
801 m_page->contextMenuController().clearContextMenu(); 775 m_page->contextMenuController().clearContextMenu();
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
936 endActiveFlingAnimation(); 910 endActiveFlingAnimation();
937 911
938 // Please refer to the comments explaining the m_suppressNextKeypressEvent 912 // Please refer to the comments explaining the m_suppressNextKeypressEvent
939 // member. 913 // member.
940 // The m_suppressNextKeypressEvent is set if the KeyDown is handled by 914 // The m_suppressNextKeypressEvent is set if the KeyDown is handled by
941 // Webkit. A keyDown event is typically associated with a keyPress(char) 915 // Webkit. A keyDown event is typically associated with a keyPress(char)
942 // event and a keyUp event. We reset this flag here as this is a new keyDown 916 // event and a keyUp event. We reset this flag here as this is a new keyDown
943 // event. 917 // event.
944 m_suppressNextKeypressEvent = false; 918 m_suppressNextKeypressEvent = false;
945 919
946 // If there is a select popup, it should be the one processing the event, 920 // If there is a popup, it should be the one processing the event,
947 // not the page. 921 // not the page.
948 if (m_selectPopup)
949 return m_selectPopup->handleKeyEvent(PlatformKeyboardEventBuilder(event) );
950 if (m_pagePopup) { 922 if (m_pagePopup) {
951 m_pagePopup->handleKeyEvent(PlatformKeyboardEventBuilder(event)); 923 m_pagePopup->handleKeyEvent(PlatformKeyboardEventBuilder(event));
952 // We need to ignore the next Char event after this otherwise pressing 924 // We need to ignore the next Char event after this otherwise pressing
953 // enter when selecting an item in the popup will go to the page. 925 // enter when selecting an item in the popup will go to the page.
954 if (WebInputEvent::RawKeyDown == event.type) 926 if (WebInputEvent::RawKeyDown == event.type)
955 m_suppressNextKeypressEvent = true; 927 m_suppressNextKeypressEvent = true;
956 return true; 928 return true;
957 } 929 }
958 930
959 RefPtrWillBeRawPtr<Frame> focusedFrame = focusedCoreFrame(); 931 RefPtrWillBeRawPtr<Frame> focusedFrame = focusedCoreFrame();
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1005 ASSERT(event.type == WebInputEvent::Char); 977 ASSERT(event.type == WebInputEvent::Char);
1006 978
1007 // Please refer to the comments explaining the m_suppressNextKeypressEvent 979 // Please refer to the comments explaining the m_suppressNextKeypressEvent
1008 // member. The m_suppressNextKeypressEvent is set if the KeyDown is 980 // member. The m_suppressNextKeypressEvent is set if the KeyDown is
1009 // handled by Webkit. A keyDown event is typically associated with a 981 // handled by Webkit. A keyDown event is typically associated with a
1010 // keyPress(char) event and a keyUp event. We reset this flag here as it 982 // keyPress(char) event and a keyUp event. We reset this flag here as it
1011 // only applies to the current keyPress event. 983 // only applies to the current keyPress event.
1012 bool suppress = m_suppressNextKeypressEvent; 984 bool suppress = m_suppressNextKeypressEvent;
1013 m_suppressNextKeypressEvent = false; 985 m_suppressNextKeypressEvent = false;
1014 986
1015 // If there is a select popup, it should be the one processing the event, 987 // If there is a popup, it should be the one processing the event,
1016 // not the page. 988 // not the page.
1017 if (m_selectPopup)
1018 return m_selectPopup->handleKeyEvent(PlatformKeyboardEventBuilder(event) );
1019 if (m_pagePopup) 989 if (m_pagePopup)
1020 return m_pagePopup->handleKeyEvent(PlatformKeyboardEventBuilder(event)); 990 return m_pagePopup->handleKeyEvent(PlatformKeyboardEventBuilder(event));
1021 991
1022 LocalFrame* frame = toLocalFrame(focusedCoreFrame()); 992 LocalFrame* frame = toLocalFrame(focusedCoreFrame());
1023 if (!frame) 993 if (!frame)
1024 return suppress; 994 return suppress;
1025 995
1026 EventHandler& handler = frame->eventHandler(); 996 EventHandler& handler = frame->eventHandler();
1027 997
1028 PlatformKeyboardEventBuilder evt(event); 998 PlatformKeyboardEventBuilder evt(event);
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
1499 *scrollDirection = ScrollDown; 1469 *scrollDirection = ScrollDown;
1500 *scrollGranularity = ScrollByPage; 1470 *scrollGranularity = ScrollByPage;
1501 break; 1471 break;
1502 default: 1472 default:
1503 return false; 1473 return false;
1504 } 1474 }
1505 1475
1506 return true; 1476 return true;
1507 } 1477 }
1508 1478
1509 void WebViewImpl::hideSelectPopup()
1510 {
1511 if (m_selectPopup)
1512 m_selectPopup->hidePopup();
1513 }
1514
1515 void WebViewImpl::popupOpened(PopupContainer* popupContainer)
1516 {
1517 ASSERT(!m_selectPopup);
1518 m_selectPopup = popupContainer;
1519 ASSERT(mainFrameImpl()->frame()->document());
1520 Document& document = *mainFrameImpl()->frame()->document();
1521 page()->frameHost().eventHandlerRegistry().didAddEventHandler(document, Even tHandlerRegistry::WheelEvent);
1522 }
1523
1524 void WebViewImpl::popupClosed(PopupContainer* popupContainer)
1525 {
1526 ASSERT(m_selectPopup);
1527 m_selectPopup = nullptr;
1528 ASSERT(mainFrameImpl()->frame()->document());
1529 Document& document = *mainFrameImpl()->frame()->document();
1530 // Remove the handler we added in |popupOpened| conditionally, because the
1531 // Document may have already removed it, for instance, due to a navigation.
1532 EventHandlerRegistry* registry = &document.frameHost()->eventHandlerRegistry ();
1533 if (registry->eventHandlerTargets(EventHandlerRegistry::WheelEvent)->contain s(&document))
1534 registry->didRemoveEventHandler(document, EventHandlerRegistry::WheelEve nt);
1535 }
1536
1537 PagePopup* WebViewImpl::openPagePopup(PagePopupClient* client, const IntRect& or iginBoundsInRootView) 1479 PagePopup* WebViewImpl::openPagePopup(PagePopupClient* client, const IntRect& or iginBoundsInRootView)
1538 { 1480 {
1539 ASSERT(client); 1481 ASSERT(client);
1540 if (hasOpenedPopup()) 1482 if (hasOpenedPopup())
1541 hidePopups(); 1483 hidePopups();
1542 ASSERT(!m_pagePopup); 1484 ASSERT(!m_pagePopup);
1543 1485
1544 WebWidget* popupWidget = m_client->createPopupMenu(WebPopupTypePage); 1486 WebWidget* popupWidget = m_client->createPopupMenu(WebPopupTypePage);
1545 ASSERT(popupWidget); 1487 ASSERT(popupWidget);
1546 m_pagePopup = toWebPagePopupImpl(popupWidget); 1488 m_pagePopup = toWebPagePopupImpl(popupWidget);
(...skipping 2251 matching lines...) Expand 10 before | Expand all | Expand 10 after
3798 3740
3799 RefPtrWillBeRawPtr<Range> range = Range::create(*startPosition.document(), s tartPosition, endPosition); 3741 RefPtrWillBeRawPtr<Range> range = Range::create(*startPosition.document(), s tartPosition, endPosition);
3800 if (!range) 3742 if (!range)
3801 return; 3743 return;
3802 3744
3803 clipHtml = createMarkup(range.get(), 0, AnnotateForInterchange, false, Resol veNonLocalURLs); 3745 clipHtml = createMarkup(range.get(), 0, AnnotateForInterchange, false, Resol veNonLocalURLs);
3804 } 3746 }
3805 3747
3806 void WebViewImpl::hidePopups() 3748 void WebViewImpl::hidePopups()
3807 { 3749 {
3808 hideSelectPopup();
3809 if (m_pagePopup) 3750 if (m_pagePopup)
3810 closePagePopup(m_pagePopup.get()); 3751 closePagePopup(m_pagePopup.get());
3811 } 3752 }
3812 3753
3813 void WebViewImpl::setIsTransparent(bool isTransparent) 3754 void WebViewImpl::setIsTransparent(bool isTransparent)
3814 { 3755 {
3815 // Set any existing frames to be transparent. 3756 // Set any existing frames to be transparent.
3816 Frame* frame = m_page->mainFrame(); 3757 Frame* frame = m_page->mainFrame();
3817 while (frame) { 3758 while (frame) {
3818 if (frame->isLocalFrame()) 3759 if (frame->isLocalFrame())
(...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after
4525 return mainFrameImpl()->frameView()->layoutSize().width() == m_size.width 4466 return mainFrameImpl()->frameView()->layoutSize().width() == m_size.width
4526 || (constraints.minimumScale == constraints.maximumScale && constraints. minimumScale != -1); 4467 || (constraints.minimumScale == constraints.maximumScale && constraints. minimumScale != -1);
4527 } 4468 }
4528 4469
4529 void WebViewImpl::forceNextWebGLContextCreationToFail() 4470 void WebViewImpl::forceNextWebGLContextCreationToFail()
4530 { 4471 {
4531 WebGLRenderingContext::forceNextWebGLContextCreationToFail(); 4472 WebGLRenderingContext::forceNextWebGLContextCreationToFail();
4532 } 4473 }
4533 4474
4534 } // namespace blink 4475 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698