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 12 matching lines...) Expand all Loading... | |
| 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/rendering/RenderObject.h" | 31 #include "core/rendering/RenderObject.h" |
| 32 #include "platform/HostWindow.h" | 32 #include "platform/HostWindow.h" |
| 33 #include "platform/text/BidiTextRun.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 void ValidationMessageClientImpl::showValidationMessage(const Element& anchor, c onst String& message, bool customError) |
| 68 { | 70 { |
| 69 if (message.isEmpty()) { | 71 if (message.isEmpty()) { |
| 70 hideValidationMessage(anchor); | 72 hideValidationMessage(anchor); |
| 71 return; | 73 return; |
| 72 } | 74 } |
| 73 if (!anchor.renderBox()) | 75 if (!anchor.renderBox()) |
| 74 return; | 76 return; |
| 75 if (m_currentAnchor) | 77 if (m_currentAnchor) |
| 76 hideValidationMessage(*m_currentAnchor); | 78 hideValidationMessage(*m_currentAnchor); |
| 77 m_currentAnchor = &anchor; | 79 m_currentAnchor = &anchor; |
| 78 IntRect anchorInRootView = currentView()->contentsToRootView(anchor.pixelSna ppedBoundingBox()); | 80 IntRect anchorInRootView = currentView()->contentsToRootView(anchor.pixelSna ppedBoundingBox()); |
| 79 m_lastAnchorRectInScreen = currentView()->hostWindow()->rootViewToScreen(anc horInRootView); | 81 m_lastAnchorRectInScreen = currentView()->hostWindow()->rootViewToScreen(anc horInRootView); |
| 80 m_lastPageScaleFactor = m_webView.pageScaleFactor(); | 82 m_lastPageScaleFactor = m_webView.pageScaleFactor(); |
| 81 m_message = message; | 83 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; | 84 const double minimumSecondToShowValidationMessage = 5.0; |
| 88 const double secondPerCharacter = 0.05; | 85 const double secondPerCharacter = 0.05; |
| 89 const double statusCheckInterval = 0.1; | 86 const double statusCheckInterval = 0.1; |
| 90 m_finishTime = monotonicallyIncreasingTime() + std::max(minimumSecondToShowV alidationMessage, (message.length() + title.length()) * secondPerCharacter); | 87 |
| 88 if (!customError) { | |
| 89 m_webView.client()->showValidationMessage(anchorInRootView, m_message, m _currentAnchor->locale().isRTL() ? WebTextDirectionRightToLeft: WebTextDirection LeftToRight, String(), WebTextDirectionLeftToRight); | |
| 90 m_finishTime = monotonicallyIncreasingTime() + std::max(minimumSecondToS howValidationMessage, message.length() * secondPerCharacter); | |
| 91 } else { | |
| 92 AtomicString subMsg = m_currentAnchor->fastGetAttribute(HTMLNames::title Attr); | |
| 93 bool hasStrongDirection; | |
| 94 WebTextDirection messageDir = determineDirectionality(message, hasStrong Direction) == LTR ? WebTextDirectionLeftToRight: WebTextDirectionRightToLeft; | |
| 95 WebTextDirection subMsgDir = WebTextDirectionLeftToRight; | |
| 96 if (!subMsg.isEmpty()) { | |
| 97 // Sub Msg takes direction of the element direction | |
| 98 AtomicString dir = m_currentAnchor->fastGetAttribute(HTMLNames::dirA ttr); | |
| 99 if (dir.isEmpty()) { | |
| 100 subMsgDir = m_currentAnchor->renderer()->style()->direction() == LTR ? WebTextDirectionLeftToRight: WebTextDirectionRightToLeft; | |
| 101 } else { | |
| 102 subMsgDir = (equalIgnoringCase(dir, "auto") ? (determineDirectio nality(message, hasStrongDirection) == LTR ? WebTextDirectionLeftToRight: WebTex tDirectionRightToLeft) | |
| 103 : (equalIgnoringCase(dir, "ltr") ? WebTextDirectionLeftToRig ht: WebTextDirectionRightToLeft)); | |
| 104 } | |
| 105 } | |
|
leviw_travelin_and_unemployed
2014/07/16 04:26:22
Can you put all this code into a helper function?
Habib Virji
2014/07/16 13:32:02
Done.
| |
| 106 m_webView.client()->showValidationMessage(anchorInRootView, m_message, m essageDir, subMsg, subMsgDir); | |
| 107 m_finishTime = monotonicallyIncreasingTime() + std::max(minimumSecondToS howValidationMessage, (message.length() + subMsg.length()) * secondPerCharacter) ; | |
|
leviw_travelin_and_unemployed
2014/07/16 04:26:22
It seems like this code doesn't need to be duplica
Habib Virji
2014/07/16 13:32:02
It had subMsg.length which differed, changed to av
| |
| 108 } | |
| 109 | |
| 91 // FIXME: We should invoke checkAnchorStatus actively when layout, scroll, | 110 // FIXME: We should invoke checkAnchorStatus actively when layout, scroll, |
| 92 // or page scale change happen. | 111 // or page scale change happen. |
| 93 m_timer.startRepeating(statusCheckInterval, FROM_HERE); | 112 m_timer.startRepeating(statusCheckInterval, FROM_HERE); |
| 94 } | 113 } |
| 95 | 114 |
| 96 void ValidationMessageClientImpl::hideValidationMessage(const Element& anchor) | 115 void ValidationMessageClientImpl::hideValidationMessage(const Element& anchor) |
| 97 { | 116 { |
| 98 if (!m_currentAnchor || !isValidationMessageVisible(anchor)) | 117 if (!m_currentAnchor || !isValidationMessageVisible(anchor)) |
| 99 return; | 118 return; |
| 100 m_timer.stop(); | 119 m_timer.stop(); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 146 hideValidationMessage(*m_currentAnchor); | 165 hideValidationMessage(*m_currentAnchor); |
| 147 } | 166 } |
| 148 | 167 |
| 149 void ValidationMessageClientImpl::trace(Visitor* visitor) | 168 void ValidationMessageClientImpl::trace(Visitor* visitor) |
| 150 { | 169 { |
| 151 visitor->trace(m_currentAnchor); | 170 visitor->trace(m_currentAnchor); |
| 152 ValidationMessageClient::trace(visitor); | 171 ValidationMessageClient::trace(visitor); |
| 153 } | 172 } |
| 154 | 173 |
| 155 } | 174 } |
| OLD | NEW |