| 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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 void ExternalPopupMenu::updateFromElement() | 145 void ExternalPopupMenu::updateFromElement() |
| 146 { | 146 { |
| 147 if (m_needsUpdate) | 147 if (m_needsUpdate) |
| 148 return; | 148 return; |
| 149 // TOOD(tkent): Even if DOMTreeVersion is not changed, we should update the | 149 // TOOD(tkent): Even if DOMTreeVersion is not changed, we should update the |
| 150 // popup location/content in some cases. e.g. Updating ComputedStyle of the | 150 // popup location/content in some cases. e.g. Updating ComputedStyle of the |
| 151 // SELECT element affects popup position and OPTION style. | 151 // SELECT element affects popup position and OPTION style. |
| 152 if (m_shownDOMTreeVersion == m_ownerElement->document().domTreeVersion()) | 152 if (m_shownDOMTreeVersion == m_ownerElement->document().domTreeVersion()) |
| 153 return; | 153 return; |
| 154 m_needsUpdate = true; | 154 m_needsUpdate = true; |
| 155 m_ownerElement->document().postTask(BLINK_FROM_HERE, createSameThreadTask(&E
xternalPopupMenu::update, PassRefPtrWillBeRawPtr<ExternalPopupMenu>(this))); | 155 m_ownerElement->document().postTask(BLINK_FROM_HERE, createSameThreadTask(&E
xternalPopupMenu::update, RawPtr<ExternalPopupMenu>(this))); |
| 156 } | 156 } |
| 157 | 157 |
| 158 void ExternalPopupMenu::update() | 158 void ExternalPopupMenu::update() |
| 159 { | 159 { |
| 160 if (!m_webExternalPopupMenu || !m_ownerElement) | 160 if (!m_webExternalPopupMenu || !m_ownerElement) |
| 161 return; | 161 return; |
| 162 m_ownerElement->document().updateLayoutTreeIfNeeded(); | 162 m_ownerElement->document().updateLayoutTreeIfNeeded(); |
| 163 // disconnectClient() might have been called. | 163 // disconnectClient() might have been called. |
| 164 if (!m_ownerElement) | 164 if (!m_ownerElement) |
| 165 return; | 165 return; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 180 void ExternalPopupMenu::didChangeSelection(int index) | 180 void ExternalPopupMenu::didChangeSelection(int index) |
| 181 { | 181 { |
| 182 } | 182 } |
| 183 | 183 |
| 184 void ExternalPopupMenu::didAcceptIndex(int index) | 184 void ExternalPopupMenu::didAcceptIndex(int index) |
| 185 { | 185 { |
| 186 // Calling methods on the HTMLSelectElement might lead to this object being | 186 // Calling methods on the HTMLSelectElement might lead to this object being |
| 187 // derefed. This ensures it does not get deleted while we are running this | 187 // derefed. This ensures it does not get deleted while we are running this |
| 188 // method. | 188 // method. |
| 189 int popupMenuItemIndex = toPopupMenuItemIndex(index, *m_ownerElement); | 189 int popupMenuItemIndex = toPopupMenuItemIndex(index, *m_ownerElement); |
| 190 RefPtrWillBeRawPtr<ExternalPopupMenu> guard(this); | 190 RawPtr<ExternalPopupMenu> guard(this); |
| 191 | 191 |
| 192 if (m_ownerElement) { | 192 if (m_ownerElement) { |
| 193 m_ownerElement->popupDidHide(); | 193 m_ownerElement->popupDidHide(); |
| 194 m_ownerElement->valueChanged(popupMenuItemIndex); | 194 m_ownerElement->valueChanged(popupMenuItemIndex); |
| 195 } | 195 } |
| 196 m_webExternalPopupMenu = 0; | 196 m_webExternalPopupMenu = 0; |
| 197 } | 197 } |
| 198 | 198 |
| 199 void ExternalPopupMenu::didAcceptIndices(const WebVector<int>& indices) | 199 void ExternalPopupMenu::didAcceptIndices(const WebVector<int>& indices) |
| 200 { | 200 { |
| 201 if (!m_ownerElement) { | 201 if (!m_ownerElement) { |
| 202 m_webExternalPopupMenu = 0; | 202 m_webExternalPopupMenu = 0; |
| 203 return; | 203 return; |
| 204 } | 204 } |
| 205 | 205 |
| 206 // Calling methods on the HTMLSelectElement might lead to this object being | 206 // Calling methods on the HTMLSelectElement might lead to this object being |
| 207 // derefed. This ensures it does not get deleted while we are running this | 207 // derefed. This ensures it does not get deleted while we are running this |
| 208 // method. | 208 // method. |
| 209 RefPtrWillBeRawPtr<ExternalPopupMenu> protect(this); | 209 RawPtr<ExternalPopupMenu> protect(this); |
| 210 RefPtrWillBeRawPtr<HTMLSelectElement> ownerElement(m_ownerElement.get()); | 210 RawPtr<HTMLSelectElement> ownerElement(m_ownerElement.get()); |
| 211 ownerElement->popupDidHide(); | 211 ownerElement->popupDidHide(); |
| 212 | 212 |
| 213 if (indices.size() == 0) { | 213 if (indices.size() == 0) { |
| 214 ownerElement->valueChanged(static_cast<unsigned>(-1)); | 214 ownerElement->valueChanged(static_cast<unsigned>(-1)); |
| 215 } else { | 215 } else { |
| 216 for (size_t i = 0; i < indices.size(); ++i) | 216 for (size_t i = 0; i < indices.size(); ++i) |
| 217 ownerElement->listBoxSelectItem(toPopupMenuItemIndex(indices[i], *ow
nerElement), (i > 0), false, (i == indices.size() - 1)); | 217 ownerElement->listBoxSelectItem(toPopupMenuItemIndex(indices[i], *ow
nerElement), (i > 0), false, (i == indices.size() - 1)); |
| 218 } | 218 } |
| 219 | 219 |
| 220 m_webExternalPopupMenu = 0; | 220 m_webExternalPopupMenu = 0; |
| 221 } | 221 } |
| 222 | 222 |
| 223 void ExternalPopupMenu::didCancel() | 223 void ExternalPopupMenu::didCancel() |
| 224 { | 224 { |
| 225 // See comment in didAcceptIndex on why we need this. | 225 // See comment in didAcceptIndex on why we need this. |
| 226 RefPtrWillBeRawPtr<ExternalPopupMenu> guard(this); | 226 RawPtr<ExternalPopupMenu> guard(this); |
| 227 | 227 |
| 228 if (m_ownerElement) | 228 if (m_ownerElement) |
| 229 m_ownerElement->popupDidHide(); | 229 m_ownerElement->popupDidHide(); |
| 230 m_webExternalPopupMenu = 0; | 230 m_webExternalPopupMenu = 0; |
| 231 } | 231 } |
| 232 | 232 |
| 233 void ExternalPopupMenu::getPopupMenuInfo(WebPopupMenuInfo& info, HTMLSelectEleme
nt& ownerElement) | 233 void ExternalPopupMenu::getPopupMenuInfo(WebPopupMenuInfo& info, HTMLSelectEleme
nt& ownerElement) |
| 234 { | 234 { |
| 235 const WillBeHeapVector<RawPtrWillBeMember<HTMLElement>>& listItems = ownerEl
ement.listItems(); | 235 const HeapVector<Member<HTMLElement>>& listItems = ownerElement.listItems(); |
| 236 size_t itemCount = listItems.size(); | 236 size_t itemCount = listItems.size(); |
| 237 size_t count = 0; | 237 size_t count = 0; |
| 238 Vector<WebMenuItemInfo> items(itemCount); | 238 Vector<WebMenuItemInfo> items(itemCount); |
| 239 for (size_t i = 0; i < itemCount; ++i) { | 239 for (size_t i = 0; i < itemCount; ++i) { |
| 240 if (ownerElement.itemIsDisplayNone(*listItems[i])) | 240 if (ownerElement.itemIsDisplayNone(*listItems[i])) |
| 241 continue; | 241 continue; |
| 242 | 242 |
| 243 Element& itemElement = *listItems[i]; | 243 Element& itemElement = *listItems[i]; |
| 244 WebMenuItemInfo& popupItem = items[count++]; | 244 WebMenuItemInfo& popupItem = items[count++]; |
| 245 popupItem.label = ownerElement.itemText(itemElement); | 245 popupItem.label = ownerElement.itemText(itemElement); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 270 info.items = items; | 270 info.items = items; |
| 271 | 271 |
| 272 } | 272 } |
| 273 | 273 |
| 274 int ExternalPopupMenu::toPopupMenuItemIndex(int externalPopupMenuItemIndex, HTML
SelectElement& ownerElement) | 274 int ExternalPopupMenu::toPopupMenuItemIndex(int externalPopupMenuItemIndex, HTML
SelectElement& ownerElement) |
| 275 { | 275 { |
| 276 if (externalPopupMenuItemIndex < 0) | 276 if (externalPopupMenuItemIndex < 0) |
| 277 return externalPopupMenuItemIndex; | 277 return externalPopupMenuItemIndex; |
| 278 | 278 |
| 279 int indexTracker = 0; | 279 int indexTracker = 0; |
| 280 const WillBeHeapVector<RawPtrWillBeMember<HTMLElement>>& items = ownerElemen
t.listItems(); | 280 const HeapVector<Member<HTMLElement>>& items = ownerElement.listItems(); |
| 281 for (int i = 0; i < static_cast<int>(items.size()); ++i) { | 281 for (int i = 0; i < static_cast<int>(items.size()); ++i) { |
| 282 if (ownerElement.itemIsDisplayNone(*items[i])) | 282 if (ownerElement.itemIsDisplayNone(*items[i])) |
| 283 continue; | 283 continue; |
| 284 if (indexTracker++ == externalPopupMenuItemIndex) | 284 if (indexTracker++ == externalPopupMenuItemIndex) |
| 285 return i; | 285 return i; |
| 286 } | 286 } |
| 287 return -1; | 287 return -1; |
| 288 } | 288 } |
| 289 | 289 |
| 290 int ExternalPopupMenu::toExternalPopupMenuItemIndex(int popupMenuItemIndex, HTML
SelectElement& ownerElement) | 290 int ExternalPopupMenu::toExternalPopupMenuItemIndex(int popupMenuItemIndex, HTML
SelectElement& ownerElement) |
| 291 { | 291 { |
| 292 if (popupMenuItemIndex < 0) | 292 if (popupMenuItemIndex < 0) |
| 293 return popupMenuItemIndex; | 293 return popupMenuItemIndex; |
| 294 | 294 |
| 295 size_t indexTracker = 0; | 295 size_t indexTracker = 0; |
| 296 const WillBeHeapVector<RawPtrWillBeMember<HTMLElement>>& items = ownerElemen
t.listItems(); | 296 const HeapVector<Member<HTMLElement>>& items = ownerElement.listItems(); |
| 297 for (int i = 0; i < static_cast<int>(items.size()); ++i) { | 297 for (int i = 0; i < static_cast<int>(items.size()); ++i) { |
| 298 if (ownerElement.itemIsDisplayNone(*items[i])) | 298 if (ownerElement.itemIsDisplayNone(*items[i])) |
| 299 continue; | 299 continue; |
| 300 if (popupMenuItemIndex == i) | 300 if (popupMenuItemIndex == i) |
| 301 return indexTracker; | 301 return indexTracker; |
| 302 ++indexTracker; | 302 ++indexTracker; |
| 303 } | 303 } |
| 304 return -1; | 304 return -1; |
| 305 } | 305 } |
| 306 | 306 |
| 307 } // namespace blink | 307 } // namespace blink |
| OLD | NEW |