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

fix wrong mouse position gotten in qqbrowser and correct wrong ua match order #5604

Merged
merged 1 commit into from Oct 25, 2019
Merged

fix wrong mouse position gotten in qqbrowser and correct wrong ua match order #5604

merged 1 commit into from Oct 25, 2019

Conversation

Marssssssss
Copy link

@Marssssssss Marssssssss commented Oct 24, 2019

Re: cocos-creator/2d-tasks#1958
之前的 cc.sys 中正则匹配的第一个表达式中的 qq 会匹配 qqbrowser 字段中的 ‘qq’ 字符串,会导致 qq 浏览器的 cc.sys.browserType 获取成 ‘qq’,这里将 qq 和 qqbrowser 的正则匹配顺序进行了调换。另外针对 qq 浏览器做了处理,现在可以正确获得点击位置了。

@@ -341,6 +341,10 @@ let inputManager = {
* @return {Vec2}
*/
getPointByEvent (event, pos) {
// by execute this can let mouse position be correctly gotten in qqbrowser
if (cc.sys.browserType === "qqbrowser")
this._updateCanvasBoundingRect();
Copy link
Contributor

@holycanvas holycanvas Oct 24, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为什么其他浏览器不需要,只有qq浏览器才需要

Copy link
Author

@Marssssssss Marssssssss Oct 24, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为什么其他浏览器不需要,只有qq浏览器才需要

目前 issue 和论坛里面说 qq 浏览器会出现这个问题,主要是 qq 浏览器改变拖动条位置的时候不会触发 resize,也就是说它不会回调执行 updateCnavasBoundingRect 这个函数,而在 chrome 上就会正常触发。

Copy link
Contributor

@PPpro PPpro Oct 24, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

qq 浏览器滚动不会触发 resize 事件,可以试试看能不能里监听到 scroll 事件
https://developer.mozilla.org/zh-CN/docs/Web/API/Document/scroll_event
最好是通过事件机制去更新 rect,防止其他地方也需要更新到

建议不要用 “qqbrowser” 字符串,用常量 cc.sys.BROWSER_TYPE_QQ

Copy link
Author

@Marssssssss Marssssssss Oct 24, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

scroll 事件也不会被触发。打算将 _updateCanvasBoundingRect 的时机放到每次鼠标事件触发的时候而非 resize 触发的时候,这样可以适应所有浏览器的情况。

Copy link
Author

@Marssssssss Marssssssss Oct 24, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不过不太确定会不会对性能有较大影响。

Copy link
Contributor

@holycanvas holycanvas Oct 24, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

开发者不是反馈2.1.3之前是正常的么,之前版本是怎么处理的?

Copy link
Author

@Marssssssss Marssssssss Oct 24, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

开发者不是反馈2.1.3之前是正常的么,之前版本是怎么处理的?

现在确定不是 resize 的问题 ,原因是 qq 浏览器在计算 pageY 的时候是错的,之前就是每次鼠标事件触发的时候都会去调用 _updateCanvasBoundingRect ,那时候这个方法的名字不叫这个,但是内部的执行基本是一致的。现在其实就是对 qq 浏览器和 uc 浏览器按照以前的流程来执行,其它浏览器不变。

Copy link
Contributor

@holycanvas holycanvas Oct 24, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这些浏览器真坑

@holycanvas holycanvas requested a review from PPpro Oct 24, 2019
@PPpro
Copy link
Contributor

@PPpro PPpro commented Oct 24, 2019

2.1.3 每次都会重新计算 canvasBoundingRect,2.2 上做了一次优化,全局缓存一个 rect,在 resize 的时候才去更新 rect
不过这里有个问题,,qq 浏览器 不能正确处理页面滚动后的点击坐标, pageY 是不正确的
https://developer.mozilla.org/zh-CN/docs/Web/API/MouseEvent/pageY

PPpro
PPpro approved these changes Oct 24, 2019
@jareguo jareguo merged commit 76233d9 into cocos:v2.2.2 Oct 25, 2019
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants