| 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 { | 65 { |
| 66 IntRect rect(controlPosition.enclosingBoundingBox()); | 66 IntRect rect(controlPosition.enclosingBoundingBox()); |
| 67 // WebCore reuses the PopupMenu of an element. | 67 // WebCore reuses the PopupMenu of an element. |
| 68 // For simplicity, we do recreate the actual external popup everytime. | 68 // For simplicity, we do recreate the actual external popup everytime. |
| 69 if (m_webExternalPopupMenu) { | 69 if (m_webExternalPopupMenu) { |
| 70 m_webExternalPopupMenu->close(); | 70 m_webExternalPopupMenu->close(); |
| 71 m_webExternalPopupMenu = 0; | 71 m_webExternalPopupMenu = 0; |
| 72 } | 72 } |
| 73 | 73 |
| 74 WebPopupMenuInfo info; | 74 WebPopupMenuInfo info; |
| 75 getPopupMenuInfo(&info); | 75 getPopupMenuInfo(info, *m_popupMenuClient); |
| 76 if (info.items.isEmpty()) | 76 if (info.items.isEmpty()) |
| 77 return; | 77 return; |
| 78 m_webExternalPopupMenu = m_webView.client()->createExternalPopupMenu(info, t
his); | 78 m_webExternalPopupMenu = m_webView.client()->createExternalPopupMenu(info, t
his); |
| 79 if (m_webExternalPopupMenu) { | 79 if (m_webExternalPopupMenu) { |
| 80 m_webExternalPopupMenu->show(m_frameView->contentsToWindow(rect)); | 80 m_webExternalPopupMenu->show(m_frameView->contentsToWindow(rect)); |
| 81 #if OS(MACOSX) | 81 #if OS(MACOSX) |
| 82 const WebInputEvent* currentEvent = WebViewImpl::currentInputEvent(); | 82 const WebInputEvent* currentEvent = WebViewImpl::currentInputEvent(); |
| 83 if (currentEvent && currentEvent->type == WebInputEvent::MouseDown) { | 83 if (currentEvent && currentEvent->type == WebInputEvent::MouseDown) { |
| 84 m_syntheticEvent = adoptPtr(new WebMouseEvent); | 84 m_syntheticEvent = adoptPtr(new WebMouseEvent); |
| 85 *m_syntheticEvent = *static_cast<const WebMouseEvent*>(currentEvent)
; | 85 *m_syntheticEvent = *static_cast<const WebMouseEvent*>(currentEvent)
; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 | 119 |
| 120 void ExternalPopupMenu::disconnectClient() | 120 void ExternalPopupMenu::disconnectClient() |
| 121 { | 121 { |
| 122 hide(); | 122 hide(); |
| 123 m_popupMenuClient = 0; | 123 m_popupMenuClient = 0; |
| 124 } | 124 } |
| 125 | 125 |
| 126 void ExternalPopupMenu::didChangeSelection(int index) | 126 void ExternalPopupMenu::didChangeSelection(int index) |
| 127 { | 127 { |
| 128 if (m_popupMenuClient) | 128 if (m_popupMenuClient) |
| 129 m_popupMenuClient->selectionChanged(toPopupMenuItemIndex(index)); | 129 m_popupMenuClient->selectionChanged(toPopupMenuItemIndex(index, *m_popup
MenuClient)); |
| 130 } | 130 } |
| 131 | 131 |
| 132 void ExternalPopupMenu::didAcceptIndex(int index) | 132 void ExternalPopupMenu::didAcceptIndex(int index) |
| 133 { | 133 { |
| 134 // Calling methods on the PopupMenuClient might lead to this object being | 134 // Calling methods on the PopupMenuClient might lead to this object being |
| 135 // derefed. This ensures it does not get deleted while we are running this | 135 // derefed. This ensures it does not get deleted while we are running this |
| 136 // method. | 136 // method. |
| 137 int popupMenuItemIndex = toPopupMenuItemIndex(index); | 137 int popupMenuItemIndex = toPopupMenuItemIndex(index, *m_popupMenuClient); |
| 138 RefPtr<ExternalPopupMenu> guard(this); | 138 RefPtr<ExternalPopupMenu> guard(this); |
| 139 | 139 |
| 140 if (m_popupMenuClient) { | 140 if (m_popupMenuClient) { |
| 141 m_popupMenuClient->popupDidHide(); | 141 m_popupMenuClient->popupDidHide(); |
| 142 m_popupMenuClient->valueChanged(popupMenuItemIndex); | 142 m_popupMenuClient->valueChanged(popupMenuItemIndex); |
| 143 } | 143 } |
| 144 m_webExternalPopupMenu = 0; | 144 m_webExternalPopupMenu = 0; |
| 145 } | 145 } |
| 146 | 146 |
| 147 void ExternalPopupMenu::didAcceptIndices(const WebVector<int>& indices) | 147 void ExternalPopupMenu::didAcceptIndices(const WebVector<int>& indices) |
| 148 { | 148 { |
| 149 if (!m_popupMenuClient) { | 149 if (!m_popupMenuClient) { |
| 150 m_webExternalPopupMenu = 0; | 150 m_webExternalPopupMenu = 0; |
| 151 return; | 151 return; |
| 152 } | 152 } |
| 153 | 153 |
| 154 // Calling methods on the PopupMenuClient might lead to this object being | 154 // Calling methods on the PopupMenuClient might lead to this object being |
| 155 // derefed. This ensures it does not get deleted while we are running this | 155 // derefed. This ensures it does not get deleted while we are running this |
| 156 // method. | 156 // method. |
| 157 RefPtr<ExternalPopupMenu> protect(this); | 157 RefPtr<ExternalPopupMenu> protect(this); |
| 158 | 158 |
| 159 if (!indices.size()) | 159 if (!indices.size()) |
| 160 m_popupMenuClient->valueChanged(static_cast<unsigned>(-1), true); | 160 m_popupMenuClient->valueChanged(static_cast<unsigned>(-1), true); |
| 161 else { | 161 else { |
| 162 for (size_t i = 0; i < indices.size(); ++i) | 162 for (size_t i = 0; i < indices.size(); ++i) |
| 163 m_popupMenuClient->listBoxSelectItem(toPopupMenuItemIndex(indices[i]
), (i > 0), false, (i == indices.size() - 1)); | 163 m_popupMenuClient->listBoxSelectItem(toPopupMenuItemIndex(indices[i]
, *m_popupMenuClient), (i > 0), false, (i == indices.size() - 1)); |
| 164 } | 164 } |
| 165 | 165 |
| 166 // The call to valueChanged above might have lead to a call to | 166 // The call to valueChanged above might have lead to a call to |
| 167 // disconnectClient, so we might not have a PopupMenuClient anymore. | 167 // disconnectClient, so we might not have a PopupMenuClient anymore. |
| 168 if (m_popupMenuClient) | 168 if (m_popupMenuClient) |
| 169 m_popupMenuClient->popupDidHide(); | 169 m_popupMenuClient->popupDidHide(); |
| 170 | 170 |
| 171 m_webExternalPopupMenu = 0; | 171 m_webExternalPopupMenu = 0; |
| 172 } | 172 } |
| 173 | 173 |
| 174 void ExternalPopupMenu::didCancel() | 174 void ExternalPopupMenu::didCancel() |
| 175 { | 175 { |
| 176 // See comment in didAcceptIndex on why we need this. | 176 // See comment in didAcceptIndex on why we need this. |
| 177 RefPtr<ExternalPopupMenu> guard(this); | 177 RefPtr<ExternalPopupMenu> guard(this); |
| 178 | 178 |
| 179 if (m_popupMenuClient) | 179 if (m_popupMenuClient) |
| 180 m_popupMenuClient->popupDidHide(); | 180 m_popupMenuClient->popupDidHide(); |
| 181 m_webExternalPopupMenu = 0; | 181 m_webExternalPopupMenu = 0; |
| 182 } | 182 } |
| 183 | 183 |
| 184 void ExternalPopupMenu::getPopupMenuInfo(WebPopupMenuInfo* info) | 184 void ExternalPopupMenu::getPopupMenuInfo(WebPopupMenuInfo& info, PopupMenuClient
& popupMenuClient) |
| 185 { | 185 { |
| 186 int itemCount = m_popupMenuClient->listSize(); | 186 int itemCount = popupMenuClient.listSize(); |
| 187 int count = 0; | 187 int count = 0; |
| 188 Vector<WebMenuItemInfo> items(static_cast<size_t>(itemCount)); | 188 Vector<WebMenuItemInfo> items(static_cast<size_t>(itemCount)); |
| 189 for (int i = 0; i < itemCount; ++i) { | 189 for (int i = 0; i < itemCount; ++i) { |
| 190 PopupMenuStyle style = m_popupMenuClient->itemStyle(i); | 190 PopupMenuStyle style = popupMenuClient.itemStyle(i); |
| 191 if (style.isDisplayNone()) | 191 if (style.isDisplayNone()) |
| 192 continue; | 192 continue; |
| 193 | 193 |
| 194 WebMenuItemInfo& popupItem = items[count++]; | 194 WebMenuItemInfo& popupItem = items[count++]; |
| 195 popupItem.label = m_popupMenuClient->itemText(i); | 195 popupItem.label = popupMenuClient.itemText(i); |
| 196 popupItem.toolTip = m_popupMenuClient->itemToolTip(i); | 196 popupItem.toolTip = popupMenuClient.itemToolTip(i); |
| 197 if (m_popupMenuClient->itemIsSeparator(i)) | 197 if (popupMenuClient.itemIsSeparator(i)) |
| 198 popupItem.type = WebMenuItemInfo::Separator; | 198 popupItem.type = WebMenuItemInfo::Separator; |
| 199 else if (m_popupMenuClient->itemIsLabel(i)) | 199 else if (popupMenuClient.itemIsLabel(i)) |
| 200 popupItem.type = WebMenuItemInfo::Group; | 200 popupItem.type = WebMenuItemInfo::Group; |
| 201 else | 201 else |
| 202 popupItem.type = WebMenuItemInfo::Option; | 202 popupItem.type = WebMenuItemInfo::Option; |
| 203 popupItem.enabled = m_popupMenuClient->itemIsEnabled(i); | 203 popupItem.enabled = popupMenuClient.itemIsEnabled(i); |
| 204 popupItem.checked = m_popupMenuClient->itemIsSelected(i); | 204 popupItem.checked = popupMenuClient.itemIsSelected(i); |
| 205 if (style.textDirection() == blink::RTL) | 205 if (style.textDirection() == blink::RTL) |
| 206 popupItem.textDirection = WebTextDirectionRightToLeft; | 206 popupItem.textDirection = WebTextDirectionRightToLeft; |
| 207 else | 207 else |
| 208 popupItem.textDirection = WebTextDirectionLeftToRight; | 208 popupItem.textDirection = WebTextDirectionLeftToRight; |
| 209 popupItem.hasTextDirectionOverride = style.hasTextDirectionOverride(); | 209 popupItem.hasTextDirectionOverride = style.hasTextDirectionOverride(); |
| 210 } | 210 } |
| 211 | 211 |
| 212 info->itemHeight = m_popupMenuClient->menuStyle().font().fontMetrics().heigh
t(); | 212 info.itemHeight = popupMenuClient.menuStyle().font().fontMetrics().height(); |
| 213 info->itemFontSize = static_cast<int>(m_popupMenuClient->menuStyle().font().
fontDescription().computedSize()); | 213 info.itemFontSize = static_cast<int>(popupMenuClient.menuStyle().font().font
Description().computedSize()); |
| 214 info->selectedIndex = toExternalPopupMenuItemIndex(m_popupMenuClient->select
edIndex()); | 214 info.selectedIndex = toExternalPopupMenuItemIndex(popupMenuClient.selectedIn
dex(), popupMenuClient); |
| 215 info->rightAligned = m_popupMenuClient->menuStyle().textDirection() == blink
::RTL; | 215 info.rightAligned = popupMenuClient.menuStyle().textDirection() == blink::RT
L; |
| 216 info->allowMultipleSelection = m_popupMenuClient->multiple(); | 216 info.allowMultipleSelection = popupMenuClient.multiple(); |
| 217 info->items = items; | 217 if (count < itemCount) |
| 218 items.shrink(count); |
| 219 info.items = items; |
| 218 } | 220 } |
| 219 | 221 |
| 220 int ExternalPopupMenu::toPopupMenuItemIndex(int externalPopupMenuItemIndex) | 222 int ExternalPopupMenu::toPopupMenuItemIndex(int externalPopupMenuItemIndex, Popu
pMenuClient& popupMenuClient) |
| 221 { | 223 { |
| 222 ASSERT(m_popupMenuClient); | |
| 223 if (externalPopupMenuItemIndex < 0) | 224 if (externalPopupMenuItemIndex < 0) |
| 224 return externalPopupMenuItemIndex; | 225 return externalPopupMenuItemIndex; |
| 225 | 226 |
| 226 int itemCount = m_popupMenuClient->listSize(); | 227 int itemCount = popupMenuClient.listSize(); |
| 227 int indexTracker = 0; | 228 int indexTracker = 0; |
| 228 for (int i = 0; i < itemCount ; ++i) { | 229 for (int i = 0; i < itemCount ; ++i) { |
| 229 if (m_popupMenuClient->itemStyle(i).isDisplayNone()) | 230 if (popupMenuClient.itemStyle(i).isDisplayNone()) |
| 230 continue; | 231 continue; |
| 231 if (indexTracker++ == externalPopupMenuItemIndex) | 232 if (indexTracker++ == externalPopupMenuItemIndex) |
| 232 return i; | 233 return i; |
| 233 } | 234 } |
| 234 return -1; | 235 return -1; |
| 235 } | 236 } |
| 236 | 237 |
| 237 int ExternalPopupMenu::toExternalPopupMenuItemIndex(int popupMenuItemIndex) | 238 int ExternalPopupMenu::toExternalPopupMenuItemIndex(int popupMenuItemIndex, Popu
pMenuClient& popupMenuClient) |
| 238 { | 239 { |
| 239 ASSERT(m_popupMenuClient); | |
| 240 if (popupMenuItemIndex < 0) | 240 if (popupMenuItemIndex < 0) |
| 241 return popupMenuItemIndex; | 241 return popupMenuItemIndex; |
| 242 | 242 |
| 243 int itemCount = m_popupMenuClient->listSize(); | 243 int itemCount = popupMenuClient.listSize(); |
| 244 int indexTracker = 0; | 244 int indexTracker = 0; |
| 245 for (int i = 0; i < itemCount; ++i) { | 245 for (int i = 0; i < itemCount; ++i) { |
| 246 if (m_popupMenuClient->itemStyle(i).isDisplayNone()) | 246 if (popupMenuClient.itemStyle(i).isDisplayNone()) |
| 247 continue; | 247 continue; |
| 248 if (popupMenuItemIndex == i) | 248 if (popupMenuItemIndex == i) |
| 249 return indexTracker; | 249 return indexTracker; |
| 250 ++indexTracker; | 250 ++indexTracker; |
| 251 } | 251 } |
| 252 return -1; | 252 return -1; |
| 253 } | 253 } |
| 254 | 254 |
| 255 } | 255 } |
| OLD | NEW |