Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(94)

Side by Side Diff: Source/web/ValidationMessageClientImpl.cpp

Issue 389343002: Custom validation message to take into account text direction (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Moved code from web to core Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 57
58 ValidationMessageClientImpl::~ValidationMessageClientImpl() 58 ValidationMessageClientImpl::~ValidationMessageClientImpl()
59 { 59 {
60 } 60 }
61 61
62 FrameView* ValidationMessageClientImpl::currentView() 62 FrameView* ValidationMessageClientImpl::currentView()
63 { 63 {
64 return m_currentAnchor->document().view(); 64 return m_currentAnchor->document().view();
65 } 65 }
66 66
67 void ValidationMessageClientImpl::showValidationMessage(const Element& anchor, c onst String& message) 67 void ValidationMessageClientImpl::showValidationMessage(const Element& anchor, c onst String& message, TextDirection messageDir, const String& subMessage, TextDi rection subMessageDir)
68 { 68 {
69 if (message.isEmpty()) { 69 if (message.isEmpty()) {
70 hideValidationMessage(anchor); 70 hideValidationMessage(anchor);
71 return; 71 return;
72 } 72 }
73 if (!anchor.renderBox()) 73 if (!anchor.renderBox())
74 return; 74 return;
75 if (m_currentAnchor) 75 if (m_currentAnchor)
76 hideValidationMessage(*m_currentAnchor); 76 hideValidationMessage(*m_currentAnchor);
77 m_currentAnchor = &anchor; 77 m_currentAnchor = &anchor;
78 IntRect anchorInRootView = currentView()->contentsToRootView(anchor.pixelSna ppedBoundingBox()); 78 IntRect anchorInRootView = currentView()->contentsToRootView(anchor.pixelSna ppedBoundingBox());
79 m_lastAnchorRectInScreen = currentView()->hostWindow()->rootViewToScreen(anc horInRootView); 79 m_lastAnchorRectInScreen = currentView()->hostWindow()->rootViewToScreen(anc horInRootView);
80 m_lastPageScaleFactor = m_webView.pageScaleFactor(); 80 m_lastPageScaleFactor = m_webView.pageScaleFactor();
81 m_message = message; 81 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; 82 const double minimumSecondToShowValidationMessage = 5.0;
88 const double secondPerCharacter = 0.05; 83 const double secondPerCharacter = 0.05;
89 const double statusCheckInterval = 0.1; 84 const double statusCheckInterval = 0.1;
90 m_finishTime = monotonicallyIncreasingTime() + std::max(minimumSecondToShowV alidationMessage, (message.length() + title.length()) * secondPerCharacter); 85
86 unsigned length = message.length() + (!subMessage.isNull() ? subMessage.leng th() : 0);
tkent 2014/07/22 01:29:56 Checking isNull is unnecessary. subMessage.length
Habib Virji 2014/07/22 16:10:00 Done.
87 m_webView.client()->showValidationMessage(anchorInRootView, m_message, messa geDir == LTR ? WebTextDirectionLeftToRight: WebTextDirectionRightToLeft,
88 subMessage, subMessageDir == LTR ? WebTextDirectionLeftToRight: WebTextD irectionRightToLeft);
89 m_webView.client()->showValidationMessage(anchorInRootView, m_message, subMe ssage, messageDir == LTR ? WebTextDirectionLeftToRight: WebTextDirectionRightToL eft);
90
91 m_finishTime = monotonicallyIncreasingTime() + std::max(minimumSecondToShowV alidationMessage, length * secondPerCharacter);
91 // FIXME: We should invoke checkAnchorStatus actively when layout, scroll, 92 // FIXME: We should invoke checkAnchorStatus actively when layout, scroll,
92 // or page scale change happen. 93 // or page scale change happen.
93 m_timer.startRepeating(statusCheckInterval, FROM_HERE); 94 m_timer.startRepeating(statusCheckInterval, FROM_HERE);
94 } 95 }
95 96
96 void ValidationMessageClientImpl::hideValidationMessage(const Element& anchor) 97 void ValidationMessageClientImpl::hideValidationMessage(const Element& anchor)
97 { 98 {
98 if (!m_currentAnchor || !isValidationMessageVisible(anchor)) 99 if (!m_currentAnchor || !isValidationMessageVisible(anchor))
99 return; 100 return;
100 m_timer.stop(); 101 m_timer.stop();
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 hideValidationMessage(*m_currentAnchor); 147 hideValidationMessage(*m_currentAnchor);
147 } 148 }
148 149
149 void ValidationMessageClientImpl::trace(Visitor* visitor) 150 void ValidationMessageClientImpl::trace(Visitor* visitor)
150 { 151 {
151 visitor->trace(m_currentAnchor); 152 visitor->trace(m_currentAnchor);
152 ValidationMessageClient::trace(visitor); 153 ValidationMessageClient::trace(visitor);
153 } 154 }
154 155
155 } 156 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698