Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 23 * SUCH DAMAGE. | 23 * SUCH DAMAGE. |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 #include "config.h" | 26 #include "config.h" |
| 27 #include "web/ValidationMessageClientImpl.h" | 27 #include "web/ValidationMessageClientImpl.h" |
| 28 | 28 |
| 29 #include "core/dom/Element.h" | 29 #include "core/dom/Element.h" |
| 30 #include "core/frame/FrameView.h" | 30 #include "core/frame/FrameView.h" |
| 31 #include "core/html/HTMLInputElement.h" | |
| 31 #include "core/rendering/RenderObject.h" | 32 #include "core/rendering/RenderObject.h" |
| 32 #include "platform/HostWindow.h" | 33 #include "platform/HostWindow.h" |
| 34 #include "platform/text/PlatformLocale.h" | |
| 33 #include "public/platform/WebRect.h" | 35 #include "public/platform/WebRect.h" |
| 34 #include "public/platform/WebString.h" | 36 #include "public/platform/WebString.h" |
| 35 #include "public/web/WebTextDirection.h" | 37 #include "public/web/WebTextDirection.h" |
| 36 #include "public/web/WebViewClient.h" | 38 #include "public/web/WebViewClient.h" |
| 37 #include "web/WebViewImpl.h" | 39 #include "web/WebViewImpl.h" |
| 38 #include "wtf/CurrentTime.h" | 40 #include "wtf/CurrentTime.h" |
| 39 | 41 |
| 40 using namespace WebCore; | 42 using namespace WebCore; |
| 41 | 43 |
| 42 namespace blink { | 44 namespace blink { |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 57 | 59 |
| 58 ValidationMessageClientImpl::~ValidationMessageClientImpl() | 60 ValidationMessageClientImpl::~ValidationMessageClientImpl() |
| 59 { | 61 { |
| 60 } | 62 } |
| 61 | 63 |
| 62 FrameView* ValidationMessageClientImpl::currentView() | 64 FrameView* ValidationMessageClientImpl::currentView() |
| 63 { | 65 { |
| 64 return m_currentAnchor->document().view(); | 66 return m_currentAnchor->document().view(); |
| 65 } | 67 } |
| 66 | 68 |
| 67 void ValidationMessageClientImpl::showValidationMessage(const Element& anchor, c onst String& message) | 69 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
| |
| 70 { | |
| 71 const UChar32 character= message.is8Bit() ? message.characters8()[0] : messa ge.characters16()[0]; | |
| 72 WTF::Unicode::Direction charDirection = WTF::Unicode::direction(character); | |
| 73 return charDirection == WTF::Unicode::LeftToRight ? WebTextDirectionLeftToRi ght: 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.
| |
| 74 } | |
| 75 | |
| 76 void ValidationMessageClientImpl::showValidationMessage(const Element& anchor, c onst String& message, bool customError) | |
| 68 { | 77 { |
| 69 if (message.isEmpty()) { | 78 if (message.isEmpty()) { |
| 70 hideValidationMessage(anchor); | 79 hideValidationMessage(anchor); |
| 71 return; | 80 return; |
| 72 } | 81 } |
| 73 if (!anchor.renderBox()) | 82 if (!anchor.renderBox()) |
| 74 return; | 83 return; |
| 75 if (m_currentAnchor) | 84 if (m_currentAnchor) |
| 76 hideValidationMessage(*m_currentAnchor); | 85 hideValidationMessage(*m_currentAnchor); |
| 77 m_currentAnchor = &anchor; | 86 m_currentAnchor = &anchor; |
| 78 IntRect anchorInRootView = currentView()->contentsToRootView(anchor.pixelSna ppedBoundingBox()); | 87 IntRect anchorInRootView = currentView()->contentsToRootView(anchor.pixelSna ppedBoundingBox()); |
| 79 m_lastAnchorRectInScreen = currentView()->hostWindow()->rootViewToScreen(anc horInRootView); | 88 m_lastAnchorRectInScreen = currentView()->hostWindow()->rootViewToScreen(anc horInRootView); |
| 80 m_lastPageScaleFactor = m_webView.pageScaleFactor(); | 89 m_lastPageScaleFactor = m_webView.pageScaleFactor(); |
| 81 m_message = message; | 90 m_message = message; |
| 82 | |
| 83 WebTextDirection dir = m_currentAnchor->renderer()->style()->direction() == RTL ? WebTextDirectionRightToLeft : WebTextDirectionLeftToRight; | |
| 84 AtomicString title = m_currentAnchor->fastGetAttribute(HTMLNames::titleAttr) ; | |
| 85 m_webView.client()->showValidationMessage(anchorInRootView, m_message, title , dir); | |
| 86 | |
| 87 const double minimumSecondToShowValidationMessage = 5.0; | 91 const double minimumSecondToShowValidationMessage = 5.0; |
| 88 const double secondPerCharacter = 0.05; | 92 const double secondPerCharacter = 0.05; |
| 89 const double statusCheckInterval = 0.1; | 93 const double statusCheckInterval = 0.1; |
| 90 m_finishTime = monotonicallyIncreasingTime() + std::max(minimumSecondToShowV alidationMessage, (message.length() + title.length()) * secondPerCharacter); | 94 |
| 95 if (!customError) { | |
| 96 m_webView.client()->showValidationMessage(anchorInRootView, m_message, m _currentAnchor->locale().isRTL() ? WebTextDirectionRightToLeft: WebTextDirection LeftToRight, String(), WebTextDirectionLeftToRight); | |
| 97 m_finishTime = monotonicallyIncreasingTime() + std::max(minimumSecondToS howValidationMessage, message.length() * secondPerCharacter); | |
| 98 } else { | |
| 99 AtomicString subMsg = m_currentAnchor->fastGetAttribute(HTMLNames::title Attr); | |
| 100 WebTextDirection messageDir = firstStrongDirection(message); | |
| 101 WebTextDirection subMsgDir; | |
| 102 if (!subMsg.isEmpty()) { | |
| 103 // Sub Msg takes direction of the element direction | |
| 104 AtomicString dir = m_currentAnchor->fastGetAttribute(HTMLNames::dirA ttr); | |
| 105 if (dir.isEmpty()) | |
| 106 subMsgDir = m_currentAnchor->renderer()->style()->direction() == LTR ? WebTextDirectionLeftToRight: WebTextDirectionRightToLeft; | |
| 107 else | |
| 108 subMsgDir = (equalIgnoringCase(dir, "auto") ? firstStrongDirecti on(subMsg.string()): (equalIgnoringCase(dir, "ltr") ? WebTextDirectionLeftToRigh t: WebTextDirectionRightToLeft)); | |
| 109 } | |
| 110 m_webView.client()->showValidationMessage(anchorInRootView, m_message, m essageDir, subMsg, subMsgDir); | |
| 111 m_finishTime = monotonicallyIncreasingTime() + std::max(minimumSecondToS howValidationMessage, (message.length() + subMsg.length()) * secondPerCharacter) ; | |
| 112 } | |
| 113 | |
| 91 // FIXME: We should invoke checkAnchorStatus actively when layout, scroll, | 114 // FIXME: We should invoke checkAnchorStatus actively when layout, scroll, |
| 92 // or page scale change happen. | 115 // or page scale change happen. |
| 93 m_timer.startRepeating(statusCheckInterval, FROM_HERE); | 116 m_timer.startRepeating(statusCheckInterval, FROM_HERE); |
| 94 } | 117 } |
| 95 | 118 |
| 96 void ValidationMessageClientImpl::hideValidationMessage(const Element& anchor) | 119 void ValidationMessageClientImpl::hideValidationMessage(const Element& anchor) |
| 97 { | 120 { |
| 98 if (!m_currentAnchor || !isValidationMessageVisible(anchor)) | 121 if (!m_currentAnchor || !isValidationMessageVisible(anchor)) |
| 99 return; | 122 return; |
| 100 m_timer.stop(); | 123 m_timer.stop(); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 146 hideValidationMessage(*m_currentAnchor); | 169 hideValidationMessage(*m_currentAnchor); |
| 147 } | 170 } |
| 148 | 171 |
| 149 void ValidationMessageClientImpl::trace(Visitor* visitor) | 172 void ValidationMessageClientImpl::trace(Visitor* visitor) |
| 150 { | 173 { |
| 151 visitor->trace(m_currentAnchor); | 174 visitor->trace(m_currentAnchor); |
| 152 ValidationMessageClient::trace(visitor); | 175 ValidationMessageClient::trace(visitor); |
| 153 } | 176 } |
| 154 | 177 |
| 155 } | 178 } |
| OLD | NEW |