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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 { | 59 { |
60 } | 60 } |
61 | 61 |
62 bool RenderFileUploadControl::canBeReplacedWithInlineRunIn() const | 62 bool RenderFileUploadControl::canBeReplacedWithInlineRunIn() const |
63 { | 63 { |
64 return false; | 64 return false; |
65 } | 65 } |
66 | 66 |
67 void RenderFileUploadControl::updateFromElement() | 67 void RenderFileUploadControl::updateFromElement() |
68 { | 68 { |
69 HTMLInputElement* input = static_cast<HTMLInputElement*>(node()); | 69 HTMLInputElement* input = toHTMLInputElement(node()); |
70 ASSERT(input->isFileUpload()); | 70 ASSERT(input->isFileUpload()); |
71 | 71 |
72 if (HTMLInputElement* button = uploadButton()) { | 72 if (HTMLInputElement* button = uploadButton()) { |
73 bool newCanReceiveDroppedFilesState = input->canReceiveDroppedFiles(); | 73 bool newCanReceiveDroppedFilesState = input->canReceiveDroppedFiles(); |
74 if (m_canReceiveDroppedFiles != newCanReceiveDroppedFilesState) { | 74 if (m_canReceiveDroppedFiles != newCanReceiveDroppedFilesState) { |
75 m_canReceiveDroppedFiles = newCanReceiveDroppedFilesState; | 75 m_canReceiveDroppedFiles = newCanReceiveDroppedFilesState; |
76 button->setActive(newCanReceiveDroppedFilesState); | 76 button->setActive(newCanReceiveDroppedFilesState); |
77 } | 77 } |
78 } | 78 } |
79 | 79 |
80 // This only supports clearing out the files, but that's OK because for | 80 // This only supports clearing out the files, but that's OK because for |
81 // security reasons that's the only change the DOM is allowed to make. | 81 // security reasons that's the only change the DOM is allowed to make. |
82 FileList* files = input->files(); | 82 FileList* files = input->files(); |
83 ASSERT(files); | 83 ASSERT(files); |
84 if (files && files->isEmpty()) | 84 if (files && files->isEmpty()) |
85 repaint(); | 85 repaint(); |
86 } | 86 } |
87 | 87 |
88 static int nodeWidth(Node* node) | 88 static int nodeWidth(Node* node) |
89 { | 89 { |
90 return (node && node->renderBox()) ? node->renderBox()->pixelSnappedWidth()
: 0; | 90 return (node && node->renderBox()) ? node->renderBox()->pixelSnappedWidth()
: 0; |
91 } | 91 } |
92 | 92 |
93 int RenderFileUploadControl::maxFilenameWidth() const | 93 int RenderFileUploadControl::maxFilenameWidth() const |
94 { | 94 { |
95 HTMLInputElement* input = static_cast<HTMLInputElement*>(node()); | 95 HTMLInputElement* input = toHTMLInputElement(node()); |
96 return max(0, contentBoxRect().pixelSnappedWidth() - nodeWidth(uploadButton(
)) - afterButtonSpacing | 96 return max(0, contentBoxRect().pixelSnappedWidth() - nodeWidth(uploadButton(
)) - afterButtonSpacing |
97 - (input->icon() ? iconWidth + iconFilenameSpacing : 0)); | 97 - (input->icon() ? iconWidth + iconFilenameSpacing : 0)); |
98 } | 98 } |
99 | 99 |
100 void RenderFileUploadControl::paintObject(PaintInfo& paintInfo, const LayoutPoin
t& paintOffset) | 100 void RenderFileUploadControl::paintObject(PaintInfo& paintInfo, const LayoutPoin
t& paintOffset) |
101 { | 101 { |
102 if (style()->visibility() != VISIBLE) | 102 if (style()->visibility() != VISIBLE) |
103 return; | 103 return; |
104 | 104 |
105 // Push a clip. | 105 // Push a clip. |
(...skipping 12 matching lines...) Expand all Loading... |
118 const Font& font = style()->font(); | 118 const Font& font = style()->font(); |
119 TextRun textRun = constructTextRun(this, font, displayedFilename, style(
), TextRun::AllowTrailingExpansion, RespectDirection | RespectDirectionOverride)
; | 119 TextRun textRun = constructTextRun(this, font, displayedFilename, style(
), TextRun::AllowTrailingExpansion, RespectDirection | RespectDirectionOverride)
; |
120 textRun.disableRoundingHacks(); | 120 textRun.disableRoundingHacks(); |
121 | 121 |
122 // Determine where the filename should be placed | 122 // Determine where the filename should be placed |
123 LayoutUnit contentLeft = paintOffset.x() + borderLeft() + paddingLeft(); | 123 LayoutUnit contentLeft = paintOffset.x() + borderLeft() + paddingLeft(); |
124 HTMLInputElement* button = uploadButton(); | 124 HTMLInputElement* button = uploadButton(); |
125 if (!button) | 125 if (!button) |
126 return; | 126 return; |
127 | 127 |
128 HTMLInputElement* input = static_cast<HTMLInputElement*>(node()); | 128 HTMLInputElement* input = toHTMLInputElement(node()); |
129 LayoutUnit buttonWidth = nodeWidth(button); | 129 LayoutUnit buttonWidth = nodeWidth(button); |
130 LayoutUnit buttonAndIconWidth = buttonWidth + afterButtonSpacing | 130 LayoutUnit buttonAndIconWidth = buttonWidth + afterButtonSpacing |
131 + (input->icon() ? iconWidth + iconFilenameSpacing : 0); | 131 + (input->icon() ? iconWidth + iconFilenameSpacing : 0); |
132 float textWidth = font.width(textRun); | 132 float textWidth = font.width(textRun); |
133 LayoutUnit textX; | 133 LayoutUnit textX; |
134 if (style()->isLeftToRightDirection()) | 134 if (style()->isLeftToRightDirection()) |
135 textX = contentLeft + buttonAndIconWidth; | 135 textX = contentLeft + buttonAndIconWidth; |
136 else | 136 else |
137 textX = contentLeft + contentWidth() - buttonAndIconWidth - textWidt
h; | 137 textX = contentLeft + contentWidth() - buttonAndIconWidth - textWidt
h; |
138 | 138 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 setPreferredLogicalWidthsDirty(false); | 223 setPreferredLogicalWidthsDirty(false); |
224 } | 224 } |
225 | 225 |
226 VisiblePosition RenderFileUploadControl::positionForPoint(const LayoutPoint&) | 226 VisiblePosition RenderFileUploadControl::positionForPoint(const LayoutPoint&) |
227 { | 227 { |
228 return VisiblePosition(); | 228 return VisiblePosition(); |
229 } | 229 } |
230 | 230 |
231 HTMLInputElement* RenderFileUploadControl::uploadButton() const | 231 HTMLInputElement* RenderFileUploadControl::uploadButton() const |
232 { | 232 { |
233 HTMLInputElement* input = static_cast<HTMLInputElement*>(node()); | 233 HTMLInputElement* input = toHTMLInputElement(node()); |
234 | 234 |
235 ASSERT(input->shadow()); | 235 ASSERT(input->shadow()); |
236 | 236 |
237 Node* buttonNode = input->shadow()->oldestShadowRoot()->firstChild(); | 237 Node* buttonNode = input->shadow()->oldestShadowRoot()->firstChild(); |
238 return buttonNode && buttonNode->isHTMLElement() && buttonNode->hasTagName(i
nputTag) ? static_cast<HTMLInputElement*>(buttonNode) : 0; | 238 return buttonNode && buttonNode->isHTMLElement() && buttonNode->hasTagName(i
nputTag) ? toHTMLInputElement(buttonNode) : 0; |
239 } | 239 } |
240 | 240 |
241 String RenderFileUploadControl::buttonValue() | 241 String RenderFileUploadControl::buttonValue() |
242 { | 242 { |
243 if (HTMLInputElement* button = uploadButton()) | 243 if (HTMLInputElement* button = uploadButton()) |
244 return button->value(); | 244 return button->value(); |
245 | 245 |
246 return String(); | 246 return String(); |
247 } | 247 } |
248 | 248 |
249 String RenderFileUploadControl::fileTextValue() const | 249 String RenderFileUploadControl::fileTextValue() const |
250 { | 250 { |
251 HTMLInputElement* input = static_cast<HTMLInputElement*>(node()); | 251 HTMLInputElement* input = toHTMLInputElement(node()); |
252 ASSERT(input->files()); | 252 ASSERT(input->files()); |
253 return theme()->fileListNameForWidth(input->files(), style()->font(), maxFil
enameWidth(), input->multiple()); | 253 return theme()->fileListNameForWidth(input->files(), style()->font(), maxFil
enameWidth(), input->multiple()); |
254 } | 254 } |
255 | 255 |
256 } // namespace WebCore | 256 } // namespace WebCore |
OLD | NEW |