Bug 807613 - Add a pref to make the placeholder disappear when a text field is focused. r=bz

This commit is contained in:
Mounir Lamouri 2012-11-09 10:32:58 +00:00
Родитель 225ba431b5
Коммит ae737c8efe
5 изменённых файлов: 37 добавлений и 0 удалений

Просмотреть файл

@ -38,6 +38,7 @@
#include "mozilla/Selection.h"
#include "nsEventListenerManager.h"
#include "nsContentUtils.h"
#include "mozilla/Preferences.h"
using namespace mozilla;
using namespace mozilla::dom;
@ -2002,6 +2003,12 @@ nsTextEditorState::UpdatePlaceholderVisibility(bool aNotify)
mPlaceholderVisibility = value.IsEmpty();
if (mPlaceholderVisibility &&
!Preferences::GetBool("dom.placeholder.show_on_focus", true)) {
nsCOMPtr<nsIContent> content = do_QueryInterface(mTextCtrlElement);
mPlaceholderVisibility = !nsContentUtils::IsFocusedContent(content);
}
if (mBoundFrame && aNotify) {
mBoundFrame->InvalidateFrame();
}

Просмотреть файл

@ -648,6 +648,12 @@ void nsTextControlFrame::SetFocus(bool aOn, bool aRepaint)
// Revoke the previous scroll event if one exists
mScrollEvent.Revoke();
// If 'dom.placeholeder.show_on_focus' preference is 'false', focusing or
// blurring the frame can have an impact on the placeholder visibility.
if (mUsePlaceholder) {
txtCtrl->UpdatePlaceholderVisibility(true);
}
if (!aOn) {
return;
}

Просмотреть файл

@ -0,0 +1,20 @@
<!DOCTYPE html>
<html class="reftest-wait">
<link rel='stylesheet' type='text/css' href='placeholder-style.css'>
<!-- Test: when focused, element should not placeholder when
'dom.placeholder.show_on_focus' pref is false. -->
<script type="text/javascript">
function focusPlaceholder()
{
document.getElementById('p1').focus();
}
function disableReftestWait()
{
document.documentElement.className = '';
}
</script>
<body onload="focusPlaceholder();">
<input type="text" id="p1" value="" placeholder="my placeholder" onfocus="disableReftestWait();">
</body>
</html>

Просмотреть файл

@ -32,3 +32,4 @@ random-if(winWidget) == placeholder-19.xul placeholder-overridden-ref.xul
needs-focus == placeholder-21.html placeholder-blank-ref.html
needs-focus == placeholder-22.html placeholder-blank-ref.html
== placeholder-rtl.html placeholder-rtl-ref.html
pref(dom.placeholder.show_on_focus,false) needs-focus == placeholder-focus-pref.html placeholder-blank-ref.html

Просмотреть файл

@ -3834,3 +3834,6 @@ pref("jsloader.reuseGlobal", false);
// When we're asked to take a screenshot, don't wait more than 2000ms for the
// event loop to become idle before actually taking the screenshot.
pref("dom.browserElement.maxScreenshotDelayMS", 2000);
// Whether we should show the placeholder when the element is focused but empty.
pref("dom.placeholder.show_on_focus", true);