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

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

Issue 389343002: Custom validation message to take into account text direction (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Moved code from web to core Created 6 years, 5 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 19 matching lines...) Expand all
30 #include "core/html/HTMLFieldSetElement.h" 30 #include "core/html/HTMLFieldSetElement.h"
31 #include "core/html/HTMLFormElement.h" 31 #include "core/html/HTMLFormElement.h"
32 #include "core/html/HTMLInputElement.h" 32 #include "core/html/HTMLInputElement.h"
33 #include "core/html/HTMLLegendElement.h" 33 #include "core/html/HTMLLegendElement.h"
34 #include "core/html/ValidityState.h" 34 #include "core/html/ValidityState.h"
35 #include "core/frame/UseCounter.h" 35 #include "core/frame/UseCounter.h"
36 #include "core/page/Page.h" 36 #include "core/page/Page.h"
37 #include "core/page/ValidationMessageClient.h" 37 #include "core/page/ValidationMessageClient.h"
38 #include "core/rendering/RenderBox.h" 38 #include "core/rendering/RenderBox.h"
39 #include "core/rendering/RenderTheme.h" 39 #include "core/rendering/RenderTheme.h"
40 #include "platform/text/BidiTextRun.h"
40 #include "wtf/Vector.h" 41 #include "wtf/Vector.h"
41 42
42 namespace WebCore { 43 namespace WebCore {
43 44
44 using namespace HTMLNames; 45 using namespace HTMLNames;
45 46
46 HTMLFormControlElement::HTMLFormControlElement(const QualifiedName& tagName, Doc ument& document, HTMLFormElement* form) 47 HTMLFormControlElement::HTMLFormControlElement(const QualifiedName& tagName, Doc ument& document, HTMLFormElement* form)
47 : LabelableElement(tagName, document) 48 : LabelableElement(tagName, document)
48 , m_disabled(false) 49 , m_disabled(false)
49 , m_isAutofilled(false) 50 , m_isAutofilled(false)
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 if (m_willValidateInitialized && m_willValidate == newWillValidate) 399 if (m_willValidateInitialized && m_willValidate == newWillValidate)
399 return; 400 return;
400 m_willValidateInitialized = true; 401 m_willValidateInitialized = true;
401 m_willValidate = newWillValidate; 402 m_willValidate = newWillValidate;
402 setNeedsValidityCheck(); 403 setNeedsValidityCheck();
403 setNeedsStyleRecalc(SubtreeStyleChange); 404 setNeedsStyleRecalc(SubtreeStyleChange);
404 if (!m_willValidate) 405 if (!m_willValidate)
405 hideVisibleValidationMessage(); 406 hideVisibleValidationMessage();
406 } 407 }
407 408
409 static void findCustomMessageTextDirection(const Element* anchor, const String& message, TextDirection& messageDir, String& subMessage, TextDirection& subMessag eDir)
tkent 2014/07/22 01:29:56 |anchor| should be |const Element&|, or this funct
Habib Virji 2014/07/22 16:10:00 Done.
410 {
411 bool hasStrongDirection;
412 subMessage = anchor->fastGetAttribute(HTMLNames::titleAttr);
tkent 2014/07/22 01:29:56 You can omit HTMLNames::.
Habib Virji 2014/07/22 16:10:00 Done.
413 messageDir = determineDirectionality(message, hasStrongDirection);
414 if (!subMessage.isEmpty()) {
415 // Sub Msg takes direction of the element direction
416 AtomicString dir = anchor->fastGetAttribute(HTMLNames::dirAttr);
tkent 2014/07/22 01:29:56 Don't refer to |dir| attribute of the element to d
Habib Virji 2014/07/22 16:10:00 Done.
417 if (dir.isEmpty())
418 subMessageDir = anchor->renderer()->style()->direction();
419 else
420 subMessageDir = equalIgnoringCase(dir, "auto") ? determineDirectiona lity(message, hasStrongDirection) : (equalIgnoringCase(dir, "ltr") ? LTR: RTL);
421 }
422 }
423
408 void HTMLFormControlElement::updateVisibleValidationMessage() 424 void HTMLFormControlElement::updateVisibleValidationMessage()
409 { 425 {
410 Page* page = document().page(); 426 Page* page = document().page();
411 if (!page) 427 if (!page)
412 return; 428 return;
413 String message; 429 String message;
414 if (renderer() && willValidate()) 430 if (renderer() && willValidate())
415 message = validationMessage().stripWhiteSpace(); 431 message = validationMessage().stripWhiteSpace();
416 432
417 m_hasValidationMessage = true; 433 m_hasValidationMessage = true;
418 ValidationMessageClient* client = &page->validationMessageClient(); 434 ValidationMessageClient* client = &page->validationMessageClient();
419 if (message.isEmpty()) 435 if (message.isEmpty()) {
420 client->hideValidationMessage(*this); 436 client->hideValidationMessage(*this);
421 else 437 } else {
422 client->showValidationMessage(*this, message); 438 TextDirection messageDir, subMessageDir = LTR;
439 String subMessage = String();
440 findCustomMessageTextDirection(this, message, messageDir, subMessage, su bMessageDir);
441 client->showValidationMessage(*this, message, messageDir, subMessage, su bMessageDir);
442 }
423 } 443 }
424 444
425 void HTMLFormControlElement::hideVisibleValidationMessage() 445 void HTMLFormControlElement::hideVisibleValidationMessage()
426 { 446 {
427 if (!m_hasValidationMessage) 447 if (!m_hasValidationMessage)
428 return; 448 return;
429 449
430 if (ValidationMessageClient* client = validationMessageClient()) 450 if (ValidationMessageClient* client = validationMessageClient())
431 client->hideValidationMessage(*this); 451 client->hideValidationMessage(*this);
432 } 452 }
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 552
533 void HTMLFormControlElement::setFocus(bool flag) 553 void HTMLFormControlElement::setFocus(bool flag)
534 { 554 {
535 LabelableElement::setFocus(flag); 555 LabelableElement::setFocus(flag);
536 556
537 if (!flag && wasChangedSinceLastFormControlChangeEvent()) 557 if (!flag && wasChangedSinceLastFormControlChangeEvent())
538 dispatchFormControlChangeEvent(); 558 dispatchFormControlChangeEvent();
539 } 559 }
540 560
541 } // namespace Webcore 561 } // namespace Webcore
OLDNEW
« no previous file with comments | « no previous file | Source/core/page/ValidationMessageClient.h » ('j') | Source/core/page/ValidationMessageClient.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698