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

Unified Diff: Source/core/html/HTMLTextFormControlElement.cpp

Issue 392573002: HTMLTextAreaElement.setSelectionRange should not change focus. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fix tests 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/html/HTMLTextFormControlElement.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/html/HTMLTextFormControlElement.cpp
diff --git a/Source/core/html/HTMLTextFormControlElement.cpp b/Source/core/html/HTMLTextFormControlElement.cpp
index 0be4ed30e57525326a24bf65781fc336c2355071..cae3020820f0623c0cdbb3749837c0d4ec571c34 100644
--- a/Source/core/html/HTMLTextFormControlElement.cpp
+++ b/Source/core/html/HTMLTextFormControlElement.cpp
@@ -34,6 +34,7 @@
#include "core/dom/NodeTraversal.h"
#include "core/dom/Text.h"
#include "core/dom/shadow/ShadowRoot.h"
+#include "core/editing/Editor.h"
#include "core/editing/FrameSelection.h"
#include "core/editing/TextIterator.h"
#include "core/events/Event.h"
@@ -41,6 +42,9 @@
#include "core/frame/UseCounter.h"
#include "core/html/HTMLBRElement.h"
#include "core/html/shadow/ShadowElementNames.h"
+#include "core/page/FocusController.h"
+#include "core/page/Page.h"
+#include "core/rendering/RenderBlock.h"
#include "core/rendering/RenderBlockFlow.h"
#include "core/rendering/RenderTheme.h"
#include "platform/heap/Handle.h"
@@ -180,7 +184,11 @@ void HTMLTextFormControlElement::setSelectionDirection(const String& direction)
void HTMLTextFormControlElement::select()
{
- setSelectionRange(0, std::numeric_limits<int>::max(), SelectionHasNoDirection);
+ document().updateLayoutIgnorePendingStylesheets();
+ RefPtrWillBeRawPtr<HTMLTextFormControlElement> protector(this);
+ if (isFocusable())
+ document().page()->focusController().setFocusedElement(this, document().frame());
+ setSelectionRange(0, std::numeric_limits<int>::max(), SelectionHasNoDirection, ChangeSelection);
}
bool HTMLTextFormControlElement::shouldDispatchFormControlChangeEvent(String& oldValue, String& newValue)
@@ -274,10 +282,13 @@ void HTMLTextFormControlElement::setSelectionRange(int start, int end, const Str
else if (directionString == "backward")
direction = SelectionHasBackwardDirection;
+ if (direction == SelectionHasNoDirection && document().frame() && document().frame()->editor().behavior().shouldConsiderSelectionAsDirectional())
+ direction = SelectionHasForwardDirection;
+
return setSelectionRange(start, end, direction);
}
-void HTMLTextFormControlElement::setSelectionRange(int start, int end, TextFieldSelectionDirection direction)
+void HTMLTextFormControlElement::setSelectionRange(int start, int end, TextFieldSelectionDirection direction, SelectionOption selectionOption)
{
document().updateLayoutIgnorePendingStylesheets();
@@ -286,11 +297,18 @@ void HTMLTextFormControlElement::setSelectionRange(int start, int end, TextField
end = std::max(end, 0);
start = std::min(std::max(start, 0), end);
+ cacheSelection(start, end, direction);
+ if (!hasVisibleTextArea(renderer(), innerEditorElement()))
+ return;
+
+ LocalFrame* frame = document().frame();
- if (!hasVisibleTextArea(renderer(), innerEditorElement())) {
- cacheSelection(start, end, direction);
+ if (!frame)
return;
- }
+
+ if (selectionOption == NotChangeSelection && document().focusedElement() != this)
+ return;
+
VisiblePosition startPosition = visiblePositionForIndex(start);
VisiblePosition endPosition;
if (start == end)
@@ -311,8 +329,7 @@ void HTMLTextFormControlElement::setSelectionRange(int start, int end, TextField
newSelection = VisibleSelection(startPosition, endPosition);
newSelection.setIsDirectional(direction != SelectionHasNoDirection);
- if (LocalFrame* frame = document().frame())
- frame->selection().setSelection(newSelection);
+ frame->selection().setSelection(newSelection, FrameSelection::CloseTyping | FrameSelection::ClearTypingStyle | FrameSelection::DoNotSetFocus);
}
VisiblePosition HTMLTextFormControlElement::visiblePositionForIndex(int index) const
« no previous file with comments | « Source/core/html/HTMLTextFormControlElement.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698