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

Unified Diff: Source/web/ValidationMessageClientImpl.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: 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/web/ValidationMessageClientImpl.h ('k') | public/web/WebViewClient.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/web/ValidationMessageClientImpl.cpp
diff --git a/Source/web/ValidationMessageClientImpl.cpp b/Source/web/ValidationMessageClientImpl.cpp
index 54b7bda41d4839454acc377d4744d96858d83dc5..55643cb8a1744efa1f133eae9786e2da3d186ef2 100644
--- a/Source/web/ValidationMessageClientImpl.cpp
+++ b/Source/web/ValidationMessageClientImpl.cpp
@@ -28,8 +28,10 @@
#include "core/dom/Element.h"
#include "core/frame/FrameView.h"
+#include "core/html/HTMLInputElement.h"
#include "core/rendering/RenderObject.h"
#include "platform/HostWindow.h"
+#include "platform/text/PlatformLocale.h"
#include "public/platform/WebRect.h"
#include "public/platform/WebString.h"
#include "public/web/WebTextDirection.h"
@@ -64,7 +66,14 @@ FrameView* ValidationMessageClientImpl::currentView()
return m_currentAnchor->document().view();
}
-void ValidationMessageClientImpl::showValidationMessage(const Element& anchor, const String& message)
+static WebTextDirection firstStrongDirection(String message)
leviw_travelin_and_unemployed 2014/07/14 19:13:50 Shouldn't you be iterating over the string until y
Habib Virji 2014/07/15 16:33:31 Agreed, updated code to use determineDirectionalit
+{
+ const UChar32 character= message.is8Bit() ? message.characters8()[0] : message.characters16()[0];
+ WTF::Unicode::Direction charDirection = WTF::Unicode::direction(character);
+ return charDirection == WTF::Unicode::LeftToRight ? WebTextDirectionLeftToRight: WebTextDirectionRightToLeft;
leviw_travelin_and_unemployed 2014/07/14 19:13:50 This seems wrong. If the *first character* is some
Habib Virji 2014/07/15 16:33:31 Done.
+}
+
+void ValidationMessageClientImpl::showValidationMessage(const Element& anchor, const String& message, bool customError)
{
if (message.isEmpty()) {
hideValidationMessage(anchor);
@@ -79,15 +88,29 @@ void ValidationMessageClientImpl::showValidationMessage(const Element& anchor, c
m_lastAnchorRectInScreen = currentView()->hostWindow()->rootViewToScreen(anchorInRootView);
m_lastPageScaleFactor = m_webView.pageScaleFactor();
m_message = message;
-
- WebTextDirection dir = m_currentAnchor->renderer()->style()->direction() == RTL ? WebTextDirectionRightToLeft : WebTextDirectionLeftToRight;
- AtomicString title = m_currentAnchor->fastGetAttribute(HTMLNames::titleAttr);
- m_webView.client()->showValidationMessage(anchorInRootView, m_message, title, dir);
-
const double minimumSecondToShowValidationMessage = 5.0;
const double secondPerCharacter = 0.05;
const double statusCheckInterval = 0.1;
- m_finishTime = monotonicallyIncreasingTime() + std::max(minimumSecondToShowValidationMessage, (message.length() + title.length()) * secondPerCharacter);
+
+ if (!customError) {
+ m_webView.client()->showValidationMessage(anchorInRootView, m_message, m_currentAnchor->locale().isRTL() ? WebTextDirectionRightToLeft: WebTextDirectionLeftToRight, String(), WebTextDirectionLeftToRight);
+ m_finishTime = monotonicallyIncreasingTime() + std::max(minimumSecondToShowValidationMessage, message.length() * secondPerCharacter);
+ } else {
+ AtomicString subMsg = m_currentAnchor->fastGetAttribute(HTMLNames::titleAttr);
+ WebTextDirection messageDir = firstStrongDirection(message);
+ WebTextDirection subMsgDir;
+ if (!subMsg.isEmpty()) {
+ // Sub Msg takes direction of the element direction
+ AtomicString dir = m_currentAnchor->fastGetAttribute(HTMLNames::dirAttr);
+ if (dir.isEmpty())
+ subMsgDir = m_currentAnchor->renderer()->style()->direction() == LTR ? WebTextDirectionLeftToRight: WebTextDirectionRightToLeft;
+ else
+ subMsgDir = (equalIgnoringCase(dir, "auto") ? firstStrongDirection(subMsg.string()): (equalIgnoringCase(dir, "ltr") ? WebTextDirectionLeftToRight: WebTextDirectionRightToLeft));
+ }
+ m_webView.client()->showValidationMessage(anchorInRootView, m_message, messageDir, subMsg, subMsgDir);
+ m_finishTime = monotonicallyIncreasingTime() + std::max(minimumSecondToShowValidationMessage, (message.length() + subMsg.length()) * secondPerCharacter);
+ }
+
// FIXME: We should invoke checkAnchorStatus actively when layout, scroll,
// or page scale change happen.
m_timer.startRepeating(statusCheckInterval, FROM_HERE);
« no previous file with comments | « Source/web/ValidationMessageClientImpl.h ('k') | public/web/WebViewClient.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698