| 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" | |
| 29 #include "core/events/MouseEvent.h" | 28 #include "core/events/MouseEvent.h" |
| 30 #include "core/fetch/ImageResource.h" | 29 #include "core/fetch/ImageResource.h" |
| 31 #include "core/html/FormDataList.h" | 30 #include "core/html/FormDataList.h" |
| 32 #include "core/html/HTMLFormElement.h" | 31 #include "core/html/HTMLFormElement.h" |
| 33 #include "core/html/HTMLImageFallbackHelper.h" | |
| 34 #include "core/html/HTMLImageLoader.h" | 32 #include "core/html/HTMLImageLoader.h" |
| 35 #include "core/html/HTMLInputElement.h" | 33 #include "core/html/HTMLInputElement.h" |
| 36 #include "core/html/parser/HTMLParserIdioms.h" | 34 #include "core/html/parser/HTMLParserIdioms.h" |
| 37 #include "core/rendering/RenderBlockFlow.h" | |
| 38 #include "core/rendering/RenderImage.h" | 35 #include "core/rendering/RenderImage.h" |
| 39 #include "wtf/PassOwnPtr.h" | 36 #include "wtf/PassOwnPtr.h" |
| 40 #include "wtf/text/StringBuilder.h" | 37 #include "wtf/text/StringBuilder.h" |
| 41 | 38 |
| 42 namespace blink { | 39 namespace blink { |
| 43 | 40 |
| 44 using namespace HTMLNames; | 41 using namespace HTMLNames; |
| 45 | 42 |
| 46 inline ImageInputType::ImageInputType(HTMLInputElement& element) | 43 inline ImageInputType::ImageInputType(HTMLInputElement& element) |
| 47 : BaseButtonInputType(element) | 44 : BaseButtonInputType(element) |
| 48 , m_useFallbackContent(false) | |
| 49 { | 45 { |
| 50 } | 46 } |
| 51 | 47 |
| 52 PassRefPtrWillBeRawPtr<InputType> ImageInputType::create(HTMLInputElement& eleme
nt) | 48 PassRefPtrWillBeRawPtr<InputType> ImageInputType::create(HTMLInputElement& eleme
nt) |
| 53 { | 49 { |
| 54 return adoptRefWillBeNoop(new ImageInputType(element)); | 50 return adoptRefWillBeNoop(new ImageInputType(element)); |
| 55 } | 51 } |
| 56 | 52 |
| 57 const AtomicString& ImageInputType::formControlType() const | 53 const AtomicString& ImageInputType::formControlType() const |
| 58 { | 54 { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 RefPtrWillBeRawPtr<HTMLInputElement> element(this->element()); | 110 RefPtrWillBeRawPtr<HTMLInputElement> element(this->element()); |
| 115 if (element->isDisabledFormControl() || !element->form()) | 111 if (element->isDisabledFormControl() || !element->form()) |
| 116 return; | 112 return; |
| 117 element->setActivatedSubmit(true); | 113 element->setActivatedSubmit(true); |
| 118 m_clickLocation = extractClickLocation(event); | 114 m_clickLocation = extractClickLocation(event); |
| 119 element->form()->prepareForSubmission(event); // Event handlers can run. | 115 element->form()->prepareForSubmission(event); // Event handlers can run. |
| 120 element->setActivatedSubmit(false); | 116 element->setActivatedSubmit(false); |
| 121 event->setDefaultHandled(); | 117 event->setDefaultHandled(); |
| 122 } | 118 } |
| 123 | 119 |
| 124 RenderObject* ImageInputType::createRenderer(RenderStyle* style) const | 120 RenderObject* ImageInputType::createRenderer(RenderStyle*) const |
| 125 { | 121 { |
| 126 if (m_useFallbackContent) | |
| 127 return new RenderBlockFlow(&element()); | |
| 128 RenderImage* image = new RenderImage(&element()); | 122 RenderImage* image = new RenderImage(&element()); |
| 129 image->setImageResource(RenderImageResource::create()); | 123 image->setImageResource(RenderImageResource::create()); |
| 130 return image; | 124 return image; |
| 131 } | 125 } |
| 132 | 126 |
| 133 void ImageInputType::altAttributeChanged() | 127 void ImageInputType::altAttributeChanged() |
| 134 { | 128 { |
| 135 if (element().userAgentShadowRoot()) { | 129 RenderImage* image = toRenderImage(element().renderer()); |
| 136 Element* text = element().userAgentShadowRoot()->getElementById("alttext
"); | 130 if (!image) |
| 137 String value = element().altText(); | 131 return; |
| 138 if (text && text->textContent() != value) | 132 image->updateAltText(); |
| 139 text->setTextContent(element().altText()); | |
| 140 } | |
| 141 } | 133 } |
| 142 | 134 |
| 143 void ImageInputType::srcAttributeChanged() | 135 void ImageInputType::srcAttributeChanged() |
| 144 { | 136 { |
| 145 if (!element().renderer()) | 137 if (!element().renderer()) |
| 146 return; | 138 return; |
| 147 element().ensureImageLoader().updateFromElement(ImageLoader::UpdateIgnorePre
viousError); | 139 element().ensureImageLoader().updateFromElement(ImageLoader::UpdateIgnorePre
viousError); |
| 148 } | 140 } |
| 149 | 141 |
| 150 void ImageInputType::valueAttributeChanged() | |
| 151 { | |
| 152 if (m_useFallbackContent) | |
| 153 return; | |
| 154 BaseButtonInputType::valueAttributeChanged(); | |
| 155 } | |
| 156 | |
| 157 void ImageInputType::startResourceLoading() | 142 void ImageInputType::startResourceLoading() |
| 158 { | 143 { |
| 159 BaseButtonInputType::startResourceLoading(); | 144 BaseButtonInputType::startResourceLoading(); |
| 160 | 145 |
| 161 HTMLImageLoader& imageLoader = element().ensureImageLoader(); | 146 HTMLImageLoader& imageLoader = element().ensureImageLoader(); |
| 162 imageLoader.updateFromElement(); | 147 imageLoader.updateFromElement(); |
| 163 | 148 |
| 164 RenderObject* renderer = element().renderer(); | 149 RenderImage* renderer = toRenderImage(element().renderer()); |
| 165 if (!renderer || !renderer->isRenderImage()) | 150 if (!renderer) |
| 166 return; | 151 return; |
| 167 | 152 |
| 168 RenderImageResource* imageResource = toRenderImage(renderer)->imageResource(
); | 153 RenderImageResource* imageResource = renderer->imageResource(); |
| 169 imageResource->setImageResource(imageLoader.image()); | 154 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(); |
| 170 } | 160 } |
| 171 | 161 |
| 172 bool ImageInputType::shouldRespectAlignAttribute() | 162 bool ImageInputType::shouldRespectAlignAttribute() |
| 173 { | 163 { |
| 174 return true; | 164 return true; |
| 175 } | 165 } |
| 176 | 166 |
| 177 bool ImageInputType::canBeSuccessfulSubmitButton() | 167 bool ImageInputType::canBeSuccessfulSubmitButton() |
| 178 { | 168 { |
| 179 return true; | 169 return true; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 bool ImageInputType::hasLegalLinkAttribute(const QualifiedName& name) const | 226 bool ImageInputType::hasLegalLinkAttribute(const QualifiedName& name) const |
| 237 { | 227 { |
| 238 return name == srcAttr || BaseButtonInputType::hasLegalLinkAttribute(name); | 228 return name == srcAttr || BaseButtonInputType::hasLegalLinkAttribute(name); |
| 239 } | 229 } |
| 240 | 230 |
| 241 const QualifiedName& ImageInputType::subResourceAttributeName() const | 231 const QualifiedName& ImageInputType::subResourceAttributeName() const |
| 242 { | 232 { |
| 243 return srcAttr; | 233 return srcAttr; |
| 244 } | 234 } |
| 245 | 235 |
| 246 void ImageInputType::ensureFallbackContent() | |
| 247 { | |
| 248 if (m_useFallbackContent) | |
| 249 return; | |
| 250 setUseFallbackContent(); | |
| 251 reattachFallbackContent(); | |
| 252 } | |
| 253 | |
| 254 void ImageInputType::setUseFallbackContent() | |
| 255 { | |
| 256 if (m_useFallbackContent) | |
| 257 return; | |
| 258 m_useFallbackContent = true; | |
| 259 if (element().document().inStyleRecalc()) | |
| 260 return; | |
| 261 if (ShadowRoot* root = element().userAgentShadowRoot()) | |
| 262 root->removeChildren(); | |
| 263 createShadowSubtree(); | |
| 264 } | |
| 265 | |
| 266 void ImageInputType::ensurePrimaryContent() | |
| 267 { | |
| 268 if (!m_useFallbackContent) | |
| 269 return; | |
| 270 m_useFallbackContent = false; | |
| 271 reattachFallbackContent(); | |
| 272 } | |
| 273 | |
| 274 void ImageInputType::reattachFallbackContent() | |
| 275 { | |
| 276 // This can happen inside of attach() in the middle of a recalcStyle so we n
eed to | |
| 277 // reattach synchronously here. | |
| 278 if (element().document().inStyleRecalc()) | |
| 279 element().reattach(); | |
| 280 else | |
| 281 element().lazyReattachIfAttached(); | |
| 282 } | |
| 283 | |
| 284 void ImageInputType::createShadowSubtree() | |
| 285 { | |
| 286 if (!m_useFallbackContent) { | |
| 287 BaseButtonInputType::createShadowSubtree(); | |
| 288 return; | |
| 289 } | |
| 290 HTMLImageFallbackHelper::createAltTextShadowTree(element()); | |
| 291 } | |
| 292 | |
| 293 PassRefPtr<RenderStyle> ImageInputType::customStyleForRenderer(PassRefPtr<Render
Style> newStyle) | |
| 294 { | |
| 295 if (!m_useFallbackContent) | |
| 296 return newStyle; | |
| 297 | |
| 298 return HTMLImageFallbackHelper::customStyleForAltText(element(), newStyle); | |
| 299 } | |
| 300 | |
| 301 } // namespace blink | 236 } // namespace blink |
| OLD | NEW |