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

Side by Side Diff: Source/WebCore/html/shadow/DateTimeSymbolicFieldElement.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
« no previous file with comments | « Source/WebCore/html/shadow/DateTimeSymbolicFieldElement.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "DateTimeSymbolicFieldElement.h" 28 #include "DateTimeSymbolicFieldElement.h"
29 29
30 #include "FontCache.h" 30 #include "Font.h"
31 #include "KeyboardEvent.h" 31 #include "KeyboardEvent.h"
32 #include "RenderStyle.h"
33 #include "StyleResolver.h"
34 #include "TextBreakIterator.h" 32 #include "TextBreakIterator.h"
35 #include "TextRun.h"
36 #include <wtf/text/StringBuilder.h> 33 #include <wtf/text/StringBuilder.h>
37 #include <wtf/unicode/Unicode.h> 34 #include <wtf/unicode/Unicode.h>
38 35
39 namespace WebCore { 36 namespace WebCore {
40 37
41 static AtomicString makeVisibleEmptyValue(const Vector<String>& symbols) 38 static AtomicString makeVisibleEmptyValue(const Vector<String>& symbols)
42 { 39 {
43 unsigned maximumLength = 0; 40 unsigned maximumLength = 0;
44 for (unsigned index = 0; index < symbols.size(); ++index) 41 for (unsigned index = 0; index < symbols.size(); ++index)
45 maximumLength = std::max(maximumLength, numGraphemeClusters(symbols[inde x])); 42 maximumLength = std::max(maximumLength, numGraphemeClusters(symbols[inde x]));
46 StringBuilder builder; 43 StringBuilder builder;
47 builder.reserveCapacity(maximumLength); 44 builder.reserveCapacity(maximumLength);
48 for (unsigned length = 0; length < maximumLength; ++length) 45 for (unsigned length = 0; length < maximumLength; ++length)
49 builder.append('-'); 46 builder.append('-');
50 return builder.toAtomicString(); 47 return builder.toAtomicString();
51 } 48 }
52 49
53 DateTimeSymbolicFieldElement::DateTimeSymbolicFieldElement(Document* document, F ieldOwner& fieldOwner, const Vector<String>& symbols) 50 DateTimeSymbolicFieldElement::DateTimeSymbolicFieldElement(Document* document, F ieldOwner& fieldOwner, const Vector<String>& symbols)
54 : DateTimeFieldElement(document, fieldOwner) 51 : DateTimeFieldElement(document, fieldOwner)
55 , m_symbols(symbols) 52 , m_symbols(symbols)
56 , m_visibleEmptyValue(makeVisibleEmptyValue(symbols)) 53 , m_visibleEmptyValue(makeVisibleEmptyValue(symbols))
57 , m_selectedIndex(-1) 54 , m_selectedIndex(-1)
58 { 55 {
59 ASSERT(!symbols.isEmpty()); 56 ASSERT(!symbols.isEmpty());
60 setHasCustomCallbacks();
61 } 57 }
62 58
63 PassRefPtr<RenderStyle> DateTimeSymbolicFieldElement::customStyleForRenderer() 59 float DateTimeSymbolicFieldElement::maximumWidth(const Font& font)
64 { 60 {
65 FontCachePurgePreventer fontCachePurgePreventer; 61 float maximumWidth = font.width(visibleEmptyValue());
66 RefPtr<RenderStyle> originalStyle = document()->styleResolver()->styleForEle ment(this);
67 RefPtr<RenderStyle> style = RenderStyle::clone(originalStyle.get());
68 float maxiumWidth = style->font().width(visibleEmptyValue());
69 for (unsigned index = 0; index < m_symbols.size(); ++index) 62 for (unsigned index = 0; index < m_symbols.size(); ++index)
70 maxiumWidth = std::max(maxiumWidth, style->font().width(m_symbols[index] )); 63 maximumWidth = std::max(maximumWidth, font.width(m_symbols[index]));
71 style->setMinWidth(Length(maxiumWidth, Fixed)); 64 return maximumWidth + DateTimeFieldElement::maximumWidth(font);
72 return style.release();
73 } 65 }
74 66
75 void DateTimeSymbolicFieldElement::handleKeyboardEvent(KeyboardEvent* keyboardEv ent) 67 void DateTimeSymbolicFieldElement::handleKeyboardEvent(KeyboardEvent* keyboardEv ent)
76 { 68 {
77 if (keyboardEvent->type() != eventNames().keypressEvent) 69 if (keyboardEvent->type() != eventNames().keypressEvent)
78 return; 70 return;
79 71
80 const UChar charCode = WTF::Unicode::toLower(keyboardEvent->charCode()); 72 const UChar charCode = WTF::Unicode::toLower(keyboardEvent->charCode());
81 if (charCode < ' ') 73 if (charCode < ' ')
82 return; 74 return;
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 } 140 }
149 141
150 String DateTimeSymbolicFieldElement::visibleValue() const 142 String DateTimeSymbolicFieldElement::visibleValue() const
151 { 143 {
152 return hasValue() ? m_symbols[m_selectedIndex] : visibleEmptyValue(); 144 return hasValue() ? m_symbols[m_selectedIndex] : visibleEmptyValue();
153 } 145 }
154 146
155 } // namespace WebCore 147 } // namespace WebCore
156 148
157 #endif 149 #endif
OLDNEW
« no previous file with comments | « Source/WebCore/html/shadow/DateTimeSymbolicFieldElement.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698