2 * Copyright (C) 2006, 2007, 2010 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).
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.
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.
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.
25 #include "core/rendering/RenderSearchField.h"
27 #include "core/dom/shadow/ShadowRoot.h"
28 #include "core/html/HTMLInputElement.h"
29 #include "core/html/shadow/ShadowElementNames.h"
33 using namespace HTMLNames;
35 // ----------------------------
37 RenderSearchField::RenderSearchField(HTMLInputElement* element)
38 : RenderTextControlSingleLine(element)
40 ASSERT(element->isSearchField());
43 RenderSearchField::~RenderSearchField()
47 inline Element* RenderSearchField::searchDecorationElement() const
49 return inputElement()->userAgentShadowRoot()->getElementById(ShadowElementNames::searchDecoration());
52 inline Element* RenderSearchField::cancelButtonElement() const
54 return inputElement()->userAgentShadowRoot()->getElementById(ShadowElementNames::clearButton());
57 LayoutUnit RenderSearchField::computeControlLogicalHeight(LayoutUnit lineHeight, LayoutUnit nonContentHeight) const
59 Element* searchDecoration = searchDecorationElement();
60 if (RenderBox* decorationRenderer = searchDecoration ? searchDecoration->renderBox() : 0) {
61 decorationRenderer->updateLogicalHeight();
62 nonContentHeight = max(nonContentHeight, decorationRenderer->borderAndPaddingLogicalHeight() + decorationRenderer->marginLogicalHeight());
63 lineHeight = max(lineHeight, decorationRenderer->logicalHeight());
65 Element* cancelButton = cancelButtonElement();
66 if (RenderBox* cancelRenderer = cancelButton ? cancelButton->renderBox() : 0) {
67 cancelRenderer->updateLogicalHeight();
68 nonContentHeight = max(nonContentHeight, cancelRenderer->borderAndPaddingLogicalHeight() + cancelRenderer->marginLogicalHeight());
69 lineHeight = max(lineHeight, cancelRenderer->logicalHeight());
72 return lineHeight + nonContentHeight;
75 LayoutUnit RenderSearchField::computeLogicalHeightLimit() const
77 return logicalHeight();
80 void RenderSearchField::centerContainerIfNeeded(RenderBox* containerRenderer) const
82 if (!containerRenderer)
85 if (containerRenderer->logicalHeight() <= contentLogicalHeight())
88 // A quirk for find-in-page box on Safari Windows.
89 // http://webkit.org/b/63157
90 LayoutUnit logicalHeightDiff = containerRenderer->logicalHeight() - contentLogicalHeight();
91 containerRenderer->setLogicalTop(containerRenderer->logicalTop() - (logicalHeightDiff / 2 + layoutMod(logicalHeightDiff, 2)));