+2006-09-12 Adam Roben <aroben@apple.com>
+
+ Reviewed many times by darin, hyatt.
+
+ Switch to new engine-based implementation of <input type="file">
+
+ * WebCore.exp: Remove obsolete symbol WebCoreFileButton
+ * WebCore.xcodeproj/project.pbxproj: Remove files for old widget-based
+ control, add files for new engine-based control
+ * css/CSSSelector.cpp: Add support for new
+ '-webkit-file-upload-button' pseudo element
+ (WebCore::CSSSelector::extractPseudoType):
+ * css/CSSSelector.h: Ditto.
+ (WebCore::CSSSelector::):
+ * css/cssstyleselector.cpp: Ditto.
+ (WebCore::CSSStyleSelector::checkOneSelector):
+ * html/HTMLInputElement.cpp: Send click events to new control
+ (WebCore::HTMLInputElement::select):
+ (WebCore::HTMLInputElement::click):
+ (WebCore::HTMLInputElement::createRenderer):
+ (WebCore::HTMLInputElement::valueWithDefault):
+ (WebCore::HTMLInputElement::defaultEventHandler):
+ * html/HTMLTextFieldInnerElement.h: Add 'virtual' keyword
+ (WebCore::HTMLTextFieldInnerElement::shadowParentNode):
+ * platform/FileButton.h: Removed.
+ * platform/FileChooser.h: Added. This is the replacement for
+ FileButton.h
+ (WebCore::FileChooser::filename):
+ (WebCore::FileChooser::icon):
+ (WebCore::FileChooser::uploadControl):
+ (WebCore::FileChooser::document):
+ * platform/Icon.h: Added new platform-specific class representing a
+ file icon.
+ * platform/LocalizedStrings.h:
+ * platform/mac/FileButtonMac.mm: Removed.
+ * platform/mac/FileChooserMac.mm: Added. This is the replacement for
+ FileButtonMac.mm
+ (-[OpenPanelController initWithFileChooser:]):
+ (-[OpenPanelController fileChooserDetachingSoon]):
+ (-[OpenPanelController beginSheet]):
+ (-[OpenPanelController chooseFilename:]):
+ (-[OpenPanelController cancel]):
+ (WebCore::FileChooser::FileChooser):
+ (WebCore::FileChooser::~FileChooser):
+ (WebCore::FileChooser::openFileChooser):
+ (WebCore::FileChooser::basenameForWidth):
+ (WebCore::FileChooser::uploadControlDetaching):
+ (WebCore::FileChooser::chooseFile):
+ * platform/mac/IconMac.mm: Added.
+ (WebCore::Icon::Icon):
+ (WebCore::Icon::~Icon):
+ (WebCore::Icon::newIconForFile):
+ (WebCore::Icon::paint):
+ * platform/mac/LocalizedStringsMac.mm: Call across bridge to get
+ localized strings.
+ (WebCore::fileButtonChooseFileLabel):
+ (WebCore::fileButtonNoFileSelectedLabel):
+ * rendering/RenderButton.cpp: Extract method setText() from
+ updateFromElement.
+ (WebCore::RenderButton::updateFromElement):
+ (WebCore::RenderButton::setText):
+ * rendering/RenderButton.h: Add declaration for new setText method.
+ * rendering/RenderFileButton.cpp: Removed.
+ * rendering/RenderFileButton.h: Removed.
+ * rendering/RenderFileUploadControl.cpp: Added. This is the
+ replacement for RenderFileButton.cpp.
+ (WebCore::RenderFileUploadInnerFileBox::renderName):
+ (WebCore::HTMLFileUploadInnerButtonElement::isShadowNode):
+ (WebCore::HTMLFileUploadInnerButtonElement::shadowParentNode):
+ (WebCore::RenderFileUploadControl::RenderFileUploadControl):
+ (WebCore::RenderFileUploadControl::~RenderFileUploadControl):
+ (WebCore::RenderFileUploadControl::setStyle):
+ (WebCore::RenderFileUploadControl::updateIconAndFilename):
+ (WebCore::RenderFileUploadControl::click):
+ (WebCore::RenderFileUploadControl::updateFromElement):
+ (WebCore::RenderFileUploadControl::maxFilenameWidth):
+ (WebCore::RenderFileUploadControl::createButtonStyle):
+ (WebCore::RenderFileUploadControl::paintObject):
+ (WebCore::RenderFileUploadInnerFileBox::RenderFileUploadInnerFileBox):
+ (WebCore::RenderFileUploadInnerFileBox::setStyle):
+ (WebCore::RenderFileUploadInnerFileBox::layout):
+ (WebCore::RenderFileUploadInnerFileBox::setHasIcon):
+ (WebCore::RenderFileUploadInnerFileBox::setFilename):
+ (WebCore::RenderFileUploadInnerFileBox::calcMinMaxWidth):
+ (WebCore::HTMLFileUploadInnerButtonElement::HTMLFileUploadInnerButtonElement):
+ (WebCore::HTMLFileUploadInnerButtonElement::createRenderer):
+ * rendering/RenderFileUploadControl.h: Added. This is the replacement
+ for RenderFileButton.h.
+ (WebCore::RenderFileUploadControl::renderName):
+ * rendering/RenderStyle.cpp: Add support for
+ -webkit-file-upload-button pseudo element.
+ (WebCore::):
+ (WebCore::pseudoBit):
+ * rendering/RenderStyle.h: Ditto.
+ (WebCore::RenderStyle::):
+
2006-09-12 Anders Carlsson <acarlsson@apple.com>
Reviewed by John Sullivan.
.objc_class_name_DOMWheelEvent
.objc_class_name_WebCoreCache
.objc_class_name_WebCoreEncodings
-.objc_class_name_WebCoreFileButton
.objc_class_name_WebCoreFrameBridge
.objc_class_name_WebCoreFrameNamespaces
.objc_class_name_WebCoreHistory
/* End PBXAggregateTarget section */
/* Begin PBXBuildFile section */
+ 066C772B0AB603B700238CC4 /* FileChooser.h in Headers */ = {isa = PBXBuildFile; fileRef = 066C772A0AB603B700238CC4 /* FileChooser.h */; };
+ 066C772D0AB603D200238CC4 /* FileChooserMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 066C772C0AB603D200238CC4 /* FileChooserMac.mm */; };
+ 066C77300AB603FD00238CC4 /* RenderFileUploadControl.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 066C772E0AB603FD00238CC4 /* RenderFileUploadControl.cpp */; };
+ 066C77310AB603FD00238CC4 /* RenderFileUploadControl.h in Headers */ = {isa = PBXBuildFile; fileRef = 066C772F0AB603FD00238CC4 /* RenderFileUploadControl.h */; };
+ 066C773C0AB6052700238CC4 /* Icon.h in Headers */ = {isa = PBXBuildFile; fileRef = 066C773B0AB6052700238CC4 /* Icon.h */; };
+ 066C773E0AB6053F00238CC4 /* IconMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 066C773D0AB6053F00238CC4 /* IconMac.mm */; };
06E81ED70AB5D5E900C87837 /* LocalCurrentGraphicsContext.h in Headers */ = {isa = PBXBuildFile; fileRef = 06E81ED60AB5D5E900C87837 /* LocalCurrentGraphicsContext.h */; };
06E81EEC0AB5DA9700C87837 /* LocalCurrentGraphicsContext.mm in Sources */ = {isa = PBXBuildFile; fileRef = 06E81EEB0AB5DA9700C87837 /* LocalCurrentGraphicsContext.mm */; };
1403B99709EB13AF00797C7F /* DOMWindow.h in Headers */ = {isa = PBXBuildFile; fileRef = 1403B99509EB13AF00797C7F /* DOMWindow.h */; };
93F1992908245E59001E9ABC /* DeprecatedCString.h in Headers */ = {isa = PBXBuildFile; fileRef = F587868302DE3B8601EA4122 /* DeprecatedCString.h */; };
93F1992E08245E59001E9ABC /* PopUpButton.h in Headers */ = {isa = PBXBuildFile; fileRef = F587868202DE3B8601EA4122 /* PopUpButton.h */; };
93F1992F08245E59001E9ABC /* Cursor.h in Headers */ = {isa = PBXBuildFile; fileRef = F587868402DE3B8601EA4122 /* Cursor.h */; };
- 93F1993908245E59001E9ABC /* FileButton.h in Headers */ = {isa = PBXBuildFile; fileRef = 93CCF7D4033BD43C008635CE /* FileButton.h */; };
93F1994F08245E59001E9ABC /* Settings.h in Headers */ = {isa = PBXBuildFile; fileRef = F587863A02DE3A1401EA4122 /* Settings.h */; };
93F1995008245E59001E9ABC /* CachePolicy.h in Headers */ = {isa = PBXBuildFile; fileRef = F587864902DE3A9A01EA4122 /* CachePolicy.h */; };
93F1995408245E59001E9ABC /* JavaAppletWidget.h in Headers */ = {isa = PBXBuildFile; fileRef = F587864502DE3A7701EA4122 /* JavaAppletWidget.h */; };
93F19AC208245E59001E9ABC /* WebCoreSettings.mm in Sources */ = {isa = PBXBuildFile; fileRef = F565AE8602ECA583018635CA /* WebCoreSettings.mm */; };
93F19AC608245E59001E9ABC /* WebCoreEncodings.mm in Sources */ = {isa = PBXBuildFile; fileRef = F56234E003026D7301629B47 /* WebCoreEncodings.mm */; };
93F19AC808245E59001E9ABC /* WebCoreHistory.m in Sources */ = {isa = PBXBuildFile; fileRef = F5517DC3031AB56301A80180 /* WebCoreHistory.m */; };
- 93F19ACC08245E59001E9ABC /* FileButtonMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 93CCF7D5033BD43C008635CE /* FileButtonMac.mm */; };
93F19ACD08245E59001E9ABC /* WebCoreResourceLoaderImp.mm in Sources */ = {isa = PBXBuildFile; fileRef = 93386B91037045B3008635CE /* WebCoreResourceLoaderImp.mm */; };
93F19AD208245E59001E9ABC /* WebCorePageState.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9394E0A503AA5BBE008635CE /* WebCorePageState.mm */; };
93F19AD508245E59001E9ABC /* RenderTreeAsText.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93955A4203D72932008635CE /* RenderTreeAsText.cpp */; };
A8EA73C30A1900E300A8EF5F /* RenderFieldset.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A8EA73AF0A1900E300A8EF5F /* RenderFieldset.cpp */; };
A8EA73C40A1900E300A8EF5F /* RenderFieldset.h in Headers */ = {isa = PBXBuildFile; fileRef = A8EA73B00A1900E300A8EF5F /* RenderFieldset.h */; };
A8EA73C50A1900E300A8EF5F /* RenderLineEdit.h in Headers */ = {isa = PBXBuildFile; fileRef = A8EA73B10A1900E300A8EF5F /* RenderLineEdit.h */; };
- A8EA73C60A1900E300A8EF5F /* RenderFileButton.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A8EA73B20A1900E300A8EF5F /* RenderFileButton.cpp */; };
- A8EA73C70A1900E300A8EF5F /* RenderFileButton.h in Headers */ = {isa = PBXBuildFile; fileRef = A8EA73B30A1900E300A8EF5F /* RenderFileButton.h */; };
A8EA73C90A1900E300A8EF5F /* RenderFormElement.h in Headers */ = {isa = PBXBuildFile; fileRef = A8EA73B50A1900E300A8EF5F /* RenderFormElement.h */; };
A8EA73CA0A1900E300A8EF5F /* RenderLegend.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A8EA73B60A1900E300A8EF5F /* RenderLegend.cpp */; };
A8EA73CB0A1900E300A8EF5F /* RenderLabel.h in Headers */ = {isa = PBXBuildFile; fileRef = A8EA73B70A1900E300A8EF5F /* RenderLabel.h */; };
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
+ 066C772A0AB603B700238CC4 /* FileChooser.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = FileChooser.h; sourceTree = "<group>"; };
+ 066C772C0AB603D200238CC4 /* FileChooserMac.mm */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.objcpp; path = FileChooserMac.mm; sourceTree = "<group>"; };
+ 066C772E0AB603FD00238CC4 /* RenderFileUploadControl.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = RenderFileUploadControl.cpp; sourceTree = "<group>"; };
+ 066C772F0AB603FD00238CC4 /* RenderFileUploadControl.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = RenderFileUploadControl.h; sourceTree = "<group>"; };
+ 066C773B0AB6052700238CC4 /* Icon.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = Icon.h; sourceTree = "<group>"; };
+ 066C773D0AB6053F00238CC4 /* IconMac.mm */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.objcpp; path = IconMac.mm; sourceTree = "<group>"; };
06E81ED60AB5D5E900C87837 /* LocalCurrentGraphicsContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LocalCurrentGraphicsContext.h; sourceTree = "<group>"; };
06E81EEB0AB5DA9700C87837 /* LocalCurrentGraphicsContext.mm */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.objcpp; path = LocalCurrentGraphicsContext.mm; sourceTree = "<group>"; };
1403B90C09EB124500797C7F /* DOMWindow.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = DOMWindow.idl; sourceTree = "<group>"; };
93CA4C9F09DF93FA00DF8677 /* quirks.css */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = quirks.css; sourceTree = "<group>"; };
93CA4CA209DF93FA00DF8677 /* svg.css */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = svg.css; sourceTree = "<group>"; };
93CA4CA309DF93FA00DF8677 /* tokenizer.flex */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = tokenizer.flex; sourceTree = "<group>"; };
- 93CCF7D4033BD43C008635CE /* FileButton.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = FileButton.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
- 93CCF7D5033BD43C008635CE /* FileButtonMac.mm */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FileButtonMac.mm; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
93CD4FD70995F9EA007ECC97 /* AtomicString.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AtomicString.cpp; sourceTree = "<group>"; };
93CD4FD80995F9EA007ECC97 /* AtomicString.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AtomicString.h; sourceTree = "<group>"; };
93CD4FD90995F9EA007ECC97 /* AtomicStringImpl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AtomicStringImpl.h; sourceTree = "<group>"; };
A8EA73AF0A1900E300A8EF5F /* RenderFieldset.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = RenderFieldset.cpp; sourceTree = "<group>"; };
A8EA73B00A1900E300A8EF5F /* RenderFieldset.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = RenderFieldset.h; sourceTree = "<group>"; };
A8EA73B10A1900E300A8EF5F /* RenderLineEdit.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = RenderLineEdit.h; sourceTree = "<group>"; };
- A8EA73B20A1900E300A8EF5F /* RenderFileButton.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = RenderFileButton.cpp; sourceTree = "<group>"; };
- A8EA73B30A1900E300A8EF5F /* RenderFileButton.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = RenderFileButton.h; sourceTree = "<group>"; };
A8EA73B50A1900E300A8EF5F /* RenderFormElement.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = RenderFormElement.h; sourceTree = "<group>"; };
A8EA73B60A1900E300A8EF5F /* RenderLegend.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = RenderLegend.cpp; sourceTree = "<group>"; };
A8EA73B70A1900E300A8EF5F /* RenderLabel.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = RenderLabel.h; sourceTree = "<group>"; };
651B4D8E09AC859F0029F1EF /* DeprecatedStringListMac.mm */,
6582A17709999EA000BEEB6D /* DeprecatedStringMac.mm */,
65F5386809B2BFDA00F3DC4A /* ExtraCFEncodings.h */,
- 93CCF7D5033BD43C008635CE /* FileButtonMac.mm */,
+ 066C772C0AB603D200238CC4 /* FileChooserMac.mm */,
6582A14A09999D6C00BEEB6D /* FloatPointMac.mm */,
6582A14B09999D6C00BEEB6D /* FloatRectMac.mm */,
6582A14C09999D6C00BEEB6D /* FloatSizeMac.mm */,
935C476C09AC4D6300A6AAB4 /* FoundationExtras.h */,
BC6DB4D30A1AFEEF00E5CD14 /* GlyphMapMac.cpp */,
935367E809AF77EF00D35CD6 /* GraphicsContextMac.mm */,
+ 066C773D0AB6053F00238CC4 /* IconMac.mm */,
6582A14D09999D6C00BEEB6D /* ImageMac.mm */,
6582A14F09999D6D00BEEB6D /* IntPointMac.mm */,
6582A15009999D6D00BEEB6D /* IntRectMac.mm */,
F58786C202DE3B8601EA4122 /* DeprecatedValueList.h */,
F587853C02DE375901EA4122 /* DeprecatedValueListImpl.cpp */,
F587853B02DE375901EA4122 /* DeprecatedValueListImpl.h */,
- 93CCF7D4033BD43C008635CE /* FileButton.h */,
+ 066C772A0AB603B700238CC4 /* FileChooser.h */,
BC73E3900978CED700EDFF8A /* FloatPoint.cpp */,
BC73E3910978CED700EDFF8A /* FloatPoint.h */,
BCB16AF50979A08500467741 /* FloatRect.cpp */,
935367E409AF77DD00D35CD6 /* GraphicsContext.h */,
938E685309F0BE04008A48EC /* GraphicsTypes.cpp */,
938E683B09F0BD7A008A48EC /* GraphicsTypes.h */,
+ 066C773B0AB6052700238CC4 /* Icon.h */,
BC6B7BAE0993603C0052867B /* Image.cpp */,
BCD75ABB0989A446003E28DF /* Image.h */,
BC9C328A09933A6D001D6924 /* ImageAnimationObserver.h */,
BCEA482D097D93020094C9E4 /* RenderContainer.h */,
A8EA73AF0A1900E300A8EF5F /* RenderFieldset.cpp */,
A8EA73B00A1900E300A8EF5F /* RenderFieldset.h */,
- A8EA73B20A1900E300A8EF5F /* RenderFileButton.cpp */,
- A8EA73B30A1900E300A8EF5F /* RenderFileButton.h */,
+ 066C772E0AB603FD00238CC4 /* RenderFileUploadControl.cpp */,
+ 066C772F0AB603FD00238CC4 /* RenderFileUploadControl.h */,
BCEA482E097D93020094C9E4 /* RenderFlexibleBox.cpp */,
BCEA482F097D93020094C9E4 /* RenderFlexibleBox.h */,
BCEA4830097D93020094C9E4 /* RenderFlow.cpp */,
93F1992908245E59001E9ABC /* DeprecatedCString.h in Headers */,
93F1992E08245E59001E9ABC /* PopUpButton.h in Headers */,
93F1992F08245E59001E9ABC /* Cursor.h in Headers */,
- 93F1993908245E59001E9ABC /* FileButton.h in Headers */,
93F1994F08245E59001E9ABC /* Settings.h in Headers */,
93F1995008245E59001E9ABC /* CachePolicy.h in Headers */,
93F1995408245E59001E9ABC /* JavaAppletWidget.h in Headers */,
BC6DADEF0A195FDF00E5CD14 /* WebFontCache.h in Headers */,
A8EA73C40A1900E300A8EF5F /* RenderFieldset.h in Headers */,
A8EA73C50A1900E300A8EF5F /* RenderLineEdit.h in Headers */,
- A8EA73C70A1900E300A8EF5F /* RenderFileButton.h in Headers */,
A8EA73C90A1900E300A8EF5F /* RenderFormElement.h in Headers */,
A8EA73CB0A1900E300A8EF5F /* RenderLabel.h in Headers */,
A8EA73D10A1900E300A8EF5F /* RenderLegend.h in Headers */,
85E9E0A50AB3A0C700069CD0 /* DOMXPathResult.h in Headers */,
51386EE70AB4F0D5004AF79E /* IntSizeHash.h in Headers */,
06E81ED70AB5D5E900C87837 /* LocalCurrentGraphicsContext.h in Headers */,
+ 066C772B0AB603B700238CC4 /* FileChooser.h in Headers */,
+ 066C77310AB603FD00238CC4 /* RenderFileUploadControl.h in Headers */,
+ 066C773C0AB6052700238CC4 /* Icon.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
93F19AC208245E59001E9ABC /* WebCoreSettings.mm in Sources */,
93F19AC608245E59001E9ABC /* WebCoreEncodings.mm in Sources */,
93F19AC808245E59001E9ABC /* WebCoreHistory.m in Sources */,
- 93F19ACC08245E59001E9ABC /* FileButtonMac.mm in Sources */,
93F19ACD08245E59001E9ABC /* WebCoreResourceLoaderImp.mm in Sources */,
93F19AD208245E59001E9ABC /* WebCorePageState.mm in Sources */,
93F19AD508245E59001E9ABC /* RenderTreeAsText.cpp in Sources */,
BC6DABF30A19015700E5CD14 /* FontCache.cpp in Sources */,
BC6DADFA0A19602B00E5CD14 /* WebFontCache.mm in Sources */,
A8EA73C30A1900E300A8EF5F /* RenderFieldset.cpp in Sources */,
- A8EA73C60A1900E300A8EF5F /* RenderFileButton.cpp in Sources */,
A8EA73CA0A1900E300A8EF5F /* RenderLegend.cpp in Sources */,
A8EA73D20A1900E300A8EF5F /* RenderLineEdit.cpp in Sources */,
A8EA73D30A1900E300A8EF5F /* RenderFormElement.cpp in Sources */,
85E9E0A20AB3A0C700069CD0 /* DOMXPathExpression.mm in Sources */,
85E9E0A60AB3A0C700069CD0 /* DOMXPathResult.mm in Sources */,
06E81EEC0AB5DA9700C87837 /* LocalCurrentGraphicsContext.mm in Sources */,
+ 066C772D0AB603D200238CC4 /* FileChooserMac.mm in Sources */,
+ 066C77300AB603FD00238CC4 /* RenderFileUploadControl.cpp in Sources */,
+ 066C773E0AB6053F00238CC4 /* IconMac.mm in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
static AtomicString autofill("-webkit-autofill");
static AtomicString before("before");
static AtomicString checked("checked");
+ static AtomicString fileUploadButton("-webkit-file-upload-button");
static AtomicString disabled("disabled");
static AtomicString drag("-webkit-drag");
static AtomicString empty("empty");
element = compat = true;
} else if (value == checked)
_pseudoType = PseudoChecked;
- else if (value == disabled)
+ else if (value == fileUploadButton) {
+ _pseudoType = PseudoFileUploadButton;
+ element = true;
+ } else if (value == disabled)
_pseudoType = PseudoDisabled;
else if (value == drag)
_pseudoType = PseudoDrag;
PseudoLang,
PseudoNot,
PseudoRoot,
- PseudoSelection
+ PseudoSelection,
+ PseudoFileUploadButton
};
PseudoType pseudoType() const
case CSSSelector::PseudoAfter:
dynamicPseudo = RenderStyle::AFTER;
return true;
+ case CSSSelector::PseudoFileUploadButton:
+ dynamicPseudo = RenderStyle::FILE_UPLOAD_BUTTON;
+ return true;
case CSSSelector::PseudoNotParsed:
assert(false);
#include "LocalizedStrings.h"
#include "MouseEvent.h"
#include "RenderButton.h"
-#include "RenderFileButton.h"
+#include "RenderFileUploadControl.h"
#include "RenderImage.h"
#include "RenderLineEdit.h"
#include "RenderText.h"
case RANGE:
case RESET:
case SUBMIT:
- break;
case FILE:
- static_cast<RenderFileButton*>(renderer())->select();
break;
case SEARCH:
static_cast<RenderLineEdit*>(renderer())->select();
break;
case FILE:
if (renderer()) {
- static_cast<RenderFileButton *>(renderer())->click(sendMouseEvents);
+ static_cast<RenderFileUploadControl*>(renderer())->click(sendMouseEvents);
return;
}
break;
case RADIO:
return RenderObject::createObject(this, style);
case FILE:
- return new (arena) RenderFileButton(this);
+ return new (arena) RenderFileUploadControl(this);
case HIDDEN:
break;
case IMAGE:
switch (inputType()) {
case BUTTON:
case CHECKBOX:
- case FILE:
case HIDDEN:
case IMAGE:
case ISINDEX:
case SEARCH:
case TEXT:
break;
+ case FILE:
+ v = fileButtonChooseFileLabel();
+ break;
case RESET:
v = resetButtonDefaultLabel();
break;
}
m_activeSubmit = false;
}
- }
+ } else if (inputType() == FILE && renderer())
+ static_cast<RenderFileUploadControl*>(renderer())->click(false);
}
// Use key press event here since sending simulated mouse events
virtual void defaultEventHandler(Event*);
virtual bool isShadowNode() const { return true; }
- Node* shadowParentNode() { return m_shadowParent; }
+ virtual Node* shadowParentNode() { return m_shadowParent; }
void setShadowParentNode(Node* node) { m_shadowParent = node; }
private:
+++ /dev/null
-/*
- * Copyright (C) 2003 Apple Computer, Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef FileButton_h
-#define FileButton_h
-
-#include "PlatformString.h"
-#include "Widget.h"
-
-#ifdef __OBJC__
-@class WebCoreFileButton;
-#else
-class WebCoreFileButton;
-#endif
-
-namespace WebCore {
-
- class Frame;
-
-class FileButton : public Widget {
-public:
- FileButton(Frame*);
-
- void setFilename(const DeprecatedString &);
- void click(bool sendMouseEvents);
-
- IntSize sizeForCharacterWidth(int characters) const;
- IntRect frameGeometry() const;
- void setFrameGeometry(const IntRect &);
- int baselinePosition(int height) const;
-
- virtual FocusPolicy focusPolicy() const;
-
- void filenameChanged(const DeprecatedString &);
-
- const String& filename() const { return m_name; }
-
- void setDisabled(bool);
-
-private:
- WebCoreFileButton* _buttonView;
- String m_name;
-};
-
-}
-
-#endif
--- /dev/null
+/*
+ * Copyright (C) 2006 Apple Computer, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ */
+
+#ifndef RENDER_FILECHOOSER_H_
+#define RENDER_FILECHOOSER_H_
+
+#include "Icon.h"
+#include "PlatformString.h"
+#include <wtf/OwnPtr.h>
+
+#if PLATFORM(MAC)
+#ifdef __OBJC__
+@class OpenPanelController;
+#else
+class OpenPanelController;
+#endif
+#endif
+
+using namespace std;
+
+namespace WebCore {
+
+class Document;
+class RenderFileUploadControl;
+class String;
+
+class FileChooser {
+public:
+ FileChooser(Document*, RenderFileUploadControl*);
+ ~FileChooser();
+
+ void openFileChooser();
+
+ const String& filename() const { return m_filename; }
+ String basenameForWidth(int width) const;
+
+ Icon* icon() const { return m_icon.get(); }
+ RenderFileUploadControl* uploadControl() const { return m_uploadControl; }
+ Document* document() { return m_document; }
+
+ void uploadControlDetaching();
+
+ void chooseFile(const String& filename);
+
+private:
+ Document* m_document;
+ String m_filename;
+ OwnPtr<Icon> m_icon;
+ RenderFileUploadControl* m_uploadControl;
+
+#if PLATFORM(MAC)
+ OpenPanelController* m_controller;
+#endif
+};
+
+}
+
+#endif
--- /dev/null
+/*
+ * Copyright (C) 2006 Apple Computer, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ */
+
+#ifndef ICON_H_
+#define ICON_H_
+
+#include <wtf/Noncopyable.h>
+
+#if PLATFORM(MAC)
+#ifdef __OBJC__
+@class NSImage;
+#else
+class NSImage;
+#endif
+#elif PLATFORM(WIN)
+typedef struct HICON__* HICON;
+#endif
+
+using namespace std;
+
+namespace WebCore {
+
+class GraphicsContext;
+class IntRect;
+class String;
+
+class Icon : Noncopyable {
+public:
+ Icon();
+ ~Icon();
+
+ static auto_ptr<Icon> newIconForFile(const String& filename);
+
+ void paint(GraphicsContext*, const IntRect&);
+
+private:
+#if PLATFORM(MAC)
+ NSImage* m_nsImage;
+#elif PLATFORM(WIN)
+ HICON m_hIcon;
+#endif
+};
+
+}
+
+#endif
String resetButtonDefaultLabel();
String searchableIndexIntroduction();
String submitButtonDefaultLabel();
+ String fileButtonChooseFileLabel();
+ String fileButtonNoFileSelectedLabel();
}
+++ /dev/null
-/*
- * Copyright (C) 2003 Apple Computer, Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#import "config.h"
-#import "FileButton.h"
-
-#import "BlockExceptions.h"
-#import "FoundationExtras.h"
-#import "FrameMac.h"
-#import "WebCoreFrameBridge.h"
-#import "WebCoreStringTruncator.h"
-#import "WebCoreViewFactory.h"
-#import "WidgetClient.h"
-
-using namespace WebCore;
-
-#define NO_FILE_SELECTED
-
-#define AFTER_BUTTON_SPACING 4
-#define ICON_HEIGHT 16
-#define ICON_WIDTH 16
-#define ICON_FILENAME_SPACING 2
-
-// We empirically determined that buttons have these extra pixels on all
-// sides. It would be better to get this info from AppKit somehow.
-#define BUTTON_TOP_MARGIN 4
-#define BUTTON_BOTTOM_MARGIN 6
-#define BUTTON_LEFT_MARGIN 5
-#define BUTTON_RIGHT_MARGIN 5
-
-// AppKit calls this kThemePushButtonSmallTextOffset.
-#define BUTTON_VERTICAL_FUDGE_FACTOR 2
-
-@interface WebFileChooserButton : NSButton
-{
- FileButton *_widget;
-}
-- (id)initWithWidget:(FileButton *)widget;
-@end
-
-@interface WebCoreFileButton : NSView <WebCoreOpenPanelResultListener>
-{
- NSString *_filename;
- WebFileChooserButton *_button;
- NSImage *_icon;
- NSString *_label;
- BOOL _inNextValidKeyView;
- FileButton *_widget;
- BOOL _isCurrentDragTarget;
-}
-- (void)setFilename:(NSString *)filename;
-- (void)performClick;
-- (NSString *)filename;
-- (float)baseline;
-- (void)setVisualFrame:(NSRect)rect;
-- (NSRect)visualFrame;
-- (NSSize)bestVisualFrameSizeForCharacterCount:(int)count;
-- (id)initWithWidget:(FileButton *)widget;
-- (void)setEnabled:(BOOL)flag;
-@end
-
-@implementation WebCoreFileButton
-
-- (void)positionButton
-{
- [_button sizeToFit];
- [_button setFrameOrigin:NSMakePoint(0, 0)];
-}
-
-- (id)initWithWidget:(FileButton*)widget
-{
- self = [super init];
- if (!self)
- return nil;
- [self registerForDraggedTypes:[NSArray arrayWithObject:NSFilenamesPboardType]];
-
- _widget = widget;
- return self;
-}
-
-- (id)initWithFrame:(NSRect)frame
-{
- self = [super initWithFrame:frame];
- if (self) {
- _button = [[WebFileChooserButton alloc] initWithWidget:_widget];
-
- [_button setTitle:[[WebCoreViewFactory sharedFactory] fileButtonChooseFileLabel]];
- [[_button cell] setControlSize:NSSmallControlSize];
- [_button setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];
- [_button setBezelStyle:NSRoundedBezelStyle];
- [_button setTarget:self];
- [_button setAction:@selector(chooseButtonPressed:)];
- [_button setNextResponder:self];
-
- [self addSubview:_button];
-
- [self positionButton];
- [self setFilename:nil];
- }
- return self;
-}
-
-- (void)dealloc
-{
- [_filename release];
- [_button release];
- [_icon release];
- [_label release];
- [super dealloc];
-}
-
-- (BOOL)isFlipped
-{
- return YES;
-}
-
-- (void)drawRect:(NSRect)rect
-{
- NSRect bounds = [self bounds];
-
- [NSGraphicsContext saveGraphicsState];
- NSRectClip(NSIntersectionRect(bounds, rect));
-
- if (_isCurrentDragTarget) {
- [[NSColor colorWithCalibratedWhite:0.0 alpha:0.25f] set];
- NSRectFillUsingOperation([self bounds], NSCompositeSourceOver);
- }
-
- float left = NSMaxX([_button frame]) + AFTER_BUTTON_SPACING;
-
- if (_icon) {
- float top = (bounds.size.height - BUTTON_BOTTOM_MARGIN - BUTTON_TOP_MARGIN - ICON_HEIGHT) / 2
- + BUTTON_TOP_MARGIN;
- [_icon drawInRect:NSMakeRect(left, top, ICON_WIDTH, ICON_HEIGHT)
- fromRect:NSMakeRect(0, 0, [_icon size].width, [_icon size].height)
- operation:NSCompositeSourceOver fraction:1.0];
- left += ICON_WIDTH + ICON_FILENAME_SPACING;
- }
-
- NSFont *font = [_button font];
- NSDictionary *attributes = [NSDictionary dictionaryWithObject:font forKey:NSFontAttributeName];
- [_label drawAtPoint:NSMakePoint(left, [self baseline] - [[_button font] ascender]) withAttributes:attributes];
-
- [NSGraphicsContext restoreGraphicsState];
-}
-
-- (void)updateLabel
-{
- [_label release];
-
- NSString *label;
- if ([_filename length])
- label = _filename;
- else
- label = [[WebCoreViewFactory sharedFactory] fileButtonNoFileSelectedLabel];
-
- float left = NSMaxX([_button frame]) + AFTER_BUTTON_SPACING;
- if (_icon)
- left += ICON_WIDTH + ICON_FILENAME_SPACING;
- float labelWidth = [self bounds].size.width - left;
-
- _label = labelWidth <= 0 ? nil : [[WebCoreStringTruncator centerTruncateString:
- [[NSFileManager defaultManager] displayNameAtPath:label]
- toWidth:labelWidth withFont:[_button font]] copy];
-}
-
-- (void)setFilename:(NSString *)filename
-{
- NSString *copy = [filename copy];
- [_filename release];
- _filename = copy;
-
- [_icon release];
- if ([_filename length] == 0 || [_filename characterAtIndex:0] != '/')
- _icon = nil;
- else {
- _icon = [[[NSWorkspace sharedWorkspace] iconForFile:_filename] retain];
- // I'm not sure why this has any effect, but including this line of code seems to make
- // the image appear right-side-up. As far as I know, the drawInRect method used above
- // in our drawRect method should work regardless of whether the image is flipped or not.
- [_icon setFlipped:YES];
- }
-
- [self updateLabel];
-
- [self setNeedsDisplay:YES];
-}
-
-- (NSString *)filename
-{
- return [[_filename copy] autorelease];
-}
-
-- (void)setFrameSize:(NSSize)size
-{
- [super setFrameSize:size];
- // FIXME: Can we just springs and struts instead of calling positionButton?
- [self positionButton];
- [self updateLabel];
-}
-
-- (NSSize)bestVisualFrameSizeForCharacterCount:(int)count
-{
- ASSERT(count > 0);
- NSSize size = [[_button cell] cellSize];
- size.height -= BUTTON_TOP_MARGIN + BUTTON_BOTTOM_MARGIN;
- size.width -= BUTTON_LEFT_MARGIN + BUTTON_RIGHT_MARGIN;
- size.width += AFTER_BUTTON_SPACING + ICON_WIDTH + ICON_FILENAME_SPACING;
- size.width += count * [@"x" sizeWithAttributes:[NSDictionary dictionaryWithObject:[_button font] forKey:NSFontAttributeName]].width;
- return size;
-}
-
-- (NSRect)visualFrame
-{
- ASSERT([self superview] == nil || [[self superview] isFlipped]);
- NSRect frame = [self frame];
- frame.origin.x += BUTTON_LEFT_MARGIN;
- frame.size.width -= BUTTON_LEFT_MARGIN;
- frame.origin.y += BUTTON_TOP_MARGIN;
- frame.size.height -= BUTTON_TOP_MARGIN + BUTTON_BOTTOM_MARGIN;
- return frame;
-}
-
-- (void)setVisualFrame:(NSRect)frame
-{
- ASSERT([self superview] == nil || [[self superview] isFlipped]);
- frame.origin.x -= BUTTON_LEFT_MARGIN;
- frame.size.width += BUTTON_LEFT_MARGIN;
- frame.origin.y -= BUTTON_TOP_MARGIN;
- frame.size.height += BUTTON_TOP_MARGIN + BUTTON_BOTTOM_MARGIN;
- [self setFrame:frame];
-}
-
-- (float)baseline
-{
- // Button text is centered vertically, with a fudge factor to account for the shadow.
- ASSERT(_button);
- NSFont *buttonFont = [_button font];
- float ascender = [buttonFont ascender];
- float descender = [buttonFont descender];
- return -BUTTON_TOP_MARGIN
- + ([[_button cell] cellSize].height + BUTTON_TOP_MARGIN + BUTTON_BOTTOM_MARGIN - (ascender - descender)) / 2.0
- + ascender - BUTTON_VERTICAL_FUDGE_FACTOR;
-}
-
-- (void)beginSheet
-{
- WebCoreFrameBridge *bridge = FrameMac::bridgeForWidget(_widget);
- [bridge retain];
- [bridge runOpenPanelForFileButtonWithResultListener:self];
-}
-
-- (void)changeFilename:(NSString *)filename
-{
- // The != check here makes sure we don't consider a change from nil to nil as a change.
- if (_filename != filename && ![_filename isEqualToString:filename]) {
- [self setFilename:filename];
- if (_widget)
- _widget->filenameChanged(DeprecatedString::fromNSString(filename));
- }
-}
-
-- (void)chooseFilename:(NSString *)filename
-{
- // call bridgetForWidget before changeFilename because changeFilename can destroy the widget [Radar 46211649]
- WebCoreFrameBridge *bridge = FrameMac::bridgeForWidget(_widget);
- [self changeFilename:filename];
- [bridge release];
-}
-
-- (void)cancel
-{
- WebCoreFrameBridge *bridge = FrameMac::bridgeForWidget(_widget);
- [bridge release];
-}
-
-- (void)chooseButtonPressed:(id)sender
-{
- if (_widget)
- _widget->sendConsumedMouseUp();
- if (_widget && _widget->client())
- _widget->client()->clicked(_widget);
- [self beginSheet];
-}
-
-- (void)mouseDown:(NSEvent *)event
-{
- [self beginSheet];
-}
-
-- (BOOL)acceptsFirstResponder
-{
- return YES;
-}
-
-- (BOOL)becomeFirstResponder
-{
- BOOL become = [_button acceptsFirstResponder];
- if (become) {
- if (_widget && _widget->client() && !FrameMac::currentEventIsMouseDownInWidget(_widget))
- _widget->client()->scrollToVisible(_widget);
- if (_widget && _widget->client())
- _widget->client()->focusIn(_widget);
- [[self window] makeFirstResponder:_button];
- }
- return become;
-}
-
-- (NSView *)nextKeyView
-{
- return _inNextValidKeyView
- ? FrameMac::nextKeyViewForWidget(_widget, SelectingNext)
- : [super nextKeyView];
-}
-
-- (NSView *)previousKeyView
-{
- return _inNextValidKeyView
- ? FrameMac::nextKeyViewForWidget(_widget, SelectingPrevious)
- : [super previousKeyView];
-}
-
-- (NSView *)nextValidKeyView
-{
- _inNextValidKeyView = YES;
- NSView *view = [super nextValidKeyView];
- _inNextValidKeyView = NO;
- return view;
-}
-
-- (NSView *)previousValidKeyView
-{
- _inNextValidKeyView = YES;
- NSView *view = [super previousValidKeyView];
- _inNextValidKeyView = NO;
- return view;
-}
-
-- (void)performClick
-{
- [_button performClick:nil];
-}
-
-- (void)setEnabled:(BOOL)flag
-{
- [_button setEnabled:flag];
-}
-
-static NSString *validFilenameFromPasteboard(NSPasteboard* pBoard)
-{
- NSArray *filenames = [pBoard propertyListForType:NSFilenamesPboardType];
- if ([filenames count] == 1) {
- NSString *filename = [filenames objectAtIndex:0];
- NSDictionary *fileAttributes = [[NSFileManager defaultManager] fileAttributesAtPath:filename traverseLink:YES];
- if ([[fileAttributes fileType] isEqualToString:NSFileTypeRegular])
- return filename;
- }
- return nil;
-}
-
-- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
-{
- if (validFilenameFromPasteboard([sender draggingPasteboard])) {
- _isCurrentDragTarget = YES;
- [self setNeedsDisplay:YES];
- return NSDragOperationCopy;
- }
- return NSDragOperationNone;
-}
-
-- (void)draggingExited:(id <NSDraggingInfo>)sender
-{
- if (_isCurrentDragTarget) {
- _isCurrentDragTarget = NO;
- [self setNeedsDisplay:YES];
- }
-}
-
-- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
-{
- _isCurrentDragTarget = NO;
- NSString *filename = validFilenameFromPasteboard([sender draggingPasteboard]);
- if (filename) {
- [self changeFilename:filename];
- [self setNeedsDisplay:YES];
- return YES;
- }
- return NO;
-}
-
-@end
-
-@implementation WebFileChooserButton
-
-- (id)initWithWidget:(FileButton *)widget
-{
- [super init];
- _widget = widget;
- return self;
-}
-
-- (NSView *)nextValidKeyView
-{
- return [[self superview] nextValidKeyView];
-}
-
-- (NSView *)previousValidKeyView
-{
- return [[self superview] previousValidKeyView];
-}
-
-- (BOOL)resignFirstResponder
-{
- if (_widget && _widget->client())
- _widget->client()->focusOut(_widget);
- return YES;
-}
-
-@end
-
-
-FileButton::FileButton(Frame *frame)
-{
- BEGIN_BLOCK_OBJC_EXCEPTIONS;
-
- _buttonView = [[WebCoreFileButton alloc] initWithWidget:this];
- setView(_buttonView);
- [_buttonView release];
-
- END_BLOCK_OBJC_EXCEPTIONS;
-}
-
-void FileButton::setFilename(const DeprecatedString &f)
-{
- BEGIN_BLOCK_OBJC_EXCEPTIONS;
- [_buttonView setFilename:f.getNSString()];
- END_BLOCK_OBJC_EXCEPTIONS;
-}
-
-void FileButton::click(bool sendMouseEvents)
-{
- BEGIN_BLOCK_OBJC_EXCEPTIONS;
- [_buttonView performClick];
- END_BLOCK_OBJC_EXCEPTIONS;
-}
-
-IntSize FileButton::sizeForCharacterWidth(int characters) const
-{
- ASSERT(characters > 0);
-
- NSSize size = {0,0};
- BEGIN_BLOCK_OBJC_EXCEPTIONS;
- size = [_buttonView bestVisualFrameSizeForCharacterCount:characters];
- return IntSize(size);
- END_BLOCK_OBJC_EXCEPTIONS;
- return IntSize(0, 0);
-}
-
-IntRect FileButton::frameGeometry() const
-{
- BEGIN_BLOCK_OBJC_EXCEPTIONS;
- return enclosingIntRect([_buttonView visualFrame]);
- END_BLOCK_OBJC_EXCEPTIONS;
- return IntRect();
-}
-
-void FileButton::setFrameGeometry(const IntRect &rect)
-{
- BEGIN_BLOCK_OBJC_EXCEPTIONS;
- [_buttonView setVisualFrame:rect];
- END_BLOCK_OBJC_EXCEPTIONS;
-}
-
-int FileButton::baselinePosition(int height) const
-{
- BEGIN_BLOCK_OBJC_EXCEPTIONS;
- return (int)([_buttonView frame].origin.y + [_buttonView baseline] - [_buttonView visualFrame].origin.y);
- END_BLOCK_OBJC_EXCEPTIONS;
-
- return 0;
-}
-
-Widget::FocusPolicy FileButton::focusPolicy() const
-{
- BEGIN_BLOCK_OBJC_EXCEPTIONS;
-
- WebCoreFrameBridge *bridge = FrameMac::bridgeForWidget(this);
- if (!bridge || ![bridge impl] || ![bridge impl]->tabsToAllControls()) {
- return NoFocus;
- }
-
- END_BLOCK_OBJC_EXCEPTIONS;
-
- return Widget::focusPolicy();
-}
-
-void FileButton::filenameChanged(const DeprecatedString& filename)
-{
- m_name = filename;
- if (client())
- client()->valueChanged(this);
-}
-
-void FileButton::setDisabled(bool flag)
-{
- BEGIN_BLOCK_OBJC_EXCEPTIONS;
- [_buttonView setEnabled:!flag];
- END_BLOCK_OBJC_EXCEPTIONS;
-}
-
--- /dev/null
+/*
+ * Copyright (C) 2006 Apple Computer, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ */
+
+#import "config.h"
+#import "FileChooser.h"
+
+#import <AppKit/NSOpenPanel.h>
+#import "Document.h"
+#import "FontData.h"
+#import "FrameMac.h"
+#import "Icon.h"
+#import "LocalizedStrings.h"
+#import "RenderFileUploadControl.h"
+#import "WebCoreFrameBridge.h"
+#import "WebCoreStringTruncator.h"
+
+using namespace WebCore;
+
+@interface OpenPanelController : NSObject <WebCoreOpenPanelResultListener> {
+ FileChooser *_fileChooser;
+ WebCoreFrameBridge *_bridge;
+}
+- (id)initWithFileChooser:(FileChooser *)fileChooser;
+- (void)fileChooserDetachingSoon;
+- (void)beginSheet;
+@end
+
+@implementation OpenPanelController
+
+- (id)initWithFileChooser:(FileChooser *)fileChooser
+{
+ self = [super init];
+ if (!self)
+ return nil;
+
+ _fileChooser = fileChooser;
+ return self;
+}
+
+- (void)fileChooserDetachingSoon
+{
+ _fileChooser = 0;
+}
+
+- (void)beginSheet
+{
+ if (!_fileChooser)
+ return;
+
+ _bridge = Mac(_fileChooser->document()->frame())->bridge();
+ [_bridge retain];
+ [_bridge runOpenPanelForFileButtonWithResultListener:self];
+}
+
+- (void)chooseFilename:(NSString *)filename
+{
+ if (_fileChooser)
+ _fileChooser->chooseFile(filename);
+ [_bridge release];
+}
+
+- (void)cancel
+{
+ [_bridge release];
+}
+
+@end
+
+namespace WebCore {
+
+FileChooser::FileChooser(Document* document, RenderFileUploadControl* uploadControl)
+ : m_document(document)
+ , m_icon(0)
+ , m_uploadControl(uploadControl)
+ , m_controller([[[OpenPanelController alloc] initWithFileChooser:this] retain])
+{
+}
+
+FileChooser::~FileChooser()
+{
+ [m_controller release];
+}
+
+void FileChooser::openFileChooser()
+{
+ [m_controller beginSheet];
+}
+
+String FileChooser::basenameForWidth(int width) const
+{
+ if (width <= 0)
+ return String();
+
+ String strToTruncate;
+ if (m_filename.isEmpty())
+ strToTruncate = fileButtonNoFileSelectedLabel();
+ else
+ strToTruncate = [[NSFileManager defaultManager] displayNameAtPath:m_filename];
+
+ return [WebCoreStringTruncator centerTruncateString:strToTruncate
+ toWidth:width withFont:m_uploadControl->style()->font().primaryFont()->getNSFont()];
+}
+
+void FileChooser::uploadControlDetaching()
+{
+ if (m_controller)
+ [m_controller fileChooserDetachingSoon];
+}
+
+void FileChooser::chooseFile(const String& filename)
+{
+ m_filename = filename;
+
+ // Need unsigned 0 here to disambiguate String::operator[] from operator(NSString*, int)[]
+ if (!m_filename.length() || m_filename[0U] != '/')
+ m_icon.set(0);
+ else
+ m_icon.set(Icon::newIconForFile(m_filename).release());
+
+ uploadControl()->updateIconAndFilename();
+}
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2006 Apple Computer, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ */
+
+#import "config.h"
+#import "Icon.h"
+
+#import "GraphicsContext.h"
+#import "LocalCurrentGraphicsContext.h"
+#import "PlatformString.h"
+#import <AppKit/NSImage.h>
+
+namespace WebCore {
+
+Icon::Icon()
+ : m_nsImage(0)
+{
+}
+
+Icon::~Icon()
+{
+ [m_nsImage release];
+}
+
+auto_ptr<Icon> Icon::newIconForFile(const String& filename)
+{
+ NSImage* fileIcon = [[[NSWorkspace sharedWorkspace] iconForFile:filename] retain];
+ if (!fileIcon)
+ return auto_ptr<Icon>(0);
+
+ auto_ptr<Icon> icon(new Icon());
+
+ icon->m_nsImage = fileIcon;
+
+ // Need this because WebCore uses AppKit's flipped coordinate system.
+ [icon->m_nsImage setFlipped:YES];
+
+ return icon;
+}
+
+void Icon::paint(GraphicsContext* context, const IntRect& r)
+{
+ if (context->paintingDisabled())
+ return;
+
+ LocalCurrentGraphicsContext localCurrentGC(context);
+
+ [m_nsImage drawInRect:r
+ fromRect:NSMakeRect(0, 0, [m_nsImage size].width, [m_nsImage size].height)
+ operation:NSCompositeSourceOver fraction:1.0];
+}
+
+}
return String();
}
+String fileButtonChooseFileLabel()
+{
+ BEGIN_BLOCK_OBJC_EXCEPTIONS;
+ return [[WebCoreViewFactory sharedFactory] fileButtonChooseFileLabel];
+ END_BLOCK_OBJC_EXCEPTIONS;
+ return String();
+}
+
+String fileButtonNoFileSelectedLabel()
+{
+ BEGIN_BLOCK_OBJC_EXCEPTIONS;
+ return [[WebCoreViewFactory sharedFactory] fileButtonNoFileSelectedLabel];
+ END_BLOCK_OBJC_EXCEPTIONS;
+ return String();
+}
+
}
if (element()->hasTagName(inputTag)) {
HTMLInputElement* input = static_cast<HTMLInputElement*>(element());
String value = input->valueWithDefault();
- if (value.isEmpty()) {
- if (m_buttonText) {
- m_buttonText->destroy();
- m_buttonText = 0;
- }
- } else {
- if (m_buttonText)
- m_buttonText->setText(value.impl());
- else {
- m_buttonText = new (renderArena()) RenderText(document(), value.impl());
- m_buttonText->setStyle(style());
- addChild(m_buttonText);
- }
+ setText(value);
+ }
+}
+
+void RenderButton::setText(const String& str)
+{
+ if (str.isEmpty()) {
+ if (m_buttonText) {
+ m_buttonText->destroy();
+ m_buttonText = 0;
+ }
+ } else {
+ if (m_buttonText)
+ m_buttonText->setText(str.impl());
+ else {
+ m_buttonText = new (renderArena()) RenderText(document(), str.impl());
+ m_buttonText->setStyle(style());
+ addChild(m_buttonText);
}
}
}
virtual void paintObject(PaintInfo&, int tx, int ty);
+ void setText(const String&);
+
virtual const char* renderName() const { return "RenderButton"; }
protected:
+++ /dev/null
-/*
- * This file is part of the DOM implementation for KDE.
- *
- * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
- * (C) 1999 Antti Koivisto (koivisto@kde.org)
- * (C) 2000 Dirk Mueller (mueller@kde.org)
- * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB. If not, write to
- * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- *
- */
-
-#include "config.h"
-#include "RenderFileButton.h"
-
-#include "FrameView.h"
-#include "HTMLFormElement.h"
-#include "HTMLInputElement.h"
-#include "FileButton.h"
-
-namespace WebCore {
-
-RenderFileButton::RenderFileButton(HTMLInputElement* element)
- : RenderFormElement(element)
-{
- setWidget(new FileButton(m_view->frame()));
-}
-
-void RenderFileButton::calcMinMaxWidth()
-{
- ASSERT(!minMaxKnown());
-
- // Let the widget tell us how big it wants to be.
- int size = static_cast<HTMLInputElement*>(node())->size();
- IntSize s(static_cast<FileButton*>(widget())->sizeForCharacterWidth(size > 0 ? size : 20));
-
- setIntrinsicWidth(s.width());
- setIntrinsicHeight(s.height());
-
- RenderFormElement::calcMinMaxWidth();
-}
-
-void RenderFileButton::updateFromElement()
-{
- static_cast<FileButton*>(widget())->setFilename(
- static_cast<HTMLInputElement*>(node())->value().deprecatedString());
-
- static_cast<FileButton*>(widget())->setDisabled(
- static_cast<HTMLInputElement*>(node())->disabled());
-
- RenderFormElement::updateFromElement();
-}
-
-void RenderFileButton::returnPressed(Widget*)
-{
- if (static_cast<HTMLInputElement*>(node())->form())
- static_cast<HTMLInputElement*>(node())->form()->prepareSubmit();
-}
-
-void RenderFileButton::valueChanged(Widget*)
-{
- static_cast<HTMLInputElement*>(node())->setValueFromRenderer(static_cast<FileButton*>(widget())->filename());
- static_cast<HTMLInputElement*>(node())->onChange();
-}
-
-void RenderFileButton::select()
-{
-}
-
-void RenderFileButton::click(bool sendMouseEvents)
-{
- static_cast<FileButton*>(widget())->click(sendMouseEvents);
-}
-
-} // namespace WebCore
+++ /dev/null
-/*
- * This file is part of the DOM implementation for KDE.
- *
- * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
- * (C) 1999 Antti Koivisto (koivisto@kde.org)
- * (C) 2000 Dirk Mueller (mueller@kde.org)
- * Copyright (C) 2004, 2006 Apple Computer, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB. If not, write to
- * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- *
- */
-
-#ifndef RenderFileButton_h
-#define RenderFileButton_h
-
-#include "RenderFormElement.h"
-
-namespace WebCore {
-
- class HTMLInputElement;
-
- class RenderFileButton : public RenderFormElement {
- public:
- RenderFileButton(HTMLInputElement*);
-
- virtual const char* renderName() const { return "RenderFileButton"; }
-
- virtual void calcMinMaxWidth();
- virtual void updateFromElement();
- void select();
-
- int calcReplacedHeight() const { return intrinsicHeight(); }
-
- void click(bool sendMouseEvents);
-
- protected:
- virtual bool isEditable() const { return true; }
-
- private:
- virtual void returnPressed(Widget*);
- virtual void valueChanged(Widget*);
- };
-
-} // namespace WebCore
-
-#endif // RenderFileButton_h
--- /dev/null
+/**
+ *
+ * Copyright (C) 2006 Apple Computer, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ */
+
+#include "config.h"
+#include "RenderFileUploadControl.h"
+
+#include "FrameView.h"
+#include "GraphicsContext.h"
+#include "HTMLInputElement.h"
+#include "HTMLNames.h"
+#include "Icon.h"
+#include "LocalizedStrings.h"
+#include "RenderButton.h"
+#include "RenderText.h"
+#include "RenderTheme.h"
+#include "RenderView.h"
+#include "TextStyle.h"
+#include <math.h>
+
+using namespace std;
+
+namespace WebCore {
+
+const int afterButtonSpacing = 4;
+const int iconHeight = 16;
+const int iconWidth = 16;
+const int iconFilenameSpacing = 2;
+const int defaultFilenameNumChars = 23;
+
+using namespace HTMLNames;
+
+class RenderFileUploadInnerFileBox : public RenderFlexibleBox {
+public:
+ RenderFileUploadInnerFileBox(Node*, RenderFileUploadControl*);
+
+ virtual void setStyle(RenderStyle*);
+ virtual void calcMinMaxWidth();
+ virtual void layout();
+
+ void setHasIcon(bool hasIcon = true);
+
+ void setFilename(const String&);
+
+ virtual const char* renderName() const { return "RenderFileUploadInnerFileBox"; }
+
+private:
+ RenderFileUploadControl* m_uploadControl;
+ RenderText* m_filenameText;
+
+ String m_filename;
+};
+
+class HTMLFileUploadInnerButtonElement : public HTMLInputElement {
+public:
+ HTMLFileUploadInnerButtonElement(Document*, Node* shadowParent = 0);
+
+ virtual RenderObject* createRenderer(RenderArena*, RenderStyle*);
+
+ virtual bool isShadowNode() const { return true; }
+
+ virtual Node* shadowParentNode() { return m_shadowParent; }
+
+private:
+ Node* m_shadowParent;
+};
+
+RenderFileUploadControl::RenderFileUploadControl(Node* node)
+ : RenderFlexibleBox(node)
+ , m_button(0)
+ , m_fileBox(0)
+ , m_fileChooser(new FileChooser(document(), this))
+{
+}
+
+RenderFileUploadControl::~RenderFileUploadControl()
+{
+ if (m_button)
+ m_button->detach();
+ if (m_fileChooser) {
+ m_fileChooser->uploadControlDetaching();
+ delete m_fileChooser;
+ }
+}
+
+void RenderFileUploadControl::setStyle(RenderStyle* s)
+{
+ RenderFlexibleBox::setStyle(s);
+ if (m_button)
+ m_button->renderer()->setStyle(createButtonStyle(s));
+ if (m_fileBox) {
+ RenderStyle* fileBoxStyle = new (renderArena()) RenderStyle();
+ fileBoxStyle->inheritFrom(s);
+ m_fileBox->setStyle(fileBoxStyle);
+ }
+ setReplaced(isInline());
+}
+
+void RenderFileUploadControl::updateIconAndFilename()
+{
+ if (m_fileChooser->icon())
+ m_fileBox->setHasIcon();
+ else
+ m_fileBox->setHasIcon(false);
+
+ // FIXME: We don't actually seem to truncate the string when our width is less than the button width and we're in RTL
+ m_fileBox->setFilename(m_fileChooser->basenameForWidth(maxFilenameWidth()));
+}
+
+void RenderFileUploadControl::click(bool sendMouseEvents)
+{
+ m_fileChooser->openFileChooser();
+}
+
+void RenderFileUploadControl::updateFromElement()
+{
+ if (!m_button) {
+ m_button = new HTMLFileUploadInnerButtonElement(document(), node());
+ RenderStyle* buttonStyle = createButtonStyle(style());
+ m_button->setRenderer(m_button->createRenderer(renderArena(), buttonStyle));
+ m_button->renderer()->setStyle(buttonStyle);
+ m_button->setAttached();
+ m_button->setInDocument(true);
+
+ addChild(m_button->renderer());
+ }
+
+ if (!m_fileBox) {
+ m_fileBox = new (renderArena()) RenderFileUploadInnerFileBox(document(), this);
+ RenderStyle* fileBoxStyle = new (renderArena()) RenderStyle();
+ fileBoxStyle->inheritFrom(style());
+ m_fileBox->setStyle(fileBoxStyle);
+ addChild(m_fileBox);
+ }
+
+ HTMLInputElement* input = static_cast<HTMLInputElement*>(node());
+ RenderButton* buttonRenderer = static_cast<RenderButton*>(m_button->renderer());
+ buttonRenderer->setText(input->valueWithDefault());
+
+ updateIconAndFilename();
+}
+
+int RenderFileUploadControl::maxFilenameWidth()
+{
+ return max(0, m_fileBox->contentWidth());
+}
+
+RenderStyle* RenderFileUploadControl::createButtonStyle(RenderStyle* parentStyle)
+{
+ RenderStyle* style = getPseudoStyle(RenderStyle::FILE_UPLOAD_BUTTON);
+ if (!style)
+ style = new (renderArena()) RenderStyle();
+
+ if (parentStyle)
+ style->inheritFrom(parentStyle);
+
+ // Button text will wrap on file upload controls with widths smaller than the intrinsic button width
+ // without this setWhiteSpace.
+ style->setWhiteSpace(NOWRAP);
+
+ // This makes the button block-level so that the flexbox layout works correctly.
+ style->setDisplay(BOX);
+
+ return style;
+}
+
+void RenderFileUploadControl::paintObject(PaintInfo& i, int tx, int ty)
+{
+ // Since we draw the file icon without going through the graphics context,
+ // we need to make sure painting is not disabled before drawing
+ if (i.p->paintingDisabled())
+ return;
+
+ // Push a clip.
+ if (i.phase == PaintPhaseForeground || i.phase == PaintPhaseChildBlockBackgrounds) {
+ IntRect clipRect(tx + borderLeft(), ty + borderTop(),
+ width() - borderLeft() - borderRight(), height() - borderBottom() - borderTop());
+ if (clipRect.width() == 0 || clipRect.height() == 0)
+ return;
+ i.p->save();
+ i.p->addClip(clipRect);
+ }
+
+ if (i.phase == PaintPhaseForeground && m_fileChooser->icon()) {
+ // Draw the file icon
+ int top = m_fileBox->absoluteBoundingBoxRect().y() + (m_fileBox->absoluteBoundingBoxRect().height() - iconHeight) / 2;
+ int left;
+ if (style()->direction() == LTR)
+ left = m_fileBox->absoluteBoundingBoxRect().x() + afterButtonSpacing;
+ else
+ left = m_fileBox->absoluteBoundingBoxRect().right() - afterButtonSpacing - iconWidth;
+ m_fileChooser->icon()->paint(i.p, IntRect(left, top, iconWidth, iconHeight));
+ }
+
+ // Paint the children.
+ RenderFlexibleBox::paintObject(i, tx, ty);
+
+ // Pop the clip.
+ if (i.phase == PaintPhaseForeground || i.phase == PaintPhaseChildBlockBackgrounds)
+ i.p->restore();
+}
+
+RenderFileUploadInnerFileBox::RenderFileUploadInnerFileBox(Node* node, RenderFileUploadControl* uploadControl)
+ : RenderFlexibleBox(node)
+ , m_uploadControl(uploadControl)
+ , m_filenameText(0)
+{
+}
+
+void RenderFileUploadInnerFileBox::setStyle(RenderStyle* s)
+{
+ if (m_filenameText)
+ m_filenameText->setStyle(s);
+
+ s->setBoxFlex(1.0f);
+ s->setDisplay(BOX);
+ s->setWhiteSpace(NOWRAP);
+
+ if (s->direction() == LTR)
+ s->setPaddingLeft(Length(afterButtonSpacing, Fixed));
+ else
+ s->setPaddingRight(Length(afterButtonSpacing, Fixed));
+
+ setReplaced(isInline());
+
+ RenderFlexibleBox::setStyle(s);
+}
+
+void RenderFileUploadInnerFileBox::layout()
+{
+ RenderFlexibleBox::layout();
+
+ ASSERT(minMaxKnown());
+ // We should know our width now, so display the filename
+ m_uploadControl->updateIconAndFilename();
+}
+
+void RenderFileUploadInnerFileBox::setHasIcon(bool hasIcon)
+{
+ int padding = afterButtonSpacing;
+
+ if (hasIcon)
+ padding += iconWidth + iconFilenameSpacing;
+
+ if (style()->direction() == LTR)
+ style()->setPaddingLeft(Length(padding, Fixed));
+ else
+ style()->setPaddingRight(Length(padding, Fixed));
+}
+
+void RenderFileUploadInnerFileBox::setFilename(const String& filename)
+{
+ if (!m_filenameText) {
+ m_filenameText = new (renderArena()) RenderText(document(), String("").impl());
+ m_filenameText->setStyle(style());
+ addChild(m_filenameText);
+ }
+
+ if (filename != m_filename) {
+ m_filenameText->setText(filename.impl());
+ m_filename = filename;
+ m_uploadControl->node()->setChanged();
+ }
+}
+
+void RenderFileUploadInnerFileBox::calcMinMaxWidth()
+{
+ m_minWidth = 0;
+ m_maxWidth = 0;
+
+ if (style()->width().isFixed() && style()->width().value() > 0)
+ m_minWidth = m_maxWidth = calcContentBoxWidth(style()->width().value());
+ else {
+ // Figure out how big the filename space needs to be for a given number of characters
+ // (using "0" as the nominal character).
+ const UChar ch = '0';
+ float charWidth = style()->font().floatWidth(TextRun(&ch, 1), TextStyle(0, 0, 0, false, false, false));
+ m_maxWidth = (int)ceilf(charWidth * defaultFilenameNumChars);
+ }
+
+ if (style()->minWidth().isFixed() && style()->minWidth().value() > 0) {
+ m_maxWidth = max(m_maxWidth, calcContentBoxWidth(style()->minWidth().value()));
+ m_minWidth = max(m_minWidth, calcContentBoxWidth(style()->minWidth().value()));
+ } else if (style()->width().isPercent() || (style()->width().isAuto() && style()->height().isPercent()))
+ m_minWidth = 0;
+ else
+ m_minWidth = m_maxWidth;
+
+ if (style()->maxWidth().isFixed() && style()->maxWidth().value() != undefinedLength) {
+ m_maxWidth = min(m_maxWidth, calcContentBoxWidth(style()->maxWidth().value()));
+ m_minWidth = min(m_minWidth, calcContentBoxWidth(style()->maxWidth().value()));
+ }
+
+ int toAdd = paddingLeft() + paddingRight() + borderLeft() + borderRight();
+ m_minWidth += toAdd;
+ m_maxWidth += toAdd;
+
+ setMinMaxKnown();
+}
+
+HTMLFileUploadInnerButtonElement::HTMLFileUploadInnerButtonElement(Document* doc, Node* shadowParent)
+ : HTMLInputElement(doc)
+ , m_shadowParent(shadowParent)
+{
+ setInputType("button");
+}
+
+RenderObject* HTMLFileUploadInnerButtonElement::createRenderer(RenderArena* arena, RenderStyle* style)
+{
+ return HTMLInputElement::createRenderer(arena, style);
+}
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2006 Apple Computer
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ */
+
+#ifndef RenderFileUploadControl_H
+#define RenderFileUploadControl_H
+
+#include "RenderFlexibleBox.h"
+
+#include "FileChooser.h"
+#include "HTMLInputElement.h"
+
+namespace WebCore {
+
+class HTMLFileUploadInnerButtonElement;
+class RenderFileUploadInnerFileBox;
+
+// RenderFileUploadControls contain a RenderButton (for opening the file chooser), and
+// a RenderFileUploadInnerFileBox (which contains a RenderText for the filename and sufficient padding to draw a file icon).
+// The RenderButton has an HTMLFileUploadInnerButtonElement shadow node associated with it to receive click/hover events.
+
+class RenderFileUploadControl : public RenderFlexibleBox {
+public:
+ RenderFileUploadControl(Node*);
+ ~RenderFileUploadControl();
+
+ virtual void setStyle(RenderStyle*);
+ virtual void updateFromElement();
+ virtual void paintObject(PaintInfo&, int tx, int ty);
+
+ virtual void click(bool sendMouseEvents);
+
+ void updateIconAndFilename();
+
+ virtual const char* renderName() const { return "RenderFileUploadControl"; }
+
+protected:
+ int maxFilenameWidth();
+ RenderStyle* createButtonStyle(RenderStyle* parentStyle = 0);
+
+ RefPtr<HTMLFileUploadInnerButtonElement> m_button;
+ RenderFileUploadInnerFileBox* m_fileBox;
+ FileChooser* m_fileChooser;
+};
+
+}
+
+#endif
}
enum EPseudoBit { NO_BIT = 0x0, BEFORE_BIT = 0x1, AFTER_BIT = 0x2, FIRST_LINE_BIT = 0x4,
- FIRST_LETTER_BIT = 0x8, SELECTION_BIT = 0x10, FIRST_LINE_INHERITED_BIT = 0x20 };
+ FIRST_LETTER_BIT = 0x8, SELECTION_BIT = 0x10, FIRST_LINE_INHERITED_BIT = 0x20,
+ FILE_UPLOAD_BUTTON_BIT = 0x40 };
static inline int pseudoBit(RenderStyle::PseudoId pseudo)
{
return SELECTION_BIT;
case RenderStyle::FIRST_LINE_INHERITED:
return FIRST_LINE_INHERITED_BIT;
+ case RenderStyle::FILE_UPLOAD_BUTTON:
+ return FILE_UPLOAD_BUTTON_BIT;
default:
return NO_BIT;
}
public:
// static pseudo styles. Dynamic ones are produced on the fly.
- enum PseudoId { NOPSEUDO, FIRST_LINE, FIRST_LETTER, BEFORE, AFTER, SELECTION, FIRST_LINE_INHERITED };
+ enum PseudoId { NOPSEUDO, FIRST_LINE, FIRST_LETTER, BEFORE, AFTER, SELECTION, FIRST_LINE_INHERITED, FILE_UPLOAD_BUTTON };
void ref() { m_ref++; }
void deref(RenderArena* arena) {
bool _affectedByHover : 1;
bool _affectedByActive : 1;
bool _affectedByDrag : 1;
- unsigned _pseudoBits : 6;
+ unsigned _pseudoBits : 7;
unsigned _unicodeBidi : 2; // EUnicodeBidi
} noninherited_flags;