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

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: Update validity before updatelayout 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
Index: Source/core/html/HTMLTextFormControlElement.cpp
diff --git a/Source/core/html/HTMLTextFormControlElement.cpp b/Source/core/html/HTMLTextFormControlElement.cpp
index 0be4ed30e57525326a24bf65781fc336c2355071..e2bbc50a9316b04771299a8399864d7e7a69f1df 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,12 @@ void HTMLTextFormControlElement::setSelectionDirection(const String& direction)
void HTMLTextFormControlElement::select()
{
- setSelectionRange(0, std::numeric_limits<int>::max(), SelectionHasNoDirection);
+ document().updateLayoutIgnorePendingStylesheets();
+ if (isFocusable()) {
+ RefPtrWillBeRawPtr<HTMLTextFormControlElement> protector(this);
tkent 2014/07/24 01:04:22 This should be moved to the outside of the |if|.
yoichio 2014/07/24 03:06:07 Done.
+ document().page()->focusController().setFocusedElement(this, document().frame());
+ }
+ setSelectionRange(0, std::numeric_limits<int>::max(), SelectionHasNoDirection, ChangeSelection);
}
bool HTMLTextFormControlElement::shouldDispatchFormControlChangeEvent(String& oldValue, String& newValue)
@@ -274,11 +283,15 @@ 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)
{
+ setNeedsValidityCheck();
document().updateLayoutIgnorePendingStylesheets();
if (!renderer() || !renderer()->isTextControl())
@@ -286,11 +299,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 +331,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
« Source/core/html/HTMLTextAreaElement.cpp ('K') | « Source/core/html/HTMLTextFormControlElement.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698