Changeset 89535 in webkit
- Timestamp:
- Jun 22, 2011 11:04:50 PM (13 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r89534 r89535 1 2011-06-22 Dimitri Glazkov <dglazkov@chromium.org> 2 3 Reviewed by Kent Tamura. 4 5 Move file-choosing and icon-loading management to FileInputType 6 https://bugs.webkit.org/show_bug.cgi?id=62069 7 8 1) Moved the duties of FileChooserClient and FileIconLoaderClient from 9 RenderFileUploadControl to FileInputType, along with all of the 10 supporting functions. 11 12 2) Moved Icon ownership to FileInputType and exposed accessor on 13 HTMInputElement to allow RenderFileUploadControl to query current icon. 14 15 As a result, RenderFileUploadControl is now completely stateless, which is 16 neat and clean. 17 18 Refactoring, covered by existing tests. 19 20 * html/FileInputType.cpp: 21 (WebCore::FileInputType::handleDOMActivateEvent): Moved logic here from RenderFileUploadControl. 22 (WebCore::FileInputType::requestIcon): Ditto. 23 (WebCore::FileInputType::filesChosen): Ditto. 24 (WebCore::FileInputType::receiveDropForDirectoryUpload): Ditto. 25 (WebCore::FileInputType::updateRendering): Ditto. 26 (WebCore::FileInputType::chrome): Ditto. 27 (WebCore::FileInputType::receiveDroppedFiles): Ditto. 28 (WebCore::FileInputType::icon): Added. 29 * html/FileInputType.h: 30 * html/HTMLInputElement.cpp: 31 (WebCore::HTMLInputElement::setValueFromRenderer): Updated comment. 32 (WebCore::HTMLInputElement::receiveDroppedFiles): Added to replace setFileListFromRenderer. 33 (WebCore::HTMLInputElement::icon): Added. 34 * html/HTMLInputElement.h: 35 * html/InputType.cpp: 36 (WebCore::InputType::receiveDroppedFiles): Added. 37 (WebCore::InputType::icon): Added. 38 * html/InputType.h: 39 * page/DragController.cpp: 40 (WebCore::DragController::concludeEditDrag): Changed to use HTMLInputElement. Ahh, nice and clean! 41 * rendering/RenderFileUploadControl.cpp: 42 (WebCore::RenderFileUploadControl::RenderFileUploadControl): Removed code that is no longer necessary. 43 (WebCore::RenderFileUploadControl::updateFromElement): Ditto. 44 (WebCore::RenderFileUploadControl::maxFilenameWidth): Changed to use HTMLInputElement icon accessor. 45 (WebCore::RenderFileUploadControl::paintObject): Ditto. 46 * rendering/RenderFileUploadControl.h: 47 1 48 2011-06-22 Pratik Solanki <psolanki@apple.com> 2 49 -
trunk/Source/WebCore/html/FileInputType.cpp
r88115 r89535 23 23 #include "FileInputType.h" 24 24 25 #include "Chrome.h" 25 26 #include "Event.h" 26 27 #include "File.h" … … 28 29 #include "FileSystem.h" 29 30 #include "FormDataList.h" 31 #include "Frame.h" 30 32 #include "HTMLInputElement.h" 31 33 #include "HTMLNames.h" 34 #include "Icon.h" 32 35 #include "LocalizedStrings.h" 36 #include "Page.h" 33 37 #include "RenderFileUploadControl.h" 38 #include "ScriptController.h" 34 39 #include "ShadowRoot.h" 35 40 #include <wtf/PassOwnPtr.h> … … 129 134 if (element()->disabled() || !element()->renderer()) 130 135 return; 131 toRenderFileUploadControl(element()->renderer())->click(); 136 137 if (!ScriptController::processingUserGesture()) 138 return; 139 140 if (Chrome* chrome = this->chrome()) { 141 FileChooserSettings settings; 142 HTMLInputElement* input = element(); 143 #if ENABLE(DIRECTORY_UPLOAD) 144 settings.allowsDirectoryUpload = input->fastHasAttribute(webkitdirectoryAttr); 145 settings.allowsMultipleFiles = settings.allowsDirectoryUpload || input->fastHasAttribute(multipleAttr); 146 #else 147 settings.allowsMultipleFiles = input->fastHasAttribute(multipleAttr); 148 #endif 149 settings.acceptTypes = input->accept(); 150 ASSERT(input->files()); 151 settings.selectedFiles = input->files()->filenames(); 152 chrome->runOpenPanel(input->document()->frame(), newFileChooser(settings)); 153 } 132 154 event->setDefaultHandled(); 133 155 } … … 231 253 } 232 254 255 void FileInputType::requestIcon(const Vector<String>& filenames) 256 { 257 if (!filenames.size()) 258 return; 259 260 if (Chrome* chrome = this->chrome()) 261 chrome->loadIconForFiles(filenames, newFileIconLoader()); 262 } 263 264 void FileInputType::filesChosen(const Vector<String>& filenames) 265 { 266 HTMLInputElement* input = element(); 267 setFileList(filenames); 268 269 input->setFormControlValueMatchesRenderer(true); 270 input->notifyFormStateChanged(); 271 input->setNeedsValidityCheck(); 272 273 requestIcon(filenames); 274 275 if (input->renderer()) 276 input->renderer()->repaint(); 277 // This call may cause destruction of this instance and thus must always be last in the function. 278 input->dispatchFormControlChangeEvent(); 279 } 280 281 #if ENABLE(DIRECTORY_UPLOAD) 282 void FileInputType::receiveDropForDirectoryUpload(const Vector<String>& paths) 283 { 284 if (Chrome* chrome = this->chrome()) { 285 FileChooserSettings settings; 286 settings.allowsDirectoryUpload = true; 287 settings.allowsMultipleFiles = true; 288 settings.selectedFiles.append(paths[0]); 289 chrome->enumerateChosenDirectory(newFileChooser(settings)); 290 } 291 } 292 #endif 293 294 void FileInputType::updateRendering(PassRefPtr<Icon> icon) 295 { 296 if (m_icon == icon) 297 return; 298 299 m_icon = icon; 300 if (element()->renderer()) 301 element()->renderer()->repaint(); 302 } 303 304 Chrome* FileInputType::chrome() const 305 { 306 if (Page* page = element()->document()->page()) 307 return page->chrome(); 308 return 0; 309 } 310 311 void FileInputType::receiveDroppedFiles(const Vector<String>& paths) 312 { 313 HTMLInputElement* input = element(); 314 #if ENABLE(DIRECTORY_UPLOAD) 315 if (input->fastHasAttribute(webkitdirectoryAttr)) { 316 receiveDropForDirectoryUpload(paths); 317 return; 318 } 319 #endif 320 321 if (input->fastHasAttribute(multipleAttr)) 322 filesChosen(paths); 323 else { 324 Vector<String> firstPathOnly; 325 firstPathOnly.append(paths[0]); 326 filesChosen(firstPathOnly); 327 } 328 } 329 330 Icon* FileInputType::icon() const 331 { 332 return m_icon.get(); 333 } 334 233 335 } // namespace WebCore -
trunk/Source/WebCore/html/FileInputType.h
r88115 r89535 34 34 35 35 #include "BaseButtonInputType.h" 36 #include "FileChooser.h" 37 #include "FileIconLoader.h" 36 38 #include <wtf/RefPtr.h> 37 39 38 40 namespace WebCore { 39 41 42 class Chrome; 40 43 class FileList; 41 44 42 class FileInputType : public BaseButtonInputType {45 class FileInputType : public BaseButtonInputType, private FileChooserClient, private FileIconLoaderClient { 43 46 public: 44 47 static PassOwnPtr<InputType> create(HTMLInputElement*); … … 58 61 virtual bool getTypeSpecificValue(String&); // Checked first, before internal storage or the value attribute. 59 62 virtual bool storesValueSeparateFromAttribute(); 60 virtual void setFileList(const Vector<String>& paths); 63 virtual void receiveDroppedFiles(const Vector<String>&); 64 virtual Icon* icon() const; 61 65 virtual bool isFileUpload() const; 62 66 virtual void createShadowSubtree(); 63 67 68 // FileChooserClient implementation. 69 virtual void filesChosen(const Vector<String>&); 70 71 // FileIconLoaderClient implementation. 72 virtual void updateRendering(PassRefPtr<Icon>); 73 74 void setFileList(const Vector<String>& paths); 75 #if ENABLE(DIRECTORY_UPLOAD) 76 void receiveDropForDirectoryUpload(const Vector<String>&); 77 #endif 78 void requestIcon(const Vector<String>&); 79 Chrome* chrome() const; 80 64 81 RefPtr<FileList> m_fileList; 82 RefPtr<Icon> m_icon; 65 83 }; 66 84 -
trunk/Source/WebCore/html/HTMLInputElement.cpp
r89460 r89535 46 46 #include "HTMLOptionElement.h" 47 47 #include "HTMLParserIdioms.h" 48 #include "Icon.h" 48 49 #include "InputType.h" 49 50 #include "KeyboardEvent.h" … … 1058 1059 void HTMLInputElement::setValueFromRenderer(const String& value) 1059 1060 { 1060 // File upload controls will always use setFileListFromRenderer.1061 // File upload controls will never use this. 1061 1062 ASSERT(!isFileUpload()); 1062 1063 … … 1084 1085 // Clear autofill flag (and yellow background) on user edit. 1085 1086 setAutofilled(false); 1086 }1087 1088 void HTMLInputElement::setFileListFromRenderer(const Vector<String>& paths)1089 {1090 m_inputType->setFileList(paths);1091 1092 setFormControlValueMatchesRenderer(true);1093 notifyFormStateChanged();1094 setNeedsValidityCheck();1095 1087 } 1096 1088 … … 1274 1266 { 1275 1267 return m_inputType->files(); 1268 } 1269 1270 void HTMLInputElement::receiveDroppedFiles(const Vector<String>& filenames) 1271 { 1272 m_inputType->receiveDroppedFiles(filenames); 1273 } 1274 1275 Icon* HTMLInputElement::icon() const 1276 { 1277 return m_inputType->icon(); 1276 1278 } 1277 1279 -
trunk/Source/WebCore/html/HTMLInputElement.h
r89460 r89535 32 32 class HTMLDataListElement; 33 33 class HTMLOptionElement; 34 class Icon; 34 35 class InputType; 35 36 class KURL; … … 164 165 165 166 void setValueFromRenderer(const String&); 166 void setFileListFromRenderer(const Vector<String>&);167 167 168 168 bool canHaveSelection() const; … … 203 203 204 204 FileList* files(); 205 void receiveDroppedFiles(const Vector<String>&); 206 Icon* icon() const; 205 207 206 208 void addSearchResult(); … … 227 229 bool lastChangeWasUserEdit() const; 228 230 void cacheSelection(int start, int end); 231 void notifyFormStateChanged(); 229 232 230 233 static const int maximumLength; … … 319 322 HTMLDataListElement* dataList() const; 320 323 #endif 321 void notifyFormStateChanged();322 324 void parseMaxLengthAttribute(Attribute*); 323 325 void updateValueIfNeeded(); -
trunk/Source/WebCore/html/InputType.cpp
r89194 r89535 538 538 } 539 539 540 void InputType:: setFileList(const Vector<String>&)540 void InputType::receiveDroppedFiles(const Vector<String>&) 541 541 { 542 542 ASSERT_NOT_REACHED(); 543 } 544 545 Icon* InputType::icon() const 546 { 547 ASSERT_NOT_REACHED(); 548 return 0; 543 549 } 544 550 -
trunk/Source/WebCore/html/InputType.h
r89460 r89535 49 49 class HTMLFormElement; 50 50 class HTMLInputElement; 51 class Icon; 51 52 class KeyboardEvent; 52 53 class MouseEvent; … … 210 211 virtual bool shouldRespectAlignAttribute(); 211 212 virtual FileList* files(); 213 virtual void receiveDroppedFiles(const Vector<String>&); 214 virtual Icon* icon() const; 212 215 // Should return true if the corresponding renderer for a type can display a suggested value. 213 216 virtual bool canSetSuggestedValue(); … … 215 218 virtual bool canSetValue(const String&); 216 219 virtual bool storesValueSeparateFromAttribute(); 217 virtual void setFileList(const Vector<String>& paths);218 220 virtual bool shouldResetOnDocumentActivation(); 219 221 virtual bool shouldRespectListAttribute(); -
trunk/Source/WebCore/page/DragController.cpp
r88476 r89535 421 421 return false; 422 422 423 // Ugly. For security none of the APIs available to us can set the input value 424 // on file inputs. Even forcing a change in HTMLInputElement doesn't work as 425 // RenderFileUploadControl clears the file when doing updateFromElement(). 426 RenderFileUploadControl* renderer = toRenderFileUploadControl(fileInput->renderer()); 427 if (!renderer) 428 return false; 429 430 renderer->receiveDroppedFiles(filenames); 423 fileInput->receiveDroppedFiles(filenames); 431 424 return true; 432 425 } -
trunk/Source/WebCore/rendering/RenderFileUploadControl.cpp
r89526 r89535 22 22 #include "RenderFileUploadControl.h" 23 23 24 #include "Chrome.h"25 24 #include "FileList.h" 26 #include "Frame.h"27 #include "FrameView.h"28 25 #include "GraphicsContext.h" 29 26 #include "HTMLInputElement.h" … … 31 28 #include "Icon.h" 32 29 #include "LocalizedStrings.h" 33 #include "Page.h"34 30 #include "PaintInfo.h" 35 31 #include "RenderButton.h" 36 32 #include "RenderText.h" 37 33 #include "RenderTheme.h" 38 #include "RenderView.h"39 #include "ScriptController.h"40 34 #include "ShadowRoot.h" 41 35 #include "TextRun.h" 36 #include "VisiblePosition.h" 42 37 #include <math.h> 43 38 … … 58 53 : RenderBlock(input) 59 54 { 60 ASSERT(input->files());61 requestIcon(input->files()->filenames());62 55 } 63 56 … … 66 59 } 67 60 68 void RenderFileUploadControl::requestIcon(const Vector<String>& filenames)69 {70 if (!filenames.size())71 return;72 73 if (Chrome* chrome = this->chrome())74 chrome->loadIconForFiles(filenames, newFileIconLoader());75 }76 77 void RenderFileUploadControl::filesChosen(const Vector<String>& filenames)78 {79 HTMLInputElement* inputElement = static_cast<HTMLInputElement*>(node());80 inputElement->setFileListFromRenderer(filenames);81 requestIcon(filenames);82 83 repaint();84 // This call may cause destruction of this instance and thus must always be last in the function.85 inputElement->dispatchFormControlChangeEvent();86 }87 88 #if ENABLE(DIRECTORY_UPLOAD)89 void RenderFileUploadControl::receiveDropForDirectoryUpload(const Vector<String>& paths)90 {91 if (Chrome* chrome = this->chrome()) {92 FileChooserSettings settings;93 settings.allowsDirectoryUpload = true;94 settings.allowsMultipleFiles = true;95 settings.selectedFiles.append(paths[0]);96 chrome->enumerateChosenDirectory(newFileChooser(settings));97 }98 }99 #endif100 101 102 void RenderFileUploadControl::updateRendering(PassRefPtr<Icon> icon)103 {104 if (m_icon == icon)105 return;106 107 m_icon = icon;108 repaint();109 }110 111 void RenderFileUploadControl::click()112 {113 if (!ScriptController::processingUserGesture())114 return;115 116 if (Chrome* chrome = this->chrome()) {117 FileChooserSettings settings;118 HTMLInputElement* input = static_cast<HTMLInputElement*>(node());119 #if ENABLE(DIRECTORY_UPLOAD)120 settings.allowsDirectoryUpload = input->fastHasAttribute(webkitdirectoryAttr);121 settings.allowsMultipleFiles = settings.allowsDirectoryUpload || input->fastHasAttribute(multipleAttr);122 #else123 settings.allowsMultipleFiles = input->fastHasAttribute(multipleAttr);124 #endif125 settings.acceptTypes = input->accept();126 ASSERT(input->files());127 settings.selectedFiles = input->files()->filenames();128 chrome->runOpenPanel(frame(), newFileChooser(settings));129 }130 }131 132 Chrome* RenderFileUploadControl::chrome() const133 {134 Frame* frame = node()->document()->frame();135 if (!frame)136 return 0;137 Page* page = frame->page();138 if (!page)139 return 0;140 return page->chrome();141 }142 143 61 void RenderFileUploadControl::updateFromElement() 144 62 { 145 HTMLInputElement* inputElement = static_cast<HTMLInputElement*>(node());146 ASSERT(inputElement->isFileUpload());147 148 149 63 if (HTMLInputElement* button = uploadButton()) 150 64 button->setDisabled(!theme()->isEnabled(this)); 151 152 // This only supports clearing out the files, but that's OK because for153 // security reasons that's the only change the DOM is allowed to make.154 FileList* files = inputElement->files();155 ASSERT(files);156 if (files && files->isEmpty() && m_icon) {157 m_icon = 0;158 repaint();159 }160 65 } 161 66 … … 167 72 int RenderFileUploadControl::maxFilenameWidth() const 168 73 { 74 HTMLInputElement* input = static_cast<HTMLInputElement*>(node()); 169 75 return max(0, contentWidth() - nodeWidth(uploadButton()) - afterButtonSpacing 170 - ( m_icon? iconWidth + iconFilenameSpacing : 0));76 - (input->icon() ? iconWidth + iconFilenameSpacing : 0)); 171 77 } 172 78 … … 198 104 return; 199 105 106 HTMLInputElement* input = static_cast<HTMLInputElement*>(node()); 200 107 int buttonWidth = nodeWidth(button); 201 108 int buttonAndIconWidth = buttonWidth + afterButtonSpacing 202 + ( m_icon? iconWidth + iconFilenameSpacing : 0);109 + (input->icon() ? iconWidth + iconFilenameSpacing : 0); 203 110 int textX; 204 111 if (style()->isLeftToRightDirection()) … … 217 124 paintInfo.context->drawBidiText(font, textRun, IntPoint(textX, textY)); 218 125 219 if ( m_icon) {126 if (input->icon()) { 220 127 // Determine where the icon should be placed 221 128 int iconY = paintOffset.y() + borderTop() + paddingTop() + (contentHeight() - iconHeight) / 2; … … 227 134 228 135 // Draw the file icon 229 m_icon->paint(paintInfo.context, IntRect(iconX, iconY, iconWidth, iconHeight));136 input->icon()->paint(paintInfo.context, IntRect(iconX, iconY, iconWidth, iconHeight)); 230 137 } 231 138 } … … 291 198 } 292 199 293 void RenderFileUploadControl::receiveDroppedFiles(const Vector<String>& paths)294 {295 HTMLInputElement* input = static_cast<HTMLInputElement*>(node());296 #if ENABLE(DIRECTORY_UPLOAD)297 if (input->fastHasAttribute(webkitdirectoryAttr)) {298 receiveDropForDirectoryUpload(paths);299 return;300 }301 #endif302 303 if (input->fastHasAttribute(multipleAttr))304 filesChosen(paths);305 else {306 Vector<String> firstPathOnly;307 firstPathOnly.append(paths[0]);308 filesChosen(firstPathOnly);309 }310 }311 312 200 String RenderFileUploadControl::buttonValue() 313 201 { -
trunk/Source/WebCore/rendering/RenderFileUploadControl.h
r89526 r89535 22 22 #define RenderFileUploadControl_h 23 23 24 #include "FileChooser.h"25 #include "FileIconLoader.h"26 24 #include "RenderBlock.h" 27 25 28 26 namespace WebCore { 29 27 30 class Chrome;31 28 class HTMLInputElement; 32 29 … … 35 32 // associated with it to receive click/hover events. 36 33 37 class RenderFileUploadControl : public RenderBlock , private FileChooserClient, private FileIconLoaderClient{34 class RenderFileUploadControl : public RenderBlock { 38 35 public: 39 36 RenderFileUploadControl(HTMLInputElement*); … … 41 38 42 39 virtual bool isFileUploadControl() const { return true; } 43 44 void click();45 46 void receiveDroppedFiles(const Vector<String>&);47 40 48 41 String buttonValue(); … … 58 51 virtual bool requiresForcedStyleRecalcPropagation() const { return true; } 59 52 60 // FileChooserClient implementation.61 virtual void filesChosen(const Vector<String>&);62 63 // FileIconLoaderClient implementation.64 virtual void updateRendering(PassRefPtr<Icon>);65 66 #if ENABLE(DIRECTORY_UPLOAD)67 void receiveDropForDirectoryUpload(const Vector<String>&);68 #endif69 70 Chrome* chrome() const;71 53 int maxFilenameWidth() const; 72 54 … … 74 56 75 57 HTMLInputElement* uploadButton() const; 76 void requestIcon(const Vector<String>&);77 78 RefPtr<Icon> m_icon;79 58 }; 80 59
Note: See TracChangeset
for help on using the changeset viewer.