diff options
Diffstat (limited to 'Source/WebCore/rendering/RenderSearchField.cpp')
-rw-r--r-- | Source/WebCore/rendering/RenderSearchField.cpp | 67 |
1 files changed, 34 insertions, 33 deletions
diff --git a/Source/WebCore/rendering/RenderSearchField.cpp b/Source/WebCore/rendering/RenderSearchField.cpp index c1b237c30..052ba7f86 100644 --- a/Source/WebCore/rendering/RenderSearchField.cpp +++ b/Source/WebCore/rendering/RenderSearchField.cpp @@ -1,5 +1,5 @@ /** - * Copyright (C) 2006, 2007, 2010 Apple Inc. All rights reserved. + * Copyright (C) 2006, 2007, 2010, 2015 Apple Inc. All rights reserved. * (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) * Copyright (C) 2010 Google Inc. All rights reserved. * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). @@ -27,6 +27,7 @@ #include "CSSFontSelector.h" #include "CSSValueKeywords.h" #include "Chrome.h" +#include "Font.h" #include "Frame.h" #include "FrameSelection.h" #include "FrameView.h" @@ -35,14 +36,11 @@ #include "HitTestResult.h" #include "LocalizedStrings.h" #include "Page.h" -#include "PlatformKeyboardEvent.h" +#include "PopupMenu.h" #include "RenderLayer.h" #include "RenderScrollbar.h" #include "RenderTheme.h" #include "RenderView.h" -#include "SearchPopupMenu.h" -#include "Settings.h" -#include "SimpleFontData.h" #include "StyleResolver.h" #include "TextControlInnerElements.h" @@ -50,8 +48,8 @@ namespace WebCore { using namespace HTMLNames; -RenderSearchField::RenderSearchField(HTMLInputElement& element, PassRef<RenderStyle> style) - : RenderTextControlSingleLine(element, std::move(style)) +RenderSearchField::RenderSearchField(HTMLInputElement& element, RenderStyle&& style) + : RenderTextControlSingleLine(element, WTFMove(style)) , m_searchPopupIsVisible(false) , m_searchPopup(0) { @@ -60,10 +58,17 @@ RenderSearchField::RenderSearchField(HTMLInputElement& element, PassRef<RenderSt RenderSearchField::~RenderSearchField() { + // Do not add any code here. Add it to willBeDestroyed() instead. +} + +void RenderSearchField::willBeDestroyed() +{ if (m_searchPopup) { m_searchPopup->popupMenu()->disconnectClient(); - m_searchPopup = 0; + m_searchPopup = nullptr; } + + RenderTextControlSingleLine::willBeDestroyed(); } inline HTMLElement* RenderSearchField::resultsButtonElement() const @@ -85,22 +90,21 @@ void RenderSearchField::addSearchResult() if (value.isEmpty()) return; - if (frame().settings().privateBrowsingEnabled()) + if (page().usesEphemeralSession()) return; - int size = static_cast<int>(m_recentSearches.size()); - for (int i = size - 1; i >= 0; --i) { - if (m_recentSearches[i] == value) - m_recentSearches.remove(i); - } + m_recentSearches.removeAllMatching([value] (const RecentSearch& recentSearch) { + return recentSearch.string == value; + }); - m_recentSearches.insert(0, value); + RecentSearch recentSearch = { value, std::chrono::system_clock::now() }; + m_recentSearches.insert(0, recentSearch); while (static_cast<int>(m_recentSearches.size()) > inputElement().maxResults()) m_recentSearches.removeLast(); const AtomicString& name = autosaveName(); if (!m_searchPopup) - m_searchPopup = document().page()->chrome().createSearchPopupMenu(this); + m_searchPopup = page().chrome().createSearchPopupMenu(*this); m_searchPopup->saveRecentSearches(name, m_recentSearches); } @@ -111,7 +115,7 @@ void RenderSearchField::showPopup() return; if (!m_searchPopup) - m_searchPopup = document().page()->chrome().createSearchPopupMenu(this); + m_searchPopup = page().chrome().createSearchPopupMenu(*this); if (!m_searchPopup->enabled()) return; @@ -130,7 +134,7 @@ void RenderSearchField::showPopup() m_searchPopup->saveRecentSearches(name, m_recentSearches); } - m_searchPopup->popupMenu()->show(pixelSnappedIntRect(absoluteBoundingBoxRect()), &view().frameView(), -1); + m_searchPopup->popupMenu()->show(snappedIntRect(absoluteBoundingBoxRect()), &view().frameView(), -1); } void RenderSearchField::hidePopup() @@ -179,9 +183,9 @@ void RenderSearchField::updateCancelButtonVisibility() const if (curStyle.visibility() == buttonVisibility) return; - auto cancelButtonStyle = RenderStyle::clone(&curStyle); - cancelButtonStyle.get().setVisibility(buttonVisibility); - cancelButtonRenderer->setStyle(std::move(cancelButtonStyle)); + auto cancelButtonStyle = RenderStyle::clone(curStyle); + cancelButtonStyle.setVisibility(buttonVisibility); + cancelButtonRenderer->setStyle(WTFMove(cancelButtonStyle)); } EVisibility RenderSearchField::visibilityForCancelButton() const @@ -191,7 +195,7 @@ EVisibility RenderSearchField::visibilityForCancelButton() const const AtomicString& RenderSearchField::autosaveName() const { - return inputElement().getAttribute(autosaveAttr); + return inputElement().attributeWithoutSynchronization(autosaveAttr); } // PopupMenuClient methods @@ -204,7 +208,7 @@ void RenderSearchField::valueChanged(unsigned listIndex, bool fireEvents) const AtomicString& name = autosaveName(); if (!name.isEmpty()) { if (!m_searchPopup) - m_searchPopup = document().page()->chrome().createSearchPopupMenu(this); + m_searchPopup = page().chrome().createSearchPopupMenu(*this); m_searchPopup->saveRecentSearches(name, m_recentSearches); } } @@ -233,7 +237,7 @@ String RenderSearchField::itemText(unsigned listIndex) const if (static_cast<int>(listIndex) == (size - 1)) return searchMenuClearRecentSearchesText(); #endif - return m_recentSearches[listIndex - 1]; + return m_recentSearches[listIndex - 1].string; } String RenderSearchField::itemLabel(unsigned) const @@ -260,8 +264,8 @@ PopupMenuStyle RenderSearchField::itemStyle(unsigned) const PopupMenuStyle RenderSearchField::menuStyle() const { - return PopupMenuStyle(style().visitedDependentColor(CSSPropertyColor), style().visitedDependentColor(CSSPropertyBackgroundColor), style().font(), style().visibility() == VISIBLE, - style().display() == NONE, style().textIndent(), style().direction(), isOverride(style().unicodeBidi()), PopupMenuStyle::CustomBackgroundColor); + return PopupMenuStyle(style().visitedDependentColor(CSSPropertyColor), style().visitedDependentColor(CSSPropertyBackgroundColor), style().fontCascade(), style().visibility() == VISIBLE, + style().display() == NONE, true, style().textIndent(), style().direction(), isOverride(style().unicodeBidi()), PopupMenuStyle::CustomBackgroundColor); } int RenderSearchField::clientInsetLeft() const @@ -339,7 +343,7 @@ void RenderSearchField::setTextFromItem(unsigned listIndex) FontSelector* RenderSearchField::fontSelector() const { - return document().ensureStyleResolver().fontSelector(); + return &document().fontSelector(); } HostWindow* RenderSearchField::hostWindow() const @@ -347,15 +351,12 @@ HostWindow* RenderSearchField::hostWindow() const return view().frameView().hostWindow(); } -PassRefPtr<Scrollbar> RenderSearchField::createScrollbar(ScrollableArea* scrollableArea, ScrollbarOrientation orientation, ScrollbarControlSize controlSize) +Ref<Scrollbar> RenderSearchField::createScrollbar(ScrollableArea& scrollableArea, ScrollbarOrientation orientation, ScrollbarControlSize controlSize) { - RefPtr<Scrollbar> widget; bool hasCustomScrollbarStyle = style().hasPseudoStyle(SCROLLBAR); if (hasCustomScrollbarStyle) - widget = RenderScrollbar::createCustomScrollbar(scrollableArea, orientation, &inputElement()); - else - widget = Scrollbar::createNativeScrollbar(scrollableArea, orientation, controlSize); - return widget.release(); + return RenderScrollbar::createCustomScrollbar(scrollableArea, orientation, &inputElement()); + return Scrollbar::createNativeScrollbar(scrollableArea, orientation, controlSize); } LayoutUnit RenderSearchField::computeLogicalHeightLimit() const |