OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2006, 2007, 2012 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2012 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * This library is free software; you can redistribute it and/or | 4 * This library is free software; you can redistribute it and/or |
5 * modify it under the terms of the GNU Library General Public | 5 * modify it under the terms of the GNU Library General Public |
6 * License as published by the Free Software Foundation; either | 6 * License as published by the Free Software Foundation; either |
7 * version 2 of the License, or (at your option) any later version. | 7 * version 2 of the License, or (at your option) any later version. |
8 * | 8 * |
9 * This library is distributed in the hope that it will be useful, | 9 * This library is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 | 44 |
45 using namespace HTMLNames; | 45 using namespace HTMLNames; |
46 | 46 |
47 const int afterButtonSpacing = 4; | 47 const int afterButtonSpacing = 4; |
48 const int iconHeight = 16; | 48 const int iconHeight = 16; |
49 const int iconWidth = 16; | 49 const int iconWidth = 16; |
50 const int iconFilenameSpacing = 2; | 50 const int iconFilenameSpacing = 2; |
51 const int defaultWidthNumChars = 34; | 51 const int defaultWidthNumChars = 34; |
52 const int buttonShadowHeight = 2; | 52 const int buttonShadowHeight = 2; |
53 | 53 |
54 RenderFileUploadControl::RenderFileUploadControl(HTMLInputElement* input) | 54 RenderFileUploadControl::RenderFileUploadControl(Handle<HTMLInputElement> input) |
55 : RenderBlock(input) | 55 : RenderBlock(input.raw()) |
56 , m_canReceiveDroppedFiles(input->canReceiveDroppedFiles()) | 56 , m_canReceiveDroppedFiles(input->canReceiveDroppedFiles()) |
57 { | 57 { |
58 } | 58 } |
59 | 59 |
60 RenderFileUploadControl::~RenderFileUploadControl() | 60 RenderFileUploadControl::~RenderFileUploadControl() |
61 { | 61 { |
62 } | 62 } |
63 | 63 |
64 bool RenderFileUploadControl::canBeReplacedWithInlineRunIn() const | 64 bool RenderFileUploadControl::canBeReplacedWithInlineRunIn() const |
65 { | 65 { |
66 return false; | 66 return false; |
67 } | 67 } |
68 | 68 |
69 void RenderFileUploadControl::updateFromElement() | 69 void RenderFileUploadControl::updateFromElement() |
70 { | 70 { |
71 HTMLInputElement* input = static_cast<HTMLInputElement*>(node()); | 71 Handle<HTMLInputElement> input(static_cast<HTMLInputElement*>(node())); |
72 ASSERT(input->isFileUpload()); | 72 ASSERT(input->isFileUpload()); |
73 | 73 |
74 if (HTMLInputElement* button = uploadButton()) { | 74 if (Handle<HTMLInputElement> button = uploadButton()) { |
75 bool newCanReceiveDroppedFilesState = input->canReceiveDroppedFiles(); | 75 bool newCanReceiveDroppedFilesState = input->canReceiveDroppedFiles(); |
76 if (m_canReceiveDroppedFiles != newCanReceiveDroppedFilesState) { | 76 if (m_canReceiveDroppedFiles != newCanReceiveDroppedFilesState) { |
77 m_canReceiveDroppedFiles = newCanReceiveDroppedFilesState; | 77 m_canReceiveDroppedFiles = newCanReceiveDroppedFilesState; |
78 button->setActive(newCanReceiveDroppedFilesState); | 78 button->setActive(newCanReceiveDroppedFilesState); |
79 } | 79 } |
80 } | 80 } |
81 | 81 |
82 // This only supports clearing out the files, but that's OK because for | 82 // This only supports clearing out the files, but that's OK because for |
83 // security reasons that's the only change the DOM is allowed to make. | 83 // security reasons that's the only change the DOM is allowed to make. |
84 FileList* files = input->files(); | 84 FileList* files = input->files(); |
85 ASSERT(files); | 85 ASSERT(files); |
86 if (files && files->isEmpty()) | 86 if (files && files->isEmpty()) |
87 repaint(); | 87 repaint(); |
88 } | 88 } |
89 | 89 |
90 static int nodeWidth(Node* node) | 90 static int nodeWidth(Handle<Node> node) |
91 { | 91 { |
92 return (node && node->renderBox()) ? node->renderBox()->pixelSnappedWidth()
: 0; | 92 return (node && node->renderBox()) ? node->renderBox()->pixelSnappedWidth()
: 0; |
93 } | 93 } |
94 | 94 |
95 int RenderFileUploadControl::maxFilenameWidth() const | 95 int RenderFileUploadControl::maxFilenameWidth() const |
96 { | 96 { |
97 HTMLInputElement* input = static_cast<HTMLInputElement*>(node()); | 97 Handle<HTMLInputElement> input(static_cast<HTMLInputElement*>(node())); |
98 return max(0, contentBoxRect().pixelSnappedWidth() - nodeWidth(uploadButton(
)) - afterButtonSpacing | 98 return max(0, contentBoxRect().pixelSnappedWidth() - nodeWidth(uploadButton(
)) - afterButtonSpacing |
99 - (input->icon() ? iconWidth + iconFilenameSpacing : 0)); | 99 - (input->icon() ? iconWidth + iconFilenameSpacing : 0)); |
100 } | 100 } |
101 | 101 |
102 void RenderFileUploadControl::paintObject(PaintInfo& paintInfo, const LayoutPoin
t& paintOffset) | 102 void RenderFileUploadControl::paintObject(PaintInfo& paintInfo, const LayoutPoin
t& paintOffset) |
103 { | 103 { |
104 if (style()->visibility() != VISIBLE) | 104 if (style()->visibility() != VISIBLE) |
105 return; | 105 return; |
106 | 106 |
107 // Push a clip. | 107 // Push a clip. |
108 GraphicsContextStateSaver stateSaver(*paintInfo.context, false); | 108 GraphicsContextStateSaver stateSaver(*paintInfo.context, false); |
109 if (paintInfo.phase == PaintPhaseForeground || paintInfo.phase == PaintPhase
ChildBlockBackgrounds) { | 109 if (paintInfo.phase == PaintPhaseForeground || paintInfo.phase == PaintPhase
ChildBlockBackgrounds) { |
110 IntRect clipRect = enclosingIntRect(LayoutRect(paintOffset.x() + borderL
eft(), paintOffset.y() + borderTop(), | 110 IntRect clipRect = enclosingIntRect(LayoutRect(paintOffset.x() + borderL
eft(), paintOffset.y() + borderTop(), |
111 width() - borderLeft() - borderRight(), height() - bord
erBottom() - borderTop() + buttonShadowHeight)); | 111 width() - borderLeft() - borderRight(), height() - bord
erBottom() - borderTop() + buttonShadowHeight)); |
112 if (clipRect.isEmpty()) | 112 if (clipRect.isEmpty()) |
113 return; | 113 return; |
114 stateSaver.save(); | 114 stateSaver.save(); |
115 paintInfo.context->clip(clipRect); | 115 paintInfo.context->clip(clipRect); |
116 } | 116 } |
117 | 117 |
118 if (paintInfo.phase == PaintPhaseForeground) { | 118 if (paintInfo.phase == PaintPhaseForeground) { |
119 const String& displayedFilename = fileTextValue(); | 119 const String& displayedFilename = fileTextValue(); |
120 const Font& font = style()->font(); | 120 const Font& font = style()->font(); |
121 TextRun textRun = constructTextRun(this, font, displayedFilename, style(
), TextRun::AllowTrailingExpansion, RespectDirection | RespectDirectionOverride)
; | 121 TextRun textRun = constructTextRun(this, font, displayedFilename, style(
), TextRun::AllowTrailingExpansion, RespectDirection | RespectDirectionOverride)
; |
122 textRun.disableRoundingHacks(); | 122 textRun.disableRoundingHacks(); |
123 | 123 |
124 // Determine where the filename should be placed | 124 // Determine where the filename should be placed |
125 LayoutUnit contentLeft = paintOffset.x() + borderLeft() + paddingLeft(); | 125 LayoutUnit contentLeft = paintOffset.x() + borderLeft() + paddingLeft(); |
126 HTMLInputElement* button = uploadButton(); | 126 Handle<HTMLInputElement> button = uploadButton(); |
127 if (!button) | 127 if (!button) |
128 return; | 128 return; |
129 | 129 |
130 HTMLInputElement* input = static_cast<HTMLInputElement*>(node()); | 130 Handle<HTMLInputElement> input(static_cast<HTMLInputElement*>(node())); |
131 LayoutUnit buttonWidth = nodeWidth(button); | 131 LayoutUnit buttonWidth = nodeWidth(button); |
132 LayoutUnit buttonAndIconWidth = buttonWidth + afterButtonSpacing | 132 LayoutUnit buttonAndIconWidth = buttonWidth + afterButtonSpacing |
133 + (input->icon() ? iconWidth + iconFilenameSpacing : 0); | 133 + (input->icon() ? iconWidth + iconFilenameSpacing : 0); |
134 LayoutUnit textX; | 134 LayoutUnit textX; |
135 if (style()->isLeftToRightDirection()) | 135 if (style()->isLeftToRightDirection()) |
136 textX = contentLeft + buttonAndIconWidth; | 136 textX = contentLeft + buttonAndIconWidth; |
137 else | 137 else |
138 textX = contentLeft + contentWidth() - buttonAndIconWidth - font.wid
th(textRun); | 138 textX = contentLeft + contentWidth() - buttonAndIconWidth - font.wid
th(textRun); |
139 | 139 |
140 LayoutUnit textY = 0; | 140 LayoutUnit textY = 0; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 // (using "0" as the nominal character). | 174 // (using "0" as the nominal character). |
175 const UChar character = '0'; | 175 const UChar character = '0'; |
176 const String characterAsString = String(&character, 1); | 176 const String characterAsString = String(&character, 1); |
177 const Font& font = style()->font(); | 177 const Font& font = style()->font(); |
178 // FIXME: Remove the need for this const_cast by making constructTextRun tak
e a const RenderObject*. | 178 // FIXME: Remove the need for this const_cast by making constructTextRun tak
e a const RenderObject*. |
179 RenderFileUploadControl* renderer = const_cast<RenderFileUploadControl*>(thi
s); | 179 RenderFileUploadControl* renderer = const_cast<RenderFileUploadControl*>(thi
s); |
180 float minDefaultLabelWidth = defaultWidthNumChars * font.width(constructText
Run(renderer, font, characterAsString, style(), TextRun::AllowTrailingExpansion)
); | 180 float minDefaultLabelWidth = defaultWidthNumChars * font.width(constructText
Run(renderer, font, characterAsString, style(), TextRun::AllowTrailingExpansion)
); |
181 | 181 |
182 const String label = theme()->fileListDefaultLabel(node()->toInputElement()-
>multiple()); | 182 const String label = theme()->fileListDefaultLabel(node()->toInputElement()-
>multiple()); |
183 float defaultLabelWidth = font.width(constructTextRun(renderer, font, label,
style(), TextRun::AllowTrailingExpansion)); | 183 float defaultLabelWidth = font.width(constructTextRun(renderer, font, label,
style(), TextRun::AllowTrailingExpansion)); |
184 if (HTMLInputElement* button = uploadButton()) | 184 if (Handle<HTMLInputElement> button = uploadButton()) |
185 if (RenderObject* buttonRenderer = button->renderer()) | 185 if (RenderObject* buttonRenderer = button->renderer()) |
186 defaultLabelWidth += buttonRenderer->maxPreferredLogicalWidth() + af
terButtonSpacing; | 186 defaultLabelWidth += buttonRenderer->maxPreferredLogicalWidth() + af
terButtonSpacing; |
187 maxLogicalWidth = static_cast<int>(ceilf(max(minDefaultLabelWidth, defaultLa
belWidth))); | 187 maxLogicalWidth = static_cast<int>(ceilf(max(minDefaultLabelWidth, defaultLa
belWidth))); |
188 | 188 |
189 if (!style()->width().isPercent()) | 189 if (!style()->width().isPercent()) |
190 minLogicalWidth = maxLogicalWidth; | 190 minLogicalWidth = maxLogicalWidth; |
191 } | 191 } |
192 | 192 |
193 void RenderFileUploadControl::computePreferredLogicalWidths() | 193 void RenderFileUploadControl::computePreferredLogicalWidths() |
194 { | 194 { |
(...skipping 22 matching lines...) Expand all Loading... |
217 m_maxPreferredLogicalWidth += toAdd; | 217 m_maxPreferredLogicalWidth += toAdd; |
218 | 218 |
219 setPreferredLogicalWidthsDirty(false); | 219 setPreferredLogicalWidthsDirty(false); |
220 } | 220 } |
221 | 221 |
222 VisiblePosition RenderFileUploadControl::positionForPoint(const LayoutPoint&) | 222 VisiblePosition RenderFileUploadControl::positionForPoint(const LayoutPoint&) |
223 { | 223 { |
224 return VisiblePosition(); | 224 return VisiblePosition(); |
225 } | 225 } |
226 | 226 |
227 HTMLInputElement* RenderFileUploadControl::uploadButton() const | 227 Result<HTMLInputElement> RenderFileUploadControl::uploadButton() const |
228 { | 228 { |
229 HTMLInputElement* input = static_cast<HTMLInputElement*>(node()); | 229 Handle<HTMLInputElement> input(static_cast<HTMLInputElement*>(node())); |
230 | 230 |
231 ASSERT(input->shadow()); | 231 ASSERT(input->shadow()); |
232 | 232 |
233 Node* buttonNode = input->shadow()->oldestShadowRoot()->firstChild(); | 233 Node* buttonNode = input->shadow()->oldestShadowRoot()->firstChild(); |
234 return buttonNode && buttonNode->isHTMLElement() && buttonNode->hasTagName(i
nputTag) ? static_cast<HTMLInputElement*>(buttonNode) : 0; | 234 return buttonNode && buttonNode->isHTMLElement() && buttonNode->hasTagName(i
nputTag) ? Handle<HTMLInputElement>(static_cast<HTMLInputElement*>(buttonNode))
: nullptr; |
235 } | 235 } |
236 | 236 |
237 String RenderFileUploadControl::buttonValue() | 237 String RenderFileUploadControl::buttonValue() |
238 { | 238 { |
239 if (HTMLInputElement* button = uploadButton()) | 239 if (Handle<HTMLInputElement> button = uploadButton()) |
240 return button->value(); | 240 return button->value(); |
241 | 241 |
242 return String(); | 242 return String(); |
243 } | 243 } |
244 | 244 |
245 String RenderFileUploadControl::fileTextValue() const | 245 String RenderFileUploadControl::fileTextValue() const |
246 { | 246 { |
247 HTMLInputElement* input = static_cast<HTMLInputElement*>(node()); | 247 Handle<HTMLInputElement> input(static_cast<HTMLInputElement*>(node())); |
248 ASSERT(input->files()); | 248 ASSERT(input->files()); |
249 return theme()->fileListNameForWidth(input->files(), style()->font(), maxFil
enameWidth(), input->multiple()); | 249 return theme()->fileListNameForWidth(input->files(), style()->font(), maxFil
enameWidth(), input->multiple()); |
250 } | 250 } |
251 | 251 |
252 } // namespace WebCore | 252 } // namespace WebCore |
OLD | NEW |