1 /**
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).
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 "core/rendering/RenderSearchField.h"
26
27 #include "core/dom/shadow/ShadowRoot.h"
28 #include "core/html/HTMLInputElement.h"
29 #include "core/html/shadow/ShadowElementNames.h"
30
31 using namespace std;
32
33 namespace WebCore {
34
35 using namespace HTMLNames;
36
37 // ----------------------------
38
RenderSearchField(HTMLInputElement * element)39 RenderSearchField::RenderSearchField(HTMLInputElement* element)
40 : RenderTextControlSingleLine(element)
41 {
42 ASSERT(element->isSearchField());
43 }
44
~RenderSearchField()45 RenderSearchField::~RenderSearchField()
46 {
47 }
48
searchDecorationElement() const49 inline Element* RenderSearchField::searchDecorationElement() const
50 {
51 return inputElement()->userAgentShadowRoot()->getElementById(ShadowElementNames::searchDecoration());
52 }
53
cancelButtonElement() const54 inline Element* RenderSearchField::cancelButtonElement() const
55 {
56 return inputElement()->userAgentShadowRoot()->getElementById(ShadowElementNames::clearButton());
57 }
58
computeControlLogicalHeight(LayoutUnit lineHeight,LayoutUnit nonContentHeight) const59 LayoutUnit RenderSearchField::computeControlLogicalHeight(LayoutUnit lineHeight, LayoutUnit nonContentHeight) const
60 {
61 Element* searchDecoration = searchDecorationElement();
62 if (RenderBox* decorationRenderer = searchDecoration ? searchDecoration->renderBox() : 0) {
63 decorationRenderer->updateLogicalHeight();
64 nonContentHeight = max(nonContentHeight, decorationRenderer->borderAndPaddingLogicalHeight() + decorationRenderer->marginLogicalHeight());
65 lineHeight = max(lineHeight, decorationRenderer->logicalHeight());
66 }
67 Element* cancelButton = cancelButtonElement();
68 if (RenderBox* cancelRenderer = cancelButton ? cancelButton->renderBox() : 0) {
69 cancelRenderer->updateLogicalHeight();
70 nonContentHeight = max(nonContentHeight, cancelRenderer->borderAndPaddingLogicalHeight() + cancelRenderer->marginLogicalHeight());
71 lineHeight = max(lineHeight, cancelRenderer->logicalHeight());
72 }
73
74 return lineHeight + nonContentHeight;
75 }
76
computeLogicalHeightLimit() const77 LayoutUnit RenderSearchField::computeLogicalHeightLimit() const
78 {
79 return logicalHeight();
80 }
81
centerContainerIfNeeded(RenderBox * containerRenderer) const82 void RenderSearchField::centerContainerIfNeeded(RenderBox* containerRenderer) const
83 {
84 if (!containerRenderer)
85 return;
86
87 if (containerRenderer->logicalHeight() <= contentLogicalHeight())
88 return;
89
90 // A quirk for find-in-page box on Safari Windows.
91 // http://webkit.org/b/63157
92 LayoutUnit logicalHeightDiff = containerRenderer->logicalHeight() - contentLogicalHeight();
93 containerRenderer->setLogicalTop(containerRenderer->logicalTop() - (logicalHeightDiff / 2 + layoutMod(logicalHeightDiff, 2)));
94 }
95
96 }
97