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" | |
34 #include "core/dom/NodeComputedStyle.h" | 33 #include "core/dom/NodeComputedStyle.h" |
35 #include "core/frame/FrameHost.h" | 34 #include "core/frame/FrameHost.h" |
36 #include "core/frame/FrameView.h" | 35 #include "core/frame/FrameView.h" |
37 #include "core/frame/LocalFrame.h" | 36 #include "core/frame/LocalFrame.h" |
38 #include "core/html/HTMLOptionElement.h" | 37 #include "core/html/HTMLOptionElement.h" |
39 #include "core/html/HTMLSelectElement.h" | 38 #include "core/html/HTMLSelectElement.h" |
40 #include "core/layout/LayoutBox.h" | |
41 #include "core/page/Page.h" | 39 #include "core/page/Page.h" |
42 #include "core/style/ComputedStyle.h" | 40 #include "core/style/ComputedStyle.h" |
43 #include "platform/geometry/FloatQuad.h" | 41 #include "platform/geometry/FloatQuad.h" |
44 #include "platform/geometry/IntPoint.h" | 42 #include "platform/geometry/IntPoint.h" |
45 #include "platform/text/TextDirection.h" | 43 #include "platform/text/TextDirection.h" |
46 #include "public/platform/WebVector.h" | 44 #include "public/platform/WebVector.h" |
47 #include "public/web/WebExternalPopupMenu.h" | 45 #include "public/web/WebExternalPopupMenu.h" |
48 #include "public/web/WebFrameClient.h" | 46 #include "public/web/WebFrameClient.h" |
49 #include "public/web/WebMenuItemInfo.h" | 47 #include "public/web/WebMenuItemInfo.h" |
50 #include "public/web/WebPopupMenuInfo.h" | 48 #include "public/web/WebPopupMenuInfo.h" |
(...skipping 15 matching lines...) Expand all Loading... |
66 { | 64 { |
67 } | 65 } |
68 | 66 |
69 DEFINE_TRACE(ExternalPopupMenu) | 67 DEFINE_TRACE(ExternalPopupMenu) |
70 { | 68 { |
71 visitor->trace(m_ownerElement); | 69 visitor->trace(m_ownerElement); |
72 visitor->trace(m_localFrame); | 70 visitor->trace(m_localFrame); |
73 PopupMenu::trace(visitor); | 71 PopupMenu::trace(visitor); |
74 } | 72 } |
75 | 73 |
76 bool ExternalPopupMenu::showInternal() | 74 void ExternalPopupMenu::show(const FloatQuad& controlPosition, const IntSize&, i
nt index) |
77 { | 75 { |
78 // Blink core reuses the PopupMenu of an element. For simplicity, we do | 76 IntRect rect(controlPosition.enclosingBoundingBox()); |
79 // recreate the actual external popup everytime. | 77 // WebCore reuses the PopupMenu of an element. |
| 78 // For simplicity, we do recreate the actual external popup everytime. |
80 if (m_webExternalPopupMenu) { | 79 if (m_webExternalPopupMenu) { |
81 m_webExternalPopupMenu->close(); | 80 m_webExternalPopupMenu->close(); |
82 m_webExternalPopupMenu = 0; | 81 m_webExternalPopupMenu = 0; |
83 } | 82 } |
84 | 83 |
85 WebPopupMenuInfo info; | 84 WebPopupMenuInfo info; |
86 getPopupMenuInfo(info, *m_ownerElement); | 85 getPopupMenuInfo(info, *m_ownerElement); |
87 if (info.items.isEmpty()) | 86 if (info.items.isEmpty()) |
88 return false; | 87 return; |
89 WebLocalFrameImpl* webframe = WebLocalFrameImpl::fromFrame(m_localFrame.get(
)); | 88 WebLocalFrameImpl* webframe = WebLocalFrameImpl::fromFrame(m_localFrame.get(
)); |
90 m_webExternalPopupMenu = webframe->client()->createExternalPopupMenu(info, t
his); | 89 m_webExternalPopupMenu = webframe->client()->createExternalPopupMenu(info, t
his); |
91 if (m_webExternalPopupMenu) { | 90 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()); | |
97 IntRect rectInViewport = m_localFrame->view()->soonToBeRemovedContentsTo
UnscaledViewport(rect); | 91 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. | |
100 m_webExternalPopupMenu->show(rectInViewport); | 92 m_webExternalPopupMenu->show(rectInViewport); |
101 return true; | 93 #if OS(MACOSX) |
| 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 |
102 } else { | 106 } else { |
103 // The client might refuse to create a popup (when there is already one
pending to be shown for example). | 107 // The client might refuse to create a popup (when there is already one
pending to be shown for example). |
104 didCancel(); | 108 didCancel(); |
105 return false; | |
106 } | 109 } |
107 } | 110 } |
108 | 111 |
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 | |
128 void ExternalPopupMenu::dispatchEvent(Timer<ExternalPopupMenu>*) | 112 void ExternalPopupMenu::dispatchEvent(Timer<ExternalPopupMenu>*) |
129 { | 113 { |
130 m_webView.handleInputEvent(*m_syntheticEvent); | 114 m_webView.handleInputEvent(*m_syntheticEvent); |
131 m_syntheticEvent.clear(); | 115 m_syntheticEvent.clear(); |
132 } | 116 } |
133 | 117 |
134 void ExternalPopupMenu::hide() | 118 void ExternalPopupMenu::hide() |
135 { | 119 { |
136 if (m_ownerElement) | 120 if (m_ownerElement) |
137 m_ownerElement->popupDidHide(); | 121 m_ownerElement->popupDidHide(); |
138 if (!m_webExternalPopupMenu) | 122 if (!m_webExternalPopupMenu) |
139 return; | 123 return; |
140 m_webExternalPopupMenu->close(); | 124 m_webExternalPopupMenu->close(); |
141 m_webExternalPopupMenu = 0; | 125 m_webExternalPopupMenu = 0; |
142 } | 126 } |
143 | 127 |
144 void ExternalPopupMenu::updateFromElement() | 128 void ExternalPopupMenu::updateFromElement() |
145 { | 129 { |
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. Notify it to the owner. | |
165 hide(); | |
166 } | 130 } |
167 | 131 |
168 void ExternalPopupMenu::disconnectClient() | 132 void ExternalPopupMenu::disconnectClient() |
169 { | 133 { |
170 hide(); | 134 hide(); |
171 m_ownerElement = nullptr; | 135 m_ownerElement = nullptr; |
172 } | 136 } |
173 | 137 |
174 void ExternalPopupMenu::didChangeSelection(int index) | 138 void ExternalPopupMenu::didChangeSelection(int index) |
175 { | 139 { |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 if (ownerElement.itemIsDisplayNone(*items[i])) | 256 if (ownerElement.itemIsDisplayNone(*items[i])) |
293 continue; | 257 continue; |
294 if (popupMenuItemIndex == i) | 258 if (popupMenuItemIndex == i) |
295 return indexTracker; | 259 return indexTracker; |
296 ++indexTracker; | 260 ++indexTracker; |
297 } | 261 } |
298 return -1; | 262 return -1; |
299 } | 263 } |
300 | 264 |
301 } // namespace blink | 265 } // namespace blink |
OLD | NEW |