Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / Source / core / layout / LayoutSearchField.cpp
blobb8b976034fc8bd02a616b516d760202132f27921
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).
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.
24 #include "config.h"
25 #include "core/layout/LayoutSearchField.h"
27 #include "core/InputTypeNames.h"
28 #include "core/dom/shadow/ShadowRoot.h"
29 #include "core/html/HTMLInputElement.h"
30 #include "core/html/shadow/ShadowElementNames.h"
32 namespace blink {
34 using namespace HTMLNames;
36 // ----------------------------
38 LayoutSearchField::LayoutSearchField(HTMLInputElement* element)
39 : LayoutTextControlSingleLine(element)
41 ASSERT(element->type() == InputTypeNames::search);
44 LayoutSearchField::~LayoutSearchField()
48 inline Element* LayoutSearchField::searchDecorationElement() const
50 return inputElement()->userAgentShadowRoot()->getElementById(ShadowElementNames::searchDecoration());
53 inline Element* LayoutSearchField::cancelButtonElement() const
55 return inputElement()->userAgentShadowRoot()->getElementById(ShadowElementNames::clearButton());
58 LayoutUnit LayoutSearchField::computeControlLogicalHeight(LayoutUnit lineHeight, LayoutUnit nonContentHeight) const
60 Element* searchDecoration = searchDecorationElement();
61 if (LayoutBox* decorationLayoutObject = searchDecoration ? searchDecoration->layoutBox() : 0) {
62 decorationLayoutObject->updateLogicalHeight();
63 nonContentHeight = max(nonContentHeight, decorationLayoutObject->borderAndPaddingLogicalHeight() + decorationLayoutObject->marginLogicalHeight());
64 lineHeight = max(lineHeight, decorationLayoutObject->logicalHeight());
66 Element* cancelButton = cancelButtonElement();
67 if (LayoutBox* cancelLayoutObject = cancelButton ? cancelButton->layoutBox() : 0) {
68 cancelLayoutObject->updateLogicalHeight();
69 nonContentHeight = max(nonContentHeight, cancelLayoutObject->borderAndPaddingLogicalHeight() + cancelLayoutObject->marginLogicalHeight());
70 lineHeight = max(lineHeight, cancelLayoutObject->logicalHeight());
73 return lineHeight + nonContentHeight;
76 LayoutUnit LayoutSearchField::computeLogicalHeightLimit() const
78 return logicalHeight();
81 void LayoutSearchField::centerContainerIfNeeded(LayoutBox* containerLayoutObject) const
83 if (!containerLayoutObject)
84 return;
86 if (containerLayoutObject->logicalHeight() <= contentLogicalHeight())
87 return;
89 // A quirk for find-in-page box on Safari Windows.
90 // http://webkit.org/b/63157
91 LayoutUnit logicalHeightDiff = containerLayoutObject->logicalHeight() - contentLogicalHeight();
92 containerLayoutObject->setLogicalTop(containerLayoutObject->logicalTop() - (logicalHeightDiff / 2 + layoutMod(logicalHeightDiff, 2)));