Skip to content
This repository has been archived by the owner on Aug 4, 2022. It is now read-only.

Commit

Permalink
Bug 807613 - Add a pref to make the placeholder disappear when a text…
Browse files Browse the repository at this point in the history
… field is focused. r=bz
  • Loading branch information
mounirlamouri committed Nov 9, 2012
1 parent 63f55a4 commit 6dfb205
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 0 deletions.
7 changes: 7 additions & 0 deletions content/html/content/src/nsTextEditorState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down
6 changes: 6 additions & 0 deletions layout/forms/nsTextControlFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
20 changes: 20 additions & 0 deletions layout/reftests/forms/placeholder/placeholder-focus-pref.html
Original file line number Diff line number Diff line change
@@ -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>
1 change: 1 addition & 0 deletions layout/reftests/forms/placeholder/reftest.list
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions modules/libpref/src/init/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

0 comments on commit 6dfb205

Please sign in to comment.