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 12 matching lines...) Expand all Loading... | |
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 "web/ExternalPopupMenu.h" | 31 #include "web/ExternalPopupMenu.h" |
32 | 32 |
33 #include "core/dom/ExecutionContextTask.h" | |
33 #include "core/dom/NodeComputedStyle.h" | 34 #include "core/dom/NodeComputedStyle.h" |
34 #include "core/frame/FrameHost.h" | 35 #include "core/frame/FrameHost.h" |
35 #include "core/frame/FrameView.h" | 36 #include "core/frame/FrameView.h" |
36 #include "core/frame/LocalFrame.h" | 37 #include "core/frame/LocalFrame.h" |
37 #include "core/html/HTMLOptionElement.h" | 38 #include "core/html/HTMLOptionElement.h" |
38 #include "core/html/HTMLSelectElement.h" | 39 #include "core/html/HTMLSelectElement.h" |
40 #include "core/layout/LayoutBox.h" | |
39 #include "core/page/Page.h" | 41 #include "core/page/Page.h" |
40 #include "core/style/ComputedStyle.h" | 42 #include "core/style/ComputedStyle.h" |
41 #include "platform/geometry/FloatQuad.h" | 43 #include "platform/geometry/FloatQuad.h" |
42 #include "platform/geometry/IntPoint.h" | 44 #include "platform/geometry/IntPoint.h" |
43 #include "platform/text/TextDirection.h" | 45 #include "platform/text/TextDirection.h" |
44 #include "public/platform/WebVector.h" | 46 #include "public/platform/WebVector.h" |
45 #include "public/web/WebExternalPopupMenu.h" | 47 #include "public/web/WebExternalPopupMenu.h" |
46 #include "public/web/WebFrameClient.h" | 48 #include "public/web/WebFrameClient.h" |
47 #include "public/web/WebMenuItemInfo.h" | 49 #include "public/web/WebMenuItemInfo.h" |
48 #include "public/web/WebPopupMenuInfo.h" | 50 #include "public/web/WebPopupMenuInfo.h" |
(...skipping 15 matching lines...) Expand all Loading... | |
64 { | 66 { |
65 } | 67 } |
66 | 68 |
67 DEFINE_TRACE(ExternalPopupMenu) | 69 DEFINE_TRACE(ExternalPopupMenu) |
68 { | 70 { |
69 visitor->trace(m_ownerElement); | 71 visitor->trace(m_ownerElement); |
70 visitor->trace(m_localFrame); | 72 visitor->trace(m_localFrame); |
71 PopupMenu::trace(visitor); | 73 PopupMenu::trace(visitor); |
72 } | 74 } |
73 | 75 |
74 void ExternalPopupMenu::show(const FloatQuad& controlPosition, const IntSize&, i nt index) | 76 bool ExternalPopupMenu::showInternal() |
75 { | 77 { |
76 IntRect rect(controlPosition.enclosingBoundingBox()); | 78 // Blink core reuses the PopupMenu of an element. For simplicity, we do |
77 // WebCore reuses the PopupMenu of an element. | 79 // recreate the actual external popup everytime. |
78 // For simplicity, we do recreate the actual external popup everytime. | |
79 if (m_webExternalPopupMenu) { | 80 if (m_webExternalPopupMenu) { |
80 m_webExternalPopupMenu->close(); | 81 m_webExternalPopupMenu->close(); |
81 m_webExternalPopupMenu = 0; | 82 m_webExternalPopupMenu = 0; |
82 } | 83 } |
83 | 84 |
84 WebPopupMenuInfo info; | 85 WebPopupMenuInfo info; |
85 getPopupMenuInfo(info, *m_ownerElement); | 86 getPopupMenuInfo(info, *m_ownerElement); |
86 if (info.items.isEmpty()) | 87 if (info.items.isEmpty()) |
87 return; | 88 return false; |
88 WebLocalFrameImpl* webframe = WebLocalFrameImpl::fromFrame(m_localFrame.get( )); | 89 WebLocalFrameImpl* webframe = WebLocalFrameImpl::fromFrame(m_localFrame.get( )); |
89 m_webExternalPopupMenu = webframe->client()->createExternalPopupMenu(info, t his); | 90 m_webExternalPopupMenu = webframe->client()->createExternalPopupMenu(info, t his); |
90 if (m_webExternalPopupMenu) { | 91 if (m_webExternalPopupMenu) { |
92 LayoutObject* layoutObject = m_ownerElement->layoutObject(); | |
93 if (!layoutObject || !layoutObject->isBox()) | |
94 return false; | |
95 FloatQuad quad(toLayoutBox(layoutObject)->localToAbsoluteQuad(FloatQuad( toLayoutBox(layoutObject)->borderBoundingBox()))); | |
96 IntRect rect(quad.enclosingBoundingBox()); | |
91 IntRect rectInViewport = m_localFrame->view()->soonToBeRemovedContentsTo UnscaledViewport(rect); | 97 IntRect rectInViewport = m_localFrame->view()->soonToBeRemovedContentsTo UnscaledViewport(rect); |
98 // TODO(tkent): If the anchor rectangle is not visible, we should not | |
99 // show a popup. | |
92 m_webExternalPopupMenu->show(rectInViewport); | 100 m_webExternalPopupMenu->show(rectInViewport); |
93 #if OS(MACOSX) | 101 return true; |
94 const WebInputEvent* currentEvent = WebViewImpl::currentInputEvent(); | |
95 if (currentEvent && currentEvent->type == WebInputEvent::MouseDown) { | |
96 m_syntheticEvent = adoptPtr(new WebMouseEvent); | |
97 *m_syntheticEvent = *static_cast<const WebMouseEvent*>(currentEvent) ; | |
98 m_syntheticEvent->type = WebInputEvent::MouseUp; | |
99 m_dispatchEventTimer.startOneShot(0, BLINK_FROM_HERE); | |
100 // FIXME: show() is asynchronous. If preparing a popup is slow and | |
101 // a user released the mouse button before showing the popup, | |
102 // mouseup and click events are correctly dispatched. Dispatching | |
103 // the synthetic mouseup event is redundant in this case. | |
104 } | |
105 #endif | |
106 } else { | 102 } else { |
107 // The client might refuse to create a popup (when there is already one pending to be shown for example). | 103 // The client might refuse to create a popup (when there is already one pending to be shown for example). |
108 didCancel(); | 104 didCancel(); |
105 return false; | |
109 } | 106 } |
110 } | 107 } |
111 | 108 |
109 void ExternalPopupMenu::show(const FloatQuad&, const IntSize&, int) | |
110 { | |
111 if (!showInternal()) | |
112 return; | |
113 #if OS(MACOSX) | |
114 const WebInputEvent* currentEvent = WebViewImpl::currentInputEvent(); | |
115 if (currentEvent && currentEvent->type == WebInputEvent::MouseDown) { | |
116 m_syntheticEvent = adoptPtr(new WebMouseEvent); | |
117 *m_syntheticEvent = *static_cast<const WebMouseEvent*>(currentEvent); | |
118 m_syntheticEvent->type = WebInputEvent::MouseUp; | |
119 m_dispatchEventTimer.startOneShot(0, BLINK_FROM_HERE); | |
120 // FIXME: show() is asynchronous. If preparing a popup is slow and a | |
121 // user released the mouse button before showing the popup, mouseup and | |
122 // click events are correctly dispatched. Dispatching the synthetic | |
123 // mouseup event is redundant in this case. | |
124 } | |
125 #endif | |
126 } | |
127 | |
112 void ExternalPopupMenu::dispatchEvent(Timer<ExternalPopupMenu>*) | 128 void ExternalPopupMenu::dispatchEvent(Timer<ExternalPopupMenu>*) |
113 { | 129 { |
114 m_webView.handleInputEvent(*m_syntheticEvent); | 130 m_webView.handleInputEvent(*m_syntheticEvent); |
115 m_syntheticEvent.clear(); | 131 m_syntheticEvent.clear(); |
116 } | 132 } |
117 | 133 |
118 void ExternalPopupMenu::hide() | 134 void ExternalPopupMenu::hide() |
119 { | 135 { |
120 if (m_ownerElement) | 136 if (m_ownerElement) |
121 m_ownerElement->popupDidHide(); | 137 m_ownerElement->popupDidHide(); |
122 if (!m_webExternalPopupMenu) | 138 if (!m_webExternalPopupMenu) |
123 return; | 139 return; |
124 m_webExternalPopupMenu->close(); | 140 m_webExternalPopupMenu->close(); |
125 m_webExternalPopupMenu = 0; | 141 m_webExternalPopupMenu = 0; |
126 } | 142 } |
127 | 143 |
128 void ExternalPopupMenu::updateFromElement() | 144 void ExternalPopupMenu::updateFromElement() |
129 { | 145 { |
146 if (m_needsUpdate) | |
147 return; | |
148 m_needsUpdate = true; | |
149 m_ownerElement->document().postTask(BLINK_FROM_HERE, createSameThreadTask(&E xternalPopupMenu::update, PassRefPtrWillBeRawPtr<ExternalPopupMenu>(this))); | |
150 } | |
151 | |
152 void ExternalPopupMenu::update() | |
153 { | |
154 if (!m_webExternalPopupMenu || !m_ownerElement) | |
155 return; | |
156 m_ownerElement->document().updateLayoutTreeIfNeeded(); | |
157 // disconnectClient() might have been called. | |
158 if (!m_ownerElement) | |
159 return; | |
160 m_needsUpdate = false; | |
161 | |
162 if (showInternal()) | |
163 return; | |
164 // We failed to show a popup. Notice it to the owner. | |
keishi
2016/01/20 03:39:34
nit: s/Notice/Notify/
tkent
2016/01/20 04:13:39
Done.
| |
165 hide(); | |
130 } | 166 } |
131 | 167 |
132 void ExternalPopupMenu::disconnectClient() | 168 void ExternalPopupMenu::disconnectClient() |
133 { | 169 { |
134 hide(); | 170 hide(); |
135 m_ownerElement = nullptr; | 171 m_ownerElement = nullptr; |
136 } | 172 } |
137 | 173 |
138 void ExternalPopupMenu::didChangeSelection(int index) | 174 void ExternalPopupMenu::didChangeSelection(int index) |
139 { | 175 { |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
256 if (ownerElement.itemIsDisplayNone(*items[i])) | 292 if (ownerElement.itemIsDisplayNone(*items[i])) |
257 continue; | 293 continue; |
258 if (popupMenuItemIndex == i) | 294 if (popupMenuItemIndex == i) |
259 return indexTracker; | 295 return indexTracker; |
260 ++indexTracker; | 296 ++indexTracker; |
261 } | 297 } |
262 return -1; | 298 return -1; |
263 } | 299 } |
264 | 300 |
265 } // namespace blink | 301 } // namespace blink |
OLD | NEW |