Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(892)

Side by Side Diff: Source/WebCore/html/shadow/DateTimeNumericFieldElement.cpp

Issue 11557024: Merge 136808 (Closed) Base URL: http://svn.webkit.org/repository/webkit/branches/chromium/1312/
Patch Set: Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution. 11 * documentation and/or other materials provided with the distribution.
12 * 12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE 16 * ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
20 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 20 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23 * SUCH DAMAGE. 23 * SUCH DAMAGE.
24 */ 24 */
25 25
26 #include "config.h" 26 #include "config.h"
27 #if ENABLE(INPUT_MULTIPLE_FIELDS_UI) 27 #if ENABLE(INPUT_MULTIPLE_FIELDS_UI)
28 #include "DateTimeNumericFieldElement.h" 28 #include "DateTimeNumericFieldElement.h"
29 29
30 #include "FontCache.h" 30 #include "Font.h"
31 #include "KeyboardEvent.h" 31 #include "KeyboardEvent.h"
32 #include "PlatformLocale.h" 32 #include "PlatformLocale.h"
33 #include "RenderStyle.h"
34 #include "StyleResolver.h"
35 #include "TextRun.h"
36 #include <wtf/text/StringBuilder.h> 33 #include <wtf/text/StringBuilder.h>
37 34
35 using namespace WTF::Unicode;
36
38 namespace WebCore { 37 namespace WebCore {
39 38
40 static const DOMTimeStamp typeAheadTimeout = 1000; 39 static const DOMTimeStamp typeAheadTimeout = 1000;
41 40
42 DateTimeNumericFieldElement::Range::Range(int minimum, int maximum) 41 DateTimeNumericFieldElement::Range::Range(int minimum, int maximum)
43 : maximum(maximum) 42 : maximum(maximum)
44 , minimum(minimum) 43 , minimum(minimum)
45 { 44 {
46 ASSERT(minimum <= maximum); 45 ASSERT(minimum <= maximum);
47 } 46 }
(...skipping 11 matching lines...) Expand all
59 // ---------------------------- 58 // ----------------------------
60 59
61 DateTimeNumericFieldElement::DateTimeNumericFieldElement(Document* document, Fie ldOwner& fieldOwner, int minimum, int maximum, const String& placeholder) 60 DateTimeNumericFieldElement::DateTimeNumericFieldElement(Document* document, Fie ldOwner& fieldOwner, int minimum, int maximum, const String& placeholder)
62 : DateTimeFieldElement(document, fieldOwner) 61 : DateTimeFieldElement(document, fieldOwner)
63 , m_lastDigitCharTime(0) 62 , m_lastDigitCharTime(0)
64 , m_placeholder(placeholder) 63 , m_placeholder(placeholder)
65 , m_range(minimum, maximum) 64 , m_range(minimum, maximum)
66 , m_value(0) 65 , m_value(0)
67 , m_hasValue(false) 66 , m_hasValue(false)
68 { 67 {
69 setHasCustomCallbacks(); 68 // We show a direction-neutral string such as "--" as a placeholder. It
69 // should follow the direction of numeric values.
70 if (localeForOwner().isRTL()) {
71 Direction dir = direction(formatValue(this->maximum())[0]);
72 if (dir == LeftToRight || dir == EuropeanNumber || dir == ArabicNumber) {
73 StringBuilder builder;
74 builder.reserveCapacity(m_placeholder.length() + 2);
75 builder.append(leftToRightMark);
76 builder.append(m_placeholder);
77 builder.append(rightToLeftMark);
78 m_placeholder = builder.toString();
79 }
80 }
70 } 81 }
71 82
72 int DateTimeNumericFieldElement::clampValueForHardLimits(int value) const 83 int DateTimeNumericFieldElement::clampValueForHardLimits(int value) const
73 { 84 {
74 return clampValue(value); 85 return clampValue(value);
75 } 86 }
76 87
77 PassRefPtr<RenderStyle> DateTimeNumericFieldElement::customStyleForRenderer() 88 float DateTimeNumericFieldElement::maximumWidth(const Font& font)
78 { 89 {
79 FontCachePurgePreventer fontCachePurgePreventer; 90 float maximumWidth = font.width(m_placeholder);
80 RefPtr<RenderStyle> originalStyle = document()->styleResolver()->styleForEle ment(this); 91 maximumWidth = std::max(maximumWidth, font.width(formatValue(maximum())));
81 RefPtr<RenderStyle> style = RenderStyle::clone(originalStyle.get()); 92 maximumWidth = std::max(maximumWidth, font.width(value()));
82 float maxiumWidth = style->font().width(m_placeholder); 93 return maximumWidth + DateTimeFieldElement::maximumWidth(font);
83 maxiumWidth = std::max(maxiumWidth, style->font().width(formatValue(maximum( ))));
84 maxiumWidth = std::max(maxiumWidth, style->font().width(value()));
85 style->setMinWidth(Length(maxiumWidth, Fixed));
86 return style.release();
87 } 94 }
88 95
89 int DateTimeNumericFieldElement::defaultValueForStepDown() const 96 int DateTimeNumericFieldElement::defaultValueForStepDown() const
90 { 97 {
91 return m_range.maximum; 98 return m_range.maximum;
92 } 99 }
93 100
94 int DateTimeNumericFieldElement::defaultValueForStepUp() const 101 int DateTimeNumericFieldElement::defaultValueForStepUp() const
95 { 102 {
96 return m_range.minimum; 103 return m_range.minimum;
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 } 214 }
208 215
209 String DateTimeNumericFieldElement::visibleValue() const 216 String DateTimeNumericFieldElement::visibleValue() const
210 { 217 {
211 return m_hasValue ? value() : m_placeholder; 218 return m_hasValue ? value() : m_placeholder;
212 } 219 }
213 220
214 } // namespace WebCore 221 } // namespace WebCore
215 222
216 #endif 223 #endif
OLDNEW
« no previous file with comments | « Source/WebCore/html/shadow/DateTimeNumericFieldElement.h ('k') | Source/WebCore/html/shadow/DateTimeSymbolicFieldElement.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698