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

Side by Side Diff: third_party/WebKit/Source/web/PopupMenuImpl.cpp

Issue 1839643009: RELEASE_ASSERT -> CHECK and ASSERT -> DCHECK in web. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Return DCHECK_IS_ON checks. Created 4 years, 8 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
OLDNEW
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "web/PopupMenuImpl.h" 5 #include "web/PopupMenuImpl.h"
6 6
7 #include "core/HTMLNames.h" 7 #include "core/HTMLNames.h"
8 #include "core/css/CSSFontSelector.h" 8 #include "core/css/CSSFontSelector.h"
9 #include "core/dom/ElementTraversal.h" 9 #include "core/dom/ElementTraversal.h"
10 #include "core/dom/ExecutionContextTask.h" 10 #include "core/dom/ExecutionContextTask.h"
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 class PopupMenuImpl::ItemIterationContext { 162 class PopupMenuImpl::ItemIterationContext {
163 STACK_ALLOCATED(); 163 STACK_ALLOCATED();
164 public: 164 public:
165 ItemIterationContext(const ComputedStyle& style, SharedBuffer* buffer) 165 ItemIterationContext(const ComputedStyle& style, SharedBuffer* buffer)
166 : m_baseStyle(style) 166 : m_baseStyle(style)
167 , m_backgroundColor(style.visitedDependentColor(CSSPropertyBackgroundCol or)) 167 , m_backgroundColor(style.visitedDependentColor(CSSPropertyBackgroundCol or))
168 , m_listIndex(0) 168 , m_listIndex(0)
169 , m_isInGroup(false) 169 , m_isInGroup(false)
170 , m_buffer(buffer) 170 , m_buffer(buffer)
171 { 171 {
172 ASSERT(m_buffer); 172 DCHECK(m_buffer);
173 #if OS(LINUX) 173 #if OS(LINUX)
174 // On other platforms, the <option> background color is the same as the 174 // On other platforms, the <option> background color is the same as the
175 // <select> background color. On Linux, that makes the <option> 175 // <select> background color. On Linux, that makes the <option>
176 // background color very dark, so by default, try to use a lighter 176 // background color very dark, so by default, try to use a lighter
177 // background color for <option>s. 177 // background color for <option>s.
178 if (LayoutTheme::theme().systemColor(CSSValueButtonface) == m_background Color) 178 if (LayoutTheme::theme().systemColor(CSSValueButtonface) == m_background Color)
179 m_backgroundColor = LayoutTheme::theme().systemColor(CSSValueMenu); 179 m_backgroundColor = LayoutTheme::theme().systemColor(CSSValueMenu);
180 #endif 180 #endif
181 } 181 }
182 182
183 void serializeBaseStyle() 183 void serializeBaseStyle()
184 { 184 {
185 ASSERT(!m_isInGroup); 185 DCHECK(!m_isInGroup);
186 PagePopupClient::addString("baseStyle: {", m_buffer); 186 PagePopupClient::addString("baseStyle: {", m_buffer);
187 addProperty("backgroundColor", m_backgroundColor.serialized(), m_buffer) ; 187 addProperty("backgroundColor", m_backgroundColor.serialized(), m_buffer) ;
188 addProperty("color", baseStyle().visitedDependentColor(CSSPropertyColor) .serialized(), m_buffer); 188 addProperty("color", baseStyle().visitedDependentColor(CSSPropertyColor) .serialized(), m_buffer);
189 addProperty("textTransform", String(textTransformToString(baseStyle().te xtTransform())), m_buffer); 189 addProperty("textTransform", String(textTransformToString(baseStyle().te xtTransform())), m_buffer);
190 addProperty("fontSize", baseFont().specifiedSize(), m_buffer); 190 addProperty("fontSize", baseFont().specifiedSize(), m_buffer);
191 addProperty("fontStyle", String(fontStyleToString(baseFont().style())), m_buffer); 191 addProperty("fontStyle", String(fontStyleToString(baseFont().style())), m_buffer);
192 addProperty("fontVariant", String(fontVariantToString(baseFont().variant ())), m_buffer); 192 addProperty("fontVariant", String(fontVariantToString(baseFont().variant ())), m_buffer);
193 193
194 PagePopupClient::addString("fontFamily: [", m_buffer); 194 PagePopupClient::addString("fontFamily: [", m_buffer);
195 for (const FontFamily* f = &baseFont().family(); f; f = f->next()) { 195 for (const FontFamily* f = &baseFont().family(); f; f = f->next()) {
196 addJavaScriptString(f->family().getString(), m_buffer); 196 addJavaScriptString(f->family().getString(), m_buffer);
197 if (f->next()) 197 if (f->next())
198 PagePopupClient::addString(",", m_buffer); 198 PagePopupClient::addString(",", m_buffer);
199 } 199 }
200 PagePopupClient::addString("]", m_buffer); 200 PagePopupClient::addString("]", m_buffer);
201 PagePopupClient::addString("},\n", m_buffer); 201 PagePopupClient::addString("},\n", m_buffer);
202 } 202 }
203 203
204 Color backgroundColor() const { return m_isInGroup ? m_groupStyle->visitedDe pendentColor(CSSPropertyBackgroundColor) : m_backgroundColor; } 204 Color backgroundColor() const { return m_isInGroup ? m_groupStyle->visitedDe pendentColor(CSSPropertyBackgroundColor) : m_backgroundColor; }
205 // Do not use baseStyle() for background-color, use backgroundColor() 205 // Do not use baseStyle() for background-color, use backgroundColor()
206 // instead. 206 // instead.
207 const ComputedStyle& baseStyle() { return m_isInGroup ? *m_groupStyle : m_ba seStyle; } 207 const ComputedStyle& baseStyle() { return m_isInGroup ? *m_groupStyle : m_ba seStyle; }
208 const FontDescription& baseFont() { return m_isInGroup ? m_groupStyle->getFo ntDescription() : m_baseStyle.getFontDescription(); } 208 const FontDescription& baseFont() { return m_isInGroup ? m_groupStyle->getFo ntDescription() : m_baseStyle.getFontDescription(); }
209 void startGroupChildren(const ComputedStyle& groupStyle) 209 void startGroupChildren(const ComputedStyle& groupStyle)
210 { 210 {
211 ASSERT(!m_isInGroup); 211 DCHECK(!m_isInGroup);
212 PagePopupClient::addString("children: [", m_buffer); 212 PagePopupClient::addString("children: [", m_buffer);
213 m_isInGroup = true; 213 m_isInGroup = true;
214 m_groupStyle = &groupStyle; 214 m_groupStyle = &groupStyle;
215 } 215 }
216 void finishGroupIfNecessary() 216 void finishGroupIfNecessary()
217 { 217 {
218 if (!m_isInGroup) 218 if (!m_isInGroup)
219 return; 219 return;
220 PagePopupClient::addString("],},\n", m_buffer); 220 PagePopupClient::addString("],},\n", m_buffer);
221 m_isInGroup = false; 221 m_isInGroup = false;
(...skipping 19 matching lines...) Expand all
241 PopupMenuImpl::PopupMenuImpl(ChromeClientImpl* chromeClient, HTMLSelectElement& ownerElement) 241 PopupMenuImpl::PopupMenuImpl(ChromeClientImpl* chromeClient, HTMLSelectElement& ownerElement)
242 : m_chromeClient(chromeClient) 242 : m_chromeClient(chromeClient)
243 , m_ownerElement(ownerElement) 243 , m_ownerElement(ownerElement)
244 , m_popup(nullptr) 244 , m_popup(nullptr)
245 , m_needsUpdate(false) 245 , m_needsUpdate(false)
246 { 246 {
247 } 247 }
248 248
249 PopupMenuImpl::~PopupMenuImpl() 249 PopupMenuImpl::~PopupMenuImpl()
250 { 250 {
251 ASSERT(!m_popup); 251 DCHECK(!m_popup);
252 } 252 }
253 253
254 DEFINE_TRACE(PopupMenuImpl) 254 DEFINE_TRACE(PopupMenuImpl)
255 { 255 {
256 visitor->trace(m_chromeClient); 256 visitor->trace(m_chromeClient);
257 visitor->trace(m_ownerElement); 257 visitor->trace(m_ownerElement);
258 PopupMenu::trace(visitor); 258 PopupMenu::trace(visitor);
259 } 259 }
260 260
261 void PopupMenuImpl::writeDocument(SharedBuffer* data) 261 void PopupMenuImpl::writeDocument(SharedBuffer* data)
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 addProperty("paddingStart", isRTL ? ownerElement.clientPaddingRight().toDoub le() / zoom : ownerElement.clientPaddingLeft().toDouble() / zoom, data); 297 addProperty("paddingStart", isRTL ? ownerElement.clientPaddingRight().toDoub le() / zoom : ownerElement.clientPaddingLeft().toDouble() / zoom, data);
298 PagePopupClient::addString("};\n", data); 298 PagePopupClient::addString("};\n", data);
299 data->append(Platform::current()->loadResource("pickerCommon.js")); 299 data->append(Platform::current()->loadResource("pickerCommon.js"));
300 data->append(Platform::current()->loadResource("listPicker.js")); 300 data->append(Platform::current()->loadResource("listPicker.js"));
301 PagePopupClient::addString("</script></body>\n", data); 301 PagePopupClient::addString("</script></body>\n", data);
302 } 302 }
303 303
304 void PopupMenuImpl::addElementStyle(ItemIterationContext& context, HTMLElement& element) 304 void PopupMenuImpl::addElementStyle(ItemIterationContext& context, HTMLElement& element)
305 { 305 {
306 const ComputedStyle* style = m_ownerElement->itemComputedStyle(element); 306 const ComputedStyle* style = m_ownerElement->itemComputedStyle(element);
307 ASSERT(style); 307 DCHECK(style);
308 SharedBuffer* data = context.m_buffer; 308 SharedBuffer* data = context.m_buffer;
309 // TODO(tkent): We generate unnecessary "style: {\n},\n" even if no 309 // TODO(tkent): We generate unnecessary "style: {\n},\n" even if no
310 // additional style. 310 // additional style.
311 PagePopupClient::addString("style: {\n", data); 311 PagePopupClient::addString("style: {\n", data);
312 if (style->visibility() == HIDDEN) 312 if (style->visibility() == HIDDEN)
313 addProperty("visibility", String("hidden"), data); 313 addProperty("visibility", String("hidden"), data);
314 if (style->display() == NONE) 314 if (style->display() == NONE)
315 addProperty("display", String("none"), data); 315 addProperty("display", String("none"), data);
316 const ComputedStyle& baseStyle = context.baseStyle(); 316 const ComputedStyle& baseStyle = context.baseStyle();
317 if (baseStyle.direction() != style->direction()) 317 if (baseStyle.direction() != style->direction())
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 } 397 }
398 398
399 void PopupMenuImpl::selectFontsFromOwnerDocument(Document& document) 399 void PopupMenuImpl::selectFontsFromOwnerDocument(Document& document)
400 { 400 {
401 Document& ownerDocument = ownerElement().document(); 401 Document& ownerDocument = ownerElement().document();
402 document.styleEngine().setFontSelector(PopupMenuCSSFontSelector::create(&doc ument, ownerDocument.styleEngine().fontSelector())); 402 document.styleEngine().setFontSelector(PopupMenuCSSFontSelector::create(&doc ument, ownerDocument.styleEngine().fontSelector()));
403 } 403 }
404 404
405 void PopupMenuImpl::setValueAndClosePopup(int numValue, const String& stringValu e) 405 void PopupMenuImpl::setValueAndClosePopup(int numValue, const String& stringValu e)
406 { 406 {
407 ASSERT(m_popup); 407 DCHECK(m_popup);
408 ASSERT(m_ownerElement); 408 DCHECK(m_ownerElement);
409 RawPtr<PopupMenuImpl> protector(this); 409 RawPtr<PopupMenuImpl> protector(this);
410 bool success; 410 bool success;
411 int listIndex = stringValue.toInt(&success); 411 int listIndex = stringValue.toInt(&success);
412 ASSERT(success); 412 DCHECK(success);
413 { 413 {
414 EventQueueScope scope; 414 EventQueueScope scope;
415 m_ownerElement->valueChanged(listIndex); 415 m_ownerElement->valueChanged(listIndex);
416 if (m_popup) 416 if (m_popup)
417 m_chromeClient->closePagePopup(m_popup); 417 m_chromeClient->closePagePopup(m_popup);
418 // 'change' event is dispatched here. For compatbility with 418 // 'change' event is dispatched here. For compatbility with
419 // Angular 1.2, we need to dispatch a change event before 419 // Angular 1.2, we need to dispatch a change event before
420 // mouseup/click events. 420 // mouseup/click events.
421 } 421 }
422 // We dispatch events on the owner element to match the legacy behavior. 422 // We dispatch events on the owner element to match the legacy behavior.
423 // Other browsers dispatch click events before and after showing the popup. 423 // Other browsers dispatch click events before and after showing the popup.
424 if (m_ownerElement) { 424 if (m_ownerElement) {
425 PlatformMouseEvent event; 425 PlatformMouseEvent event;
426 RawPtr<Element> owner = &ownerElement(); 426 RawPtr<Element> owner = &ownerElement();
427 owner->dispatchMouseEvent(event, EventTypeNames::mouseup); 427 owner->dispatchMouseEvent(event, EventTypeNames::mouseup);
428 owner->dispatchMouseEvent(event, EventTypeNames::click); 428 owner->dispatchMouseEvent(event, EventTypeNames::click);
429 } 429 }
430 } 430 }
431 431
432 void PopupMenuImpl::setValue(const String& value) 432 void PopupMenuImpl::setValue(const String& value)
433 { 433 {
434 ASSERT(m_ownerElement); 434 DCHECK(m_ownerElement);
435 bool success; 435 bool success;
436 int listIndex = value.toInt(&success); 436 int listIndex = value.toInt(&success);
437 ASSERT(success); 437 DCHECK(success);
438 m_ownerElement->provisionalSelectionChanged(listIndex); 438 m_ownerElement->provisionalSelectionChanged(listIndex);
439 } 439 }
440 440
441 void PopupMenuImpl::didClosePopup() 441 void PopupMenuImpl::didClosePopup()
442 { 442 {
443 // Clearing m_popup first to prevent from trying to close the popup again. 443 // Clearing m_popup first to prevent from trying to close the popup again.
444 m_popup = nullptr; 444 m_popup = nullptr;
445 RawPtr<PopupMenuImpl> protector(this); 445 RawPtr<PopupMenuImpl> protector(this);
446 if (m_ownerElement) 446 if (m_ownerElement)
447 m_ownerElement->popupDidHide(); 447 m_ownerElement->popupDidHide();
(...skipping 18 matching lines...) Expand all
466 } 466 }
467 467
468 void PopupMenuImpl::dispose() 468 void PopupMenuImpl::dispose()
469 { 469 {
470 if (m_popup) 470 if (m_popup)
471 m_chromeClient->closePagePopup(m_popup); 471 m_chromeClient->closePagePopup(m_popup);
472 } 472 }
473 473
474 void PopupMenuImpl::show() 474 void PopupMenuImpl::show()
475 { 475 {
476 ASSERT(!m_popup); 476 DCHECK(!m_popup);
477 m_popup = m_chromeClient->openPagePopup(this); 477 m_popup = m_chromeClient->openPagePopup(this);
478 } 478 }
479 479
480 void PopupMenuImpl::hide() 480 void PopupMenuImpl::hide()
481 { 481 {
482 if (m_popup) 482 if (m_popup)
483 m_chromeClient->closePagePopup(m_popup); 483 m_chromeClient->closePagePopup(m_popup);
484 } 484 }
485 485
486 void PopupMenuImpl::updateFromElement() 486 void PopupMenuImpl::updateFromElement()
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 535
536 void PopupMenuImpl::disconnectClient() 536 void PopupMenuImpl::disconnectClient()
537 { 537 {
538 m_ownerElement = nullptr; 538 m_ownerElement = nullptr;
539 // Cannot be done during finalization, so instead done when the 539 // Cannot be done during finalization, so instead done when the
540 // layout object is destroyed and disconnected. 540 // layout object is destroyed and disconnected.
541 dispose(); 541 dispose();
542 } 542 }
543 543
544 } // namespace blink 544 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/web/PageOverlay.cpp ('k') | third_party/WebKit/Source/web/RemoteFrameOwner.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698