| File: | Volumes/Data/worker/Apple-iOS-26-Safer-CPP-Checks-EWS/build/Source/WebCore/rendering/RenderSearchField.cpp |
| Warning: | line 126, column 67 Call argument is unchecked and unsafe |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | /* |
| 2 | * Copyright (C) 2006, 2007, 2010, 2015 Apple Inc. All rights reserved. |
| 3 | * (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) |
| 4 | * Copyright (C) 2010 Google Inc. All rights reserved. |
| 5 | * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
| 6 | * |
| 7 | * This library is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU Library General Public |
| 9 | * License as published by the Free Software Foundation; either |
| 10 | * version 2 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | * This library is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * Library General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU Library General Public License |
| 18 | * along with this library; see the file COPYING.LIB. If not, write to |
| 19 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 20 | * Boston, MA 02110-1301, USA. |
| 21 | * |
| 22 | */ |
| 23 | |
| 24 | #include "config.h" |
| 25 | #include "RenderSearchField.h" |
| 26 | |
| 27 | #include "ContainerNodeInlines.h" |
| 28 | #include "CSSFontSelector.h" |
| 29 | #include "CSSValueKeywords.h" |
| 30 | #include "Chrome.h" |
| 31 | #include "DocumentInlines.h" |
| 32 | #include "DocumentView.h" |
| 33 | #include "ElementInlines.h" |
| 34 | #include "Font.h" |
| 35 | #include "FrameSelection.h" |
| 36 | #include "HTMLInputElement.h" |
| 37 | #include "HTMLNames.h" |
| 38 | #include "HitTestResult.h" |
| 39 | #include "LocalFrame.h" |
| 40 | #include "LocalFrameView.h" |
| 41 | #include "LocalizedStrings.h" |
| 42 | #include "NodeInlines.h" |
| 43 | #include "Page.h" |
| 44 | #include "PopupMenu.h" |
| 45 | #include "RenderBoxInlines.h" |
| 46 | #include "RenderBoxModelObjectInlines.h" |
| 47 | #include "RenderLayer.h" |
| 48 | #include "RenderObjectInlines.h" |
| 49 | #include "RenderTheme.h" |
| 50 | #include "RenderView.h" |
| 51 | #include "SearchInputType.h" |
| 52 | #include "StyleResolver.h" |
| 53 | #include "TextControlInnerElements.h" |
| 54 | #include "UnicodeBidi.h" |
| 55 | #include <wtf/TZoneMallocInlines.h> |
| 56 | |
| 57 | namespace WebCore { |
| 58 | |
| 59 | using namespace HTMLNames; |
| 60 | |
| 61 | WTF_MAKE_TZONE_ALLOCATED_IMPL(RenderSearchField)::bmalloc::api::HeapRef RenderSearchField::s_heapRef; const TZoneSpecification RenderSearchField::s_heapSpec = { &RenderSearchField::s_heapRef , TZoneSpecification::encodeSize<RenderSearchField>(), TZoneSpecification ::encodeAlignment<RenderSearchField>(), TZoneSpecification ::encodeCategory<RenderSearchField>(), ::bmalloc::api:: compactAllocationMode<RenderSearchField>(), TZoneSpecification ::encodeDescriptor<RenderSearchField>(), }; void* RenderSearchField ::operatorNewSlow(size_t size) { if constexpr (::bmalloc::api ::compactAllocationMode<RenderSearchField>() == CompactAllocationMode ::Compact) return ::bmalloc::api::tzoneAllocateCompactSlow(size , s_heapSpec); return ::bmalloc::api::tzoneAllocateNonCompactSlow (size, s_heapSpec); } using __makeBtzoneMallocedInlineMacroSemicolonifier __attribute__((unused)) = int; |
| 62 | |
| 63 | RenderSearchField::RenderSearchField(HTMLInputElement& element, RenderStyle&& style) |
| 64 | : RenderTextControlSingleLine(Type::SearchField, element, WTF::move(style)) |
| 65 | , m_searchPopupIsVisible(false) |
| 66 | , m_searchPopup(nullptr) |
| 67 | { |
| 68 | ASSERT(element.isSearchField())((void)0); |
| 69 | ASSERT(isRenderSearchField())((void)0); |
| 70 | } |
| 71 | |
| 72 | // Do not add any code in below destructor. Add it to willBeDestroyed() instead. |
| 73 | RenderSearchField::~RenderSearchField() = default; |
| 74 | |
| 75 | void RenderSearchField::willBeDestroyed() |
| 76 | { |
| 77 | if (RefPtr searchPopup = std::exchange(m_searchPopup, nullptr)) |
| 78 | protect(searchPopup->popupMenu())->disconnectClient(); |
| 79 | |
| 80 | RenderTextControlSingleLine::willBeDestroyed(); |
| 81 | } |
| 82 | |
| 83 | inline HTMLElement* RenderSearchField::resultsButtonElement() const |
| 84 | { |
| 85 | return protect(inputElement())->resultsButtonElement(); |
| 86 | } |
| 87 | |
| 88 | inline HTMLElement* RenderSearchField::cancelButtonElement() const |
| 89 | { |
| 90 | return protect(inputElement())->cancelButtonElement(); |
| 91 | } |
| 92 | |
| 93 | void RenderSearchField::showPopup() |
| 94 | { |
| 95 | if (m_searchPopupIsVisible) |
| 96 | return; |
| 97 | |
| 98 | |
| 99 | |
| 100 | if (!m_searchPopup) |
| 101 | m_searchPopup = page().chrome().createSearchPopupMenu(downcast<SearchInputType>(*inputElement().inputType())); |
| 102 | |
| 103 | Ref popup = *m_searchPopup; |
| 104 | if (!popup->enabled()) |
| 105 | return; |
| 106 | |
| 107 | m_searchPopupIsVisible = true; |
| 108 | |
| 109 | auto recentSearches = downcast<SearchInputType>(*inputElement().inputType()).recentSearches(); |
| 110 | const AtomString& name = autosaveName(); |
| 111 | popup->loadRecentSearches(name, recentSearches); |
| 112 | |
| 113 | // Trim the recent searches list if the maximum size has changed since we last saved. |
| 114 | |
| 115 | if (static_cast<int>(recentSearches.size()) > inputElement().maxResults()) { |
| 116 | do { |
| 117 | recentSearches.removeLast(); |
| 118 | } while (static_cast<int>(recentSearches.size()) > inputElement().maxResults()); |
| 119 | |
| 120 | popup->saveRecentSearches(name, recentSearches); |
| 121 | } |
| 122 | |
| 123 | FloatPoint absTopLeft = localToAbsolute(FloatPoint(), UseTransforms); |
| 124 | IntRect absBounds = absoluteBoundingBoxRectIgnoringTransforms(); |
| 125 | absBounds.setLocation(roundedIntPoint(absTopLeft)); |
| 126 | protect(protect(m_searchPopup)->popupMenu())->show(absBounds, view().frameView(), -1); |
Call argument is unchecked and unsafe | |
| 127 | } |
| 128 | |
| 129 | void RenderSearchField::hidePopup() |
| 130 | { |
| 131 | if (RefPtr searchPopup = m_searchPopup) |
| 132 | protect(searchPopup->popupMenu())->hide(); |
| 133 | } |
| 134 | |
| 135 | LayoutUnit RenderSearchField::computeControlLogicalHeight(LayoutUnit lineHeight, LayoutUnit nonContentHeight) const |
| 136 | { |
| 137 | RefPtr resultsButton = resultsButtonElement(); |
| 138 | if (CheckedPtr resultsRenderer = resultsButton ? resultsButton->renderBox() : nullptr) { |
| 139 | resultsRenderer->updateLogicalHeight(); |
| 140 | nonContentHeight = std::max(nonContentHeight, resultsRenderer->borderAndPaddingLogicalHeight() + resultsRenderer->marginLogicalHeight()); |
| 141 | lineHeight = std::max(lineHeight, resultsRenderer->logicalHeight()); |
| 142 | } |
| 143 | RefPtr cancelButton = cancelButtonElement(); |
| 144 | if (CheckedPtr cancelRenderer = cancelButton ? cancelButton->renderBox() : nullptr) { |
| 145 | cancelRenderer->updateLogicalHeight(); |
| 146 | nonContentHeight = std::max(nonContentHeight, cancelRenderer->borderAndPaddingLogicalHeight() + cancelRenderer->marginLogicalHeight()); |
| 147 | lineHeight = std::max(lineHeight, cancelRenderer->logicalHeight()); |
| 148 | } |
| 149 | |
| 150 | return lineHeight + nonContentHeight; |
| 151 | } |
| 152 | |
| 153 | std::span<const RecentSearch> RenderSearchField::recentSearches() |
| 154 | { |
| 155 | if (!m_searchPopup) |
| 156 | m_searchPopup = page().chrome().createSearchPopupMenu(downcast<SearchInputType>(*inputElement().inputType())); |
| 157 | |
| 158 | auto& recentSearches = downcast<SearchInputType>(*inputElement().inputType()).recentSearches(); |
| 159 | |
| 160 | const AtomString& name = autosaveName(); |
| 161 | protect(m_searchPopup)->loadRecentSearches(name, recentSearches); |
| 162 | |
| 163 | return recentSearches.span(); |
| 164 | } |
| 165 | |
| 166 | void RenderSearchField::updateFromElement() |
| 167 | { |
| 168 | RenderTextControlSingleLine::updateFromElement(); |
| 169 | |
| 170 | if (cancelButtonElement()) |
| 171 | updateCancelButtonVisibility(); |
| 172 | |
| 173 | if (m_searchPopupIsVisible) |
| 174 | protect(protect(m_searchPopup)->popupMenu())->updateFromElement(); |
| 175 | } |
| 176 | |
| 177 | void RenderSearchField::updateCancelButtonVisibility() const |
| 178 | { |
| 179 | CheckedPtr cancelButtonRenderer = cancelButtonElement()->renderer(); |
| 180 | if (!cancelButtonRenderer) |
| 181 | return; |
| 182 | |
| 183 | CheckedRef curStyle = cancelButtonRenderer->style(); |
| 184 | Visibility buttonVisibility = visibilityForCancelButton(); |
| 185 | if (curStyle->usedVisibility() == buttonVisibility) |
| 186 | return; |
| 187 | |
| 188 | auto cancelButtonStyle = RenderStyle::clone(curStyle.get()); |
| 189 | cancelButtonStyle.setVisibility(buttonVisibility); |
| 190 | cancelButtonRenderer->setStyle(WTF::move(cancelButtonStyle)); |
| 191 | } |
| 192 | |
| 193 | Visibility RenderSearchField::visibilityForCancelButton() const |
| 194 | { |
| 195 | return (style().usedVisibility() == Visibility::Hidden || protect(inputElement())->value()->isEmpty()) ? Visibility::Hidden : Visibility::Visible; |
| 196 | } |
| 197 | |
| 198 | const AtomString& RenderSearchField::autosaveName() const |
| 199 | { |
| 200 | return inputElement().attributeWithoutSynchronization(nameAttr); |
| 201 | } |
| 202 | |
| 203 | void RenderSearchField::updatePopup(const AtomString& name, const Vector<RecentSearch>& searchItems) |
| 204 | { |
| 205 | if (!m_searchPopup) |
| 206 | m_searchPopup = page().chrome().createSearchPopupMenu(downcast<SearchInputType>(*inputElement().inputType())); |
| 207 | protect(m_searchPopup)->saveRecentSearches(name, searchItems); |
| 208 | } |
| 209 | |
| 210 | void RenderSearchField::popupDidHide() |
| 211 | { |
| 212 | m_searchPopupIsVisible = false; |
| 213 | } |
| 214 | |
| 215 | #if PLATFORM(WIN)(defined WTF_PLATFORM_WIN && WTF_PLATFORM_WIN) |
| 216 | int RenderSearchField::clientInsetLeft() const |
| 217 | { |
| 218 | // Inset the menu by the radius of the cap on the left so that |
| 219 | // it only runs along the straight part of the bezel. |
| 220 | return height() / 2; |
| 221 | } |
| 222 | |
| 223 | int RenderSearchField::clientInsetRight() const |
| 224 | { |
| 225 | // Inset the menu by the radius of the cap on the right so that |
| 226 | // it only runs along the straight part of the bezel (unless it needs |
| 227 | // to be wider). |
| 228 | return height() / 2; |
| 229 | } |
| 230 | |
| 231 | LayoutUnit RenderSearchField::clientPaddingLeft() const |
| 232 | { |
| 233 | LayoutUnit padding = paddingLeft(); |
| 234 | RefPtr innerBlock = innerBlockElement(); |
| 235 | if (auto* box = innerBlock ? innerBlock->renderBox() : nullptr) |
| 236 | padding += box->x(); |
| 237 | return padding; |
| 238 | } |
| 239 | |
| 240 | LayoutUnit RenderSearchField::clientPaddingRight() const |
| 241 | { |
| 242 | LayoutUnit padding = paddingRight(); |
| 243 | RefPtr container = containerElement(); |
| 244 | if (CheckedPtr containerBox = container ? container->renderBox() : nullptr) { |
| 245 | RefPtr innerBlock = innerBlockElement(); |
| 246 | if (auto* innerBlockBox = innerBlock ? innerBlock->renderBox() : nullptr) |
| 247 | padding += containerBox->width() - (innerBlockBox->x() + innerBlockBox->width()); |
| 248 | } |
| 249 | return padding; |
| 250 | } |
| 251 | |
| 252 | FontSelector* RenderSearchField::fontSelector() const |
| 253 | { |
| 254 | return &protect(document())->fontSelector(); |
| 255 | } |
| 256 | |
| 257 | HostWindow* RenderSearchField::hostWindow() const |
| 258 | { |
| 259 | return RenderTextControlSingleLine::hostWindow(); |
| 260 | } |
| 261 | #endif |
| 262 | |
| 263 | } |