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

Side by Side Diff: Source/core/html/HTMLTextFormControlElement.cpp

Issue 995363002: Implement autocapitalize in Blink to be used by the embedder. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: ready for review Created 5 years, 9 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller (mueller@kde.org) 4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. 5 * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
6 * (C) 2006 Alexey Proskuryakov (ap@nypop.com) 6 * (C) 2006 Alexey Proskuryakov (ap@nypop.com)
7 * 7 *
8 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public 9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 namespace blink { 56 namespace blink {
57 57
58 using namespace HTMLNames; 58 using namespace HTMLNames;
59 59
60 HTMLTextFormControlElement::HTMLTextFormControlElement(const QualifiedName& tagN ame, Document& doc, HTMLFormElement* form) 60 HTMLTextFormControlElement::HTMLTextFormControlElement(const QualifiedName& tagN ame, Document& doc, HTMLFormElement* form)
61 : HTMLFormControlElementWithState(tagName, doc, form) 61 : HTMLFormControlElementWithState(tagName, doc, form)
62 , m_lastChangeWasUserEdit(false) 62 , m_lastChangeWasUserEdit(false)
63 , m_cachedSelectionStart(0) 63 , m_cachedSelectionStart(0)
64 , m_cachedSelectionEnd(0) 64 , m_cachedSelectionEnd(0)
65 , m_cachedSelectionDirection(SelectionHasNoDirection) 65 , m_cachedSelectionDirection(SelectionHasNoDirection)
66 , m_autocapitalize(TextFieldAutocapitalize::Uninitialized)
66 { 67 {
67 } 68 }
68 69
69 HTMLTextFormControlElement::~HTMLTextFormControlElement() 70 HTMLTextFormControlElement::~HTMLTextFormControlElement()
70 { 71 {
71 } 72 }
72 73
73 Node::InsertionNotificationRequest HTMLTextFormControlElement::insertedInto(Cont ainerNode* insertionPoint) 74 Node::InsertionNotificationRequest HTMLTextFormControlElement::insertedInto(Cont ainerNode* insertionPoint)
74 { 75 {
75 HTMLFormControlElementWithState::insertedInto(insertionPoint); 76 HTMLFormControlElementWithState::insertedInto(insertionPoint);
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 542
542 offset += length; 543 offset += length;
543 } 544 }
544 545
545 if (!startNode || !endNode) 546 if (!startNode || !endNode)
546 return nullptr; 547 return nullptr;
547 548
548 return Range::create(document(), startNode, start, endNode, end); 549 return Range::create(document(), startNode, start, endNode, end);
549 } 550 }
550 551
552 static const AtomicString& autocapitalizeString(TextFieldAutocapitalize autocapi talize)
553 {
554 DEFINE_STATIC_LOCAL(const AtomicString, none, ("none", AtomicString::Constru ctFromLiteral));
555 DEFINE_STATIC_LOCAL(const AtomicString, characters, ("characters", AtomicStr ing::ConstructFromLiteral));
556 DEFINE_STATIC_LOCAL(const AtomicString, words, ("words", AtomicString::Const ructFromLiteral));
557 DEFINE_STATIC_LOCAL(const AtomicString, sentences, ("sentences", AtomicStrin g::ConstructFromLiteral));
558
559 switch (autocapitalize) {
560 case TextFieldAutocapitalize::Uninitialized:
561 ASSERT_NOT_REACHED();
562 case TextFieldAutocapitalize::None:
563 return none;
564 case TextFieldAutocapitalize::Characters:
565 return characters;
566 case TextFieldAutocapitalize::Words:
567 return words;
568 case TextFieldAutocapitalize::Sentences:
569 return sentences;
570 }
571
572 ASSERT_NOT_REACHED();
573 return none;
574 }
575
576 TextFieldAutocapitalize HTMLTextFormControlElement::autocapitalizeValue() const
577 {
578 if (m_autocapitalize == TextFieldAutocapitalize::Uninitialized)
579 return defaultAutocapitalizeValue();
580 return m_autocapitalize;
581 }
582
583 const AtomicString& HTMLTextFormControlElement::autocapitalize() const
584 {
585 return autocapitalizeString(autocapitalizeValue());
586 }
587
588 void HTMLTextFormControlElement::setAutocapitalize(const AtomicString& autocapit alize)
589 {
590 setAttribute(autocapitalizeAttr, autocapitalize);
591 }
592
551 void HTMLTextFormControlElement::restoreCachedSelection() 593 void HTMLTextFormControlElement::restoreCachedSelection()
552 { 594 {
553 setSelectionRange(m_cachedSelectionStart, m_cachedSelectionEnd, m_cachedSele ctionDirection, NotDispatchSelectEvent); 595 setSelectionRange(m_cachedSelectionStart, m_cachedSelectionEnd, m_cachedSele ctionDirection, NotDispatchSelectEvent);
554 } 596 }
555 597
556 void HTMLTextFormControlElement::selectionChanged(bool userTriggered) 598 void HTMLTextFormControlElement::selectionChanged(bool userTriggered)
557 { 599 {
558 if (!layoutObject() || !isTextFormControl()) 600 if (!layoutObject() || !isTextFormControl())
559 return; 601 return;
560 602
(...skipping 11 matching lines...) Expand all
572 RefPtrWillBeRawPtr<Event> event = Event::createBubble(EventTypeNames::select ); 614 RefPtrWillBeRawPtr<Event> event = Event::createBubble(EventTypeNames::select );
573 event->setTarget(this); 615 event->setTarget(this);
574 document().enqueueUniqueAnimationFrameEvent(event.release()); 616 document().enqueueUniqueAnimationFrameEvent(event.release());
575 } 617 }
576 618
577 void HTMLTextFormControlElement::parseAttribute(const QualifiedName& name, const AtomicString& value) 619 void HTMLTextFormControlElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
578 { 620 {
579 if (name == placeholderAttr) { 621 if (name == placeholderAttr) {
580 updatePlaceholderVisibility(true); 622 updatePlaceholderVisibility(true);
581 UseCounter::count(document(), UseCounter::PlaceholderAttribute); 623 UseCounter::count(document(), UseCounter::PlaceholderAttribute);
624 } else if (name == autocapitalizeAttr) {
625 if (equalIgnoringCase(value, "off") || equalIgnoringCase(value, "none"))
626 m_autocapitalize = TextFieldAutocapitalize::None;
627 else if (equalIgnoringCase(value, "characters"))
628 m_autocapitalize = TextFieldAutocapitalize::Characters;
629 else if (equalIgnoringCase(value, "words"))
630 m_autocapitalize = TextFieldAutocapitalize::Words;
631 else if (equalIgnoringCase(value, "sentences"))
632 m_autocapitalize = TextFieldAutocapitalize::Sentences;
633 else
634 m_autocapitalize = TextFieldAutocapitalize::Uninitialized;
582 } else 635 } else
583 HTMLFormControlElementWithState::parseAttribute(name, value); 636 HTMLFormControlElementWithState::parseAttribute(name, value);
584 } 637 }
585 638
586 bool HTMLTextFormControlElement::lastChangeWasUserEdit() const 639 bool HTMLTextFormControlElement::lastChangeWasUserEdit() const
587 { 640 {
588 if (!isTextFormControl()) 641 if (!isTextFormControl())
589 return false; 642 return false;
590 return m_lastChangeWasUserEdit; 643 return m_lastChangeWasUserEdit;
591 } 644 }
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
977 } 1030 }
978 1031
979 void HTMLTextFormControlElement::copyNonAttributePropertiesFromElement(const Ele ment& source) 1032 void HTMLTextFormControlElement::copyNonAttributePropertiesFromElement(const Ele ment& source)
980 { 1033 {
981 const HTMLTextFormControlElement& sourceElement = static_cast<const HTMLText FormControlElement&>(source); 1034 const HTMLTextFormControlElement& sourceElement = static_cast<const HTMLText FormControlElement&>(source);
982 m_lastChangeWasUserEdit = sourceElement.m_lastChangeWasUserEdit; 1035 m_lastChangeWasUserEdit = sourceElement.m_lastChangeWasUserEdit;
983 HTMLFormControlElement::copyNonAttributePropertiesFromElement(source); 1036 HTMLFormControlElement::copyNonAttributePropertiesFromElement(source);
984 } 1037 }
985 1038
986 } // namespace blink 1039 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698