Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r ights reserved. | 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r ights reserved. |
| 3 * Copyright (C) 2010 Google Inc. All rights reserved. | 3 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 4 * Copyright (C) 2012 Samsung Electronics. All rights reserved. | 4 * Copyright (C) 2012 Samsung Electronics. All rights reserved. |
| 5 * | 5 * |
| 6 * This library is free software; you can redistribute it and/or | 6 * This library is free software; you can redistribute it and/or |
| 7 * modify it under the terms of the GNU Library General Public | 7 * modify it under the terms of the GNU Library General Public |
| 8 * License as published by the Free Software Foundation; either | 8 * License as published by the Free Software Foundation; either |
| 9 * version 2 of the License, or (at your option) any later version. | 9 * version 2 of the License, or (at your option) any later version. |
| 10 * | 10 * |
| 11 * This library is distributed in the hope that it will be useful, | 11 * This library is distributed in the hope that it will be useful, |
| 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 * Library General Public License for more details. | 14 * Library General Public License for more details. |
| 15 * | 15 * |
| 16 * You should have received a copy of the GNU Library General Public License | 16 * You should have received a copy of the GNU Library General Public License |
| 17 * along with this library; see the file COPYING.LIB. If not, write to | 17 * along with this library; see the file COPYING.LIB. If not, write to |
| 18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 19 * Boston, MA 02110-1301, USA. | 19 * Boston, MA 02110-1301, USA. |
| 20 * | 20 * |
| 21 */ | 21 */ |
| 22 | 22 |
| 23 #include "config.h" | 23 #include "config.h" |
| 24 #include "core/html/forms/ImageInputType.h" | 24 #include "core/html/forms/ImageInputType.h" |
| 25 | 25 |
| 26 #include "core/HTMLNames.h" | 26 #include "core/HTMLNames.h" |
| 27 #include "core/InputTypeNames.h" | 27 #include "core/InputTypeNames.h" |
| 28 #include "core/dom/shadow/ShadowRoot.h" | |
| 28 #include "core/events/MouseEvent.h" | 29 #include "core/events/MouseEvent.h" |
| 29 #include "core/fetch/ImageResource.h" | 30 #include "core/fetch/ImageResource.h" |
| 30 #include "core/html/FormDataList.h" | 31 #include "core/html/FormDataList.h" |
| 31 #include "core/html/HTMLFormElement.h" | 32 #include "core/html/HTMLFormElement.h" |
| 33 #include "core/html/HTMLImageFallbackHelper.h" | |
| 32 #include "core/html/HTMLImageLoader.h" | 34 #include "core/html/HTMLImageLoader.h" |
| 33 #include "core/html/HTMLInputElement.h" | 35 #include "core/html/HTMLInputElement.h" |
| 34 #include "core/html/parser/HTMLParserIdioms.h" | 36 #include "core/html/parser/HTMLParserIdioms.h" |
| 37 #include "core/rendering/RenderBlockFlow.h" | |
| 35 #include "core/rendering/RenderImage.h" | 38 #include "core/rendering/RenderImage.h" |
| 36 #include "wtf/PassOwnPtr.h" | 39 #include "wtf/PassOwnPtr.h" |
| 37 #include "wtf/text/StringBuilder.h" | 40 #include "wtf/text/StringBuilder.h" |
| 38 | 41 |
| 39 namespace blink { | 42 namespace blink { |
| 40 | 43 |
| 41 using namespace HTMLNames; | 44 using namespace HTMLNames; |
| 42 | 45 |
| 43 inline ImageInputType::ImageInputType(HTMLInputElement& element) | 46 inline ImageInputType::ImageInputType(HTMLInputElement& element) |
| 44 : BaseButtonInputType(element) | 47 : BaseButtonInputType(element) |
| 48 , m_useFallbackContent(false) | |
| 49 , m_altTextNode(0) | |
| 45 { | 50 { |
| 46 } | 51 } |
| 47 | 52 |
| 48 PassRefPtrWillBeRawPtr<InputType> ImageInputType::create(HTMLInputElement& eleme nt) | 53 PassRefPtrWillBeRawPtr<InputType> ImageInputType::create(HTMLInputElement& eleme nt) |
| 49 { | 54 { |
| 50 return adoptRefWillBeNoop(new ImageInputType(element)); | 55 return adoptRefWillBeNoop(new ImageInputType(element)); |
| 51 } | 56 } |
| 52 | 57 |
| 53 const AtomicString& ImageInputType::formControlType() const | 58 const AtomicString& ImageInputType::formControlType() const |
| 54 { | 59 { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 110 RefPtrWillBeRawPtr<HTMLInputElement> element(this->element()); | 115 RefPtrWillBeRawPtr<HTMLInputElement> element(this->element()); |
| 111 if (element->isDisabledFormControl() || !element->form()) | 116 if (element->isDisabledFormControl() || !element->form()) |
| 112 return; | 117 return; |
| 113 element->setActivatedSubmit(true); | 118 element->setActivatedSubmit(true); |
| 114 m_clickLocation = extractClickLocation(event); | 119 m_clickLocation = extractClickLocation(event); |
| 115 element->form()->prepareForSubmission(event); // Event handlers can run. | 120 element->form()->prepareForSubmission(event); // Event handlers can run. |
| 116 element->setActivatedSubmit(false); | 121 element->setActivatedSubmit(false); |
| 117 event->setDefaultHandled(); | 122 event->setDefaultHandled(); |
| 118 } | 123 } |
| 119 | 124 |
| 120 RenderObject* ImageInputType::createRenderer(RenderStyle*) const | 125 RenderObject* ImageInputType::createRenderer(RenderStyle* style) const |
| 121 { | 126 { |
| 127 if (m_useFallbackContent && !element().shadowRoot() && element().userAgentSh adowRoot()) | |
| 128 return new RenderBlockFlow(&element()); | |
| 122 RenderImage* image = new RenderImage(&element()); | 129 RenderImage* image = new RenderImage(&element()); |
| 123 image->setImageResource(RenderImageResource::create()); | 130 image->setImageResource(RenderImageResource::create()); |
| 124 return image; | 131 return image; |
| 125 } | 132 } |
| 126 | 133 |
| 127 void ImageInputType::altAttributeChanged() | 134 void ImageInputType::altAttributeChanged() |
| 128 { | 135 { |
| 129 RenderImage* image = toRenderImage(element().renderer()); | 136 if (Text* text = altTextNode()) { |
|
esprehn
2014/09/05 00:47:52
Element* text = element().ensureUserAgentShadowRoo
rhogan
2014/09/08 19:52:42
I don't want to create the UA shadow root for ever
| |
| 130 if (!image) | 137 String alt = element().altText(); |
| 131 return; | 138 if (text->data() != alt) |
| 132 image->updateAltText(); | 139 text->setData(alt); |
| 140 } | |
| 133 } | 141 } |
| 134 | 142 |
| 135 void ImageInputType::srcAttributeChanged() | 143 void ImageInputType::srcAttributeChanged() |
| 136 { | 144 { |
| 137 if (!element().renderer()) | 145 if (!element().renderer()) |
| 138 return; | 146 return; |
| 139 element().imageLoader()->updateFromElement(ImageLoader::UpdateIgnorePrevious Error); | 147 element().imageLoader()->updateFromElement(ImageLoader::UpdateIgnorePrevious Error); |
| 140 } | 148 } |
| 141 | 149 |
| 150 void ImageInputType::valueAttributeChanged() | |
| 151 { | |
| 152 if (m_useFallbackContent) | |
| 153 return; | |
| 154 BaseButtonInputType::valueAttributeChanged(); | |
| 155 } | |
| 156 | |
| 142 void ImageInputType::startResourceLoading() | 157 void ImageInputType::startResourceLoading() |
| 143 { | 158 { |
| 144 BaseButtonInputType::startResourceLoading(); | 159 BaseButtonInputType::startResourceLoading(); |
| 145 | 160 |
| 146 HTMLImageLoader* imageLoader = element().imageLoader(); | 161 HTMLImageLoader* imageLoader = element().imageLoader(); |
| 147 imageLoader->updateFromElement(); | 162 imageLoader->updateFromElement(); |
| 148 | 163 |
| 149 RenderImage* renderer = toRenderImage(element().renderer()); | 164 RenderObject* renderer = element().renderer(); |
| 150 if (!renderer) | 165 if (!renderer || !renderer->isRenderImage()) |
| 151 return; | 166 return; |
| 152 | 167 |
| 153 RenderImageResource* imageResource = renderer->imageResource(); | 168 RenderImageResource* imageResource = toRenderImage(renderer)->imageResource( ); |
| 154 imageResource->setImageResource(imageLoader->image()); | 169 imageResource->setImageResource(imageLoader->image()); |
| 155 | |
| 156 // If we have no image at all because we have no src attribute, set | |
| 157 // image height and width for the alt text instead. | |
| 158 if (!imageLoader->image() && !imageResource->cachedImage()) | |
| 159 renderer->setImageSizeForAltText(); | |
| 160 } | 170 } |
| 161 | 171 |
| 162 bool ImageInputType::shouldRespectAlignAttribute() | 172 bool ImageInputType::shouldRespectAlignAttribute() |
| 163 { | 173 { |
| 164 return true; | 174 return true; |
| 165 } | 175 } |
| 166 | 176 |
| 167 bool ImageInputType::canBeSuccessfulSubmitButton() | 177 bool ImageInputType::canBeSuccessfulSubmitButton() |
| 168 { | 178 { |
| 169 return true; | 179 return true; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 235 bool ImageInputType::hasLegalLinkAttribute(const QualifiedName& name) const | 245 bool ImageInputType::hasLegalLinkAttribute(const QualifiedName& name) const |
| 236 { | 246 { |
| 237 return name == srcAttr || BaseButtonInputType::hasLegalLinkAttribute(name); | 247 return name == srcAttr || BaseButtonInputType::hasLegalLinkAttribute(name); |
| 238 } | 248 } |
| 239 | 249 |
| 240 const QualifiedName& ImageInputType::subResourceAttributeName() const | 250 const QualifiedName& ImageInputType::subResourceAttributeName() const |
| 241 { | 251 { |
| 242 return srcAttr; | 252 return srcAttr; |
| 243 } | 253 } |
| 244 | 254 |
| 255 void ImageInputType::ensureFallbackContent() | |
| 256 { | |
| 257 if (m_useFallbackContent) | |
| 258 return; | |
| 259 setUseFallbackContent(); | |
| 260 if (!element().inDocument()) | |
|
esprehn
2014/09/05 00:47:52
Don't check this, reattach already knows how to do
rhogan
2014/09/08 19:52:42
Done
| |
| 261 return; | |
| 262 reattachFallbackContent(); | |
| 263 } | |
| 264 | |
| 265 void ImageInputType:: setUseFallbackContent() | |
|
esprehn
2014/09/05 00:47:51
extra space
rhogan
2014/09/08 19:52:42
Done
| |
| 266 { | |
| 267 if (m_useFallbackContent) | |
| 268 return; | |
| 269 m_useFallbackContent = true; | |
| 270 if (ShadowRoot* root = element().userAgentShadowRoot()) | |
| 271 root->removeChildren(); | |
|
esprehn
2014/09/05 00:47:52
ensureUserAgentShadowRoot().removeChildren();
rhogan
2014/09/08 19:52:42
Done
| |
| 272 createShadowSubtree(); | |
| 273 } | |
| 274 | |
| 275 void ImageInputType::ensurePrimaryContent() | |
| 276 { | |
| 277 if (!m_useFallbackContent || !element().inDocument()) | |
|
esprehn
2014/09/05 00:47:52
Don't check inDocument()
rhogan
2014/09/08 19:52:42
Done
| |
| 278 return; | |
| 279 m_useFallbackContent = false; | |
| 280 reattachFallbackContent(); | |
| 281 } | |
| 282 | |
| 283 void ImageInputType::reattachFallbackContent() | |
| 284 { | |
| 285 RefPtrWillBeRawPtr<HTMLInputElement> element(this->element()); | |
|
esprehn
2014/09/05 00:47:52
you don't need this ref ptr.
rhogan
2014/09/08 19:52:42
Done
| |
| 286 // This can happen inside of attach() in the middle of a recalcStyle so we n eed to | |
| 287 // reattach synchronously here. | |
| 288 if (element->document().inStyleRecalc()) | |
| 289 element->reattach(); | |
| 290 else | |
| 291 element->lazyReattachIfAttached(); | |
| 292 } | |
| 293 | |
| 294 void ImageInputType::createShadowSubtree() | |
| 295 { | |
| 296 if (!m_useFallbackContent) { | |
| 297 BaseButtonInputType::createShadowSubtree(); | |
| 298 return; | |
| 299 } | |
| 300 m_altTextNode = createAltTextShadowTree(&element()); | |
|
esprehn
2014/09/05 00:47:52
createAltTextShadowTree should take a reference, n
rhogan
2014/09/08 19:52:42
Done
| |
| 301 } | |
| 302 | |
| 303 PassRefPtr<RenderStyle> ImageInputType::customStyleForRenderer(PassRefPtr<Render Style> newStyle) | |
| 304 { | |
| 305 if (!m_useFallbackContent) | |
| 306 return newStyle; | |
| 307 | |
| 308 return customStyleForAltText(&element(), newStyle); | |
| 309 } | |
| 310 | |
| 245 } // namespace blink | 311 } // namespace blink |
| OLD | NEW |