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

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: Fix failing test 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 12 matching lines...) Expand all
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
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 void findCustomMessageTextDirection(const Element& anchor, const String& message, WebTextDirection& messageDir, String& subMessage, WebTextDirection& sub MessageDir)
70 {
71 bool hasStrongDirection;
72 subMessage = anchor.fastGetAttribute(HTMLNames::titleAttr);
73 messageDir = determineDirectionality(message, hasStrongDirection) == LTR ? W ebTextDirectionLeftToRight: WebTextDirectionRightToLeft;
74 if (!subMessage.isEmpty()) {
75 // Sub Msg takes direction of the element direction
76 AtomicString dir = anchor.fastGetAttribute(HTMLNames::dirAttr);
77 if (dir.isEmpty()) {
78 subMessageDir = anchor.renderer()->style()->direction() == LTR ? Web TextDirectionLeftToRight: WebTextDirectionRightToLeft;
79 } else {
80 subMessageDir = (equalIgnoringCase(dir, "auto") ? (determineDirectio nality(message, hasStrongDirection) == LTR ? WebTextDirectionLeftToRight: WebTex tDirectionRightToLeft)
81 : (equalIgnoringCase(dir, "ltr") ? WebTextDirectionLeftToRight: WebTextDirectionRightToLeft));
82 }
83 }
84 }
85
86 void ValidationMessageClientImpl::showValidationMessage(const Element& anchor, c onst String& message, MessageType type)
68 { 87 {
69 if (message.isEmpty()) { 88 if (message.isEmpty()) {
70 hideValidationMessage(anchor); 89 hideValidationMessage(anchor);
71 return; 90 return;
72 } 91 }
73 if (!anchor.renderBox()) 92 if (!anchor.renderBox())
74 return; 93 return;
75 if (m_currentAnchor) 94 if (m_currentAnchor)
76 hideValidationMessage(*m_currentAnchor); 95 hideValidationMessage(*m_currentAnchor);
77 m_currentAnchor = &anchor; 96 m_currentAnchor = &anchor;
78 IntRect anchorInRootView = currentView()->contentsToRootView(anchor.pixelSna ppedBoundingBox()); 97 IntRect anchorInRootView = currentView()->contentsToRootView(anchor.pixelSna ppedBoundingBox());
79 m_lastAnchorRectInScreen = currentView()->hostWindow()->rootViewToScreen(anc horInRootView); 98 m_lastAnchorRectInScreen = currentView()->hostWindow()->rootViewToScreen(anc horInRootView);
80 m_lastPageScaleFactor = m_webView.pageScaleFactor(); 99 m_lastPageScaleFactor = m_webView.pageScaleFactor();
81 m_message = message; 100 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; 101 const double minimumSecondToShowValidationMessage = 5.0;
88 const double secondPerCharacter = 0.05; 102 const double secondPerCharacter = 0.05;
89 const double statusCheckInterval = 0.1; 103 const double statusCheckInterval = 0.1;
90 m_finishTime = monotonicallyIncreasingTime() + std::max(minimumSecondToShowV alidationMessage, (message.length() + title.length()) * secondPerCharacter); 104
105 unsigned length;
106 String subMsg = String();
107 WebTextDirection messageDir, subMsgDir = WebTextDirectionLeftToRight;
108
109 if (type == CannedMessage)
110 messageDir = m_currentAnchor->locale().isRTL() ? WebTextDirectionRightTo Left: WebTextDirectionLeftToRight;
tkent 2014/07/18 13:57:49 Looking at the element locale is wrong at this mom
Habib Virji 2014/07/18 15:37:45 Okay, I was more looking for browser UI locale. As
tkent 2014/07/22 01:29:56 There is. But using determineDirectionality for c
111 else
112 findCustomMessageTextDirection(anchor, message, messageDir, subMsg, subM sgDir);
113
114 length = message.length() + (!subMsg.isNull() ? subMsg.length() : 0);
115 m_webView.client()->showValidationMessage(anchorInRootView, m_message, messa geDir, subMsg, subMsgDir);
116 m_webView.client()->showValidationMessage(anchorInRootView, m_message, subMs g, subMsgDir);
117
118 m_finishTime = monotonicallyIncreasingTime() + std::max(minimumSecondToShowV alidationMessage, length * secondPerCharacter);
91 // FIXME: We should invoke checkAnchorStatus actively when layout, scroll, 119 // FIXME: We should invoke checkAnchorStatus actively when layout, scroll,
92 // or page scale change happen. 120 // or page scale change happen.
93 m_timer.startRepeating(statusCheckInterval, FROM_HERE); 121 m_timer.startRepeating(statusCheckInterval, FROM_HERE);
94 } 122 }
95 123
96 void ValidationMessageClientImpl::hideValidationMessage(const Element& anchor) 124 void ValidationMessageClientImpl::hideValidationMessage(const Element& anchor)
97 { 125 {
98 if (!m_currentAnchor || !isValidationMessageVisible(anchor)) 126 if (!m_currentAnchor || !isValidationMessageVisible(anchor))
99 return; 127 return;
100 m_timer.stop(); 128 m_timer.stop();
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 hideValidationMessage(*m_currentAnchor); 174 hideValidationMessage(*m_currentAnchor);
147 } 175 }
148 176
149 void ValidationMessageClientImpl::trace(Visitor* visitor) 177 void ValidationMessageClientImpl::trace(Visitor* visitor)
150 { 178 {
151 visitor->trace(m_currentAnchor); 179 visitor->trace(m_currentAnchor);
152 ValidationMessageClient::trace(visitor); 180 ValidationMessageClient::trace(visitor);
153 } 181 }
154 182
155 } 183 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698