Changeset 129086 in webkit
- Timestamp:
- Sep 19, 2012 7:07:27 PM (12 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r129084 r129086 1 2012-09-19 Shinya Kawanaka <shinyak@chromium.org> 2 3 [Refactoring] ButtonInputType of <input> element should have innerElement to make <input> AuthorShadowDOM-ready 4 https://bugs.webkit.org/show_bug.cgi?id=95939 5 6 Reviewed by Dimitri Glazkov. 7 8 We had 2 ways to show text in RenderButton. One is to use RenderButton::setText() and the other is to add renderer 9 as a child of RenderButton. <input type="button"> used the former one, and <button> used the latter one. 10 The former makes RenderButton a bit messy, and also prevents from making <input> AuthorShadowDOM ready. 11 12 So we remove RenderButton::setText() and refactor <input type="button"> to use a Shadow DOM to show text. 13 14 Since the text in <input type="button"> should create RenderTextFragment, we introduce TextForButtonInputType 15 class. RenderText will allow us to select the inner text of <input>, but it should not. 16 17 No new tests, existing tests should cover the change. 18 19 * html/BaseButtonInputType.cpp: 20 (TextForButtonInputType): Special Text node which creates RenderTextFragment. 21 (WebCore): 22 (WebCore::TextForButtonInputType::create): 23 (WebCore::TextForButtonInputType::TextForButtonInputType): 24 (WebCore::TextForButtonInputType::createRenderer): 25 (WebCore::BaseButtonInputType::BaseButtonInputType): 26 (WebCore::BaseButtonInputType::createShadowSubtree): 27 (WebCore::BaseButtonInputType::destroyShadowSubtree): 28 (WebCore::BaseButtonInputType::valueAttributeChanged): When a button value is changed, we reflect the value to 29 the text node in ShadowDOM. 30 * html/BaseButtonInputType.h: 31 (BaseButtonInputType): 32 * html/FileInputType.cpp: 33 (WebCore::UploadButtonElement::create): Creates Shadow DOM subtree. 34 (WebCore::UploadButtonElement::createForMultiple): Creates Shadow DOM subtree. 35 * html/HTMLInputElement.cpp: 36 (WebCore::HTMLInputElement::parseAttribute): 37 * html/InputType.cpp: 38 (WebCore::InputType::valueAttributeChanged): 39 (WebCore): 40 * html/InputType.h: 41 (InputType): 42 * rendering/RenderButton.cpp: 43 (WebCore::RenderButton::RenderButton): 44 (WebCore::RenderButton::styleDidChange): Removed unnecessary text related code. 45 * rendering/RenderButton.h: 46 (RenderButton): 47 1 48 2012-09-19 Jason Liu <jason.liu@torchmobile.com.cn> 2 49 -
trunk/Source/WebCore/html/BaseButtonInputType.cpp
r122414 r129086 37 37 #include "KeyboardEvent.h" 38 38 #include "RenderButton.h" 39 #include "RenderTextFragment.h" 40 #include "ShadowRoot.h" 41 #include "Text.h" 39 42 40 43 namespace WebCore { 41 44 42 45 using namespace HTMLNames; 46 47 class TextForButtonInputType : public Text { 48 public: 49 static PassRefPtr<TextForButtonInputType> create(Document*, const String&); 50 51 private: 52 TextForButtonInputType(Document*, const String&); 53 virtual RenderObject* createRenderer(RenderArena*, RenderStyle*) OVERRIDE; 54 }; 55 56 PassRefPtr<TextForButtonInputType> TextForButtonInputType::create(Document* document, const String& data) 57 { 58 return adoptRef(new TextForButtonInputType(document, data)); 59 } 60 61 TextForButtonInputType::TextForButtonInputType(Document* document, const String& data) 62 : Text(document, data) 63 { 64 } 65 66 RenderObject* TextForButtonInputType::createRenderer(RenderArena* arena, RenderStyle*) 67 { 68 return new (arena) RenderTextFragment(document(), dataImpl()); 69 } 70 71 BaseButtonInputType::BaseButtonInputType(HTMLInputElement* element) 72 : BaseClickableWithKeyInputType(element) 73 { 74 } 75 76 void BaseButtonInputType::createShadowSubtree() 77 { 78 ASSERT(element()->userAgentShadowRoot()); 79 80 RefPtr<TextForButtonInputType> text = TextForButtonInputType::create(element()->document(), defaultValue()); 81 element()->userAgentShadowRoot()->appendChild(text); 82 } 83 84 void BaseButtonInputType::destroyShadowSubtree() 85 { 86 InputType::destroyShadowSubtree(); 87 } 88 89 void BaseButtonInputType::valueAttributeChanged() 90 { 91 String value = element()->valueWithDefault(); 92 toText(element()->userAgentShadowRoot()->firstChild())->setData(value, ASSERT_NO_EXCEPTION); 93 } 43 94 44 95 bool BaseButtonInputType::shouldSaveAndRestoreFormControlState() const -
trunk/Source/WebCore/html/BaseButtonInputType.h
r122414 r129086 39 39 class BaseButtonInputType : public BaseClickableWithKeyInputType { 40 40 protected: 41 BaseButtonInputType(HTMLInputElement* element) : BaseClickableWithKeyInputType(element) { }41 BaseButtonInputType(HTMLInputElement*); 42 42 43 43 private: 44 virtual void createShadowSubtree() OVERRIDE; 45 virtual void destroyShadowSubtree() OVERRIDE; 46 47 virtual void valueAttributeChanged() OVERRIDE; 48 44 49 virtual bool shouldSaveAndRestoreFormControlState() const OVERRIDE; 45 50 virtual bool appendFormData(FormDataList&, bool) const OVERRIDE; -
trunk/Source/WebCore/html/FileInputType.cpp
r128149 r129086 63 63 { 64 64 RefPtr<UploadButtonElement> button = adoptRef(new UploadButtonElement(document)); 65 button->createShadowSubtree(); 65 66 button->setType("button"); 66 67 button->setValue(fileButtonChooseFileLabel()); … … 71 72 { 72 73 RefPtr<UploadButtonElement> button = adoptRef(new UploadButtonElement(document)); 74 button->createShadowSubtree(); 73 75 button->setType("button"); 74 76 button->setValue(fileButtonChooseMultipleFilesLabel()); -
trunk/Source/WebCore/html/HTMLInputElement.cpp
r128572 r129086 678 678 setNeedsStyleRecalc(); 679 679 } 680 m_inputType->valueAttributeChanged(); 680 681 setFormControlValueMatchesRenderer(false); 681 682 setNeedsValidityCheck(); -
trunk/Source/WebCore/html/InputType.cpp
r128149 r129086 890 890 } 891 891 892 void InputType::valueAttributeChanged() 893 { 894 } 895 892 896 void InputType::multipleAttributeChanged() 893 897 { -
trunk/Source/WebCore/html/InputType.h
r128149 r129086 279 279 virtual void updateInnerTextValue(); 280 280 virtual void updatePlaceholderText(); 281 virtual void valueAttributeChanged(); 281 282 virtual void multipleAttributeChanged(); 282 283 virtual void disabledAttributeChanged(); -
trunk/Source/WebCore/rendering/RenderButton.cpp
r126359 r129086 36 36 RenderButton::RenderButton(Node* node) 37 37 : RenderDeprecatedFlexibleBox(node) 38 , m_buttonText(0)39 38 , m_inner(0) 40 39 , m_default(false) … … 84 83 RenderBlock::styleDidChange(diff, oldStyle); 85 84 86 if (m_buttonText)87 m_buttonText->setStyle(style());88 85 if (m_inner) // RenderBlock handled updating the anonymous block's style. 89 86 setupInnerStyle(m_inner->style()); … … 107 104 innerStyle->setBoxFlex(1.0f); 108 105 innerStyle->setBoxOrient(style()->boxOrient()); 109 }110 111 void RenderButton::updateFromElement()112 {113 // If we're an input element, we may need to change our button text.114 if (node()->hasTagName(inputTag)) {115 HTMLInputElement* input = static_cast<HTMLInputElement*>(node());116 String value = input->valueWithDefault();117 setText(value);118 }119 }120 121 void RenderButton::setText(const String& str)122 {123 if (str.isEmpty()) {124 if (m_buttonText) {125 m_buttonText->destroy();126 m_buttonText = 0;127 }128 } else {129 if (m_buttonText)130 m_buttonText->setText(str.impl());131 else {132 m_buttonText = new (renderArena()) RenderTextFragment(document(), str.impl());133 m_buttonText->setStyle(style());134 addChild(m_buttonText);135 }136 }137 }138 139 String RenderButton::text() const140 {141 return m_buttonText ? m_buttonText->text() : 0;142 106 } 143 107 -
trunk/Source/WebCore/rendering/RenderButton.h
r111946 r129086 49 49 50 50 void setupInnerStyle(RenderStyle*); 51 virtual void updateFromElement();52 51 53 52 virtual void updateBeforeAfterContent(PseudoId); … … 56 55 virtual bool hasControlClip() const { return true; } 57 56 virtual LayoutRect controlClipRect(const LayoutPoint&) const; 58 59 void setText(const String&);60 String text() const;61 57 62 58 private: … … 70 66 void timerFired(Timer<RenderButton>*); 71 67 72 RenderTextFragment* m_buttonText;73 68 RenderBlock* m_inner; 74 75 69 OwnPtr<Timer<RenderButton> > m_timer; 76 70 bool m_default;
Note: See TracChangeset
for help on using the changeset viewer.