Skip to content
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

Position insertion point in input field with mouse #14291

Merged
merged 1 commit into from Jan 11, 2017

Conversation

@fiji-flo
Copy link
Contributor

fiji-flo commented Nov 20, 2016

Implements cursor positioning in input elements (text/password) via mouse. The related issue is #10083 but is only covered partly.
This PR does not cover:

  • positioning in textarea elements via mouse
  • text selection in input/textarea elements via mouse

  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes fix #10083 (github issue number if applicable).
  • There are tests for these changes OR
  • These changes do not require tests because I can't think of a way to test mouse interaction in the current test pipeline.

This change is Reviewable

@highfive
Copy link

highfive commented Nov 20, 2016

Heads up! This PR modifies the following files:

  • @KiChjang: components/script/dom/htmlinputelement.rs, components/script/dom/window.rs, components/script_layout_interface/message.rs, components/script_layout_interface/rpc.rs
  • @fitzgen: components/script/dom/htmlinputelement.rs, components/script/dom/window.rs, components/script_layout_interface/message.rs, components/script_layout_interface/rpc.rs
  • @emilio: components/layout/query.rs
@highfive
Copy link

highfive commented Nov 20, 2016

warning Warning warning

  • These commits modify unsafe code. Please review it carefully!
  • These commits modify gfx, layout, and script code, but no tests are modified. Please consider adding a test!
@bors-servo
Copy link
Contributor

bors-servo commented Dec 6, 2016

The latest upstream changes (presumably #14367) made this pull request unmergeable. Please resolve the merge conflicts.

@jdm
Copy link
Member

jdm commented Dec 6, 2016

@nox review ping.

@fiji-flo fiji-flo force-pushed the fiji-flo:text-input-select branch from 244bc44 to b130521 Dec 7, 2016
@fiji-flo
Copy link
Contributor Author

fiji-flo commented Dec 7, 2016

I rebased my branch to solve some merge conflicts.

@KiChjang KiChjang removed the S-needs-rebase label Dec 7, 2016
@jdm
Copy link
Member

jdm commented Dec 15, 2016

@nox Review ping.

@nox
Copy link
Member

nox commented Dec 16, 2016

I know nothing about gfx and layout. r? @pcwalton

@highfive highfive assigned pcwalton and unassigned nox Dec 16, 2016
Copy link
Member

emilio left a comment

Only minor nits. The approach in general makes sense to me (I'd need to review way more carefully though). Seems like @pcwalton can review this with less effort than I.

if !self.reflow(ReflowGoal::ForScriptQuery,
ReflowQueryType::TextIndexQuery(node, mouse_x, mouse_y),
ReflowReason::Query) {
println!("failed in reflow");

This comment has been minimized.

Copy link
@emilio

emilio Dec 16, 2016

Member

remove.

@@ -92,3 +94,6 @@ impl MarginStyleResponse {
}
}
}

#[derive(Clone)]
pub struct TextIndexResponse(pub Option<(usize)>);

This comment has been minimized.

Copy link
@emilio

emilio Dec 16, 2016

Member

Why not just TextIndexResponse(pub Option<usize>)?

This comment has been minimized.

Copy link
@fiji-flo

fiji-flo Dec 17, 2016

Author Contributor

An early draft had tuple here. Thanks for seeing this.

@@ -304,6 +304,24 @@ impl<'a> TextRun {
})
}

/// Returns the index in the range of the first glyph advancing over given advance
pub fn range_index_of_advance(&self, range: &Range<ByteIndex>, advance: Au) -> Option<usize> {
if range.is_empty() {

This comment has been minimized.

Copy link
@emilio

emilio Dec 16, 2016

Member

Is this check necessary? Doesn't natural_words_in_range handle empty ranges?

Also, this function seems to always return Some(..), so why not returning just an usize?

This comment has been minimized.

Copy link
@fiji-flo

fiji-flo Dec 17, 2016

Author Contributor

Indeed

@fiji-flo
Copy link
Contributor Author

fiji-flo commented Dec 17, 2016

@emilio Thanks for the first round of feedback. I'll go over it today.

@fiji-flo fiji-flo force-pushed the fiji-flo:text-input-select branch from b130521 to 7c08848 Dec 17, 2016
@fiji-flo fiji-flo force-pushed the fiji-flo:text-input-select branch from 7c08848 to 6f913e7 Jan 5, 2017
@fiji-flo
Copy link
Contributor Author

fiji-flo commented Jan 5, 2017

@jdm @pcwalton: I rebased and squashed the changes I did after emilio's comments. Could I get some feedback here?

@bors-servo
Copy link
Contributor

bors-servo commented Jan 10, 2017

The latest upstream changes (presumably #14938) made this pull request unmergeable. Please resolve the merge conflicts.

@jdm
Copy link
Member

jdm commented Jan 10, 2017

I'm really sorry about how this work has been received so far @fiji-flo ! I'll make sure it gets some traction today.

index += 1;
true
}
}).collect::<Vec<_>>();

This comment has been minimized.

Copy link
@pcwalton

pcwalton Jan 10, 2017

Contributor

It looks like you're collecting this into a vector and then throwing it away.

I recommend just using a for loop:

for glyph in self.iter_glyphs_for_byte_range(range) {
    ...
}

This comment has been minimized.

Copy link
@fiji-flo

fiji-flo Jan 10, 2017

Author Contributor

Indeed. My bad.

translated_point: &mut Point2D<Au>,
scroll_offsets: &ScrollOffsetMap) {
// Adjust the translated point to account for the scroll offset if
// necessary. This can only happen when WebRender is in use.

This comment has been minimized.

Copy link
@pcwalton

pcwalton Jan 10, 2017

Contributor

While you're here, could you remove the "This can only happen when WebRender is in use." bit? WebRender is always enabled now.

This comment has been minimized.

Copy link
@fiji-flo

fiji-flo Jan 10, 2017

Author Contributor

Sure.

}
self.hit_test_contents(traversal, &translated_point, client_point, scroll_offsets, result);
}

fn hit_test_stacking_context<'a>(&self,

This comment has been minimized.

Copy link
@pcwalton

pcwalton Jan 10, 2017

Contributor

Could you add a comment explaining that this function translates the point to account for the scroll offset?

This comment has been minimized.

Copy link
@fiji-flo

fiji-flo Jan 10, 2017

Author Contributor

I'm not sure if get which function you're referring to? While adopting to your comments if removed hit_test_stacking_context to make it more readable.

@fiji-flo fiji-flo force-pushed the fiji-flo:text-input-select branch from 6f913e7 to fee9d1f Jan 10, 2017
@fiji-flo
Copy link
Contributor Author

fiji-flo commented Jan 10, 2017

@jdm thanks for pushing
@pcwalton thanks for the feedback

I adopted my changes to the feedback, rebased and squashed.

@jdm jdm removed the S-needs-rebase label Jan 11, 2017
Copy link
Contributor

pcwalton left a comment

This is looking pretty good, just a couple more nits

}
if current_advance > advance {
break;
} else {

This comment has been minimized.

Copy link
@pcwalton

pcwalton Jan 11, 2017

Contributor

nit: No need for else after break.

@@ -547,6 +547,25 @@ impl<'a> GlyphStore {
}

#[inline]
pub fn range_index_of_advance(&self, range: &Range<ByteIndex>, advance: Au, extra_word_spacing: Au) -> (usize, Au) {

This comment has been minimized.

Copy link
@pcwalton

pcwalton Jan 11, 2017

Contributor

Please document what the return values of this function are in a comment.

This comment has been minimized.

Copy link
@fiji-flo

fiji-flo Jan 11, 2017

Author Contributor

While describing what this function returns I realized that it's more intuitive if it returns (index, current_advance) instead of (index, advance -current_advance). This just needed a slight modification in the part that invokes this.
I'll add some comments after I push the modifications.

let (new_index, new_remaining) =
slice.glyphs.range_index_of_advance(&slice.range, remaining, self.extra_word_spacing);
remaining = new_remaining;
new_index + index

This comment has been minimized.

Copy link
@pcwalton

pcwalton Jan 11, 2017

Contributor

Isn't there a sum method on iterators?

This comment has been minimized.

Copy link
@fiji-flo

fiji-flo Jan 11, 2017

Author Contributor

I guess you mean doing a map and sum which would indeed look nicer. That's just a habit from my early haskell days.

@fiji-flo fiji-flo force-pushed the fiji-flo:text-input-select branch from fee9d1f to b40db5b Jan 11, 2017
@fiji-flo
Copy link
Contributor Author

fiji-flo commented Jan 11, 2017

Thanks for the feedback. Adopted and squashed.

.map(|slice| {
let (slice_index, slice_advance) =
slice.glyphs.range_index_of_advance(&slice.range, remaining, self.extra_word_spacing);
remaining -= slice_advance;

This comment has been minimized.

Copy link
@fiji-flo

fiji-flo Jan 11, 2017

Author Contributor

@pcwalton glyphs.range_index_of_advance now returns (index, advanced) instead of (index, remaining) to make it more intuitive. Therefore we need to update remaining here.

@pcwalton
Copy link
Contributor

pcwalton commented Jan 11, 2017

@bors-servo
Copy link
Contributor

bors-servo commented Jan 11, 2017

📌 Commit b40db5b has been approved by pcwalton

@bors-servo
Copy link
Contributor

bors-servo commented Jan 11, 2017

Testing commit b40db5b with merge 68a8e1b...

bors-servo added a commit that referenced this pull request Jan 11, 2017
Position insertion point in input field with mouse

<!-- Please describe your changes on the following line: -->
Implements cursor positioning in input elements (text/password) via mouse. The related issue is #10083 but is only covered partly.
This PR does **not** cover:
* positioning in textarea elements via mouse
* text selection in input/textarea elements via mouse

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [ ] These changes fix #10083 (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because I can't think of a way to test mouse interaction in the current test pipeline.

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/14291)
<!-- Reviewable:end -->
@bors-servo bors-servo merged commit b40db5b into servo:master Jan 11, 2017
3 checks passed
3 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
@paulrouget
Copy link
Contributor

paulrouget commented Jan 16, 2017

This caused a regression: #15015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

9 participants
You can’t perform that action at this time.