Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upPosition insertion point in input field with mouse #14291
Conversation
highfive
commented
Nov 20, 2016
|
Heads up! This PR modifies the following files:
|
highfive
commented
Nov 20, 2016
|
|
|
@nox review ping. |
|
I rebased my branch to solve some merge conflicts. |
|
@nox Review ping. |
|
I know nothing about gfx and layout. r? @pcwalton |
| if !self.reflow(ReflowGoal::ForScriptQuery, | ||
| ReflowQueryType::TextIndexQuery(node, mouse_x, mouse_y), | ||
| ReflowReason::Query) { | ||
| println!("failed in reflow"); |
This comment has been minimized.
This comment has been minimized.
| @@ -92,3 +94,6 @@ impl MarginStyleResponse { | |||
| } | |||
| } | |||
| } | |||
|
|
|||
| #[derive(Clone)] | |||
| pub struct TextIndexResponse(pub Option<(usize)>); | |||
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
| @@ -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.
This comment has been minimized.
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.
This comment has been minimized.
|
@emilio Thanks for the first round of feedback. I'll go over it today. |
|
|
|
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.
This comment has been minimized.
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.
This comment has been minimized.
| 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.
This comment has been minimized.
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.
This comment has been minimized.
| } | ||
| self.hit_test_contents(traversal, &translated_point, client_point, scroll_offsets, result); | ||
| } | ||
|
|
||
| fn hit_test_stacking_context<'a>(&self, |
This comment has been minimized.
This comment has been minimized.
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.
This comment has been minimized.
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.
|
This is looking pretty good, just a couple more nits |
| } | ||
| if current_advance > advance { | ||
| break; | ||
| } else { |
This comment has been minimized.
This comment has been minimized.
| @@ -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.
This comment has been minimized.
pcwalton
Jan 11, 2017
Contributor
Please document what the return values of this function are in a comment.
This comment has been minimized.
This comment has been minimized.
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.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
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.
|
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.
This comment has been minimized.
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.
|
@bors-servo: r+ |
|
|
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 -->
|
|
|
This caused a regression: #15015 |
fiji-flo commentedNov 20, 2016
•
edited by larsbergstrom
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:
./mach build -ddoes not report any errors./mach test-tidydoes not report any errorsThis change is