Chromium Code Reviews| 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); |