-
Notifications
You must be signed in to change notification settings - Fork 50.2k
Minimally support iframes (nested browsing contexts) in selection event handling #12037
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
6940e33
Prefer node’s window and document over globals
acusti 3f3c1d7
Support active elements in nested browsing contexts
acusti b08a270
Merge branch 'master' into minimal-iframes
acusti 51be426
Avoid invoking defaultView getter unnecessarily
acusti 3714067
Prefer node’s window and document over globals
acusti 66b8766
Support active elements in nested browsing contexts
acusti 75bc65e
Avoid invoking defaultView getter unnecessarily
acusti 5a61b66
Implement selection event fixtures
f752792
Prefer node’s window and document over globals
acusti a8fcf05
Avoid invoking defaultView getter unnecessarily
acusti 0003681
Fix react-scripts to work with alphas after 16.0.0
fef8519
Run prettier on new selection events fixtures
799ee39
Add fixture for onSelect in iframes, remove DraftJS fixture
6e3d4b7
Merge branch 'minimal-iframes' of github.com:brandcast/react into min…
acusti d1ad016
Purge remnants of draft.js from fixtures
acusti 3c32963
Use prop-types import instead of window global
acusti 3f7b5c5
Make fixtures’ Iframe component Firefox-compatible
acusti 05d8969
Merge branch 'master' into minimal-iframes
acusti a776570
Merge branch 'master' into minimal-iframes
acusti 26e9d82
Merge branch 'master' into minimal-iframes
wilsonhyng 4db5c44
Fix switch case for SelectionEventsFixture
wilsonhyng ccf0329
Remove draft.js / immutable.js dependencies
wilsonhyng 2edf1f8
Cache owner doc as var to avoid reading it twice
wilsonhyng db02b65
Add documentation for getActiveElementDeep to explain try/catch
wilsonhyng 75b9992
Ensure getActiveElement always returns DOM element
wilsonhyng 0f1de45
Tighten up isNode and isTextNode
wilsonhyng 95b2aef
Remove ie8 compatibility
wilsonhyng d997ba8
Specify cross-origin example in getActiveElementDeep
wilsonhyng e63391c
Revert back to returning null if document is not defined
wilsonhyng File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
Prefer node’s window and document over globals
- Loading branch information
commit 6940e33b6977d0a6839d4322d98bb9709dcfdf73
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -64,32 +64,55 @@ function getSelection(node) { | |
| start: node.selectionStart, | ||
| end: node.selectionEnd, | ||
| }; | ||
| } else if (window.getSelection) { | ||
| const selection = window.getSelection(); | ||
| return { | ||
| anchorNode: selection.anchorNode, | ||
| anchorOffset: selection.anchorOffset, | ||
| focusNode: selection.focusNode, | ||
| focusOffset: selection.focusOffset, | ||
| }; | ||
| } else { | ||
| let win = window; | ||
| if (node.ownerDocument && node.ownerDocument.defaultView) { | ||
| win = node.ownerDocument.defaultView; | ||
| } | ||
| if (win.getSelection) { | ||
|
||
| const selection = win.getSelection(); | ||
| return { | ||
| anchorNode: selection.anchorNode, | ||
| anchorOffset: selection.anchorOffset, | ||
| focusNode: selection.focusNode, | ||
| focusOffset: selection.focusOffset, | ||
| }; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Get document associated with the event target. | ||
| * | ||
| * @param {object} nativeEventTarget | ||
| * @return {Document} | ||
| */ | ||
| function getEventTargetDocument(eventTarget) { | ||
| return eventTarget.window === eventTarget | ||
| ? eventTarget.document | ||
| : eventTarget.nodeType === DOCUMENT_NODE | ||
| ? eventTarget | ||
| : eventTarget.ownerDocument; | ||
| } | ||
|
|
||
| /** | ||
| * Poll selection to see whether it's changed. | ||
| * | ||
| * @param {object} nativeEvent | ||
| * @param {object} nativeEventTarget | ||
| * @return {?SyntheticEvent} | ||
| */ | ||
| function constructSelectEvent(nativeEvent, nativeEventTarget) { | ||
| // Ensure we have the right element, and that the user is not dragging a | ||
| // selection (this matches native `select` event behavior). In HTML5, select | ||
| // fires only on input and textarea thus if there's no focused element we | ||
| // won't dispatch. | ||
| const doc = getEventTargetDocument(nativeEventTarget); | ||
|
|
||
| if ( | ||
| mouseDown || | ||
| activeElement == null || | ||
| activeElement !== getActiveElement() | ||
| activeElement !== getActiveElement(doc) | ||
| ) { | ||
| return null; | ||
| } | ||
|
|
@@ -140,12 +163,7 @@ const SelectEventPlugin = { | |
| nativeEvent, | ||
| nativeEventTarget, | ||
| ) { | ||
| const doc = | ||
| nativeEventTarget.window === nativeEventTarget | ||
| ? nativeEventTarget.document | ||
| : nativeEventTarget.nodeType === DOCUMENT_NODE | ||
| ? nativeEventTarget | ||
| : nativeEventTarget.ownerDocument; | ||
| const doc = getEventTargetDocument(nativeEventTarget); | ||
| // Track whether all listeners exists for this plugin. If none exist, we do | ||
| // not extract events. See #3639. | ||
| if (!doc || !isListeningToAllDependencies('onSelect', doc)) { | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
defaultViewis defined as a getter, and since we don't expect it to change withinsetOffsetsmaybe we should store the value in a local variable so we avoid triggering the getter twice.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made that change (for this line and two other instances) in 51be426