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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 { | 66 { |
67 if (message.isEmpty()) { | 67 if (message.isEmpty()) { |
68 hideValidationMessage(anchor); | 68 hideValidationMessage(anchor); |
69 return; | 69 return; |
70 } | 70 } |
71 if (!anchor.renderBox()) | 71 if (!anchor.renderBox()) |
72 return; | 72 return; |
73 if (m_currentAnchor) | 73 if (m_currentAnchor) |
74 hideValidationMessage(*m_currentAnchor); | 74 hideValidationMessage(*m_currentAnchor); |
75 m_currentAnchor = &anchor; | 75 m_currentAnchor = &anchor; |
76 IntRect anchorInRootView = currentView()->contentsToRootView(anchor.pixelSna
ppedBoundingBox()); | 76 IntRect anchorInViewport = currentView()->contentsToWindow(anchor.pixelSnapp
edBoundingBox()); |
77 m_lastAnchorRectInScreen = currentView()->hostWindow()->rootViewToScreen(anc
horInRootView); | 77 m_lastAnchorRectInScreen = currentView()->hostWindow()->viewportToScreen(anc
horInViewport); |
78 m_lastPageScaleFactor = m_webView.pageScaleFactor(); | 78 m_lastPageScaleFactor = m_webView.pageScaleFactor(); |
79 m_message = message; | 79 m_message = message; |
80 const double minimumSecondToShowValidationMessage = 5.0; | 80 const double minimumSecondToShowValidationMessage = 5.0; |
81 const double secondPerCharacter = 0.05; | 81 const double secondPerCharacter = 0.05; |
82 const double statusCheckInterval = 0.1; | 82 const double statusCheckInterval = 0.1; |
83 | 83 |
84 m_webView.client()->showValidationMessage(anchorInRootView, m_message, toWeb
TextDirection(messageDir), | 84 m_webView.client()->showValidationMessage(anchorInViewport, m_message, toWeb
TextDirection(messageDir), |
85 subMessage, toWebTextDirection(subMessageDir)); | 85 subMessage, toWebTextDirection(subMessageDir)); |
86 | 86 |
87 m_finishTime = monotonicallyIncreasingTime() + std::max(minimumSecondToShowV
alidationMessage, (message.length() + subMessage.length()) * secondPerCharacter)
; | 87 m_finishTime = monotonicallyIncreasingTime() + std::max(minimumSecondToShowV
alidationMessage, (message.length() + subMessage.length()) * secondPerCharacter)
; |
88 // FIXME: We should invoke checkAnchorStatus actively when layout, scroll, | 88 // FIXME: We should invoke checkAnchorStatus actively when layout, scroll, |
89 // or page scale change happen. | 89 // or page scale change happen. |
90 m_timer.startRepeating(statusCheckInterval, FROM_HERE); | 90 m_timer.startRepeating(statusCheckInterval, FROM_HERE); |
91 } | 91 } |
92 | 92 |
93 void ValidationMessageClientImpl::hideValidationMessage(const Element& anchor) | 93 void ValidationMessageClientImpl::hideValidationMessage(const Element& anchor) |
94 { | 94 { |
(...skipping 20 matching lines...) Expand all Loading... |
115 void ValidationMessageClientImpl::checkAnchorStatus(Timer<ValidationMessageClien
tImpl>*) | 115 void ValidationMessageClientImpl::checkAnchorStatus(Timer<ValidationMessageClien
tImpl>*) |
116 { | 116 { |
117 ASSERT(m_currentAnchor); | 117 ASSERT(m_currentAnchor); |
118 if (monotonicallyIncreasingTime() >= m_finishTime || !currentView()) { | 118 if (monotonicallyIncreasingTime() >= m_finishTime || !currentView()) { |
119 hideValidationMessage(*m_currentAnchor); | 119 hideValidationMessage(*m_currentAnchor); |
120 return; | 120 return; |
121 } | 121 } |
122 | 122 |
123 // Check the visibility of the element. | 123 // Check the visibility of the element. |
124 // FIXME: Can we check invisibility by scrollable non-frame elements? | 124 // FIXME: Can we check invisibility by scrollable non-frame elements? |
125 IntRect newAnchorRect = currentView()->contentsToRootView(m_currentAnchor->p
ixelSnappedBoundingBox()); | 125 IntRect newAnchorRectInViewport = currentView()->contentsToWindow(m_currentA
nchor->pixelSnappedBoundingBox()); |
126 newAnchorRect = intersection(currentView()->convertToContainingWindow(curren
tView()->boundsRect()), newAnchorRect); | 126 |
127 if (newAnchorRect.isEmpty()) { | 127 // FIXME: This intersection eliminates the part of the rect outside the root
view. |
| 128 // If this is meant as a visiblity test, intersecting it against the viewpor
t rect |
| 129 // likely makes more sense. |
| 130 newAnchorRectInViewport = intersection(currentView()->convertToContainingWin
dow(currentView()->boundsRect()), newAnchorRectInViewport); |
| 131 if (newAnchorRectInViewport.isEmpty()) { |
128 hideValidationMessage(*m_currentAnchor); | 132 hideValidationMessage(*m_currentAnchor); |
129 return; | 133 return; |
130 } | 134 } |
131 | 135 |
132 IntRect newAnchorRectInScreen = currentView()->hostWindow()->rootViewToScree
n(newAnchorRect); | 136 IntRect newAnchorRectInViewportInScreen = currentView()->hostWindow()->viewp
ortToScreen(newAnchorRectInViewport); |
133 if (newAnchorRectInScreen == m_lastAnchorRectInScreen && m_webView.pageScale
Factor() == m_lastPageScaleFactor) | 137 if (newAnchorRectInViewportInScreen == m_lastAnchorRectInScreen && m_webView
.pageScaleFactor() == m_lastPageScaleFactor) |
134 return; | 138 return; |
135 m_lastAnchorRectInScreen = newAnchorRectInScreen; | 139 m_lastAnchorRectInScreen = newAnchorRectInViewportInScreen; |
136 m_lastPageScaleFactor = m_webView.pageScaleFactor(); | 140 m_lastPageScaleFactor = m_webView.pageScaleFactor(); |
137 m_webView.client()->moveValidationMessage(newAnchorRect); | 141 m_webView.client()->moveValidationMessage(newAnchorRectInViewport); |
138 } | 142 } |
139 | 143 |
140 void ValidationMessageClientImpl::willBeDestroyed() | 144 void ValidationMessageClientImpl::willBeDestroyed() |
141 { | 145 { |
142 if (m_currentAnchor) | 146 if (m_currentAnchor) |
143 hideValidationMessage(*m_currentAnchor); | 147 hideValidationMessage(*m_currentAnchor); |
144 } | 148 } |
145 | 149 |
146 DEFINE_TRACE(ValidationMessageClientImpl) | 150 DEFINE_TRACE(ValidationMessageClientImpl) |
147 { | 151 { |
148 visitor->trace(m_currentAnchor); | 152 visitor->trace(m_currentAnchor); |
149 ValidationMessageClient::trace(visitor); | 153 ValidationMessageClient::trace(visitor); |
150 } | 154 } |
151 | 155 |
152 } // namespace blink | 156 } // namespace blink |
OLD | NEW |