Changeset 88115 in webkit
- Timestamp:
- Jun 4, 2011 10:14:22 AM (13 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r88110 r88115 1 2011-06-03 Dimitri Glazkov <dglazkov@chromium.org> 2 3 Reviewed by Darin Adler. 4 5 Convert file <input> to use the new shadow DOM model 6 https://bugs.webkit.org/show_bug.cgi?id=59005 7 8 Refactoring, covered by existing tests. 9 10 * css/CSSSelector.cpp: 11 (WebCore::CSSSelector::pseudoId): Removed FILE_UPLOAD_BUTTON pseudoId and all references to it. 12 (WebCore::nameToPseudoTypeMap): Ditto. 13 (WebCore::CSSSelector::extractPseudoType): Ditto. 14 * css/CSSSelector.h: Ditto. 15 * css/html.css: 16 (input[type="button"], input[type="submit"], input[type="reset"]): Moved -webkit-file-upload-button to its own rule. 17 (input[type="file"]::-webkit-file-upload-button): Added and moved all previously hard-coded properties there. 18 * html/FileInputType.cpp: 19 (WebCore::UploadButtonElement::create): Added. 20 (WebCore::UploadButtonElement::UploadButtonElement): Added. 21 (WebCore::UploadButtonElement::shadowPseudoId): Added. 22 (WebCore::FileInputType::createShadowSubtree): Added. 23 * html/FileInputType.h: Added createShadowSubtree decl. 24 * page/DragController.cpp: 25 (WebCore::asFileInput): Changed the logic to use new shadow DOM. 26 * rendering/RenderFileUploadControl.cpp: Removed UploadButton class. 27 (WebCore::RenderFileUploadControl::~RenderFileUploadControl): Removed initializer for m_button. 28 (WebCore::RenderFileUploadControl::updateFromElement): Removed attachment logic that's no longer necessary. 29 (WebCore::nodeWidth): Added a helper. 30 (WebCore::RenderFileUploadControl::maxFilenameWidth): Changed to use uploadButton and nodeWidth. 31 (WebCore::RenderFileUploadControl::paintObject): Ditto. 32 (WebCore::RenderFileUploadControl::uploadButton): Added a helper to retrieve the button. 33 (WebCore::RenderFileUploadControl::buttonValue): Changed to use uploadButton. 34 * rendering/RenderFileUploadControl.h: Changed decls. 35 * rendering/style/RenderStyleConstants.h: Removed FILE_UPLOAD_BUTTON decls. 36 1 37 2011-06-04 Alexey Proskuryakov <ap@apple.com> 2 38 -
trunk/Source/WebCore/css/CSSSelector.cpp
r87660 r88115 127 127 case PseudoAfter: 128 128 return AFTER; 129 case PseudoFileUploadButton:130 return FILE_UPLOAD_BUTTON;131 129 case PseudoInputPlaceholder: 132 130 return INPUT_PLACEHOLDER; … … 234 232 DEFINE_STATIC_LOCAL(AtomicString, before, ("before")); 235 233 DEFINE_STATIC_LOCAL(AtomicString, checked, ("checked")); 236 DEFINE_STATIC_LOCAL(AtomicString, fileUploadButton, ("-webkit-file-upload-button"));237 234 DEFINE_STATIC_LOCAL(AtomicString, defaultString, ("default")); 238 235 DEFINE_STATIC_LOCAL(AtomicString, disabled, ("disabled")); … … 315 312 nameToPseudoType->set(before.impl(), CSSSelector::PseudoBefore); 316 313 nameToPseudoType->set(checked.impl(), CSSSelector::PseudoChecked); 317 nameToPseudoType->set(fileUploadButton.impl(), CSSSelector::PseudoFileUploadButton);318 314 nameToPseudoType->set(defaultString.impl(), CSSSelector::PseudoDefault); 319 315 nameToPseudoType->set(disabled.impl(), CSSSelector::PseudoDisabled); … … 414 410 case PseudoFirstLine: 415 411 compat = true; 416 case PseudoFileUploadButton:417 412 case PseudoInputListButton: 418 413 case PseudoInputPlaceholder: -
trunk/Source/WebCore/css/CSSSelector.h
r87660 r88115 173 173 PseudoNoButton, 174 174 PseudoSelection, 175 PseudoFileUploadButton,176 175 PseudoInputListButton, 177 176 PseudoLeftPage, -
trunk/Source/WebCore/css/html.css
r87881 r88115 518 518 } 519 519 520 input[type="button"], input[type="submit"], input[type="reset"] , input[type="file"]::-webkit-file-upload-button{520 input[type="button"], input[type="submit"], input[type="reset"] { 521 521 -webkit-appearance: push-button; 522 522 white-space: pre 523 } 524 525 input[type="file"]::-webkit-file-upload-button { 526 -webkit-appearance: push-button; 527 white-space: nowrap; 528 margin: 0; 523 529 } 524 530 -
trunk/Source/WebCore/html/FileInputType.cpp
r87095 r88115 32 32 #include "LocalizedStrings.h" 33 33 #include "RenderFileUploadControl.h" 34 #include "ShadowRoot.h" 34 35 #include <wtf/PassOwnPtr.h> 35 36 #include <wtf/text/WTFString.h> … … 38 39 39 40 using namespace HTMLNames; 41 42 class UploadButtonElement : public HTMLInputElement { 43 public: 44 static PassRefPtr<UploadButtonElement> create(Document*); 45 46 private: 47 UploadButtonElement(Document*); 48 49 virtual const AtomicString& shadowPseudoId() const; 50 }; 51 52 PassRefPtr<UploadButtonElement> UploadButtonElement::create(Document* document) 53 { 54 RefPtr<UploadButtonElement> button = adoptRef(new UploadButtonElement(document)); 55 button->setType("button"); 56 button->setValue(fileButtonChooseFileLabel()); 57 return button.release(); 58 } 59 60 61 UploadButtonElement::UploadButtonElement(Document* document) 62 : HTMLInputElement(inputTag, document, 0, false) 63 { 64 } 65 66 const AtomicString& UploadButtonElement::shadowPseudoId() const 67 { 68 DEFINE_STATIC_LOCAL(AtomicString, pseudoId, ("-webkit-file-upload-button")); 69 return pseudoId; 70 } 40 71 41 72 inline FileInputType::FileInputType(HTMLInputElement* element) … … 194 225 } 195 226 227 void FileInputType::createShadowSubtree() 228 { 229 ExceptionCode ec = 0; 230 element()->ensureShadowRoot()->appendChild(UploadButtonElement::create(element()->document()), ec); 231 } 232 196 233 } // namespace WebCore -
trunk/Source/WebCore/html/FileInputType.h
r74895 r88115 60 60 virtual void setFileList(const Vector<String>& paths); 61 61 virtual bool isFileUpload() const; 62 virtual void createShadowSubtree(); 62 63 63 64 RefPtr<FileList> m_fileList; -
trunk/Source/WebCore/page/DragController.cpp
r87878 r88115 254 254 ASSERT(node); 255 255 256 // The button for a FILE input is a sub element with no set input type 257 // In order to get around this problem we assume any non-FILE input element 258 // is this internal button, and try querying the shadow parent node. 259 if (node->hasTagName(HTMLNames::inputTag) && node->isShadowRoot() && !static_cast<HTMLInputElement*>(node)->isFileUpload()) 260 node = node->shadowHost(); 261 262 if (!node || !node->hasTagName(HTMLNames::inputTag)) 263 return 0; 264 265 HTMLInputElement* inputElement = static_cast<HTMLInputElement*>(node); 266 if (!inputElement->isFileUpload()) 267 return 0; 268 269 return inputElement; 256 HTMLInputElement* inputElement = node->toInputElement(); 257 258 // If this is a button inside of the a file input, move up to the file input. 259 if (inputElement && inputElement->isTextButton() && inputElement->treeScope()->isShadowBoundary()) 260 inputElement = inputElement->treeScope()->shadowHost()->toInputElement(); 261 262 return inputElement && inputElement->isFileUpload() ? inputElement : 0; 270 263 } 271 264 -
trunk/Source/WebCore/rendering/RenderFileUploadControl.cpp
r88087 r88115 37 37 #include "RenderTheme.h" 38 38 #include "RenderView.h" 39 #include "ShadowRoot.h" 39 40 #include "TextRun.h" 40 41 #include <math.h> … … 53 54 const int buttonShadowHeight = 2; 54 55 55 class UploadButton : public HTMLInputElement {56 public:57 static PassRefPtr<UploadButton> create(HTMLInputElement*);58 virtual void detach();59 60 private:61 UploadButton(HTMLInputElement*);62 };63 64 PassRefPtr<UploadButton> UploadButton::create(HTMLInputElement* shadowParent)65 {66 return adoptRef(new UploadButton(shadowParent));67 }68 69 void UploadButton::detach()70 {71 HTMLInputElement::detach();72 setShadowHost(0);73 }74 75 UploadButton::UploadButton(HTMLInputElement* shadowParent)76 : HTMLInputElement(inputTag, shadowParent->document(), 0, false)77 {78 setShadowHost(shadowParent);79 }80 81 56 RenderFileUploadControl::RenderFileUploadControl(HTMLInputElement* input) 82 57 : RenderBlock(input) … … 92 67 RenderFileUploadControl::~RenderFileUploadControl() 93 68 { 94 if (m_button)95 m_button->detach();96 69 m_fileChooser->disconnectClient(); 97 }98 99 void RenderFileUploadControl::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle)100 {101 RenderBlock::styleDidChange(diff, oldStyle);102 if (m_button)103 m_button->renderer()->setStyle(createButtonStyle(style()));104 70 } 105 71 … … 178 144 HTMLInputElement* inputElement = static_cast<HTMLInputElement*>(node()); 179 145 ASSERT(inputElement->isFileUpload()); 180 181 if (!m_button) { 182 m_button = UploadButton::create(inputElement); 183 m_button->setType("button"); 184 m_button->setValue(fileButtonChooseFileLabel()); 185 RefPtr<RenderStyle> buttonStyle = createButtonStyle(style()); 186 RenderObject* renderer = m_button->createRenderer(renderArena(), buttonStyle.get()); 187 m_button->setRenderer(renderer); 188 renderer->setStyle(buttonStyle.release()); 189 renderer->updateFromElement(); 190 m_button->setAttached(); 191 m_button->setInDocument(); 192 193 addChild(renderer); 194 } 195 196 m_button->setDisabled(!theme()->isEnabled(this)); 146 147 148 if (HTMLInputElement* button = uploadButton()) 149 button->setDisabled(!theme()->isEnabled(this)); 197 150 198 151 // This only supports clearing out the files, but that's OK because for … … 206 159 } 207 160 161 static int nodeWidth(Node* node) 162 { 163 return node ? node->renderBox()->width() : 0; 164 } 165 208 166 int RenderFileUploadControl::maxFilenameWidth() const 209 167 { 210 return max(0, contentWidth() - m_button->renderBox()->width() - afterButtonSpacing168 return max(0, contentWidth() - nodeWidth(uploadButton()) - afterButtonSpacing 211 169 - (m_fileChooser->icon() ? iconWidth + iconFilenameSpacing : 0)); 212 }213 214 PassRefPtr<RenderStyle> RenderFileUploadControl::createButtonStyle(const RenderStyle* parentStyle) const215 {216 RefPtr<RenderStyle> style = getCachedPseudoStyle(FILE_UPLOAD_BUTTON);217 if (!style) {218 style = RenderStyle::create();219 if (parentStyle)220 style->inheritFrom(parentStyle);221 }222 223 // Button text will wrap on file upload controls with widths smaller than the intrinsic button width224 // without this setWhiteSpace.225 style->setWhiteSpace(NOWRAP);226 227 return style.release();228 170 } 229 171 … … 252 194 // Determine where the filename should be placed 253 195 int contentLeft = paintOffset.x() + borderLeft() + paddingLeft(); 254 int buttonAndIconWidth = m_button->renderBox()->width() + afterButtonSpacing 196 HTMLInputElement* button = uploadButton(); 197 if (!button) 198 return; 199 200 int buttonWidth = nodeWidth(button); 201 int buttonAndIconWidth = buttonWidth + afterButtonSpacing 255 202 + (m_fileChooser->icon() ? iconWidth + iconFilenameSpacing : 0); 256 203 int textX; … … 260 207 textX = contentLeft + contentWidth() - buttonAndIconWidth - font.width(textRun); 261 208 // We want to match the button's baseline 262 RenderButton* buttonRenderer = toRenderButton( m_button->renderer());209 RenderButton* buttonRenderer = toRenderButton(button->renderer()); 263 210 int textY = buttonRenderer->absoluteBoundingBoxRect().y() 264 211 + buttonRenderer->marginTop() + buttonRenderer->borderTop() + buttonRenderer->paddingTop() … … 275 222 int iconX; 276 223 if (style()->isLeftToRightDirection()) 277 iconX = contentLeft + m_button->renderBox()->width()+ afterButtonSpacing;224 iconX = contentLeft + buttonWidth + afterButtonSpacing; 278 225 else 279 iconX = contentLeft + contentWidth() - m_button->renderBox()->width()- afterButtonSpacing - iconWidth;226 iconX = contentLeft + contentWidth() - buttonWidth - afterButtonSpacing - iconWidth; 280 227 281 228 // Draw the file icon … … 334 281 } 335 282 283 HTMLInputElement* RenderFileUploadControl::uploadButton() const 284 { 285 HTMLInputElement* input = static_cast<HTMLInputElement*>(node()); 286 287 ASSERT(input->shadowRoot()); 288 289 Node* buttonNode = input->shadowRoot()->firstChild(); 290 return buttonNode && buttonNode->isHTMLElement() && buttonNode->hasTagName(inputTag) ? static_cast<HTMLInputElement*>(buttonNode) : 0; 291 } 292 336 293 void RenderFileUploadControl::receiveDroppedFiles(const Vector<String>& paths) 337 294 { … … 351 308 String RenderFileUploadControl::buttonValue() 352 309 { 353 if ( !m_button)354 return String();310 if (HTMLInputElement* button = uploadButton()) 311 return button->value(); 355 312 356 return m_button->value();313 return String(); 357 314 } 358 315 -
trunk/Source/WebCore/rendering/RenderFileUploadControl.h
r88087 r88115 55 55 virtual void paintObject(PaintInfo&, const IntPoint&); 56 56 57 virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle);58 59 57 virtual bool requiresForcedStyleRecalcPropagation() const { return true; } 60 58 … … 76 74 virtual VisiblePosition positionForPoint(const IntPoint&); 77 75 78 RefPtr<HTMLInputElement> m_button; 76 HTMLInputElement* uploadButton() const; 77 79 78 RefPtr<FileChooser> m_fileChooser; 80 79 }; -
trunk/Source/WebCore/rendering/style/RenderStyleConstants.h
r87660 r88115 75 75 NOPSEUDO, FIRST_LINE, FIRST_LETTER, BEFORE, AFTER, SELECTION, FIRST_LINE_INHERITED, SCROLLBAR, 76 76 // Internal IDs follow: 77 FILE_UPLOAD_BUTTON,INPUT_PLACEHOLDER,77 INPUT_PLACEHOLDER, 78 78 SCROLLBAR_THUMB, SCROLLBAR_BUTTON, SCROLLBAR_TRACK, SCROLLBAR_TRACK_PIECE, SCROLLBAR_CORNER, RESIZER, 79 79 INPUT_LIST_BUTTON, VISITED_LINK, … … 81 81 FULL_SCREEN, FULL_SCREEN_DOCUMENT, FULL_SCREEN_ANCESTOR, ANIMATING_FULL_SCREEN_TRANSITION, 82 82 FIRST_PUBLIC_PSEUDOID = FIRST_LINE, 83 FIRST_INTERNAL_PSEUDOID = FILE_UPLOAD_BUTTON,83 FIRST_INTERNAL_PSEUDOID = INPUT_PLACEHOLDER, 84 84 PUBLIC_PSEUDOID_MASK = ((1 << FIRST_INTERNAL_PSEUDOID) - 1) & ~((1 << FIRST_PUBLIC_PSEUDOID) - 1) 85 85 };
Note: See TracChangeset
for help on using the changeset viewer.