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

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

Issue 1686483002: Oilpan: Remove most WillBe types from the code base (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 case TTNONE: 96 case TTNONE:
97 return "none"; 97 return "none";
98 } 98 }
99 ASSERT_NOT_REACHED(); 99 ASSERT_NOT_REACHED();
100 return ""; 100 return "";
101 } 101 }
102 102
103 } // anonymous namespace 103 } // anonymous namespace
104 104
105 class PopupMenuCSSFontSelector : public CSSFontSelector, private CSSFontSelector Client { 105 class PopupMenuCSSFontSelector : public CSSFontSelector, private CSSFontSelector Client {
106 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(PopupMenuCSSFontSelector); 106 USING_GARBAGE_COLLECTED_MIXIN(PopupMenuCSSFontSelector);
107 public: 107 public:
108 static PassRefPtrWillBeRawPtr<PopupMenuCSSFontSelector> create(Document* doc ument, CSSFontSelector* ownerFontSelector) 108 static RawPtr<PopupMenuCSSFontSelector> create(Document* document, CSSFontSe lector* ownerFontSelector)
109 { 109 {
110 return adoptRefWillBeNoop(new PopupMenuCSSFontSelector(document, ownerFo ntSelector)); 110 return (new PopupMenuCSSFontSelector(document, ownerFontSelector));
111 } 111 }
112 112
113 ~PopupMenuCSSFontSelector(); 113 ~PopupMenuCSSFontSelector();
114 114
115 // We don't override willUseFontData() for now because the old PopupListBox 115 // We don't override willUseFontData() for now because the old PopupListBox
116 // only worked with fonts loaded when opening the popup. 116 // only worked with fonts loaded when opening the popup.
117 PassRefPtr<FontData> getFontData(const FontDescription&, const AtomicString& ) override; 117 PassRefPtr<FontData> getFontData(const FontDescription&, const AtomicString& ) override;
118 118
119 DECLARE_VIRTUAL_TRACE(); 119 DECLARE_VIRTUAL_TRACE();
120 120
121 private: 121 private:
122 PopupMenuCSSFontSelector(Document*, CSSFontSelector*); 122 PopupMenuCSSFontSelector(Document*, CSSFontSelector*);
123 123
124 void fontsNeedUpdate(CSSFontSelector*) override; 124 void fontsNeedUpdate(CSSFontSelector*) override;
125 125
126 RefPtrWillBeMember<CSSFontSelector> m_ownerFontSelector; 126 Member<CSSFontSelector> m_ownerFontSelector;
127 }; 127 };
128 128
129 PopupMenuCSSFontSelector::PopupMenuCSSFontSelector(Document* document, CSSFontSe lector* ownerFontSelector) 129 PopupMenuCSSFontSelector::PopupMenuCSSFontSelector(Document* document, CSSFontSe lector* ownerFontSelector)
130 : CSSFontSelector(document) 130 : CSSFontSelector(document)
131 , m_ownerFontSelector(ownerFontSelector) 131 , m_ownerFontSelector(ownerFontSelector)
132 { 132 {
133 m_ownerFontSelector->registerForInvalidationCallbacks(this); 133 m_ownerFontSelector->registerForInvalidationCallbacks(this);
134 } 134 }
135 135
136 PopupMenuCSSFontSelector::~PopupMenuCSSFontSelector() 136 PopupMenuCSSFontSelector::~PopupMenuCSSFontSelector()
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 Color m_backgroundColor; 226 Color m_backgroundColor;
227 const ComputedStyle* m_groupStyle; 227 const ComputedStyle* m_groupStyle;
228 228
229 unsigned m_listIndex; 229 unsigned m_listIndex;
230 bool m_isInGroup; 230 bool m_isInGroup;
231 SharedBuffer* m_buffer; 231 SharedBuffer* m_buffer;
232 }; 232 };
233 233
234 // ---------------------------------------------------------------- 234 // ----------------------------------------------------------------
235 235
236 PassRefPtrWillBeRawPtr<PopupMenuImpl> PopupMenuImpl::create(ChromeClientImpl* ch romeClient, HTMLSelectElement& ownerElement) 236 RawPtr<PopupMenuImpl> PopupMenuImpl::create(ChromeClientImpl* chromeClient, HTML SelectElement& ownerElement)
237 { 237 {
238 return adoptRefWillBeNoop(new PopupMenuImpl(chromeClient, ownerElement)); 238 return (new PopupMenuImpl(chromeClient, ownerElement));
239 } 239 }
240 240
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
(...skipping 17 matching lines...) Expand all
266 PagePopupClient::addString("<!DOCTYPE html><head><meta charset='UTF-8'><styl e>\n", data); 266 PagePopupClient::addString("<!DOCTYPE html><head><meta charset='UTF-8'><styl e>\n", data);
267 data->append(Platform::current()->loadResource("pickerCommon.css")); 267 data->append(Platform::current()->loadResource("pickerCommon.css"));
268 data->append(Platform::current()->loadResource("listPicker.css")); 268 data->append(Platform::current()->loadResource("listPicker.css"));
269 PagePopupClient::addString("</style></head><body><div id=main>Loading...</di v><script>\n" 269 PagePopupClient::addString("</style></head><body><div id=main>Loading...</di v><script>\n"
270 "window.dialogArguments = {\n", data); 270 "window.dialogArguments = {\n", data);
271 addProperty("selectedIndex", ownerElement.optionToListIndex(ownerElement.sel ectedIndex()), data); 271 addProperty("selectedIndex", ownerElement.optionToListIndex(ownerElement.sel ectedIndex()), data);
272 const ComputedStyle* ownerStyle = ownerElement.computedStyle(); 272 const ComputedStyle* ownerStyle = ownerElement.computedStyle();
273 ItemIterationContext context(*ownerStyle, data); 273 ItemIterationContext context(*ownerStyle, data);
274 context.serializeBaseStyle(); 274 context.serializeBaseStyle();
275 PagePopupClient::addString("children: [\n", data); 275 PagePopupClient::addString("children: [\n", data);
276 const WillBeHeapVector<RawPtrWillBeMember<HTMLElement>>& items = ownerElemen t.listItems(); 276 const HeapVector<Member<HTMLElement>>& items = ownerElement.listItems();
277 for (; context.m_listIndex < items.size(); ++context.m_listIndex) { 277 for (; context.m_listIndex < items.size(); ++context.m_listIndex) {
278 Element& child = *items[context.m_listIndex]; 278 Element& child = *items[context.m_listIndex];
279 if (!isHTMLOptGroupElement(child.parentNode())) 279 if (!isHTMLOptGroupElement(child.parentNode()))
280 context.finishGroupIfNecessary(); 280 context.finishGroupIfNecessary();
281 if (isHTMLOptionElement(child)) 281 if (isHTMLOptionElement(child))
282 addOption(context, toHTMLOptionElement(child)); 282 addOption(context, toHTMLOptionElement(child));
283 else if (isHTMLOptGroupElement(child)) 283 else if (isHTMLOptGroupElement(child))
284 addOptGroup(context, toHTMLOptGroupElement(child)); 284 addOptGroup(context, toHTMLOptGroupElement(child));
285 else if (isHTMLHRElement(child)) 285 else if (isHTMLHRElement(child))
286 addSeparator(context, toHTMLHRElement(child)); 286 addSeparator(context, toHTMLHRElement(child));
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 ASSERT(m_popup);
408 ASSERT(m_ownerElement); 408 ASSERT(m_ownerElement);
409 RefPtrWillBeRawPtr<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 ASSERT(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 RefPtrWillBeRawPtr<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 ASSERT(m_ownerElement);
435 bool success; 435 bool success;
436 int listIndex = value.toInt(&success); 436 int listIndex = value.toInt(&success);
437 ASSERT(success); 437 ASSERT(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 RefPtrWillBeRawPtr<PopupMenuImpl> protector(this); 445 RawPtr<PopupMenuImpl> protector(this);
446 if (m_ownerElement) 446 if (m_ownerElement)
447 m_ownerElement->popupDidHide(); 447 m_ownerElement->popupDidHide();
448 } 448 }
449 449
450 Element& PopupMenuImpl::ownerElement() 450 Element& PopupMenuImpl::ownerElement()
451 { 451 {
452 return *m_ownerElement; 452 return *m_ownerElement;
453 } 453 }
454 454
455 Locale& PopupMenuImpl::locale() 455 Locale& PopupMenuImpl::locale()
(...skipping 25 matching lines...) Expand all
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()
487 { 487 {
488 if (m_needsUpdate) 488 if (m_needsUpdate)
489 return; 489 return;
490 m_needsUpdate = true; 490 m_needsUpdate = true;
491 ownerElement().document().postTask(BLINK_FROM_HERE, createSameThreadTask(&Po pupMenuImpl::update, PassRefPtrWillBeRawPtr<PopupMenuImpl>(this))); 491 ownerElement().document().postTask(BLINK_FROM_HERE, createSameThreadTask(&Po pupMenuImpl::update, RawPtr<PopupMenuImpl>(this)));
492 } 492 }
493 493
494 void PopupMenuImpl::update() 494 void PopupMenuImpl::update()
495 { 495 {
496 if (!m_popup || !m_ownerElement) 496 if (!m_popup || !m_ownerElement)
497 return; 497 return;
498 ownerElement().document().updateLayoutTreeIfNeeded(); 498 ownerElement().document().updateLayoutTreeIfNeeded();
499 // disconnectClient() might have been called. 499 // disconnectClient() might have been called.
500 if (!m_ownerElement) 500 if (!m_ownerElement)
501 return; 501 return;
502 m_needsUpdate = false; 502 m_needsUpdate = false;
503 503
504 if (!ownerElement().document().frame()->view()->visibleContentRect().interse cts(ownerElement().pixelSnappedBoundingBox())) { 504 if (!ownerElement().document().frame()->view()->visibleContentRect().interse cts(ownerElement().pixelSnappedBoundingBox())) {
505 hide(); 505 hide();
506 return; 506 return;
507 } 507 }
508 508
509 RefPtr<SharedBuffer> data = SharedBuffer::create(); 509 RefPtr<SharedBuffer> data = SharedBuffer::create();
510 PagePopupClient::addString("window.updateData = {\n", data.get()); 510 PagePopupClient::addString("window.updateData = {\n", data.get());
511 PagePopupClient::addString("type: \"update\",\n", data.get()); 511 PagePopupClient::addString("type: \"update\",\n", data.get());
512 ItemIterationContext context(*m_ownerElement->computedStyle(), data.get()); 512 ItemIterationContext context(*m_ownerElement->computedStyle(), data.get());
513 context.serializeBaseStyle(); 513 context.serializeBaseStyle();
514 PagePopupClient::addString("children: [", data.get()); 514 PagePopupClient::addString("children: [", data.get());
515 const WillBeHeapVector<RawPtrWillBeMember<HTMLElement>>& items = m_ownerElem ent->listItems(); 515 const HeapVector<Member<HTMLElement>>& items = m_ownerElement->listItems();
516 for (; context.m_listIndex < items.size(); ++context.m_listIndex) { 516 for (; context.m_listIndex < items.size(); ++context.m_listIndex) {
517 Element& child = *items[context.m_listIndex]; 517 Element& child = *items[context.m_listIndex];
518 if (!isHTMLOptGroupElement(child.parentNode())) 518 if (!isHTMLOptGroupElement(child.parentNode()))
519 context.finishGroupIfNecessary(); 519 context.finishGroupIfNecessary();
520 if (isHTMLOptionElement(child)) 520 if (isHTMLOptionElement(child))
521 addOption(context, toHTMLOptionElement(child)); 521 addOption(context, toHTMLOptionElement(child));
522 else if (isHTMLOptGroupElement(child)) 522 else if (isHTMLOptGroupElement(child))
523 addOptGroup(context, toHTMLOptGroupElement(child)); 523 addOptGroup(context, toHTMLOptGroupElement(child));
524 else if (isHTMLHRElement(child)) 524 else if (isHTMLHRElement(child))
525 addSeparator(context, toHTMLHRElement(child)); 525 addSeparator(context, toHTMLHRElement(child));
526 } 526 }
527 context.finishGroupIfNecessary(); 527 context.finishGroupIfNecessary();
528 PagePopupClient::addString("],\n", data.get()); 528 PagePopupClient::addString("],\n", data.get());
529 IntRect anchorRectInScreen = m_chromeClient->viewportToScreen(m_ownerElement ->elementRectRelativeToViewport()); 529 IntRect anchorRectInScreen = m_chromeClient->viewportToScreen(m_ownerElement ->elementRectRelativeToViewport());
530 addProperty("anchorRectInScreen", anchorRectInScreen, data.get()); 530 addProperty("anchorRectInScreen", anchorRectInScreen, data.get());
531 PagePopupClient::addString("}\n", data.get()); 531 PagePopupClient::addString("}\n", data.get());
532 m_popup->postMessage(String::fromUTF8(data->data(), data->size())); 532 m_popup->postMessage(String::fromUTF8(data->data(), data->size()));
533 } 533 }
534 534
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

Powered by Google App Engine
This is Rietveld 408576698