Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(643)

Side by Side Diff: Source/core/html/forms/ImageInputType.cpp

Issue 696123002: Revert of Use Shadow DOM to display fallback content for images (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/html/forms/ImageInputType.h ('k') | Source/core/html/forms/InputTypeView.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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().imageLoader()->updateFromElement(ImageLoader::UpdateIgnorePrevious Error); 139 element().imageLoader()->updateFromElement(ImageLoader::UpdateIgnorePrevious Error);
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().imageLoader(); 146 HTMLImageLoader* imageLoader = element().imageLoader();
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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 bool ImageInputType::hasLegalLinkAttribute(const QualifiedName& name) const 230 bool ImageInputType::hasLegalLinkAttribute(const QualifiedName& name) const
241 { 231 {
242 return name == srcAttr || BaseButtonInputType::hasLegalLinkAttribute(name); 232 return name == srcAttr || BaseButtonInputType::hasLegalLinkAttribute(name);
243 } 233 }
244 234
245 const QualifiedName& ImageInputType::subResourceAttributeName() const 235 const QualifiedName& ImageInputType::subResourceAttributeName() const
246 { 236 {
247 return srcAttr; 237 return srcAttr;
248 } 238 }
249 239
250 void ImageInputType::ensureFallbackContent()
251 {
252 if (m_useFallbackContent)
253 return;
254 setUseFallbackContent();
255 reattachFallbackContent();
256 }
257
258 void ImageInputType::setUseFallbackContent()
259 {
260 if (m_useFallbackContent)
261 return;
262 m_useFallbackContent = true;
263 if (ShadowRoot* root = element().userAgentShadowRoot())
264 root->removeChildren();
265 createShadowSubtree();
266 }
267
268 void ImageInputType::ensurePrimaryContent()
269 {
270 if (!m_useFallbackContent)
271 return;
272 m_useFallbackContent = false;
273 reattachFallbackContent();
274 }
275
276 void ImageInputType::reattachFallbackContent()
277 {
278 // This can happen inside of attach() in the middle of a recalcStyle so we n eed to
279 // reattach synchronously here.
280 if (element().document().inStyleRecalc())
281 element().reattach();
282 else
283 element().lazyReattachIfAttached();
284 }
285
286 void ImageInputType::createShadowSubtree()
287 {
288 if (!m_useFallbackContent) {
289 BaseButtonInputType::createShadowSubtree();
290 return;
291 }
292 HTMLImageFallbackHelper::createAltTextShadowTree(element());
293 }
294
295 PassRefPtr<RenderStyle> ImageInputType::customStyleForRenderer(PassRefPtr<Render Style> newStyle)
296 {
297 if (!m_useFallbackContent)
298 return newStyle;
299
300 return HTMLImageFallbackHelper::customStyleForAltText(element(), newStyle);
301 }
302
303 } // namespace blink 240 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/html/forms/ImageInputType.h ('k') | Source/core/html/forms/InputTypeView.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698