OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/renderer_host/render_widget_host_view_win.h" | 5 #include "chrome/browser/renderer_host/render_widget_host_view_win.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/i18n/rtl.h" | 10 #include "base/i18n/rtl.h" |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
312 UINT swp_flags = SWP_NOSENDCHANGING | SWP_NOOWNERZORDER | SWP_NOCOPYBITS | | 312 UINT swp_flags = SWP_NOSENDCHANGING | SWP_NOOWNERZORDER | SWP_NOCOPYBITS | |
313 SWP_NOZORDER | SWP_NOACTIVATE | SWP_DEFERERASE; | 313 SWP_NOZORDER | SWP_NOACTIVATE | SWP_DEFERERASE; |
314 | 314 |
315 // If the style is not popup, you have to convert the point to client | 315 // If the style is not popup, you have to convert the point to client |
316 // coordinate. | 316 // coordinate. |
317 POINT point = { rect.x(), rect.y() }; | 317 POINT point = { rect.x(), rect.y() }; |
318 if (GetStyle() & WS_CHILD) | 318 if (GetStyle() & WS_CHILD) |
319 ScreenToClient(&point); | 319 ScreenToClient(&point); |
320 | 320 |
321 SetWindowPos(NULL, point.x, point.y, rect.width(), rect.height(), swp_flags); | 321 SetWindowPos(NULL, point.x, point.y, rect.width(), rect.height(), swp_flags); |
322 if (compositor_host_window_) { | |
323 ::SetWindowPos(compositor_host_window_, NULL, point.x, point.y, | |
324 rect.width(), rect.height(), | |
325 SWP_NOSENDCHANGING | SWP_NOCOPYBITS | SWP_NOZORDER | SWP_NOACTIVATE); | |
326 } | |
327 render_widget_host_->WasResized(); | 322 render_widget_host_->WasResized(); |
328 EnsureTooltip(); | 323 EnsureTooltip(); |
329 } | 324 } |
330 | 325 |
331 gfx::NativeView RenderWidgetHostViewWin::GetNativeView() { | 326 gfx::NativeView RenderWidgetHostViewWin::GetNativeView() { |
332 return m_hWnd; | 327 return m_hWnd; |
333 } | 328 } |
334 | 329 |
335 void RenderWidgetHostViewWin::MovePluginWindows( | 330 void RenderWidgetHostViewWin::MovePluginWindows( |
336 const std::vector<WebPluginGeometry>& plugin_window_moves) { | 331 const std::vector<WebPluginGeometry>& plugin_window_moves) { |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
455 static BOOL CALLBACK AddChildWindowToVector(HWND hwnd, LPARAM lparam) { | 450 static BOOL CALLBACK AddChildWindowToVector(HWND hwnd, LPARAM lparam) { |
456 std::vector<HWND>* vector = reinterpret_cast<std::vector<HWND>*>(lparam); | 451 std::vector<HWND>* vector = reinterpret_cast<std::vector<HWND>*>(lparam); |
457 vector->push_back(hwnd); | 452 vector->push_back(hwnd); |
458 return TRUE; | 453 return TRUE; |
459 } | 454 } |
460 | 455 |
461 void RenderWidgetHostViewWin::CleanupCompositorWindow() { | 456 void RenderWidgetHostViewWin::CleanupCompositorWindow() { |
462 if (!compositor_host_window_) | 457 if (!compositor_host_window_) |
463 return; | 458 return; |
464 | 459 |
465 std::vector<HWND> all_child_windows; | 460 // Hide the compositor and parent it to the desktop rather than destroying |
466 ::EnumChildWindows(compositor_host_window_, AddChildWindowToVector, | 461 // it immediately. The GPU process has a grace period to stop accessing the |
467 reinterpret_cast<LPARAM>(&all_child_windows)); | 462 // window. TODO(apatrick): the GPU process should acknowledge that it has |
468 if (all_child_windows.size()) { | 463 // finished with the window handle and the browser process should destroy it |
469 DCHECK(all_child_windows.size() == 1); | 464 // at that point. |
470 ::ShowWindow(all_child_windows[0], SW_HIDE); | 465 ::ShowWindow(compositor_host_window_, SW_HIDE); |
471 ::SetParent(all_child_windows[0], NULL); | 466 ::SetParent(compositor_host_window_, NULL); |
472 } | 467 |
468 BrowserThread::PostDelayedTask( | |
469 BrowserThread::UI, | |
470 FROM_HERE, | |
471 NewRunnableFunction(::DestroyWindow, compositor_host_window_), | |
472 10000); | |
jam
2011/04/27 20:45:22
nit: use constant
apatrick_chromium
2011/04/27 22:45:22
Done.
| |
473 | |
473 compositor_host_window_ = NULL; | 474 compositor_host_window_ = NULL; |
474 } | 475 } |
475 | 476 |
476 bool RenderWidgetHostViewWin::IsActivatable() const { | 477 bool RenderWidgetHostViewWin::IsActivatable() const { |
477 // Popups should not be activated. | 478 // Popups should not be activated. |
478 return popup_type_ == WebKit::WebPopupTypeNone; | 479 return popup_type_ == WebKit::WebPopupTypeNone; |
479 } | 480 } |
480 | 481 |
481 void RenderWidgetHostViewWin::Focus() { | 482 void RenderWidgetHostViewWin::Focus() { |
482 if (IsWindow()) | 483 if (IsWindow()) |
(...skipping 976 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1459 if (!render_widget_host_ || | 1460 if (!render_widget_host_ || |
1460 render_process_host != render_widget_host_->process()) | 1461 render_process_host != render_widget_host_->process()) |
1461 return; | 1462 return; |
1462 | 1463 |
1463 // If it was our RenderProcessHost that posted the notification, | 1464 // If it was our RenderProcessHost that posted the notification, |
1464 // clear the BrowserAccessibilityManager, because the renderer is | 1465 // clear the BrowserAccessibilityManager, because the renderer is |
1465 // dead and any accessibility information we have is now stale. | 1466 // dead and any accessibility information we have is now stale. |
1466 browser_accessibility_manager_.reset(NULL); | 1467 browser_accessibility_manager_.reset(NULL); |
1467 } | 1468 } |
1468 | 1469 |
1469 // Looks through the children windows of the CompositorHostWindow. If the | |
1470 // compositor child window is found, its size is checked against the host | |
1471 // window's size. If the child is smaller in either dimensions, we fill | |
1472 // the host window with white to avoid unseemly cracks. | |
1473 static void PaintCompositorHostWindow(HWND hWnd) { | 1470 static void PaintCompositorHostWindow(HWND hWnd) { |
1474 PAINTSTRUCT paint; | 1471 PAINTSTRUCT paint; |
1475 BeginPaint(hWnd, &paint); | 1472 BeginPaint(hWnd, &paint); |
1476 | 1473 |
1477 std::vector<HWND> child_windows; | |
1478 EnumChildWindows(hWnd, AddChildWindowToVector, | |
1479 reinterpret_cast<LPARAM>(&child_windows)); | |
1480 | |
1481 if (child_windows.size()) { | |
1482 HWND child = child_windows[0]; | |
1483 | |
1484 RECT host_rect, child_rect; | |
1485 GetClientRect(hWnd, &host_rect); | |
1486 if (GetClientRect(child, &child_rect)) { | |
1487 if (child_rect.right < host_rect.right || | |
1488 child_rect.bottom != host_rect.bottom) { | |
1489 FillRect(paint.hdc, &host_rect, | |
1490 static_cast<HBRUSH>(GetStockObject(WHITE_BRUSH))); | |
1491 } | |
1492 } | |
1493 } | |
1494 EndPaint(hWnd, &paint); | 1474 EndPaint(hWnd, &paint); |
1495 } | 1475 } |
1496 | 1476 |
1497 // WndProc for the compositor host window. We use this instead of Default so | 1477 // WndProc for the compositor host window. We use this instead of Default so |
1498 // we can drop WM_PAINT and WM_ERASEBKGD messages on the floor. | 1478 // we can drop WM_PAINT and WM_ERASEBKGD messages on the floor. |
1499 static LRESULT CALLBACK CompositorHostWindowProc(HWND hWnd, UINT message, | 1479 static LRESULT CALLBACK CompositorHostWindowProc(HWND hWnd, UINT message, |
1500 WPARAM wParam, LPARAM lParam) { | 1480 WPARAM wParam, LPARAM lParam) { |
1501 switch (message) { | 1481 switch (message) { |
1502 case WM_ERASEBKGND: | 1482 case WM_ERASEBKGND: |
1503 return 0; | 1483 return 0; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1555 } | 1535 } |
1556 | 1536 |
1557 void RenderWidgetHostViewWin::ShowCompositorHostWindow(bool show) { | 1537 void RenderWidgetHostViewWin::ShowCompositorHostWindow(bool show) { |
1558 // When we first create the compositor, we will get a show request from | 1538 // When we first create the compositor, we will get a show request from |
1559 // the renderer before we have gotten the create request from the GPU. In this | 1539 // the renderer before we have gotten the create request from the GPU. In this |
1560 // case, simply ignore the show request. | 1540 // case, simply ignore the show request. |
1561 if (compositor_host_window_ == NULL) | 1541 if (compositor_host_window_ == NULL) |
1562 return; | 1542 return; |
1563 | 1543 |
1564 if (show) { | 1544 if (show) { |
1565 UINT flags = SWP_NOSENDCHANGING | SWP_NOCOPYBITS | SWP_NOZORDER | | 1545 ::ShowWindow(compositor_host_window_, SW_SHOW); |
1566 SWP_NOACTIVATE | SWP_DEFERERASE | SWP_SHOWWINDOW; | |
1567 gfx::Rect rect = GetViewBounds(); | |
1568 ::SetWindowPos(compositor_host_window_, NULL, 0, 0, | |
1569 rect.width(), rect.height(), | |
1570 flags); | |
1571 | 1546 |
1572 // Get all the child windows of this view, including the compositor window. | 1547 // Get all the child windows of this view, including the compositor window. |
1573 std::vector<HWND> all_child_windows; | 1548 std::vector<HWND> all_child_windows; |
1574 ::EnumChildWindows(m_hWnd, AddChildWindowToVector, | 1549 ::EnumChildWindows(m_hWnd, AddChildWindowToVector, |
1575 reinterpret_cast<LPARAM>(&all_child_windows)); | 1550 reinterpret_cast<LPARAM>(&all_child_windows)); |
1576 | 1551 |
1577 // Build a list of just the plugin window handles | 1552 // Build a list of just the plugin window handles |
1578 std::vector<HWND> plugin_windows; | 1553 std::vector<HWND> plugin_windows; |
1579 bool compositor_host_window_found = false; | 1554 bool compositor_host_window_found = false; |
1580 for (size_t i = 0; i < all_child_windows.size(); ++i) { | 1555 for (size_t i = 0; i < all_child_windows.size(); ++i) { |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1799 } | 1774 } |
1800 | 1775 |
1801 // static | 1776 // static |
1802 RenderWidgetHostView* | 1777 RenderWidgetHostView* |
1803 RenderWidgetHostView::GetRenderWidgetHostViewFromNativeView( | 1778 RenderWidgetHostView::GetRenderWidgetHostViewFromNativeView( |
1804 gfx::NativeView native_view) { | 1779 gfx::NativeView native_view) { |
1805 return ::IsWindow(native_view) ? | 1780 return ::IsWindow(native_view) ? |
1806 reinterpret_cast<RenderWidgetHostView*>( | 1781 reinterpret_cast<RenderWidgetHostView*>( |
1807 ViewProp::GetValue(native_view, kRenderWidgetHostViewKey)) : NULL; | 1782 ViewProp::GetValue(native_view, kRenderWidgetHostViewKey)) : NULL; |
1808 } | 1783 } |
OLD | NEW |