| 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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 { | 71 { |
| 72 if (message.isEmpty()) { | 72 if (message.isEmpty()) { |
| 73 hideValidationMessage(anchor); | 73 hideValidationMessage(anchor); |
| 74 return; | 74 return; |
| 75 } | 75 } |
| 76 if (!anchor.renderBox()) | 76 if (!anchor.renderBox()) |
| 77 return; | 77 return; |
| 78 if (m_currentAnchor) | 78 if (m_currentAnchor) |
| 79 hideValidationMessage(*m_currentAnchor); | 79 hideValidationMessage(*m_currentAnchor); |
| 80 m_currentAnchor = &anchor; | 80 m_currentAnchor = &anchor; |
| 81 m_lastAnchorRectInScreen = currentView()->contentsToScreen(anchor.pixelSnapp
edBoundingBox()); | 81 IntRect anchorInRootView = currentView()->contentsToRootView(anchor.pixelSna
ppedBoundingBox()); |
| 82 m_lastAnchorRectInScreen = currentView()->hostWindow()->rootViewToScreen(anc
horInRootView); |
| 82 m_lastPageScaleFactor = m_webView.pageScaleFactor(); | 83 m_lastPageScaleFactor = m_webView.pageScaleFactor(); |
| 83 m_message = message; | 84 m_message = message; |
| 84 askClientToShowValidationMessage(); | 85 |
| 86 WebTextDirection dir = m_currentAnchor->renderer()->style()->direction() ==
RTL ? WebTextDirectionRightToLeft : WebTextDirectionLeftToRight; |
| 87 AtomicString title = m_currentAnchor->fastGetAttribute(HTMLNames::titleAttr)
; |
| 88 m_client.showValidationMessage(anchorInRootView, m_message, title, dir); |
| 85 | 89 |
| 86 const double minimumSecondToShowValidationMessage = 5.0; | 90 const double minimumSecondToShowValidationMessage = 5.0; |
| 87 const double secondPerCharacter = 0.05; | 91 const double secondPerCharacter = 0.05; |
| 88 const double statusCheckInterval = 0.1; | 92 const double statusCheckInterval = 0.1; |
| 89 m_finishTime = monotonicallyIncreasingTime() + std::max(minimumSecondToShowV
alidationMessage, message.length() * secondPerCharacter); | 93 m_finishTime = monotonicallyIncreasingTime() + std::max(minimumSecondToShowV
alidationMessage, (message.length() + title.length()) * secondPerCharacter); |
| 90 // FIXME: We should invoke checkAnchorStatus actively when layout, scroll, | 94 // FIXME: We should invoke checkAnchorStatus actively when layout, scroll, |
| 91 // or page scale change happen. | 95 // or page scale change happen. |
| 92 m_timer.startRepeating(statusCheckInterval); | 96 m_timer.startRepeating(statusCheckInterval); |
| 93 } | 97 } |
| 94 | 98 |
| 95 void ValidationMessageClientImpl::askClientToShowValidationMessage() | |
| 96 { | |
| 97 WebTextDirection dir = m_currentAnchor->renderer()->style()->direction() ==
RTL ? WebTextDirectionRightToLeft : WebTextDirectionLeftToRight; | |
| 98 m_client.showValidationMessage(m_lastAnchorRectInScreen, m_message, m_curren
tAnchor->fastGetAttribute(HTMLNames::titleAttr), dir); | |
| 99 } | |
| 100 | |
| 101 void ValidationMessageClientImpl::hideValidationMessage(const Element& anchor) | 99 void ValidationMessageClientImpl::hideValidationMessage(const Element& anchor) |
| 102 { | 100 { |
| 103 if (!m_currentAnchor || !isValidationMessageVisible(anchor)) | 101 if (!m_currentAnchor || !isValidationMessageVisible(anchor)) |
| 104 return; | 102 return; |
| 105 m_timer.stop(); | 103 m_timer.stop(); |
| 106 m_currentAnchor = 0; | 104 m_currentAnchor = 0; |
| 107 m_message = String(); | 105 m_message = String(); |
| 108 m_finishTime = 0; | 106 m_finishTime = 0; |
| 109 m_client.hideValidationMessage(); | 107 m_client.hideValidationMessage(); |
| 110 } | 108 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 129 if (newAnchorRect.isEmpty()) { | 127 if (newAnchorRect.isEmpty()) { |
| 130 hideValidationMessage(*m_currentAnchor); | 128 hideValidationMessage(*m_currentAnchor); |
| 131 return; | 129 return; |
| 132 } | 130 } |
| 133 | 131 |
| 134 IntRect newAnchorRectInScreen = currentView()->hostWindow()->rootViewToScree
n(newAnchorRect); | 132 IntRect newAnchorRectInScreen = currentView()->hostWindow()->rootViewToScree
n(newAnchorRect); |
| 135 if (newAnchorRectInScreen == m_lastAnchorRectInScreen && m_webView.pageScale
Factor() == m_lastPageScaleFactor) | 133 if (newAnchorRectInScreen == m_lastAnchorRectInScreen && m_webView.pageScale
Factor() == m_lastPageScaleFactor) |
| 136 return; | 134 return; |
| 137 m_lastAnchorRectInScreen = newAnchorRectInScreen; | 135 m_lastAnchorRectInScreen = newAnchorRectInScreen; |
| 138 m_lastPageScaleFactor = m_webView.pageScaleFactor(); | 136 m_lastPageScaleFactor = m_webView.pageScaleFactor(); |
| 139 askClientToShowValidationMessage(); | 137 m_client.moveValidationMessage(newAnchorRect); |
| 140 } | 138 } |
| 141 | 139 |
| 142 } | 140 } |
| OLD | NEW |