OLD | NEW |
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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 USING_GARBAGE_COLLECTED_MIXIN(PopupMenuCSSFontSelector); | 106 USING_GARBAGE_COLLECTED_MIXIN(PopupMenuCSSFontSelector); |
107 public: | 107 public: |
108 static RawPtr<PopupMenuCSSFontSelector> create(Document* document, CSSFontSe
lector* ownerFontSelector) | 108 static PopupMenuCSSFontSelector* create(Document* document, CSSFontSelector*
ownerFontSelector) |
109 { | 109 { |
110 return new PopupMenuCSSFontSelector(document, ownerFontSelector); | 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 |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 RawPtr<PopupMenuImpl> PopupMenuImpl::create(ChromeClientImpl* chromeClient, HTML
SelectElement& ownerElement) | 236 PopupMenuImpl* PopupMenuImpl::create(ChromeClientImpl* chromeClient, HTMLSelectE
lement& ownerElement) |
237 { | 237 { |
238 return 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 { |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 DCHECK(m_popup); | 407 DCHECK(m_popup); |
408 DCHECK(m_ownerElement); | 408 DCHECK(m_ownerElement); |
409 RawPtr<PopupMenuImpl> protector(this); | |
410 bool success; | 409 bool success; |
411 int listIndex = stringValue.toInt(&success); | 410 int listIndex = stringValue.toInt(&success); |
412 DCHECK(success); | 411 DCHECK(success); |
413 { | 412 { |
414 EventQueueScope scope; | 413 EventQueueScope scope; |
415 m_ownerElement->valueChanged(listIndex); | 414 m_ownerElement->valueChanged(listIndex); |
416 if (m_popup) | 415 if (m_popup) |
417 m_chromeClient->closePagePopup(m_popup); | 416 m_chromeClient->closePagePopup(m_popup); |
418 // 'change' event is dispatched here. For compatbility with | 417 // 'change' event is dispatched here. For compatbility with |
419 // Angular 1.2, we need to dispatch a change event before | 418 // Angular 1.2, we need to dispatch a change event before |
420 // mouseup/click events. | 419 // mouseup/click events. |
421 } | 420 } |
422 // We dispatch events on the owner element to match the legacy behavior. | 421 // We dispatch events on the owner element to match the legacy behavior. |
423 // Other browsers dispatch click events before and after showing the popup. | 422 // Other browsers dispatch click events before and after showing the popup. |
424 if (m_ownerElement) { | 423 if (m_ownerElement) { |
425 PlatformMouseEvent event; | 424 PlatformMouseEvent event; |
426 RawPtr<Element> owner = &ownerElement(); | 425 Element* owner = &ownerElement(); |
427 owner->dispatchMouseEvent(event, EventTypeNames::mouseup); | 426 owner->dispatchMouseEvent(event, EventTypeNames::mouseup); |
428 owner->dispatchMouseEvent(event, EventTypeNames::click); | 427 owner->dispatchMouseEvent(event, EventTypeNames::click); |
429 } | 428 } |
430 } | 429 } |
431 | 430 |
432 void PopupMenuImpl::setValue(const String& value) | 431 void PopupMenuImpl::setValue(const String& value) |
433 { | 432 { |
434 DCHECK(m_ownerElement); | 433 DCHECK(m_ownerElement); |
435 bool success; | 434 bool success; |
436 int listIndex = value.toInt(&success); | 435 int listIndex = value.toInt(&success); |
437 DCHECK(success); | 436 DCHECK(success); |
438 m_ownerElement->provisionalSelectionChanged(listIndex); | 437 m_ownerElement->provisionalSelectionChanged(listIndex); |
439 } | 438 } |
440 | 439 |
441 void PopupMenuImpl::didClosePopup() | 440 void PopupMenuImpl::didClosePopup() |
442 { | 441 { |
443 // Clearing m_popup first to prevent from trying to close the popup again. | 442 // Clearing m_popup first to prevent from trying to close the popup again. |
444 m_popup = nullptr; | 443 m_popup = nullptr; |
445 RawPtr<PopupMenuImpl> protector(this); | |
446 if (m_ownerElement) | 444 if (m_ownerElement) |
447 m_ownerElement->popupDidHide(); | 445 m_ownerElement->popupDidHide(); |
448 } | 446 } |
449 | 447 |
450 Element& PopupMenuImpl::ownerElement() | 448 Element& PopupMenuImpl::ownerElement() |
451 { | 449 { |
452 return *m_ownerElement; | 450 return *m_ownerElement; |
453 } | 451 } |
454 | 452 |
455 Locale& PopupMenuImpl::locale() | 453 Locale& PopupMenuImpl::locale() |
(...skipping 25 matching lines...) Expand all Loading... |
481 { | 479 { |
482 if (m_popup) | 480 if (m_popup) |
483 m_chromeClient->closePagePopup(m_popup); | 481 m_chromeClient->closePagePopup(m_popup); |
484 } | 482 } |
485 | 483 |
486 void PopupMenuImpl::updateFromElement() | 484 void PopupMenuImpl::updateFromElement() |
487 { | 485 { |
488 if (m_needsUpdate) | 486 if (m_needsUpdate) |
489 return; | 487 return; |
490 m_needsUpdate = true; | 488 m_needsUpdate = true; |
491 ownerElement().document().postTask(BLINK_FROM_HERE, createSameThreadTask(&Po
pupMenuImpl::update, RawPtr<PopupMenuImpl>(this))); | 489 ownerElement().document().postTask(BLINK_FROM_HERE, createSameThreadTask(&Po
pupMenuImpl::update, this)); |
492 } | 490 } |
493 | 491 |
494 void PopupMenuImpl::update() | 492 void PopupMenuImpl::update() |
495 { | 493 { |
496 if (!m_popup || !m_ownerElement) | 494 if (!m_popup || !m_ownerElement) |
497 return; | 495 return; |
498 ownerElement().document().updateLayoutTree(); | 496 ownerElement().document().updateLayoutTree(); |
499 // disconnectClient() might have been called. | 497 // disconnectClient() might have been called. |
500 if (!m_ownerElement) | 498 if (!m_ownerElement) |
501 return; | 499 return; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
535 | 533 |
536 void PopupMenuImpl::disconnectClient() | 534 void PopupMenuImpl::disconnectClient() |
537 { | 535 { |
538 m_ownerElement = nullptr; | 536 m_ownerElement = nullptr; |
539 // Cannot be done during finalization, so instead done when the | 537 // Cannot be done during finalization, so instead done when the |
540 // layout object is destroyed and disconnected. | 538 // layout object is destroyed and disconnected. |
541 dispose(); | 539 dispose(); |
542 } | 540 } |
543 | 541 |
544 } // namespace blink | 542 } // namespace blink |
OLD | NEW |