Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(15)

Side by Side Diff: Source/web/ExternalPopupMenu.cpp

Issue 415343003: Option Groups with display: none should not show the children option elements (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fixed assert failure in linux dbg build Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/web/ExternalPopupMenu.h ('k') | Source/web/PopupListBox.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(index); 129 m_popupMenuClient->selectionChanged(toPopupMenuItemIndex(index));
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 RefPtr<ExternalPopupMenu> guard(this); 138 RefPtr<ExternalPopupMenu> guard(this);
138 139
139 if (m_popupMenuClient) { 140 if (m_popupMenuClient) {
140 m_popupMenuClient->popupDidHide(); 141 m_popupMenuClient->popupDidHide();
141 m_popupMenuClient->valueChanged(index); 142 m_popupMenuClient->valueChanged(popupMenuItemIndex);
142 } 143 }
143 m_webExternalPopupMenu = 0; 144 m_webExternalPopupMenu = 0;
144 } 145 }
145 146
146 void ExternalPopupMenu::didAcceptIndices(const WebVector<int>& indices) 147 void ExternalPopupMenu::didAcceptIndices(const WebVector<int>& indices)
147 { 148 {
148 if (!m_popupMenuClient) { 149 if (!m_popupMenuClient) {
149 m_webExternalPopupMenu = 0; 150 m_webExternalPopupMenu = 0;
150 return; 151 return;
151 } 152 }
152 153
153 // Calling methods on the PopupMenuClient might lead to this object being 154 // 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 155 // derefed. This ensures it does not get deleted while we are running this
155 // method. 156 // method.
156 RefPtr<ExternalPopupMenu> protect(this); 157 RefPtr<ExternalPopupMenu> protect(this);
157 158
158 if (!indices.size()) 159 if (!indices.size())
159 m_popupMenuClient->valueChanged(static_cast<unsigned>(-1), true); 160 m_popupMenuClient->valueChanged(static_cast<unsigned>(-1), true);
160 else { 161 else {
161 for (size_t i = 0; i < indices.size(); ++i) 162 for (size_t i = 0; i < indices.size(); ++i)
162 m_popupMenuClient->listBoxSelectItem(indices[i], (i > 0), false, (i == indices.size() - 1)); 163 m_popupMenuClient->listBoxSelectItem(toPopupMenuItemIndex(indices[i] ), (i > 0), false, (i == indices.size() - 1));
163 } 164 }
164 165
165 // 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
166 // disconnectClient, so we might not have a PopupMenuClient anymore. 167 // disconnectClient, so we might not have a PopupMenuClient anymore.
167 if (m_popupMenuClient) 168 if (m_popupMenuClient)
168 m_popupMenuClient->popupDidHide(); 169 m_popupMenuClient->popupDidHide();
169 170
170 m_webExternalPopupMenu = 0; 171 m_webExternalPopupMenu = 0;
171 } 172 }
172 173
173 void ExternalPopupMenu::didCancel() 174 void ExternalPopupMenu::didCancel()
174 { 175 {
175 // See comment in didAcceptIndex on why we need this. 176 // See comment in didAcceptIndex on why we need this.
176 RefPtr<ExternalPopupMenu> guard(this); 177 RefPtr<ExternalPopupMenu> guard(this);
177 178
178 if (m_popupMenuClient) 179 if (m_popupMenuClient)
179 m_popupMenuClient->popupDidHide(); 180 m_popupMenuClient->popupDidHide();
180 m_webExternalPopupMenu = 0; 181 m_webExternalPopupMenu = 0;
181 } 182 }
182 183
183 void ExternalPopupMenu::getPopupMenuInfo(WebPopupMenuInfo* info) 184 void ExternalPopupMenu::getPopupMenuInfo(WebPopupMenuInfo* info)
184 { 185 {
185 int itemCount = m_popupMenuClient->listSize(); 186 int itemCount = m_popupMenuClient->listSize();
186 WebVector<WebMenuItemInfo> items(static_cast<size_t>(itemCount)); 187 int count = 0;
188 Vector<WebMenuItemInfo> items(static_cast<size_t>(itemCount));
187 for (int i = 0; i < itemCount; ++i) { 189 for (int i = 0; i < itemCount; ++i) {
188 WebMenuItemInfo& popupItem = items[i]; 190 PopupMenuStyle style = m_popupMenuClient->itemStyle(i);
191 if (style.isDisplayNone())
192 continue;
193
194 WebMenuItemInfo& popupItem = items[count++];
189 popupItem.label = m_popupMenuClient->itemText(i); 195 popupItem.label = m_popupMenuClient->itemText(i);
190 popupItem.toolTip = m_popupMenuClient->itemToolTip(i); 196 popupItem.toolTip = m_popupMenuClient->itemToolTip(i);
191 if (m_popupMenuClient->itemIsSeparator(i)) 197 if (m_popupMenuClient->itemIsSeparator(i))
192 popupItem.type = WebMenuItemInfo::Separator; 198 popupItem.type = WebMenuItemInfo::Separator;
193 else if (m_popupMenuClient->itemIsLabel(i)) 199 else if (m_popupMenuClient->itemIsLabel(i))
194 popupItem.type = WebMenuItemInfo::Group; 200 popupItem.type = WebMenuItemInfo::Group;
195 else 201 else
196 popupItem.type = WebMenuItemInfo::Option; 202 popupItem.type = WebMenuItemInfo::Option;
197 popupItem.enabled = m_popupMenuClient->itemIsEnabled(i); 203 popupItem.enabled = m_popupMenuClient->itemIsEnabled(i);
198 popupItem.checked = m_popupMenuClient->itemIsSelected(i); 204 popupItem.checked = m_popupMenuClient->itemIsSelected(i);
199 PopupMenuStyle style = m_popupMenuClient->itemStyle(i);
200 if (style.textDirection() == blink::RTL) 205 if (style.textDirection() == blink::RTL)
201 popupItem.textDirection = WebTextDirectionRightToLeft; 206 popupItem.textDirection = WebTextDirectionRightToLeft;
202 else 207 else
203 popupItem.textDirection = WebTextDirectionLeftToRight; 208 popupItem.textDirection = WebTextDirectionLeftToRight;
204 popupItem.hasTextDirectionOverride = style.hasTextDirectionOverride(); 209 popupItem.hasTextDirectionOverride = style.hasTextDirectionOverride();
205 } 210 }
206 211
207 info->itemHeight = m_popupMenuClient->menuStyle().font().fontMetrics().heigh t(); 212 info->itemHeight = m_popupMenuClient->menuStyle().font().fontMetrics().heigh t();
208 info->itemFontSize = static_cast<int>(m_popupMenuClient->menuStyle().font(). fontDescription().computedSize()); 213 info->itemFontSize = static_cast<int>(m_popupMenuClient->menuStyle().font(). fontDescription().computedSize());
209 info->selectedIndex = m_popupMenuClient->selectedIndex(); 214 info->selectedIndex = toExternalPopupMenuItemIndex(m_popupMenuClient->select edIndex());
210 info->rightAligned = m_popupMenuClient->menuStyle().textDirection() == blink ::RTL; 215 info->rightAligned = m_popupMenuClient->menuStyle().textDirection() == blink ::RTL;
211 info->allowMultipleSelection = m_popupMenuClient->multiple(); 216 info->allowMultipleSelection = m_popupMenuClient->multiple();
212 info->items.swap(items); 217 info->items = items;
218 }
219
220 int ExternalPopupMenu::toPopupMenuItemIndex(int externalPopupMenuItemIndex)
221 {
222 ASSERT(m_popupMenuClient);
223 if (externalPopupMenuItemIndex < 0)
224 return externalPopupMenuItemIndex;
225
226 int itemCount = m_popupMenuClient->listSize();
227 int indexTracker = 0;
228 for (int i = 0; i < itemCount ; ++i) {
229 if (m_popupMenuClient->itemStyle(i).isDisplayNone())
230 continue;
231 if (indexTracker++ == externalPopupMenuItemIndex)
232 return i;
233 }
234 return -1;
235 }
236
237 int ExternalPopupMenu::toExternalPopupMenuItemIndex(int popupMenuItemIndex)
238 {
239 ASSERT(m_popupMenuClient);
240 if (popupMenuItemIndex < 0)
241 return popupMenuItemIndex;
242
243 int itemCount = m_popupMenuClient->listSize();
244 int indexTracker = 0;
245 for (int i = 0; i < itemCount; ++i) {
246 if (m_popupMenuClient->itemStyle(i).isDisplayNone())
247 continue;
248 if (popupMenuItemIndex == i)
249 return indexTracker;
250 ++indexTracker;
251 }
252 return -1;
213 } 253 }
214 254
215 } 255 }
OLDNEW
« no previous file with comments | « Source/web/ExternalPopupMenu.h ('k') | Source/web/PopupListBox.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698