Skip to content

Commit

Permalink
* 优化select弹出菜单的弹出速度。原理是把原来多次发送WM_COMMIT消息合并成只发一次,只到响应完再发。
Browse files Browse the repository at this point in the history
  • Loading branch information
weolar committed May 31, 2017
1 parent f3ffb1e commit 0cfe2ad
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
35 changes: 24 additions & 11 deletions content/browser/PopupMenuWin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ PopupMenuWin::PopupMenuWin(HWND hWnd, IntPoint offset, WebViewImpl* webViewImpl)
m_hasResize = true;
m_needResize = true;
m_initialize = false;
m_isCommiting = false;
m_lastFrameTimeMonotonic = 0;
m_memoryCanvas = nullptr;
m_layerTreeHost = nullptr;
Expand Down Expand Up @@ -136,7 +137,6 @@ LRESULT PopupMenuWin::wndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPa
LRESULT lResult = 0;

switch (message) {

case WM_MOUSEMOVE:
case WM_LBUTTONDOWN:
case WM_LBUTTONUP: {
Expand Down Expand Up @@ -228,10 +228,11 @@ LRESULT PopupMenuWin::wndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPa

void PopupMenuWin::beginMainFrame()
{
m_isCommiting = false;
if (!m_needsCommit || !m_initialize)
return;
m_needsCommit = false;

blink::WebPagePopup* popup = m_popupImpl;

updataSize();
Expand Down Expand Up @@ -277,7 +278,11 @@ void PopupMenuWin::show(WebNavigationPolicy)
m_needResize = true;
m_hasResize = true;
m_needsCommit = true;
::PostMessage(m_hPopup, WM_COMMIT, 0, 0);

if (!m_isCommiting && m_hPopup) {
m_isCommiting = true;
::PostMessage(m_hPopup, WM_COMMIT, 0, 0);
}
}

void PopupMenuWin::paint(HDC hdc, RECT rcPaint)
Expand Down Expand Up @@ -309,7 +314,6 @@ void PopupMenuWin::updataPaint()
paint.setAntiAlias(true);
m_memoryCanvas->drawPaint(paint);
m_layerTreeHost->drawToCanvas(m_memoryCanvas, clip);

m_memoryCanvas->restore();
skia::EndPlatformPaint(m_memoryCanvas);
}
Expand Down Expand Up @@ -361,7 +365,10 @@ void PopupMenuWin::didInvalidateRect(const blink::WebRect& r)
{
::InvalidateRect(m_hPopup, NULL, TRUE);
m_needsCommit = true;
::PostMessage(m_hPopup, WM_COMMIT, 0, 0);
if (!m_isCommiting && m_hPopup) {
m_isCommiting = true;
::PostMessage(m_hPopup, WM_COMMIT, 0, 0);
}
}

void PopupMenuWin::didAutoResize(const WebSize& newSize)
Expand All @@ -374,7 +381,10 @@ void PopupMenuWin::didUpdateLayoutSize(const WebSize& newSize)
m_needResize = true;
m_hasResize = true;
m_needsCommit = true;
::PostMessage(m_hPopup, WM_COMMIT, 0, 0);
if (!m_isCommiting && m_hPopup) {
m_isCommiting = true;
::PostMessage(m_hPopup, WM_COMMIT, 0, 0);
}
}

static void trimWidthHeight(blink::IntRect& rect)
Expand All @@ -389,21 +399,24 @@ static void trimWidthHeight(blink::IntRect& rect)
void PopupMenuWin::setWindowRect(const WebRect& r)
{
m_rect = r;
// m_rect.setWidth(r.width);
// m_rect.setHeight(r.height);

trimWidthHeight(m_rect);

m_needResize = true;
m_hasResize = true;
m_needsCommit = true;
::PostMessage(m_hPopup, WM_COMMIT, 0, 0);
if (!m_isCommiting && m_hPopup) {
m_isCommiting = true;
::PostMessage(m_hPopup, WM_COMMIT, 0, 0);
}
}

void PopupMenuWin::scheduleAnimation()
{
m_needsCommit = true;
::PostMessage(m_hPopup, WM_COMMIT, 0, 0);
if (!m_isCommiting && m_hPopup) {
m_isCommiting = true;
::PostMessage(m_hPopup, WM_COMMIT, 0, 0);
}
}

WebLayerTreeView* PopupMenuWin::layerTreeView()
Expand Down
3 changes: 2 additions & 1 deletion content/browser/PopupMenuWin.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ class PopupMenuWin : public blink::WebViewClient {
HWND m_hPopup;
skia::PlatformCanvas* m_memoryCanvas;
blink::IntRect m_rect;
bool m_needsCommit;
bool m_needsCommit; // ·ÀÖ¹ÖØÈëbeginMainFrame
bool m_isCommiting; // ·ÀÖ¹¶à´Î·¢ËÍCommit
bool m_hasResize;
bool m_needResize;
bool m_initialize;
Expand Down

0 comments on commit 0cfe2ad

Please sign in to comment.