Chromium Code Reviews| 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 47 using namespace blink; | 47 using namespace blink; |
| 48 | 48 |
| 49 namespace blink { | 49 namespace blink { |
| 50 | 50 |
| 51 ExternalPopupMenu::ExternalPopupMenu(LocalFrame& frame, PopupMenuClient* popupMe nuClient, WebViewImpl& webView) | 51 ExternalPopupMenu::ExternalPopupMenu(LocalFrame& frame, PopupMenuClient* popupMe nuClient, WebViewImpl& webView) |
| 52 : m_popupMenuClient(popupMenuClient) | 52 : m_popupMenuClient(popupMenuClient) |
| 53 , m_frameView(frame.view()) | 53 , m_frameView(frame.view()) |
| 54 , m_webView(webView) | 54 , m_webView(webView) |
| 55 , m_dispatchEventTimer(this, &ExternalPopupMenu::dispatchEvent) | 55 , m_dispatchEventTimer(this, &ExternalPopupMenu::dispatchEvent) |
| 56 , m_webExternalPopupMenu(0) | 56 , m_webExternalPopupMenu(0) |
| 57 , m_itemCount(0) | |
| 57 { | 58 { |
| 58 } | 59 } |
| 59 | 60 |
| 60 ExternalPopupMenu::~ExternalPopupMenu() | 61 ExternalPopupMenu::~ExternalPopupMenu() |
| 61 { | 62 { |
| 62 } | 63 } |
| 63 | 64 |
| 64 void ExternalPopupMenu::show(const FloatQuad& controlPosition, const IntSize&, i nt index) | 65 void ExternalPopupMenu::show(const FloatQuad& controlPosition, const IntSize&, i nt index) |
| 65 { | 66 { |
| 66 IntRect rect(controlPosition.enclosingBoundingBox()); | 67 IntRect rect(controlPosition.enclosingBoundingBox()); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 119 | 120 |
| 120 void ExternalPopupMenu::disconnectClient() | 121 void ExternalPopupMenu::disconnectClient() |
| 121 { | 122 { |
| 122 hide(); | 123 hide(); |
| 123 m_popupMenuClient = 0; | 124 m_popupMenuClient = 0; |
| 124 } | 125 } |
| 125 | 126 |
| 126 void ExternalPopupMenu::didChangeSelection(int index) | 127 void ExternalPopupMenu::didChangeSelection(int index) |
| 127 { | 128 { |
| 128 if (m_popupMenuClient) | 129 if (m_popupMenuClient) |
| 129 m_popupMenuClient->selectionChanged(index); | 130 m_popupMenuClient->selectionChanged(toPopupMenuItemIndex(index)); |
| 130 } | 131 } |
| 131 | 132 |
| 132 void ExternalPopupMenu::didAcceptIndex(int index) | 133 void ExternalPopupMenu::didAcceptIndex(int index) |
| 133 { | 134 { |
| 134 // Calling methods on the PopupMenuClient might lead to this object being | 135 // 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 | 136 // derefed. This ensures it does not get deleted while we are running this |
| 136 // method. | 137 // method. |
| 138 int popupMenuItemIndex = toPopupMenuItemIndex(index); | |
| 137 RefPtr<ExternalPopupMenu> guard(this); | 139 RefPtr<ExternalPopupMenu> guard(this); |
| 138 | 140 |
| 139 if (m_popupMenuClient) { | 141 if (m_popupMenuClient) { |
| 140 m_popupMenuClient->popupDidHide(); | 142 m_popupMenuClient->popupDidHide(); |
| 141 m_popupMenuClient->valueChanged(index); | 143 m_popupMenuClient->valueChanged(popupMenuItemIndex); |
| 142 } | 144 } |
| 143 m_webExternalPopupMenu = 0; | 145 m_webExternalPopupMenu = 0; |
| 144 } | 146 } |
| 145 | 147 |
| 146 void ExternalPopupMenu::didAcceptIndices(const WebVector<int>& indices) | 148 void ExternalPopupMenu::didAcceptIndices(const WebVector<int>& indices) |
| 147 { | 149 { |
| 148 if (!m_popupMenuClient) { | 150 if (!m_popupMenuClient) { |
| 149 m_webExternalPopupMenu = 0; | 151 m_webExternalPopupMenu = 0; |
| 150 return; | 152 return; |
| 151 } | 153 } |
| 152 | 154 |
| 153 // Calling methods on the PopupMenuClient might lead to this object being | 155 // Calling methods on the PopupMenuClient might lead to this object being |
| 154 // derefed. This ensures it does not get deleted while we are running this | 156 // derefed. This ensures it does not get deleted while we are running this |
| 155 // method. | 157 // method. |
| 156 RefPtr<ExternalPopupMenu> protect(this); | 158 RefPtr<ExternalPopupMenu> protect(this); |
| 157 | 159 |
| 158 if (!indices.size()) | 160 if (!indices.size()) |
| 159 m_popupMenuClient->valueChanged(static_cast<unsigned>(-1), true); | 161 m_popupMenuClient->valueChanged(static_cast<unsigned>(-1), true); |
| 160 else { | 162 else { |
| 161 for (size_t i = 0; i < indices.size(); ++i) | 163 for (size_t i = 0; i < indices.size(); ++i) |
| 162 m_popupMenuClient->listBoxSelectItem(indices[i], (i > 0), false, (i == indices.size() - 1)); | 164 m_popupMenuClient->listBoxSelectItem(toPopupMenuItemIndex(indices[i] ), (i > 0), false, (i == indices.size() - 1)); |
| 163 } | 165 } |
| 164 | 166 |
| 165 // The call to valueChanged above might have lead to a call to | 167 // The call to valueChanged above might have lead to a call to |
| 166 // disconnectClient, so we might not have a PopupMenuClient anymore. | 168 // disconnectClient, so we might not have a PopupMenuClient anymore. |
| 167 if (m_popupMenuClient) | 169 if (m_popupMenuClient) |
| 168 m_popupMenuClient->popupDidHide(); | 170 m_popupMenuClient->popupDidHide(); |
| 169 | 171 |
| 170 m_webExternalPopupMenu = 0; | 172 m_webExternalPopupMenu = 0; |
| 171 } | 173 } |
| 172 | 174 |
| 173 void ExternalPopupMenu::didCancel() | 175 void ExternalPopupMenu::didCancel() |
| 174 { | 176 { |
| 175 // See comment in didAcceptIndex on why we need this. | 177 // See comment in didAcceptIndex on why we need this. |
| 176 RefPtr<ExternalPopupMenu> guard(this); | 178 RefPtr<ExternalPopupMenu> guard(this); |
| 177 | 179 |
| 178 if (m_popupMenuClient) | 180 if (m_popupMenuClient) |
| 179 m_popupMenuClient->popupDidHide(); | 181 m_popupMenuClient->popupDidHide(); |
| 180 m_webExternalPopupMenu = 0; | 182 m_webExternalPopupMenu = 0; |
| 181 } | 183 } |
| 182 | 184 |
| 183 void ExternalPopupMenu::getPopupMenuInfo(WebPopupMenuInfo* info) | 185 void ExternalPopupMenu::getPopupMenuInfo(WebPopupMenuInfo* info) |
| 184 { | 186 { |
| 185 int itemCount = m_popupMenuClient->listSize(); | 187 int itemCount = m_popupMenuClient->listSize(); |
| 188 m_itemCount = 0; | |
| 186 WebVector<WebMenuItemInfo> items(static_cast<size_t>(itemCount)); | 189 WebVector<WebMenuItemInfo> items(static_cast<size_t>(itemCount)); |
| 187 for (int i = 0; i < itemCount; ++i) { | 190 for (int i = 0; i < itemCount; ++i) { |
| 188 WebMenuItemInfo& popupItem = items[i]; | 191 PopupMenuStyle style = m_popupMenuClient->itemStyle(i); |
| 192 if (style.isDisplayNone()) | |
| 193 continue; | |
| 194 | |
| 195 WebMenuItemInfo& popupItem = items[m_itemCount++]; | |
| 189 popupItem.label = m_popupMenuClient->itemText(i); | 196 popupItem.label = m_popupMenuClient->itemText(i); |
| 190 popupItem.toolTip = m_popupMenuClient->itemToolTip(i); | 197 popupItem.toolTip = m_popupMenuClient->itemToolTip(i); |
| 191 if (m_popupMenuClient->itemIsSeparator(i)) | 198 if (m_popupMenuClient->itemIsSeparator(i)) |
| 192 popupItem.type = WebMenuItemInfo::Separator; | 199 popupItem.type = WebMenuItemInfo::Separator; |
| 193 else if (m_popupMenuClient->itemIsLabel(i)) | 200 else if (m_popupMenuClient->itemIsLabel(i)) |
| 194 popupItem.type = WebMenuItemInfo::Group; | 201 popupItem.type = WebMenuItemInfo::Group; |
| 195 else | 202 else |
| 196 popupItem.type = WebMenuItemInfo::Option; | 203 popupItem.type = WebMenuItemInfo::Option; |
| 197 popupItem.enabled = m_popupMenuClient->itemIsEnabled(i); | 204 popupItem.enabled = m_popupMenuClient->itemIsEnabled(i); |
| 198 popupItem.checked = m_popupMenuClient->itemIsSelected(i); | 205 popupItem.checked = m_popupMenuClient->itemIsSelected(i); |
| 199 PopupMenuStyle style = m_popupMenuClient->itemStyle(i); | |
| 200 if (style.textDirection() == blink::RTL) | 206 if (style.textDirection() == blink::RTL) |
| 201 popupItem.textDirection = WebTextDirectionRightToLeft; | 207 popupItem.textDirection = WebTextDirectionRightToLeft; |
| 202 else | 208 else |
| 203 popupItem.textDirection = WebTextDirectionLeftToRight; | 209 popupItem.textDirection = WebTextDirectionLeftToRight; |
| 204 popupItem.hasTextDirectionOverride = style.hasTextDirectionOverride(); | 210 popupItem.hasTextDirectionOverride = style.hasTextDirectionOverride(); |
| 205 } | 211 } |
| 206 | 212 |
| 207 info->itemHeight = m_popupMenuClient->menuStyle().font().fontMetrics().heigh t(); | 213 info->itemHeight = m_popupMenuClient->menuStyle().font().fontMetrics().heigh t(); |
| 208 info->itemFontSize = static_cast<int>(m_popupMenuClient->menuStyle().font(). fontDescription().computedSize()); | 214 info->itemFontSize = static_cast<int>(m_popupMenuClient->menuStyle().font(). fontDescription().computedSize()); |
| 209 info->selectedIndex = m_popupMenuClient->selectedIndex(); | 215 info->selectedIndex = toExternalPopupMenuItemIndex(m_popupMenuClient->select edIndex()); |
| 210 info->rightAligned = m_popupMenuClient->menuStyle().textDirection() == blink ::RTL; | 216 info->rightAligned = m_popupMenuClient->menuStyle().textDirection() == blink ::RTL; |
| 211 info->allowMultipleSelection = m_popupMenuClient->multiple(); | 217 info->allowMultipleSelection = m_popupMenuClient->multiple(); |
| 218 if (m_itemCount < itemCount) | |
| 219 items.shrink(m_itemCount); | |
| 212 info->items.swap(items); | 220 info->items.swap(items); |
| 213 } | 221 } |
| 214 | 222 |
| 223 int ExternalPopupMenu::toPopupMenuItemIndex(int externalPopupMenuItemIndex) | |
| 224 { | |
| 225 ASSERT(m_popupMenuClient); | |
| 226 int itemCount = m_popupMenuClient->listSize(); | |
| 227 if (itemCount == m_itemCount || externalPopupMenuItemIndex < 0) | |
|
keishi
2014/08/06 03:00:20
I get what you're trying to do with itemCount == m
spartha
2014/08/06 08:13:31
Done.
| |
| 228 return externalPopupMenuItemIndex; | |
| 229 | |
| 230 int indexTracker = 0; | |
| 231 for (int i = 0; i < itemCount ; ++i) { | |
| 232 if (m_popupMenuClient->itemStyle(i).isDisplayNone()) | |
| 233 continue; | |
| 234 if (indexTracker++ == externalPopupMenuItemIndex) | |
| 235 return i; | |
| 236 } | |
| 237 return -1; | |
| 215 } | 238 } |
| 239 | |
| 240 int ExternalPopupMenu::toExternalPopupMenuItemIndex(int popupMenuItemIndex) | |
| 241 { | |
| 242 ASSERT(m_popupMenuClient); | |
| 243 int itemCount = m_popupMenuClient->listSize(); | |
| 244 if (itemCount == m_itemCount || popupMenuItemIndex < 0) | |
| 245 return popupMenuItemIndex; | |
| 246 | |
| 247 int indexTracker = 0; | |
| 248 for (int i = 0; i < itemCount; ++i) { | |
| 249 if (m_popupMenuClient->itemStyle(i).isDisplayNone()) | |
| 250 continue; | |
| 251 if (popupMenuItemIndex == i) | |
| 252 return indexTracker; | |
| 253 ++indexTracker; | |
| 254 } | |
| 255 return -1; | |
| 256 } | |
| 257 | |
| 258 } | |
| OLD | NEW |