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

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

Issue 27746003: Have InputType factories take an HTMLInputElement reference in parameter (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase on master Created 7 years, 2 months 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/InputType.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 *
(...skipping 21 matching lines...) Expand all
32 #include "core/html/HTMLInputElement.h" 32 #include "core/html/HTMLInputElement.h"
33 #include "core/html/forms/InputTypeNames.h" 33 #include "core/html/forms/InputTypeNames.h"
34 #include "core/html/parser/HTMLParserIdioms.h" 34 #include "core/html/parser/HTMLParserIdioms.h"
35 #include "core/rendering/RenderImage.h" 35 #include "core/rendering/RenderImage.h"
36 #include "wtf/PassOwnPtr.h" 36 #include "wtf/PassOwnPtr.h"
37 37
38 namespace WebCore { 38 namespace WebCore {
39 39
40 using namespace HTMLNames; 40 using namespace HTMLNames;
41 41
42 inline ImageInputType::ImageInputType(HTMLInputElement* element) 42 inline ImageInputType::ImageInputType(HTMLInputElement& element)
43 : BaseButtonInputType(element) 43 : BaseButtonInputType(element)
44 { 44 {
45 } 45 }
46 46
47 PassRefPtr<InputType> ImageInputType::create(HTMLInputElement* element) 47 PassRefPtr<InputType> ImageInputType::create(HTMLInputElement& element)
48 { 48 {
49 return adoptRef(new ImageInputType(element)); 49 return adoptRef(new ImageInputType(element));
50 } 50 }
51 51
52 const AtomicString& ImageInputType::formControlType() const 52 const AtomicString& ImageInputType::formControlType() const
53 { 53 {
54 return InputTypeNames::image(); 54 return InputTypeNames::image();
55 } 55 }
56 56
57 bool ImageInputType::isFormDataAppendable() const 57 bool ImageInputType::isFormDataAppendable() const
58 { 58 {
59 return true; 59 return true;
60 } 60 }
61 61
62 bool ImageInputType::appendFormData(FormDataList& encoding, bool) const 62 bool ImageInputType::appendFormData(FormDataList& encoding, bool) const
63 { 63 {
64 if (!element()->isActivatedSubmit()) 64 if (!element().isActivatedSubmit())
65 return false; 65 return false;
66 const AtomicString& name = element()->name(); 66 const AtomicString& name = element().name();
67 if (name.isEmpty()) { 67 if (name.isEmpty()) {
68 encoding.appendData("x", m_clickLocation.x()); 68 encoding.appendData("x", m_clickLocation.x());
69 encoding.appendData("y", m_clickLocation.y()); 69 encoding.appendData("y", m_clickLocation.y());
70 return true; 70 return true;
71 } 71 }
72 72
73 DEFINE_STATIC_LOCAL(String, dotXString, (".x")); 73 DEFINE_STATIC_LOCAL(String, dotXString, (".x"));
74 DEFINE_STATIC_LOCAL(String, dotYString, (".y")); 74 DEFINE_STATIC_LOCAL(String, dotYString, (".y"));
75 encoding.appendData(name + dotXString, m_clickLocation.x()); 75 encoding.appendData(name + dotXString, m_clickLocation.x());
76 encoding.appendData(name + dotYString, m_clickLocation.y()); 76 encoding.appendData(name + dotYString, m_clickLocation.y());
77 77
78 if (!element()->value().isEmpty()) 78 if (!element().value().isEmpty())
79 encoding.appendData(name, element()->value()); 79 encoding.appendData(name, element().value());
80 return true; 80 return true;
81 } 81 }
82 82
83 bool ImageInputType::supportsValidation() const 83 bool ImageInputType::supportsValidation() const
84 { 84 {
85 return false; 85 return false;
86 } 86 }
87 87
88 static IntPoint extractClickLocation(Event* event) 88 static IntPoint extractClickLocation(Event* event)
89 { 89 {
90 if (!event->underlyingEvent() || !event->underlyingEvent()->isMouseEvent()) 90 if (!event->underlyingEvent() || !event->underlyingEvent()->isMouseEvent())
91 return IntPoint(); 91 return IntPoint();
92 MouseEvent* mouseEvent = toMouseEvent(event->underlyingEvent()); 92 MouseEvent* mouseEvent = toMouseEvent(event->underlyingEvent());
93 if (mouseEvent->isSimulated()) 93 if (mouseEvent->isSimulated())
94 return IntPoint(); 94 return IntPoint();
95 return IntPoint(mouseEvent->offsetX(), mouseEvent->offsetY()); 95 return IntPoint(mouseEvent->offsetX(), mouseEvent->offsetY());
96 } 96 }
97 97
98 void ImageInputType::handleDOMActivateEvent(Event* event) 98 void ImageInputType::handleDOMActivateEvent(Event* event)
99 { 99 {
100 RefPtr<HTMLInputElement> element = this->element(); 100 RefPtr<HTMLInputElement> element(this->element());
101 if (element->isDisabledFormControl() || !element->form()) 101 if (element->isDisabledFormControl() || !element->form())
102 return; 102 return;
103 element->setActivatedSubmit(true); 103 element->setActivatedSubmit(true);
104 m_clickLocation = extractClickLocation(event); 104 m_clickLocation = extractClickLocation(event);
105 element->form()->prepareForSubmission(event); // Event handlers can run. 105 element->form()->prepareForSubmission(event); // Event handlers can run.
106 element->setActivatedSubmit(false); 106 element->setActivatedSubmit(false);
107 event->setDefaultHandled(); 107 event->setDefaultHandled();
108 } 108 }
109 109
110 RenderObject* ImageInputType::createRenderer(RenderStyle*) const 110 RenderObject* ImageInputType::createRenderer(RenderStyle*) const
111 { 111 {
112 RenderImage* image = new RenderImage(element()); 112 RenderImage* image = new RenderImage(&element());
113 image->setImageResource(RenderImageResource::create()); 113 image->setImageResource(RenderImageResource::create());
114 return image; 114 return image;
115 } 115 }
116 116
117 void ImageInputType::altAttributeChanged() 117 void ImageInputType::altAttributeChanged()
118 { 118 {
119 RenderImage* image = toRenderImage(element()->renderer()); 119 RenderImage* image = toRenderImage(element().renderer());
120 if (!image) 120 if (!image)
121 return; 121 return;
122 image->updateAltText(); 122 image->updateAltText();
123 } 123 }
124 124
125 void ImageInputType::srcAttributeChanged() 125 void ImageInputType::srcAttributeChanged()
126 { 126 {
127 if (!element()->renderer()) 127 if (!element().renderer())
128 return; 128 return;
129 element()->imageLoader()->updateFromElementIgnoringPreviousError(); 129 element().imageLoader()->updateFromElementIgnoringPreviousError();
130 } 130 }
131 131
132 void ImageInputType::attach() 132 void ImageInputType::attach()
133 { 133 {
134 BaseButtonInputType::attach(); 134 BaseButtonInputType::attach();
135 135
136 HTMLImageLoader* imageLoader = element()->imageLoader(); 136 HTMLImageLoader* imageLoader = element().imageLoader();
137 imageLoader->updateFromElement(); 137 imageLoader->updateFromElement();
138 138
139 RenderImage* renderer = toRenderImage(element()->renderer()); 139 RenderImage* renderer = toRenderImage(element().renderer());
140 if (!renderer) 140 if (!renderer)
141 return; 141 return;
142 142
143 if (imageLoader->hasPendingBeforeLoadEvent()) 143 if (imageLoader->hasPendingBeforeLoadEvent())
144 return; 144 return;
145 145
146 RenderImageResource* imageResource = renderer->imageResource(); 146 RenderImageResource* imageResource = renderer->imageResource();
147 imageResource->setImageResource(imageLoader->image()); 147 imageResource->setImageResource(imageLoader->image());
148 148
149 // If we have no image at all because we have no src attribute, set 149 // If we have no image at all because we have no src attribute, set
(...skipping 22 matching lines...) Expand all
172 return false; 172 return false;
173 } 173 }
174 174
175 bool ImageInputType::shouldRespectHeightAndWidthAttributes() 175 bool ImageInputType::shouldRespectHeightAndWidthAttributes()
176 { 176 {
177 return true; 177 return true;
178 } 178 }
179 179
180 unsigned ImageInputType::height() const 180 unsigned ImageInputType::height() const
181 { 181 {
182 RefPtr<HTMLInputElement> element = this->element(); 182 RefPtr<HTMLInputElement> element(this->element());
183 183
184 if (!element->renderer()) { 184 if (!element->renderer()) {
185 // Check the attribute first for an explicit pixel value. 185 // Check the attribute first for an explicit pixel value.
186 unsigned height; 186 unsigned height;
187 if (parseHTMLNonNegativeInteger(element->fastGetAttribute(heightAttr), h eight)) 187 if (parseHTMLNonNegativeInteger(element->fastGetAttribute(heightAttr), h eight))
188 return height; 188 return height;
189 189
190 // If the image is available, use its height. 190 // If the image is available, use its height.
191 if (element->hasImageLoader()) { 191 if (element->hasImageLoader()) {
192 HTMLImageLoader* imageLoader = element->imageLoader(); 192 HTMLImageLoader* imageLoader = element->imageLoader();
193 if (imageLoader->image()) 193 if (imageLoader->image())
194 return imageLoader->image()->imageSizeForRenderer(element->rende rer(), 1).height(); 194 return imageLoader->image()->imageSizeForRenderer(element->rende rer(), 1).height();
195 } 195 }
196 } 196 }
197 197
198 element->document().updateLayout(); 198 element->document().updateLayout();
199 199
200 RenderBox* box = element->renderBox(); 200 RenderBox* box = element->renderBox();
201 return box ? adjustForAbsoluteZoom(box->contentHeight(), box) : 0; 201 return box ? adjustForAbsoluteZoom(box->contentHeight(), box) : 0;
202 } 202 }
203 203
204 unsigned ImageInputType::width() const 204 unsigned ImageInputType::width() const
205 { 205 {
206 RefPtr<HTMLInputElement> element = this->element(); 206 RefPtr<HTMLInputElement> element(this->element());
207 207
208 if (!element->renderer()) { 208 if (!element->renderer()) {
209 // Check the attribute first for an explicit pixel value. 209 // Check the attribute first for an explicit pixel value.
210 unsigned width; 210 unsigned width;
211 if (parseHTMLNonNegativeInteger(element->fastGetAttribute(widthAttr), wi dth)) 211 if (parseHTMLNonNegativeInteger(element->fastGetAttribute(widthAttr), wi dth))
212 return width; 212 return width;
213 213
214 // If the image is available, use its width. 214 // If the image is available, use its width.
215 if (element->hasImageLoader()) { 215 if (element->hasImageLoader()) {
216 HTMLImageLoader* imageLoader = element->imageLoader(); 216 HTMLImageLoader* imageLoader = element->imageLoader();
217 if (imageLoader->image()) 217 if (imageLoader->image())
218 return imageLoader->image()->imageSizeForRenderer(element->rende rer(), 1).width(); 218 return imageLoader->image()->imageSizeForRenderer(element->rende rer(), 1).width();
219 } 219 }
220 } 220 }
221 221
222 element->document().updateLayout(); 222 element->document().updateLayout();
223 223
224 RenderBox* box = element->renderBox(); 224 RenderBox* box = element->renderBox();
225 return box ? adjustForAbsoluteZoom(box->contentWidth(), box) : 0; 225 return box ? adjustForAbsoluteZoom(box->contentWidth(), box) : 0;
226 } 226 }
227 227
228 } // namespace WebCore 228 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/html/forms/ImageInputType.h ('k') | Source/core/html/forms/InputType.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698