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

when window gains focus, update mouse coordinate #11794

Merged
merged 1 commit into from Jul 5, 2016

Conversation

@mrmiywj
Copy link
Contributor

mrmiywj commented Jun 19, 2016


  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes fix #11130 (github issue number if applicable).
  • There are tests for these changes OR
  • These changes do not require tests because these cannot be tested automated.

This change is Reviewable

@mrmiywj
Copy link
Contributor Author

mrmiywj commented Jun 19, 2016

cc @paulrouget
Since my modify to servo/glutin has not been merged in crate.io. This PR cannot compiled successfully.

@KiChjang
Copy link
Member

KiChjang commented Jun 19, 2016

You can update glutin by modifying the Cargo.toml file under ports/glutin and running ./mach update-cargo -p glutin

self.mouse_pos.set(Point2D::new(x, y));
self.handle_mouse(mouse_button, element_state, x, y);
self.event_queue.borrow_mut().push(
WindowEvent::MouseWindowMoveEventClass(Point2D::typed(x as f32, y as f32)));

This comment has been minimized.

@paulrouget

paulrouget Jun 20, 2016

Contributor

You need a move event, but also a click event. So you'll need to call handle_mouse here as well.

This comment has been minimized.

@mrmiywj

mrmiywj Jun 20, 2016

Author Contributor

Hmm, I'm wrong here. But I do think the solution should be:

  1. set the new position
  2. push the MouseWindowMoveEventClass into event_queue
  3. call handle_mouse

For the move event, should I also call handle_mouse? I though handle_mouse is only for the click event.

This comment has been minimized.

@paulrouget

paulrouget Jun 20, 2016

Contributor

I believe the mousemove event should happen when the window gains focus.
See my latest comment.

@@ -17,7 +17,7 @@ log = "0.3.5"
msg = {path = "../../components/msg"}
net_traits = {path = "../../components/net_traits"}
script_traits = {path = "../../components/script_traits"}
servo-glutin = "0.4"
servo-glutin = { git = "https://github.com/servo/glutin"}

This comment has been minimized.

This comment has been minimized.

@Manishearth

Manishearth Jun 20, 2016

Member

Just change this line to "0.4.24". Remove the git link

@Manishearth
Copy link
Member

Manishearth commented Jun 20, 2016

@highfive highfive assigned paulrouget and unassigned Manishearth Jun 20, 2016
@Manishearth
Copy link
Member

Manishearth commented Jun 20, 2016

@bors-servo delegate=paulrouget

@bors-servo
Copy link
Contributor

bors-servo commented Jun 20, 2016

✌️ @paulrouget can now approve this pull request

@paulrouget
Copy link
Contributor

paulrouget commented Jun 20, 2016

STR:

  1. load the above example
  2. click anywhere. see the red div being moved exactly where the click occurs
  3. move the mouse anywhere above the window. Do not click. Let's call this new position P1
  4. with Alt-Tab (or Cmd-Tab), bring another non-Servo window above the Servo window (make it so the servo window loses focus)
  5. move the mouse 10 pixels to the right. Let's call this new position P2
  6. with Alt-Tab (or Cmd-Tab), bring back the Servo window. Do not move mouse.
  7. Click
  8. the red div moves to P1, not to P2. Which is wrong.

Ideally, we should get a mouse move event when 6) happens.

<style>
  div {
    width: 0px;
    height: 0px;
    position: absolute;
    border: 2px solid red;
    top: 0;
    left: 0;
  }
</style>
<div></div>
<script>
  var div = document.querySelector("div");
  window.addEventListener("click", e => {
    div.style.top = e.clientY - 2 + "px";
    div.style.left = e.clientX - 2 + "px";
  });
</script>
@mrmiywj
Copy link
Contributor Author

mrmiywj commented Jun 20, 2016

@paulrouget
Hi, I've updated my PR. I do think it's enough.
But unfortunately, it cannot be compiled on my RMBP.

Updating git repository `https://github.com/servo/glutin`
error: no matching package named `servo-glutin` found (required by `glutin_app`)
location searched: https://github.com/servo/glutin
version required: *
Build completed in 0:00:07

Is there anything wrong with my modification to Cargo.toml?

@jdm
Copy link
Member

jdm commented Jun 20, 2016

The change to gluten will need to be published, and then we'll need to use the version from crates.io instead of git.

@mrmiywj
Copy link
Contributor Author

mrmiywj commented Jun 20, 2016

@jdm
So what do I need to do now? My PR is merged by servo/glutin, which is forked.

@Manishearth
Copy link
Member

Manishearth commented Jun 20, 2016

./mach update-cargo -p servo-glutin , and commit the lockfile changes

@mrmiywj
Copy link
Contributor Author

mrmiywj commented Jun 20, 2016

@Manishearth

➜  servo git:(update-mouse-coordinate-when-focus) ✗ ./mach update-cargo -p servo-glutin
components/servo
    Updating registry `https://github.com/rust-lang/crates.io-index`
    Updating git repository `https://github.com/servo/glutin`
error: no matching package named `servo-glutin` found (required by `glutin_app`)
location searched: https://github.com/servo/glutin
version required: *
ports/cef
    Updating registry `https://github.com/rust-lang/crates.io-index`
    Updating git repository `https://github.com/servo/glutin`
error: no matching package named `servo-glutin` found (required by `glutin_app`)
location searched: https://github.com/servo/glutin
version required: *
ports/geckolib
error: package id specification `servo-glutin` matched no packages

It also complains. QAQ

@Manishearth
Copy link
Member

Manishearth commented Jun 20, 2016

Oh, undo your check to that cargo.toml too. Mention servo-glutin 0.4 or 0.4.24

@mrmiywj
Copy link
Contributor Author

mrmiywj commented Jun 20, 2016

Sorry for that maybe I cannot understand what you said.
Maybe u said is that I should specify the servo-glutin version based on my commit? Like this:
servo-glutin = { git = "https://github.com/servo/glutin", version = "0.4.24"}
But it also complained...

➜  servo git:(update-mouse-coordinate-when-focus) ✗ ./mach update-cargo -p servo-glutin
components/servo
    Updating registry `https://github.com/rust-lang/crates.io-index`
    Updating git repository `https://github.com/servo/glutin`
error: no matching package named `servo-glutin` found (required by `glutin_app`)
location searched: https://github.com/servo/glutin
version required: ^0.4.24
ports/cef
    Updating registry `https://github.com/rust-lang/crates.io-index`
    Updating git repository `https://github.com/servo/glutin`
error: no matching package named `servo-glutin` found (required by `glutin_app`)
location searched: https://github.com/servo/glutin
version required: ^0.4.24
ports/geckolib
error: package id specification `servo-glutin` matched no packages

Or just like the Cargo.toml in master? Like:
servo-glutin="0.4.24"
But it will use the repo on crate.io, not our own repo, I think.
It also complained...

➜  servo git:(update-mouse-coordinate-when-focus) ✗ ./mach update-cargo -p servo-glutin
components/servo
    Updating registry `https://github.com/rust-lang/crates.io-index`
    Updating cocoa v0.4.3 -> v0.4.4
    Updating servo-glutin v0.4.23 -> v0.4.24
ports/cef
    Updating registry `https://github.com/rust-lang/crates.io-index`
error: failed to select a version for `cocoa` (required by `servo-glutin`):
all possible versions conflict with previously selected versions of `cocoa`
  version 0.4.3 in use by cocoa v0.4.3
  possible versions to select: 0.4.4
ports/geckolib
error: package id specification `servo-glutin` matched no packages
@jdm
Copy link
Member

jdm commented Jun 20, 2016

You may need to run ./mach cargo-update -p cocoa first.

@mrmiywj
Copy link
Contributor Author

mrmiywj commented Jun 20, 2016

I've updated this PR.
But if this PR is not merged by the crate.io. I do think it will not compile successfully...

@jdm
Copy link
Member

jdm commented Jun 20, 2016

Looks like there's a change missing to Servo's code:

/home/travis/build/servo/servo/ports/glutin/window.rs:268:29: 268:39 error: this pattern has 2 fields, but the corresponding variant has 1 field [E0023]
/home/travis/build/servo/servo/ports/glutin/window.rs:268                             Some(x, y) => {
                                                                                      ^~~~~~~~~~
/home/travis/build/servo/servo/ports/glutin/window.rs:268:29: 268:39 help: run `rustc --explain E0023` to see a detailed explanation
error: aborting due to previous error
Build failed, waiting for other jobs to finish...
error: Could not compile `glutin_app`.

I think it's supposed to be Some((x, y)).

@@ -279,7 +288,8 @@ impl Window {
MouseScrollDelta::PixelDelta(dx, dy) => (dx, dy),
};
let phase = glutin_phase_to_touch_event_type(phase);
self.scroll_window(dx, dy, phase);
self.scroll_window(
dx, dy, phase);

This comment has been minimized.

@KiChjang

KiChjang Jul 5, 2016

Member

Revert this change please.

let mouse_pos = self.mouse_pos.get();
self.handle_mouse(mouse_button, element_state, mouse_pos.x, mouse_pos.y);
}
mouse_button == MouseButton::Right {

This comment has been minimized.

@KiChjang

KiChjang Jul 5, 2016

Member

I think the problem is here, the mouse_button here should match up with the last line's mouse_button columns, and the match expression on the next line should be de-indented once.

@mrmiywj
Copy link
Contributor Author

mrmiywj commented Jul 5, 2016

@KiChjang Is the indent correct now?

self.handle_mouse(mouse_button, element_state, mouse_pos.x, mouse_pos.y);
}
}
}

This comment has been minimized.

@KiChjang

KiChjang Jul 5, 2016

Member

The last one is correct, but you can see that the one above it is indented too much to the right. De-indenting once should fix it.

@mrmiywj
Copy link
Contributor Author

mrmiywj commented Jul 5, 2016

I think it's due to the two lines of if conditions, which may mistake my emacs auto-intending.

@KiChjang
Copy link
Member

KiChjang commented Jul 5, 2016

@bors-servo r+

Thank you!

@bors-servo
Copy link
Contributor

bors-servo commented Jul 5, 2016

📌 Commit 6bcca8e has been approved by KiChjang

@bors-servo
Copy link
Contributor

bors-servo commented Jul 5, 2016

Testing commit 6bcca8e with merge d99ff8d...

bors-servo added a commit that referenced this pull request Jul 5, 2016
…KiChjang

when window gains focus, update mouse coordinate

<!-- Please describe your changes on the following line: -->

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

<!-- Either: -->
- [ ] There are tests for these changes OR
- [X] These changes do not require tests because these cannot be tested automated.

<!-- 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="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/11794)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Jul 5, 2016

@bors-servo bors-servo merged commit 6bcca8e into servo:master Jul 5, 2016
2 checks passed
2 checks passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
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.