Commit fa2d40dd authored by Elly Fong-Jones's avatar Elly Fong-Jones Committed by Commit Bot

views: support Mac textfield-focus behavior

On Mac, textfields always scroll to the start when gaining or losing focus;
this change implements that by:

1) On keyboard focus, doing a reversed SelectAll, so that the new selection
   "ends" at the logical start on Mac;
2) In OnBlur(), moving the selection to the logical start if PlatformStyle
   calls for same

Bug: 657558
Change-Id: I81c01f6ae5a546f1abb51a28638091907379d04e
Reviewed-on: https://chromium-review.googlesource.com/598122Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: Elly Fong-Jones <ellyjones@chromium.org>
Cr-Commit-Position: refs/heads/master@{#491723}
parent ed8ae789
......@@ -803,7 +803,7 @@ bool Textfield::CanHandleAccelerators() const {
}
void Textfield::AboutToRequestFocusFromTabTraversal(bool reverse) {
SelectAll(false);
SelectAll(PlatformStyle::kTextfieldScrollsToStartOnFocusChange);
}
bool Textfield::SkipDefaultKeyEventProcessing(const ui::KeyEvent& event) {
......@@ -1036,6 +1036,11 @@ void Textfield::OnFocus() {
void Textfield::OnBlur() {
gfx::RenderText* render_text = GetRenderText();
render_text->set_focused(false);
// If necessary, yank the cursor to the logical start of the textfield.
if (PlatformStyle::kTextfieldScrollsToStartOnFocusChange)
model_->MoveCursorTo(gfx::SelectionModel(0, gfx::CURSOR_FORWARD));
if (GetInputMethod()) {
GetInputMethod()->DetachTextInputClient(this);
#if defined(OS_CHROMEOS)
......
......@@ -50,6 +50,7 @@ const bool PlatformStyle::kTreeViewSelectionPaintsEntireRow = false;
const bool PlatformStyle::kTreeViewUsesOpenIcon = true;
const bool PlatformStyle::kUseRipples = true;
const bool PlatformStyle::kMirrorBubbleArrowInRTLByDefault = true;
const bool PlatformStyle::kTextfieldScrollsToStartOnFocusChange = false;
// static
std::unique_ptr<ScrollBar> PlatformStyle::CreateScrollBar(bool is_horizontal) {
......
......@@ -66,6 +66,10 @@ class VIEWS_EXPORT PlatformStyle {
// opens in the opposite direction.
static const bool kMirrorBubbleArrowInRTLByDefault;
// Whether to scroll text fields to the beginning when they gain or lose
// focus.
static const bool kTextfieldScrollsToStartOnFocusChange;
// Creates the default scrollbar for the given orientation.
static std::unique_ptr<ScrollBar> CreateScrollBar(bool is_horizontal);
......
......@@ -20,6 +20,7 @@ const bool PlatformStyle::kDefaultLabelButtonHasBoldFont = false;
const bool PlatformStyle::kDialogDefaultButtonCanBeCancel = false;
const bool PlatformStyle::kSelectWordOnRightClick = true;
const bool PlatformStyle::kSelectAllOnRightClickWhenUnfocused = true;
const bool PlatformStyle::kTextfieldScrollsToStartOnFocusChange = true;
const bool PlatformStyle::kTreeViewSelectionPaintsEntireRow = true;
const bool PlatformStyle::kTreeViewUsesOpenIcon = false;
const bool PlatformStyle::kUseRipples = false;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment