~ubuntu-branches/ubuntu/karmic/webkit/karmic-proposed

« back to all changes in this revision

Viewing changes to WebCore/html/HTMLInputElement.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Gustavo Noronha Silva
  • Date: 2009-05-15 18:30:58 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20090515183058-50q5exjo9b1kxy9s
Tags: 1.1.7-1
* New upstream release
* debian/libwebkit-1.0-2.symbols:
- updated with the new symbols in 1.1.7
* debian/libwebkit-dev.install, debian/libwebkit-dev.links,
  debian/rules:
- Build, and ship gtk-doc documentation (Closes: #526683)
* debian/copyright:
- updated.

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
#include "ScriptEventListener.h"
45
45
#include "KeyboardEvent.h"
46
46
#include "LocalizedStrings.h"
 
47
#include "MappedAttribute.h"
47
48
#include "MouseEvent.h"
48
49
#include "Page.h"
49
50
#include "RenderButton.h"
96
97
    removeFromForm();
97
98
}
98
99
 
99
 
const AtomicString& HTMLInputElement::name() const
 
100
const AtomicString& HTMLInputElement::formControlName() const
100
101
{
101
102
    return m_data.name();
102
103
}
229
230
        newType = SEARCH;
230
231
    else if (equalIgnoringCase(t, "range"))
231
232
        newType = RANGE;
 
233
    else if (equalIgnoringCase(t, "email"))
 
234
        newType = EMAIL;
 
235
    else if (equalIgnoringCase(t, "number"))
 
236
        newType = NUMBER;
 
237
    else if (equalIgnoringCase(t, "tel"))
 
238
        newType = TELEPHONE;
 
239
    else if (equalIgnoringCase(t, "url"))
 
240
        newType = URL;
232
241
    else
233
242
        newType = TEXT;
234
243
 
274
283
 
275
284
            if (didRespectHeightAndWidth != willRespectHeightAndWidth) {
276
285
                NamedMappedAttrMap* map = mappedAttributes();
 
286
                ASSERT(map);
277
287
                if (Attribute* height = map->getAttributeItem(heightAttr))
278
288
                    attributeChanged(height, false);
279
289
                if (Attribute* width = map->getAttributeItem(widthAttr))
299
309
        m_imageLoader.clear();
300
310
}
301
311
 
302
 
const AtomicString& HTMLInputElement::type() const
 
312
const AtomicString& HTMLInputElement::formControlType() const
303
313
{
304
314
    // needs to be lowercase according to DOM spec
305
315
    switch (inputType()) {
311
321
            DEFINE_STATIC_LOCAL(const AtomicString, checkbox, ("checkbox"));
312
322
            return checkbox;
313
323
        }
 
324
        case EMAIL: {
 
325
            DEFINE_STATIC_LOCAL(const AtomicString, email, ("email"));
 
326
            return email;
 
327
        }
314
328
        case FILE: {
315
329
            DEFINE_STATIC_LOCAL(const AtomicString, file, ("file"));
316
330
            return file;
325
339
        }
326
340
        case ISINDEX:
327
341
            return emptyAtom;
 
342
        case NUMBER: {
 
343
            DEFINE_STATIC_LOCAL(const AtomicString, number, ("number"));
 
344
            return number;
 
345
        }
328
346
        case PASSWORD: {
329
347
            DEFINE_STATIC_LOCAL(const AtomicString, password, ("password"));
330
348
            return password;
349
367
            DEFINE_STATIC_LOCAL(const AtomicString, submit, ("submit"));
350
368
            return submit;
351
369
        }
 
370
        case TELEPHONE: {
 
371
            DEFINE_STATIC_LOCAL(const AtomicString, telephone, ("tel"));
 
372
            return telephone;
 
373
        }
352
374
        case TEXT: {
353
375
            DEFINE_STATIC_LOCAL(const AtomicString, text, ("text"));
354
376
            return text;
355
377
        }
 
378
        case URL: {
 
379
            DEFINE_STATIC_LOCAL(const AtomicString, url, ("url"));
 
380
            return url;
 
381
        }
356
382
    }
357
383
    return emptyAtom;
358
384
}
359
385
 
360
 
bool HTMLInputElement::saveState(String& result) const
 
386
bool HTMLInputElement::saveFormControlState(String& result) const
361
387
{
362
388
    if (!autoComplete())
363
389
        return false;
364
390
 
365
391
    switch (inputType()) {
366
392
        case BUTTON:
 
393
        case EMAIL:
367
394
        case FILE:
368
395
        case HIDDEN:
369
396
        case IMAGE:
370
397
        case ISINDEX:
 
398
        case NUMBER:
371
399
        case RANGE:
372
400
        case RESET:
373
401
        case SEARCH:
374
402
        case SUBMIT:
 
403
        case TELEPHONE:
375
404
        case TEXT:
 
405
        case URL:
376
406
            result = value();
377
407
            return true;
378
408
        case CHECKBOX:
386
416
    return false;
387
417
}
388
418
 
389
 
void HTMLInputElement::restoreState(const String& state)
 
419
void HTMLInputElement::restoreFormControlState(const String& state)
390
420
{
391
421
    ASSERT(inputType() != PASSWORD); // should never save/restore password fields
392
422
    switch (inputType()) {
393
423
        case BUTTON:
 
424
        case EMAIL:
394
425
        case FILE:
395
426
        case HIDDEN:
396
427
        case IMAGE:
397
428
        case ISINDEX:
 
429
        case NUMBER:
398
430
        case RANGE:
399
431
        case RESET:
400
432
        case SEARCH:
401
433
        case SUBMIT:
 
434
        case TELEPHONE:
402
435
        case TEXT:
 
436
        case URL:
403
437
            setValue(state);
404
438
            break;
405
439
        case CHECKBOX:
495
529
        case HIDDEN:
496
530
            // a no-op for this type
497
531
            break;
 
532
        case EMAIL:
498
533
        case ISINDEX:
 
534
        case NUMBER:
499
535
        case PASSWORD:
500
536
        case SEARCH:
 
537
        case TELEPHONE:
501
538
        case TEXT:
 
539
        case URL:
502
540
            // should never restore previous selection here
503
541
            focus(false);
504
542
            break;
549
587
        // We only need to setChanged if the form is looking at the default value right now.
550
588
        if (m_data.value().isNull())
551
589
            setNeedsStyleRecalc();
552
 
        setValueMatchesRenderer(false);
 
590
        setFormControlValueMatchesRenderer(false);
553
591
    } else if (attr->name() == checkedAttr) {
554
592
        m_defaultChecked = !attr->isNull();
555
593
        if (m_useDefaultChecked) {
631
669
    switch (inputType()) {
632
670
        case BUTTON:
633
671
        case CHECKBOX:
 
672
        case EMAIL:
634
673
        case FILE:
635
674
        case IMAGE:
636
675
        case ISINDEX:
 
676
        case NUMBER:
637
677
        case PASSWORD:
638
678
        case RADIO:
639
679
        case RANGE:
640
680
        case RESET:
641
681
        case SEARCH:
642
682
        case SUBMIT:
 
683
        case TELEPHONE:
643
684
        case TEXT:
 
685
        case URL:
644
686
            return HTMLFormControlElementWithState::rendererIsNeeded(style);
645
687
        case HIDDEN:
646
688
            return false;
667
709
            return new (arena) RenderImage(this);
668
710
        case RANGE:
669
711
            return new (arena) RenderSlider(this);
 
712
        case EMAIL:
670
713
        case ISINDEX:
 
714
        case NUMBER:
671
715
        case PASSWORD:
672
716
        case SEARCH:
 
717
        case TELEPHONE:
673
718
        case TEXT:
 
719
        case URL:
674
720
            return new (arena) RenderTextControlSingleLine(this);
675
721
    }
676
722
    ASSERT(false);
706
752
void HTMLInputElement::detach()
707
753
{
708
754
    HTMLFormControlElementWithState::detach();
709
 
    setValueMatchesRenderer(false);
 
755
    setFormControlValueMatchesRenderer(false);
710
756
}
711
757
 
712
758
String HTMLInputElement::altText() const
749
795
        return false;
750
796
 
751
797
    switch (inputType()) {
 
798
        case EMAIL:
752
799
        case HIDDEN:
753
800
        case ISINDEX:
 
801
        case NUMBER:
754
802
        case PASSWORD:
755
803
        case RANGE:
756
804
        case SEARCH:
 
805
        case TELEPHONE:
757
806
        case TEXT:
 
807
        case URL:
758
808
            // always successful
759
809
            encoding.appendData(name(), value());
760
810
            return true;
904
954
        switch (inputType()) {
905
955
            case BUTTON:
906
956
            case CHECKBOX:
 
957
            case EMAIL:
907
958
            case FILE:
908
959
            case HIDDEN:
909
960
            case IMAGE:
910
961
            case ISINDEX:
 
962
            case NUMBER:
911
963
            case PASSWORD:
912
964
            case RADIO:
913
965
            case RANGE:
914
966
            case SEARCH:
 
967
            case TELEPHONE:
915
968
            case TEXT:
 
969
            case URL:
916
970
                break;
917
971
            case RESET:
918
972
                v = resetButtonDefaultLabel();
933
987
    if (inputType() == FILE && !value.isEmpty())
934
988
        return;
935
989
 
936
 
    setValueMatchesRenderer(false);
 
990
    setFormControlValueMatchesRenderer(false);
937
991
    if (storesValueSeparateFromAttribute()) {
938
992
        if (inputType() == FILE)
939
993
            m_fileList->clear();
961
1015
    InputElement::notifyFormStateChanged(m_data, document());
962
1016
}
963
1017
 
964
 
String HTMLInputElement::placeholderValue() const
 
1018
String HTMLInputElement::placeholder() const
965
1019
{
966
1020
    return getAttribute(placeholderAttr).string();
967
1021
}
968
1022
 
 
1023
void HTMLInputElement::setPlaceholder(const String& value)
 
1024
{
 
1025
    setAttribute(placeholderAttr, value);
 
1026
}
 
1027
 
969
1028
bool HTMLInputElement::searchEventsShouldBeDispatched() const
970
1029
{
971
1030
    return hasAttribute(incrementalAttr);
985
1044
    for (int i = 0; i < size; i++)
986
1045
        m_fileList->append(File::create(paths[i]));
987
1046
 
988
 
    setValueMatchesRenderer();
 
1047
    setFormControlValueMatchesRenderer(true);
989
1048
    InputElement::notifyFormStateChanged(m_data, document());
990
1049
}
991
1050
 
1000
1059
        case RESET:
1001
1060
        case SUBMIT:
1002
1061
            return false;
 
1062
        case EMAIL:
1003
1063
        case FILE:
1004
1064
        case ISINDEX:
 
1065
        case NUMBER:
1005
1066
        case PASSWORD:
1006
1067
        case RANGE:
1007
1068
        case SEARCH:
 
1069
        case TELEPHONE:
1008
1070
        case TEXT:
 
1071
        case URL:
1009
1072
            return true;
1010
1073
    }
1011
1074
    return false;
1171
1234
        if (charCode == '\r') {
1172
1235
            switch (inputType()) {
1173
1236
                case CHECKBOX:
 
1237
                case EMAIL:
1174
1238
                case HIDDEN:
1175
1239
                case ISINDEX:
 
1240
                case NUMBER:
1176
1241
                case PASSWORD:
1177
1242
                case RANGE:
1178
1243
                case SEARCH:
 
1244
                case TELEPHONE:
1179
1245
                case TEXT:
 
1246
                case URL:
1180
1247
                    // Simulate mouse click on the default form button for enter for these types of elements.
1181
1248
                    clickDefaultFormButton = true;
1182
1249
                    break;
1294
1361
                    if (!checked())
1295
1362
                        clickElement = true;
1296
1363
                    break;
 
1364
                case EMAIL:
1297
1365
                case HIDDEN:
1298
1366
                case ISINDEX:
 
1367
                case NUMBER:
1299
1368
                case PASSWORD:
1300
1369
                case RANGE:
1301
1370
                case SEARCH:
 
1371
                case TELEPHONE:
1302
1372
                case TEXT:
 
1373
                case URL:
1303
1374
                    break;
1304
1375
            }
1305
1376
        }